Home | History | Annotate | only in /src/sys/arch/amd64
History log of /src/sys/arch/amd64
RevisionDateAuthorComments
 1.8 22-Dec-2017  maxv Build and install the prekern by default. I didn't build a full
distribution to test this change, but it seems fine enough.
 1.7 18-Mar-2011  dyoung Fix tags target.
 1.6 28-Apr-2010  dyoung branches: 1.6.2;
Fix 'tags' target.
 1.5 26-Oct-2008  mrg branches: 1.5.8; 1.5.14; 1.5.16;
- install i386 includes on amd64
- sort
 1.4 25-Oct-2008  apb Use ${TOOL_SED} instead if plain sed in Makefiles.
 1.3 17-Feb-2008  bouyer branches: 1.3.6; 1.3.10; 1.3.16;
Install xenio.h and xenio3.h in /usr/include/xen, for the benefit
of xentools3.

XXX ignore those in Makefile.ioctl-c, they don't compile properly outside
of the Xen context and the ioctls from xenio.h conflicts with
soundcard.h
 1.2 26-Apr-2003  fvdl branches: 1.2.18; 1.2.80; 1.2.86;
x86_64 -> amd64
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.2.86.1 18-Feb-2008  mjf Sync with HEAD.
 1.2.80.1 23-Mar-2008  matt sync with HEAD
 1.2.18.1 27-Feb-2008  yamt sync with head.
 1.3.16.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.3.10.2 11-Aug-2010  yamt sync with head.
 1.3.10.1 04-May-2009  yamt sync with head.
 1.3.6.1 17-Jan-2009  mjf Sync with HEAD.
 1.5.16.2 21-Apr-2011  rmind sync with head
 1.5.16.1 30-May-2010  rmind sync with head
 1.5.14.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.5.8.2 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.5.8.1 24-Oct-2010  jym Sync with HEAD
 1.6.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.1 06-Sep-2007  jmcneill branches: 1.1.2;
file Makefile.wakecode was initially added on branch jmcneill-pm.
 1.1.2.4 24-Sep-2007  joerg Generate the ACPI wakecode image dynamically at build time.
 1.1.2.3 07-Sep-2007  jmcneill Share ACPI wakecode generation between i386 and amd64, and convert amd64
to use joerg's new build scripts for generating wakecode.
 1.1.2.2 06-Sep-2007  jmcneill Cleanup objects after build.
 1.1.2.1 06-Sep-2007  jmcneill Add work-in-progress amd64 wakecode. Doesn't yet reach long mode..
 1.13 24-Jul-2016  maxv KNF, and reduce the diff between amd64 and i386.
 1.12 15-Jan-2014  joerg branches: 1.12.6; 1.12.10;
LLVM doesn't support data32/addr32, but is smart enough to figure the
necessary prefixes out.
 1.11 19-Apr-2012  jym branches: 1.11.2; 1.11.4;
Set the CR0_AM bit so processes can enable alignment check errors under
x86 through PSL_AC bit.

ATF test incoming shortly.
 1.10 24-Aug-2009  jmcneill branches: 1.10.12; 1.10.16; 1.10.18;
Add definition for WAKEUP_vesa_modenum
 1.9 24-Aug-2009  jmcneill Ensure that the VBE mode is only restored when machdep.acpi_vbios_reset=1
 1.8 24-Aug-2009  jmcneill Pass the VBE mode number from the bootloader to the kernel, and then
make the ACPI wakecode aware of it. Restore the desired VBE mode on resume
when acpi_vbios_reset=1, so suspend/resume with genfb console will work.
 1.7 25-May-2008  joerg branches: 1.7.12;
Random underdocumented CPU facts:
AMD K8 and newer will trap when enabling the NX support outside PAE
paging mode. The AMD64 wake code was restoring the MSR EFER to switch to
Long Mode and naturally didn't have paging enabled at that point.
While this works fine with Intel CPUs, it resulted in an immediate
reboot with AMD processors.

Fixed by a joint brain storming session of jmcneill@, cegger@ and
myself, based on some input from the hardware developers. This fixes
PR 38587.
 1.6 25-May-2008  jmcneill Remove unnecessary rdmsr when modifying MSR_EFER.
 1.5 11-May-2008  ad Share cpu.h between the x86 ports.
 1.4 28-Apr-2008  martin branches: 1.4.2;
Remove clause 3 and 4 from TNF licenses
 1.3 18-Dec-2007  joerg branches: 1.3.2; 1.3.4; 1.3.10; 1.3.12; 1.3.14;
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.2 09-Dec-2007  jmcneill branches: 1.2.2;
Merge jmcneill-pm branch.
 1.1 06-Sep-2007  jmcneill branches: 1.1.2; 1.1.8; 1.1.10; 1.1.12;
file acpi_wakecode.S was initially added on branch jmcneill-pm.
 1.1.12.1 11-Dec-2007  yamt sync with head.
 1.1.10.1 26-Dec-2007  ad Sync with head.
 1.1.8.1 27-Dec-2007  mjf Sync with HEAD.
 1.1.2.12 23-Nov-2007  joerg Exploit that PAE support implies PSE support and simplify the low-level
wake code to just load some useful values for cr0 and cr4 similiar to
what locore.S does. Load the real GDT from acpi_md_sleep_exit as well.
 1.1.2.11 28-Oct-2007  joerg Add my copyright.
 1.1.2.10 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.1.2.9 27-Sep-2007  joerg Fix braino: the %esp value is a constant and not a memory reference.
 1.1.2.8 26-Sep-2007  joerg Start commenting the code.
 1.1.2.7 25-Sep-2007  joerg Reinitialise ss when in protected mode.
 1.1.2.6 25-Sep-2007  joerg Simplify low-level wakecode by exploiting constant load address.
 1.1.2.5 10-Sep-2007  joerg Add work-in-progress remerge of i386 changes for the ACPI wakecode
and changes to adopt it to AMD64.
 1.1.2.4 08-Sep-2007  jmcneill Wrap more screen output in WAKECODE_VERBOSE
 1.1.2.3 07-Sep-2007  jmcneill Share ACPI wakecode generation between i386 and amd64, and convert amd64
to use joerg's new build scripts for generating wakecode.
 1.1.2.2 06-Sep-2007  jmcneill Wrap more debug output in WAKECODE_VERBOSE
 1.1.2.1 06-Sep-2007  jmcneill Add work-in-progress amd64 wakecode. Doesn't yet reach long mode..
 1.2.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.3.14.3 16-Sep-2009  yamt sync with head
 1.3.14.2 04-May-2009  yamt sync with head.
 1.3.14.1 16-May-2008  yamt sync with head.
 1.3.12.2 04-Jun-2008  yamt sync with head
 1.3.12.1 18-May-2008  yamt sync with head.
 1.3.10.1 02-Jun-2008  mjf Sync with HEAD.
 1.3.4.2 21-Jan-2008  yamt sync with head
 1.3.4.1 18-Dec-2007  yamt file acpi_wakecode.S was added on branch yamt-lazymbuf on 2008-01-21 09:35:12 +0000
 1.3.2.2 09-Jan-2008  matt sync with HEAD
 1.3.2.1 18-Dec-2007  matt file acpi_wakecode.S was added on branch matt-armv6 on 2008-01-09 01:44:41 +0000
 1.4.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.7.12.1 01-Nov-2009  jym Sync with HEAD.
 1.10.18.1 20-Apr-2012  riz Pull up following revision(s) (requested by jym in ticket #189):
sys/arch/x86/include/psl.h: revision 1.7
sys/arch/i386/i386/locore.S: revision 1.98
sys/arch/amd64/acpi/acpi_wakecode.S: revision 1.11
sys/arch/amd64/amd64/mptramp.S: revision 1.13
sys/arch/i386/acpi/acpi_wakecode.S: revision 1.15
sys/arch/i386/i386/mptramp.S: revision 1.23
sys/arch/amd64/amd64/locore.S: revision 1.68
Set the CR0_AM bit so processes can enable alignment check errors under
x86 through PSL_AC bit.
ATF test incoming shortly.
PSL_AC is user-settable.
 1.10.16.1 29-Apr-2012  mrg sync to latest -current.
 1.10.12.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.10.12.1 23-May-2012  yamt sync with head.
 1.11.4.1 18-May-2014  rmind sync with head
 1.11.2.2 03-Dec-2017  jdolecek update from HEAD
 1.11.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.12.10.1 26-Jul-2016  pgoyette Sync with HEAD
 1.12.6.1 05-Oct-2016  skrll Sync with HEAD
 1.1 06-Sep-2007  jmcneill branches: 1.1.2;
file acpi_wakecode.h was initially added on branch jmcneill-pm.
 1.1.2.6 24-Sep-2007  joerg Generate the ACPI wakecode image dynamically at build time.
 1.1.2.5 10-Sep-2007  joerg Add work-in-progress remerge of i386 changes for the ACPI wakecode
and changes to adopt it to AMD64.
 1.1.2.4 08-Sep-2007  jmcneill Wrap more screen output in WAKECODE_VERBOSE
 1.1.2.3 07-Sep-2007  jmcneill Share ACPI wakecode generation between i386 and amd64, and convert amd64
to use joerg's new build scripts for generating wakecode.
 1.1.2.2 06-Sep-2007  jmcneill Regen.
 1.1.2.1 06-Sep-2007  jmcneill Generate acpi_wakecode.h from amd64 acpi_wakecode.S
 1.7 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.6 15-Dec-2007  joerg Move mapping of the real mode location for the ACPI wakeup code into a
separate function called from acpi_md_callback.
 1.5 15-Dec-2007  joerg Steal some rope from innocent users and disallow ACPI suspend if more
than one CPU was found.
 1.4 09-Dec-2007  jmcneill branches: 1.4.2;
Merge jmcneill-pm branch.
 1.3 11-Dec-2005  christos branches: 1.3.48; 1.3.50; 1.3.56; 1.3.60; 1.3.62;
merge ktrace-lwp.
 1.2 14-Jul-2003  lukem branches: 1.2.16;
__KERNEL_RCSID()
 1.1 11-May-2003  fvdl branches: 1.1.2;
Empty sleep stub function.
 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.2.16.1 21-Jan-2008  yamt sync with head
 1.3.62.1 11-Dec-2007  yamt sync with head.
 1.3.60.1 26-Dec-2007  ad Sync with head.
 1.3.56.1 27-Dec-2007  mjf Sync with HEAD.
 1.3.50.1 23-Mar-2008  matt sync with HEAD
 1.3.48.23 23-Nov-2007  joerg Exploit that PAE support implies PSE support and simplify the low-level
wake code to just load some useful values for cr0 and cr4 similiar to
what locore.S does. Load the real GDT from acpi_md_sleep_exit as well.
 1.3.48.22 14-Nov-2007  joerg Fix resume order for LAPIC, following ad@ changes to cpu_hatch.
 1.3.48.21 11-Nov-2007  joerg Change code flow below acpi_md_sleep.

Before:
- acpi_md_sleep calls acpi_savecpu
- acpi_savecpu saves registers and returns with -1
- acpi_md_sleep now patches the wakecode and calls AcpiEnterSleepState
- on resume, acpi_restorecpu restores registers and returns at the same
place as acpi_savecpu did with 0.

After:
- acpi_md_sleep calls acpi_md_sleep_prepare
- acpi_md_sleep_prepare saves registers and calls acpi_md_sleep_enter
- acpi_md_sleep_enter patches the wakecode and calls
AcpiEnterSleepState. It only returns on error.
- on resume, acpi_md_sleep_exit gets called, restores the registers and
returns as acpi_md_sleep_prepare with 0.
 1.3.48.20 28-Oct-2007  joerg Force FPU context to be saved on suspend.

XXX not sure if the splipi is really needed, but other callers do that.
 1.3.48.19 28-Oct-2007  joerg Make the reset of FS/GS base in cpu_init_msrs optional. We don't want
that in the ACPI resume path.
 1.3.48.18 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.3.48.17 13-Oct-2007  joerg Explicitly commit MTRR settings again on resume. This fixes abysmal
performance of Xorg e.g. during video playback.
 1.3.48.16 13-Oct-2007  joerg Move ACPI_EVENT_POWER_BUTTON reset into acpi_md_sleep. Add splhigh
guards around the x86_disable_intr/x86_enable_intr calls for the moment
until it is clear where the interrupts are incorrectly reenabled.
 1.3.48.15 02-Oct-2007  joerg Sync with HEAD.
 1.3.48.14 30-Sep-2007  joerg Add a second function ioapic_reenable that restores all vectors.
 1.3.48.13 25-Sep-2007  joerg Actually update the pmap after entering the ACPI wakecode page.
 1.3.48.12 25-Sep-2007  joerg ...and make the second copy actually syntactically correct.
 1.3.48.11 25-Sep-2007  joerg Use the conditional version of the primary CPU check.
 1.3.48.10 25-Sep-2007  jmcneill No need to check curcpu() twice.
 1.3.48.9 25-Sep-2007  joerg Explicitly initialise all MSRs. This allows a Dell Optiplex to resume
and ping my system.
 1.3.48.8 10-Sep-2007  joerg Remove unused cr3 label. Make optimiser less aggressive by telling it
that acpi_savecpu can return more than once...
 1.3.48.7 10-Sep-2007  jmcneill Restore machdep.acpi_vbios_reset's default to 1.
 1.3.48.6 10-Sep-2007  joerg Add work-in-progress remerge of i386 changes for the ACPI wakecode
and changes to adopt it to AMD64.
 1.3.48.5 09-Sep-2007  jmcneill Un-break amd64 acpi_md_sleep.
 1.3.48.4 08-Sep-2007  joerg Catch up with i386 and fix the build of GENERIC.
 1.3.48.3 08-Sep-2007  joerg Start to revamp the ACPI wake code (i386 only, amd64 gets minimal fixes
to keep being compilable):

- In init386 and the amd64 equivalent, just reserve the low-level code.
Do not map and don't copy the wakecode yet. This avoids the conflicts
with the MP tramp code as well. The wakecode is expected to be less
than one page long, which is way too much space.
acpi_md_get_npages_of_wakecode and acpi_md_install_wakecode are
dropped, acpi_wakeup_paddr is set instead of the reserved address.
- Split the wakecode into the essential low-level part to setup
protected mode with paging and valid CS and DS (which stays as
wakecode) and the rest. Inline beepon and beepoff as they are used
exactly once.
- Split the acpi_restorecpu and acpi_savecpu assembly from apci_wakeup.c
and merge acpi_restorecpu with the second half dropped from wakecode.
Most registers are not exported, just those needed to be patched into
wakecode. Don't bother to save or restore %eax, it is overriden
anyway.
- Don't bother to save and restore eflags in acpi_md_sleep, they are
handled correctly by the assembly. Don't play games with cr3 either,
we modify the pmap of the running processes. Copy the wakecode
directly before patching it, after the identity mapping has been
setup.
- Drop clear_reg and acpi_printcpu.
- Add an commented out broadcast IPI to halt the other CPUs explicitly.
 1.3.48.2 07-Sep-2007  jmcneill Share ACPI wakecode generation between i386 and amd64, and convert amd64
to use joerg's new build scripts for generating wakecode.
 1.3.48.1 06-Sep-2007  jmcneill Add work-in-progress amd64 wakecode. Doesn't yet reach long mode..
 1.4.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.10 14-Jul-2018  maxv Drop NENTRY() from the x86 kernels, use ENTRY(). With PMCs (and other hardware
tracing facilities) we have a much better ways of monitoring the CPU activity
than GPROF, without software modification.

Also I think GPROF has never worked, because the 'start' functions of both
i386 and amd64 use ENTRY(), and it would have caused a function call while the
kernel was not yet relocated.
 1.9 01-Nov-2017  maxv branches: 1.9.2; 1.9.4;
Use NENTRY -> END.
 1.8 21-Oct-2017  maxv Improve our segregs model. Pass 3/3.

Treat %gs the same way we treat %ds/%es/%fs: restore it in INTRFASTEXIT
on 32bit LWPs.

On Xen however, its behavior does not change, because we need to do an
hypercall before INTR_RESTORE_GPRS, and that's too complicated for now.

As a side effect, this change fixes a bug in the ACPI wakeup code; %fs/%gs
were not restored on 32bit LWPs, and chances are they would segfault
shortly afterwards.

Support for USER_LDT on amd64 is almost complete now.
 1.7 19-Oct-2017  maxv Improve our segregs model. Pass 1/3.

Right now, we are saving and restoring %ds/%es each time we enter/leave the
kernel. However, we let %fs/%gs live in the kernel space, and we rely on
the fact that when switching to an LWP, %fs/%gs are set right away (via
cpu_switchto or setregs).

It has two drawbacks: we are taking care of %ds/%es while they are
deprecated (useless) on 64bit LWPs, and we are restricting %fs/%gs while
they still have a meaning on 32bit LWPs.

Therefore, handle 32bit and 64bit LWPs differently:
* 64bit LWPs use fixed segregs, which are not taken care of.
* 32bit LWPs have dynamic segregs, always saved/restored.

For now, only %ds and %es are changed; %fs and %gs will be in the next
passes.

The trapframe is constructed as usual. In INTRFASTEXIT, we restore %ds/%es
depending on the %cs value. If %cs contains one of the two standard 64bit
selectors, don't do anything. Otherwise, restore everything.

When doing a context switch, just restore %ds/%es to their default values.
On a 32bit LWP they will be overwritten by INTRFASTEXIT; on a 64bit LWP
they won't be updated.

In the ACPI wakeup code, restore %ds/%es to the default 64bit user value.
 1.6 23-Sep-2017  maxv Make sure %edx is clear.
 1.5 24-Jul-2016  maxv KNF, and reduce the diff between amd64 and i386.
 1.4 11-May-2008  ad branches: 1.4.42; 1.4.62; 1.4.66;
Share cpu.h between the x86 ports.
 1.3 18-Dec-2007  joerg branches: 1.3.2; 1.3.4; 1.3.10; 1.3.12; 1.3.14; 1.3.16;
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.2 09-Dec-2007  jmcneill branches: 1.2.2;
Merge jmcneill-pm branch.
 1.1 10-Sep-2007  joerg branches: 1.1.2; 1.1.8; 1.1.10; 1.1.12;
file acpi_wakeup_low.S was initially added on branch jmcneill-pm.
 1.1.12.1 11-Dec-2007  yamt sync with head.
 1.1.10.1 26-Dec-2007  ad Sync with head.
 1.1.8.1 27-Dec-2007  mjf Sync with HEAD.
 1.1.2.13 23-Nov-2007  joerg Exploit that PAE support implies PSE support and simplify the low-level
wake code to just load some useful values for cr0 and cr4 similiar to
what locore.S does. Load the real GDT from acpi_md_sleep_exit as well.
 1.1.2.12 12-Nov-2007  joerg Don't save and restore registers that are not necessary to be preserved
in the amd64 ABI.
 1.1.2.11 11-Nov-2007  joerg Use $-1 and not -1 for the return path.
 1.1.2.10 11-Nov-2007  joerg Also update name in .type to match the label.
 1.1.2.9 11-Nov-2007  joerg Change code flow below acpi_md_sleep.

Before:
- acpi_md_sleep calls acpi_savecpu
- acpi_savecpu saves registers and returns with -1
- acpi_md_sleep now patches the wakecode and calls AcpiEnterSleepState
- on resume, acpi_restorecpu restores registers and returns at the same
place as acpi_savecpu did with 0.

After:
- acpi_md_sleep calls acpi_md_sleep_prepare
- acpi_md_sleep_prepare saves registers and calls acpi_md_sleep_enter
- acpi_md_sleep_enter patches the wakecode and calls
AcpiEnterSleepState. It only returns on error.
- on resume, acpi_md_sleep_exit gets called, restores the registers and
returns as acpi_md_sleep_prepare with 0.
 1.1.2.8 06-Nov-2007  joerg Add newline at end of file.
 1.1.2.7 29-Oct-2007  joerg Save and restore MSR_EFER explicitly as the NOX bit is needed for
manipulation of the GDT. With that ltr and lldt can finally be done and
AMD64 fully resume now.
 1.1.2.6 28-Oct-2007  joerg Save kernelgsbase and gsbase directly instead of playing with swapgs.
 1.1.2.5 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.1.2.4 28-Sep-2007  joerg Don't try to save and restore fs and gs, just zero them on resume.
 1.1.2.3 25-Sep-2007  joerg Save and restore FS and GS base.
 1.1.2.2 10-Sep-2007  jmcneill Restore cr0 and cr8 while we're here.
 1.1.2.1 10-Sep-2007  joerg Add work-in-progress remerge of i386 changes for the ACPI wakecode
and changes to adopt it to AMD64.
 1.2.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.3.16.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.3.14.1 16-May-2008  yamt sync with head.
 1.3.12.1 18-May-2008  yamt sync with head.
 1.3.10.1 02-Jun-2008  mjf Sync with HEAD.
 1.3.4.2 21-Jan-2008  yamt sync with head
 1.3.4.1 18-Dec-2007  yamt file acpi_wakeup_low.S was added on branch yamt-lazymbuf on 2008-01-21 09:35:13 +0000
 1.3.2.2 09-Jan-2008  matt sync with HEAD
 1.3.2.1 18-Dec-2007  matt file acpi_wakeup_low.S was added on branch matt-armv6 on 2008-01-09 01:44:41 +0000
 1.4.66.1 26-Jul-2016  pgoyette Sync with HEAD
 1.4.62.1 05-Oct-2016  skrll Sync with HEAD
 1.4.42.1 03-Dec-2017  jdolecek update from HEAD
 1.9.4.1 10-Jun-2019  christos Sync with HEAD
 1.9.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.1 06-Sep-2007  jmcneill branches: 1.1.2;
file genwakecode.sh was initially added on branch jmcneill-pm.
 1.1.2.3 24-Sep-2007  joerg Generate the ACPI wakecode image dynamically at build time.
 1.1.2.2 07-Sep-2007  jmcneill Share ACPI wakecode generation between i386 and amd64, and convert amd64
to use joerg's new build scripts for generating wakecode.
 1.1.2.1 06-Sep-2007  jmcneill Add work-in-progress amd64 wakecode. Doesn't yet reach long mode..
 1.13 20-Oct-2025  thorpej Revert an inadvertent bit of v 1.12
 1.12 19-Oct-2025  thorpej G/C amd64_mainbus_print(); nothing uses it.
 1.11 19-Oct-2025  thorpej Use {,e}isabus_attach().
 1.10 08-Jul-2025  imil Rename pvbus component to pv to allow conditional NPV define

pvbus is always defined in files.pv, which prevents the use of
#if NPVBUS > 0. Renaming it to pv aligns with naming conventions used
for other bus components and allows NPV to be conditionally defined.
 1.9 02-May-2025  imil Allow NVMM to use pv(4) bus
 1.8 02-Jan-2025  imil Trivial bus implementation inspired by OpenBSD's pv(4) to attach devices
that don't need nor rely on a PCI or ISA bus.
 1.7 07-Aug-2021  thorpej branches: 1.7.12;
Merge thorpej-cfargs2.
 1.6 24-Apr-2021  thorpej branches: 1.6.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.5 14-Feb-2019  cherry branches: 1.5.4; 1.5.16;
Fix NLAPIC, NISA and NIOAPIC related conditional compile errors.

This will allow us to now compile an amd64 kernel without PCI.

No functional changes.
 1.4 22-Dec-2018  maxv branches: 1.4.2;
Style, once again.
 1.3 22-Dec-2018  cherry This change modifies the mainbus(4) entry point for all x86 sub-archs
in the following way:

i) It provides a unified entry point in
x86/x86/mainbus.c:mainbus_attach()
ii) It carves out the preliminary bus attachment sequence that is
common to all sub-archs into
x86/x86/mainbus.c: x86_cpubus_attach()
iii) It consolidates the remaining pathways as internal callee
functions so that these may be called piecemeal if required. A
special usecase of this is XEN PVHVM which may need to call the
native configure path, the xen configure path, or both.
iv) It moves the driver private data structures from
i386/i386_mainbus.c to an x86/ level one. This allows for other
sub-arch's to do similar, if needed. (They do not at the moment).
v) For dom0 kernels, it enables 'acpi0 at mainbus?' and
'acpi0 at hypervisorbus'. This serves two purposes:
a) To demonstrate the possibility of dynamic configuration tree
traversal ordering changes.
b) To allow for the common acpi_check(self, "acpibus") call in
x86/mainbus.c to not barf when it is called from the dom0 attach
path. We allow for the acpi0 device to be a child of mainbus with
the changes to amd64/conf/XEN3_DOM0 and i386/conf/XEN3PAE_DOM0
without actually probing further in the code. This path will later
be pursued in a PVHVM boot codepath.

There should be no operative changes with this change. If there are,
please complain loudly.
 1.2 22-Dec-2018  cherry Don't forget pedigree. Re-introduce old RCS Id tags from the originals
 1.1 22-Dec-2018  cherry Move mainbus(4) driver files in various x86 sub-archs to name prefixed
versions. This allows us to further modularise them by unifying common
bus probe code in x86/x86/mainbus.c to be introduced next.

This commit has no functional changes. It is done for ease of
visibility of newer diffs in the queue.
 1.4.2.2 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.4.2.1 22-Dec-2018  pgoyette file amd64_mainbus.c was added on branch pgoyette-compat on 2018-12-26 14:01:31 +0000
 1.5.16.1 02-Apr-2021  thorpej config_found_ia() -> config_found() w/ CFARG_IATTR.
 1.5.4.2 10-Jun-2019  christos Sync with HEAD
 1.5.4.1 14-Feb-2019  christos file amd64_mainbus.c was added on branch phil-wifi on 2019-06-10 22:05:46 +0000
 1.6.8.1 03-Aug-2021  thorpej Adapt to CFARGS().
 1.7.12.1 02-Aug-2025  perseant Sync with HEAD
 1.55 27-Feb-2023  riastradh amd64_trap.S: Annotate trap vectors with their mnemonics.

Derived from Intel and AMD manuals.

Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 3
(3A, 3B, 3C, & 3D: System Programming Guide, Order Number:
325384-077US, April 2022.
https://cdrdv2.intel.com/v1/dl/getContent/671447

AMD64 Technology: AMD64 Architecture Programmers' Manual, Volume 2:
System Programming, Publication No. 24953, Revision 3.40, January 2023.
https://www.amd.com/system/files/TechDocs/24593.pdf

No functional change intended.

XXX Should apply the same treatment to i386_trap.S.
 1.54 07-Sep-2022  knakahara branches: 1.54.4;
NetBSD/x86: Raise the number of interrupt sources per CPU from 32 to 56.

There has been no objection for three years.
https://mail-index.netbsd.org/port-amd64/2019/09/22/msg003012.html
Implemented by nonaka@n.o, updated by me.
 1.53 29-Jun-2020  riastradh Nix trailing whitespace.
 1.52 21-Jun-2020  bouyer On amd64, Xen PV calls syscalls and traps with events enabled.
Disable events on entry to be safe.
It should have been mostly safe for most cases, but for FPU traps
we need to reload the FPU state if we got interrupted at trap entry.

Hopefully fixes:
panic: kernel diagnostic assertion "curlwp->l_md.md_flags & MDL_FPU_IN_CPU" failed: file "/home/source/ab/HEAD/src/sys/arch/x86/x86/fpu.c", line 524

when running tests.
 1.51 07-Dec-2019  maxv Panic instead of printf, same as syscall.
 1.50 14-Nov-2019  maxv Add support for Kernel Memory Sanitizer (kMSan). It detects uninitialized
memory used by the kernel at run time, and just like kASan and kCSan, it
is an excellent feature. It has already detected 38 uninitialized variables
in the kernel during my testing, which I have since discreetly fixed.

We use two shadows:
- "shad", to track uninitialized memory with a bit granularity (1:1).
Each bit set to 1 in the shad corresponds to one uninitialized bit of
real kernel memory.
- "orig", to track the origin of the memory with a 4-byte granularity
(1:1). Each uint32_t cell in the orig indicates the origin of the
associated uint32_t of real kernel memory.

The memory consumption of these shadows is consequent, so at least 4GB of
RAM is recommended to run kMSan.

The compiler inserts calls to specific __msan_* functions on each memory
access, to manage both the shad and the orig and detect uninitialized
memory accesses that change the execution flow (like an "if" on an
uninitialized variable).

We mark as uninit several types of memory buffers (stack, pools, kmem,
malloc, uvm_km), and check each buffer passed to copyout, copyoutstr,
bwrite, if_transmit_lock and DMA operations, to detect uninitialized memory
that leaves the system. This allows us to detect kernel info leaks in a way
that is more efficient and also more user-friendly than KLEAK.

Contrary to kASan, kMSan requires comprehensive coverage, ie we cannot
tolerate having one non-instrumented function, because this could cause
false positives. kMSan cannot instrument ASM functions, so I converted
most of them to __asm__ inlines, which kMSan is able to instrument. Those
that remain receive special treatment.

Contrary to kASan again, kMSan uses a TLS, so we must context-switch this
TLS during interrupts. We use different contexts depending on the interrupt
level.

The orig tracks precisely the origin of a buffer. We use a special encoding
for the orig values, and pack together in each uint32_t cell of the orig:
- a code designating the type of memory (Stack, Pool, etc), and
- a compressed pointer, which points either (1) to a string containing
the name of the variable associated with the cell, or (2) to an area
in the kernel .text section which we resolve to a symbol name + offset.

This encoding allows us not to consume extra memory for associating
information with each cell, and produces a precise output, that can tell
for example the name of an uninitialized variable on the stack, the
function in which it was pushed on the stack, and the function where we
accessed this uninitialized variable.

kMSan is available with LLVM, but not with GCC.

The code is organized in a way that is similar to kASan and kCSan, so it
means that other architectures than amd64 can be supported.
 1.49 12-Oct-2019  maxv 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.48 18-May-2019  maxv Two changes in the CPU mitigations:

* Micro-optimize: put every mitigation in the same branch. This removes
two branches in each exc/int return path, and removes all branches in
the syscall return path.

* Modify the SpectreV2 mitigation to be compatible with SpectreV4. I
recently realized that both couldn't be enabled at the same time on
Intel. This is because initially, when there was just SpectreV2, we
could reset the whole IA32_SPEC_CTRL MSR. But then Intel added another
bit in it for SpectreV4, so it isn't right to reset it entirely
anymore. SSBD needs to stay.
 1.47 14-May-2019  maxv Mitigation for INTEL-SA-00233: Microarchitectural Data Sampling (MDS).

It requires a microcode update, now available on the Intel website. The
microcode modifies the behavior of the VERW instruction, and makes it flush
internal CPU buffers. We hotpatch the return-to-userland path to add VERW.

Two sysctls are added:

machdep.mds.mitigated = {0/1} user-settable
machdep.mds.method = {string} constructed by the kernel

The kernel will automatically enable the mitigation if the updated
microcode is present. If the new microcode is not present, the user can
load it via cpuctl, and set machdep.mds.mitigated=1.
 1.46 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.45 12-Aug-2018  maxv Eliminate the only ASM reference to VM_MIN_KERNEL_ADDRESS. Rename the
value to VM_SPACE_SEP_HIGH32, it is now the highest 32bits of the first
va of the higher half of the address space (right after the canonical
hole).
 1.44 14-Jul-2018  maxv Drop NENTRY() from the x86 kernels, use ENTRY(). With PMCs (and other hardware
tracing facilities) we have a much better ways of monitoring the CPU activity
than GPROF, without software modification.

Also I think GPROF has never worked, because the 'start' functions of both
i386 and amd64 use ENTRY(), and it would have caused a function call while the
kernel was not yet relocated.
 1.43 12-Jul-2018  maxv Handle NMIs correctly when SVS is enabled. We store the kernel's CR3 at the
top of the NMI stack, and we unconditionally switch to it, because we don't
know with which page tables we received the NMI. Hotpatch the whole thing as
usual.

This restores the ability to use PMCs on Intel CPUs.
 1.42 25-May-2018  maxv branches: 1.42.2;
When the previous contrext is in kernel mode we are not guaranteed to have
a 16-byte-aligned stack pointer, so align it. That's what the CPU would do
on exception entry.
 1.41 08-May-2018  maxv Mitigation for the SS bug, CVE-2018-8897. We disabled dbregs a month ago
in -current and -8 so we are not particularly affected anymore.

The #DB handler runs on ist3, if we decide to process the exception we
copy the iret frame on the correct non-ist stack and continue as usual.
 1.40 28-Mar-2018  maxv Add the IBRS mitigation for SpectreV2 on amd64.

Different operations are performed during context transitions:

user->kernel: IBRS <- 1
kernel->user: IBRS <- 0

And during context switches:

user->user: IBPB <- 0
kernel->user: IBPB <- 0
[user->kernel:IBPB <- 0 this one may not be needed]

We use two macros, IBRS_ENTER and IBRS_LEAVE, to set the IBRS bit. The
thing is hotpatched for better performance, like SVS.

The idea is that IBRS is a "privileged" bit, which is set to 1 in kernel
mode and 0 in user mode. To protect the branch predictor between user
processes (which are of the same privilege), we use the IBPB barrier.

The Intel manual also talks about (MWAIT/HLT)+HyperThreading, and says
that when using either of the two instructions IBRS must be disabled for
better performance on the core. I'm not totally sure about this part, so
I'm not adding it now.

IBRS is available only when the Intel microcode update is applied. The
mitigation must be enabled manually with machdep.spectreV2.mitigated.

Tested by msaitoh a week ago (but I adapted a few things since). Probably
more changes to come.
 1.39 20-Mar-2018  maxv (Re)Fix handling of segment register faults. My previous attempt did fix
faults occuring when reloading %es/%ds/%fs/%gs, but it did not fix faults
occuring when executing 'iretq', because before iretq we needed to do +16
in %rsp, and the resulting stack layout was not the one kernuser_reenter()
expected (tf_trapno and tf_err were not there).

So now: pop tf_trapno and tf_err right away in intrfastexit(), and update
the layout in kernuser_reenter() accordingly. The resulting code is
actually simpler.

Tested by "hardcoding" an iretq fault; the process correctly receives a
SIGSEGV.

(Note that segment register faults do not happen in the wild, you really
need to try hard to trigger one.)
 1.38 20-Mar-2018  maxv Remove the sysretq fault handler. It is broken with SVS, and not really
needed anyway. Initially I had added it so that if such a fault was
received the kernel would panic "cleanly" instead of crashing in a
potentially undefined way.

I'll re-add this handler later.
 1.37 25-Feb-2018  maxv branches: 1.37.2;
Fix handling of segment register faults when running with SVS. The behavior
is changed also in the non-SVS case.

I've put a documentation in amd64_trap.S. Basically, the problem with SVS
is that if iret faults, we already have a full trapframe pushed on the
stack and the CPU will push another frame on this stack (nested), but it
hits the redzone below the stack since it is still running with the user
page table loaded.

To fix that, we pop a good part of the trapframe earlier in intrfastexit.
If iret faults, the current %rsp has enough room for an iret frame, and
the CPU can push that without problem. We then switch back to the outer
iret frame (the frame the CPU was trying to pop by executing iret, but that
it didn't pop for real because iret faulted), call INTRENTRY, and handle
the trap as if it had been received from userland directly.
 1.36 25-Feb-2018  maxv Ah. Don't use NENTRY() to declare check_swapgs, use LABEL() instead. NENTRY
puts the code in the .text section, so the effect of TEXT_USER_BEGIN was
overwritten, and check_swapgs was not put in the .text.user section.

As a result kernels running SVS would crash when jumping here - because we
execute this place with the user page table loaded, and in this page table
only .text.user is mapped.

While here, rename check_swapgs -> kernuser_reenter, because we do more
things than just SWAPGS.
 1.35 25-Feb-2018  maxv Replace %rax -> %rdi, so that check_swapgs clobbers only one register.
 1.34 25-Feb-2018  maxv There are two places where we reload %gs:

* In setusergs. Here we can't fault. So we don't need to handle this
case.

* In intrfastexit for 32bit processes. This case needs to be handled,
and we already have a label.

So use the label instead of disassembling %rip.
 1.33 22-Feb-2018  maxv Revert all my latest changes, and restore this file back to how it was
in rev1.24. I wanted to replace the functions dynamically for SVS, but
that was a dumb idea, we'll just hotpatch instead.
 1.32 18-Feb-2018  maxv Pass the name of the function as argument in SWAPGS_HANDLER.
 1.31 17-Feb-2018  maxv Declare check_swapgs in an ASM macro. No real functional change.
 1.30 17-Feb-2018  maxv Use ASM macros for the rest of the entry points. No real functional
change. Now the format of the entry points is:

.macro TRAP_ENTRY_POINT_xx arg1,arg2,arg3
...the asm code...
.endm

TEXT_USER_BEGIN
TRAP_ENTRY_POINT_xx arg1,arg2,arg3
TEXT_USER_END
 1.29 17-Feb-2018  maxv Declare and use TRAP_ENTRY_POINT_DNA. This time we don't give an is_ztrap
argument, because the macro is tied to the entry point, and it would be
wrong to suggest the paramater is controllable. No real functional change.
 1.28 17-Feb-2018  maxv Now that [Z]TRAP and [Z]TRAP_NJ are identical, put back the

INTRENTRY
jmp .Lalltraps_noentry

instructions for Xen, and remove [Z]TRAP_NJ.
 1.27 17-Feb-2018  maxv Declare and use TRAP_ENTRY_POINT_SPUR. No real functional change.
 1.26 17-Feb-2018  maxv Declare and use TRAP_ENTRY_POINT_FPU. No real functional change.
 1.25 17-Feb-2018  maxv Start using ASM macros to define the trap entry points. No real functional
change.
 1.24 09-Feb-2018  maxv Don't restore segment registers when leaving NMIs. In nmitrap (and the
functions it later calls), we are not allowing the trap frame to change;
so the segregs don't change since we are running with interrupts disabled
and there is no rescheduling in this case.
 1.23 21-Jan-2018  maxv Unmap the kernel from userland in SVS, and leave only the needed
trampolines. As explained below, SVS should now completely mitigate
Meltdown on GENERIC kernels, even though it needs some more tweaking
for GENERIC_KASLR.

Until now the kernel entry points looked like:

FUNC(intr)
pushq $ERR
pushq $TRAPNO
INTRENTRY
... handle interrupt ...
INTRFASTEXIT
END(intr)

With this change they are split and become:

FUNC(handle)
... handle interrupt ...
INTRFASTEXIT
END(handle)

TEXT_USER_BEGIN
FUNC(intr)
pushq $ERR
pushq $TRAPNO
INTRENTRY
jmp handle
END(intr)
TEXT_USER_END

A new section is introduced, .text.user, that contains minimal kernel
entry/exit points. In order to choose what to put in this section, two
macros are introduced, TEXT_USER_BEGIN and TEXT_USER_END.

The section is mapped in userland with normal 4K pages.

In GENERIC, the section is 4K-page-aligned and embedded in .text, which
is mapped with large pages. That is to say, when an interrupt comes in,
the CPU has the user page tables loaded and executes the 'intr' functions
on 4K pages; after calling SVS_ENTER (in INTRENTRY) these 4K pages become
2MB large pages, and remain so when executing in kernel mode.

In GENERIC_KASLR, the section is 4K-page-aligned and independent from the
other kernel texts. The prekern just picks it up and maps it at a random
address.

In GENERIC, SVS should now completely mitigate Meltdown: what we put in
.text.user is not secret.

In GENERIC_KASLR, SVS would have to be improved a bit more: the
'jmp handle' instruction is actually secret, since it leaks the address
of the section we are jumping into. By exploiting Meltdown on Intel, this
theoretically allows a local user to reconstruct the address of the first
text section. But given that our KASLR produces several texts, and that
each section is not correlated with the others, the level of protection
KASLR provides is still good.
 1.22 20-Jan-2018  maxv Compile amd64_trap.S as a file instead of including it.
 1.21 20-Jan-2018  maxv Eliminate a '.text'.
 1.20 20-Jan-2018  maxv Don't declare exceptions[] with IDTVEC, it's an array, not a function.
Rename it to x86_exceptions[], and move it to .rodata.
 1.19 20-Jan-2018  maxv Fix the double-fault handler. We're executing on ist1 and must not jump
out of it, so don't enable interrupts. And use the SVS_*_ALTSTACK macros.

While here, fix the NMI handler too: it should use SVS_LEAVE_ALTSTACK.
 1.18 18-Jan-2018  maxv Unmap the kernel heap from the user page tables (SVS).

This implementation is optimized and organized in such a way that we
don't need to copy the kernel stack to a safe place during user<->kernel
transitions. We create two VAs that point to the same physical page; one
will be mapped in userland and is offset in order to contain only the
trapframe, the other is mapped in the kernel and maps the entire stack.

Sent on tech-kern@ a week ago.
 1.17 07-Jan-2018  maxv Add a new option, SVS (for Separate Virtual Space), that unmaps kernel
pages when running in userland. For now, only the PTE area is unmapped.

Sent on tech-kern@.
 1.16 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.15 06-Jan-2018  maxv Mmh, I made a mistake in r1.10 - I forgot to update this function call.
 1.14 02-Jan-2018  maxv Use decimal numbering - hex is just misleading -, use ZTRAP_NJ for NMIs,
and declare intrspurious independently.
 1.13 26-Nov-2017  maxv Hide a bunch of raw symbols.
 1.12 17-Oct-2017  maxv Have the cpu clear PSL_D automatically when entering the kernel via a
syscall. Then, don't clear PSL_D and PSL_AC in the syscall entry point,
they are now both cleared by the cpu (faster). However they still need to
be manually cleared in the interrupt/trap entry points.
 1.11 15-Sep-2017  maxv Declare INTRFASTEXIT as a function, so that there is only one iretq in the
kernel. Then, check %rip against the address of this iretq instead of
disassembling (%rip) - which could fault again, or point at some random
address which happens to contain the iretq opcode. The same is true for gs
below, but I'll fix that in another commit.
 1.10 03-Sep-2017  maxv Remove useless debug code, and split trap() into smaller functions, easier
to understand. NMIs take another, faster path now. No functional change
beyond that.
 1.9 31-Aug-2017  maxv Add a layer of mitigation against the intel sysret vuln: restore %gs when
sysretq faults. Right now we try to make sure that %rip is canonical by
performing sanity checks in several places, but I've already found missing
checks two times already, and there may be others.

By performing an additional swapgs here, we are turning ring0 exploits to
simple DoSes - which are still security bugs, but of a lower impact.
 1.8 31-Aug-2017  maxv Reorder for clarity, and style.
 1.7 18-Aug-2017  maxv Revert my previous change. I hadn't checked carefully enough: the
symbols are used in src/external. There is a number of things that seem
wrong to me here, but I'm not changing them for now.
 1.6 18-Aug-2017  maxv Remove unused and broken code. On amd64 we won't want int3 from kernel
mode to be valid.
 1.5 24-Mar-2017  maxv branches: 1.5.6;
Unconditionnally save the segment registers - because we could have a
kernel %gs and a userland %es/%ds -, and explain why T_NMI is a special
case.

Note that checking %gs directly is not a good idea: recent CPUs have the
FSGSBASE instruction set, which allows userland to directly modify %gs
without going through the kernel. If we ever enable this set, we will have
to change this function, since we won't be able to test %gs against
VM_MIN_KERNEL_ADDRESS anymore.
 1.4 07-Aug-2016  maxv branches: 1.4.2;
Explain a little.
 1.3 22-Nov-2015  maxv branches: 1.3.2;
KNF a bit, so I don't get scared each time I open a file
 1.2 12-Feb-2014  dsl branches: 1.2.4; 1.2.8; 1.2.10;
Change the argument to fpudna() to be the trapframe.
Move the checks for fpu traps in kernel into x86/fpu.c.
Remove the code from amd64/trap.c related to fpu traps (they've not gone
there for ages - expect to panic in kernel mode).
In fpudna():
- Don't actually enable hardware interrupts unless we need to
allow in IPIs.
- There is no point in enabling them when they are blocked in software
(by splhigh()).
- Keep the splhigh() to avoid a load of the KASSERTS() firing.
 1.1 25-Jun-2013  uebayasi branches: 1.1.2;
Split these to improve diffability.
 1.1.2.1 18-May-2014  rmind sync with head
 1.2.10.3 28-Aug-2017  skrll Sync with HEAD
 1.2.10.2 05-Oct-2016  skrll Sync with HEAD
 1.2.10.1 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.2.8.3 03-Dec-2017  jdolecek update from HEAD
 1.2.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.8.1 12-Feb-2014  tls file amd64_trap.S was added on branch tls-maxphys on 2014-08-20 00:02:42 +0000
 1.2.4.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.2.4.1 12-Feb-2014  yamt file amd64_trap.S was added on branch yamt-pagecache on 2014-05-22 11:39:28 +0000
 1.3.2.1 26-Apr-2017  pgoyette Sync with HEAD
 1.4.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.5.6.4 14-May-2019  martin Pull up following revision(s) (requested by maxv in ticket #1269):

sys/arch/amd64/amd64/locore.S: revision 1.181 (adapted)
sys/arch/amd64/amd64/amd64_trap.S: revision 1.47 (adapted)
sys/arch/x86/include/specialreg.h: revision 1.144 (adapted)
sys/arch/amd64/include/frameasm.h: revision 1.43 (adapted)
sys/arch/x86/x86/spectre.c: revision 1.27 (adapted)

Mitigation for INTEL-SA-00233: Microarchitectural Data Sampling (MDS).
It requires a microcode update, now available on the Intel website. The
microcode modifies the behavior of the VERW instruction, and makes it flush
internal CPU buffers. We hotpatch the return-to-userland path to add VERW.

Two sysctls are added:

machdep.mds.mitigated = {0/1} user-settable
machdep.mds.method = {string} constructed by the kernel

The kernel will automatically enable the mitigation if the updated
microcode is present. If the new microcode is not present, the user can
load it via cpuctl, and set machdep.mds.mitigated=1.
 1.5.6.3 14-Apr-2018  martin Pullup the following revisions via patch, requested by maxv in ticket #748:

sys/arch/amd64/amd64/copy.S 1.29 (adapted, via patch)
sys/arch/amd64/amd64/amd64_trap.S 1.16,1.19 (partial) (via patch)
sys/arch/amd64/amd64/trap.c 1.102,1.106 (partial),1.110 (via patch)
sys/arch/amd64/include/frameasm.h 1.22,1.24 (via patch)
sys/arch/x86/x86/cpu.c 1.137 (via patch)
sys/arch/x86/x86/patch.c 1.23,1.26 (partial) (via patch)

Backport of SMAP support.
 1.5.6.2 22-Mar-2018  martin Pull up the following revisions, requested by maxv in ticket #652:

sys/arch/amd64/amd64/amd64_trap.S upto 1.39 (partial, patch)
sys/arch/amd64/amd64/db_machdep.c 1.6 (patch)
sys/arch/amd64/amd64/genassym.cf 1.65,1.66,1.67 (patch)
sys/arch/amd64/amd64/locore.S upto 1.159 (partial, patch)
sys/arch/amd64/amd64/machdep.c 1.299-1.302 (patch)
sys/arch/amd64/amd64/trap.c upto 1.113 (partial, patch)
sys/arch/amd64/amd64/amd64/vector.S upto 1.61 (partial, patch)
sys/arch/amd64/conf/GENERIC 1.477,1.478 (patch)
sys/arch/amd64/conf/kern.ldscript 1.26 (patch)
sys/arch/amd64/include/frameasm.h upto 1.37 (partial, patch)
sys/arch/amd64/include/param.h 1.25 (patch)
sys/arch/amd64/include/pmap.h 1.41,1.43,1.44 (patch)
sys/arch/x86/conf/files.x86 1.91,1.93 (patch)
sys/arch/x86/include/cpu.h 1.88,1.89 (patch)
sys/arch/x86/include/pmap.h 1.75 (patch)
sys/arch/x86/x86/cpu.c 1.144,1.146,1.148,1.149 (patch)
sys/arch/x86/x86/pmap.c upto 1.289 (partial, patch)
sys/arch/x86/x86/vm_machdep.c 1.31,1.32 (patch)
sys/arch/x86/x86/x86_machdep.c 1.104,1.106,1.108 (patch)
sys/arch/x86/x86/svs.c 1.1-1.14
sys/arch/xen/conf/files.compat 1.30 (patch)

Backport SVS. Not enabled yet.
 1.5.6.1 07-Mar-2018  martin Pull up the following revisions (via patch), requested by maxv in ticket #610:

sys/arch/amd64/amd64/amd64_trap.S 1.8,1.10,1.12 (partial),1.13-1.15,
1.19 (partial),1.20,1.21,1.22,1.24
(via patch)
sys/arch/amd64/amd64/locore.S 1.129 (partial),1.132 (via patch)
sys/arch/amd64/amd64/trap.c 1.97 (partial),1.111 (via patch)
sys/arch/amd64/amd64/vector.S 1.54,1.55 (via patch)
sys/arch/amd64/include/frameasm.h 1.21,1.23 (via patch)
sys/arch/x86/x86/cpu.c 1.138 (via patch)
sys/arch/xen/conf/Makefile.xen 1.45 (via patch)

Rename and reorder several things in amd64_trap.S.
Compile amd64_trap.S as a file.
Introduce nmitrap and doubletrap.
Have the CPU clear PSL_D automatically in the syscall entry point.
 1.37.2.6 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.37.2.5 28-Jul-2018  pgoyette Sync with HEAD
 1.37.2.4 25-Jun-2018  pgoyette Sync with HEAD
 1.37.2.3 21-May-2018  pgoyette Sync with HEAD
 1.37.2.2 30-Mar-2018  pgoyette Resolve conflicts between branch and HEAD
 1.37.2.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.42.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.42.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.42.2.1 10-Jun-2019  christos Sync with HEAD
 1.54.4.1 20-Sep-2024  martin Pull up following revision(s) (requested by rin in ticket #876):

sys/arch/amd64/amd64/amd64_trap.S: revision 1.55

amd64_trap.S: Annotate trap vectors with their mnemonics.

Derived from Intel and AMD manuals.
Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 3
(3A, 3B, 3C, & 3D: System Programming Guide, Order Number:
325384-077US, April 2022.
https://cdrdv2.intel.com/v1/dl/getContent/671447

AMD64 Technology: AMD64 Architecture Programmers' Manual, Volume 2:
System Programming, Publication No. 24953, Revision 3.40, January 2023.
https://www.amd.com/system/files/TechDocs/24593.pdf

No functional change intended.
 1.8 07-Sep-2019  maxv Merge amd64func.S into cpufunc.S, and clean up.
 1.7 22-Jun-2013  uebayasi branches: 1.7.34;
Use END() to set ELF symbol size.
 1.6 10-May-2008  ad branches: 1.6.32; 1.6.42;
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.5 28-Apr-2008  martin branches: 1.5.2;
Remove clause 3 and 4 from TNF licenses
 1.4 27-Mar-2008  ad branches: 1.4.2; 1.4.4; 1.4.6;
Disable the fast tsc_get_timecount() for now. The divide can overflow
causing an exception.
 1.3 17-Mar-2008  ad branches: 1.3.2; 1.3.4;
Shave more cycles off tsc_get_timecount(). From dsl@
 1.2 11-Mar-2008  ad branches: 1.2.2;
tsc_get_timecount: remove unneeded instructions. Pointed out by dsl@.
 1.1 10-Mar-2008  ad Implement an optimized, preemption-safe asm version of tsc_get_timecount().
The C version needs work to be preemption safe. Cuts the clock cycles
for microtime() from 950 down to 300 on a Pentium D.
 1.2.2.3 24-Mar-2008  yamt sync with head.
 1.2.2.2 17-Mar-2008  yamt sync with head.
 1.2.2.1 11-Mar-2008  yamt file amd64func.S was added on branch yamt-lazymbuf on 2008-03-17 09:14:13 +0000
 1.3.4.2 24-Mar-2008  keiichi sync with head.
 1.3.4.1 17-Mar-2008  keiichi file amd64func.S was added on branch keiichi-mipv6 on 2008-03-24 07:14:52 +0000
 1.3.2.2 23-Mar-2008  matt sync with HEAD
 1.3.2.1 17-Mar-2008  matt file amd64func.S was added on branch matt-armv6 on 2008-03-23 02:03:52 +0000
 1.4.6.1 16-May-2008  yamt sync with head.
 1.4.4.1 18-May-2008  yamt sync with head.
 1.4.2.3 02-Jun-2008  mjf Sync with HEAD.
 1.4.2.2 03-Apr-2008  mjf Sync with HEAD.
 1.4.2.1 27-Mar-2008  mjf file amd64func.S was added on branch mjf-devfs2 on 2008-04-03 12:42:10 +0000
 1.5.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.6.42.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.6.32.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.7.34.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.11 31-Oct-2018  maxv Move the MI parts of KASAN into kern/subr_asan.c. This file includes
machine/asan.h, which contains the MD functions. We use an include rather
than a plain C file, because we want GCC to optimize/inline some functions
into one single block.

The amd64 MD parts of KASAN are moved accordingly.

The naming convention we use is:

kasan_*
a generic kasan object, declared in subr_asan.c
kasan_md_*
an MD kasan object, declared in machine/asan.h, and used
in subr_asan.c
__md_*
an MD object, declared in machine/asan.h, and not used
outside

Overall this makes it easier to add KASAN support on more architectures.

Discussed with several people.
 1.10 27-Oct-2018  maxv Rename kasan_shadow_fill, remove one check in it, and inline it. Remove
the use-after-scope code for now, because our GCC does not support that
and when it does we will want to test the feature for real rather than
letting a potentially broken code compile.
 1.9 27-Oct-2018  maxv Remove functions that aren't supposed to be used.
 1.8 24-Sep-2018  maxv Don't go beyond start().
 1.7 27-Aug-2018  maxv branches: 1.7.2;
Add kasan interceptors for strcpy/strcmp/strlen.
 1.6 23-Aug-2018  maxv Improve the detection on global variables, no need to round up.
 1.5 22-Aug-2018  maxv Unwind the stack on error, to get the full path that led to the illegal
access. Example of output:

kASan: Unauthorized Access In 0xffffffff80e6219c: Addr 0xffffbb007a39fd03 [1 byte, read]
#0 0xffffffff80e6219c in ras_purgeall <netbsd>
#1 0xffffffff80e62330 in sys_rasctl <netbsd>
#2 0xffffffff80265008 in syscall <netbsd>

(I manually added a one-byte stack read overflow in rasctl to demonstrate.)
 1.4 22-Aug-2018  maxv Explicitly unpoison the stack when entering a softint.

Softints are the only place where we "discard" a part of the stack: we may
have left the thread without allowing the asan instrumentation to clear
the poison, and in this case, we can get false positives when we hit a
poisoned area of the stack while executing another handler within the same
softint thread.

(I was actually getting a rare false positive in ip6intr.)
 1.3 22-Aug-2018  maxv Add support for monitoring the stack with kASan. This allows us to detect
illegal memory accesses occuring there.

The compiler inlines a piece of code in each function that adds redzones
around the local variables and poisons them. The illegal accesses are then
detected using the usual kASan machinery.

The stack size is doubled, from 4 pages to 8 pages.

Several boot functions are marked with the __noasan flag, to prevent the
compiler from adding redzones in them (because we haven't yet initialized
kASan). The kasan_early_init function is called early at boot time to
quickly create the shadow for the current stack; after this is done, we
don't need __noasan anymore in the boot path.

We pass -fasan-shadow-offset=0xDFFF900000000000, because the compiler
wants to do
shad = shadow-offset + (addr >> 3)
and we do, in kasan_addr_to_shad
shad = KASAN_SHADOW_START + ((addr - CANONICAL_BASE) >> 3)
hence
shad = KASAN_SHADOW_START + (addr >> 3) - (CANONICAL_BASE >> 3)
= [KASAN_SHADOW_START - (CANONICAL_BASE >> 3)] + (addr >> 3)
implies
shadow-offset = KASAN_SHADOW_START - (CANONICAL_BASE >> 3)
= 0xFFFF800000000000 - (0xFFFF800000000000 >> 3)
= 0xDFFF900000000000

In UVM, we add a kasan_free (that is not preceded by a kasan_alloc). We
don't add poisoned redzones ourselves, but all the functions we execute
do, so we need to manually clear the poison before freeing the stack.

With the help of Kamil for the makefile stuff.
 1.2 22-Aug-2018  maxv Fix the computation in kasan_shadow_map, we may need one more page because
of the rounddown.
 1.1 20-Aug-2018  maxv Add support for kASan on amd64. Written by me, with some parts inspired
from Siddharth Muralee's initial work. This feature can detect several
kinds of memory bugs, and it's an excellent feature.

It can be enabled by uncommenting these three lines in GENERIC:

#makeoptions KASAN=1 # Kernel Address Sanitizer
#options KASAN
#no options SVS

The kernel is compiled without SVS, without DMAP and without PCPU area.
A shadow area is created at boot time, and it can cover the upper 128TB
of the address space. This area is populated gradually as we allocate
memory. With this design the memory consumption is kept at its lowest
level.

The compiler calls the __asan_* functions each time a memory access is
done. We verify whether this access is legal by looking at the shadow
area.

We declare our own special memcpy/memset/etc functions, because the
compiler's builtins don't add the __asan_* instrumentation.

Initially all the mappings are marked as valid. During dynamic
allocations, we add a redzone, which we mark as invalid. Any access on
it will trigger a kASan error message. Additionally, the compiler adds
a redzone on global variables, and we mark these redzones as invalid too.
The illegal-access detection works with a 1-byte granularity.

For now, we cover three areas:

- global variables
- kmem_alloc-ated areas
- malloc-ated areas

More will come, but that's a good start.
 1.7.2.4 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.7.2.3 30-Sep-2018  pgoyette Ssync with HEAD
 1.7.2.2 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.7.2.1 27-Aug-2018  pgoyette file asan.c was added on branch pgoyette-compat on 2018-09-06 06:55:24 +0000
 1.30 02-May-2020  bouyer Introduce Xen PVH support in GENERIC.
This is compiled in with
options XENPVHVM
x86 changes:
- add Xen section and xen pvh entry points to locore.S. Set vm_guest
to VM_GUEST_XENPVH in this entry point.
Most of the boot procedure (especially page table setup and switch to
paged mode) is shared with native.
- change some x86_delay() to delay_func(), which points to x86_delay() for
native/HVM, and xen_delay() for PVH

Xen changes:
- remove Xen bits from init_x86_64_ksyms() and init386_ksyms()
and move to xen_init_ksyms(), used for both PV and PVH
- set ISA no-legacy-devices property for PVH
- factor out code from Xen's cpu_bootconf() to xen_bootconf()
in xen_machdep.c
- set up a specific pvh_consinit() which starts with printk()
(which uses a simple hypercall that is available early) and switch to
xencons when we can use pmap_kenter_pa().
 1.29 27-Dec-2019  ad Redo the page allocator to perform better, especially on multi-core and
multi-socket systems. Proposed on tech-kern. While here:

- add rudimentary NUMA support - needs more work.
- remove now unused "listq" from vm_page.
 1.28 22-Oct-2017  maya branches: 1.28.4;
Move initialization code out of efi_probe into efi_init

and call it from cpu_configure
 1.27 22-Jul-2017  maxv Call _proc0_tss_ldt_init only once, and rename them.
 1.26 23-May-2017  nonaka x86: hypervisor detection from FreeBSD for x2APIC support.
 1.25 22-Nov-2015  maxv KNF a bit, so I don't get scared each time I open a file
 1.24 08-Nov-2012  chs branches: 1.24.14;
add include of opt_intrdebug.h.
 1.23 22-Feb-2011  dholland branches: 1.23.4; 1.23.10; 1.23.14;
Include <sys/device.h> for config_rootfound, instead of relying on it
being included by accident. From Jarle Greipsland in PR 43449.
 1.22 15-Mar-2009  cegger branches: 1.22.4; 1.22.6; 1.22.8;
ansify function definitions
 1.21 11-May-2008  ad branches: 1.21.6; 1.21.12;
Share cpu.h between the x86 ports.
 1.20 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.19 23-Jan-2008  joerg branches: 1.19.6; 1.19.8; 1.19.10; 1.19.12;
Initialise the Local Vector Table of the primary LAPIC directly after
enabling it. Explicitly initialise LINT0 as ExtInt and LINT1 as NMI,
the platform default. Mask the NMIs on the application processors and
mask the ExtInt if a IOAPIC was found.

With this patch, "disable ioapic" is supposed to work and it will allow
enabling the local APIC on all systems that have one to gain e.g. the
better clock interrupt.
 1.18 09-Dec-2007  jmcneill Merge jmcneill-pm branch.
 1.17 17-Oct-2007  garbled branches: 1.17.2; 1.17.4; 1.17.6;
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.16 17-May-2007  yamt branches: 1.16.8; 1.16.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.15 07-Jun-2006  kardel branches: 1.15.12; 1.15.16; 1.15.18; 1.15.24;
convert to timecounters (from branch simonb-timecounters)
 1.14 04-Feb-2006  jmmv branches: 1.14.2; 1.14.8;
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.13 03-Feb-2006  jmmv branches: 1.13.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.12 11-Dec-2005  christos branches: 1.12.4;
merge ktrace-lwp.
 1.11 23-Oct-2004  thorpej branches: 1.11.12;
Centralize the declaration of booted_device and booted_partition.
 1.10 20-Oct-2004  thorpej Move boot device detection code from i386 and amd64 ports to x86_autoconf.c.
Rename i386_alldisks and x86_64_alldisks to x86_alldisks, adjust other
references to compensate.
 1.9 15-Oct-2004  thorpej match_harddisk(): Open RAW_PART, not the booted partition; we're
only performing the ioctl to fetch the disklabel.
 1.8 17-Sep-2004  skrll There's no need to pass a proc value when using UIO_SYSSPACE with
vn_rdwr(9) and uiomove(9).

OK'd by Jason Thorpe
 1.7 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.6 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.5 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.4 14-Jul-2003  lukem __KERNEL_RCSID()
 1.3 23-Jun-2003  martin branches: 1.3.2;
Make sure to include opt_foo.h if a defflag option FOO is used.
 1.2 18-Jun-2003  drochner don't #include <sys/dkstat.h> where it is (appearently) unused
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.3.2.5 02-Nov-2004  skrll Sync with HEAD.
 1.3.2.4 19-Oct-2004  skrll Sync with HEAD
 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.11.12.4 04-Feb-2008  yamt sync with head.
 1.11.12.3 21-Jan-2008  yamt sync with head
 1.11.12.2 03-Sep-2007  yamt sync with head.
 1.11.12.1 21-Jun-2006  yamt sync with head.
 1.12.4.1 09-Sep-2006  rpaulo sync with head
 1.13.2.2 30-Apr-2006  kardel initialize TSC timecounter implementation shortly before spl0()
 1.13.2.1 22-Apr-2006  simonb Sync with head.
 1.14.8.1 19-Jun-2006  chap Sync with head.
 1.14.2.1 26-Jun-2006  yamt sync with head.
 1.15.24.1 22-May-2007  matt Update to HEAD.
 1.15.18.1 11-Jul-2007  mjf Sync with head.
 1.15.16.1 27-May-2007  ad Sync with head.
 1.15.12.1 03-Mar-2007  yamt adapt amd64.

XXX changes in identcpu.c is minmum for MONITOR.
XXX identcpu.c should be shared with i386.
 1.16.10.3 23-Mar-2008  matt sync with HEAD
 1.16.10.2 09-Jan-2008  matt sync with HEAD
 1.16.10.1 06-Nov-2007  matt sync with HEAD
 1.16.8.1 30-Nov-2007  jmcneill Call x86 platform_init to parse SMBIOS tables at startup.
 1.17.6.1 11-Dec-2007  yamt sync with head.
 1.17.4.1 26-Dec-2007  ad Sync with head.
 1.17.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.19.12.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.19.10.2 04-May-2009  yamt sync with head.
 1.19.10.1 16-May-2008  yamt sync with head.
 1.19.8.1 18-May-2008  yamt sync with head.
 1.19.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.21.12.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.21.12.2 01-Nov-2009  jym Sync with HEAD.
 1.21.12.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.21.6.1 28-Apr-2009  skrll Sync with HEAD.
 1.22.8.1 05-Mar-2011  bouyer Sync with HEAD
 1.22.6.1 06-Jun-2011  jruoho Sync with HEAD.
 1.22.4.1 05-Mar-2011  rmind sync with head
 1.23.14.2 03-Dec-2017  jdolecek update from HEAD
 1.23.14.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.23.10.1 22-Nov-2012  riz Pull up following revision(s) (requested by chs in ticket #689):
sys/arch/amd64/amd64/autoconf.c: revision 1.24
add include of opt_intrdebug.h.
 1.23.4.1 16-Jan-2013  yamt sync with (a bit old) head
 1.24.14.2 28-Aug-2017  skrll Sync with HEAD
 1.24.14.1 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.28.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.24 15-Aug-2017  maxv Merge into x86/.
 1.23 15-Aug-2017  maxv Reduce the diff between i386 and amd64 (bios32_service not implemented
there).
 1.22 11-Mar-2017  nonaka search SMBIOS from UEFI configuration table when boot with UEFI.
 1.21 22-Nov-2015  maxv branches: 1.21.2; 1.21.4;
KNF a bit, so I don't get scared each time I open a file
 1.20 25-Feb-2012  joerg branches: 1.20.2; 1.20.16;
Avoid empty loop bodies.
 1.19 07-Nov-2009  cegger branches: 1.19.12; 1.19.16;
Add a flags argument to pmap_kenter_pa(9).
Patch showed on tech-kern@ http://mail-index.netbsd.org/tech-kern/2009/11/04/msg006434.html
No objections.
 1.18 16-May-2009  cegger KNF, same object code generated
 1.17 18-Mar-2009  cegger bcopy -> memcpy
 1.16 15-Mar-2009  cegger ansify function definitions
 1.15 17-Feb-2009  jmcneill Make SMBIOS rev. message use aprint_debug (matches i386)
 1.14 18-Dec-2008  cegger branches: 1.14.2;
remove unused malloc.h
 1.13 28-Apr-2008  martin branches: 1.13.8;
Remove clause 3 and 4 from TNF licenses
 1.12 16-Apr-2008  cegger branches: 1.12.2; 1.12.4;
use POSIX integer types
 1.11 09-Dec-2007  jmcneill branches: 1.11.10;
Merge jmcneill-pm branch.
 1.10 01-Dec-2007  jmcneill branches: 1.10.2; 1.10.4;
aprintify
 1.9 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.8 17-Oct-2007  garbled branches: 1.8.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.7 29-Aug-2007  ad branches: 1.7.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.6 03-Jul-2007  briggs branches: 1.6.4; 1.6.8; 1.6.10;
Add (commented-out) support for IPMI on amd64--pretty much copied straight
from i386.
 1.5 04-Mar-2007  christos branches: 1.5.2; 1.5.4; 1.5.10;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.4 24-Dec-2005  perry branches: 1.4.24; 1.4.26; 1.4.30;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.3 11-Dec-2005  christos merge ktrace-lwp.
 1.2 14-Jul-2003  lukem branches: 1.2.16;
__KERNEL_RCSID()
 1.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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.2.16.4 21-Jan-2008  yamt sync with head
 1.2.16.3 07-Dec-2007  yamt sync with head
 1.2.16.2 03-Sep-2007  yamt sync with head.
 1.2.16.1 21-Jun-2006  yamt sync with head.
 1.4.30.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.4.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.4.24.1 19-Dec-2007  ghen Pull up following revision(s) (requested by briggs in ticket #989):
sys/arch/amd64/conf/GENERIC: revision 1.151
sys/arch/x86/x86/ipmi.c: revision 1.12
sys/dev/DEVNAMES: revision 1.228
sys/arch/amd64/amd64/bios32.c: revision 1.6
sys/arch/x86/x86/ipmi.c: revision 1.8
sys/arch/amd64/conf/files.amd64: revision 1.39 via patch
sys/arch/amd64/amd64/mainbus.c: revision 1.17
Use PRIx64 for a 64-bit quantity instead of llx in a debug print.
Add (commented-out) support for IPMI on amd64--pretty much copied straight
from i386.
Check for duplicate sensor names in the IPMI table. If a duplicate name
is found, try to make it unique by appending a count (1-99) to the sensor
description (truncating, if necessary).
 1.5.10.1 03-Oct-2007  garbled Sync with HEAD
 1.5.4.1 11-Jul-2007  mjf Sync with head.
 1.5.2.3 03-Dec-2007  ad Sync with HEAD.
 1.5.2.2 23-Aug-2007  ad More calls to pmap_update().
 1.5.2.1 15-Jul-2007  ad Sync with head.
 1.6.10.2 09-Jan-2008  matt sync with HEAD
 1.6.10.1 06-Nov-2007  matt sync with HEAD
 1.6.8.4 01-Dec-2007  jmcneill Sync with HEAD.
 1.6.8.3 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.6.8.2 03-Sep-2007  jmcneill Sync with HEAD.
 1.6.8.1 03-Aug-2007  jmcneill Pull in power management changes from private branch.
 1.6.4.1 03-Sep-2007  skrll Sync with HEAD.
 1.7.4.1 19-Nov-2007  bouyer Add Xen support.
 1.8.2.2 27-Dec-2007  mjf Sync with HEAD.
 1.8.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.10.4.1 11-Dec-2007  yamt sync with head.
 1.10.2.1 26-Dec-2007  ad Sync with head.
 1.11.10.2 17-Jan-2009  mjf Sync with HEAD.
 1.11.10.1 02-Jun-2008  mjf Sync with HEAD.
 1.12.4.4 11-Mar-2010  yamt sync with head
 1.12.4.3 16-May-2009  yamt sync with head
 1.12.4.2 04-May-2009  yamt sync with head.
 1.12.4.1 16-May-2008  yamt sync with head.
 1.12.2.1 18-May-2008  yamt sync with head.
 1.13.8.3 28-Apr-2009  skrll Sync with HEAD.
 1.13.8.2 03-Mar-2009  skrll Sync with HEAD.
 1.13.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.14.2.4 24-Oct-2010  jym Sync with HEAD
 1.14.2.3 01-Nov-2009  jym Sync with HEAD.
 1.14.2.2 31-May-2009  jym Sync with HEAD.
 1.14.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.19.16.1 04-Mar-2012  mrg sync to latest -current.
 1.19.12.1 17-Apr-2012  yamt sync with head
 1.20.16.2 28-Aug-2017  skrll Sync with HEAD
 1.20.16.1 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.20.2.1 03-Dec-2017  jdolecek update from HEAD
 1.21.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.21.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.2 27-Sep-2012  alnsn Remove bpf_jit which was ported from FreeBSD recently.

It will soon be replaced with the new bpfjit kernel module.
 1.1 01-Aug-2012  rmind branches: 1.1.2;
Add BPF JIT compiler, currently supporting amd64 and i386. Code obtained
from FreeBSD. Also, make few BPF fixes and simplifications while here.
Note that bpf_jit_enable is false for now.

OK dyoung@, some feedback from matt@
 1.1.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.2 27-Sep-2012  alnsn Remove bpf_jit which was ported from FreeBSD recently.

It will soon be replaced with the new bpfjit kernel module.
 1.1 01-Aug-2012  rmind branches: 1.1.2;
Add BPF JIT compiler, currently supporting amd64 and i386. Code obtained
from FreeBSD. Also, make few BPF fixes and simplifications while here.
Note that bpf_jit_enable is false for now.

OK dyoung@, some feedback from matt@
 1.1.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.12 14-Nov-2019  maxv Add support for Kernel Memory Sanitizer (kMSan). It detects uninitialized
memory used by the kernel at run time, and just like kASan and kCSan, it
is an excellent feature. It has already detected 38 uninitialized variables
in the kernel during my testing, which I have since discreetly fixed.

We use two shadows:
- "shad", to track uninitialized memory with a bit granularity (1:1).
Each bit set to 1 in the shad corresponds to one uninitialized bit of
real kernel memory.
- "orig", to track the origin of the memory with a 4-byte granularity
(1:1). Each uint32_t cell in the orig indicates the origin of the
associated uint32_t of real kernel memory.

The memory consumption of these shadows is consequent, so at least 4GB of
RAM is recommended to run kMSan.

The compiler inserts calls to specific __msan_* functions on each memory
access, to manage both the shad and the orig and detect uninitialized
memory accesses that change the execution flow (like an "if" on an
uninitialized variable).

We mark as uninit several types of memory buffers (stack, pools, kmem,
malloc, uvm_km), and check each buffer passed to copyout, copyoutstr,
bwrite, if_transmit_lock and DMA operations, to detect uninitialized memory
that leaves the system. This allows us to detect kernel info leaks in a way
that is more efficient and also more user-friendly than KLEAK.

Contrary to kASan, kMSan requires comprehensive coverage, ie we cannot
tolerate having one non-instrumented function, because this could cause
false positives. kMSan cannot instrument ASM functions, so I converted
most of them to __asm__ inlines, which kMSan is able to instrument. Those
that remain receive special treatment.

Contrary to kASan again, kMSan uses a TLS, so we must context-switch this
TLS during interrupts. We use different contexts depending on the interrupt
level.

The orig tracks precisely the origin of a buffer. We use a special encoding
for the orig values, and pack together in each uint32_t cell of the orig:
- a code designating the type of memory (Stack, Pool, etc), and
- a compressed pointer, which points either (1) to a string containing
the name of the variable associated with the cell, or (2) to an area
in the kernel .text section which we resolve to a symbol name + offset.

This encoding allows us not to consume extra memory for associating
information with each cell, and produces a precise output, that can tell
for example the name of an uninitialized variable on the stack, the
function in which it was pushed on the stack, and the function where we
accessed this uninitialized variable.

kMSan is available with LLVM, but not with GCC.

The code is organized in a way that is similar to kASan and kCSan, so it
means that other architectures than amd64 can be supported.
 1.11 22-Jun-2013  uebayasi branches: 1.11.34;
Use END() to set ELF symbol size.
 1.10 20-May-2011  joerg branches: 1.10.4; 1.10.14;
The %dx argument of in/out is not a memory reference, so don't use it as
such.
 1.9 05-May-2010  dyoung branches: 1.9.2;
As Andrew Doran points out, _ALIGN_TEXT is unused, and to test that
X86_BUS_SPACE_IO equals 0 is no longer necessary. Get rid of the
_ALIGN_TEXT definition, and do not "assert" that X86_BUS_SPACE_IO == 0.
 1.8 28-Apr-2010  dyoung On x86, change the bus_space_tag_t to a pointer to a struct
bus_space_tag. For now, bus_space_tag's only member is
bst_type, the type of space, which is either X86_BUS_SPACE_IO
or X86_BUS_SPACE_MEM. In the future, new bus_space_tag members
will refer to override-functions installed by a new function,
bus_space_tag_create(9).

Add pointers to constant struct bus_space_tag, x86_bus_space_io and
x86_bus_space_mem. Use them to replace most uses of X86_BUS_SPACE_IO
and X86_BUS_SPACE_MEM.

Add an x86-specific bus_space_is_equal(9) implementation that compares
the two tags' bst_type.
 1.7 25-May-2008  chs branches: 1.7.12; 1.7.18; 1.7.20;
enable profiling of assembly functions.
 1.6 28-Apr-2008  martin branches: 1.6.2;
Remove clause 3 and 4 from TNF licenses
 1.5 24-Apr-2008  ad branches: 1.5.2;
Add 64-bit bus_space methods.
 1.4 12-Nov-2007  ad branches: 1.4.14; 1.4.16;
Don't unconditionally clear the direction flag. The ABI says it must always
be clear when making a function call, and 'cld' takes about 50 clock cyles
on the P4.
 1.3 01-Oct-2007  ad branches: 1.3.2; 1.3.4; 1.3.6; 1.3.8; 1.3.10; 1.3.12; 1.3.14;
Fix inverted tests. VT switching works again.
 1.2 28-Sep-2007  ad Shuffle registers a bit to make bus_space_write_region_N work again.
 1.1 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.3.14.3 09-Jan-2008  matt sync with HEAD
 1.3.14.2 06-Nov-2007  matt sync with HEAD
 1.3.14.1 01-Oct-2007  matt file busfunc.S was added on branch matt-armv6 on 2007-11-06 23:14:00 +0000
 1.3.12.1 19-Nov-2007  mjf Sync with HEAD.
 1.3.10.3 15-Nov-2007  yamt sync with head.
 1.3.10.2 27-Oct-2007  yamt sync with head.
 1.3.10.1 01-Oct-2007  yamt file busfunc.S was added on branch yamt-lazymbuf on 2007-10-27 11:25:00 +0000
 1.3.8.1 13-Nov-2007  bouyer Sync with HEAD
 1.3.6.3 03-Dec-2007  ad Sync with HEAD.
 1.3.6.2 09-Oct-2007  ad Sync with head.
 1.3.6.1 01-Oct-2007  ad file busfunc.S was added on branch vmlocking on 2007-10-09 13:37:14 +0000
 1.3.4.2 07-Oct-2007  yamt sync with head.
 1.3.4.1 01-Oct-2007  yamt file busfunc.S was added on branch yamt-x86pmap on 2007-10-07 08:33:19 +0000
 1.3.2.2 14-Nov-2007  joerg Sync with HEAD.
 1.3.2.1 01-Oct-2007  joerg file busfunc.S was added on branch jmcneill-pm on 2007-11-14 19:04:01 +0000
 1.4.16.2 04-Jun-2008  yamt sync with head
 1.4.16.1 18-May-2008  yamt sync with head.
 1.4.14.1 02-Jun-2008  mjf Sync with HEAD.
 1.5.2.3 11-Aug-2010  yamt sync with head.
 1.5.2.2 04-May-2009  yamt sync with head.
 1.5.2.1 16-May-2008  yamt sync with head.
 1.6.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.7.20.2 31-May-2011  rmind sync with head
 1.7.20.1 30-May-2010  rmind sync with head
 1.7.18.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.7.18.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.7.12.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.7.12.1 24-Oct-2010  jym Sync with HEAD
 1.9.2.1 06-Jun-2011  jruoho Sync with 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.11.34.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.3 07-Dec-2017  christos Save maxv@ some work and put back the compat_13_sigreturn changes that allow
amd64 to run ancient i386 binaries.
 1.2 02-Dec-2017  maxv Drop COMPAT_13 on amd64, already not enabled. Reduces the number of
critical places.
 1.1 14-Dec-2014  christos branches: 1.1.2;
Move the empty sigreturn functions to their own files to allow the compat
module to load by itself.
 1.1.2.2 06-Apr-2015  skrll Sync with HEAD
 1.1.2.1 14-Dec-2014  skrll file compat_13_machdep.c was added on branch nick-nhusb on 2015-04-06 15:17:51 +0000
 1.5 14-Dec-2014  christos branches: 1.5.2; 1.5.18;
Move the empty sigreturn functions to their own files to allow the compat
module to load by itself.
 1.4 25-Mar-2004  drochner remove sigcontext-style signal delivery code
 1.3 19-Oct-2003  fvdl Don't use err and trapno from a copied in mcontext.
 1.2 13-Oct-2003  fvdl Do checks on passed in context values (sigreturn/setcontext) explicitly;
can't rely on catching the trap on iret for a few reasons.
 1.1 06-Oct-2003  fvdl SIGINFO support.
Todo: 32bit compat support (COMPAT_NETBSD32 will not compile right now,
as it won't on other platforms).
 1.5.18.2 03-Dec-2017  jdolecek update from HEAD
 1.5.18.1 14-Dec-2014  jdolecek file compat_16_machdep.c was added on branch tls-maxphys on 2017-12-03 11:35:47 +0000
 1.5.2.2 06-Apr-2015  skrll Sync with HEAD
 1.5.2.1 14-Dec-2014  skrll file compat_16_machdep.c was added on branch nick-nhusb on 2015-04-06 15:17:51 +0000
 1.36 24-Sep-2024  andvar s/acually/actually/ in comment.

P.S. the comment itself is hardly readable though.
 1.35 18-Dec-2022  skrll branches: 1.35.6;
Typo in comment
 1.34 30-Jun-2020  maxv Make copystr() a MI C function, part of libkern and shared on all
architectures.

Notes:

- On alpha and ia64 the function is kept but gets renamed locally to avoid
symbol collision. This is because on these two arches, I am not sure
whether the ASM callers do not rely on fixed registers, so I prefer to
keep the ASM body for now.
- On Vax, only the symbol is removed, because the body is used from other
functions.
- On RISC-V, this change fixes a bug: copystr() was just a wrapper around
strlcpy(), but strlcpy() makes the operation less safe (strlen on the
source beyond its size).
- The kASan, kCSan and kMSan wrappers are removed, because now that
copystr() is in C, the compiler transformations are applied to it,
without the need for manual wrappers.

Could test on amd64 only, but should be fine.
 1.33 04-May-2019  maxv Hum. Fix a potentially catastrophic bug: kcopy() sets DF=1 if the areas
overlap, but doesn't clear it if the copy faults. If this happens, we
return to the caller with DF=1, and each future memory copy will be
backwards.

I wonder if there really are places where kcopy() is called with
overlapping areas.
 1.32 06-Apr-2019  thorpej Fix a think-o / paste-o in the max user address check, pointed out
by maxv@.
 1.31 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.30 14-Jul-2018  maxv Drop NENTRY() from the x86 kernels, use ENTRY(). With PMCs (and other hardware
tracing facilities) we have a much better ways of monitoring the CPU activity
than GPROF, without software modification.

Also I think GPROF has never worked, because the 'start' functions of both
i386 and amd64 use ENTRY(), and it would have caused a function call while the
kernel was not yet relocated.
 1.29 07-Jan-2018  maxv branches: 1.29.2; 1.29.4;
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.28 01-Nov-2017  maxv Don't fall through functions, explicitly jump instead. While here don't
call smap_enable twice (harmless), and add END() markers.
 1.27 30-Oct-2017  maxv Always use END() markers when declaring functions in assembly, so that ld
can compute the size of the functions. A few remain.

While here, fix a bug in the INTRSTUB macro: we are falling through
resume_, but it is aligned, so it looks like we're executing the inter-
function padding - which probably happens to contain NOPs, but that's
still bad.
 1.26 17-Oct-2017  maxv fix comment, rdx, not edx
 1.25 17-Oct-2017  maxv Add support for SMAP on amd64.

PSL_AC is cleared from %rflags in each kernel entry point. In the copy
sections, a copy window is opened and the kernel can touch userland
pages. This window is closed when the kernel is done, either at the end
of the copy sections or in the fault-recover functions.

This implementation is not optimized yet, due to the fact that INTRENTRY
is a macro, and we can't hotpatch macros.

Sent on tech-kern@ a month or two ago, tested on a Kabylake.
 1.24 25-Aug-2017  maxv Move incq outside of the copy section. No functional change, reduces
my smap diff.
 1.23 25-Aug-2017  maxv Split comment, otherwise it is misleading. kcopy operates on kernel
memory, and must *not* be used with userland pages.
 1.22 23-Aug-2017  maxv style, reduces an incoming diff
 1.21 23-Aug-2017  maxv Fix a bug in ucas_32 and ucas_64. There is a branch where they don't
initialize %rax.
 1.20 09-Dec-2015  maxv branches: 1.20.10;
KNF, and use C-style comments. Also, remove fusword/susword.
 1.19 21-Nov-2015  maxv Remove the amd64 implementation of fuword and suword. They are not used in
the MI+amd64 code - Christos replaced them yesterday by copy*.

They are both buggy:
- suword does not properly check the userspace limit: 64 bits are copied,
but the max address checked is VM_MAXUSER_ADDRESS-4, which means that 4
bytes may overflow. Reported by Ed Schouten.
- fuword is supposed to be symmetrical with suword. But it uses 32bit
registers, so it stores 32bit values! Spotted by Chuck (chs@).
 1.18 07-Jul-2010  chs branches: 1.18.14; 1.18.18; 1.18.20; 1.18.28; 1.18.34; 1.18.36; 1.18.38; 1.18.40;
fix more bugs in ucas_*():
move the "old" value to %*ax so that cmpxchg* can work.
remove the PCB_ONFAULT stuff, onfault_handler() handles this already.
return the error from fault handler in ucas_fault rather than forcing EFAULT.
 1.17 22-Jun-2010  rmind Fix ucas_32/ucas_64 on amd64.
 1.16 27-Nov-2009  rmind branches: 1.16.2; 1.16.4;
- Use uvm_lwp_setuarea() instead of directly setting address to lwp_t::l_addr.
- Replace most remaining uses of l_addr with uvm_lwp_getuarea() or lwp_getpcb().
- Amend assembly in ports where it accesses PCB via struct user.
- Rename L_ADDR to L_PCB in few places. Reduce sys/user.h inclusions.
 1.15 13-Nov-2009  dsl tlbstate is 'int', so use 'cmpl' not 'cmpq'.
Fixes gprof on amd64 PR/40960.
 1.14 28-Mar-2009  rmind Change amd64 fault handler to check instruction pointer for copyin/out et al
functions, like in i386. Avoids setting pcb_onfault, saves few instructions.
 1.13 23-Feb-2009  rmind Add ucas (CAS for user-space address) support for i386 and amd64.
API provides ucas_int() and ucas_ptr() for now.

Reviewed by <ad>.
 1.12 18-Sep-2008  dsl branches: 1.12.2; 1.12.4; 1.12.8;
Annotate some of the assembler.
Remove 2 redundant register-register moves.
 1.11 30-May-2008  ad branches: 1.11.4;
fillw is dead.
 1.10 28-Apr-2008  ad branches: 1.10.2;
Make kernel pagefault handling preeemption safe.
 1.9 06-Feb-2008  dsl branches: 1.9.6; 1.9.8; 1.9.10;
Reorder code so that we don't default-mispredict the 'deferred switch'
branch on (almost) every copy-in/out.
 1.8 12-Nov-2007  ad Don't unconditionally clear the direction flag. The ABI says it must always
be clear when making a function call, and 'cld' takes about 50 clock cyles
on the P4.
 1.7 18-Oct-2007  yamt branches: 1.7.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.6 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.5 17-May-2007  yamt branches: 1.5.8; 1.5.10; 1.5.12; 1.5.14;
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.4 04-Mar-2007  christos branches: 1.4.2; 1.4.4; 1.4.10;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.3 11-Dec-2005  christos branches: 1.3.26;
merge ktrace-lwp.
 1.2 14-Mar-2005  fvdl branches: 1.2.4;
Check the passed in address as well as determining the maximum length
using VM_MAXUSER_ADDRESS in copyinstr and copyoutstr.

Problem originally fixed in OpenBSD/i386.
This fix suggested by Charles Hannum (mycroft at netbsd dot org).
 1.1 26-Apr-2003  fvdl branches: 1.1.2; 1.1.4; 1.1.8; 1.1.10; 1.1.12;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.12.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.10.1 29-Apr-2005  kent sync with -current
 1.1.8.1 16-Mar-2005  tron Pull up revision 1.2 (requested by fvdl in ticket #1317):
Check the passed in address as well as determining the maximum length
using VM_MAXUSER_ADDRESS in copyinstr and copyoutstr.
Problem originally fixed in OpenBSD/i386.
This fix suggested by Charles Hannum (mycroft at netbsd dot org).
 1.1.4.1 16-Mar-2005  tron Pull up revision 1.2 (requested by fvdl in ticket #1317):
Check the passed in address as well as determining the maximum length
using VM_MAXUSER_ADDRESS in copyinstr and copyoutstr.
Problem originally fixed in OpenBSD/i386.
This fix suggested by Charles Hannum (mycroft at netbsd dot org).
 1.1.2.1 01-Apr-2005  skrll Sync with HEAD.
 1.2.4.4 11-Feb-2008  yamt sync with head.
 1.2.4.3 15-Nov-2007  yamt sync with head.
 1.2.4.2 27-Oct-2007  yamt sync with head.
 1.2.4.1 03-Sep-2007  yamt sync with head.
 1.3.26.2 12-Mar-2007  rmind Sync with HEAD.
 1.3.26.1 03-Mar-2007  yamt adapt amd64.

XXX changes in identcpu.c is minmum for MONITOR.
XXX identcpu.c should be shared with i386.
 1.4.10.1 22-May-2007  matt Update to HEAD.
 1.4.4.1 11-Jul-2007  mjf Sync with head.
 1.4.2.3 03-Dec-2007  ad Sync with HEAD.
 1.4.2.2 23-Oct-2007  ad Sync with head.
 1.4.2.1 27-May-2007  ad Sync with head.
 1.5.14.2 13-Nov-2007  bouyer Sync with HEAD
 1.5.14.1 25-Oct-2007  bouyer Sync with HEAD.
 1.5.12.2 07-Oct-2007  yamt remove some #ifdef _LOCORE and use genassym instead.
 1.5.12.1 30-Sep-2007  yamt implement deferred pmap switching for amd64, and make amd64 use
x86 shared pmap code. it makes several i386 pmap improvements available
to amd64, including tlb shootdown reduction and bug fixes from Stephan Uphoff.
 1.5.10.3 23-Mar-2008  matt 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.2 14-Nov-2007  joerg Sync with HEAD.
 1.5.8.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.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.7.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.9.10.4 11-Aug-2010  yamt sync with head.
 1.9.10.3 11-Mar-2010  yamt sync with head
 1.9.10.2 04-May-2009  yamt sync with head.
 1.9.10.1 16-May-2008  yamt sync with head.
 1.9.8.2 04-Jun-2008  yamt sync with head
 1.9.8.1 18-May-2008  yamt sync with head.
 1.9.6.2 28-Sep-2008  mjf Sync with HEAD.
 1.9.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.10.2.2 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.10.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.11.4.1 19-Oct-2008  haad Sync with HEAD.
 1.12.8.3 28-Mar-2011  jym Cure sync hiccups. Code with compile errors is not really useful, heh.
 1.12.8.2 01-Nov-2009  jym Sync with HEAD.
 1.12.8.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.12.4.1 26-Feb-2009  snj Pull up following revision(s) (requested by rmind in ticket #493):
sys/arch/amd64/amd64/copy.S: revision 1.13
sys/arch/i386/i386/copy.S: revision 1.17
sys/sys/systm.h: revision 1.234
Add ucas (CAS for user-space address) support for i386 and amd64.
API provides ucas_int() and ucas_ptr() for now.
Reviewed by <ad>.
 1.12.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.12.2.1 03-Mar-2009  skrll Sync with HEAD.
 1.16.4.2 05-Mar-2011  rmind sync with head
 1.16.4.1 03-Jul-2010  rmind sync with head
 1.16.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.18.40.1 18-Jan-2017  skrll Sync with netbsd-5
 1.18.38.2 05-May-2019  martin Pull up following revision(s) (requested by maxv in ticket #1693):

sys/arch/amd64/amd64/copy.S: revision 1.33
sys/arch/i386/i386/copy.S: revision 1.31

Hum. Fix a potentially catastrophic bug: kcopy() sets DF=1 if the areas
overlap, but doesn't clear it if the copy faults. If this happens, we
return to the caller with DF=1, and each future memory copy will be
backwards.

I wonder if there really are places where kcopy() is called with
overlapping areas.
 1.18.38.1 24-Dec-2016  snj Apply patch (requested by maxv in ticket #1278):
suword: Don't allow 4 bytes to overflow beyond the userland space.
 1.18.36.2 28-Aug-2017  skrll Sync with HEAD
 1.18.36.1 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.18.34.2 05-May-2019  martin Pull up following revision(s) (requested by maxv in ticket #1693):

sys/arch/amd64/amd64/copy.S: revision 1.33
sys/arch/i386/i386/copy.S: revision 1.31

Hum. Fix a potentially catastrophic bug: kcopy() sets DF=1 if the areas
overlap, but doesn't clear it if the copy faults. If this happens, we
return to the caller with DF=1, and each future memory copy will be
backwards.

I wonder if there really are places where kcopy() is called with
overlapping areas.
 1.18.34.1 24-Dec-2016  snj branches: 1.18.34.1.2;
Apply patch (requested by maxv in ticket #1278):
suword: Don't allow 4 bytes to overflow beyond the userland space.
 1.18.34.1.2.1 05-May-2019  martin Pull up following revision(s) (requested by maxv in ticket #1693):

sys/arch/amd64/amd64/copy.S: revision 1.33
sys/arch/i386/i386/copy.S: revision 1.31

Hum. Fix a potentially catastrophic bug: kcopy() sets DF=1 if the areas
overlap, but doesn't clear it if the copy faults. If this happens, we
return to the caller with DF=1, and each future memory copy will be
backwards.

I wonder if there really are places where kcopy() is called with
overlapping areas.
 1.18.28.1 05-Feb-2017  snj Apply patch (requested by maxv in ticket #1431):
suword: Don't allow 4 bytes to overflow beyond the userland space.
 1.18.20.1 05-Feb-2017  snj Apply patch (requested by maxv in ticket #1431):
suword: Don't allow 4 bytes to overflow beyond the userland space.
 1.18.18.1 03-Dec-2017  jdolecek update from HEAD
 1.18.14.1 05-Feb-2017  snj Apply patch (requested by maxv in ticket #1431):
suword: Don't allow 4 bytes to overflow beyond the userland space.
 1.20.10.4 05-May-2019  martin Pull up following revision(s) (requested by maxv in ticket #1257):

sys/arch/amd64/amd64/copy.S: revision 1.33
sys/arch/i386/i386/copy.S: revision 1.31

Hum. Fix a potentially catastrophic bug: kcopy() sets DF=1 if the areas
overlap, but doesn't clear it if the copy faults. If this happens, we
return to the caller with DF=1, and each future memory copy will be
backwards.

I wonder if there really are places where kcopy() is called with
overlapping areas.
 1.20.10.3 14-Apr-2018  martin Pullup the following revisions via patch, requested by maxv in ticket #748:

sys/arch/amd64/amd64/copy.S 1.29 (adapted, via patch)
sys/arch/amd64/amd64/amd64_trap.S 1.16,1.19 (partial) (via patch)
sys/arch/amd64/amd64/trap.c 1.102,1.106 (partial),1.110 (via patch)
sys/arch/amd64/include/frameasm.h 1.22,1.24 (via patch)
sys/arch/x86/x86/cpu.c 1.137 (via patch)
sys/arch/x86/x86/patch.c 1.23,1.26 (partial) (via patch)

Backport of SMAP support.
 1.20.10.2 26-Feb-2018  snj Pull up following revision(s) (requested by maxv in ticket #575):
sys/arch/amd64/amd64/copy.S: 1.28 via patch
sys/arch/amd64/amd64/cpufunc.S: 1.31
Don't fall through functions, explicitly jump instead.
 1.20.10.1 04-Sep-2017  snj Pull up following revision(s) (requested by maxv in ticket #257):
sys/compat/linux/arch/amd64/linux_machdep.c: 1.52
sys/arch/amd64/amd64/copy.S: 1.21-1.24
sys/arch/amd64/amd64/locore.S: 1.125
sys/arch/amd64/amd64/machdep.c: 1.256
Fix a bug in ucas_32 and ucas_64. There is a branch where they don't
initialize %rax.
--
style, reduces an incoming diff
00
Split comment, otherwise it is misleading. kcopy operates on kernel
memory, and must *not* be used with userland pages.
--
Move incq outside of the copy section. No functional change, reduces
my smap diff.
--
Remove dumb debug code and outdated comment.
--
Don't forget to clean l_md.md_flags, otherwise there may be MDL_COMPAT32,
in which case the kernel would always use iret (slower).
 1.29.4.1 10-Jun-2019  christos Sync with HEAD
 1.29.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.35.6.1 02-Aug-2025  perseant Sync with HEAD
 1.4 30-Mar-2009  rmind Merge/move core_machdep.c into x86, no difference between i386 and amd64.
 1.3 28-Mar-2009  rmind cpu_coredump: pass UIO_SYSSPACE to coredump_write(), not UIO_USERSPACE.
 1.2 18-Dec-2008  cegger branches: 1.2.2; 1.2.4; 1.2.6;
remove unused malloc.h
 1.1 19-Nov-2008  ad branches: 1.1.4;
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.1.4.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.1.4.1 19-Nov-2008  haad file core_machdep.c was added on branch haad-dm on 2008-12-13 01:12:58 +0000
 1.2.6.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.2.4.3 28-Apr-2009  skrll Sync with HEAD.
 1.2.4.2 19-Jan-2009  skrll Sync with HEAD.
 1.2.4.1 18-Dec-2008  skrll file core_machdep.c was added on branch nick-hppapmap on 2009-01-19 13:15:54 +0000
 1.2.2.2 17-Jan-2009  mjf Sync with HEAD.
 1.2.2.1 18-Dec-2008  mjf file core_machdep.c was added on branch mjf-devfs2 on 2009-01-17 13:27:48 +0000
 1.18 29-Aug-2007  ad 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.17 04-Jun-2007  xtraeme branches: 1.17.4; 1.17.8; 1.17.10;
Ansify, de-__P(), unregister.
 1.16 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.15 05-Mar-2007  drochner branches: 1.15.2; 1.15.4; 1.15.10;
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.14 04-Mar-2007  christos Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.13 09-Feb-2007  ad branches: 1.13.2;
Merge newlock2 to head.
 1.12 24-Jul-2006  drochner branches: 1.12.4;
revert previous (executable mapping of data needed for secondary CPU
spinup), this is not needed anymore
 1.11 13-Jul-2006  drochner Map kernel stack and "struct cpuinfo" of secondary processors with
execute permission. (I don't understand yet why the latter is needed.)
This fixes crashes of MP kernels reported by Kurt Schreiner and in
the context of PR port-amd64/33927 (which is about a different problem
otherwise).
MP kernels reported to boot again by Dave Huang and Kurt Schreiner.
 1.10 07-Jun-2006  kardel branches: 1.10.2;
convert to timecounters (from branch simonb-timecounters)
 1.9 11-Dec-2005  christos branches: 1.9.4; 1.9.6; 1.9.8; 1.9.14;
merge ktrace-lwp.
 1.8 01-Apr-2005  yamt branches: 1.8.2;
merge yamt-km branch.
- don't use managed mappings/backing objects for wired memory allocations.
save some resources like pv_entry. also fix (most of) PR/27030.
- simplify kernel memory management API.
- simplify pmap bootstrap of some ports.
- some related cleanups.
 1.7 28-Jun-2004  fvdl branches: 1.7.4; 1.7.6;
Set the double fault stack pointer at the end of the stack.
 1.6 15-Jun-2004  fvdl Make the IDT read-only. It's only mapped R/W when really needed. Could
catch disasters such as overwriting it. Should probably be made
conditional on DIAGNOSTIC later, but there's no time-critical code
involved here.

Move the double fault stack away from the IPI stack. It's now shared
between CPUs, but that's not a big deal; double faults are fatal
and can't be recovered from.
 1.5 30-Apr-2004  toshii Compile TSC support code when __x86_64__ is defined.
 1.4 19-Feb-2004  drochner branches: 1.4.2;
use no-execute page permissions if supported
 1.3 13-Feb-2004  wiz Uppercase CPU, plural is CPUs.
 1.2 14-Jul-2003  lukem __KERNEL_RCSID()
 1.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.2.4 01-Apr-2005  skrll Sync with HEAD.
 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.2.1 06-May-2004  jmc Pullup rev 1.5 (requested by toshii in ticket #254)

Compile TSC support code when __x86_64__ is defined.
 1.7.6.1 13-Feb-2005  yamt - use new apis.
- simplify pmap bootstrap and pv_page allocation.
 1.7.4.1 29-Apr-2005  kent sync with -current
 1.8.2.3 03-Sep-2007  yamt sync with head.
 1.8.2.2 26-Feb-2007  yamt sync with head.
 1.8.2.1 21-Jun-2006  yamt sync with head.
 1.9.14.1 19-Jun-2006  chap Sync with head.
 1.9.8.1 26-Jun-2006  yamt sync with head.
 1.9.6.1 30-Apr-2006  kardel retire cc_microtime code in favor of timecounters
 1.9.4.1 09-Sep-2006  rpaulo sync with head
 1.10.2.1 13-Jul-2006  gdamore Merge from HEAD.
 1.12.4.5 06-Feb-2007  ad - Print CPU boot/startup messages with aprint_debug().
- Don't call printf from an IPI handler.
 1.12.4.4 12-Jan-2007  ad Fix 'SPL NOT LOWERED ON SYSCALL EXIT' with amd64.
 1.12.4.3 12-Jan-2007  ad Make amd64 build again.
 1.12.4.2 11-Jan-2007  ad Checkpoint work in progress.
 1.12.4.1 20-Oct-2006  ad Call mi_cpu_init() on attach.
 1.13.2.3 24-Mar-2007  yamt initialize ci->ci_schedstate.spc_mutex of APs.
(sched_rqinit is called before APs are attached.)
 1.13.2.2 12-Mar-2007  rmind Sync with HEAD.
 1.13.2.1 03-Mar-2007  yamt adapt amd64.

XXX changes in identcpu.c is minmum for MONITOR.
XXX identcpu.c should be shared with i386.
 1.15.10.3 03-Oct-2007  garbled Sync with HEAD
 1.15.10.2 26-Jun-2007  garbled Sync with HEAD.
 1.15.10.1 22-May-2007  matt Update to HEAD.
 1.15.4.1 11-Jul-2007  mjf Sync with head.
 1.15.2.5 23-Aug-2007  ad Merged x86 cpu.c.
 1.15.2.4 21-Aug-2007  ad amd64 changes, as yet untested:

- Adapt to vmlocking branch.
- Apply TLB shootdown and pv allocation changes to the pmap.
- Make it build.
 1.15.2.3 15-Jul-2007  xtraeme Make this build again... ok ad@.
 1.15.2.2 09-Jun-2007  ad Sync with head.
 1.15.2.1 27-May-2007  ad Sync with head.
 1.17.10.1 06-Nov-2007  matt sync with HEAD
 1.17.8.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.17.4.1 03-Sep-2007  skrll Sync with HEAD.
 1.5 15-Nov-2019  maxv Since cpu_in_cksum.S can be built outside of the kernel, add an ugly #ifdef
_KERNEL for kMSan.
 1.4 14-Nov-2019  maxv Add support for Kernel Memory Sanitizer (kMSan). It detects uninitialized
memory used by the kernel at run time, and just like kASan and kCSan, it
is an excellent feature. It has already detected 38 uninitialized variables
in the kernel during my testing, which I have since discreetly fixed.

We use two shadows:
- "shad", to track uninitialized memory with a bit granularity (1:1).
Each bit set to 1 in the shad corresponds to one uninitialized bit of
real kernel memory.
- "orig", to track the origin of the memory with a 4-byte granularity
(1:1). Each uint32_t cell in the orig indicates the origin of the
associated uint32_t of real kernel memory.

The memory consumption of these shadows is consequent, so at least 4GB of
RAM is recommended to run kMSan.

The compiler inserts calls to specific __msan_* functions on each memory
access, to manage both the shad and the orig and detect uninitialized
memory accesses that change the execution flow (like an "if" on an
uninitialized variable).

We mark as uninit several types of memory buffers (stack, pools, kmem,
malloc, uvm_km), and check each buffer passed to copyout, copyoutstr,
bwrite, if_transmit_lock and DMA operations, to detect uninitialized memory
that leaves the system. This allows us to detect kernel info leaks in a way
that is more efficient and also more user-friendly than KLEAK.

Contrary to kASan, kMSan requires comprehensive coverage, ie we cannot
tolerate having one non-instrumented function, because this could cause
false positives. kMSan cannot instrument ASM functions, so I converted
most of them to __asm__ inlines, which kMSan is able to instrument. Those
that remain receive special treatment.

Contrary to kASan again, kMSan uses a TLS, so we must context-switch this
TLS during interrupts. We use different contexts depending on the interrupt
level.

The orig tracks precisely the origin of a buffer. We use a special encoding
for the orig values, and pack together in each uint32_t cell of the orig:
- a code designating the type of memory (Stack, Pool, etc), and
- a compressed pointer, which points either (1) to a string containing
the name of the variable associated with the cell, or (2) to an area
in the kernel .text section which we resolve to a symbol name + offset.

This encoding allows us not to consume extra memory for associating
information with each cell, and produces a precise output, that can tell
for example the name of an uninitialized variable on the stack, the
function in which it was pushed on the stack, and the function where we
accessed this uninitialized variable.

kMSan is available with LLVM, but not with GCC.

The code is organized in a way that is similar to kASan and kCSan, so it
means that other architectures than amd64 can be supported.
 1.3 30-Jun-2015  christos branches: 1.3.18;
handle PIC compilation (if we are building a PIE system; this is used by tests)
 1.2 22-Jun-2013  uebayasi branches: 1.2.10;
Use END() to set ELF symbol size. Set local string type/size too.
 1.1 25-Jan-2008  joerg branches: 1.1.2; 1.1.4; 1.1.12; 1.1.50; 1.1.60;
Refactor in_cksum/in4_cksum/in6_cksum implementations:
- All three functions are included in the kernel by default.
They call a backend function cpu_in_cksum after possibly
computing the checksum of the pseudo header.
- cpu_in_cksum is the core to implement the one-complement sum.
The default implementation is moderate fast on most platforms
and provides a 32bit accumulator with 16bit addends for L32 platforms
and a 64bit accumulator with 32bit addends for L64 platforms.
It handles edge cases like very large mbuf chains (could happen with
native IPv6 in the future) and provides a good base for new native
implementations.
- Modify i386 and amd64 assembly to use the new interface.

This disables the MD implementations on !x86 until the conversion is
done. For Alpha, the portable version is faster.
 1.1.60.2 03-Dec-2017  jdolecek update from HEAD
 1.1.60.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.50.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 23-Mar-2008  matt sync with HEAD
 1.1.12.1 25-Jan-2008  matt file cpu_in_cksum.S was added on branch matt-armv6 on 2008-03-23 02:03:52 +0000
 1.1.4.2 18-Feb-2008  mjf Sync with HEAD.
 1.1.4.1 25-Jan-2008  mjf file cpu_in_cksum.S was added on branch mjf-devfs on 2008-02-18 21:04:20 +0000
 1.1.2.2 04-Feb-2008  yamt sync with head.
 1.1.2.1 25-Jan-2008  yamt file cpu_in_cksum.S was added on branch yamt-lazymbuf on 2008-02-04 09:21:39 +0000
 1.2.10.1 22-Sep-2015  skrll Sync with HEAD
 1.3.18.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.70 06-Sep-2025  riastradh paravirt_membar_sync(9): New memory barrier.

For use in paravirtualized drivers which require store-before-load
ordering -- irrespective of whether the kernel is built for a single
processor, or whether the (virtual) machine is booted with a single
processor.

This is even required on architectures that don't even have a
store-before-load ordering barrier, like m68k; adding, e.g., a virtio
bus is _as if_ the architecture has been extended with relaxed memory
ordering when talking with that new bus. Such architectures need
some way to request the hypervisor enforce that ordering -- on m68k,
that's done by issuing a CASL instruction, which qemu maps to an
atomic r/m/w with sequential consistency ordering in the host.

PR kern/59618: occasional virtio block device lock ups/hangs
 1.69 23-May-2025  riastradh branches: 1.69.2;
x86: Expose dtrace_smap_enable/disable symbols even under XENPV.

They're no-ops in that case, but this enables the dtrace modules to
load and work.

PR port-xen/58373: Missing KDTRACE_HOOKS in Xen kernels
 1.68 16-Jul-2024  riastradh xen: Don't hotpatch away LOCK prefix in xen_mb, even on UP boots.

Both xen_mb and membar_sync are designed to provide store-before-load
ordering, but xen_mb has to provide it in synchronizing guest with
hypervisor, while membar_sync only has to provide it in synchronizing
one (guest) CPU with another (guest) CPU.

It is safe to hotpatch away the LOCK prefix in membar_sync on a
uniprocessor boot because membar_sync is only designed to coordinate
between normal memory on multiple CPUs, and is never necessary when
there's only one CPU involved.

But xen_mb is used to coordinate between the guest and the `device'
implemented by a hypervisor, which might be running on another
_physical_ CPU even if the NetBSD guest only sees one `CPU', i.e.,
one _virtual_ CPU. So even on `uniprocessor' boots, xen_mb must
still issue an instruction with store-before-load ordering on
multiprocessor systems, such as a LOCK ADD (or MFENCE, but MFENCE is
costlier for no benefit here).

No need to change xen_wmb (release ordering, load/store-before-store)
or xen_rmb (acquire ordering, load-before-load/store) because every
x86 store is a store-release and every x86 load is a load-acquire,
even on multiprocessor systems, so there's no hotpatching involved
anyway.

PR kern/57199
 1.67 03-Nov-2023  chs branches: 1.67.6;
dtrace: add support for SMAP

Add support in dtrace for SMAP, so that actions like copyinstr() work.
It would be better if dtrace could use the SMAP_* hotpatch macros directly,
but the hotpatching code does not currently operate on kernel modules,
so we'll use some tiny functions in the base kernel for now.
 1.66 04-Oct-2023  ad Eliminate l->l_ncsw and l->l_nivcsw. From memory think they were added
before we had per-LWP struct rusage; the same is now tracked there.
 1.65 30-Nov-2020  bouyer branches: 1.65.18;
Introduce smap_enable()/smap_disable() functions, to be used from
C code.
 1.64 19-Jul-2020  maxv branches: 1.64.2;
Revert most of ad's movs/stos change. Instead do a lot simpler: declare
svs_quad_copy() used by SVS only, with no need for instrumentation, because
SVS is disabled when sanitizers are on.
 1.63 24-Jun-2020  maxv remove unused x86_stos
 1.62 15-Jun-2020  riastradh Nix trailing whitespace.
 1.61 15-Jun-2020  msaitoh Serialize rdtsc using with lfence, mfence or cpuid to read TSC more precisely.

x86/x86/tsc.c rev. 1.67 reduced cache problem and got big improvement, but it
still has room. I measured the effect of lfence, mfence, cpuid and rdtscp.
The impact to TSC skew and/or drift is:

AMD: mfence > rdtscp > cpuid > lfence-serialize > lfence = nomodify
Intel: lfence > rdtscp > cpuid > nomodify

So, mfence is the best on AMD and lfence is the best on Intel. If it has no
SSE2, we can use cpuid.

NOTE:
- An AMD's document says DE_CFG_LFENCE_SERIALIZE bit can be used for
serializing, but it's not so good.
- On Intel i386(not amd64), it seems the improvement is very little.
- rdtscp instruct can be used as serializing instruction + rdtsc, but
it's not good as [lm]fence. Both Intel and AMD's document say that
the latency of rdtscp is bigger than rdtsc, so I suspect the difference
of the result comes from it.
 1.60 13-Jun-2020  ad Print a rate limited warning if the TSC timecounter goes backwards from the
viewpoint of any single LWP.
 1.59 01-Jun-2020  ad Reported-by: syzbot+6dd5a230d19f0cbc7814@syzkaller.appspotmail.com

Instrument STOS/MOVS for KMSAN to unbreak it.
 1.58 27-May-2020  ad - mismatched END pointed out by maxv@
- ditch the frame, tracer should be able to deal without it in leaf on x86_64
 1.57 27-May-2020  ad - Add a couple of wrapper functions around STOS and MOVS and use them to zero
and copy PTEs in preference to memset()/memcpy().

- Remove related SSE / pageidlezero stuff.
 1.56 20-May-2020  maxv this is kmsan
 1.55 20-May-2020  ad Deal with KMSAN fussiness. Pointed out by msaitoh@.
 1.54 19-May-2020  ad xen needs the TSC funcs too
 1.53 19-May-2020  ad Make cpu_counter(), cpu_counter32() and tsc_get_timecount() into a single
preemption-safe routine.
 1.52 08-May-2020  ad cpu_counter: only need to clear %eax (zero extends).
 1.51 02-May-2020  bouyer Move x86_hotpatch() in !XENPV section. Fixes XEN3* builds.
 1.50 02-May-2020  maxv Modify the hotpatch mechanism, in order to make it much less ROP-friendly.

Currently x86_patch_window_open is a big problem, because it is a perfect
function to inject/modify executable code with ROP.

- Remove x86_patch_window_open(), along with its x86_patch_window_close()
counterpart.
- Introduce a read-only link-set of hotpatch descriptor structures,
which reference a maximum of two read-only hotpatch sources.
- Modify x86_hotpatch() to open a window and call the new
x86_hotpatch_apply() function in a hard-coded manner.
- Modify x86_hotpatch() to take a name and a selector, and have
x86_hotpatch_apply() resolve the descriptor from the name and the
source from the selector, before hotpatching.
- Move the error handling in a separate x86_hotpatch_cleanup() function,
that gets called after we closed the window.

The resulting implementation is a bit complex and non-obvious. But it
gains the following properties: the code executed in the hotpatch window
is strictly hard-coded (no callback and no possibility to execute your own
code in the window) and the pointers this code accesses are strictly
read-only (no possibility to forge pointers to hotpatch an area that was
not designated as hotpatchable at compile-time, and no possibility to
choose what bytes to write other than the maximum of two read-only
templates that were designated as valid for the given destination at
compile-time).

With current CPUs this slightly improves a situation that is already
pretty bad by definition on x86. Assuming CET however, this change closes
a big hole and is kinda great.

The only ~problem there is, is that dtrace-fbt tries to hotpatch random
places with random bytes, and there is just no way to make it safe.
However dtrace is only in a module, that is rarely used and never compiled
into the kernel, so it's not a big problem; add a shitty & vulnerable
independent hotpatch window in it, and leave big XXXs. It looks like fbt
is going to collapse soon anyway.
 1.49 21-Nov-2019  ad mi_userret(): take care of calling preempt(), set spc_curpriority directly,
and remove MD code that does the same.
 1.48 15-Nov-2019  maxv Remove the ins* and outs* functions. Not sanitizer-friendly, and unused
anyway.
 1.47 14-Nov-2019  maxv Add support for Kernel Memory Sanitizer (kMSan). It detects uninitialized
memory used by the kernel at run time, and just like kASan and kCSan, it
is an excellent feature. It has already detected 38 uninitialized variables
in the kernel during my testing, which I have since discreetly fixed.

We use two shadows:
- "shad", to track uninitialized memory with a bit granularity (1:1).
Each bit set to 1 in the shad corresponds to one uninitialized bit of
real kernel memory.
- "orig", to track the origin of the memory with a 4-byte granularity
(1:1). Each uint32_t cell in the orig indicates the origin of the
associated uint32_t of real kernel memory.

The memory consumption of these shadows is consequent, so at least 4GB of
RAM is recommended to run kMSan.

The compiler inserts calls to specific __msan_* functions on each memory
access, to manage both the shad and the orig and detect uninitialized
memory accesses that change the execution flow (like an "if" on an
uninitialized variable).

We mark as uninit several types of memory buffers (stack, pools, kmem,
malloc, uvm_km), and check each buffer passed to copyout, copyoutstr,
bwrite, if_transmit_lock and DMA operations, to detect uninitialized memory
that leaves the system. This allows us to detect kernel info leaks in a way
that is more efficient and also more user-friendly than KLEAK.

Contrary to kASan, kMSan requires comprehensive coverage, ie we cannot
tolerate having one non-instrumented function, because this could cause
false positives. kMSan cannot instrument ASM functions, so I converted
most of them to __asm__ inlines, which kMSan is able to instrument. Those
that remain receive special treatment.

Contrary to kASan again, kMSan uses a TLS, so we must context-switch this
TLS during interrupts. We use different contexts depending on the interrupt
level.

The orig tracks precisely the origin of a buffer. We use a special encoding
for the orig values, and pack together in each uint32_t cell of the orig:
- a code designating the type of memory (Stack, Pool, etc), and
- a compressed pointer, which points either (1) to a string containing
the name of the variable associated with the cell, or (2) to an area
in the kernel .text section which we resolve to a symbol name + offset.

This encoding allows us not to consume extra memory for associating
information with each cell, and produces a precise output, that can tell
for example the name of an uninitialized variable on the stack, the
function in which it was pushed on the stack, and the function where we
accessed this uninitialized variable.

kMSan is available with LLVM, but not with GCC.

The code is organized in a way that is similar to kASan and kCSan, so it
means that other architectures than amd64 can be supported.
 1.46 30-Oct-2019  maxv More inlined ASM.
 1.45 07-Sep-2019  maxv Merge amd64func.S into cpufunc.S, and clean up.
 1.44 07-Sep-2019  maxv Convert rdmsr_locked and wrmsr_locked to inlines.
 1.43 05-Jul-2019  maxv branches: 1.43.2;
More inlines, prerequisites for future changes. Also, remove fngetsw(),
which was a duplicate of fnstsw().
 1.42 03-Jul-2019  maxv Inline x86_cpuid2(), prerequisite for future changes. Also, add "memory"
on certain other inlines, to make sure GCC does not reorder.
 1.41 29-May-2019  maxv Add PCID support in SVS. This avoids TLB flushes during kernel<->user
transitions, which greatly reduces the performance penalty introduced by
SVS.

We use two ASIDs, 0 (kern) and 1 (user), and use invpcid to flush pages
in both ASIDs.

The read-only machdep.svs.pcid={0,1} sysctl is added, and indicates whether
SVS+PCID is in use.
 1.40 19-May-2019  maxv Misc changes in the x86 FPU code. Reduces a future diff. No real functional
change.
 1.39 04-May-2019  maxv More inlined ASM. While here switch to proper types.
 1.38 01-May-2019  maxv Start converting the x86 CPU functions to inlined ASM. Matters for NVMM,
where some are invoked millions of times.
 1.37 01-May-2019  maxv Remove unused functions and reorder a little.
 1.36 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.35 06-Jan-2019  cherry Rollback http://mail-index.netbsd.org/source-changes/2018/12/22/msg101629.html

This change breaks module loading due to weak alias being unsupported
in the kernel module linker.

Requested by maxv@ and others as it affects their work.

No immediate decision on a replacement method is available, but other options
suggested include pre-processing, conditional compilation (#ifdef etc) and other
source level methods to avoid linktime decision making.
 1.34 22-Dec-2018  cherry Introduce a weak alias method of exporting different implementations
of the same API.

For eg: the amd64 native implementation of invlpg() now becomes
amd64_invlpg() with a weak symbol export of invlpg(), while the XEN
implementation becomes xen_invlpg(), also weakly exported as invlpg()

Note that linking in both together without having an override function
named invlpg() would be a mistake, as we have limited control over
which of the two options would emerge as the finally exported invlpg()
resulting in a potential situation where the wrong function is finally
exported. This change avoids this situation.

We should however include an override function invlpg() in that case,
such that it is able to then pass on the call to the appropriate
backing function (amd64_invlpg() in the case of native, and
xen_invlpg() in the case of under XEN virtualisation) at runtime.

This change does not introduce such a function and therefore does not
alter builds to include native as well as XEN implementations in the
same binary. This will be done later, with the introduction of XEN
PVHVM mode, where precisely such a runtime switch is required.

There are no operational changes introduced by this change.
 1.33 21-Jul-2018  maxv More ASLR. Randomize the location of the direct map at boot time on amd64.
This doesn't need "options KASLR" and works on GENERIC. Will soon be
enabled by default.

The location of the areas is abstracted in a slotspace structure. Ideally
we should always use this structure when touching the L4 slots, instead of
the current cocktail of global variables and constants.

machdep initializes the structure with the default values, and we then
randomize its dmap entry. Ideally machdep should randomize everything at
once, but in the case of the direct map its size is determined a little
later in the boot procedure, so we're forced to randomize its location
later too.
 1.32 14-Jul-2018  maxv Drop NENTRY() from the x86 kernels, use ENTRY(). With PMCs (and other hardware
tracing facilities) we have a much better ways of monitoring the CPU activity
than GPROF, without software modification.

Also I think GPROF has never worked, because the 'start' functions of both
i386 and amd64 use ENTRY(), and it would have caused a function call while the
kernel was not yet relocated.
 1.31 01-Nov-2017  maxv branches: 1.31.2; 1.31.4;
Don't fall through functions, explicitly jump instead. While here don't
call smap_enable twice (harmless), and add END() markers.
 1.30 30-Oct-2017  maxv Always use END() markers when declaring functions in assembly, so that ld
can compute the size of the functions. A few remain.

While here, fix a bug in the INTRSTUB macro: we are falling through
resume_, but it is aligned, so it looks like we're executing the inter-
function padding - which probably happens to contain NOPs, but that's
still bad.
 1.29 15-Oct-2017  maxv Add setds and setes, will be useful in the future.
 1.28 15-Oct-2017  maxv Add setusergs on Xen, and simplify.
 1.27 27-Nov-2016  kamil branches: 1.27.8;
Add accessors for available x86 Debug Registers

There are 8 Debug Registers on i386 (available at least since 80386) and 16
on AMD64. Currently DR4 and DR5 are reserved on both cpu-families and
DR9-DR15 are still reserved on AMD64. Therefore add accessors for DR0-DR3,
DR6-DR7 for all ports.

Debug Registers x86:
* DR0-DR3 Debug Address Registers
* DR4-DR5 Reserved
* DR6 Debug Status Register
* DR7 Debug Control Register
* DR8-DR15 Reserved

Access the registers is available only from a kernel (ring 0) as there is
needed top protected access. For this reason there is need to use special
XEN functions to get and set the registers in the XEN3 kernels.

XEN specific functions as defined in NetBSD:
- HYPERVISOR_get_debugreg()
- HYPERVISOR_set_debugreg()

This code extends the existing rdr6() and ldr6() accessor for additional:
- rdr0() & ldr0()
- rdr1() & ldr1()
- rdr2() & ldr2()
- rdr3() & ldr3()
- rdr7() & ldr7()

Traditionally accessors for DR6 were passing vaddr_t argument, while it's
appropriate type for DR0-DR3, DR6-DR7 should be using u_long, however it's
not a big deal. The resulting functionality should be equivalent so stick
to this convention and use the vaddr_t type for all DR accessors.

There was already a function defined for rdr6() in XEN, but it had a nit on
AMD64 as it was casting HYPERVISOR_get_debugreg() to u_int (32-bit on
AMD64), truncating result. It still works for DR6, but for the sake of
simplicity always return full 64-bit value.

New accessors duplicate functionality of the dr0() function available on
i386 within the KSTACK_CHECK_DR0 option. dr0() is a specialized layer with
logic to set appropriate types of interrupts, now accessors are designed to
pass verbatim values from user-land (with simple sanity checks in the
kernel). At the moment there are no plans to make possible to coexist
KSTACK_CHECK_DR0 with debug registers for user applications (debuggers).

options KSTACK_CHECK_DR0
Detect kernel stack overflow using DR0 register. This option uses DR0
register exclusively so you can't use DR0 register for other purpose
(e.g., hardware breakpoint) if you turn this on.

The KSTACK_CHECK_DR0 functionality was designed for i386 and never ported
to amd64.

Code tested on i386 and amd64 with kernels: GENERIC, XEN3_DOMU, XEN3_DOM0.

Sponsored by <The NetBSD Foundation>
 1.26 27-Nov-2016  kamil Fix rdr6() function on amd64

According to the AMD64 SysV ABI the first returned value is passed in RAX,
not in RDI. Actually RDI is used for the first argument passed to a
function.

So far this function was dead code, it will be used for a ptrace(2)
feature to support CPU watchpoints.

The rdr6() function reads state of the DR6 register and returns its value.

Sponsored by <The NetBSD Foundation>
 1.25 12-Feb-2014  dsl branches: 1.25.6; 1.25.10;
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.24 09-Feb-2014  dsl Best if x86_stmxcsr executes stmxcsr.
 1.23 09-Feb-2014  dsl Add x86_stmxcsr for amd64.
 1.22 08-Dec-2013  dsl Add some definitions for cpu 'extended state'.
These are needed for support of the AVX SIMD instructions.
Nothing yet uses them.
 1.21 24-Sep-2011  jym branches: 1.21.2; 1.21.12; 1.21.16;
White space fix.
 1.20 24-Sep-2011  jym Import rdmsr_safe(msr, *value) for x86 world. It allows reading MSRs
in a safe way by handling the fault that might trigger for certain
register <> CPU/arch combos.

Requested by Jukka. Patch adapted from one found in DragonflyBSD.
 1.19 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.18 22-Feb-2011  joerg branches: 1.18.2;
Be explicit about the member of the fld family wanted here.
 1.17 07-Jul-2010  chs branches: 1.17.2; 1.17.4;
add the guts of TLS support on amd64. based on joerg's patch,
reworked by me to support 32-bit processes as well.
we now keep %fs and %gs loaded with the user values
while in the kernel, which means we don't need to
reload them when returning to user mode.
 1.16 01-Oct-2009  skrll branches: 1.16.2; 1.16.4;
Fix up mwait/monitor now that gas has been fixed.
 1.15 24-Jun-2008  ad branches: 1.15.6; 1.15.10; 1.15.16; 1.15.20;
getss -> x86_getss
 1.14 25-May-2008  chs branches: 1.14.2;
enable profiling of assembly functions, except for x86_pause().
profiling that one causes the system with profiling on to become so slow
that we get spinlock timeouts.
 1.13 11-May-2008  ad Don't reload LDTR unless a new value, which only happens for USER_LDT.
 1.12 10-May-2008  ad Take skew into account for cpu_counter().
 1.11 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.10 28-Apr-2008  ad branches: 1.10.2;
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.9 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.8 27-Apr-2008  ad branches: 1.8.2;
+lcr2
 1.7 08-Feb-2008  ad branches: 1.7.6; 1.7.8;
breakpoint: set up a stack frame so not to confuse gdb.
 1.6 01-Jan-2008  yamt add x86_cpuid2, which can specify ecx register.
 1.5 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.4 06-Dec-2007  ad branches: 1.4.4;
Correct argument shuffling in the string I/O functions.
 1.3 22-Nov-2007  bouyer branches: 1.3.2;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.2 12-Nov-2007  ad Don't unconditionally clear the direction flag. The ABI says it must always
be clear when making a function call, and 'cld' takes about 50 clock cyles
on the P4.
 1.1 26-Sep-2007  ad branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8; 1.1.10; 1.1.12; 1.1.14;
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.1.14.4 23-Mar-2008  matt sync with HEAD
 1.1.14.3 09-Jan-2008  matt sync with HEAD
 1.1.14.2 06-Nov-2007  matt sync with HEAD
 1.1.14.1 26-Sep-2007  matt file cpufunc.S was added on branch matt-armv6 on 2007-11-06 23:14:01 +0000
 1.1.12.4 18-Feb-2008  mjf Sync with HEAD.
 1.1.12.3 27-Dec-2007  mjf Sync with HEAD.
 1.1.12.2 08-Dec-2007  mjf Sync with HEAD.
 1.1.12.1 19-Nov-2007  mjf Sync with HEAD.
 1.1.10.6 11-Feb-2008  yamt sync with head.
 1.1.10.5 21-Jan-2008  yamt sync with head
 1.1.10.4 07-Dec-2007  yamt sync with head
 1.1.10.3 15-Nov-2007  yamt sync with head.
 1.1.10.2 27-Oct-2007  yamt sync with head.
 1.1.10.1 26-Sep-2007  yamt file cpufunc.S was added on branch yamt-lazymbuf on 2007-10-27 11:25:01 +0000
 1.1.8.2 13-Nov-2007  bouyer Sync with HEAD
 1.1.8.1 17-Oct-2007  bouyer amd64 (aka x86-64) support for Xen. Based on the OpenBSD port done by
Mathieu Ropert in 2006.
DomU-only for now. An INSTALL_XEN3_DOMU kernel with a ramdisk will boot to
sysinst if you're lucky. Often it panics because a runable LWP has
a NULL stack (really, it's all of l->l_addr which is has been zeroed out
while the process was on the queue !)
TODO:
- bug fixes :)
- Most of the xpq_* functions should be shared with xen/i386
- The xen/i386 assembly bootstrap code should be remplaced with the C
version in xenamd64/amd64/xpmap.c
- see if a config(5) trick could allow to merge xenamd64 back to xen or amd64.
 1.1.6.4 03-Dec-2007  ad Sync with HEAD.
 1.1.6.3 03-Dec-2007  ad Sync with HEAD.
 1.1.6.2 09-Oct-2007  ad Sync with head.
 1.1.6.1 26-Sep-2007  ad file cpufunc.S was added on branch vmlocking on 2007-10-09 13:37:14 +0000
 1.1.4.2 07-Oct-2007  yamt sync with head.
 1.1.4.1 26-Sep-2007  yamt file cpufunc.S was added on branch yamt-x86pmap on 2007-10-07 08:33:20 +0000
 1.1.2.4 09-Dec-2007  jmcneill Sync with HEAD.
 1.1.2.3 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.1.2.2 14-Nov-2007  joerg Sync with HEAD.
 1.1.2.1 26-Sep-2007  joerg file cpufunc.S was added on branch jmcneill-pm on 2007-11-14 19:04:01 +0000
 1.3.2.2 26-Dec-2007  ad Sync with head.
 1.3.2.1 08-Dec-2007  ad Sync with head.
 1.4.4.1 02-Jan-2008  bouyer Sync with HEAD
 1.7.8.2 04-Jun-2008  yamt sync with head
 1.7.8.1 18-May-2008  yamt sync with head.
 1.7.6.2 29-Jun-2008  mjf Sync with HEAD.
 1.7.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.8.2.4 11-Aug-2010  yamt sync with head.
 1.8.2.3 11-Mar-2010  yamt sync with head
 1.8.2.2 04-May-2009  yamt sync with head.
 1.8.2.1 16-May-2008  yamt sync with head.
 1.10.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.10.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.14.2.1 27-Jun-2008  simonb Sync with head.
 1.15.20.1 01-Jun-2015  sborrill Pull up the following revisions(s) (requested by msaitoh in ticket #1969):
sys/arch/x86/include/cpufunc.h: revision 1.13
sys/arch/amd64/amd64/cpufunc.S: revision 1.20-1.21 via patch
sys/arch/i386/i386/cpufunc.S: revision 1.16-1.17, 1.21 via patch

Backport rdmsr_safe() to access MSR safely.
 1.15.16.1 01-Jun-2015  sborrill Pull up the following revisions(s) (requested by msaitoh in ticket #1969):
sys/arch/x86/include/cpufunc.h: revision 1.13
sys/arch/amd64/amd64/cpufunc.S: revision 1.20-1.21 via patch
sys/arch/i386/i386/cpufunc.S: revision 1.16-1.17, 1.21 via patch

Backport rdmsr_safe() to access MSR safely.
 1.15.10.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.15.10.3 28-Mar-2011  jym Cure sync hiccups. Code with compile errors is not really useful, heh.
 1.15.10.2 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.15.10.1 01-Nov-2009  jym Sync with HEAD.
 1.15.6.1 01-Jun-2015  sborrill Pull up the following revisions(s) (requested by msaitoh in ticket #1969):
sys/arch/x86/include/cpufunc.h: revision 1.13
sys/arch/amd64/amd64/cpufunc.S: revision 1.20-1.21 via patch
sys/arch/i386/i386/cpufunc.S: revision 1.16-1.17, 1.21 via patch

Backport rdmsr_safe() to access MSR safely.
 1.16.4.2 17-Mar-2011  rmind - Fix tlbflushg() to behave like tlbflush(), if page global extension (PGE)
is not (yet) enabled. This fixes the issue of stale TLB entry, experienced
early on boot, when PGE is not yet set on primary CPU.
- Rewrite i386/amd64 TLB interrupt handlers in C (only stubs are in assembly),
which simplifies and unifies (under x86) code, plus fixes few bugs.
- cpu_attach: remove assignment to cpus_running, as primary CPU might not be
attached first, which causes reset (and thus missed secondary CPUs).
 1.16.4.1 05-Mar-2011  rmind sync with head
 1.16.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.17.4.1 05-Mar-2011  bouyer Sync with HEAD
 1.17.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.18.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.21.16.1 18-May-2014  rmind sync with head
 1.21.12.2 03-Dec-2017  jdolecek update from HEAD
 1.21.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.21.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.25.10.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.25.6.1 05-Dec-2016  skrll Sync with HEAD
 1.27.8.1 26-Feb-2018  snj Pull up following revision(s) (requested by maxv in ticket #575):
sys/arch/amd64/amd64/copy.S: 1.28 via patch
sys/arch/amd64/amd64/cpufunc.S: 1.31
Don't fall through functions, explicitly jump instead.
 1.31.4.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.31.4.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.31.4.1 10-Jun-2019  christos Sync with HEAD
 1.31.2.3 18-Jan-2019  pgoyette Synch with HEAD
 1.31.2.2 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.31.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.43.2.1 19-Oct-2025  martin Pull up following revision(s) (requested by riastradh in ticket #60):

sys/arch/sparc/sparc/locore.s: revision 1.287
share/man/man9/Makefile: revision 1.475
sys/arch/mips/mips/cpu_subr.c: revision 1.65
sys/arch/mips/mips/cpu_subr.c: revision 1.66
sys/arch/amd64/amd64/cpufunc.S: revision 1.70
sys/arch/hppa/hppa/support.S: revision 1.9
sys/arch/alpha/alpha/locore.s: revision 1.145
share/man/man9/paravirt_membar_sync.9: revision 1.1
sys/arch/sparc64/sparc64/locore.s: revision 1.436
distrib/sets/lists/comp/mi: revision 1.2499
sys/arch/i386/i386/cpufunc.S: revision 1.54
sys/sys/paravirt_membar.h: revision 1.1
sys/arch/arm/arm/cpu_subr.c: revision 1.6
(all via patch)

paravirt_membar_sync(9): New memory barrier.

For use in paravirtualized drivers which require store-before-load
ordering -- irrespective of whether the kernel is built for a single
processor, or whether the (virtual) machine is booted with a single
processor.

This is even required on architectures that don't even have a
store-before-load ordering barrier, like m68k; adding, e.g., a virtio
bus is _as if_ the architecture has been extended with relaxed memory
ordering when talking with that new bus. Such architectures need
some way to request the hypervisor enforce that ordering -- on m68k,
that's done by issuing a CASL instruction, which qemu maps to an
atomic r/m/w with sequential consistency ordering in the host.

PR kern/59618: occasional virtio block device lock ups/hangs

mips: Fix asm arch options in new paravirt_membar_sync.
Need to explicitly enable mips2 (MIPS-II) instructions in order to
use sync. Fixes:
/tmp/ccxgOmXc.s: Assembler messages:
/tmp/ccxgOmXc.s:3576: Error: opcode not supported on this processor: mips1 (mips1) `sync'
--- cpu_subr.o ---
*** Failed target: cpu_subr.o

PR kern/59618: occasional virtio block device lock ups/hangs
 1.64.2.1 14-Dec-2020  thorpej Sync w/ HEAD.
 1.65.18.2 19-Oct-2025  martin Pull up following revision(s) (requested by riastradh in ticket #60):

sys/arch/sparc/sparc/locore.s: revision 1.287
share/man/man9/Makefile: revision 1.475
sys/arch/mips/mips/cpu_subr.c: revision 1.65
sys/arch/mips/mips/cpu_subr.c: revision 1.66
sys/arch/amd64/amd64/cpufunc.S: revision 1.70
common/lib/libc/arch/i386/atomic/atomic.S: revision 1.38
common/lib/libc/arch/sparc/atomic/membar_ops.S: revision 1.9
sys/arch/hppa/hppa/support.S: revision 1.9
sys/arch/alpha/alpha/locore.s: revision 1.145
share/man/man9/paravirt_membar_sync.9: revision 1.1
sys/arch/sparc64/sparc64/locore.s: revision 1.436
distrib/sets/lists/comp/mi: revision 1.2499
sys/arch/i386/i386/cpufunc.S: revision 1.54
common/lib/libc/arch/sparc64/atomic/membar_ops.S: revision 1.10
sys/sys/paravirt_membar.h: revision 1.1
sys/arch/arm/arm/cpu_subr.c: revision 1.6
common/lib/libc/arch/x86_64/atomic/atomic.S: revision 1.32
(all via patch)

paravirt_membar_sync(9): New memory barrier.

For use in paravirtualized drivers which require store-before-load
ordering -- irrespective of whether the kernel is built for a single
processor, or whether the (virtual) machine is booted with a single
processor.

This is even required on architectures that don't even have a
store-before-load ordering barrier, like m68k; adding, e.g., a virtio
bus is _as if_ the architecture has been extended with relaxed memory
ordering when talking with that new bus. Such architectures need
some way to request the hypervisor enforce that ordering -- on m68k,
that's done by issuing a CASL instruction, which qemu maps to an
atomic r/m/w with sequential consistency ordering in the host.

PR kern/59618: occasional virtio block device lock ups/hangs

mips: Fix asm arch options in new paravirt_membar_sync.
Need to explicitly enable mips2 (MIPS-II) instructions in order to
use sync. Fixes:
/tmp/ccxgOmXc.s: Assembler messages:
/tmp/ccxgOmXc.s:3576: Error: opcode not supported on this processor: mips1 (mips1) `sync'
--- cpu_subr.o ---
*** Failed target: cpu_subr.o

PR kern/59618: occasional virtio block device lock ups/hangs
 1.65.18.1 20-Jul-2024  martin Pull up following revision(s) (requested by riastradh in ticket #764):

common/lib/libc/arch/i386/atomic/atomic.S: revision 1.37
sys/arch/xen/include/xenring.h: revision 1.8
sys/arch/i386/i386/cpufunc.S: revision 1.52
sys/arch/amd64/amd64/cpufunc.S: revision 1.68
sys/arch/xen/include/hypervisor.h: revision 1.60
common/lib/libc/arch/x86_64/atomic/atomic.S: revision 1.30

xen: Don't hotpatch away LOCK prefix in xen_mb, even on UP boots.

Both xen_mb and membar_sync are designed to provide store-before-load
ordering, but xen_mb has to provide it in synchronizing guest with
hypervisor, while membar_sync only has to provide it in synchronizing
one (guest) CPU with another (guest) CPU.

It is safe to hotpatch away the LOCK prefix in membar_sync on a
uniprocessor boot because membar_sync is only designed to coordinate
between normal memory on multiple CPUs, and is never necessary when
there's only one CPU involved.

But xen_mb is used to coordinate between the guest and the `device'
implemented by a hypervisor, which might be running on another
_physical_ CPU even if the NetBSD guest only sees one `CPU', i.e.,
one _virtual_ CPU. So even on `uniprocessor' boots, xen_mb must
still issue an instruction with store-before-load ordering on
multiprocessor systems, such as a LOCK ADD (or MFENCE, but MFENCE is
costlier for no benefit here).

No need to change xen_wmb (release ordering, load/store-before-store)
or xen_rmb (acquire ordering, load-before-load/store) because every
x86 store is a store-release and every x86 load is a load-acquire,
even on multiprocessor systems, so there's no hotpatching involved
anyway.

PR kern/57199
 1.67.6.1 02-Aug-2025  perseant Sync with HEAD
 1.69.2.1 19-Oct-2025  martin Pull up following revision(s) (requested by riastradh in ticket #60):

sys/arch/sparc/sparc/locore.s: revision 1.287
share/man/man9/Makefile: revision 1.475
sys/arch/mips/mips/cpu_subr.c: revision 1.65
sys/arch/riscv/riscv/cpu_subr.c: revision 1.6
sys/arch/mips/mips/cpu_subr.c: revision 1.66
sys/arch/amd64/amd64/cpufunc.S: revision 1.70
common/lib/libc/arch/i386/atomic/atomic.S: revision 1.38
common/lib/libc/arch/sparc/atomic/membar_ops.S: revision 1.9
sys/arch/hppa/hppa/support.S: revision 1.9
sys/arch/alpha/alpha/locore.s: revision 1.145
share/man/man9/paravirt_membar_sync.9: revision 1.1
sys/arch/sparc64/sparc64/locore.s: revision 1.436
distrib/sets/lists/comp/mi: revision 1.2499
sys/arch/i386/i386/cpufunc.S: revision 1.54
common/lib/libc/arch/sparc64/atomic/membar_ops.S: revision 1.10
sys/sys/paravirt_membar.h: revision 1.1
sys/arch/arm/arm/cpu_subr.c: revision 1.6
sys/arch/virt68k/virt68k/locore.s: revision 1.17
common/lib/libc/arch/x86_64/atomic/atomic.S: revision 1.32

paravirt_membar_sync(9): New memory barrier.

For use in paravirtualized drivers which require store-before-load
ordering -- irrespective of whether the kernel is built for a single
processor, or whether the (virtual) machine is booted with a single
processor.

This is even required on architectures that don't even have a
store-before-load ordering barrier, like m68k; adding, e.g., a virtio
bus is _as if_ the architecture has been extended with relaxed memory
ordering when talking with that new bus. Such architectures need
some way to request the hypervisor enforce that ordering -- on m68k,
that's done by issuing a CASL instruction, which qemu maps to an
atomic r/m/w with sequential consistency ordering in the host.

PR kern/59618: occasional virtio block device lock ups/hangs

mips: Fix asm arch options in new paravirt_membar_sync.
Need to explicitly enable mips2 (MIPS-II) instructions in order to
use sync. Fixes:
/tmp/ccxgOmXc.s: Assembler messages:
/tmp/ccxgOmXc.s:3576: Error: opcode not supported on this processor: mips1 (mips1) `sync'
--- cpu_subr.o ---
*** Failed target: cpu_subr.o

PR kern/59618: occasional virtio block device lock ups/hangs
 1.28 23-May-2021  riastradh ddb/amd64: Don't go out of the way to detect invalid addresses.

db_disasm had logic to detect invalid addresses before trying to
disassemble them. But when disassembling a null instruction address,
the logic to detect invalid addresses itself tried to dereference an
invalid address.

db_get_value can already handle this situation gracefully, so there is
no need for this faulty fault-avoidance logic.

Fixes double-fault in ddb on calling null function pointers. With
any luck, this should make diagnosing such bugs easier in the future!
 1.27 09-Mar-2019  maxv branches: 1.27.4; 1.27.16; 1.27.18;
Start replacing the x86 PTE bits.
 1.26 03-Feb-2019  mrg - add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily
 1.25 08-Sep-2018  maxv Work around dumb KASSERT in vtopte(), the PTE area can now be above the
MAIN area. I guess the KASSERT should be removed because it doesn't make
a lot of sense.
 1.24 21-Jan-2018  christos branches: 1.24.2; 1.24.4;
CID-1364351: Fix uninitialized warnings.
 1.23 25-Mar-2016  shm Add support for clac and stac instructions.
 1.22 12-May-2015  christos When in Rome... use true or false, instead of TRUE and FALSE.
 1.21 12-May-2015  msaitoh Catch up FreeBSD and OpenBSD's changes. Not completed but it's better than
before:
- Add support rdrand, rdseed, fxrstor, ldmxcsr, stmxcsr, xsare, xrstor,
xsaveopt, cflush and some others.
- Check REX bit correctly.
- Print correct register.
- Fix a lot of bugs.
- KNF.
 1.20 23-Oct-2014  msaitoh branches: 1.20.2;
Add support for sysenter, sysexit, vmptrld, vmptrst and getsec.
 1.19 09-Oct-2014  msaitoh Fix bugs:
- aaa and daa were reversed. Same as *BSDs.
- fix operand order of shld and shrd. Same as *BSDs.
 1.18 07-Oct-2014  msaitoh No functional change.
- 0 -> NULL
- Don't use cast.
- Style fix.
- Fix typos in comment.
 1.17 12-Sep-2014  msaitoh KNF. No binary change.
 1.16 17-Jul-2011  joerg branches: 1.16.12; 1.16.28;
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.15 10-Apr-2011  christos Merge db_trace for x86. From: Vladimir Kirillov proger at wilab dot org dot ua
 1.14 18-Feb-2011  drochner fix misinterpretation of REX prefixes where use of the accumulator
as operand is hardwired into the instruction code,
mostly from Wolfgang Stukenbrock per PR port-amd64/44405
 1.13 14-Mar-2009  dsl branches: 1.13.4; 1.13.6; 1.13.8;
ANSIfy another 1261 function definitions.
The only ones left in sys are beyond by sed script!
(or in sys/dist or sys/external)
Mostly they have function pointer parameters.
 1.12 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.11 01-Jan-2008  yamt branches: 1.11.10; 1.11.18; 1.11.24;
add swapgs.
 1.10 20-Dec-2007  ad Decode cmpxchg8b correctly.
 1.9 18-Oct-2007  yamt branches: 1.9.2; 1.9.4; 1.9.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.8 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.7 22-Jun-2007  dsl branches: 1.7.8; 1.7.10; 1.7.12; 1.7.14;
Correct the disassembly of instructions that move immediate values into
64bit targets. Only the 0xb8-0xbf instructions (move immediate to register)
have a 64bit immediate constant.
Correct the disassembly of movq %eax to/from an immediate address - 64bit addr.
Add cmovxx instructions.
Now stands a chance of not getting all misaligned on normal C code.
Add a few others, but there are a lot missing, but probably mainly SIMD ones.
 1.6 22-Feb-2007  thorpej branches: 1.6.4; 1.6.6; 1.6.12;
TRUE -> true, FALSE -> false
 1.5 21-Feb-2007  thorpej 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 11-Dec-2005  christos branches: 1.4.26;
merge ktrace-lwp.
 1.3 01-Jun-2005  blymn branches: 1.3.2;
Const'ify structure declarations to prevent compiler warnings.
 1.2 01-Mar-2005  matt Add disasm support for amd64 (x86-64).
From Cliff Neighbors.
 1.1 26-Apr-2003  fvdl branches: 1.1.2; 1.1.8; 1.1.10; 1.1.12;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.12.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.10.1 29-Apr-2005  kent sync with -current
 1.1.8.1 07-May-2005  snj Pull up revision 1.2 (requested by matt in ticket #1275):
Add disasm support for amd64 (x86-64).
From Cliff Neighbors.
 1.1.2.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.2.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.3.2.4 21-Jan-2008  yamt sync with head
 1.3.2.3 27-Oct-2007  yamt sync with head.
 1.3.2.2 03-Sep-2007  yamt sync with head.
 1.3.2.1 26-Feb-2007  yamt sync with head.
 1.4.26.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.6.12.1 26-Jun-2007  garbled Sync with HEAD.
 1.6.6.1 11-Jul-2007  mjf Sync with head.
 1.6.4.2 23-Oct-2007  ad Sync with head.
 1.6.4.1 15-Jul-2007  ad Sync with head.
 1.7.14.1 25-Oct-2007  bouyer Sync with HEAD.
 1.7.12.1 04-Oct-2007  yamt remove LARGEPAGES option. always use large pages if available.
 1.7.10.2 09-Jan-2008  matt sync with HEAD
 1.7.10.1 06-Nov-2007  matt sync with HEAD
 1.7.8.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.9.8.1 02-Jan-2008  bouyer Sync with HEAD
 1.9.4.1 26-Dec-2007  ad Sync with head.
 1.9.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.11.24.5 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.11.24.4 02-May-2011  jym Sync with head.
 1.11.24.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.11.24.2 01-Nov-2009  jym Sync with HEAD.
 1.11.24.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.11.18.1 28-Apr-2009  skrll Sync with HEAD.
 1.11.10.1 04-May-2009  yamt sync with head.
 1.13.8.1 05-Mar-2011  bouyer Sync with HEAD
 1.13.6.1 06-Jun-2011  jruoho Sync with HEAD.
 1.13.4.2 21-Apr-2011  rmind sync with head
 1.13.4.1 05-Mar-2011  rmind sync with head
 1.16.28.1 12-Dec-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #313):
sys/arch/amd64/amd64/db_disasm.c: revision 1.20
sys/arch/i386/i386/db_disasm.c: revision 1.41
sys/arch/i386/i386/db_disasm.c: revision 1.42
sys/arch/i386/i386/db_disasm.c: revision 1.43
sys/arch/i386/i386/db_disasm.c: revision 1.44
sys/arch/amd64/amd64/db_disasm.c: revision 1.17
sys/arch/amd64/amd64/db_disasm.c: revision 1.18
sys/arch/amd64/amd64/db_disasm.c: revision 1.19
KNF. No binary change.
No functional change.
- 0 -> NULL
- Don't use cast.
- Style fix.
- Fix typos in comment.
Fix bugs:
- aaa and daa were reversed. Same as *BSDs.
- fix operand order of shld and shrd. Same as *BSDs.
Add support for sysenter, sysexit, vmptrld, vmptrst and getsec.
 1.16.12.1 03-Dec-2017  jdolecek update from HEAD
 1.20.2.2 22-Apr-2016  skrll Sync with HEAD
 1.20.2.1 06-Jun-2015  skrll Sync with HEAD
 1.24.4.1 10-Jun-2019  christos Sync with HEAD
 1.24.2.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.27.18.1 31-May-2021  cjep sync with head
 1.27.16.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.27.4.1 21-Jun-2021  martin Pull up following revision(s) (requested by riastradh in ticket #1307):

sys/arch/amd64/amd64/db_disasm.c: revision 1.28
sys/arch/i386/i386/db_disasm.c: revision 1.49

ddb/amd64: Don't go out of the way to detect invalid addresses.

db_disasm had logic to detect invalid addresses before trying to
disassemble them. But when disassembling a null instruction address,
the logic to detect invalid addresses itself tried to dereference an
invalid address.

db_get_value can already handle this situation gracefully, so there is
no need for this faulty fault-avoidance logic.

Fixes double-fault in ddb on calling null function pointers. With
any luck, this should make diagnosing such bugs easier in the future!

ddb/i386: Don't go out of the way to detect invalid addresses.
db_read_bytes already does this better (but didn't at the time this
check was originally added back in 1998). Not sure if this code had
the same mistake as the amd64 code causing it to trip over its own
shoelaces, but there should be no need for it here.
 1.42 31-Jul-2023  mrg when cpus are paused (spinning) in DDB, call x86_pause() in the loop,
hopefully this can reduce power usage while doing nothing.

ok chs@

XXX: pullup-*
XXX: apply to i386
 1.41 26-Oct-2022  riastradh branches: 1.41.2;
ddb/db_active.h: New home for extern db_active.

This can be included unconditionally, and db_active can then be
queried unconditionally; if DDB is not in the kernel, then db_active
is a constant zero. Reduces need for #include opt_ddb.h, #ifdef DDB.
 1.40 23-Dec-2021  yamaguchi x86: improve error handling related to idt_vec_alloc()
 1.39 23-Feb-2021  mrg introduce DDB_END_CMD and replace more than 20 copies of the same
list of NULLs and 0. idea from rillig@.

all touched ports built, several booted.
 1.38 14-Jul-2020  yamaguchi branches: 1.38.2;
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.37 29-Feb-2020  christos Fix boot -c or -d by avoiding ipi handling before the vector is initialized.
 1.36 14-Feb-2019  cherry branches: 1.36.4; 1.36.6;
Fix NLAPIC, NISA and NIOAPIC related conditional compile errors.

This will allow us to now compile an amd64 kernel without PCI.

No functional changes.
 1.35 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.34 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.33 03-Apr-2018  christos branches: 1.33.2;
Rename the DDB IPI IDT vectors for consistency. ok maxv@
 1.32 13-Feb-2018  maxv branches: 1.32.2;
Remove double declaration; 'ddb_regs' is already declared as a macro
in db_machdep.h if MULTIPROCESSOR is on, and the macro has higher
priority.

Don't declare 'ddb_regs' locally in this case, because it is misleading.
Part of PR/52964.
 1.31 13-Feb-2018  ozaki-r Define ddb_regp only if MULTIPROCESSOR (NFC)
 1.30 13-Feb-2018  ozaki-r Fix NULL pointer dereference via ddb_regs

ddb_regs can be *ddb_regp (see db_machdep.h) so ddb_regp should be NULL-ed
after dereference to ddb_regs.

Also dbreg should be restored to ddb_regp because ddb_regp can be changed
by db_mach_cpu during db_trap.

Fix PR 52964
Helped by nonaka@
 1.29 10-Feb-2018  christos make it compile without MULTIPROCESSOR (xen?)
 1.28 09-Feb-2018  maxv Reset ddb_regp to NULL. Reported by David Binderman in PR/52964.
 1.27 15-Aug-2017  maxv Rename intrddb -> intrddbipi, like i386.
 1.26 15-Aug-2017  maxv Reduce the diff between amd64 and i386.
 1.25 23-May-2017  nonaka branches: 1.25.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.24 11-Aug-2011  cherry branches: 1.24.12; 1.24.30;
make ddb minimally MP aware
 1.23 03-Apr-2011  dyoung branches: 1.23.2;
Clean up excessive #ifdef'age of NMI trap handling for amd64/i386/xen.
Handle NMI in all Xen kernels.
 1.22 20-Dec-2010  matt branches: 1.22.2;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.
 1.21 15-Nov-2009  dholland branches: 1.21.4;
Declare trap name array as extern const char *const [] to match how
it's defined in trap.c. (Should really be in a header, of course.)
Compile-tested.
 1.20 29-Jan-2009  joerg branches: 1.20.2;
Match declaration of trap_type in trap.c.
 1.19 15-Oct-2008  ad branches: 1.19.2;
- Rename cpu_lookup_byindex() to cpu_lookup(). The hardware ID isn't of
interest to MI code. No functional change.
- Change /dev/cpu to operate on cpu index, not hardware ID. Now cpuctl
shouldn't print confused output.
 1.18 28-May-2008  ad branches: 1.18.4;
Another use of X86_MAXPROCS.
 1.17 28-May-2008  ad Kill use of X86_MAXPROCS.
 1.16 12-May-2008  ad - Make cpu_number() return MI index, otherwise the pmap cannot work on
systems with lapic IDs > X86_MAXPROCS.
- Kill cpu_info[] array and use MI cpu_lookup_byindex().
 1.15 28-Nov-2007  ad branches: 1.15.14; 1.15.16; 1.15.18; 1.15.20;
Use the new atomic ops.
 1.14 22-Nov-2007  bouyer Reinclude machine/cpuvar.h lost in bouyer-xenamd64 merge; make GENERIC.MP
kernel build again.
 1.13 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.12 15-Nov-2007  ad Disable TLB shootdown IPIs while in the debugger. Crashdumps may try to
use them, and all but one CPU is paused. Reported and tested by martin@.
 1.11 17-Oct-2007  garbled branches: 1.11.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.10 02-Oct-2007  martin branches: 1.10.2;
Add verbose help for (the one and only) "mach" command.
 1.9 22-Sep-2007  martin branches: 1.9.2;
Add a new option DDB_VERBOSE_HELP that adds online help to ddb.
From Adam Hamsik.
Minor modifications by me, all bugs are probably mine.
 1.8 04-Jun-2007  xtraeme branches: 1.8.8; 1.8.10;
Ansify, de-__P(), unregister.
 1.7 22-Feb-2007  dogcow branches: 1.7.4; 1.7.6; 1.7.10; 1.7.12;
miscellaneous fallout from the great boolean rototill.
 1.6 22-Feb-2007  thorpej TRUE -> true, FALSE -> false
 1.5 11-Dec-2005  christos branches: 1.5.26;
merge ktrace-lwp.
 1.4 01-Jun-2005  drochner branches: 1.4.2;
adapt to ddb constification
 1.3 13-Feb-2004  wiz Uppercase CPU, plural is CPUs.
 1.2 23-Jun-2003  martin branches: 1.2.2;
Make sure to include opt_foo.h if a defflag option FOO is used.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.2.2.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 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.4.2.4 07-Dec-2007  yamt sync with head
 1.4.2.3 27-Oct-2007  yamt sync with head.
 1.4.2.2 03-Sep-2007  yamt sync with head.
 1.4.2.1 26-Feb-2007  yamt sync with head.
 1.5.26.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.7.12.2 03-Oct-2007  garbled Sync with HEAD
 1.7.12.1 26-Jun-2007  garbled Sync with HEAD.
 1.7.10.1 18-Apr-2007  thorpej Convert i386 and amd64 to the new atomic ops API.
 1.7.6.1 11-Jul-2007  mjf Sync with head.
 1.7.4.4 03-Dec-2007  ad Sync with HEAD.
 1.7.4.3 03-Dec-2007  ad Sync with HEAD.
 1.7.4.2 09-Oct-2007  ad Sync with head.
 1.7.4.1 09-Jun-2007  ad Sync with head.
 1.8.10.2 09-Jan-2008  matt sync with HEAD
 1.8.10.1 06-Nov-2007  matt sync with HEAD
 1.8.8.3 03-Dec-2007  joerg Sync with HEAD.
 1.8.8.2 21-Nov-2007  joerg Sync with HEAD.
 1.8.8.1 02-Oct-2007  joerg Sync with HEAD.
 1.9.2.1 06-Oct-2007  yamt sync with head.
 1.10.2.2 18-Nov-2007  bouyer Sync with HEAD
 1.10.2.1 17-Oct-2007  bouyer amd64 (aka x86-64) support for Xen. Based on the OpenBSD port done by
Mathieu Ropert in 2006.
DomU-only for now. An INSTALL_XEN3_DOMU kernel with a ramdisk will boot to
sysinst if you're lucky. Often it panics because a runable LWP has
a NULL stack (really, it's all of l->l_addr which is has been zeroed out
while the process was on the queue !)
TODO:
- bug fixes :)
- Most of the xpq_* functions should be shared with xen/i386
- The xen/i386 assembly bootstrap code should be remplaced with the C
version in xenamd64/amd64/xpmap.c
- see if a config(5) trick could allow to merge xenamd64 back to xen or amd64.
 1.11.2.2 08-Dec-2007  mjf Sync with HEAD.
 1.11.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.15.20.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.15.18.3 11-Mar-2010  yamt sync with head
 1.15.18.2 04-May-2009  yamt sync with head.
 1.15.18.1 16-May-2008  yamt sync with head.
 1.15.16.2 04-Jun-2008  yamt sync with head
 1.15.16.1 18-May-2008  yamt sync with head.
 1.15.14.2 17-Jan-2009  mjf Sync with HEAD.
 1.15.14.1 02-Jun-2008  mjf Sync with HEAD.
 1.18.4.1 19-Oct-2008  haad Sync with HEAD.
 1.19.2.1 03-Mar-2009  skrll Sync with HEAD.
 1.20.2.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.20.2.3 02-May-2011  jym Sync with head.
 1.20.2.2 10-Jan-2011  jym Sync with HEAD
 1.20.2.1 24-Oct-2010  jym Sync with HEAD
 1.21.4.2 21-Apr-2011  rmind sync with head
 1.21.4.1 05-Mar-2011  rmind sync with head
 1.22.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.23.2.2 31-Jul-2011  cherry grow MP support for i386. boots to single user
 1.23.2.1 03-Jun-2011  cherry Initial import of xen MP sources, with kernel and userspace tests.
- this is a source priview.
- boots to single user.
- spurious interrupt and pmap related panics are normal
 1.24.30.1 28-Aug-2017  skrll Sync with HEAD
 1.24.12.1 03-Dec-2017  jdolecek update from HEAD
 1.25.2.1 05-Apr-2018  martin Pull up following revision(s) (requested by christos in ticket #696):

sys/arch/amd64/amd64/vector.S: revision 1.62 (patch)
sys/arch/x86/include/intr.h: revision 1.55
sys/arch/i386/i386/vector.S: revision 1.77
sys/arch/i386/i386/db_interface.c: revision 1.82 (patch)
sys/arch/amd64/amd64/spl.S: revision 1.34 (patch)
sys/arch/amd64/amd64/db_interface.c: revision 1.33 (patch)
sys/arch/x86/x86/intr.c: revision 1.125
sys/arch/i386/i386/spl.S: revision 1.43 (patch)
sys/arch/i386/i386/machdep.c: revision 1.805 (patch)
sys/arch/x86/x86/lapic.c: revision 1.66 (patch)

Rename the DDB IPI IDT vectors for consistency. ok maxv@

Rename Xpreempt{recurse,resume} -> X{recurse,resume}_preempt so that
they fit the pattern. Also the debugger trap sniffer matches them
without adding special entries...

XXX: pullup-8.
 1.32.2.2 30-Sep-2018  pgoyette Ssync with HEAD
 1.32.2.1 07-Apr-2018  pgoyette Sync with HEAD. 77 conflicts resolved - all of them $NetBSD$
 1.33.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.33.2.1 10-Jun-2019  christos Sync with HEAD
 1.36.6.1 29-Feb-2020  ad Sync with head.
 1.36.4.1 02-Mar-2020  martin Pull up following revision(s) (requested by christos in ticket #750):

sys/arch/amd64/amd64/db_interface.c: revision 1.37

Fix boot -c or -d by avoiding ipi handling before the vector is initialized.
 1.38.2.1 03-Apr-2021  thorpej Sync with HEAD.
 1.41.2.1 21-Sep-2024  martin Pull up following revision(s) (requested by rin in ticket #900):

sys/arch/amd64/amd64/db_interface.c: revision 1.42
sys/arch/i386/i386/db_interface.c: revision 1.89

when cpus are paused (spinning) in DDB, call x86_pause() in the loop,
hopefully this can reduce power usage while doing nothing.

ok chs@
XXX: apply to i386

i386: DDB: Call x86_pause() (`pause` insn) when CPUs are paused
as already done for amd64:
https://mail-index.netbsd.org/source-changes/2023/07/31/msg146423.html

`pause` insn has been introduced to Pentium 4. However, its opcode is
consisted of `nop` (0x90) followed by `rep` prefix (0xf3), and therefore
interpreted as `nop` for older processors. Intel assured this behavior [1].

Also note that we already use `pause` unconditionally for i386.

Briefly tested on QEMU.

[1] Intel, ``AP-949 Using Spin-Loops on Intel Pentium 4 Processor and
Intel Xeon Processor'', Version 2.1, Sec 2.1.1. (2001)
 1.15 24-Dec-2022  uwe {amd64,i386}/db_machdep.c: Don't bury a function call in an if condition

db_frame_info has many arguments and requires contorted line wrapping
that obscures the condition. The same object code is generated
(modulo a local variable moved closer to its only use site).
 1.14 24-Dec-2022  uwe {amd64,i386}/db_machdep.c: Use DB_SYM_NULL
 1.13 27-Jun-2022  riastradh amd64: Handle __syscall trap frames specially too.
 1.12 26-Jun-2022  riastradh amd64: Print effective syscall number for SYS_syscall stack traces.

This time with compile-testing, at least.
 1.11 26-Jun-2022  riastradh Revert "amd64: Print effective syscall number for SYS_syscall stack traces."

Built the wrong kernel (arm64 is not amd64), oops. Will redo.
 1.10 26-Jun-2022  riastradh amd64: Print effective syscall number for SYS_syscall stack traces.
 1.9 13-Dec-2021  chs ddb: fix function names of "noreturn" functions in stack traces.

when looking up function names for stack traces (where the addresses are the
return addresses of function calls), if the address is the first instruction
in the function, assume that the function being called is marked "noreturn"
and that the function containing the call is actually the function immediately
before the address that we looked up. to find the correct function name,
do the lookup again with (address - 1) and then add one to the offset within
the function that we find.
 1.8 06-Jun-2020  maxv If the frame is not aligned, leave right away. This place probably needs
to be revisited, because %rbp could easily contain garbage.

Reported-by: syzbot+ecb40cf7f8acc102c29b@syzkaller.appspotmail.com
 1.7 14-May-2020  maxv Don't even try to go past a syscall. Fixes severe panic recursions in
KUBSAN.
 1.6 16-Mar-2018  maxv Rename "handle_" -> "Xhandle_", and add the function names (introduced by
SVS) in db_machdep.c.

Should fix the DDB part of PR/53060.
 1.5 11-Feb-2018  maxv branches: 1.5.2;
Style, and reduce the diff between i386 and amd64. No functional change.
 1.4 03-Oct-2012  riastradh branches: 1.4.30;
Use db_read_value to read the trapframe fields in db_nextframe.

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

ok christos
 1.3 12-Jul-2012  dsl branches: 1.3.2;
Neither i386 nor amd64 have had separate syscall_plain/fancy functions
for ages, so this code can't be correct in looking for them.
Change to compare against "syscall".
I don't know if this changes any behaviour anywhere.
 1.2 22-Feb-2012  chs fix stack backtraces through traps.
 1.1 10-Apr-2011  christos branches: 1.1.2; 1.1.4; 1.1.8; 1.1.10; 1.1.14; 1.1.16;
Merge db_trace for x86. From: Vladimir Kirillov proger at wilab dot org dot ua
 1.1.16.2 17-Oct-2012  riz Pull up following revision(s) (requested by riastradh in ticket #604):
sys/arch/amd64/amd64/db_machdep.c: revision 1.4
Use db_read_value to read the trapframe fields in db_nextframe.
Fixes SIGSEGV on bt in crash(8) when the stack trace ends in syscall,
and probably other problems as well.
ok christos
 1.1.16.1 23-Feb-2012  riz Pull up following revision(s) (requested by chs in ticket #37):
sys/arch/amd64/amd64/db_machdep.c: revision 1.2
fix stack backtraces through traps.
 1.1.14.1 24-Feb-2012  mrg sync to -current.
 1.1.10.2 30-Oct-2012  yamt sync with head
 1.1.10.1 17-Apr-2012  yamt sync with head
 1.1.8.2 06-Jun-2011  jruoho Sync with HEAD.
 1.1.8.1 10-Apr-2011  jruoho file db_machdep.c was added on branch jruoho-x86intr on 2011-06-06 09:04:47 +0000
 1.1.4.2 02-May-2011  jym Sync with head.
 1.1.4.1 10-Apr-2011  jym file db_machdep.c was added on branch jym-xensuspend on 2011-05-02 22:49:54 +0000
 1.1.2.2 21-Apr-2011  rmind sync with head
 1.1.2.1 10-Apr-2011  rmind file db_machdep.c was added on branch rmind-uvmplock on 2011-04-21 01:40:47 +0000
 1.3.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.4.30.1 22-Mar-2018  martin Pull up the following revisions, requested by maxv in ticket #652:

sys/arch/amd64/amd64/amd64_trap.S upto 1.39 (partial, patch)
sys/arch/amd64/amd64/db_machdep.c 1.6 (patch)
sys/arch/amd64/amd64/genassym.cf 1.65,1.66,1.67 (patch)
sys/arch/amd64/amd64/locore.S upto 1.159 (partial, patch)
sys/arch/amd64/amd64/machdep.c 1.299-1.302 (patch)
sys/arch/amd64/amd64/trap.c upto 1.113 (partial, patch)
sys/arch/amd64/amd64/amd64/vector.S upto 1.61 (partial, patch)
sys/arch/amd64/conf/GENERIC 1.477,1.478 (patch)
sys/arch/amd64/conf/kern.ldscript 1.26 (patch)
sys/arch/amd64/include/frameasm.h upto 1.37 (partial, patch)
sys/arch/amd64/include/param.h 1.25 (patch)
sys/arch/amd64/include/pmap.h 1.41,1.43,1.44 (patch)
sys/arch/x86/conf/files.x86 1.91,1.93 (patch)
sys/arch/x86/include/cpu.h 1.88,1.89 (patch)
sys/arch/x86/include/pmap.h 1.75 (patch)
sys/arch/x86/x86/cpu.c 1.144,1.146,1.148,1.149 (patch)
sys/arch/x86/x86/pmap.c upto 1.289 (partial, patch)
sys/arch/x86/x86/vm_machdep.c 1.31,1.32 (patch)
sys/arch/x86/x86/x86_machdep.c 1.104,1.106,1.108 (patch)
sys/arch/x86/x86/svs.c 1.1-1.14
sys/arch/xen/conf/files.compat 1.30 (patch)

Backport SVS. Not enabled yet.
 1.5.2.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.12 07-May-2012  jym Merge i386 and amd64 version of db_memrw.c.

Use this opportunity to skip calculating the VA of the page. Let the CPU
deal with the invalidation itself through invlpg + destination address to
avoid converting between canonical/non canonical forms.
 1.11 07-May-2012  jym invlpg on a non canonical address is a noop, so no chance to invalidate
the TLB and the CPU will not notice the access right change.

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

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

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

XXX this is the patch that will be pulled-up to -5 and -6.
 1.10 07-May-2012  jym Use the current destination address to compute PTE, not the address of
origin.

Harmless, except when db_write_text() passes a page boundary.

From Bug Hunting.

XXX has to be pulled up to -5 and -6.
 1.9 23-Nov-2011  jym branches: 1.9.2; 1.9.4;
Kill dependency to xpmap_update(), and use setbits/clearbits to update
kernel PTE rights.
 1.8 20-Dec-2010  matt branches: 1.8.8;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.
 1.7 29-Jan-2009  joerg branches: 1.7.2; 1.7.6;
Match mem.c's extern for __data_start.
 1.6 28-Apr-2008  martin branches: 1.6.8; 1.6.10;
Remove clause 3 and 4 from TNF licenses
 1.5 22-Nov-2007  bouyer branches: 1.5.14; 1.5.16; 1.5.18;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.4 18-Oct-2007  yamt branches: 1.4.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.3 11-Dec-2005  christos branches: 1.3.30; 1.3.48; 1.3.50; 1.3.52; 1.3.54;
merge ktrace-lwp.
 1.2 01-Jun-2005  drochner branches: 1.2.2;
adapt to ddb constification
 1.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.2.1 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.2.2.2 07-Dec-2007  yamt sync with head
 1.2.2.1 27-Oct-2007  yamt sync with head.
 1.3.54.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.3.54.1 17-Oct-2007  bouyer amd64 (aka x86-64) support for Xen. Based on the OpenBSD port done by
Mathieu Ropert in 2006.
DomU-only for now. An INSTALL_XEN3_DOMU kernel with a ramdisk will boot to
sysinst if you're lucky. Often it panics because a runable LWP has
a NULL stack (really, it's all of l->l_addr which is has been zeroed out
while the process was on the queue !)
TODO:
- bug fixes :)
- Most of the xpq_* functions should be shared with xen/i386
- The xen/i386 assembly bootstrap code should be remplaced with the C
version in xenamd64/amd64/xpmap.c
- see if a config(5) trick could allow to merge xenamd64 back to xen or amd64.
 1.3.52.3 04-Oct-2007  yamt remove LARGEPAGES option. always use large pages if available.
 1.3.52.2 04-Oct-2007  yamt - move etext before rodata. define __data_start at the start of
.data section and use it instead of etext where appropriate.
- put .rodata.* into .rodata section as well.
- pmap_bootstrap: don't assume NBPD_L2 alignment.
- pmap_bootstrap: if DEBUG, print how many large pages and normal pages are
used to map kernel text.
 1.3.52.1 01-Oct-2007  yamt - fix LARGEPAGES.
- add amd64 linker script for it.
 1.3.50.2 09-Jan-2008  matt sync with HEAD
 1.3.50.1 06-Nov-2007  matt sync with HEAD
 1.3.48.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.3.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.3.30.3 03-Dec-2007  ad Sync with HEAD.
 1.3.30.2 03-Dec-2007  ad Sync with HEAD.
 1.3.30.1 23-Oct-2007  ad Sync with head.
 1.4.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.5.18.2 04-May-2009  yamt sync with head.
 1.5.18.1 16-May-2008  yamt sync with head.
 1.5.16.1 18-May-2008  yamt sync with head.
 1.5.14.1 02-Jun-2008  mjf Sync with HEAD.
 1.6.10.1 19-May-2012  riz Pull up following revision(s) (requested by jym in ticket #1754):
sys/arch/amd64/amd64/db_memrw.c: revision 1.10
sys/arch/amd64/amd64/db_memrw.c: revision 1.11
sys/arch/i386/i386/db_memrw.c: revision 1.29
Use the current destination address to compute PTE, not the address of
origin.
Harmless, except when db_write_text() passes a page boundary.
From Bug Hunting.
XXX has to be pulled up to -5 and -6.
invlpg on a non canonical address is a noop, so no chance to invalidate
the TLB and the CPU will not notice the access right change.
This results in write protection faults in supervisor mode when patching
kernel code through ddb(4) (originally mapped as read only).
Bug reported by David Laight on port-amd64@ (thanks!), patch and test by
me.
i386 is unaffected as PG_LGFRAME does not mask the sign bits. For the
sake of correctness, use VA_SIGN_NEG(...) anyway.
XXX this is the patch that will be pulled-up to -5 and -6.
 1.6.8.1 03-Mar-2009  skrll Sync with HEAD.
 1.7.6.1 05-Mar-2011  rmind sync with head
 1.7.2.1 10-Jan-2011  jym Sync with HEAD
 1.8.8.2 23-May-2012  yamt sync with head.
 1.8.8.1 17-Apr-2012  yamt sync with head
 1.9.4.1 09-May-2012  riz Pull up following revision(s) (requested by jym in ticket #233):
sys/arch/amd64/amd64/db_memrw.c: revision 1.10
sys/arch/amd64/amd64/db_memrw.c: revision 1.11
sys/arch/i386/i386/db_memrw.c: revision 1.29
Use the current destination address to compute PTE, not the address of
origin.
Harmless, except when db_write_text() passes a page boundary.
From Bug Hunting.
XXX has to be pulled up to -5 and -6.
invlpg on a non canonical address is a noop, so no chance to invalidate
the TLB and the CPU will not notice the access right change.
This results in write protection faults in supervisor mode when patching
kernel code through ddb(4) (originally mapped as read only).
Bug reported by David Laight on port-amd64@ (thanks!), patch and test by
me.
i386 is unaffected as PG_LGFRAME does not mask the sign bits. For the
sake of correctness, use VA_SIGN_NEG(...) anyway.
XXX this is the patch that will be pulled-up to -5 and -6.
 1.9.2.1 02-Jun-2012  mrg sync to latest -current.
 1.19 10-Apr-2011  christos Merge db_trace for x86. From: Vladimir Kirillov proger at wilab dot org dot ua
 1.18 01-Jul-2010  rmind branches: 1.18.2;
Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.
 1.17 21-Nov-2009  rmind branches: 1.17.2; 1.17.4;
Use lwp_getpcb() on x86 MD code, clean from struct user usage.
 1.16 21-Oct-2009  rmind Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.
 1.15 15-Mar-2009  cegger ansify function definitions
 1.14 05-Sep-2008  tron branches: 1.14.2; 1.14.8;
Compile NetBSD/amd64 kernels with "-Wextra". Patches contributed by
Juan RP in PR port-amd64/39266.
 1.13 02-Jul-2008  rmind branches: 1.13.2;
Remove proc_representative_lwp(), use a simple LIST_FIRST() instead.
OK by <ad>.
 1.12 22-Dec-2007  dsl branches: 1.12.6; 1.12.10; 1.12.12; 1.12.14;
Define 'struct intrframe' in terms of 'struct trapframe' since the two are
assumed to match by a lot of code (including that which saves the regs).
This only slightly reduces the number of places the trapframe register
layout is defined.
 1.11 22-Feb-2007  thorpej branches: 1.11.22; 1.11.30; 1.11.34;
TRUE -> true, FALSE -> false
 1.10 21-Feb-2007  thorpej Pick up some additional files that were missed before due to conflicts
with newlock2 merge:

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.9 20-Feb-2007  ad - Add /a modifier to trace that allows a specific LWP to be selected.
- When doing trace/t, always note which pid/lid combination is being traced.
 1.8 17-Feb-2007  pavel Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.
 1.7 09-Feb-2007  ad branches: 1.7.2;
Merge newlock2 to head.
 1.6 06-Sep-2006  ad branches: 1.6.2;
Use p_find(addr, PFIND_LOCKED) in case the proclist_lock is held.
 1.5 11-Dec-2005  christos branches: 1.5.4; 1.5.8;
merge ktrace-lwp.
 1.4 01-Jun-2005  blymn branches: 1.4.2;
Function declarations did not match prototypes, fix.
 1.3 16-Apr-2004  fvdl Make tracing work better (through interrupts, etc). Essentially a synch
with i386.
 1.2 22-Oct-2003  fvdl Remove use of NULL as an integer value.
 1.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.2.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 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.2.3 21-Jan-2008  yamt sync with head
 1.4.2.2 26-Feb-2007  yamt sync with head.
 1.4.2.1 30-Dec-2006  yamt sync with head.
 1.5.8.1 14-Sep-2006  yamt sync with head.
 1.5.4.1 09-Sep-2006  rpaulo sync with head
 1.6.2.1 21-Oct-2006  ad Update for proc_representative_lwp() / calcru() signature change.
 1.7.2.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.11.34.1 02-Jan-2008  bouyer Sync with HEAD
 1.11.30.1 26-Dec-2007  ad Sync with head.
 1.11.22.1 09-Jan-2008  matt sync with HEAD
 1.12.14.1 03-Jul-2008  simonb Sync with head.
 1.12.12.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.12.10.3 11-Aug-2010  yamt sync with head.
 1.12.10.2 11-Mar-2010  yamt sync with head
 1.12.10.1 04-May-2009  yamt sync with head.
 1.12.6.1 28-Sep-2008  mjf Sync with HEAD.
 1.13.2.1 19-Oct-2008  haad Sync with HEAD.
 1.14.8.4 02-May-2011  jym Sync with head.
 1.14.8.3 24-Oct-2010  jym Sync with HEAD
 1.14.8.2 01-Nov-2009  jym Sync with HEAD.
 1.14.8.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.14.2.1 28-Apr-2009  skrll Sync with HEAD.
 1.17.4.2 21-Apr-2011  rmind sync with head
 1.17.4.1 03-Jul-2010  rmind sync with head
 1.17.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.18.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.10 18-Dec-2005  yamt remove an unused file.
 1.9 11-Dec-2005  christos merge ktrace-lwp.
 1.8 08-Oct-2003  lukem branches: 1.8.16;
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.7 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.6 14-Jul-2003  lukem __KERNEL_RCSID()
 1.5 10-May-2003  thorpej branches: 1.5.2;
Change bounds_check_with_label() to take a pointer to the disk structure,
rather than the label itself. This paves the way for some future changes.
 1.4 08-May-2003  fvdl Revert previous until I look at some issues regarding default labels.
 1.3 07-May-2003  fvdl Don't whine if no disklabel was found, it's not a fatal error. Follows
Jason's commit to the ARM disksubr.c
 1.2 02-May-2003  dsl Change return type of readdisklabel() to const char *
I hope I've found all the correct places!
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.5.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.5.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.5.2.1 03-Aug-2004  skrll Sync with HEAD
 1.8.16.1 21-Jun-2006  yamt sync with head.
 1.49 11-Feb-2014  dsl Move sys/arch/amd64/amd64/fpu.c and sys/arch/amd64/include/fpu.h
into sys/arch/x86 in preparation for using the same code for i386.
 1.48 09-Feb-2014  dsl Steal the table from i386/isa/npx.c than selects the highest priority
floating point error when raising a signal.
Multiple errors bits can easily be set if different sub-fields of an
xmm simd operation generate different errors.
 1.47 09-Feb-2014  dsl Simplify fputrap() considerably.
There is no need to save the fpu state here, and definitely no need
to initialise the fpu.
The code is running with interrupts disabled having trapped on either
an x87 instruction (the one after the one that generated the error)
or on an SSE (etc) instruction that caused the error.
So all it needs to do it obtain the 'error' bits from the relevant
status register, clear the bits, and then raise any signal.
The signal code will save the fp state if the signal itself isn't masked.
It also passes the FP state to the signal handler - which can modify it.
(I suspect that wasn't thecase when this code was written.)
Seems to work for both 64bit and 32bit 'divide by zero' errors.
For the xmm trap, the xmm registers are updated for the result of the
instruction, but the trap returns to re-execute the instruction!
This makes it difficult for the signal handler to do anything sensible.

I've also changed the code to only use unmasked error bits when deciding
the signal code.
 1.46 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.45 04-Feb-2014  dsl There is no need to check for recursive calls into fpudna().
Rename the associated ci_fpsaving field to 'unused'.
I'm not sure they could ever happen, you could get unwanted calls into
the fpu trap code while saving state when using INT13 - but these are
different.
The return value from the i386 fpudna() was always 1 - possibly a historic
relic of the kernel fp emulation. Remove and don't check in trap.S.
The amd64 and i386 fpudna() code is now almost identical.
 1.44 11-Dec-2013  dsl Remove the fields that were used to save the i387 fp state on interrupt.
They were written but never read.
Possibly they should be saved for 32 bit processes, but that might be a relic
from real i387 where the fpu was actully asynchronous.
 1.43 01-Dec-2013  christos revert fpu/pcu changes until we figure out what's wrong; they cause random
freezes
 1.42 27-Oct-2013  rmind - fpu_state_save() on amd64: ci->ci_fpsaving is no longer used, simplify.
- Remove some unnecessary header inclusions. Misc clean up while here.
 1.41 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.40 31-Dec-2012  dsl branches: 1.40.2;
Move the two fields used to save some i387 state on the last fpu trap
into their own sub-structure of the pcb (from 'struct savefpu').
They only (seem) to be used in some code that generates core dumps
for 32bit processes (code that might be broken as well!).
'struct safefpu' is now identical to 'struct fxsave64'. One (or both)
needs extending to support AVX - might need to be dynamically sized.
Removed all the __aligned(16) except for the one in struct pcb itself.
Only the copy used for the fsave instruction need be aligned.
 1.39 08-Jul-2012  dsl branches: 1.39.2;
The MDP_USEDFPU (amd64 and sh3) and MDP_SSTEP (sh3) are lwp flags not
process ones, rename to MDL_xxx.
 1.38 11-Aug-2011  cherry branches: 1.38.2;
unbreak the build. #include <sys/cpu.h>
 1.37 11-Aug-2011  cherry More appropriate use of xen_send_ipi().
 1.36 10-Aug-2011  cherry xen ipi infrastructure
 1.35 01-Jul-2011  dyoung #include <sys/bus.h> instead of <machine/bus.h>.
 1.34 07-Mar-2011  cherry branches: 1.34.2;
Use macros clts/stts instead of directly manipulating CR0 flags.
Expose fpuinit to XEN build. (remove #ifdef XEN)
 1.33 20-Dec-2010  matt branches: 1.33.2;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.
 1.32 21-Nov-2009  rmind branches: 1.32.4;
Use lwp_getpcb() on x86 MD code, clean from struct user usage.
 1.31 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.30 25-Nov-2008  ad branches: 1.30.4;
fpudna: enable interrupts in an error path.
 1.29 11-Nov-2008  ad PR port-i386/39299 FPU use in signal handlers is unsafe
 1.28 11-Nov-2008  ad PR port-amd64/38293 panic: fp_save ipi didn't

Fix race conditions in FPU IPI handling.
 1.27 11-Nov-2008  ad PR port-amd64/38293 panic: fp_save ipi didn't

Kill the FP flush IPI and always save. The synchronization here isn't strong
and we could easily pull the chain on an innocent LWP's FP state.

Another fix to follow.
 1.26 29-Jun-2008  bouyer branches: 1.26.2; 1.26.4; 1.26.6;
Proper FPU exeptions support for Xen. Should fix FPU issues reported by
various users.
 1.25 30-May-2008  ad branches: 1.25.2;
PR kern/38663 Kernel preemption can't be enabled on x86 because of amd64
FPU handling

Adjust FPU trap handling to be preemption safe.
 1.24 30-Apr-2008  cegger branches: 1.24.2;
AMD's APM Volume 2 says 'All control registers are 64bit in long mode'.
Fix the CR0 prototype to match this (the asm implementation is correct though).
OK ad
 1.23 16-Apr-2008  cegger branches: 1.23.2; 1.23.4;
use POSIX integer types
 1.22 15-Jan-2008  joerg branches: 1.22.6;
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.21 02-Jan-2008  ad Merge vmlocking2 to head.
 1.20 22-Nov-2007  bouyer branches: 1.20.2; 1.20.6;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.19 17-Oct-2007  garbled branches: 1.19.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.18 26-Sep-2007  ad branches: 1.18.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.17 09-Feb-2007  ad branches: 1.17.6; 1.17.14; 1.17.22; 1.17.24; 1.17.26;
Merge newlock2 to head.
 1.16 21-May-2006  christos branches: 1.16.6;
Put the __insn_barrier() inside the spinloop for the DIAGNOSTIC case, so
that we have a barrier for the DIAGNOSTIC case too.
 1.15 20-Apr-2006  christos branches: 1.15.2;
Make this compile again.
 1.14 19-Apr-2006  christos Apply fix from FreeBSD's advisory: fxrstor on AMD FPU's does not restore
FIP,FDP,FOP thus leaking other process's execution history.
 1.13 11-Dec-2005  christos branches: 1.13.4; 1.13.6; 1.13.8; 1.13.10; 1.13.12;
merge ktrace-lwp.
 1.12 31-Oct-2004  yamt branches: 1.12.10; 1.12.12; 1.12.20;
use __insn_barrier rather than homegrown equivalents.
 1.11 05-Mar-2004  drochner branches: 1.11.2; 1.11.4; 1.11.6;
-oops - correct the x87 si_code reporting to use the current fsw
-for XMM traps, report mxcsr in si_trap
 1.10 05-Mar-2004  drochner deal with XMM exceptions
(I'm not sure whether it is right to clear the "sticky"
exception bits here, but in the i387 case even the whole
FPU is initialized...)
 1.9 03-Mar-2004  drochner fix some problems with lazy fpu context handling:
-if a new process gets a CPU with an FPU state of another process, it
needs to initialize it to a clean state
(actually, put the "fninit" where it belongs logically)
-initialize mxcsr as well
minor cleanup/optimization
Signal delivery after unmasking some cause is still broken - it doesn't
care about xmm exceptions. For now, set at least si_code to something
positive so that it doesn't look like a user generated asynchonous signal.
 1.8 19-Oct-2003  cl don't uvm_swapout LWPs which are LSONPROC on another cpu.

uvm_swapout_threads will swapout LWPs which are running on another CPU:
- uvm_swapout_threads considers LWPs running on another CPU for swapout
if their l_swtime is high
- uvm_swapout_threads considers LWPs on the runqueue for swapout if their
l_swtime is high but these LWPs might be running by the time uvm_swapout
is called

symptoms of failure: panic in setrunqueue

fixes PR kern/23095
 1.7 08-Oct-2003  fvdl Do proper FPU trap reporting for SIGFPE, copied from the i386 port.
 1.6 08-Oct-2003  thorpej Use KSI_INIT_TRAP().
 1.5 06-Oct-2003  fvdl SIGINFO support.
Todo: 32bit compat support (COMPAT_NETBSD32 will not compile right now,
as it won't on other platforms).
 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 14-Jul-2003  lukem __KERNEL_RCSID()
 1.2 23-Jun-2003  martin branches: 1.2.2;
Make sure to include opt_foo.h if a defflag option FOO is used.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.2.2.4 02-Nov-2004  skrll Sync with HEAD.
 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.11.6.2 12-May-2006  tron Pull up following revision(s) (requested by adrianp in ticket #10553):
sys/arch/amd64/amd64/fpu.c: revision 1.15
Make this compile again.
 1.11.6.1 12-May-2006  tron Pull up following revision(s) (requested by adrianp in ticket #10553):
sys/arch/amd64/amd64/fpu.c: revision 1.14
sys/arch/i386/isa/npx.c: revision 1.112
Apply fix from FreeBSD's advisory: fxrstor on AMD FPU's does not restore
FIP,FDP,FOP thus leaking other process's execution history.
 1.11.4.2 12-May-2006  tron Pull up following revision(s) (requested by adrianp in ticket #10553):
sys/arch/amd64/amd64/fpu.c: revision 1.15
Make this compile again.
 1.11.4.1 12-May-2006  tron Pull up following revision(s) (requested by adrianp in ticket #10553):
sys/arch/amd64/amd64/fpu.c: revision 1.14
sys/arch/i386/isa/npx.c: revision 1.112
Apply fix from FreeBSD's advisory: fxrstor on AMD FPU's does not restore
FIP,FDP,FOP thus leaking other process's execution history.
 1.11.2.2 12-May-2006  tron Pull up following revision(s) (requested by adrianp in ticket #10553):
sys/arch/amd64/amd64/fpu.c: revision 1.15
Make this compile again.
 1.11.2.1 12-May-2006  tron Pull up following revision(s) (requested by adrianp in ticket #10553):
sys/arch/amd64/amd64/fpu.c: revision 1.14
sys/arch/i386/isa/npx.c: revision 1.112
Apply fix from FreeBSD's advisory: fxrstor on AMD FPU's does not restore
FIP,FDP,FOP thus leaking other process's execution history.
 1.12.20.2 12-May-2006  tron Pull up following revision(s) (requested by adrianp in ticket #1321):
sys/arch/amd64/amd64/fpu.c: revision 1.15
Make this compile again.
 1.12.20.1 12-May-2006  tron Pull up following revision(s) (requested by adrianp in ticket #1321):
sys/arch/amd64/amd64/fpu.c: revision 1.14
sys/arch/i386/isa/npx.c: revision 1.112
Apply fix from FreeBSD's advisory: fxrstor on AMD FPU's does not restore
FIP,FDP,FOP thus leaking other process's execution history.
 1.12.12.5 21-Jan-2008  yamt sync with head
 1.12.12.4 07-Dec-2007  yamt sync with head
 1.12.12.3 27-Oct-2007  yamt sync with head.
 1.12.12.2 26-Feb-2007  yamt sync with head.
 1.12.12.1 21-Jun-2006  yamt sync with head.
 1.12.10.2 12-May-2006  tron Pull up following revision(s) (requested by adrianp in ticket #1321):
sys/arch/amd64/amd64/fpu.c: revision 1.15
Make this compile again.
 1.12.10.1 12-May-2006  tron Pull up following revision(s) (requested by adrianp in ticket #1321):
sys/arch/amd64/amd64/fpu.c: revision 1.14
sys/arch/i386/isa/npx.c: revision 1.112
Apply fix from FreeBSD's advisory: fxrstor on AMD FPU's does not restore
FIP,FDP,FOP thus leaking other process's execution history.
 1.13.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.13.10.1 11-May-2006  elad sync with head
 1.13.8.1 24-May-2006  yamt sync with head.
 1.13.6.2 01-Jun-2006  kardel 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.15.2.1 19-Jun-2006  chap Sync with head.
 1.16.6.2 11-Jan-2007  ad Checkpoint work in progress.
 1.16.6.1 17-Nov-2006  ad Checkpoint work in progress.
 1.17.26.1 06-Oct-2007  yamt sync with head.
 1.17.24.3 23-Mar-2008  matt sync with HEAD
 1.17.24.2 09-Jan-2008  matt sync with HEAD
 1.17.24.1 06-Nov-2007  matt sync with HEAD
 1.17.22.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.17.22.1 02-Oct-2007  joerg Sync with HEAD.
 1.17.14.1 03-Oct-2007  garbled Sync with HEAD
 1.17.6.3 03-Dec-2007  ad Sync with HEAD.
 1.17.6.2 03-Dec-2007  ad Sync with HEAD.
 1.17.6.1 09-Oct-2007  ad Sync with head.
 1.18.2.1 17-Oct-2007  bouyer amd64 (aka x86-64) support for Xen. Based on the OpenBSD port done by
Mathieu Ropert in 2006.
DomU-only for now. An INSTALL_XEN3_DOMU kernel with a ramdisk will boot to
sysinst if you're lucky. Often it panics because a runable LWP has
a NULL stack (really, it's all of l->l_addr which is has been zeroed out
while the process was on the queue !)
TODO:
- bug fixes :)
- Most of the xpq_* functions should be shared with xen/i386
- The xen/i386 assembly bootstrap code should be remplaced with the C
version in xenamd64/amd64/xpmap.c
- see if a config(5) trick could allow to merge xenamd64 back to xen or amd64.
 1.19.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.19.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.20.6.2 19-Jan-2008  bouyer Sync with HEAD
 1.20.6.1 02-Jan-2008  bouyer Sync with HEAD
 1.20.2.1 04-Dec-2007  ad Pull the vmlocking changes into a new branch.
 1.22.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.22.6.2 02-Jul-2008  mjf Sync with HEAD.
 1.22.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.23.4.3 11-Mar-2010  yamt sync with head
 1.23.4.2 04-May-2009  yamt sync with head.
 1.23.4.1 16-May-2008  yamt sync with head.
 1.23.2.2 04-Jun-2008  yamt sync with head
 1.23.2.1 18-May-2008  yamt sync with head.
 1.24.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.24.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.25.2.1 03-Jul-2008  simonb Sync with head.
 1.26.6.4 25-Nov-2008  snj Pull up following revision(s) (requested by ad in ticket #127):
sys/arch/amd64/amd64/fpu.c: revision 1.30
fpudna: enable interrupts in an error path.
 1.26.6.3 20-Nov-2008  snj Pull up following revision(s) (requested by ad in ticket #71):
sys/arch/i386/isa/npx.c: revision 1.132
sys/arch/amd64/amd64/fpu.c: revision 1.29
sys/arch/amd64/amd64/machdep.c: revision 1.105
sys/arch/i386/i386/machdep.c: revision 1.647
PR port-i386/39299 FPU use in signal handlers is unsafe
 1.26.6.2 17-Nov-2008  snj Pull up following revision(s) (requested by ad in ticket #74):
sys/arch/i386/isa/npx.c: revision 1.131
sys/arch/amd64/amd64/fpu.c: revision 1.28
sys/arch/i386/i386/genassym.cf: revision 1.77
sys/arch/i386/i386/autoconf.c: revision 1.93
sys/arch/amd64/amd64/locore.S: revision 1.48
sys/arch/amd64/amd64/machdep.c: revision 1.104
sys/arch/i386/i386/machdep.c: revision 1.646
sys/arch/amd64/amd64/genassym.cf: revision 1.38
sys/arch/i386/i386/locore.S: revision 1.79
PR port-amd64/38293 panic: fp_save ipi didn't
Fix race conditions in FPU IPI handling.
 1.26.6.1 17-Nov-2008  snj Pull up following revision(s) (requested by ad in ticket #73):
sys/arch/amd64/amd64/fpu.c: revision 1.27
sys/arch/amd64/amd64/ipifuncs.c: revision 1.20
sys/arch/i386/i386/ipifuncs.c: revision 1.28
sys/arch/i386/isa/npx.c: revision 1.130
sys/arch/x86/include/intrdefs.h: revision 1.14
PR port-amd64/38293 panic: fp_save ipi didn't
Kill the FP flush IPI and always save. The synchronization here isn't
strong and we could easily pull the chain on an innocent LWP's FP state.
Another fix to follow.
 1.26.4.2 28-Apr-2009  skrll Sync with HEAD.
 1.26.4.1 19-Jan-2009  skrll Sync with HEAD.
 1.26.2.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.30.4.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.30.4.5 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.30.4.4 10-Jan-2011  jym Sync with HEAD
 1.30.4.3 24-Oct-2010  jym Sync with HEAD
 1.30.4.2 01-Nov-2009  jym Sync with HEAD.
 1.30.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.32.4.2 21-Apr-2011  rmind sync with head
 1.32.4.1 05-Mar-2011  rmind sync with head
 1.33.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.34.2.2 21-Oct-2011  bouyer Make this build without 'options MULTIPROCESSOR'
 1.34.2.1 03-Jun-2011  cherry Initial import of xen MP sources, with kernel and userspace tests.
- this is a source priview.
- boots to single user.
- spurious interrupt and pmap related panics are normal
 1.38.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.38.2.2 23-Jan-2013  yamt sync with head
 1.38.2.1 30-Oct-2012  yamt sync with head
 1.39.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.39.2.1 25-Feb-2013  tls resync with head
 1.40.2.1 18-May-2014  rmind sync with head
 1.48 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.47 09-Mar-2019  maxv Start replacing the x86 PTE bits.
 1.46 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.45 05-Jan-2018  maxv branches: 1.45.4;
Add a __HAVE_PCPU_AREA option, enabled by default on native amd64 but not
Xen.

With this option, the CPU structures that must always be present in the
CPU's page tables are moved on L4 slot 384, which means address
0xffffc00000000000.

A new pcpu_area structure is defined. It contains shared structures (IDT,
LDT), and then an array of pcpu_entry structures, indexed by cpu_index(ci).
Theoretically the LDT should be in the array, but this will be done later.

During the boot procedure, cpu0 calls pmap_init_pcpu, which creates a
page tree that is able to map the pcpu_area structure entirely. cpu0 then
immediately maps the shared structures. Later, every CPU goes through
cpu_pcpuarea_init, which allocates physical pages and kenters the relevant
pcpu_entry to them. Finally, each pointer is replaced to point to pcpuarea.

The point of this change is to make sure that the structures that must
always be present in the page tables have their own L4 slot. Until now
their L4 slot was that of pmap_kernel, and making a distinction between
what must be mapped and what does not need to be was complicated.

Even in the non-speculative-bug case this change makes some sense: there
are several x86 instructions that leak the addresses of the CPU structures,
and putting these structures inside pmap_kernel actually offered a way to
compute the address of the kernel heap - which would have made ASLR on it
plainly useless, had we implemented that.

Note that, for now, pcpuarea does not contain rsp0.

Unfortunately this change adds many #ifdefs, and makes the code harder to
understand. There is also some duplication, but that will be solved later.
 1.44 04-Jan-2018  maxv Declare gdt_size as const, simplifies.
 1.43 10-Sep-2017  maxv simplify
 1.42 06-Sep-2017  bouyer The last GDT slots are reserved for Xen, so use FIRST_RESERVED_GDT_BYTE
instead of MAXGDTSIZ for gdt_size.
Xen kernels should boot again.
 1.41 02-Sep-2017  maxv Fix a subtle ring0 escalation vulnerability in amd64, and implement a
mitigation against similar bugs.

The operations on segment registers can generate a page fault if there is
an issue when touching the in-memory gdt. Theoretically, it is never
supposed to happen, since the gdt is mapped correctly. However, in the
kernel we allow the gdt to be resized, and to do that, we allocate the
maximum amount of va needed by it, but only kenter a few pages until we
need more. Moreover, to avoid reloading the gdt each time we grow it, the
'size' field of gdtr is set to the maximum value. All of this means that
if a mov or iretq is done with a segment register whose index hits a page
that has not been kentered, a page fault is sent.

Such a page fault, if received in kernel mode, does not trigger a swapgs
on amd64; in other words, the kernel would be re-entered with the userland
tls.

And there just happens to be a place in compat_linux32 where the index of
%cs is controlled by userland, making it easy to trigger the page fault
and get kernel privileges.

The mitigation simply consists in abandoning the gdt_grow mechanism and
allocating/kentering the maximum size right away, in such a way that no
page fault can be triggered because of segment registers.
 1.40 02-Jul-2017  maxv Put some ()s in the macro (kre).
 1.39 02-Jul-2017  maxv Hide the computation in a macro.
 1.38 25-Mar-2017  maxv branches: 1.38.6;
Use a bitmap-based allocator, will be easier to share with i386.
 1.37 08-Feb-2017  kre All bow down before the Great Code Compiler.

Specifically, it has been commanded that unused-functions is a warning,
and, as all should know, all warnings be errors.

Hence, since XEN kernels do not call set_sys_gdt(), that function
may not be included (and the XEN kernel saves a few tens of bytes.)

An alternate fix would be to just remove "static" - but that would be
the equivalent to just giving the compiler the finger ... hmm, maybe
that would have been a better fix...
 1.36 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.35 08-Feb-2017  maxv Localify, add a comment and merge some others.
 1.34 21-Aug-2016  maxv branches: 1.34.2;
Simplify gdt_grow, and make sure we don't kenter more than has been
virtually allocated.
 1.33 21-Aug-2016  maxv Use KASSERT, and panic by default instead of allowing the area to overflow.
 1.32 21-Aug-2016  maxv Explain a little what we are doing. Also, make sure gdt_init_cpu is called
on the currently running CPU. Theoretically, we could put the same KASSERT
in gdt_reload_cpu, but the associated IPI is never sent, which is another
issue.
 1.31 21-Aug-2016  christos fix the build.
 1.30 20-Aug-2016  maxv Make this area compile, even if we don't support USER_LDT on amd64.
 1.29 20-Aug-2016  maxv The GDT needs to be grown on each CPU, and not just gdtstore (cpu0).
Otherwise, if the caller gets switched to another CPU, the kernel will
end up accessing unallocated memory.

Currently, it never happens. The same is done in i386.
 1.28 20-Aug-2016  christos fix the build.
 1.27 20-Aug-2016  maxv Localify.
 1.26 22-Nov-2015  maxv branches: 1.26.2;
KNF a bit, so I don't get scared each time I open a file
 1.25 16-Oct-2013  christos branches: 1.25.6;
remove unused
 1.24 07-Jul-2010  chs branches: 1.24.8; 1.24.18; 1.24.22;
add the guts of TLS support on amd64. based on joerg's patch,
reworked by me to support 32-bit processes as well.
we now keep %fs and %gs loaded with the user values
while in the kernel, which means we don't need to
reload them when returning to user mode.
 1.23 21-Nov-2009  rmind branches: 1.23.2; 1.23.4;
Use lwp_getpcb() on x86 MD code, clean from struct user usage.
 1.22 07-Nov-2009  cegger Add a flags argument to pmap_kenter_pa(9).
Patch showed on tech-kern@ http://mail-index.netbsd.org/tech-kern/2009/11/04/msg006434.html
No objections.
 1.21 21-Mar-2009  ad 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.20 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.19 11-May-2008  ad branches: 1.19.6; 1.19.8; 1.19.12;
Share cpu.h between the x86 ports.
 1.18 28-Apr-2008  martin branches: 1.18.2;
Remove clause 3 and 4 from TNF licenses
 1.17 16-Apr-2008  cegger branches: 1.17.2; 1.17.4;
use POSIX integer types
 1.16 05-Jan-2008  yamt branches: 1.16.6;
- make amd64 use per-cpu tss.
- fix iopl syscall for amd64+xen.
 1.15 06-Dec-2007  ad branches: 1.15.4;
lockmgr -> mutex
 1.14 22-Nov-2007  bouyer branches: 1.14.2;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 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 29-Aug-2007  ad branches: 1.12.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.11 04-Jun-2007  xtraeme branches: 1.11.4; 1.11.8; 1.11.10;
Ansify, de-__P(), unregister.
 1.10 22-Feb-2007  thorpej branches: 1.10.4; 1.10.6; 1.10.8; 1.10.12;
TRUE -> true, FALSE -> false
 1.9 24-Dec-2005  perry branches: 1.9.26;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.8 11-Dec-2005  christos merge ktrace-lwp.
 1.7 01-Apr-2005  yamt branches: 1.7.2;
merge yamt-km branch.
- don't use managed mappings/backing objects for wired memory allocations.
save some resources like pv_entry. also fix (most of) PR/27030.
- simplify kernel memory management API.
- simplify pmap bootstrap of some ports.
- some related cleanups.
 1.6 08-Feb-2005  fvdl if 0 out the parts of the code that allocated VM space per CPU for GDTs.
Seperate GDTs are not used on amd64 because it doesn't need any seperate
descriptors per CPU.
 1.5 16-Jun-2004  fvdl branches: 1.5.4; 1.5.6;
When converting GDT length units from segment structures to bytes for the
amd64 port, I converted MINGDTSIZ wrongly; it was not page aligned, causing
gdt_grow to corrupt the GDT. Fix this, and remove the extraneous definitions
of the sizes from gdt.c.

From OpenBSD.
 1.4 13-Feb-2004  wiz branches: 1.4.2;
Uppercase CPU, plural is CPUs.
 1.3 14-Jul-2003  lukem __KERNEL_RCSID()
 1.2 23-Jun-2003  martin branches: 1.2.2;
Make sure to include opt_foo.h if a defflag option FOO is used.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.2.2.5 01-Apr-2005  skrll Sync with HEAD.
 1.2.2.4 09-Feb-2005  skrll Sync with HEAD.
 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.4.2.1 17-Jun-2004  tron Pull up revision 1.5 (requested by fvdl in ticket #506):
When converting GDT length units from segment structures to bytes for the
amd64 port, I converted MINGDTSIZ wrongly; it was not page aligned, causing
gdt_grow to corrupt the GDT. Fix this, and remove the extraneous definitions
of the sizes from gdt.c.
From OpenBSD.
 1.5.6.2 13-Feb-2005  yamt - use new apis.
- simplify pmap bootstrap and pv_page allocation.
 1.5.6.1 12-Feb-2005  yamt sync with head.
 1.5.4.1 29-Apr-2005  kent sync with -current
 1.7.2.5 21-Jan-2008  yamt sync with head
 1.7.2.4 07-Dec-2007  yamt sync with head
 1.7.2.3 03-Sep-2007  yamt sync with head.
 1.7.2.2 26-Feb-2007  yamt sync with head.
 1.7.2.1 21-Jun-2006  yamt sync with head.
 1.9.26.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.10.12.2 03-Oct-2007  garbled Sync with HEAD
 1.10.12.1 26-Jun-2007  garbled Sync with HEAD.
 1.10.8.1 09-Dec-2007  reinoud Pullup to HEAD
 1.10.6.1 11-Jul-2007  mjf Sync with head.
 1.10.4.4 03-Dec-2007  ad Sync with HEAD.
 1.10.4.3 03-Dec-2007  ad Sync with HEAD.
 1.10.4.2 23-Aug-2007  ad More calls to pmap_update().
 1.10.4.1 09-Jun-2007  ad Sync with head.
 1.11.10.2 09-Jan-2008  matt sync with HEAD
 1.11.10.1 06-Nov-2007  matt sync with HEAD
 1.11.8.3 09-Dec-2007  jmcneill Sync with HEAD.
 1.11.8.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.11.8.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.11.4.1 03-Sep-2007  skrll Sync with HEAD.
 1.12.4.3 22-Nov-2007  bouyer Disable debug messages
 1.12.4.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.12.4.1 17-Oct-2007  bouyer amd64 (aka x86-64) support for Xen. Based on the OpenBSD port done by
Mathieu Ropert in 2006.
DomU-only for now. An INSTALL_XEN3_DOMU kernel with a ramdisk will boot to
sysinst if you're lucky. Often it panics because a runable LWP has
a NULL stack (really, it's all of l->l_addr which is has been zeroed out
while the process was on the queue !)
TODO:
- bug fixes :)
- Most of the xpq_* functions should be shared with xen/i386
- The xen/i386 assembly bootstrap code should be remplaced with the C
version in xenamd64/amd64/xpmap.c
- see if a config(5) trick could allow to merge xenamd64 back to xen or amd64.
 1.13.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.13.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.14.2.1 08-Dec-2007  ad Sync with head.
 1.15.4.1 08-Jan-2008  bouyer Sync with HEAD
 1.16.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.17.4.4 11-Aug-2010  yamt sync with head.
 1.17.4.3 11-Mar-2010  yamt sync with head
 1.17.4.2 04-May-2009  yamt sync with head.
 1.17.4.1 16-May-2008  yamt sync with head.
 1.17.2.1 18-May-2008  yamt sync with head.
 1.18.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.19.12.3 24-Oct-2010  jym Sync with HEAD
 1.19.12.2 01-Nov-2009  jym Sync with HEAD.
 1.19.12.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.19.8.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.19.6.1 28-Apr-2009  skrll Sync with HEAD.
 1.23.4.1 05-Mar-2011  rmind sync with head
 1.23.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.24.22.1 18-May-2014  rmind sync with head
 1.24.18.2 03-Dec-2017  jdolecek update from HEAD
 1.24.18.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.24.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.25.6.3 28-Aug-2017  skrll Sync with HEAD
 1.25.6.2 05-Oct-2016  skrll Sync with HEAD
 1.25.6.1 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.26.2.2 26-Apr-2017  pgoyette Sync with HEAD
 1.26.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.34.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.38.6.1 16-Mar-2018  martin Pull up the following revisions (via patch), requested by maxv in #635:

sys/arch/amd64/amd64/gdt.c 1.39-1.45 (patch)
sys/arch/amd64/amd64/amd64/machdep.c 1.284,1.287,1.288 (patch)
sys/arch/amd64/amd64/include/param.h 1.23 (patch)
sys/arch/amd64/include/types.h 1.53 (patch)
sys/arch/x86/include/cpu.h 1.87 (patch)
sys/arch/x86/include/pmap.h 1.73,1.74 (patch)
sys/arch/x86/x86/cpu.c 1.142 (patch)
sys/arch/x86/x86/intr.c 1.117 (partial),1.120 (patch)
sys/arch/x86/x86/pmap.c 1.276 (patch)

Initialize ist0 in cpu_init_tss.
Backport __HAVE_PCPU_AREA.
 1.45.4.1 10-Jun-2019  christos Sync with HEAD
 1.99 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.98 02-Dec-2024  bouyer Add support for non-Xen PVH guests to amd64. Patch from
Emile 'iMil' Heitor in PR kern/57813, with some cosmetic tweaks by me.
Tested on bare metal, Xen PV and Xen PVH by me.
 1.97 04-Oct-2023  ad branches: 1.97.6;
Eliminate l->l_ncsw and l->l_nivcsw. From memory think they were added
before we had per-LWP struct rusage; the same is now tracked there.
 1.96 23-Sep-2023  ad Remove unused L_KPRIORITY.
 1.95 03-Mar-2023  riastradh Revert "x86: Add kthread_fpu_enter/exit support, take two."

kthread_fpu_enter/exit changes broke some hardware, unclear why, to
investigate before fixing and reapplying these changes.
 1.94 25-Feb-2023  riastradh x86: Add kthread_fpu_enter/exit support, take two.

This time, make sure to restore the FPU state when switching to a
kthread in the middle of kthread_fpu_enter/exit.

This adds a single predicted-taken branch for the case of kthreads
that are not in kthread_fpu_enter/exit, so it incurs a penalty only
for threads that actually use it. Since it avoids FPU state
switching in kthreads that do use the FPU, namely cgd worker threads,
this should be a net performance win on systems using it and have
negligible impact otherwise.

XXX pullup-10
 1.93 27-Dec-2022  msaitoh Move some definitions. Add comment. No functional change.
 1.92 26-Dec-2022  msaitoh Reduce diff between i386/i386/genassym.cf and amd64/amd64/genassym.cf. NFCI.
 1.91 26-Dec-2022  msaitoh Sort lines. Add comment. No functional change.
 1.90 26-Dec-2022  msaitoh Reduce diff between i386/i386/genassym.cf and amd64/amd64/genassym.cf. NFCI.

- Whitespace fix.
- Sort lines.
 1.89 07-Sep-2022  knakahara branches: 1.89.4;
NetBSD/x86: Raise the number of interrupt sources per CPU from 32 to 56.

There has been no objection for three years.
https://mail-index.netbsd.org/port-amd64/2019/09/22/msg003012.html
Implemented by nonaka@n.o, updated by me.
 1.88 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.87 12-Jun-2022  bouyer XenPV: in cpu_switchto(), reset ci_xen_clockf_usermode/ci_xen_clockf_pc,
in case a clock interrupt is deffered while we're switching lwp.
Fix a (rare) panic:
panic: kernel diagnostic assertion "p != NULL" failed: file "/usr/src/sys/kern/kern_clock.c", line 438
seen when xen_timer_handler() is called from the splx() at the end of
mi_switch()
 1.86 24-May-2022  bouyer Some devices (e.g. ixg in MSI-X mode) don't to have their handlers called
when no interrupt are pending. So add an extra ih_pending field
to struct intrhand, which is incremeted when the handler is not called because
of IPL level and reset to 0 when called. Check this in Xen's resume
assembly to call only handlers that are really pending.
 1.85 16-May-2020  christos Add ACL support for FFS. From FreeBSD.
 1.84 02-May-2020  bouyer Introduce Xen PVH support in GENERIC.
This is compiled in with
options XENPVHVM
x86 changes:
- add Xen section and xen pvh entry points to locore.S. Set vm_guest
to VM_GUEST_XENPVH in this entry point.
Most of the boot procedure (especially page table setup and switch to
paged mode) is shared with native.
- change some x86_delay() to delay_func(), which points to x86_delay() for
native/HVM, and xen_delay() for PVH

Xen changes:
- remove Xen bits from init_x86_64_ksyms() and init386_ksyms()
and move to xen_init_ksyms(), used for both PV and PVH
- set ISA no-legacy-devices property for PVH
- factor out code from Xen's cpu_bootconf() to xen_bootconf()
in xen_machdep.c
- set up a specific pvh_consinit() which starts with printk()
(which uses a simple hypercall that is available early) and switch to
xencons when we can use pmap_kenter_pa().
 1.83 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.82 17-Feb-2020  skrll branches: 1.82.4;
G/C LS{SLEEP,RUN,ONPROC}

LWP status manipulation was moved out of assembly long ago.
 1.81 08-Jan-2020  ad Hopefully fix some problems seen with MP support on non-x86, in particular
where curcpu() is defined as curlwp->l_cpu:

- mi_switch(): undo the ~2007ish optimisation to unlock curlwp before
calling cpu_switchto(). It's not safe to let other actors mess with the
LWP (in particular l->l_cpu) while it's still context switching. This
removes l->l_ctxswtch.

- Move the LP_RUNNING flag into l->l_flag and rename to LW_RUNNING since
it's now covered by the LWP's lock.

- Ditch lwp_exit_switchaway() and just call mi_switch() instead. Everything
is in cache anyway so it wasn't buying much by trying to avoid saving old
state. This means cpu_switchto() will never be called with prevlwp ==
NULL.

- Remove some KERNEL_LOCK handling which hasn't been needed for years.
 1.80 30-Dec-2019  thorpej branches: 1.80.2;
Fix a problem with intr_unmask() that can cause a forever-loop:
- When handling the source-is-masked case in the interrupt vector, set the
interrupt bit in a new ci_imasked field and ensure the bit is cleared
from ci_ipending.
- In intr_unmask(), transfer the bit from ci_imasked to ci_ipending for
non-level-sensitive interrupts (the PIC does the work for us in the
level-sensitive case), and only force pending interrupts to be processed
in this case. (In all cases, make sure the now-unmasked bit is cleared
from ci_imasked.)

Before, the bit was left in ci_ipending so as not to use edge-triggered
interrupts while the source is masked, but Xspllower() relies on the
pending bits getting cleared.

Tested by forcing all wm(4) interrupts on my test system though an
intr_mask() / softint / intr_unmask() cycle and exercising the network
heavily.
 1.79 22-Dec-2019  thorpej Add intr_mask() and corresponding intr_unmask() calls that allow specific
interrupt lines / sources to be masked as needed (rather than making a
set of sources by IPL as with spl*()).
 1.78 21-Nov-2019  ad x86: abort pageidlezero unconditionally if there is something to run.
 1.77 12-Oct-2019  maxv 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.76 29-May-2019  maxv Add PCID support in SVS. This avoids TLB flushes during kernel<->user
transitions, which greatly reduces the performance penalty introduced by
SVS.

We use two ASIDs, 0 (kern) and 1 (user), and use invpcid to flush pages
in both ASIDs.

The read-only machdep.svs.pcid={0,1} sysctl is added, and indicates whether
SVS+PCID is in use.
 1.75 27-May-2019  maxv Remove 'ci_svs_kpdirpa', unused. While here fix a few comments here and
there, reduces a future diff.
 1.74 15-Feb-2019  nonaka Added Microsoft Hyper-V support. It ported from OpenBSD and FreeBSD.

graphical console is not work on Gen.2 VM yet. To use the serial console,
enter "consdev com,0x3f8,115200" on efiboot.
 1.73 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.72 02-Feb-2019  cherry Switch NetBSD/xen to use XEN api tag RELEASE-4.11.1

The headers for this api are in sys/external/mit/xen-include-public/dist/
 1.71 25-Dec-2018  cherry Excise XEN specific code out of x86/x86/intr.c into xen/x86/xen_intr.c

While at it, separate the source function tracking so that the interrupt
paths are truly independant.

Use weak symbol exporting to provision for future PVHVM co-existence
of both files, but with independant paths. Introduce assembler code
such that in a unified scenario, native interrupts get first priority
in spllower(), followed by XEN event callbacks. IPL management and
semantics are unchanged - native handlers and xen callbacks are
expected to maintain their ipl related semantics.

In summary, after this commit, native and XEN now have completely
unrelated interrupt handling mechanisms, including
intr_establish_xname() and assembler stubs and intr handler
management.

Happy Christmas!
 1.70 12-Aug-2018  maxv More ASLR: randomize the location of the PTE area. The PTE slot is not
created in locore anymore, but a little later; by using the already
entered L4 page, rather than the recursive slot itself (which doesn't
exist yet).

In the prekern we still map the slot - the prekern behaves as an external
locore -, because we need it as part of the randomization/relocation
work. The kernel then removes this slot, and regenerates a randomized
one.

Tested on GENERIC and GENERIC_KASLR, Xen doesn't have it and dom0 still
boots fine.
 1.69 12-Aug-2018  maxv Eliminate the only ASM reference to VM_MIN_KERNEL_ADDRESS. Rename the
value to VM_SPACE_SEP_HIGH32, it is now the highest 32bits of the first
va of the higher half of the address space (right after the canonical
hole).
 1.68 30-Mar-2018  maxv branches: 1.68.2;
Fix warning when compiling Xen; FLAT_RING3_CS64 is defined in a child of
xen.h, which is already included in genassym.cf. So don't redefine it.
 1.67 18-Jan-2018  maxv branches: 1.67.2;
Unmap the kernel heap from the user page tables (SVS).

This implementation is optimized and organized in such a way that we
don't need to copy the kernel stack to a safe place during user<->kernel
transitions. We create two VAs that point to the same physical page; one
will be mapped in userland and is offset in order to contain only the
trapframe, the other is mapped in the kernel and maps the entire stack.

Sent on tech-kern@ a week ago.
 1.66 07-Jan-2018  christos make this compile again
 1.65 07-Jan-2018  maxv Add a new option, SVS (for Separate Virtual Space), that unmaps kernel
pages when running in userland. For now, only the PTE area is unmapped.

Sent on tech-kern@.
 1.64 04-Jan-2018  maxv Allocate the TSS area dynamically. This way cpu_info and cpu_tss can be
put in separate pages.
 1.63 04-Jan-2018  maxv Group the different TSSes into a cpu_tss structure. And pack this
structure to make sure there is no padding between 'tss' and 'iomap'.
 1.62 28-Oct-2017  bouyer Use FLAT_RING3_CS64 (defined in Xen public headers) instead of numeric
value.
 1.61 16-Jul-2017  cherry branches: 1.61.2;
Unify the xen and native x86/ interrupt setup functions and
spl traversal data structures.

This is towards PVHVM.
 1.60 20-Nov-2015  maxv branches: 1.60.10;
A few changes:
- remove cpu_id and cpu_brand_id (unused)
- copy a comment from i386 about fillkpt
- define PDE_SIZE (i386)
 1.59 26-Aug-2015  uebayasi Have MI genassym.cf.
 1.58 25-Aug-2015  uebayasi Replace COHERENCY_UNIT in ldscript.
 1.57 11-Jul-2015  kamil Improve spelling: regsister -> register

This change is non-functional.

Approved by <riastradh>, <pgoyette>
 1.56 20-Feb-2014  dsl branches: 1.56.6;
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.55 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.54 01-Dec-2013  christos revert fpu/pcu changes until we figure out what's wrong; they cause random
freezes
 1.53 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.52 15-Jul-2012  dsl branches: 1.52.2; 1.52.4;
Rename MDP_IRET to MDL_IRET since it is an lwp flag, not a proc one.
Add an MDL_COMPAT32 flag to the lwp's md_flags, set it for 32bit lwps
and use it to force 'return to user' with iret (as is done when
MDL_IRET is set).
Split the iret/sysret code paths much later.
Remove all the replicated code for 32bit system calls - which was only
needed so that iret was always used.
frameasm.h for XEN contains '#define swapgs', while XEN probable never
needs swapgs, this is likely to be confusing.
Add a SWAPGS which is a nop on XEN and swapgs otherwise.
(I've not yet checked all the swapgs in files that include frameasm.h)
Simple x86 programs still work.
Hijack 6.99.9 kernel bump (needed for compat32 modules)
 1.51 11-Jun-2012  chs make dtrace work on amd64.
 1.50 20-Apr-2012  rmind - 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.49 07-Dec-2011  cegger branches: 1.49.2;
switch from xen3-public to xen-public.
 1.48 01-Jul-2011  dyoung branches: 1.48.2; 1.48.6;
#include <sys/bus.h> instead of <machine/bus.h>.
 1.47 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.46 20-Dec-2010  matt branches: 1.46.6;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.
 1.45 07-Jul-2010  chs add the guts of TLS support on amd64. based on joerg's patch,
reworked by me to support 32-bit processes as well.
we now keep %fs and %gs loaded with the user values
while in the kernel, which means we don't need to
reload them when returning to user mode.
 1.44 28-Apr-2010  dyoung On x86, change the bus_space_tag_t to a pointer to a struct
bus_space_tag. For now, bus_space_tag's only member is
bst_type, the type of space, which is either X86_BUS_SPACE_IO
or X86_BUS_SPACE_MEM. In the future, new bus_space_tag members
will refer to override-functions installed by a new function,
bus_space_tag_create(9).

Add pointers to constant struct bus_space_tag, x86_bus_space_io and
x86_bus_space_mem. Use them to replace most uses of X86_BUS_SPACE_IO
and X86_BUS_SPACE_MEM.

Add an x86-specific bus_space_is_equal(9) implementation that compares
the two tags' bst_type.
 1.43 27-Nov-2009  rmind branches: 1.43.2; 1.43.4;
- Use uvm_lwp_setuarea() instead of directly setting address to lwp_t::l_addr.
- Replace most remaining uses of l_addr with uvm_lwp_getuarea() or lwp_getpcb().
- Amend assembly in ports where it accesses PCB via struct user.
- Rename L_ADDR to L_PCB in few places. Reduce sys/user.h inclusions.
 1.42 25-Nov-2009  rmind Remove IPL_LPT and IPL_IPI aliases, use the actual IPLs.
Fix some broken comments.
 1.41 21-Nov-2009  rmind Use lwp_getpcb() on x86 MD code, clean from struct user usage.
 1.40 30-Dec-2008  pooka branches: 1.40.2;
!defined(_LKM) -> defined(_KERNEL_OPT)
 1.39 03-Dec-2008  ad Don't abort pageidlezero unless a realtime thread wants to run.
 1.38 11-Nov-2008  ad PR port-amd64/38293 panic: fp_save ipi didn't

Fix race conditions in FPU IPI handling.
 1.37 20-Sep-2008  tsutsui branches: 1.37.2; 1.37.4;
Remove advertising clause for UCB in various genassym.cf files,
which were derived from genassym.c in 4.4BSD-Lite2 (or 386BSD).
Closes PR misc/39573. Approved by martin@.
 1.36 03-Jul-2008  drochner branches: 1.36.2;
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.35 04-Jun-2008  ad branches: 1.35.2;
Remove ref to uvm.page_idle_zero
 1.34 01-Jun-2008  ad Oops, add CPU_INFO_NTRAP.
 1.33 11-May-2008  ad Don't reload LDTR unless a new value, which only happens for USER_LDT.
 1.32 11-May-2008  ad Share cpu.h between the x86 ports.
 1.31 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.30 28-Apr-2008  ad branches: 1.30.2;
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.29 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.28 28-Apr-2008  ad Make kernel pagefault handling preeemption safe.
 1.27 21-Apr-2008  cegger branches: 1.27.2;
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.26 26-Mar-2008  ad branches: 1.26.2;
Correct pasto in the cc_microtime defs. From tsutsui@.
 1.25 11-Mar-2008  ad Make context switch + syscall counters optionally per-CPU and accumulate
in schedclock() at "about 16 hz".
 1.24 10-Mar-2008  ad Implement an optimized, preemption-safe asm version of tsc_get_timecount().
The C version needs work to be preemption safe. Cuts the clock cycles
for microtime() from 950 down to 300 on a Pentium D.
 1.23 05-Jan-2008  yamt branches: 1.23.2; 1.23.6;
- make amd64 use per-cpu tss.
- fix iopl syscall for amd64+xen.
 1.22 01-Jan-2008  yamt make the nmi handler safer.

XXX should use IST.
 1.21 21-Dec-2007  dsl Create the trap/syscall frame space for all the registers in one go.
Use the tramp-frame offsets (TF_foo) for all references to the registers.
Sort the saving of the GP registers into the same order as the trap frame
because consequetive memory accesses are liekly to be faster.
 1.20 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.19 03-Dec-2007  ad branches: 1.19.2; 1.19.6;
Interrupt handling changes, in discussion since February:

- Reduce available SPL levels for hardware devices to none, vm, sched, high.
- Acquire kernel_lock only for interrupts at IPL_VM.
- Implement threaded soft interrupts.
 1.18 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.17 20-Nov-2007  yamt put back IPL_IPI as it's still used.
 1.16 19-Nov-2007  ad IPL_IPI -> IPL_HIGH
 1.15 31-Oct-2007  dsl branches: 1.15.2;
Fallout from fixing the linux32 system calls to use the correct kernel
functions and parameter layouts.
 1.14 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.13 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.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 26-Sep-2007  ad ci_astpending is no more.
 1.10 29-Aug-2007  ad branches: 1.10.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.9 17-May-2007  yamt branches: 1.9.4; 1.9.8; 1.9.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.8 18-Feb-2007  cube branches: 1.8.4; 1.8.6; 1.8.12;
Fix a couple missed occurrences of P_32 -> PK_32.
 1.7 17-Feb-2007  pavel Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.
 1.6 09-Feb-2007  ad branches: 1.6.2;
Merge newlock2 to head.
 1.5 09-Feb-2006  manu branches: 1.5.14;
Add initial (but unfinished) COMPAT_LINUX32 for amd64. This is good enough so
that the i386 license manager part of amd64 version of Fluent works.

While I'm here, add SysV IPC to COMPAT_LINUX/amd64
 1.4 11-Dec-2005  christos branches: 1.4.2; 1.4.4; 1.4.6;
merge ktrace-lwp.
 1.3 04-Nov-2003  dsl branches: 1.3.16;
Remove p_nras from struct proc - use LIST_EMPTY(&p->p_raslist) instead.
Remove p_raslock and rename p_lwplock p_lock (one lock is enough).
Simplify window test when adding a ras and correct test on VM_MAXUSER_ADDRESS.
Avoid unpredictable branch in i386 locore.S
(pad fields left in struct proc to avoid kernel bump)
 1.2 04-May-2003  fvdl branches: 1.2.2;
Follow i386, and mask deferred level-triggered interrupts at the ioapic.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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.3.16.8 17-Mar-2008  yamt sync with head.
 1.3.16.7 21-Jan-2008  yamt sync with head
 1.3.16.6 07-Dec-2007  yamt sync with head
 1.3.16.5 15-Nov-2007  yamt sync with head.
 1.3.16.4 27-Oct-2007  yamt sync with head.
 1.3.16.3 03-Sep-2007  yamt sync with head.
 1.3.16.2 26-Feb-2007  yamt sync with head.
 1.3.16.1 21-Jun-2006  yamt sync with head.
 1.4.6.1 22-Apr-2006  simonb Sync with head.
 1.4.4.1 09-Sep-2006  rpaulo sync with head
 1.4.2.1 18-Feb-2006  yamt sync with head.
 1.5.14.7 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.5.14.6 12-Jan-2007  ad Make amd64 build again.
 1.5.14.5 11-Jan-2007  ad Checkpoint work in progress.
 1.5.14.4 29-Dec-2006  ad Checkpoint work in progress.
 1.5.14.3 17-Nov-2006  ad Checkpoint work in progress.
 1.5.14.2 20-Oct-2006  ad Export/remove new symbols to asm code.
 1.5.14.1 10-Sep-2006  ad Add updated locking primatives.
 1.6.2.4 04-Apr-2007  ad PK_SYSTEM -> LW_SYSTEM
 1.6.2.3 23-Mar-2007  yamt remove L_FORW and L_BACK.
 1.6.2.2 03-Mar-2007  yamt adapt amd64.

XXX changes in identcpu.c is minmum for MONITOR.
XXX identcpu.c should be shared with i386.
 1.6.2.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.8.12.2 03-Oct-2007  garbled Sync with HEAD
 1.8.12.1 22-May-2007  matt Update to HEAD.
 1.8.6.1 11-Jul-2007  mjf Sync with head.
 1.8.4.6 03-Dec-2007  ad Sync with HEAD.
 1.8.4.5 03-Dec-2007  ad Sync with HEAD.
 1.8.4.4 23-Oct-2007  ad Sync with head.
 1.8.4.3 09-Oct-2007  ad Sync with head.
 1.8.4.2 21-Aug-2007  ad amd64 changes, as yet untested:

- Adapt to vmlocking branch.
- Apply TLB shootdown and pv allocation changes to the pmap.
- Make it build.
 1.8.4.1 27-May-2007  ad Sync with head.
 1.9.10.3 23-Mar-2008  matt sync with HEAD
 1.9.10.2 09-Jan-2008  matt sync with HEAD
 1.9.10.1 06-Nov-2007  matt sync with HEAD
 1.9.8.7 09-Dec-2007  jmcneill Sync with HEAD.
 1.9.8.6 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.9.8.5 21-Nov-2007  joerg Sync with HEAD.
 1.9.8.4 04-Nov-2007  jmcneill Sync with HEAD.
 1.9.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.9.8.2 02-Oct-2007  joerg Sync with HEAD.
 1.9.8.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.9.4.1 03-Sep-2007  skrll Sync with HEAD.
 1.10.2.7 07-Oct-2007  yamt fix DIAGNOSTIC
 1.10.2.6 07-Oct-2007  yamt add KERNTEXTOFF.
 1.10.2.5 07-Oct-2007  yamt whitespace changes to reduce diffs.
 1.10.2.4 07-Oct-2007  yamt reduce diffs from i386.
 1.10.2.3 07-Oct-2007  yamt remove some #ifdef _LOCORE and use genassym instead.
 1.10.2.2 06-Oct-2007  yamt sync with head.
 1.10.2.1 30-Sep-2007  yamt implement deferred pmap switching for amd64, and make amd64 use
x86 shared pmap code. it makes several i386 pmap improvements available
to amd64, including tlb shootdown reduction and bug fixes from Stephan Uphoff.
 1.12.2.5 21-Nov-2007  bouyer Sync with HEAD
 1.12.2.4 16-Nov-2007  bouyer Initial domain0 support for xenamd64. The kernel boots multiuser, but
xen tools have not been tried yet.
In this process, cleanup some more the page table bootstrap, and properly
handle event counters for soft interrupts.
 1.12.2.3 13-Nov-2007  bouyer Sync with HEAD
 1.12.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.12.2.1 17-Oct-2007  bouyer amd64 (aka x86-64) support for Xen. Based on the OpenBSD port done by
Mathieu Ropert in 2006.
DomU-only for now. An INSTALL_XEN3_DOMU kernel with a ramdisk will boot to
sysinst if you're lucky. Often it panics because a runable LWP has
a NULL stack (really, it's all of l->l_addr which is has been zeroed out
while the process was on the queue !)
TODO:
- bug fixes :)
- Most of the xpq_* functions should be shared with xen/i386
- The xen/i386 assembly bootstrap code should be remplaced with the C
version in xenamd64/amd64/xpmap.c
- see if a config(5) trick could allow to merge xenamd64 back to xen or amd64.
 1.15.2.3 18-Feb-2008  mjf Sync with HEAD.
 1.15.2.2 27-Dec-2007  mjf Sync with HEAD.
 1.15.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.19.6.2 08-Jan-2008  bouyer Sync with HEAD
 1.19.6.1 02-Jan-2008  bouyer Sync with HEAD
 1.19.2.1 26-Dec-2007  ad Sync with head.
 1.23.6.5 17-Jan-2009  mjf Sync with HEAD.
 1.23.6.4 28-Sep-2008  mjf Sync with HEAD.
 1.23.6.3 05-Jun-2008  mjf Sync with HEAD.

Also fix build.
 1.23.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.23.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.23.2.1 24-Mar-2008  keiichi sync with head.
 1.26.2.3 17-Jun-2008  yamt sync with head.
 1.26.2.2 04-Jun-2008  yamt sync with head
 1.26.2.1 18-May-2008  yamt sync with head.
 1.27.2.4 11-Aug-2010  yamt sync with head.
 1.27.2.3 11-Mar-2010  yamt sync with head
 1.27.2.2 04-May-2009  yamt sync with head.
 1.27.2.1 16-May-2008  yamt sync with head.
 1.30.2.3 10-Oct-2008  skrll Sync with HEAD.
 1.30.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.30.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.35.2.1 03-Jul-2008  simonb Sync with head.
 1.36.2.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.36.2.1 19-Oct-2008  haad Sync with HEAD.
 1.37.4.2 02-Feb-2009  snj Pull up following revision(s) (requested by ad in ticket #345):
sys/arch/amd64/amd64/genassym.cf: revision 1.39
sys/arch/i386/i386/genassym.cf: revision 1.79
sys/arch/i386/i386/locore.S: revision 1.82
sys/arch/x86/x86/x86_machdep.c: revision 1.26
Don't abort pageidlezero unless a realtime thread wants to run.
 1.37.4.1 17-Nov-2008  snj Pull up following revision(s) (requested by ad in ticket #74):
sys/arch/i386/isa/npx.c: revision 1.131
sys/arch/amd64/amd64/fpu.c: revision 1.28
sys/arch/i386/i386/genassym.cf: revision 1.77
sys/arch/i386/i386/autoconf.c: revision 1.93
sys/arch/amd64/amd64/locore.S: revision 1.48
sys/arch/amd64/amd64/machdep.c: revision 1.104
sys/arch/i386/i386/machdep.c: revision 1.646
sys/arch/amd64/amd64/genassym.cf: revision 1.38
sys/arch/i386/i386/locore.S: revision 1.79
PR port-amd64/38293 panic: fp_save ipi didn't
Fix race conditions in FPU IPI handling.
 1.37.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.40.2.3 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.40.2.2 10-Jan-2011  jym Sync with HEAD
 1.40.2.1 24-Oct-2010  jym Sync with HEAD
 1.43.4.4 17-Mar-2011  rmind - Fix tlbflushg() to behave like tlbflush(), if page global extension (PGE)
is not (yet) enabled. This fixes the issue of stale TLB entry, experienced
early on boot, when PGE is not yet set on primary CPU.
- Rewrite i386/amd64 TLB interrupt handlers in C (only stubs are in assembly),
which simplifies and unifies (under x86) code, plus fixes few bugs.
- cpu_attach: remove assignment to cpus_running, as primary CPU might not be
attached first, which causes reset (and thus missed secondary CPUs).
 1.43.4.3 05-Mar-2011  rmind sync with head
 1.43.4.2 30-May-2010  rmind sync with head
 1.43.4.1 26-Apr-2010  rmind Partly rewrite amd64 TLB shutdown handler for the changes in x86 pmap.
At this point, branch seems to pass preliminar stress tests on amd64.
 1.43.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.43.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.46.6.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.48.6.2 29-Apr-2012  mrg sync to latest -current.
 1.48.6.1 18-Feb-2012  mrg merge to -current.
 1.48.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.48.2.3 30-Oct-2012  yamt sync with head
 1.48.2.2 23-May-2012  yamt sync with head.
 1.48.2.1 17-Apr-2012  yamt sync with head
 1.49.2.2 22-Nov-2012  riz Pull up following revision(s) (requested by chs in ticket #690):
external/cddl/osnet/dev/dtrace/amd64/dtrace_isa.c: revision 1.4
sys/arch/amd64/include/Makefile.inc: revision 1.4
sys/arch/amd64/include/pmap.h: revision 1.33
external/cddl/osnet/dev/dtrace/amd64/dtrace_subr.c: revision 1.6
sys/arch/amd64/include/asm.h: revision 1.15
sys/arch/amd64/amd64/genassym.cf: revision 1.51
external/cddl/osnet/dev/dtrace/amd64/dtrace_asm.S: revision 1.4
make dtrace work on amd64.
allow more space for modules.
 1.49.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.52.4.1 18-May-2014  rmind sync with head
 1.52.2.2 03-Dec-2017  jdolecek update from HEAD
 1.52.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.56.6.3 28-Aug-2017  skrll Sync with HEAD
 1.56.6.2 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.56.6.1 22-Sep-2015  skrll Sync with HEAD
 1.60.10.3 09-Mar-2019  martin Pull up following revision(s) via patch (requested by nonaka in ticket #1210):

sys/dev/hyperv/vmbusvar.h: revision 1.1
sys/dev/hyperv/hvs.c: revision 1.1
sys/dev/hyperv/if_hvn.c: revision 1.1
sys/dev/hyperv/vmbusic.c: revision 1.1
sys/arch/x86/x86/lapic.c: revision 1.69
sys/arch/x86/isa/clock.c: revision 1.34
sys/arch/x86/include/intrdefs.h: revision 1.22
sys/arch/i386/conf/GENERIC: revision 1.1201
sys/arch/x86/x86/hyperv.c: revision 1.1
sys/arch/x86/include/cpu.h: revision 1.105
sys/arch/x86/x86/x86_machdep.c: revision 1.124
sys/arch/i386/conf/GENERIC: revision 1.1203
sys/arch/amd64/amd64/genassym.cf: revision 1.74
sys/arch/i386/conf/GENERIC: revision 1.1204
sys/arch/amd64/conf/GENERIC: revision 1.520
sys/arch/x86/x86/hypervreg.h: revision 1.1
sys/arch/amd64/amd64/vector.S: revision 1.69
sys/dev/hyperv/hvshutdown.c: revision 1.1
sys/dev/hyperv/hvshutdown.c: revision 1.2
sys/dev/usb/if_urndisreg.h: file removal
sys/arch/x86/x86/cpu.c: revision 1.167
sys/arch/x86/conf/files.x86: revision 1.107
sys/dev/usb/if_urndis.c: revision 1.20
sys/dev/hyperv/vmbusicreg.h: revision 1.1
sys/dev/hyperv/hvheartbeat.c: revision 1.1
sys/dev/hyperv/vmbusicreg.h: revision 1.2
sys/dev/hyperv/hvheartbeat.c: revision 1.2
sys/dev/hyperv/files.hyperv: revision 1.1
sys/dev/ic/rndisreg.h: revision 1.1
sys/arch/i386/i386/genassym.cf: revision 1.111
sys/dev/ic/rndisreg.h: revision 1.2
sys/dev/hyperv/hyperv_common.c: revision 1.1
sys/dev/hyperv/hvtimesync.c: revision 1.1
sys/dev/hyperv/hypervreg.h: revision 1.1
sys/dev/hyperv/hvtimesync.c: revision 1.2
sys/dev/hyperv/vmbusicvar.h: revision 1.1
sys/dev/hyperv/if_hvnreg.h: revision 1.1
sys/arch/x86/x86/lapic.c: revision 1.70
sys/arch/amd64/amd64/vector.S: revision 1.70
sys/dev/ic/ndisreg.h: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.516
sys/dev/hyperv/hypervvar.h: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.518
sys/arch/amd64/conf/GENERIC: revision 1.519
sys/arch/i386/conf/files.i386: revision 1.400
sys/dev/acpi/vmbus_acpi.c: revision 1.1
sys/dev/hyperv/vmbus.c: revision 1.1
sys/dev/hyperv/vmbus.c: revision 1.2
sys/arch/x86/x86/intr.c: revision 1.144
sys/arch/i386/i386/vector.S: revision 1.83
sys/arch/amd64/conf/files.amd64: revision 1.112

separate RNDIS definitions from urndis(4) for use with Hyper-V NetVSC.

-

Added Microsoft Hyper-V support. It ported from OpenBSD and FreeBSD.
graphical console is not work on Gen.2 VM yet. To use the serial console,
enter "consdev com,0x3f8,115200" on efiboot.

-

Add __diagused.

-

PR/53984: Partial revert of modify lapic_calibrate_timer() in lapic.c r1.69.

-

Update Hyper-V related drivers description.

-

Remove unused definition.

-

Rename the MODULE_*_HOOK() macros to MODULE_HOOK_*() as briefly
discussed on irc.
NFCI intended.

-

commented out hvkvp entry.

-

fix typo. pointed out by pgoyette@n.o.

-

Use IDTVEC instead of NENTRY for handle_hyperv_hypercall.

-

Rename the MODULE_*_HOOK() macros to MODULE_HOOK_*() as briefly
discussed on irc.
 1.60.10.2 22-Mar-2018  martin Pull up the following revisions, requested by maxv in ticket #652:

sys/arch/amd64/amd64/amd64_trap.S upto 1.39 (partial, patch)
sys/arch/amd64/amd64/db_machdep.c 1.6 (patch)
sys/arch/amd64/amd64/genassym.cf 1.65,1.66,1.67 (patch)
sys/arch/amd64/amd64/locore.S upto 1.159 (partial, patch)
sys/arch/amd64/amd64/machdep.c 1.299-1.302 (patch)
sys/arch/amd64/amd64/trap.c upto 1.113 (partial, patch)
sys/arch/amd64/amd64/amd64/vector.S upto 1.61 (partial, patch)
sys/arch/amd64/conf/GENERIC 1.477,1.478 (patch)
sys/arch/amd64/conf/kern.ldscript 1.26 (patch)
sys/arch/amd64/include/frameasm.h upto 1.37 (partial, patch)
sys/arch/amd64/include/param.h 1.25 (patch)
sys/arch/amd64/include/pmap.h 1.41,1.43,1.44 (patch)
sys/arch/x86/conf/files.x86 1.91,1.93 (patch)
sys/arch/x86/include/cpu.h 1.88,1.89 (patch)
sys/arch/x86/include/pmap.h 1.75 (patch)
sys/arch/x86/x86/cpu.c 1.144,1.146,1.148,1.149 (patch)
sys/arch/x86/x86/pmap.c upto 1.289 (partial, patch)
sys/arch/x86/x86/vm_machdep.c 1.31,1.32 (patch)
sys/arch/x86/x86/x86_machdep.c 1.104,1.106,1.108 (patch)
sys/arch/x86/x86/svs.c 1.1-1.14
sys/arch/xen/conf/files.compat 1.30 (patch)

Backport SVS. Not enabled yet.
 1.60.10.1 13-Mar-2018  martin Pullup the following revisions via patch, requested by maxv in ticket #629:

sys/arch/amd64/amd64/genassym.cf 1.63,1.64
sys/arch/amd64/amd64/locore.S 1.144
sys/arch/amd64/amd64/machdep.c 1.281-1.283
sys/arch/i386/i386/genassym.cf 1.105-1.106
sys/arch/i386/i386/locore.S 1.155
sys/arch/i386/i386/machdep.c 1.802 (adapted),1.803
sys/arch/x86/include/cpu.h 1.85
sys/arch/x86/x86/intr.c 1.115-1.116
sys/arch/x86/x86/pmap.c 1.275
sys/arch/x86/x86/sys_machdep.c 1.45
sys/arch/xen/x86/cpu.c 1.117

Stop sharing the double-fault stack.
Merge the TSS structures into one single cpu_tss structure, and
allocate it dynamically.
 1.61.2.2 16-Jul-2017  cherry 2302677
 1.61.2.1 16-Jul-2017  cherry file genassym.cf was added on branch perseant-stdc-iso10646 on 2017-07-16 14:02:49 +0000
 1.67.2.3 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.67.2.2 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.67.2.1 07-Apr-2018  pgoyette Sync with HEAD. 77 conflicts resolved - all of them $NetBSD$
 1.68.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.68.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.68.2.1 10-Jun-2019  christos Sync with HEAD
 1.80.2.4 29-Feb-2020  ad Sync with head.
 1.80.2.3 22-Jan-2020  ad Back out previous.
 1.80.2.2 19-Jan-2020  ad Adaptive rwlocks proposed on tech-kern and working well on this branch
with vnode locks.
 1.80.2.1 17-Jan-2020  ad Sync with head.
 1.82.4.3 12-Apr-2020  bouyer Get rid of xen-specific ci_x* interrupt handling:
- use the general SIR mechanism, reserving 3 more slots for IPL_VM, IPL_SCHED
and IPL_HIGH
- remove specific handling from C sources, or change to ipending
- convert IPL number to SIR number in various places
- Remove XUNMASK/XPENDING in assembly or change to IUNMASK/IPENDING
- remove Xen-specific ci_xsources, ci_xmask, ci_xunmask, ci_xpending from
struct cpu_info
- for now remove a KASSERT that there are no pending interrupts in
idle_block(). We can get there with some software interrupts pending
in autoconf XXX needs to be looked at.
 1.82.4.2 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.82.4.1 08-Apr-2020  bouyer Remove VM_GUEST_XEN and define only Xen subtypes:
VM_GUEST_XENPV
VM_GUEST_XENPVH
VM_GUEST_XENHVM
VM_GUEST_XENPVHVM

Set vm_guest in the start routine, if it is hypervisor-specific (e.g Xen PV).
If vm_guest was not set early and we detect Xen in identify_hypervisor(),
assume it is VM_GUEST_XENHVM. Refine to VM_GUEST_PVXENHVM in
hypervisor_match().
 1.89.4.1 29-Mar-2025  martin Pull up following revision(s) (requested by imil in ticket #1074):

sys/arch/x86/x86/x86_machdep.c: revision 1.155
sys/arch/x86/include/cpu.h: revision 1.137
sys/arch/x86/x86/x86_machdep.c: revision 1.156
sys/arch/x86/include/cpu.h: revision 1.138
sys/arch/x86/x86/consinit.c: revision 1.40
sys/arch/x86/acpi/acpi_machdep.c: revision 1.37
sys/arch/x86/acpi/acpi_machdep.c: revision 1.38
sys/arch/amd64/amd64/machdep.c: revision 1.370
sys/arch/xen/xen/hypervisor.c: revision 1.97
sys/arch/xen/xen/hypervisor.c: revision 1.98
sys/arch/amd64/amd64/genassym.cf: revision 1.98
sys/arch/x86/x86/x86_autoconf.c: revision 1.88
sys/arch/x86/x86/x86_autoconf.c: revision 1.89
sys/arch/amd64/amd64/locore.S: revision 1.226
sys/arch/amd64/amd64/locore.S: revision 1.227
sys/arch/x86/x86/identcpu.c: revision 1.131

Add support for non-Xen PVH guests to amd64. Patch from
Emile 'iMil' Heitor in PR kern/57813, with some cosmetic tweaks by me.
Tested on bare metal, Xen PV and Xen PVH by me.

Get one more change from PR kern/57813, needed for non-Xen PVH.

Introduce vm_guest_is_pvh() and use it in place of
(vm_guest == VM_GUEST_XENPVH || vm_guest == VM_GUEST_GENPVH)
 1.97.6.1 02-Aug-2025  perseant Sync with HEAD
 1.40 11-May-2008  ad Simplify x86 identcpu code, and share between i386/amd64.
 1.39 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.38 28-Apr-2008  ad branches: 1.38.2;
Noisy printf.
 1.37 19-Apr-2008  simonb branches: 1.37.2;
Reduce differences in dmesg output between i386 and amd64 slightly, both
now print "cpuN: features ....".
 1.36 16-Apr-2008  cegger branches: 1.36.2;
use POSIX integer types
 1.35 04-Apr-2008  cegger use aprint_*_dev
OK joerg
 1.34 01-Jan-2008  yamt branches: 1.34.6;
try to detect processor resource sharing topologies. ie. package/core/smt IDs.
 1.33 12-Dec-2007  xtraeme Fix previous with suggestion by cube: rather than checking for cpu_model[0]
check that cpu_vendor is CPUVENDOR_AMD.
 1.32 12-Dec-2007  xtraeme Check for the first 'D' letter in the cpu_model string for POWERNOW_K8,
so that it works in Dual Core Opterons (and maybe others).

Patch from Akihiko Taniguchi in PR port-amd64/37526.
 1.31 22-Nov-2007  bouyer branches: 1.31.2; 1.31.4; 1.31.6;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.30 13-Nov-2007  ad In cpu_hatch(), recompute ci_tsc_freq instead of using the boot CPU's value.
 1.29 12-Nov-2007  ad - cpu_vendor was both an int and char[] on amd64 - fix it.
- Run the errata check/patch on all CPUs, not just the boot processor.
 1.28 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.27 29-Oct-2007  xtraeme branches: 1.27.2;
Add coretemp(4). A new driver for Intel Core's on-die thermal sensor,
available on Intel Core or newer CPUs.

Ported from FreeBSD. Tested by rmind on i386 and joerg on amd64.

Enabled with "options INTEL_CORETEMP".
 1.26 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.25 26-Sep-2007  ad branches: 1.25.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.24 29-Aug-2007  ad branches: 1.24.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.23 14-Jun-2007  njoly branches: 1.23.4; 1.23.8; 1.23.10;
Only print cpu features3 for Intel processors.

ok by xtraeme.
 1.22 04-Jun-2007  xtraeme - Use aprint_verbose for consistency with i386 (suggested by ad).
- Wrap long lines.
 1.21 04-Jun-2007  xtraeme Print Intel CPUID extended features if they are available, also
simplify ci_feature2_flags and use directly CPUID2_FLAGS on
bitmask_snprintf(9).

Now I can see the same CPUID features than on i386:

$ dmesg|grep -E '(cpu0.*features)'
cpu0: features: bffbfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR>
cpu0: features: bffbfbff<PGE,MCA,CMOV,PAT,PSE36,CFLUSH,B20,DS,ACPI,MMX>
cpu0: features: bffbfbff<FXSR,SSE,SSE2,SS,HTT,TM,SBF>
cpu0: features2: 649d<SSE3,MONITOR,DS-CPL,EST,CID,xTPR>
cpu0: features3: bffbfbff<SYSCALL/SYSRET,XD,EM64T>
$

Ok'ed by Andrew Doran.
 1.20 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.19 22-May-2007  xtraeme Do not print twice features2. This was added with yamt-idlelwp.
 1.18 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.17 20-Mar-2007  xtraeme branches: 1.17.4;
Driver for Intel Thermal Monitor (feature TM) On-Demand Clock
Modulation.

This works by changing the duty cycle of the clock modulation,
and saves power and helps to not increase the temperature by
software.

Adapted from OpenBSD/FreeBSD's p4tcc.

To enable it one must use "options INTEL_ONDEMAND_CLOCKMOD".

Tested by me in UP and SMP, ok'ed by Matthew R. Green.
 1.16 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.15 18-Mar-2007  xtraeme Change k8_powernow_init to accept a struct cpu_info * as argument,
so that in the informative messages it prints the correct cpu
and not curcpu().

This fixes the first part of PR kern/35676.
 1.14 16-Mar-2007  xtraeme struct cpu_info: add a ci_feature2_flags member.
identcpu: print extended cpuid features with ci_feature2_flags.

"Looks good" by christos and njoly.
 1.13 15-Mar-2007  xtraeme Ok... there were people really angry with this, backing it out.
 1.12 15-Mar-2007  xtraeme Call p4tcc_init(), the driver takes care of detection.
 1.11 07-Mar-2007  njoly branches: 1.11.2; 1.11.4; 1.11.6;
Fix features display for Intel CPUs.
Slightly updated version from PR/35302.

ok by cube
 1.10 03-Mar-2007  yamt revert an unreasonable whitespace change in rev.1.8.
 1.9 09-Feb-2007  ad branches: 1.9.2;
Merge newlock2 to head.
 1.8 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.7 04-Oct-2006  cube branches: 1.7.2; 1.7.4;
Rework the way PowerNow! and Cool'n'Quiet features are detected and
displayed, to make the code much simpler and easier to follow. Also, use
bitmask_printf() to make output consistent with other stuff. Use
CPUID2FAMILY() where appropriate.
 1.6 07-Aug-2006  xtraeme branches: 1.6.4; 1.6.6;
* Do not change struct powernow_pst_s (I added another member in my
previous patch) and this MUST be of that size, otherwise the tables
won't be found.

* powernow_k8.c moved into x86/x86, it should work both i386 and amd64.

* Added more DPRINTFs needed to found the first problem.

* Create "machdep.powernow.frequency" again, I can't remember why I
removed frequency... it should work with estd now.

* Do not try to call k[78]_powernow_init() if cpu is not AMD (thanks
to christos).

And more things I can't remember, but this time it will work in
Athlon 64 cpus and it won't crash in EM64T cpus.
 1.5 06-Aug-2006  xtraeme AMD PowerNow!/Cool`n'Quiet driver for NetBSD/amd64,
adapted from OpenBSD.

Tested on a few machines:

http://bigbird.dohd.org:3021/NetBSD/dmesg
http://www.bsd.org.il/netbsd/acpi/dmesg

Thanks to cube, elad and others for testing and fixes.

Enabled by default on GENERIC.
 1.4 07-Jun-2006  kardel convert to timecounters (from branch simonb-timecounters)
 1.3 11-Dec-2005  christos branches: 1.3.4; 1.3.6; 1.3.8; 1.3.14;
merge ktrace-lwp.
 1.2 14-Jul-2003  lukem branches: 1.2.16;
__KERNEL_RCSID()
 1.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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.2.16.8 21-Jan-2008  yamt sync with head
 1.2.16.7 07-Dec-2007  yamt sync with head
 1.2.16.6 15-Nov-2007  yamt sync with head.
 1.2.16.5 27-Oct-2007  yamt sync with head.
 1.2.16.4 03-Sep-2007  yamt sync with head.
 1.2.16.3 26-Feb-2007  yamt sync with head.
 1.2.16.2 30-Dec-2006  yamt sync with head.
 1.2.16.1 21-Jun-2006  yamt sync with head.
 1.3.14.1 19-Jun-2006  chap Sync with head.
 1.3.8.2 11-Aug-2006  yamt sync with head
 1.3.8.1 26-Jun-2006  yamt sync with head.
 1.3.6.1 30-Apr-2006  kardel retire cc_microtime code in favor of timecounters
 1.3.4.1 09-Sep-2006  rpaulo sync with head
 1.6.6.1 22-Oct-2006  yamt sync with head
 1.6.4.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.6.4.2 12-Jan-2007  ad Sync with head.
 1.6.4.1 18-Nov-2006  ad Sync with head.
 1.7.4.2 23-Sep-2007  wrstuden Sync with somewhat-recent netbsd-4.
 1.7.4.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.7.2.3 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.7.2.2 15-Jun-2007  liamjfoy Pull up following revision(s) (requested by njoly in ticket #722):
sys/arch/amd64/amd64/identcpu.c: revision 1.23
Only print cpu features3 for Intel processors.
ok by xtraeme.
 1.7.2.1 05-Jun-2007  bouyer Pull up following revision(s) (requested by xtraeme in ticket 702):
sys/arch/amd64/amd64/identcpu.c patch
sys/arch/amd64/include/cpu.h patch
sys/arch/x86/include/cputypes.h 1.1
Print all extended features for Intel EM64T CPUs on amd64.
 1.9.2.3 24-Mar-2007  yamt sync with head.
 1.9.2.2 12-Mar-2007  rmind Sync with HEAD.
 1.9.2.1 03-Mar-2007  yamt adapt amd64.

XXX changes in identcpu.c is minmum for MONITOR.
XXX identcpu.c should be shared with i386.
 1.11.6.2 29-Mar-2007  reinoud Pullup to -current
 1.11.6.1 18-Mar-2007  reinoud First attempt to bring branch in sync with HEAD
 1.11.4.1 11-Jul-2007  mjf Sync with head.
 1.11.2.7 03-Dec-2007  ad Sync with HEAD.
 1.11.2.6 09-Oct-2007  ad Sync with head.
 1.11.2.5 23-Aug-2007  ad Merged x86 cpu.c.
 1.11.2.4 15-Jul-2007  ad Sync with head.
 1.11.2.3 09-Jun-2007  ad Sync with head.
 1.11.2.2 27-May-2007  ad Sync with head.
 1.11.2.1 10-Apr-2007  ad Sync with head.
 1.17.4.3 03-Oct-2007  garbled Sync with HEAD
 1.17.4.2 26-Jun-2007  garbled Sync with HEAD.
 1.17.4.1 22-May-2007  matt Update to HEAD.
 1.23.10.2 09-Jan-2008  matt sync with HEAD
 1.23.10.1 06-Nov-2007  matt sync with HEAD
 1.23.8.6 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.23.8.5 14-Nov-2007  joerg Sync with HEAD.
 1.23.8.4 11-Nov-2007  joerg Sync with HEAD.
 1.23.8.3 29-Oct-2007  joerg Sync with HEAD.
 1.23.8.2 02-Oct-2007  joerg Sync with HEAD.
 1.23.8.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.23.4.1 03-Sep-2007  skrll Sync with HEAD.
 1.24.2.1 06-Oct-2007  yamt sync with head.
 1.25.2.3 18-Nov-2007  bouyer Sync with HEAD
 1.25.2.2 13-Nov-2007  bouyer Sync with HEAD
 1.25.2.1 17-Oct-2007  bouyer amd64 (aka x86-64) support for Xen. Based on the OpenBSD port done by
Mathieu Ropert in 2006.
DomU-only for now. An INSTALL_XEN3_DOMU kernel with a ramdisk will boot to
sysinst if you're lucky. Often it panics because a runable LWP has
a NULL stack (really, it's all of l->l_addr which is has been zeroed out
while the process was on the queue !)
TODO:
- bug fixes :)
- Most of the xpq_* functions should be shared with xen/i386
- The xen/i386 assembly bootstrap code should be remplaced with the C
version in xenamd64/amd64/xpmap.c
- see if a config(5) trick could allow to merge xenamd64 back to xen or amd64.
 1.27.2.4 18-Feb-2008  mjf Sync with HEAD.
 1.27.2.3 27-Dec-2007  mjf Sync with HEAD.
 1.27.2.2 08-Dec-2007  mjf Sync with HEAD.
 1.27.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.31.6.2 02-Jan-2008  bouyer Sync with HEAD
 1.31.6.1 13-Dec-2007  bouyer Sync with HEAD
 1.31.4.1 13-Dec-2007  yamt sync with head.
 1.31.2.1 26-Dec-2007  ad Sync with head.
 1.34.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.36.2.1 17-Jun-2008  yamt fix merge botches
 1.37.2.1 16-May-2008  yamt sync with head.
 1.38.2.1 23-Jun-2008  wrstuden Remove files removed on branch. Updating using patch has its
drawbacks. :-)
 1.3 25-Jan-2008  joerg Refactor in_cksum/in4_cksum/in6_cksum implementations:
- All three functions are included in the kernel by default.
They call a backend function cpu_in_cksum after possibly
computing the checksum of the pseudo header.
- cpu_in_cksum is the core to implement the one-complement sum.
The default implementation is moderate fast on most platforms
and provides a 32bit accumulator with 16bit addends for L32 platforms
and a 64bit accumulator with 32bit addends for L64 platforms.
It handles edge cases like very large mbuf chains (could happen with
native IPv6 in the future) and provides a good base for new native
implementations.
- Modify i386 and amd64 assembly to use the new interface.

This disables the MD implementations on !x86 until the conversion is
done. For Alpha, the portable version is faster.
 1.2 23-Jan-2008  joerg Fix a logic bug when handling multiple continious misaligned mbufs.
 1.1 09-Jan-2008  joerg branches: 1.1.2; 1.1.4;
Add assembler version of in_cksum. Thanks to ad@ for his time as
peep hole optimiser. This is 30% faster than the portable C version
for checksumming 64byte and larger mbufs and as fast as or slightly
faster for shorter mbufs (with a high variance).
 1.1.4.3 04-Feb-2008  yamt sync with head.
 1.1.4.2 21-Jan-2008  yamt sync with head
 1.1.4.1 09-Jan-2008  yamt file in_cksum.S was added on branch yamt-lazymbuf on 2008-01-21 09:35:15 +0000
 1.1.2.3 23-Jan-2008  bouyer Sync with HEAD.
 1.1.2.2 10-Jan-2008  bouyer Sync with HEAD
 1.1.2.1 09-Jan-2008  bouyer file in_cksum.S was added on branch bouyer-xeni386 on 2008-01-10 23:43:07 +0000
 1.22 30-Mar-2009  rmind Merge i386 and amd64 ipifuncs.c into x86. No functional changes intended.
XXX: fpu #ifdefs are ugly (should be revisited at some point).
 1.21 28-Mar-2009  rmind x86_64_ipi_halt: unset CPU as running (sync with i386).
 1.20 11-Nov-2008  ad branches: 1.20.4;
PR port-amd64/38293 panic: fp_save ipi didn't

Kill the FP flush IPI and always save. The synchronization here isn't strong
and we could easily pull the chain on an innocent LWP's FP state.

Another fix to follow.
 1.19 10-May-2008  ad branches: 1.19.4; 1.19.6; 1.19.8;
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.18 28-Apr-2008  ad branches: 1.18.2;
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.17 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.16 15-Jan-2008  joerg branches: 1.16.6; 1.16.8; 1.16.10;
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.15 27-Dec-2007  joerg Fix typo.
 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 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.12 17-Oct-2007  garbled branches: 1.12.2; 1.12.4; 1.12.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.11 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.10 29-Aug-2007  ad branches: 1.10.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.9 21-Mar-2007  xtraeme branches: 1.9.2; 1.9.4; 1.9.8; 1.9.12; 1.9.14;
Remove the MSR read IPI handler, there won't be any driver that will
use it, and we can see if the values are ok in the CPUs in the write
operation.

Suggested by YAMAMOTO Takashi.
 1.8 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.7 09-Feb-2007  ad branches: 1.7.2; 1.7.6; 1.7.8; 1.7.10;
Merge newlock2 to head.
 1.6 07-Jun-2006  kardel branches: 1.6.6; 1.6.10;
convert to timecounters (from branch simonb-timecounters)
 1.5 24-Dec-2005  perry branches: 1.5.4; 1.5.6; 1.5.8; 1.5.14;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.4 11-Dec-2005  christos merge ktrace-lwp.
 1.3 14-Jul-2003  lukem branches: 1.3.16;
__KERNEL_RCSID()
 1.2 23-Jun-2003  martin branches: 1.2.2;
Make sure to include opt_foo.h if a defflag option FOO is used.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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.3.16.5 21-Jan-2008  yamt sync with head
 1.3.16.4 27-Oct-2007  yamt sync with head.
 1.3.16.3 03-Sep-2007  yamt sync with head.
 1.3.16.2 26-Feb-2007  yamt sync with head.
 1.3.16.1 21-Jun-2006  yamt sync with head.
 1.5.14.1 19-Jun-2006  chap Sync with head.
 1.5.8.1 26-Jun-2006  yamt sync with head.
 1.5.6.1 30-Apr-2006  kardel call TSC timecounter calibration instead of retired microtime code
 1.5.4.1 09-Sep-2006  rpaulo sync with head
 1.6.10.1 20-Apr-2007  bouyer 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.6.6.1 06-Feb-2007  ad - Print CPU boot/startup messages with aprint_debug().
- Don't call printf from an IPI handler.
 1.7.10.1 29-Mar-2007  reinoud Pullup to -current
 1.7.8.1 11-Jul-2007  mjf Sync with head.
 1.7.6.3 09-Oct-2007  ad Sync with head.
 1.7.6.2 21-Aug-2007  ad amd64 changes, as yet untested:

- Adapt to vmlocking branch.
- Apply TLB shootdown and pv allocation changes to the pmap.
- Make it build.
 1.7.6.1 10-Apr-2007  ad Sync with head.
 1.7.2.1 24-Mar-2007  yamt sync with head.
 1.9.14.3 23-Mar-2008  matt sync with HEAD
 1.9.14.2 09-Jan-2008  matt sync with HEAD
 1.9.14.1 06-Nov-2007  matt sync with HEAD
 1.9.12.2 02-Oct-2007  joerg Sync with HEAD.
 1.9.12.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.9.8.1 03-Sep-2007  skrll 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.10.2.1 06-Oct-2007  yamt sync with head.
 1.12.8.2 19-Jan-2008  bouyer Sync with HEAD
 1.12.8.1 02-Jan-2008  bouyer Sync with HEAD
 1.12.4.1 26-Dec-2007  ad Sync with head.
 1.12.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.16.10.2 04-May-2009  yamt sync with head.
 1.16.10.1 16-May-2008  yamt sync with head.
 1.16.8.1 18-May-2008  yamt sync with head.
 1.16.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.16.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.18.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.19.8.1 17-Nov-2008  snj Pull up following revision(s) (requested by ad in ticket #73):
sys/arch/amd64/amd64/fpu.c: revision 1.27
sys/arch/amd64/amd64/ipifuncs.c: revision 1.20
sys/arch/i386/i386/ipifuncs.c: revision 1.28
sys/arch/i386/isa/npx.c: revision 1.130
sys/arch/x86/include/intrdefs.h: revision 1.14
PR port-amd64/38293 panic: fp_save ipi didn't
Kill the FP flush IPI and always save. The synchronization here isn't
strong and we could easily pull the chain on an innocent LWP's FP state.
Another fix to follow.
 1.19.6.2 28-Apr-2009  skrll Sync with HEAD.
 1.19.6.1 19-Jan-2009  skrll Sync with HEAD.
 1.19.4.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.20.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.12 15-Aug-2017  maxv Merge into x86/.
 1.11 15-Aug-2017  maxv Reduce the diff between amd64 and i386. It also fixes a bug in amd64, where
large pages were not handled correctly.
 1.10 22-Nov-2015  maxv KNF a bit, so I don't get scared each time I open a file
 1.9 26-Jul-2015  mrg properly copy regs for kgdb, and define the number of registers properly.
from openbsd via Vicente Chaves and PR port-amd64/50091.
 1.8 03-Apr-2011  dyoung branches: 1.8.14; 1.8.32;
Clean up excessive #ifdef'age of NMI trap handling for amd64/i386/xen.
Handle NMI in all Xen kernels.
 1.7 20-Dec-2010  matt branches: 1.7.2;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.
 1.6 18-Oct-2009  snj branches: 1.6.4;
Move Matthias Pfaller's files to 2-clause license. OK matthias@.
 1.5 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.4 11-Jan-2009  cegger branches: 1.4.2;
adaption for making kgdb_dev a dev_t
 1.3 28-Apr-2008  martin branches: 1.3.8;
Remove clause 3 and 4 from TNF licenses
 1.2 18-Oct-2007  yamt branches: 1.2.16; 1.2.18; 1.2.20;
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.1 10-Jul-2006  fvdl branches: 1.1.2; 1.1.6; 1.1.10; 1.1.16; 1.1.22; 1.1.40; 1.1.42; 1.1.44; 1.1.46;
kern/33961: add kgdb support and remove some redundant (and incorrect) register
offset definitions from reg.h
 1.1.46.1 25-Oct-2007  bouyer Sync with HEAD.
 1.1.44.1 04-Oct-2007  yamt remove LARGEPAGES option. always use large pages if available.
 1.1.42.1 06-Nov-2007  matt sync with HEAD
 1.1.40.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.1.22.1 23-Oct-2007  ad Sync with head.
 1.1.16.3 27-Oct-2007  yamt sync with head.
 1.1.16.2 30-Dec-2006  yamt sync with head.
 1.1.16.1 10-Jul-2006  yamt file kgdb_machdep.c was added on branch yamt-lazymbuf on 2006-12-30 20:45:22 +0000
 1.1.10.2 09-Sep-2006  rpaulo sync with head
 1.1.10.1 10-Jul-2006  rpaulo file kgdb_machdep.c was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:37:05 +0000
 1.1.6.2 11-Aug-2006  yamt sync with head
 1.1.6.1 10-Jul-2006  yamt file kgdb_machdep.c was added on branch yamt-pdpolicy on 2006-08-11 15:41:00 +0000
 1.1.2.2 13-Jul-2006  gdamore Merge from HEAD.
 1.1.2.1 10-Jul-2006  gdamore file kgdb_machdep.c was added on branch gdamore-uart on 2006-07-13 17:48:44 +0000
 1.2.20.3 11-Mar-2010  yamt sync with head
 1.2.20.2 04-May-2009  yamt sync with head.
 1.2.20.1 16-May-2008  yamt sync with head.
 1.2.18.1 18-May-2008  yamt sync with head.
 1.2.16.2 17-Jan-2009  mjf Sync with HEAD.
 1.2.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.3.8.2 28-Apr-2009  skrll Sync with HEAD.
 1.3.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.4.2.4 02-May-2011  jym Sync with head.
 1.4.2.3 10-Jan-2011  jym Sync with HEAD
 1.4.2.2 01-Nov-2009  jym Sync with HEAD.
 1.4.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.6.4.2 21-Apr-2011  rmind sync with head
 1.6.4.1 05-Mar-2011  rmind sync with head
 1.7.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.8.32.3 28-Aug-2017  skrll Sync with HEAD
 1.8.32.2 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.8.32.1 22-Sep-2015  skrll Sync with HEAD
 1.8.14.1 03-Dec-2017  jdolecek update from HEAD
 1.9 28-Apr-2023  skrll Pass local symbols relocations in both passes and provide the kobj_reloc
implementation visibility of these relocations.

Currently all implementations resolve local symbol relocations in the first
pass and simply skip them in the second. The RISC-V implementation will
make use of this visiblity.
 1.8 28-May-2019  kamil Replace misaligned operations with memcpy() calls in kobj_machdep.c

Detected with kUBSan.
 1.7 24-Dec-2018  christos Treat R_X86_64_PLT32 relocation as R_X86_64_PC32 for binutils-2.31
See: https://lore.kernel.org/patchwork/patch/892629/
 1.6 03-Nov-2017  maxv branches: 1.6.2; 1.6.4;
Handle absolute relocations coming from the kernel: preserve SHN_ABS in
the kernel and module symbols, and when relocating a symbol that has
SHN_ABS, take its value as-is and don't return an error if it equals zero.

Sent on tech-kern@.
 1.5 08-Dec-2008  njoly branches: 1.5.24;
Add R_X86_64_32 relocation support, which enable loading modules with
debugging information. And ensure that addr is not null before using
it.

From ad@, thanks.
 1.4 12-Nov-2008  ad Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.
 1.3 28-Apr-2008  martin branches: 1.3.6; 1.3.8;
Remove clause 3 and 4 from TNF licenses
 1.2 06-Jan-2008  ad branches: 1.2.2; 1.2.4; 1.2.6; 1.2.8; 1.2.14; 1.2.16; 1.2.18;
Only do the xcall if !cold.
 1.1 04-Jan-2008  ad Add a simple in-kernel linker, derived from FreeBSD's link_elf_obj.c. Needs
more work but is enough to load simple LKMs. amd64 is untested.

Locking is caller provided. This is decoupled from the LKM framework because
kernel modules need not be loaded from the file system - they could be built
into the kernel and referenced via link set.
 1.2.18.2 04-May-2009  yamt sync with head.
 1.2.18.1 16-May-2008  yamt sync with head.
 1.2.16.1 18-May-2008  yamt sync with head.
 1.2.14.2 17-Jan-2009  mjf Sync with HEAD.
 1.2.14.1 02-Jun-2008  mjf Sync with HEAD.
 1.2.8.2 18-Feb-2008  mjf Sync with HEAD.
 1.2.8.1 06-Jan-2008  mjf file kobj_machdep.c was added on branch mjf-devfs on 2008-02-18 21:04:20 +0000
 1.2.6.2 21-Jan-2008  yamt sync with head
 1.2.6.1 06-Jan-2008  yamt file kobj_machdep.c was added on branch yamt-lazymbuf on 2008-01-21 09:35:16 +0000
 1.2.4.2 09-Jan-2008  matt sync with HEAD
 1.2.4.1 06-Jan-2008  matt file kobj_machdep.c was added on branch matt-armv6 on 2008-01-09 01:44:45 +0000
 1.2.2.2 08-Jan-2008  bouyer Sync with HEAD
 1.2.2.1 06-Jan-2008  bouyer file kobj_machdep.c was added on branch bouyer-xeni386 on 2008-01-08 22:09:13 +0000
 1.3.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.3.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.5.24.1 03-Dec-2017  jdolecek update from HEAD
 1.6.4.1 10-Jun-2019  christos Sync with HEAD
 1.6.2.1 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.6 14-Jul-2018  maxv Drop NENTRY() from the x86 kernels, use ENTRY(). With PMCs (and other hardware
tracing facilities) we have a much better ways of monitoring the CPU activity
than GPROF, without software modification.

Also I think GPROF has never worked, because the 'start' functions of both
i386 and amd64 use ENTRY(), and it would have caused a function call while the
kernel was not yet relocated.
 1.5 01-Nov-2017  maxv branches: 1.5.2; 1.5.4;
More END(). In linux_sigcode.S we only provide symbols, not defined as
functions.
 1.4 30-Oct-2017  maxv Always use END() markers when declaring functions in assembly, so that ld
can compute the size of the functions. A few remain.

While here, fix a bug in the INTRSTUB macro: we are falling through
resume_, but it is aligned, so it looks like we're executing the inter-
function padding - which probably happens to contain NOPs, but that's
still bad.
 1.3 22-Nov-2015  maxv KNF a bit, so I don't get scared each time I open a file
 1.2 01-Aug-2011  joerg branches: 1.2.12; 1.2.30;
Remove redundant , after .balign.
 1.1 09-Feb-2006  manu branches: 1.1.2; 1.1.10; 1.1.16; 1.1.22; 1.1.94;
Add initial (but unfinished) COMPAT_LINUX32 for amd64. This is good enough so
that the i386 license manager part of amd64 version of Fluent works.

While I'm here, add SysV IPC to COMPAT_LINUX/amd64
 1.1.94.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.1.22.2 09-Sep-2006  rpaulo sync with head
 1.1.22.1 09-Feb-2006  rpaulo file linux32_sigcode.S was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:37:05 +0000
 1.1.16.2 21-Jun-2006  yamt sync with head.
 1.1.16.1 09-Feb-2006  yamt file linux32_sigcode.S was added on branch yamt-lazymbuf on 2006-06-21 14:48:18 +0000
 1.1.10.2 22-Apr-2006  simonb Sync with head.
 1.1.10.1 09-Feb-2006  simonb file linux32_sigcode.S was added on branch simonb-timecounters on 2006-04-22 11:37:11 +0000
 1.1.2.2 18-Feb-2006  yamt sync with head.
 1.1.2.1 09-Feb-2006  yamt file linux32_sigcode.S was added on branch yamt-uio_vmspace on 2006-02-18 15:38:30 +0000
 1.2.30.1 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.2.12.1 03-Dec-2017  jdolecek update from HEAD
 1.5.4.1 10-Jun-2019  christos Sync with HEAD
 1.5.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.33 05-Oct-2023  ad Arrange to update cached LWP credentials in userret() rather than during
syscall/trap entry, eliminating a test+branch on every syscall/trap.

This wasn't possible in the 3.99.x timeframe when l->l_cred came about
because there wasn't a reliable/timely way to force an ONPROC LWP running on
a remote CPU into the kernel (which is just about the only new thing in
this scheme).
 1.32 07-Mar-2015  christos add dtrace hooks
 1.31 25-Nov-2014  christos branches: 1.31.2;
CID 981752: printf format
 1.30 20-Dec-2010  matt branches: 1.30.18;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.
 1.29 21-Nov-2009  rmind branches: 1.29.4;
Use lwp_getpcb() on x86 MD code, clean from struct user usage.
 1.28 14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.27 21-Oct-2008  ad branches: 1.27.2; 1.27.8;
Provide a small inline wrapper for sysent::sy_call() and use it to store
the active syscall description in struct lwp. To be used at some future
point to prevent unloading of modules that provide syscalls, while the
syscalls are in use.
 1.26 21-Oct-2008  ad Undo revivesa damage to userret().
 1.25 15-Oct-2008  wrstuden Merge wrstuden-revivesa into HEAD.
 1.24 24-Apr-2008  ad branches: 1.24.2; 1.24.4; 1.24.8;
- Retire SYCALL_MPSAFE. With the exceptions of darwin and irix emulations,
all system calls are now MPSAFE.
- Remove unneeded acquire/release of kernel_lock.
 1.23 11-Mar-2008  ad branches: 1.23.2;
Make context switch + syscall counters optionally per-CPU and accumulate
in schedclock() at "about 16 hz".
 1.22 06-Mar-2008  njoly Do not use SYS_NSYSENT but the corresponding emulation definitions
instead {LINUX,LINUX32}_SYS_NSYSENT.

While here, cleanup some includes.
 1.21 24-Feb-2008  dsl Set p->p_trace_enabled in fork and whenever the controlling falgs change
instead of doing it in syscall_intern().
Note that syscall_intern() must still be called when the flags change
since many ports use a different copy of the syscall entry code when
tracing is enabled.
 1.20 06-Feb-2008  dsl branches: 1.20.2; 1.20.6;
Remove the 'args' parameter to 'trace_exit()' it is no longer used.
Instead of passing the (un)real system call code and syscall table pointer,
just pass the number of arguments - which is what ktrace really wants.
Ride forthcoming 4.99.53
 1.19 05-Jan-2008  dsl Don't pass 'curlwp' into trace_enter() and trace_exit().
 1.18 31-Dec-2007  ad Remove systrace. Ok core@.
 1.17 03-Nov-2007  dsl branches: 1.17.2; 1.17.8;
Linux doesn't have a SYS_syscall system call (it is all done in libc), and
definitely doesn't have SYS___syscall.
Kill all the code - now matching i386/i386/linux_syscall.c
There is also no point using a switch statement (and it's unpredictable
jump indirect) to save a few memory copies.
 1.16 03-Nov-2007  dsl Merge linux_syscall_fancy and linux_syscall_plain.
 1.15 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.14 15-Aug-2007  ad branches: 1.14.2; 1.14.6;
Changes to make ktrace LKM friendly and reduce ifdef KTRACE. Proposed
on tech-kern.
 1.13 26-Apr-2007  njoly branches: 1.13.2; 1.13.6; 1.13.10;
Save the translated error value from Native to Linux, used by tracing
functions.

Reviewed by manu.
 1.12 22-Mar-2007  njoly s/linux/linux32/ in warning messages.
 1.11 05-Mar-2007  christos branches: 1.11.2; 1.11.4; 1.11.6;
more caddr_t lossage.
 1.10 04-Mar-2007  christos Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.9 17-Feb-2007  pavel Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.
 1.8 09-Feb-2007  ad branches: 1.8.2;
Merge newlock2 to head.
 1.7 24-Sep-2006  elad PR/34594: KIYOHARA Takashi: ifdefed by KTRACE or SYSTRACE in
linux32_syscall.c

Applied patch, thanks for the report!
 1.6 19-Jul-2006  ad branches: 1.6.4; 1.6.6; 1.6.8;
- Hold a reference to the process credentials in each struct lwp.
- Update the reference on syscall and user trap if p_cred has changed.
- Collect accounting flags in the LWP, and collate on LWP exit.
 1.5 07-Mar-2006  thorpej branches: 1.5.2; 1.5.6; 1.5.12;
Syscall debug tracing is handled by trace_enter() / trace_exit(). Change
trace_is_enabled() to return TRUE if SYSCALL_DEBUG is defined, and g/c
all of the SYSCALL_DEBUG handling from individual system call dispatch
routines.
 1.4 07-Mar-2006  thorpej Clean up fallout proc_is_traced_p() change:
- proc_is_traced_p() -> trace_is_enabled(), to match trace_enter() and
trace_exit().
- trace_is_enabled() becomes a real function.
- Remove unnecessary include files from various files that used to care
about KTRACE and SYSTRACE, but do no more.
 1.3 05-Mar-2006  christos Add a proc_is_traced_p() macro and use it, instead of copying the same code
in many places. Idea from thorpej.
 1.2 05-Mar-2006  christos branches: 1.2.2;
implement PT_SYSCALL
 1.1 09-Feb-2006  manu branches: 1.1.2;
Add initial (but unfinished) COMPAT_LINUX32 for amd64. This is good enough so
that the i386 license manager part of amd64 version of Fluent works.

While I'm here, add SysV IPC to COMPAT_LINUX/amd64
 1.1.2.2 18-Feb-2006  yamt sync with head.
 1.1.2.1 09-Feb-2006  yamt file linux32_syscall.c was added on branch yamt-uio_vmspace on 2006-02-18 15:38:30 +0000
 1.2.2.3 11-Aug-2006  yamt sync with head
 1.2.2.2 13-Mar-2006  yamt sync with head.
 1.2.2.1 05-Mar-2006  yamt file linux32_syscall.c was added on branch yamt-pdpolicy on 2006-03-13 09:06:51 +0000
 1.5.12.10 17-Mar-2008  yamt sync with head.
 1.5.12.9 27-Feb-2008  yamt sync with head.
 1.5.12.8 11-Feb-2008  yamt sync with head.
 1.5.12.7 21-Jan-2008  yamt sync with head
 1.5.12.6 15-Nov-2007  yamt sync with head.
 1.5.12.5 03-Sep-2007  yamt sync with head.
 1.5.12.4 26-Feb-2007  yamt sync with head.
 1.5.12.3 30-Dec-2006  yamt sync with head.
 1.5.12.2 21-Jun-2006  yamt sync with head.
 1.5.12.1 07-Mar-2006  yamt file linux32_syscall.c was added on branch yamt-lazymbuf on 2006-06-21 14:48:18 +0000
 1.5.6.2 22-Apr-2006  simonb Sync with head.
 1.5.6.1 07-Mar-2006  simonb file linux32_syscall.c was added on branch simonb-timecounters on 2006-04-22 11:37:11 +0000
 1.5.2.2 07-Mar-2006  thorpej Syscall debug tracing is handled by trace_enter() / trace_exit(). Change
trace_is_enabled() to return TRUE if SYSCALL_DEBUG is defined, and g/c
all of the SYSCALL_DEBUG handling from individual system call dispatch
routines.
 1.5.2.1 07-Mar-2006  thorpej file linux32_syscall.c was added on branch elad-kernelauth on 2006-03-07 07:21:51 +0000
 1.6.8.1 22-Oct-2006  yamt sync with head
 1.6.6.2 09-Sep-2006  rpaulo sync with head
 1.6.6.1 19-Jul-2006  rpaulo file linux32_syscall.c was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:37:05 +0000
 1.6.4.4 30-Jan-2007  ad Remove support for SA. Ok core@.
 1.6.4.3 11-Jan-2007  ad Checkpoint work in progress.
 1.6.4.2 18-Nov-2006  ad Sync with head.
 1.6.4.1 17-Nov-2006  ad Checkpoint work in progress.
 1.8.2.4 07-May-2007  yamt sync with head.
 1.8.2.3 24-Mar-2007  yamt sync with head.
 1.8.2.2 12-Mar-2007  rmind Sync with HEAD.
 1.8.2.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.11.6.1 29-Mar-2007  reinoud Pullup to -current
 1.11.4.1 11-Jul-2007  mjf Sync with head.
 1.11.2.4 03-Dec-2007  ad Sync with HEAD.
 1.11.2.3 20-Aug-2007  ad Sync with HEAD.
 1.11.2.2 27-May-2007  ad Sync with head.
 1.11.2.1 10-Apr-2007  ad Sync with head.
 1.13.10.2 04-Nov-2007  jmcneill Sync with HEAD.
 1.13.10.1 16-Aug-2007  jmcneill Sync with HEAD.
 1.13.6.1 03-Sep-2007  skrll Sync with HEAD.
 1.13.2.1 03-Oct-2007  garbled Sync with HEAD
 1.14.6.1 13-Nov-2007  bouyer Sync with HEAD
 1.14.2.3 23-Mar-2008  matt sync with HEAD
 1.14.2.2 09-Jan-2008  matt sync with HEAD
 1.14.2.1 06-Nov-2007  matt sync with HEAD
 1.17.8.2 08-Jan-2008  bouyer Sync with HEAD
 1.17.8.1 02-Jan-2008  bouyer Sync with HEAD
 1.17.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.20.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.20.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.20.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.20.2.1 24-Mar-2008  keiichi sync with head.
 1.23.2.1 18-May-2008  yamt sync with head.
 1.24.8.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.24.8.1 19-Oct-2008  haad Sync with HEAD.
 1.24.4.3 15-Oct-2008  wrstuden Remove some now-unneeded includes. Matches previous changes to i386 code.
 1.24.4.2 23-May-2008  wrstuden Re-add userret hook. Add a new define, SA_NO_USERRET, which
indicates that upcall support should NOT be included. Add this
for all non-netbsd emulations. They will never be SA apps, so
let's make the invarient pretty blatant.

NetBSD code should include both sys/sa.h and sys/savar.h.
 1.24.4.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.24.2.2 11-Mar-2010  yamt sync with head
 1.24.2.1 04-May-2009  yamt sync with head.
 1.27.8.4 10-Jan-2011  jym Sync with HEAD
 1.27.8.3 24-Oct-2010  jym Sync with HEAD
 1.27.8.2 01-Nov-2009  jym Sync with HEAD.
 1.27.8.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.27.2.1 28-Apr-2009  skrll Sync with HEAD.
 1.29.4.1 05-Mar-2011  rmind sync with head
 1.30.18.1 03-Dec-2017  jdolecek update from HEAD
 1.31.2.1 06-Apr-2015  skrll Sync with HEAD
 1.4 01-Nov-2017  maxv More END(). In linux_sigcode.S we only provide symbols, not defined as
functions.
 1.3 30-Oct-2017  maxv Always use END() markers when declaring functions in assembly, so that ld
can compute the size of the functions. A few remain.

While here, fix a bug in the INTRSTUB macro: we are falling through
resume_, but it is aligned, so it looks like we're executing the inter-
function padding - which probably happens to contain NOPs, but that's
still bad.
 1.2 11-Dec-2005  christos branches: 1.2.122;
merge ktrace-lwp.
 1.1 03-May-2005  manu branches: 1.1.8;
First work on COMPAT_LINUX/amd64
Process startup and dynamiclinking work, but processes hang due to
Linux arch_prctl(2) not being really supported yet.
 1.1.8.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.8.1 03-May-2005  skrll file linux_sigcode.S was added on branch ktrace-lwp on 2005-11-10 13:50:24 +0000
 1.2.122.1 03-Dec-2017  jdolecek update from HEAD
 1.33 05-Oct-2023  ad Arrange to update cached LWP credentials in userret() rather than during
syscall/trap entry, eliminating a test+branch on every syscall/trap.

This wasn't possible in the 3.99.x timeframe when l->l_cred came about
because there wasn't a reliable/timely way to force an ONPROC LWP running on
a remote CPU into the kernel (which is just about the only new thing in
this scheme).
 1.32 07-Mar-2015  christos add dtrace hooks
 1.31 20-Dec-2010  matt branches: 1.31.18; 1.31.36;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.
 1.30 21-Nov-2009  rmind branches: 1.30.4;
Use lwp_getpcb() on x86 MD code, clean from struct user usage.
 1.29 21-Oct-2008  ad branches: 1.29.8;
Provide a small inline wrapper for sysent::sy_call() and use it to store
the active syscall description in struct lwp. To be used at some future
point to prevent unloading of modules that provide syscalls, while the
syscalls are in use.
 1.28 21-Oct-2008  ad Undo revivesa damage to userret().
 1.27 15-Oct-2008  wrstuden Merge wrstuden-revivesa into HEAD.
 1.26 28-Apr-2008  martin branches: 1.26.2; 1.26.6;
Remove clause 3 and 4 from TNF licenses
 1.25 24-Apr-2008  ad branches: 1.25.2;
- Retire SYCALL_MPSAFE. With the exceptions of darwin and irix emulations,
all system calls are now MPSAFE.
- Remove unneeded acquire/release of kernel_lock.
 1.24 11-Mar-2008  ad branches: 1.24.2;
Make context switch + syscall counters optionally per-CPU and accumulate
in schedclock() at "about 16 hz".
 1.23 06-Mar-2008  njoly Do not use SYS_NSYSENT but the corresponding emulation definitions
instead {LINUX,LINUX32}_SYS_NSYSENT.

While here, cleanup some includes.
 1.22 24-Feb-2008  dsl Set p->p_trace_enabled in fork and whenever the controlling falgs change
instead of doing it in syscall_intern().
Note that syscall_intern() must still be called when the flags change
since many ports use a different copy of the syscall entry code when
tracing is enabled.
 1.21 06-Feb-2008  dsl branches: 1.21.2; 1.21.6;
Remove the 'args' parameter to 'trace_exit()' it is no longer used.
Instead of passing the (un)real system call code and syscall table pointer,
just pass the number of arguments - which is what ktrace really wants.
Ride forthcoming 4.99.53
 1.20 05-Jan-2008  dsl Don't pass 'curlwp' into trace_enter() and trace_exit().
 1.19 05-Jan-2008  dsl Reorder the amd64 trapframe (swap rcx/r10 and add 4 spare slots after r9).
This allows the syscall code to pass the syscall args directly from the
trapframe instead of copying them to a separate structure.
It is still possible that some lurking code still assumes that
'struct trapframe', 'struct mcontext' and 'struct reg' all have the
registers in the same order, but I've fixed enough of them to get gdb working.
 1.18 03-Nov-2007  dsl branches: 1.18.2; 1.18.8;
Linux doesn't have a SYS_syscall system call (it is all done in libc), and
definitely doesn't have SYS___syscall.
Kill all the code - now matching i386/i386/linux_syscall.c
There is also no point using a switch statement (and it's unpredictable
jump indirect) to save a few memory copies.
 1.17 03-Nov-2007  dsl Merge linux_syscall_fancy and linux_syscall_plain.
 1.16 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.15 14-Sep-2007  njoly branches: 1.15.4;
Do not include opt_*.h unless _KERNEL_OPT is defined
 1.14 26-Apr-2007  njoly branches: 1.14.2; 1.14.10; 1.14.12;
Save the translated error value from Native to Linux, used by tracing
functions.

Reviewed by manu.
 1.13 05-Mar-2007  xtraeme branches: 1.13.2; 1.13.4;
die caddr_t, die.
 1.12 04-Mar-2007  christos Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.11 09-Feb-2007  ad branches: 1.11.2;
Merge newlock2 to head.
 1.10 24-Jan-2007  hubertf 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.9 19-Jul-2006  ad branches: 1.9.4;
- Hold a reference to the process credentials in each struct lwp.
- Update the reference on syscall and user trap if p_cred has changed.
- Collect accounting flags in the LWP, and collate on LWP exit.
 1.8 07-Mar-2006  thorpej branches: 1.8.2;
Syscall debug tracing is handled by trace_enter() / trace_exit(). Change
trace_is_enabled() to return TRUE if SYSCALL_DEBUG is defined, and g/c
all of the SYSCALL_DEBUG handling from individual system call dispatch
routines.
 1.7 07-Mar-2006  thorpej Clean up fallout proc_is_traced_p() change:
- proc_is_traced_p() -> trace_is_enabled(), to match trace_enter() and
trace_exit().
- trace_is_enabled() becomes a real function.
- Remove unnecessary include files from various files that used to care
about KTRACE and SYSTRACE, but do no more.
 1.6 05-Mar-2006  christos Add a proc_is_traced_p() macro and use it, instead of copying the same code
in many places. Idea from thorpej.
 1.5 05-Mar-2006  christos branches: 1.5.2;
implement PT_SYSCALL
 1.4 07-Dec-2005  rjs branches: 1.4.4; 1.4.6;
Make it compile when not using KTRACE or SYSTRACE.
 1.3 01-Nov-2005  christos branches: 1.3.2;
Split the linux syscall out to make the code easier to read and maintain.
 1.2 15-May-2005  fvdl branches: 1.2.2; 1.2.4;
Fix up COMPAT_LINUX support for amd64. Still a work in progress, not
usable yet ("Hello World" runs, but many other things do not work).
 1.1 03-May-2005  manu First work on COMPAT_LINUX/amd64
Process startup and dynamiclinking work, but processes hang due to
Linux arch_prctl(2) not being really supported yet.
 1.2.4.1 02-Nov-2005  yamt sync with head.
 1.2.2.10 17-Mar-2008  yamt sync with head.
 1.2.2.9 27-Feb-2008  yamt sync with head.
 1.2.2.8 11-Feb-2008  yamt sync with head.
 1.2.2.7 21-Jan-2008  yamt sync with head
 1.2.2.6 15-Nov-2007  yamt sync with head.
 1.2.2.5 27-Oct-2007  yamt sync with head.
 1.2.2.4 03-Sep-2007  yamt sync with head.
 1.2.2.3 26-Feb-2007  yamt sync with head.
 1.2.2.2 30-Dec-2006  yamt sync with head.
 1.2.2.1 21-Jun-2006  yamt sync with head.
 1.3.2.3 11-Dec-2005  christos Sync with head.
 1.3.2.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.3.2.1 01-Nov-2005  skrll file linux_syscall.c was added on branch ktrace-lwp on 2005-11-10 13:50:24 +0000
 1.4.6.1 22-Apr-2006  simonb Sync with head.
 1.4.4.1 09-Sep-2006  rpaulo sync with head
 1.5.2.3 11-Aug-2006  yamt sync with head
 1.5.2.2 13-Mar-2006  yamt sync with head.
 1.5.2.1 05-Mar-2006  yamt file linux_syscall.c was added on branch yamt-pdpolicy on 2006-03-13 09:06:51 +0000
 1.8.2.2 07-Mar-2006  thorpej Syscall debug tracing is handled by trace_enter() / trace_exit(). Change
trace_is_enabled() to return TRUE if SYSCALL_DEBUG is defined, and g/c
all of the SYSCALL_DEBUG handling from individual system call dispatch
routines.
 1.8.2.1 07-Mar-2006  thorpej file linux_syscall.c was added on branch elad-kernelauth on 2006-03-07 07:21:51 +0000
 1.9.4.4 01-Feb-2007  ad Sync with head.
 1.9.4.3 30-Jan-2007  ad Remove support for SA. Ok core@.
 1.9.4.2 11-Jan-2007  ad Checkpoint work in progress.
 1.9.4.1 17-Nov-2006  ad Checkpoint work in progress.
 1.11.2.2 07-May-2007  yamt sync with head.
 1.11.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.13.4.1 11-Jul-2007  mjf Sync with head.
 1.13.2.3 03-Dec-2007  ad Sync with HEAD.
 1.13.2.2 09-Oct-2007  ad Sync with head.
 1.13.2.1 27-May-2007  ad Sync with head.
 1.14.12.3 23-Mar-2008  matt sync with HEAD
 1.14.12.2 09-Jan-2008  matt sync with HEAD
 1.14.12.1 06-Nov-2007  matt sync with HEAD
 1.14.10.2 04-Nov-2007  jmcneill Sync with HEAD.
 1.14.10.1 02-Oct-2007  joerg Sync with HEAD.
 1.14.2.1 03-Oct-2007  garbled Sync with HEAD
 1.15.4.1 13-Nov-2007  bouyer Sync with HEAD
 1.18.8.1 08-Jan-2008  bouyer Sync with HEAD
 1.18.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.21.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.21.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.21.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.21.2.1 24-Mar-2008  keiichi sync with head.
 1.24.2.1 18-May-2008  yamt sync with head.
 1.25.2.3 11-Mar-2010  yamt sync with head
 1.25.2.2 04-May-2009  yamt sync with head.
 1.25.2.1 16-May-2008  yamt sync with head.
 1.26.6.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.26.6.1 19-Oct-2008  haad Sync with HEAD.
 1.26.2.3 15-Oct-2008  wrstuden Remove some now-unneeded includes. Matches previous changes to i386 code.
 1.26.2.2 23-May-2008  wrstuden Re-add userret hook. Add a new define, SA_NO_USERRET, which
indicates that upcall support should NOT be included. Add this
for all non-netbsd emulations. They will never be SA apps, so
let's make the invarient pretty blatant.

NetBSD code should include both sys/sa.h and sys/savar.h.
 1.26.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.29.8.2 10-Jan-2011  jym Sync with HEAD
 1.29.8.1 24-Oct-2010  jym Sync with HEAD
 1.30.4.1 05-Mar-2011  rmind sync with head
 1.31.36.1 06-Apr-2015  skrll Sync with HEAD
 1.31.18.1 03-Dec-2017  jdolecek update from HEAD
 1.2 15-May-2005  fvdl Move linux_trap.c from sys/arch/i386/i386 to sys/arch/x86/x86, and share
it. Remove the amd64 linux_trap.c (which was just a stub with a printf
anyway).
 1.1 03-May-2005  manu First work on COMPAT_LINUX/amd64
Process startup and dynamiclinking work, but processes hang due to
Linux arch_prctl(2) not being really supported yet.
 1.38 13-Sep-2022  knakahara Fix PR kern/57007. I missed applying a part of the original patch.
 1.37 07-Sep-2022  knakahara NetBSD/x86: Raise the number of interrupt sources per CPU from 32 to 56.

There has been no objection for three years.
https://mail-index.netbsd.org/port-amd64/2019/09/22/msg003012.html
Implemented by nonaka@n.o, updated by me.
 1.36 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.35 08-Dec-2019  ad branches: 1.35.2; 1.35.6;
After lots of testing I'm not convinced of the benefit to the tweak
I made to rw_enter(), so undo it to return to baseline.
 1.34 23-Nov-2019  ad For this case during build.sh:

rw_enter(lock, RW_READ);

Having instrumented it, it turns out that >99.5% of the time the lock is
completely unknowned. Make this assumption in the assembly stub for
rw_enter(), and avoid the initial read of the lock word. Where there are
existing read holds, we'll do an additional CMPXCHG but should already have
the cache line in the EXCLUSIVE state.
 1.33 14-Nov-2019  maxv Add support for Kernel Memory Sanitizer (kMSan). It detects uninitialized
memory used by the kernel at run time, and just like kASan and kCSan, it
is an excellent feature. It has already detected 38 uninitialized variables
in the kernel during my testing, which I have since discreetly fixed.

We use two shadows:
- "shad", to track uninitialized memory with a bit granularity (1:1).
Each bit set to 1 in the shad corresponds to one uninitialized bit of
real kernel memory.
- "orig", to track the origin of the memory with a 4-byte granularity
(1:1). Each uint32_t cell in the orig indicates the origin of the
associated uint32_t of real kernel memory.

The memory consumption of these shadows is consequent, so at least 4GB of
RAM is recommended to run kMSan.

The compiler inserts calls to specific __msan_* functions on each memory
access, to manage both the shad and the orig and detect uninitialized
memory accesses that change the execution flow (like an "if" on an
uninitialized variable).

We mark as uninit several types of memory buffers (stack, pools, kmem,
malloc, uvm_km), and check each buffer passed to copyout, copyoutstr,
bwrite, if_transmit_lock and DMA operations, to detect uninitialized memory
that leaves the system. This allows us to detect kernel info leaks in a way
that is more efficient and also more user-friendly than KLEAK.

Contrary to kASan, kMSan requires comprehensive coverage, ie we cannot
tolerate having one non-instrumented function, because this could cause
false positives. kMSan cannot instrument ASM functions, so I converted
most of them to __asm__ inlines, which kMSan is able to instrument. Those
that remain receive special treatment.

Contrary to kASan again, kMSan uses a TLS, so we must context-switch this
TLS during interrupts. We use different contexts depending on the interrupt
level.

The orig tracks precisely the origin of a buffer. We use a special encoding
for the orig values, and pack together in each uint32_t cell of the orig:
- a code designating the type of memory (Stack, Pool, etc), and
- a compressed pointer, which points either (1) to a string containing
the name of the variable associated with the cell, or (2) to an area
in the kernel .text section which we resolve to a symbol name + offset.

This encoding allows us not to consume extra memory for associating
information with each cell, and produces a precise output, that can tell
for example the name of an uninitialized variable on the stack, the
function in which it was pushed on the stack, and the function where we
accessed this uninitialized variable.

kMSan is available with LLVM, but not with GCC.

The code is organized in a way that is similar to kASan and kCSan, so it
means that other architectures than amd64 can be supported.
 1.32 05-Sep-2019  maxv Remove unused, and style.
 1.31 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.30 25-Dec-2018  cherry Excise XEN specific code out of x86/x86/intr.c into xen/x86/xen_intr.c

While at it, separate the source function tracking so that the interrupt
paths are truly independant.

Use weak symbol exporting to provision for future PVHVM co-existence
of both files, but with independant paths. Introduce assembler code
such that in a unified scenario, native interrupts get first priority
in spllower(), followed by XEN event callbacks. IPL management and
semantics are unchanged - native handlers and xen callbacks are
expected to maintain their ipl related semantics.

In summary, after this commit, native and XEN now have completely
unrelated interrupt handling mechanisms, including
intr_establish_xname() and assembler stubs and intr handler
management.

Happy Christmas!
 1.29 14-Jul-2018  maxv Drop NENTRY() from the x86 kernels, use ENTRY(). With PMCs (and other hardware
tracing facilities) we have a much better ways of monitoring the CPU activity
than GPROF, without software modification.

Also I think GPROF has never worked, because the 'start' functions of both
i386 and amd64 use ENTRY(), and it would have caused a function call while the
kernel was not yet relocated.
 1.28 07-Jan-2018  maxv branches: 1.28.2; 1.28.4;
Switch x86_retpatch[] -> HOTPATCH().
 1.27 07-Jan-2018  maxv Switch x86_lockpatch[] -> HOTPATCH().
 1.26 11-Apr-2016  bouyer __cpu_simple_unlock() is called from _mcount(), so don't call mcount() from
__cpu_simple_unlock().
Kernel profiling should work again
 1.25 22-Jun-2013  uebayasi branches: 1.25.10;
Use END() to set ELF symbol size. Set local data type/size too.
 1.24 12-Jan-2011  joerg branches: 1.24.8; 1.24.18;
Allow use of traditional CPP to be set on a per platform base in sys.mk.
Honour this for dependency processing in bsd.dep.mk. Switch i386 and
amd64 assembly to use ISO C90 preprocessor concat and drop the
-traditional-cpp on this platform.
 1.23 24-Apr-2009  ad branches: 1.23.4;
.long -> .quad
 1.22 24-Apr-2009  ad A workaround for a bug with some Opteron revisions where locked operations
sometimes do not serve as memory barriers, allowing memory references to
bleed outside of critical sections. It's possible that this is the
reason for pkgbuild's longstanding crashiness.

This is not complete (atomic ops need some work too).
 1.21 05-Dec-2008  ad branches: 1.21.4;
- Fix a bug in amd64 rw_tryenter() where it could return failure even after
acquiring a lock, if aligned on a 4GB boundary.

- Microoptimize more.
 1.20 27-Jun-2008  ad branches: 1.20.2; 1.20.4; 1.20.6;
mutex_spin_enter: xchg is usually cheaper than cmpxchg, so use it.
 1.19 25-May-2008  chs branches: 1.19.2;
enable profiling of assembly functions.
 1.18 06-May-2008  ad branches: 1.18.2;
doh
 1.17 06-May-2008  ad rw_tryenter: there is a few instruction race between reading rw_owner and
doing the cmpxchg, where another thread can successfully get a read hold
on the lock. That shouldn't fail anyone trying trying to get a read
hold. So for read locks, never bail just because the CAS fails, only bail
if we the status bits in the lock word say we can't have it.
 1.16 03-May-2008  yamt rename END to ENDLABEL. i'll use END for other purpose. ok by Andrew Doran.
 1.15 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.14 28-Apr-2008  ad - Make these preemption safe.
- Try to avoid mispredicted branches.
 1.13 25-Jan-2008  ad branches: 1.13.6; 1.13.8; 1.13.10;
- Prevent LOCKDEBUG from complaining if we do rw_tryenter() on a lock
that we already own.
- Add an assembly stub for rw_tryenter().
 1.12 21-Dec-2007  dsl Change the xen CLI() and STI() defines to only use one scratch register.
As well as saving an instruction, in one place it saves a push/pop pair.
 1.11 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.10 28-Nov-2007  ad branches: 1.10.2; 1.10.6;
x86_mb_nop is now unused.
 1.9 28-Nov-2007  ad Hook in the atomic ops from libkern.
 1.8 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.7 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.6 18-Oct-2007  yamt branches: 1.6.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.5 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.4 29-Aug-2007  ad branches: 1.4.2; 1.4.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.3 17-May-2007  yamt branches: 1.3.4; 1.3.8; 1.3.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.2 09-Feb-2007  ad branches: 1.2.2; 1.2.4; 1.2.8; 1.2.10; 1.2.14; 1.2.16;
Merge newlock2 to head.
 1.1 10-Sep-2006  ad branches: 1.1.2;
file lock_stubs.S was initially added on branch newlock2.
 1.1.2.13 02-Feb-2007  ad - Define memory barrier ops in lock_stubs.S.
- If lfence/mfence are available, patch them in at boot.
- Patch to a no-op if !MULTIPROCESSOR. XXX Should be determined at runtime.
 1.1.2.12 27-Jan-2007  ad Rename some functions to better describe what they do.
 1.1.2.11 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.1.2.10 19-Jan-2007  ad Fix double byte branch target in smutex_exit. From yamt@.
 1.1.2.9 12-Jan-2007  ad Fix 'SPL NOT LOWERED ON SYSCALL EXIT' with amd64.
 1.1.2.8 12-Jan-2007  ad Make amd64 build again.
 1.1.2.7 11-Jan-2007  ad Checkpoint work in progress.
 1.1.2.6 29-Dec-2006  ad Checkpoint work in progress.
 1.1.2.5 17-Nov-2006  ad Checkpoint work in progress.
 1.1.2.4 20-Oct-2006  ad Tweak slightly, and fix a bug in the 80386 case.
 1.1.2.3 11-Sep-2006  ad Tweak slightly, no functional change.
 1.1.2.2 11-Sep-2006  ad Fix a thinko.
 1.1.2.1 10-Sep-2006  ad Add updated locking primatives.
 1.2.16.2 03-Oct-2007  garbled Sync with HEAD
 1.2.16.1 22-May-2007  matt Update to HEAD.
 1.2.14.1 17-Apr-2007  thorpej G/C _lock_cas(). atomic_cas_ptr() is used instead.
 1.2.10.1 11-Jul-2007  mjf Sync with head.
 1.2.8.6 03-Dec-2007  ad Sync with HEAD.
 1.2.8.5 23-Oct-2007  ad Sync with head.
 1.2.8.4 09-Oct-2007  ad Sync with head.
 1.2.8.3 09-Oct-2007  ad Sync with head.
 1.2.8.2 21-Aug-2007  ad amd64 changes, as yet untested:

- Adapt to vmlocking branch.
- Apply TLB shootdown and pv allocation changes to the pmap.
- Make it build.
 1.2.8.1 27-May-2007  ad Sync with head.
 1.2.4.8 04-Feb-2008  yamt sync with head.
 1.2.4.7 21-Jan-2008  yamt sync with head
 1.2.4.6 07-Dec-2007  yamt sync with head
 1.2.4.5 15-Nov-2007  yamt sync with head.
 1.2.4.4 27-Oct-2007  yamt sync with head.
 1.2.4.3 03-Sep-2007  yamt sync with head.
 1.2.4.2 26-Feb-2007  yamt sync with head.
 1.2.4.1 09-Feb-2007  yamt file lock_stubs.S was added on branch yamt-lazymbuf on 2007-02-26 09:05:39 +0000
 1.2.2.1 04-Apr-2007  ad Sync with i386:

If cmpxchg8b fails, don't immediatley enter Xspllower - retry first.
 1.3.10.3 23-Mar-2008  matt sync with HEAD
 1.3.10.2 09-Jan-2008  matt sync with HEAD
 1.3.10.1 06-Nov-2007  matt sync with HEAD
 1.3.8.5 03-Dec-2007  joerg Sync with HEAD.
 1.3.8.4 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.3.8.3 11-Nov-2007  joerg Sync with HEAD.
 1.3.8.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.3.8.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.3.4.1 03-Sep-2007  skrll Sync with HEAD.
 1.4.4.3 13-Nov-2007  bouyer Sync with HEAD
 1.4.4.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.4.4.1 17-Oct-2007  bouyer amd64 (aka x86-64) support for Xen. Based on the OpenBSD port done by
Mathieu Ropert in 2006.
DomU-only for now. An INSTALL_XEN3_DOMU kernel with a ramdisk will boot to
sysinst if you're lucky. Often it panics because a runable LWP has
a NULL stack (really, it's all of l->l_addr which is has been zeroed out
while the process was on the queue !)
TODO:
- bug fixes :)
- Most of the xpq_* functions should be shared with xen/i386
- The xen/i386 assembly bootstrap code should be remplaced with the C
version in xenamd64/amd64/xpmap.c
- see if a config(5) trick could allow to merge xenamd64 back to xen or amd64.
 1.4.2.1 07-Oct-2007  yamt remove some #ifdef _LOCORE and use genassym instead.
 1.6.2.4 18-Feb-2008  mjf Sync with HEAD.
 1.6.2.3 27-Dec-2007  mjf Sync with HEAD.
 1.6.2.2 08-Dec-2007  mjf Sync with HEAD.
 1.6.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.10.6.1 02-Jan-2008  bouyer Sync with HEAD
 1.10.2.1 26-Dec-2007  ad Sync with head.
 1.13.10.2 04-May-2009  yamt sync with head.
 1.13.10.1 16-May-2008  yamt sync with head.
 1.13.8.2 04-Jun-2008  yamt sync with head
 1.13.8.1 18-May-2008  yamt sync with head.
 1.13.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.13.6.2 29-Jun-2008  mjf Sync with HEAD.
 1.13.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.18.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.18.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.19.2.1 03-Jul-2008  simonb Sync with head.
 1.20.6.3 13-May-2009  snj Pull up following revision(s) (requested by ad in ticket #725):
sys/arch/amd64/amd64/lock_stubs.S: revision 1.23
.long -> .quad
 1.20.6.2 13-May-2009  snj Pull up following revision(s) (requested by ad in ticket #725):
sys/arch/amd64/amd64/lock_stubs.S: revision 1.22
sys/arch/i386/i386/lock_stubs.S: revision 1.23
sys/arch/x86/x86/patch.c: revision 1.18
A workaround for a bug with some Opteron revisions where locked operations
sometimes do not serve as memory barriers, allowing memory references to
bleed outside of critical sections. It is possible that this is the
reason for pkgbuild's longstanding crashiness.
This is not complete (atomic ops need some work too).
 1.20.6.1 02-Feb-2009  snj branches: 1.20.6.1.2;
Pull up following revision(s) (requested by ad in ticket #342):
sys/arch/amd64/amd64/lock_stubs.S: revision 1.21
sys/arch/i386/i386/lock_stubs.S: revision 1.22
- Fix a bug in amd64 rw_tryenter() where it could return failure even after
acquiring a lock, if aligned on a 4GB boundary.
- Microoptimize more.
 1.20.6.1.2.2 13-May-2009  snj branches: 1.20.6.1.2.2.2;
Pull up following revision(s) (requested by ad in ticket #725):
sys/arch/amd64/amd64/lock_stubs.S: revision 1.23
.long -> .quad
 1.20.6.1.2.1 13-May-2009  snj Pull up following revision(s) (requested by ad in ticket #725):
sys/arch/amd64/amd64/lock_stubs.S: revision 1.22
sys/arch/i386/i386/lock_stubs.S: revision 1.23
sys/arch/x86/x86/patch.c: revision 1.18
A workaround for a bug with some Opteron revisions where locked operations
sometimes do not serve as memory barriers, allowing memory references to
bleed outside of critical sections. It's possible that this is the
reason for pkgbuild's longstanding crashiness.
This is not complete (atomic ops need some work too).
 1.20.6.1.2.2.2.1 21-Apr-2010  matt sync to netbsd-5
 1.20.4.2 28-Apr-2009  skrll Sync with HEAD.
 1.20.4.1 19-Jan-2009  skrll Sync with HEAD.
 1.20.2.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.21.4.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.21.4.2 01-Nov-2009  jym Sync with HEAD.
 1.21.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.23.4.1 05-Mar-2011  rmind sync with head
 1.24.18.2 03-Dec-2017  jdolecek update from HEAD
 1.24.18.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.24.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.25.10.1 22-Apr-2016  skrll Sync with HEAD
 1.28.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.28.4.1 10-Jun-2019  christos Sync with HEAD
 1.28.2.2 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.28.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.35.6.2 12-Apr-2020  bouyer Get rid of xen-specific ci_x* interrupt handling:
- use the general SIR mechanism, reserving 3 more slots for IPL_VM, IPL_SCHED
and IPL_HIGH
- remove specific handling from C sources, or change to ipending
- convert IPL number to SIR number in various places
- Remove XUNMASK/XPENDING in assembly or change to IUNMASK/IPENDING
- remove Xen-specific ci_xsources, ci_xmask, ci_xunmask, ci_xpending from
struct cpu_info
- for now remove a KASSERT that there are no pending interrupts in
idle_block(). We can get there with some software interrupts pending
in autoconf XXX needs to be looked at.
 1.35.6.1 11-Apr-2020  bouyer Move softint and preemtion-related functions out of x86/x86/intr.c to
its own file, x86/x86/x86_softintr.c
Add x86/x86/x86_softintr.c for native and XenPV
Make sure XenPV also check ci_ioending, which is used for softints.
Switch XenPV to fast softints and allow kernel preemption.
kpreempt_disable() before calling pmap_changeprot_local()
run xen_wallclock_time() and xen_global_systime_ns() at splshed() to
avoid being interrupted.

XXX amd64 lock stubs are racy for XPENDING
 1.35.2.2 22-Jan-2020  ad Back out previous.
 1.35.2.1 19-Jan-2020  ad Adaptive rwlocks proposed on tech-kern and working well on this branch
with vnode locks.
 1.233 09-Sep-2025  bouyer Fix some issues with symbol table detection on Xen PVH:
- the stack grows down so the last pushed value is at 0(%esp), not -4(%esp).
Pointed out by Joachim Kuebart.
- 0x3fffffff is 1GB-1, not 1MB-1. Test the symtab size against 16MB
(amd64 generic symbol table is just above 1MB these days)
- I got confused by cmp's arguments order between intel and gas syntax,
so the tests did the opposite of intended and the symtab was always
considered valid.
While there use unsigned conditions.

Should fix booting in PVH mode with netbsd-INSTALL (which is stripped)
 1.232 07-Sep-2025  andvar Fix various typos, mainly in comments.
 1.231 03-Sep-2025  bouyer Our PVH bootstrap code assumed that the hvm_start_info structure provided
by Xen is just after the end of the symbol case. With Xen 4.20 it's not
always the case, so:
- get the symbol table size from the first byte of the symbol table area
provided by Xen. As we don't know if there is a symbol table or not,
do a minimal sanity check on the size.
- if the hvm_start_info structure is not in the page after kernel_end or
esym, copy it there (this was already done in the genpvh case). While
there, if we copy we can easily compute the size and not assume it all fits
in one page.
With this, a NetBSD PVH dom0 can boot on Xen 4.20
 1.230 30-Jun-2025  imil branches: 1.230.2;
Make getstarttsc() conditional on BOOT_DURATION kernel option.
Avoids use of rdtsc on i486-class CPUs which do not support it.
 1.229 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.228 30-Mar-2025  khorben locore.S: remove duplicate comment

Trivial change, tested anyway on NetBSD/amd64; NFCI.

"Go go" imil@
 1.227 03-Dec-2024  bouyer Get one more change from PR kern/57813, needed for non-Xen PVH.
 1.226 02-Dec-2024  bouyer Add support for non-Xen PVH guests to amd64. Patch from
Emile 'iMil' Heitor in PR kern/57813, with some cosmetic tweaks by me.
Tested on bare metal, Xen PV and Xen PVH by me.
 1.225 31-Jul-2024  andvar s/brinds/brings/ in comments.
 1.224 16-Oct-2023  bouyer branches: 1.224.6;
Xen's start_info_t is larger than 512 bytes these days, so bump the copy
size to a whole PAGE_SIZE, and CTASSERT() that start_info_t is smaller.
Luckily we didn't use yet the parts skipped
 1.223 16-Jul-2023  riastradh x86: Sprinkle extensive commentary about %fs/%gs initialization.

Plus some other side quests like the three-stage GDT metamorphosis
lifecycle.

No functional change intended.
 1.222 24-Jun-2023  msaitoh Fix typo in comment.
 1.221 14-May-2023  riastradh x86/locore.S: Nix trailing whitespace.
 1.220 05-May-2023  manu Add a SELFRELOC kernel option for the sake of documentation clarity.

Instead of telling that x86/boot(8) reloc command needs a kernel able
to self relocate, we can tell it needs a kernel built with the
SELFRELOC option. This keeps the reader from wondering what could
make a kernel able to self relocate.
 1.219 20-Apr-2023  manu Add reloc keyworkd to let EFI bootstrap load amd64 kernel at any address

EFI bootstrap assumes it can copy the amd64 kernel to its ELF load
address (that is KERNTEXTOFF - KERNBASE = 0x200000), but it can
clash with previous UEFI memory allocation, as described here:
http://mail-index.netbsd.org/tech-kern/2023/04/07/msg028833.html

This change adds a reloc keyword for controling where the EFI
boostrap will copy the kernel image. Possible values are:
default - the default and prior behavior, copy at 0x200000.
none - do not copy and use the kernel image where it was loaded.
address - specify an explicit address where to copy the kernel.

This comes with an amd64 kernel patch that makes it self-relocatable.
It first discover where it was loaded in memory, and if this is
different than the expected 0x200000, hhe the kernel relocates
itself and start over at the right address.
 1.218 03-Mar-2023  riastradh Revert "x86: Add kthread_fpu_enter/exit support, take two."

kthread_fpu_enter/exit changes broke some hardware, unclear why, to
investigate before fixing and reapplying these changes.
 1.217 01-Mar-2023  riastradh x86: Expand on comments on ordering around stores to ci_curlwp.

No functional change intended.

PR kern/57240
 1.216 25-Feb-2023  riastradh x86: Add kthread_fpu_enter/exit support, take two.

This time, make sure to restore the FPU state when switching to a
kthread in the middle of kthread_fpu_enter/exit.

This adds a single predicted-taken branch for the case of kthreads
that are not in kthread_fpu_enter/exit, so it incurs a penalty only
for threads that actually use it. Since it avoids FPU state
switching in kthreads that do use the FPU, namely cgd worker threads,
this should be a net performance win on systems using it and have
negligible impact otherwise.

XXX pullup-10
 1.215 26-Dec-2022  christos sysret -> sysretl for new binutils
 1.214 07-Sep-2022  knakahara branches: 1.214.4;
NetBSD/x86: Raise the number of interrupt sources per CPU from 32 to 56.

There has been no objection for three years.
https://mail-index.netbsd.org/port-amd64/2019/09/22/msg003012.html
Implemented by nonaka@n.o, updated by me.
 1.213 12-Jun-2022  bouyer XenPV: in cpu_switchto(), reset ci_xen_clockf_usermode/ci_xen_clockf_pc,
in case a clock interrupt is deffered while we're switching lwp.
Fix a (rare) panic:
panic: kernel diagnostic assertion "p != NULL" failed: file "/usr/src/sys/kern/kern_clock.c", line 438
seen when xen_timer_handler() is called from the splx() at the end of
mi_switch()
 1.212 10-Nov-2021  msaitoh s/annouce/announce/ in comment.
 1.211 13-Aug-2021  andvar s/struture/structure/ s/structre/structure/
 1.210 21-Jun-2020  bouyer On amd64, Xen PV calls syscalls and traps with events enabled.
Disable events on entry to be safe.
It should have been mostly safe for most cases, but for FPU traps
we need to reload the FPU state if we got interrupted at trap entry.

Hopefully fixes:
panic: kernel diagnostic assertion "curlwp->l_md.md_flags & MDL_FPU_IN_CPU" failed: file "/home/source/ab/HEAD/src/sys/arch/x86/x86/fpu.c", line 524

when running tests.
 1.209 27-May-2020  ad - Add a couple of wrapper functions around STOS and MOVS and use them to zero
and copy PTEs in preference to memset()/memcpy().

- Remove related SSE / pageidlezero stuff.
 1.208 05-May-2020  maxv Fix KASAN, init_xen_early must be called after kasan_early_init.
 1.207 02-May-2020  christos Fix build without XEN
 1.206 02-May-2020  bouyer Introduce Xen PVH support in GENERIC.
This is compiled in with
options XENPVHVM
x86 changes:
- add Xen section and xen pvh entry points to locore.S. Set vm_guest
to VM_GUEST_XENPVH in this entry point.
Most of the boot procedure (especially page table setup and switch to
paged mode) is shared with native.
- change some x86_delay() to delay_func(), which points to x86_delay() for
native/HVM, and xen_delay() for PVH

Xen changes:
- remove Xen bits from init_x86_64_ksyms() and init386_ksyms()
and move to xen_init_ksyms(), used for both PV and PVH
- set ISA no-legacy-devices property for PVH
- factor out code from Xen's cpu_bootconf() to xen_bootconf()
in xen_machdep.c
- set up a specific pvh_consinit() which starts with printk()
(which uses a simple hypercall that is available early) and switch to
xencons when we can use pmap_kenter_pa().
 1.205 02-May-2020  maxv Call kasan_early_init earlier, to unbreak KASAN after the recent RNG
changes. Will also prevent further trouble.
 1.204 30-Apr-2020  maxv The labels are already global, drop unused.
 1.203 30-Apr-2020  maxv Switch to templates.
 1.202 26-Apr-2020  maxv Put the template functions in the rodata section; they get hotpatched
into other places, but never execute directly.
 1.201 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.200 15-Jan-2020  ad branches: 1.200.4;
Back out the cpu_switchto() workaround now that it's no longer needed.
 1.199 13-Jan-2020  ad It looks like Xen cpu_hatch() calls cpu_switchto() with prevlwp=NULL,
instead of calling idle_loop() directly. I can't test a change to
cpu_hatch() right now so allow for prevlwp=NULL.
 1.198 09-Jan-2020  manu Rollback multiboot2 for amd64, as requested by core
 1.197 08-Jan-2020  skrll oldlwp is always non-NULL in cpu_switchto so remove the test for NULL.
 1.196 08-Jan-2020  ad Hopefully fix some problems seen with MP support on non-x86, in particular
where curcpu() is defined as curlwp->l_cpu:

- mi_switch(): undo the ~2007ish optimisation to unlock curlwp before
calling cpu_switchto(). It's not safe to let other actors mess with the
LWP (in particular l->l_cpu) while it's still context switching. This
removes l->l_ctxswtch.

- Move the LP_RUNNING flag into l->l_flag and rename to LW_RUNNING since
it's now covered by the LWP's lock.

- Ditch lwp_exit_switchaway() and just call mi_switch() instead. Everything
is in cache anyway so it wasn't buying much by trying to avoid saving old
state. This means cpu_switchto() will never be called with prevlwp ==
NULL.

- Remove some KERNEL_LOCK handling which hasn't been needed for years.
 1.195 15-Dec-2019  manu branches: 1.195.2;
Fix typo that caused two instructions to be commented out

Oddly, that did not break booting.
 1.194 15-Dec-2019  manu Restore multiboot 2 header in amd64 kernel

The header must appear below 32k offset in the kernel file, but we
have to make sure it does not load at low addresses, otherwise we
break BIOS boot.

.text section used to load at 0x200000, we just load multiboot section
there, and have .text loaded just after.
 1.193 10-Dec-2019  manu Add multiboot 2 support to amd64 kernel
 1.192 22-Nov-2019  ad - On-demand zeroing pages with MOVNTI is crazy. It empties L1/L2/L3.
- Disable zeroing in the idle loop. That needs a cache-friendly strategy.

Result: 3 to 4% reduction in kernel build time on my test system.
Inspired by a discussion with Mateusz Guzik and David Maxwell.
 1.191 21-Nov-2019  ad x86: abort pageidlezero unconditionally if there is something to run.
 1.190 14-Nov-2019  maxv Add support for Kernel Memory Sanitizer (kMSan). It detects uninitialized
memory used by the kernel at run time, and just like kASan and kCSan, it
is an excellent feature. It has already detected 38 uninitialized variables
in the kernel during my testing, which I have since discreetly fixed.

We use two shadows:
- "shad", to track uninitialized memory with a bit granularity (1:1).
Each bit set to 1 in the shad corresponds to one uninitialized bit of
real kernel memory.
- "orig", to track the origin of the memory with a 4-byte granularity
(1:1). Each uint32_t cell in the orig indicates the origin of the
associated uint32_t of real kernel memory.

The memory consumption of these shadows is consequent, so at least 4GB of
RAM is recommended to run kMSan.

The compiler inserts calls to specific __msan_* functions on each memory
access, to manage both the shad and the orig and detect uninitialized
memory accesses that change the execution flow (like an "if" on an
uninitialized variable).

We mark as uninit several types of memory buffers (stack, pools, kmem,
malloc, uvm_km), and check each buffer passed to copyout, copyoutstr,
bwrite, if_transmit_lock and DMA operations, to detect uninitialized memory
that leaves the system. This allows us to detect kernel info leaks in a way
that is more efficient and also more user-friendly than KLEAK.

Contrary to kASan, kMSan requires comprehensive coverage, ie we cannot
tolerate having one non-instrumented function, because this could cause
false positives. kMSan cannot instrument ASM functions, so I converted
most of them to __asm__ inlines, which kMSan is able to instrument. Those
that remain receive special treatment.

Contrary to kASan again, kMSan uses a TLS, so we must context-switch this
TLS during interrupts. We use different contexts depending on the interrupt
level.

The orig tracks precisely the origin of a buffer. We use a special encoding
for the orig values, and pack together in each uint32_t cell of the orig:
- a code designating the type of memory (Stack, Pool, etc), and
- a compressed pointer, which points either (1) to a string containing
the name of the variable associated with the cell, or (2) to an area
in the kernel .text section which we resolve to a symbol name + offset.

This encoding allows us not to consume extra memory for associating
information with each cell, and produces a precise output, that can tell
for example the name of an uninitialized variable on the stack, the
function in which it was pushed on the stack, and the function where we
accessed this uninitialized variable.

kMSan is available with LLVM, but not with GCC.

The code is organized in a way that is similar to kASan and kCSan, so it
means that other architectures than amd64 can be supported.
 1.189 12-Oct-2019  maxv 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.188 04-Oct-2019  maxv Rename fpu_eagerswitch to fpu_switch, and add fpu_xstate_reload to
simplify.
 1.187 03-Oct-2019  maxv Remove the LazyFPU code, as posted 5 months ago on port-amd64@.
 1.186 21-Aug-2019  maxv Switch from printf to panic. These messages were notorious for being
unreadable, and at least a clean panic allows the user to inspect the
system via DDB. Also simplify the output, EAX gets overwritten with
the error code so it indicates nothing meaningful.
 1.185 18-May-2019  maxv branches: 1.185.2;
Two changes in the CPU mitigations:

* Micro-optimize: put every mitigation in the same branch. This removes
two branches in each exc/int return path, and removes all branches in
the syscall return path.

* Modify the SpectreV2 mitigation to be compatible with SpectreV4. I
recently realized that both couldn't be enabled at the same time on
Intel. This is because initially, when there was just SpectreV2, we
could reset the whole IA32_SPEC_CTRL MSR. But then Intel added another
bit in it for SpectreV4, so it isn't right to reset it entirely
anymore. SSBD needs to stay.
 1.184 18-May-2019  maxv Set the symbol type for intrfastexit, so that tools like tprof can find
the symbol name.
 1.183 15-May-2019  maxv Enable EagerFPU on Xen PV. Should work as-is. Sent on port-amd64@.
 1.182 15-May-2019  maxv Change the way SVS is disabled. Now you have to pass "boot -3" from the
bootloader. The machdep.svs.enabled sysctl becomes read-only, and just
indicates whether SVS is enabled.

Sent on port-amd64@.
 1.181 14-May-2019  maxv Mitigation for INTEL-SA-00233: Microarchitectural Data Sampling (MDS).

It requires a microcode update, now available on the Intel website. The
microcode modifies the behavior of the VERW instruction, and makes it flush
internal CPU buffers. We hotpatch the return-to-userland path to add VERW.

Two sysctls are added:

machdep.mds.mitigated = {0/1} user-settable
machdep.mds.method = {string} constructed by the kernel

The kernel will automatically enable the mitigation if the updated
microcode is present. If the new microcode is not present, the user can
load it via cpuctl, and set machdep.mds.mitigated=1.
 1.180 09-Mar-2019  maxv Start replacing the x86 PTE bits.
 1.179 07-Mar-2019  maxv Drop PG_RO, PG_KR and PG_PROT, they are useless and create confusion.
 1.178 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.177 13-Feb-2019  cherry Rig the hypercall callback page such that when the kernel happens to
run without a XEN domain loader having previously overwritten the
hypercall page with its hypercall trampoline machine code, we still
get to detect its presence by calling the xen_version hypercall stub.

We use this hack to detect the presence or absence of the hypervisor,
without relying on the MSR support on HVM domains.

This works as an added sanity check that the hypercall page
registration has indeed succeeded in HVM mode.
 1.176 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.175 02-Feb-2019  cherry Switch NetBSD/xen to use XEN api tag RELEASE-4.11.1

The headers for this api are in sys/external/mit/xen-include-public/dist/
 1.174 12-Aug-2018  maxv More ASLR: randomize the location of the PTE area. The PTE slot is not
created in locore anymore, but a little later; by using the already
entered L4 page, rather than the recursive slot itself (which doesn't
exist yet).

In the prekern we still map the slot - the prekern behaves as an external
locore -, because we need it as part of the randomization/relocation
work. The kernel then removes this slot, and regenerates a randomized
one.

Tested on GENERIC and GENERIC_KASLR, Xen doesn't have it and dom0 still
boots fine.
 1.173 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.172 21-Jul-2018  maxv More ASLR. Randomize the location of the direct map at boot time on amd64.
This doesn't need "options KASLR" and works on GENERIC. Will soon be
enabled by default.

The location of the areas is abstracted in a slotspace structure. Ideally
we should always use this structure when touching the L4 slots, instead of
the current cocktail of global variables and constants.

machdep initializes the structure with the default values, and we then
randomize its dmap entry. Ideally machdep should randomize everything at
once, but in the case of the direct map its size is determined a little
later in the boot procedure, so we're forced to randomize its location
later too.
 1.171 14-Jul-2018  maxv Drop NENTRY() from the x86 kernels, use ENTRY(). With PMCs (and other hardware
tracing facilities) we have a much better ways of monitoring the CPU activity
than GPROF, without software modification.

Also I think GPROF has never worked, because the 'start' functions of both
i386 and amd64 use ENTRY(), and it would have caused a function call while the
kernel was not yet relocated.
 1.170 12-Jul-2018  maxv Handle NMIs correctly when SVS is enabled. We store the kernel's CR3 at the
top of the NMI stack, and we unconditionally switch to it, because we don't
know with which page tables we received the NMI. Hotpatch the whole thing as
usual.

This restores the ability to use PMCs on Intel CPUs.
 1.169 09-Jul-2018  maxv Don't push/pop %rdx, we don't care about preserving its value.
 1.168 09-Jul-2018  maxv Small optimization: don't execute the Meltdown/SpectreV2 cswitch code if
we're leaving a softint. We were executing the softint with the LWP's
context, so no need to switch the SVS/IBRS contexts, we already are in
the desired contexts.
 1.167 29-Jun-2018  maxv Call fpu_eagerswitch a little later, after we make sure newlwp is not
pinned.

Because if it is, the fpu state of the lwp we are context-switching to
is already installed on the current cpu, so no point re-installing it.
Or, it isn't, and in this case we don't want to install it.

This wrong re-installation can occur when we leave a softint.

It may fix bugs in places that call fpusave_lwp with spl != IPL_HIGH,
and that expect the fpu state to stay in memory. As far as I can tell
only cpu_lwp_free meets these conditions, and as far as I can tell
again, there it's harmless.

Should help PR/53399.
 1.166 14-Jun-2018  maxv branches: 1.166.2;
Add some code to support eager fpu switch, INTEL-SA-00145. We restore the
FPU state of the lwp right away during context switches. This guarantees
that when the CPU executes in userland, the FPU doesn't contain secrets.

Maybe we also need to clear the FPU in setregs(), not sure about this one.

Can be enabled/disabled via:

machdep.fpu_eager = {0/1}

Not yet turned on automatically on affected CPUs (Intel Family 6).

More generally it would be good to turn it on automatically when XSAVEOPT
is supported, because in this case there is probably a non-negligible
performance gain; but we need to fix PR/52966.
 1.165 23-Apr-2018  joerg Adjust Xsyscall_svs to not use movq for 64bit immediates either.
 1.164 21-Apr-2018  joerg Do not use movq for loading arbitrary 64bit immediates. The ISA
restricts it to 32bit immediates.
 1.163 30-Mar-2018  maxv Add #ifndef XEN, xen doesn't have speculation_barrier.
 1.162 29-Mar-2018  maxv Allow IBRS to be disabled dynamically.
 1.161 28-Mar-2018  maxv The call to svs_lwp_switch can clobber %rdi/%rsi, so restore them before
calling speculation_barrier.
 1.160 28-Mar-2018  maxv Add the IBRS mitigation for SpectreV2 on amd64.

Different operations are performed during context transitions:

user->kernel: IBRS <- 1
kernel->user: IBRS <- 0

And during context switches:

user->user: IBPB <- 0
kernel->user: IBPB <- 0
[user->kernel:IBPB <- 0 this one may not be needed]

We use two macros, IBRS_ENTER and IBRS_LEAVE, to set the IBRS bit. The
thing is hotpatched for better performance, like SVS.

The idea is that IBRS is a "privileged" bit, which is set to 1 in kernel
mode and 0 in user mode. To protect the branch predictor between user
processes (which are of the same privilege), we use the IBPB barrier.

The Intel manual also talks about (MWAIT/HLT)+HyperThreading, and says
that when using either of the two instructions IBRS must be disabled for
better performance on the core. I'm not totally sure about this part, so
I'm not adding it now.

IBRS is available only when the Intel microcode update is applied. The
mitigation must be enabled manually with machdep.spectreV2.mitigated.

Tested by msaitoh a week ago (but I adapted a few things since). Probably
more changes to come.
 1.159 20-Mar-2018  maxv (Re)Fix handling of segment register faults. My previous attempt did fix
faults occuring when reloading %es/%ds/%fs/%gs, but it did not fix faults
occuring when executing 'iretq', because before iretq we needed to do +16
in %rsp, and the resulting stack layout was not the one kernuser_reenter()
expected (tf_trapno and tf_err were not there).

So now: pop tf_trapno and tf_err right away in intrfastexit(), and update
the layout in kernuser_reenter() accordingly. The resulting code is
actually simpler.

Tested by "hardcoding" an iretq fault; the process correctly receives a
SIGSEGV.

(Note that segment register faults do not happen in the wild, you really
need to try hard to trigger one.)
 1.158 20-Mar-2018  maxv Remove the sysretq fault handler. It is broken with SVS, and not really
needed anyway. Initially I had added it so that if such a fault was
received the kernel would panic "cleanly" instead of crashing in a
potentially undefined way.

I'll re-add this handler later.
 1.157 25-Feb-2018  maxv branches: 1.157.2;
Fix handling of segment register faults when running with SVS. The behavior
is changed also in the non-SVS case.

I've put a documentation in amd64_trap.S. Basically, the problem with SVS
is that if iret faults, we already have a full trapframe pushed on the
stack and the CPU will push another frame on this stack (nested), but it
hits the redzone below the stack since it is still running with the user
page table loaded.

To fix that, we pop a good part of the trapframe earlier in intrfastexit.
If iret faults, the current %rsp has enough room for an iret frame, and
the CPU can push that without problem. We then switch back to the outer
iret frame (the frame the CPU was trying to pop by executing iret, but that
it didn't pop for real because iret faulted), call INTRENTRY, and handle
the trap as if it had been received from userland directly.
 1.156 24-Feb-2018  maxv Use %rax instead of %r15 in the non-SVS case, to reduce the diff against
SVS. In SVS we use %rax instead of %r15 because the following instructions
cannot be encoded:

movq %r15,SVS_UTLS+UTLS_SCRATCH
movq SVS_UTLS+UTLS_RSP0,%r15
 1.155 22-Feb-2018  maxv Adapt previous; put #ifdef SVS around the declaration directly.
 1.154 22-Feb-2018  martin Protect the SVS part of SYSCALL_ENTRY by #ifdef SVS to make non-SVS
kernels compile again.
 1.153 22-Feb-2018  maxv Make the machdep.svs_enabled sysctl writable, and add the kernel code
needed to disable SVS at runtime.

We set 'svs_enabled' to false, and hotpatch the kernel entry/exit points
to eliminate the context switch code.

We need to make sure there is no remote CPU that is executing the code we
are hotpatching. So we use two barriers:

* After the first one each CPU is guaranteed to be executing in
svs_disable_cpu with interrupts disabled (this way it can't leave this
place).

* After the second one it is guaranteed that SVS is disabled, so we flush
the cache, enable interrupts and continue execution normally.

Between the two barriers, cpu0 will disable SVS (svs_enabled=false and
hotpatch), and each CPU will restore the generic syscall entry point.

Three notes:

* We should call svs_pgg_update(true) afterwards, to put back PG_G on
the kernel pages (for better performance). This will be done in another
commit.

* The fact that we disable interrupts does not prevent us from receiving
an NMI, and it would be problematic. So we need to add some code to
verify that PMCs are disabled before hotpatching. This will be done
in another commit.

* In svs_disable() we expect each CPU to be online. We need to add a
check to make sure they indeed are.

The sysctl allows only a 1->0 transition. There is no point in doing 0->1
transitions anyway, and it would be complicated to implement because we
need to re-synchronize the CPU user page tables with the current ones (we
lost track of them in the last 1->0 transition).
 1.152 22-Feb-2018  maxv Add a dynamic detection for SVS.

The SVS_* macros are now compiled as skip-noopt. When the system boots, if
the cpu is from Intel, they are hotpatched to their real content.
Typically:

jmp 1f
int3
int3
int3
... int3 ...
1:

gets hotpatched to:

movq SVS_UTLS+UTLS_KPDIRPA,%rax
movq %rax,%cr3
movq CPUVAR(KRSP0),%rsp

These two chunks of code being of the exact same size. We put int3 (0xCC)
to make sure we never execute there.

In the non-SVS (ie non-Intel) case, all it costs is one jump. Given that
the SVS_* macros are small, this jump will likely leave us in the same
icache line, so it's pretty fast.

The syscall entry point is special, because there we use a scratch uint64_t
not in curcpu but in the UTLS page, and it's difficult to hotpatch this
properly. So instead of hotpatching we declare the entry point as an ASM
macro, and define two functions: syscall and syscall_svs, the latter being
the one used in the SVS case.

While here 'syscall' is optimized not to contain an SVS_ENTER - this way
we don't even need to do a jump on the non-SVS case.

When adding pages in the user page tables, make sure we don't have PG_G,
now that it's dynamic.

A read-only sysctl is added, machdep.svs_enabled, that tells whether the
kernel uses SVS or not.

More changes to come, svs_init() is not very clean.
 1.151 18-Feb-2018  maxv Add svs_enabled, which defaults to 'true' when SVS is compiled (no dynamic
detection yet).
 1.150 27-Jan-2018  maxv Use testb, faster.
 1.149 22-Jan-2018  maxv Ah, remove duplicate SVS_LEAVE. Fixes 32bit binaries. While here remove
duplicate 'cli', but that's harmless.
 1.148 21-Jan-2018  maxv Unmap the kernel from userland in SVS, and leave only the needed
trampolines. As explained below, SVS should now completely mitigate
Meltdown on GENERIC kernels, even though it needs some more tweaking
for GENERIC_KASLR.

Until now the kernel entry points looked like:

FUNC(intr)
pushq $ERR
pushq $TRAPNO
INTRENTRY
... handle interrupt ...
INTRFASTEXIT
END(intr)

With this change they are split and become:

FUNC(handle)
... handle interrupt ...
INTRFASTEXIT
END(handle)

TEXT_USER_BEGIN
FUNC(intr)
pushq $ERR
pushq $TRAPNO
INTRENTRY
jmp handle
END(intr)
TEXT_USER_END

A new section is introduced, .text.user, that contains minimal kernel
entry/exit points. In order to choose what to put in this section, two
macros are introduced, TEXT_USER_BEGIN and TEXT_USER_END.

The section is mapped in userland with normal 4K pages.

In GENERIC, the section is 4K-page-aligned and embedded in .text, which
is mapped with large pages. That is to say, when an interrupt comes in,
the CPU has the user page tables loaded and executes the 'intr' functions
on 4K pages; after calling SVS_ENTER (in INTRENTRY) these 4K pages become
2MB large pages, and remain so when executing in kernel mode.

In GENERIC_KASLR, the section is 4K-page-aligned and independent from the
other kernel texts. The prekern just picks it up and maps it at a random
address.

In GENERIC, SVS should now completely mitigate Meltdown: what we put in
.text.user is not secret.

In GENERIC_KASLR, SVS would have to be improved a bit more: the
'jmp handle' instruction is actually secret, since it leaks the address
of the section we are jumping into. By exploiting Meltdown on Intel, this
theoretically allows a local user to reconstruct the address of the first
text section. But given that our KASLR produces several texts, and that
each section is not correlated with the others, the level of protection
KASLR provides is still good.
 1.147 18-Jan-2018  maxv Unmap the kernel heap from the user page tables (SVS).

This implementation is optimized and organized in such a way that we
don't need to copy the kernel stack to a safe place during user<->kernel
transitions. We create two VAs that point to the same physical page; one
will be mapped in userland and is offset in order to contain only the
trapframe, the other is mapped in the kernel and maps the entire stack.

Sent on tech-kern@ a week ago.
 1.146 11-Jan-2018  maxv Declare new SVS_* variants: SVS_ENTER_NOSTACK and SVS_LEAVE_NOSTACK. Use
SVS_ENTER_NOSTACK in the syscall entry point, and put it before the code
that touches curlwp. (curlwp is located in the direct map.)

Then, disable __HAVE_CPU_UAREA_ROUTINES (to be removed later). This moves
the kernel stack into pmap_kernel(), and not the direct map. That's a
change I've always wanted to make: because of the direct map we can't add
a redzone on the stack, and basically, a stack overflow can go very far
in memory without being detected (as far as erasing all of the system's
memory).

Finally, unmap the direct map from userland.
 1.145 07-Jan-2018  maxv Add a new option, SVS (for Separate Virtual Space), that unmaps kernel
pages when running in userland. For now, only the PTE area is unmapped.

Sent on tech-kern@.
 1.144 04-Jan-2018  maxv Allocate the TSS area dynamically. This way cpu_info and cpu_tss can be
put in separate pages.
 1.143 26-Nov-2017  maxv Update a comment, and use testw instead.
 1.142 26-Nov-2017  maxv Hide a bunch of raw symbols.
 1.141 21-Nov-2017  maxv Remove unused symbol - it is aligned to 4096 and this reduces the number
of possible locations for .bss in KASLR kernels.
 1.140 28-Oct-2017  bouyer Use FLAT_RING3_CS64 (defined in Xen public headers) instead of numeric
value.
 1.139 28-Oct-2017  maxv It appears that Xen remaps the userland %cs to 0xE033. So add it to the
checklist. Otherwise we're going through Luexit32: %fs gets reloaded,
which sets the FS.base to NULL, which will cause the thread to page-fault
next time it accesses its TLS (as seen in PR/52662).

This fix is not very clean, and it would be nice to understand why Xen
remaps %cs. But I'm committing it now anyway, so that people can test.
 1.138 21-Oct-2017  maxv Use labels instead of disassembling *(%rip). intrfastexit is now the
only place where the segregs can fault.
 1.137 21-Oct-2017  maxv Improve our segregs model. Pass 3/3.

Treat %gs the same way we treat %ds/%es/%fs: restore it in INTRFASTEXIT
on 32bit LWPs.

On Xen however, its behavior does not change, because we need to do an
hypercall before INTR_RESTORE_GPRS, and that's too complicated for now.

As a side effect, this change fixes a bug in the ACPI wakeup code; %fs/%gs
were not restored on 32bit LWPs, and chances are they would segfault
shortly afterwards.

Support for USER_LDT on amd64 is almost complete now.
 1.136 19-Oct-2017  maxv Use cmpw.
 1.135 19-Oct-2017  maxv Improve our segregs model. Pass 2/3.

Treat %fs the same way we treat %ds and %es. For a new 32bit LWP %fs is
set to GUDATA32_SEL, and always updated in INTRFASTEXIT.

This solves an important issue we had until now: we couldn't handle the
faults generated by the "movw $val,%fs" instructions, because they were
deep into the kernel context. Now %fs can fault only in INTRFASTEXIT,
which is safe.

Note that it also fixes a bug I believe affected the kernel: on AMD CPUs,
setting %fs to zero does not flush the internal register state, and
therefore we could leak the %fs base address when context-switching. This
being said, I couldn't trigger the issue on the AMD cpu I have. Whatever,
it's fixed now, since we first set %fs to GUDATA32 - which does flush the
register state.
 1.134 19-Oct-2017  maxv Improve our segregs model. Pass 1/3.

Right now, we are saving and restoring %ds/%es each time we enter/leave the
kernel. However, we let %fs/%gs live in the kernel space, and we rely on
the fact that when switching to an LWP, %fs/%gs are set right away (via
cpu_switchto or setregs).

It has two drawbacks: we are taking care of %ds/%es while they are
deprecated (useless) on 64bit LWPs, and we are restricting %fs/%gs while
they still have a meaning on 32bit LWPs.

Therefore, handle 32bit and 64bit LWPs differently:
* 64bit LWPs use fixed segregs, which are not taken care of.
* 32bit LWPs have dynamic segregs, always saved/restored.

For now, only %ds and %es are changed; %fs and %gs will be in the next
passes.

The trapframe is constructed as usual. In INTRFASTEXIT, we restore %ds/%es
depending on the %cs value. If %cs contains one of the two standard 64bit
selectors, don't do anything. Otherwise, restore everything.

When doing a context switch, just restore %ds/%es to their default values.
On a 32bit LWP they will be overwritten by INTRFASTEXIT; on a 64bit LWP
they won't be updated.

In the ACPI wakeup code, restore %ds/%es to the default 64bit user value.
 1.133 17-Oct-2017  maxv Move %ds and %es into the GDT on 64bit LWPs.
 1.132 17-Oct-2017  maxv Have the cpu clear PSL_D automatically when entering the kernel via a
syscall. Then, don't clear PSL_D and PSL_AC in the syscall entry point,
they are now both cleared by the cpu (faster). However they still need to
be manually cleared in the interrupt/trap entry points.
 1.131 30-Sep-2017  maxv Add a bootspace structure. It describes the physical and virtual space
layout created by the early kernel bootstrap code. Start using it, and
eliminate several references to KERNBASE and other global symbols. While
here clean up xen-i386, it's really tiring.
 1.130 28-Sep-2017  maxv Clean up, and initialize the lwp0 fields in init_x86_64.
 1.129 15-Sep-2017  maxv Declare INTRFASTEXIT as a function, so that there is only one iretq in the
kernel. Then, check %rip against the address of this iretq instead of
disassembling (%rip) - which could fault again, or point at some random
address which happens to contain the iretq opcode. The same is true for gs
below, but I'll fix that in another commit.
 1.128 31-Aug-2017  maxv Add a layer of mitigation against the intel sysret vuln: restore %gs when
sysretq faults. Right now we try to make sure that %rip is canonical by
performing sanity checks in several places, but I've already found missing
checks two times already, and there may be others.

By performing an additional swapgs here, we are turning ring0 exploits to
simple DoSes - which are still security bugs, but of a lower impact.
 1.127 31-Aug-2017  maxv Construct the trap frame with interrupts disabled, for safety, just like
the rest of the interrupt entry points.
 1.126 10-Aug-2017  maxv Don't include opt_compat_ibcs2.h. No idea what it was doing in amd64,
since it never got implemented there.
 1.125 08-Aug-2017  maxv Remove dumb debug code and outdated comment.
 1.124 01-Jul-2017  maxv Remove the osyscall call gate on i386, and emulate it. There is a one-
instruction race in it that could panic the kernel.
 1.123 25-Mar-2017  maxv branches: 1.123.6;
Don't need gdtstore here.
 1.122 23-Mar-2017  maxv Remove this call gate on amd64, it is useless and vulnerable.

Call gates do not modify %rflags, so interrupts are not disabled when
entering the gate. There is a small window where we are in kernel mode and
with a userland %gs, and if an interrupt happens here we will rejump into
the kernel but not switch to the kernel TLS.

Userland can simply perform a gate call in a loop, and hope that at some
point an interrupt will be received in this window - which necessarily will
be the case. With a specially-crafted %gs it is certainly enough to
escalate privileges.
 1.121 09-Feb-2017  maxv If the preloaded modules cannot be mapped with the initial amount of VA,
discard the associated bootinfo entry. Otherwise the machine faults and
reboots immediately.

I spotted this bug more than a year ago, but I recently saw that there is
already PR/42645 (7 years old), so just fix it. The size has been increased
in the meantime, so the limit is unlikely to be reached anyway.
 1.120 09-Feb-2017  maxv Restore %ds before swapgs. Movs to segment registers are allowed to fault
in kernel mode but simply cause a signal to be sent to userland. The thing
is, in this case %gs is not restored when entering the trap routine, which
means the kernel uses userland's TLS instead of using its own. Which in
short makes it easy to escalate privileges.

Currently, this bug is triggered only in one place, which I am about to
fix too.
 1.119 02-Feb-2017  maxv Fix these comments, we probably won't want to keep them up to date.
 1.118 17-Dec-2016  maxv branches: 1.118.2;
Fix the name of the labels. I think I got confused by jne, so while here
replace it by jnz, which is more explicit.
 1.117 16-Dec-2016  maxv The way the xen dummy page is taken care of makes absolutely no sense at
all, with magic offsets here and there in different layers of the system.
It is just blind luck that everything has always worked as expected so
far.

Due to this wrong design we have a problem now: we allocate one physical
page for lapic, and it happens to overlap with the dummy page, which
causes the system to crash.

Fix this by keeping the dummy va directly in a variable instead of magic
offsets. The asm locore now increments the first pa to hide the dummy page
to machdep and pmap.
 1.116 09-Dec-2016  maxv On amd64 we try to guarantee that VA = PA + KERNBASE in the bootstrap
memory. But we have a problem with the ISA I/O MEM, because its va is
located above the kernel and its pa below it, so it does not respect
the rule.

To compensate for that we make the map look like the ISA stuff is above
the kernel by applying an offset on the pa. The issue with this design is
that we systematically lose 96 pages of physical memory.

Fix this by applying the offset on the va instead. Now these 96 pages are
internalized into uvm, and the rule is respected until kern_end.
 1.115 06-Dec-2016  maxv Use __kernel_end instead. Does not change anything, but will be meaningful
soon.
 1.114 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.113 11-Nov-2016  maxv Rename xen_pmap_bootstrap to xen_locore, it really has nothing to do with
pmap and is just a C version of what amd64 and i386 do in asm.
 1.112 11-Nov-2016  maxv Mmh, I mistakenly removed the lapic page (which is part of another diff),
put it back in.
 1.111 11-Nov-2016  maxv KNF and simplify Xen
 1.110 16-Oct-2016  maxv Remove lapic_tpr on amd64 and i386, unused. Now, we have only one pointer
to the LAPIC page, and each register access is done with relative offsets.
 1.109 21-Aug-2016  maxv Simplify.
 1.108 25-Jul-2016  maxv Remove lapic_id, lapic_ppr and lapic_isr. We need to be careful though: the
offset of lapic_tpr must not change, and the whole area must be exactly one
page.
 1.107 11-Jul-2016  maxv branches: 1.107.2;
KNF and simplify.
 1.106 09-Jul-2016  maxv The CPU considers a given va as executable if none of its levels have
the NOX bit. With the top level recursive slot, however, several levels
are recursively omitted, which implies that each entry that is not the
child of NOX-ed parents actually appears somewhere in the virtual space
as executable via this slot, even if it is followed by an underlying
entry that has the NOX bit.

This recursive slot is only used to edit the page tree itself. Make it
non-executable.
 1.105 08-Jul-2016  maxv The preloaded modules are now reallocated dynamically by the kernel. This
area does not need to be executable anymore.
 1.104 04-Jul-2016  maxv Make the execution flow canonical instead of jumping back and forth, and
complete the userland check.
 1.103 01-Jul-2016  maxv Try to make this part more readable. No functional change.
 1.102 04-Jun-2016  maxv The ISA I/O MEM does not need to be executable. Remove the X permission
on it.
 1.101 04-Jun-2016  maxv Use the same instruction layout to map the ISA I/O. No functional
change.

The comment is still wrong: we are not on (4), we are actually below
the kernel area in physical memory. I'll fix that later.
 1.100 04-Jun-2016  maxv Reorder some definitions. Reduces the diff between amd64 and i386.
 1.99 29-May-2016  bouyer Switch to elf notes for amd64 instead of the old key=value list to describe the
guest requirements and support.
Add infrastructure to query the hypervisor about features support.
For verbose boot, print the features suppoted by the hypervisor for this
guest.
 1.98 29-May-2016  maxv Define tablesize. Useful when debugging.
 1.97 29-May-2016  maxv Revert rev1.94. It apparently raises a page fault from SMEP. I need to
investigate the whole kernel mappings anyway, so I'll recommit this
patch later.
 1.96 28-May-2016  maxv Define fillkpt_blank, which creates blank entries in a page table. Use
it to map the first MB. No functional change.
 1.95 28-May-2016  maxv Move proc0's stack out of the BOOTSTRAP TABLES, and map it independently
with RW permissions. Reduces the impact of a stack overflow.
 1.94 26-May-2016  maxv There is an issue in the way the fillkpt macro sets up pages on both
amd64 and i386.

The fillkpt loop is equivalent to the following:

do {
/* fill in the slot */
/* increment %ebx to the next slot */
/* increment %eax to the next pa */
} while (%ecx > 0)

The issue here is that if %ecx = 0 (i.e., the chunk we are trying to
map is zero-sized), there is still one entry created in the page table.
The kernel expects the va<->pa translation to be linear in low memory.
If there is a zero-sized chunk, the dead entry creates a +4096 offset in
the virtual space, with two consecutive entries that point to the same
physical address. In other words, the mappings are not linear anymore,
which causes the kernel to die.

Before my recent changes, there were only two big chunks that were
mapped, and neither of these could be zero-sized. Now, with multiple,
fine-grained chunks, it is possible that the [SYMS]+[PRELOADED_MODULES]
chunk could be zero-sized.

[PRELOADED_MODULES] is almost never here, and [SYMS] is always here on
default kernels. Except for floppies, where the bootloader does not load
[SYMS].

Should fix PR 51148.
 1.93 22-May-2016  maxv Save L4's physical address earlier. Also, PDE_SIZE has nothing to do
here, we are just zeroing out the upper 32bits of the 64bit pointer.
 1.92 15-May-2016  maxv Split the PRELOADED_MODULES+BOOTSTRAP_TABLES chunk into two separate
chunks mapped independently with RWX and RW, on both amd64 and i386.

This way the BOOTSTRAP TABLES are non-executable.
 1.91 15-May-2016  maxv Reduce the diff between amd64 and i386. We invert two instructions on
amd64, but it makes no difference since PDE_SIZE = 8.
 1.90 12-May-2016  maxv Map the data+bss chunk independently on amd64, and remove the X
permission on it.
 1.89 12-May-2016  maxv Define fillkpt_nox, which sets up a set of pages and puts the NOX bit on
them by using nox_flag. Use fillkpt_nox to map the rodata segment
without X permissions.
 1.88 12-May-2016  maxv Map the rodata segment independently on amd64, and remove the W permission
on it.
 1.87 12-May-2016  maxv Split the {text+rodata} chunk in two separate chunks on x86. The
rodata segment now loses the large page optimization, gets mapped inside
the data segment, and therefore becomes RWX. It may break the build on
Xen.
 1.86 11-May-2016  maxv There is a bug in the way the secondary CPUs are launched on amd64.

When CPU0 is launched, EFER_NXE is enabled in it, and it allows it to
handle pages that have the NOX bit. When the secondary CPUs are
launched, however, EFER_NXE is enabled only after paging is set in their
%cr0. And therefore, between the moment when paging is enabled and the
moment when EFER_NXE is enabled, the secondary CPUs cannot access pages
that have the NOX bit - they crash if they try to.

The funny thing is that in order to enable EFER_NXE, the secondary CPUs
give a look at cpu_feature[2], which is in the DATA segment, which in
turn could have the NOX bit. In other words, the secondary CPUs crash if
the DATA segment is mapped with the NOX bit.

Fix this by enabling EFER_NXE in the secondary CPUs before enabling
paging. CPU0 initializes nox_flag to the 32bit version of PG_NX if NOX
is supported; the secondary CPUs then use nox_flag to know whether NOX
is supported.

nox_flag will be used for other purposes soon.
 1.85 08-May-2016  maxv Use killkpt for the PML4 entries as well.
 1.84 07-May-2016  maxv clarify
 1.83 25-Nov-2015  maxv Cosmetic changes.
 1.82 22-Nov-2015  maxv Remove cpu_vendorname (unused). It is retrieved later in identcpu.c.
 1.81 22-Nov-2015  maxv Clarify:
- add some comments
- rename some jumps
- KNF
No functional change.
 1.80 20-Nov-2015  maxv A few changes:
- remove cpu_id and cpu_brand_id (unused)
- copy a comment from i386 about fillkpt
- define PDE_SIZE (i386)
 1.79 14-Nov-2015  maxv KNF, and fix some comments
 1.78 30-Aug-2015  uebayasi Use makeoptions_COPY_SYMTAB via opt_copy_symtab.h in sources. Remove a hack
to set -DCOPY_SYMTAB from sys/conf/Makefile.kern.inc. Remove unnecessary
dependencies too.
 1.77 17-Aug-2014  joerg branches: 1.77.2;
Reorganize symbol table embedding. The existing option SYMTAB_SPACE is
replaced by the make option COPY_SYMTAB set to any value. The copy of
the symbol table is no longer put into a buffer in kern_ksyms.o, but a
small helper object. This object is build first with a dummy size, then
the kernel is linked to compute the real dimension of the symbol table
buffer. After that, the helper object is rebuild and the kernel linked
again.
 1.76 16-May-2014  rmind branches: 1.76.2; 1.76.4; 1.76.8;
pcu(9):
- Remove PCU_KERNEL (hi matt!) and significantly simplify the code.
This experimental feature was tried on ARM did not meet the expectations.
It may be revived one day, but it should be done in a much simpler way.
- Add a message structure for xcall function, pass the LWP ower and thus
optimise a race condition: if LWP is discarding its state on a remote CPU,
but another LWP already did it - do not cause an unecessary re-faulting.
- Reduce the variety of flags for PCU operations (only PCU_VALID and
PCU_REENABLE are used now), pass them only to the pcu_state_load().
- Rename pcu_used_p() to pcu_valid_p(); hopefully it is less confusing.
- pcu_save_all_on_cpu: SPL ought to be used here.
- Update and improve the pcu(9) man page; it needs wizd(8) though.
 1.75 01-Dec-2013  christos branches: 1.75.2;
revert fpu/pcu changes until we figure out what's wrong; they cause random
freezes
 1.74 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.73 23-Jun-2013  uebayasi branches: 1.73.2;
Whitespace, comment, NBPG -> PAGE_SIZE.
 1.72 23-Jun-2013  uebayasi Whitespace.
 1.71 22-Jun-2013  uebayasi Use END() markers, etc. Pure ELF .symtab (size) changes.
 1.70 15-Jul-2012  dsl branches: 1.70.2;
Rename MDP_IRET to MDL_IRET since it is an lwp flag, not a proc one.
Add an MDL_COMPAT32 flag to the lwp's md_flags, set it for 32bit lwps
and use it to force 'return to user' with iret (as is done when
MDL_IRET is set).
Split the iret/sysret code paths much later.
Remove all the replicated code for 32bit system calls - which was only
needed so that iret was always used.
frameasm.h for XEN contains '#define swapgs', while XEN probable never
needs swapgs, this is likely to be confusing.
Add a SWAPGS which is a nop on XEN and swapgs otherwise.
(I've not yet checked all the swapgs in files that include frameasm.h)
Simple x86 programs still work.
Hijack 6.99.9 kernel bump (needed for compat32 modules)
 1.69 16-Jun-2012  chs rename the global variable "cpu" to "cputype" to avoid conflicting with
dtrace, which wants to use "cpu" as a local variable.
 1.68 19-Apr-2012  jym Set the CR0_AM bit so processes can enable alignment check errors under
x86 through PSL_AC bit.

ATF test incoming shortly.
 1.67 24-Feb-2012  cherry (xen) - remove the (*xpq_cpu)() shim.We hasten the %fs/%gs setup process during boot.Although this is hacky, it lets us use the non-xen specificpmap_pte_xxx() functions in pmap code (and others).
 1.66 04-Dec-2011  chs branches: 1.66.2;
map all of physical memory using large pages.
ported from openbsd years ago by Murray Armfield,
updated for changes since then by me.
 1.65 20-May-2011  joerg branches: 1.65.4; 1.65.8;
Be more explicit that the "w" part of %r11 is meant.
 1.64 20-Dec-2010  matt branches: 1.64.2;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.
 1.63 18-Dec-2010  jym Free tables are already zeroed in xen_pmap_bootstrap. No need to
do it a second time in assembly code.
 1.62 21-Oct-2010  yamt Xosyscall: sync with Xsyscall.
 1.61 21-Oct-2010  yamt Xsyscall: remove a stale comment.
 1.60 21-Oct-2010  yamt Xsyscall: remove an unused label.
 1.59 21-Oct-2010  yamt Xsyscall: save %es before enabling interrupts. otherwise it can be
clobbered by preemption. PR/43903.
 1.58 07-Jul-2010  chs add the guts of TLS support on amd64. based on joerg's patch,
reworked by me to support 32-bit processes as well.
we now keep %fs and %gs loaded with the user values
while in the kernel, which means we don't need to
reload them when returning to user mode.
 1.57 18-Apr-2010  jym This patch fixes the NX regression issue observed on amd64 kernels, where
per-page execution right was disabled (therefore leading to the inability
of the kernel to detect fraudulent use of memory mappings marked as not
being executable).

- replace cpu_feature and ci_feature_flags variables by cpu_feature and
ci_feat_val arrays. This makes it cleaner and brings kernel code closer
to the design of cpuctl(8). A warning will be raised for each CPU that
does not expose the same features as the Boot Processor (BP).

- the blacklist of CPU features is now a macro defined in the
specialreg.h header, instead of hardcoding it inside MD initialization
code; fix comments.

- replace checks against CPUID_TSC with the cpu_hascounter() function.

- clean up the code in init_x86_64(), as cpu_feature variables are set
inside cpu_probe().

- use cpu_init_msrs() for i386. It will be eventually used later for NX
feature under i386 PAE kernels.

- remove code that checks for CPUID_NOX in amd64 mptramp.S, this is already
performed by cpu_hatch() through cpu_init_msrs().

- remove cpu_signature and feature_flags members from struct mpbios_proc
(they were never used).

This patch was tested with i386 MONOLITHIC, XEN3PAE_DOM0 and XEN3_DOM0 under
a native i386 host, and amd64 GENERIC, XEN3_DOM0 via QEMU virtual machines.

XXX Should kernel rev be bumped?

XXX A similar patch should be pulled-up for NetBSD-5, hopefully tomorrow.
 1.56 18-Apr-2010  jym When kernel remaps to high memory in amd64 locore, the GDT used before
becomes invalid. As such, split it in two parts, one for use when system
boots in low memory, and one for use when it jumps to high memory.
 1.55 27-Nov-2009  rmind branches: 1.55.2; 1.55.4;
- Use uvm_lwp_setuarea() instead of directly setting address to lwp_t::l_addr.
- Replace most remaining uses of l_addr with uvm_lwp_getuarea() or lwp_getpcb().
- Amend assembly in ports where it accesses PCB via struct user.
- Rename L_ADDR to L_PCB in few places. Reduce sys/user.h inclusions.
 1.54 26-Nov-2009  matt Kill proc0paddr. Use lwp0.l_addr instead.
 1.53 25-Nov-2009  rmind Remove IPL_LPT and IPL_IPI aliases, use the actual IPLs.
Fix some broken comments.
 1.52 19-Oct-2009  bouyer Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.51 13-Feb-2009  apb Use "defopt MODULAR" in sys/conf/files, and #include "opt_modular.h"
in all kernel sources that use the MODULAR option.
Proposed in tech-kern on 18 Jan 2009.
 1.50 03-Dec-2008  ad branches: 1.50.4;
Don't abort pageidlezero unless a realtime thread wants to run.
 1.49 13-Nov-2008  ad LKM -> MODULAR
 1.48 11-Nov-2008  ad PR port-amd64/38293 panic: fp_save ipi didn't

Fix race conditions in FPU IPI handling.
 1.47 02-Jun-2008  ad branches: 1.47.4; 1.47.6; 1.47.8;
- Don't bother using sse to copy/zero pages on demand. It turns out not
to be worth it.
- If the machine has sse, re-enable zeroing pages in the idle loop and
use the sse instructions so that we don't blow out the cache.
 1.46 21-May-2008  ad PR port-amd64/38708 lkm_map issues on amd64

Don't plonk lkm_map right on top of the ISA ROM/video hole.
 1.45 16-May-2008  bouyer Initialize cpuid_level for Xen too.
 1.44 11-May-2008  ad Expose the 'cpu' variable.:
 1.43 02-May-2008  ad branches: 1.43.2;
- Give x86 BIOS boot the ability to load new style modules and pass them
into the kernel. Based on a patch by jmcneill@, with many fixes and
improvements by me.

- Put MEMORY_DISK_DYNAMIC and MODULAR into the GENERIC kernels, so that
you can load miniroot.kmod from the boot blocks and boot into the
installer!
 1.42 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.41 28-Apr-2008  ad - Make some entry/exit points preemption safe.
- Try to avoid mispredicted bracnhes in Xsyscall.
- Interrupts were being enabled in Xsyscall _after_ checking for ASTs,
while could have resulted in ugly behaviour like delayed signals or
context switches. Fix it.
 1.40 11-Mar-2008  ad branches: 1.40.2; 1.40.4;
Make context switch + syscall counters optionally per-CPU and accumulate
in schedclock() at "about 16 hz".
 1.39 10-Jan-2008  ad branches: 1.39.2; 1.39.6;
- Fix a memory order problem with non-interlocked mutex release.
- Give kernel_lock its own cache line.
 1.38 05-Jan-2008  yamt - make amd64 use per-cpu tss.
- fix iopl syscall for amd64+xen.
 1.37 21-Dec-2007  dsl Create the trap/syscall frame space for all the registers in one go.
Use the tramp-frame offsets (TF_foo) for all references to the registers.
Sort the saving of the GP registers into the same order as the trap frame
because consequetive memory accesses are liekly to be faster.
 1.36 21-Dec-2007  dsl Change the xen CLI() and STI() defines to only use one scratch register.
As well as saving an instruction, in one place it saves a push/pop pair.
 1.35 03-Dec-2007  ad branches: 1.35.4;
Merge from vmlocking.
 1.34 02-Dec-2007  dsl branches: 1.34.2;
Improve the likelyhood of the 'oosyscall' code (ie that for system call entry
via a call gate for i386 netbsd 1.0 and ibcs2) doing the right thing.
Untested because I've failed to get an a.out netbsd 1.0 binary to load.
 1.33 23-Nov-2007  bouyer Sync BSD_SYMTAB declaration with xeni386, pointed out by Christoph Egger
 1.32 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.31 19-Nov-2007  ad IPL_IPI -> IPL_HIGH
 1.30 12-Nov-2007  ad - cpu_vendor was both an int and char[] on amd64 - fix it.
- Run the errata check/patch on all CPUs, not just the boot processor.
 1.29 18-Oct-2007  yamt branches: 1.29.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.28 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.27 26-Sep-2007  ad branches: 1.27.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.26 29-Aug-2007  ad branches: 1.26.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.25 25-May-2007  yamt branches: 1.25.4; 1.25.8; 1.25.10;
dumpsys: build a fake switchframe for postmortem debugging.
reviewed by Frank van der Linden.
 1.24 21-May-2007  fvdl Revert fs/gs changes until I figure out issues with them.
 1.23 19-May-2007  fvdl cpu_switchto: PCB_CR0(%r14) is a 32bit value, so don't use movq to retrieve it.
Using movq would copy pcb_flags along as well, which would cause traps
because bad bits would be written into %cr0 a few instructions later.
This wouldn't happen for native NetBSD processes (no pcb_flags set), but
it would happen for Linux processes.
 1.22 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.21 11-May-2007  fvdl Don't save/restore %fs and %gs in trapframe. The kernel won't touch them.
Instead, save/restore them on context switch. For 32bit processes, save/restore
the selector values only, for 64bit processes, save/restore the appropriate
MSRs. Iff the defaults have been changed.
 1.20 17-Feb-2007  pavel branches: 1.20.4; 1.20.6; 1.20.12;
Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.
 1.19 09-Feb-2007  ad branches: 1.19.2;
Merge newlock2 to head.
 1.18 14-May-2006  elad branches: 1.18.8; 1.18.12; 1.18.14;
integrate kauth.
 1.17 13-May-2006  skrll Fix some more comments.
 1.16 30-Apr-2006  rjs Fix comment for cpu_switch().
 1.15 11-Dec-2005  christos branches: 1.15.4; 1.15.6; 1.15.8; 1.15.10; 1.15.12;
merge ktrace-lwp.
 1.14 01-Apr-2005  yamt branches: 1.14.2;
merge yamt-km branch.
- don't use managed mappings/backing objects for wired memory allocations.
save some resources like pv_entry. also fix (most of) PR/27030.
- simplify kernel memory management API.
- simplify pmap bootstrap of some ports.
- some related cleanups.
 1.13 25-Mar-2004  drochner branches: 1.13.8; 1.13.10;
Native code doesn't need sigcode. Never.
So replace it by a dummy setting sigcode=esigcode=0, just to get
COMPAT_16+COMPAT_NETBSD32 kernels linking.
 1.12 23-Mar-2004  drochner put the old and the very old syscall glue into appropriate
COMPAT_ conditionals
 1.11 01-Mar-2004  drochner on (fast) syscall exit, force %ds to its standard value --
it might have been modified by a netbsd32 process
 1.10 19-Feb-2004  drochner use no-execute page permissions if supported
 1.9 30-Nov-2003  fvdl Reenable interrupts sooner in the idle_exit case.
 1.8 10-Nov-2003  wiz Spell address with two d's. Inspired by similar changes in OpenBSD,
originating from Jonathon Gray and forwarded by jmc@openbsd.
 1.7 04-Nov-2003  dsl Remove p_nras from struct proc - use LIST_EMPTY(&p->p_raslist) instead.
Remove p_raslock and rename p_lwplock p_lock (one lock is enough).
Simplify window test when adding a ras and correct test on VM_MAXUSER_ADDRESS.
Avoid unpredictable branch in i386 locore.S
(pad fields left in struct proc to avoid kernel bump)
 1.6 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.5 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.4 13-May-2003  fvdl branches: 1.4.2;
While the previous change actually made the code do what it intended,
it was still wrong. cpu_switch() must return 1 when it switched to
a different LWP, 0 if it didn't. It was doing exactly the reverse.
 1.3 13-May-2003  fvdl Return the correct value in cpu_switch; from Stephan Uphoff for i386.
 1.2 26-Apr-2003  fvdl Skip sym space if ksyms or LKMs are included, too.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.4.2.4 01-Apr-2005  skrll Sync with HEAD.
 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.13.10.1 13-Feb-2005  yamt remove no longer needed .globl decls.
 1.13.8.1 29-Apr-2005  kent sync with -current
 1.14.2.8 17-Mar-2008  yamt sync with head.
 1.14.2.7 21-Jan-2008  yamt sync with head
 1.14.2.6 07-Dec-2007  yamt sync with head
 1.14.2.5 15-Nov-2007  yamt sync with head.
 1.14.2.4 27-Oct-2007  yamt sync with head.
 1.14.2.3 03-Sep-2007  yamt sync with head.
 1.14.2.2 26-Feb-2007  yamt sync with head.
 1.14.2.1 21-Jun-2006  yamt sync with head.
 1.15.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.15.10.1 11-May-2006  elad sync with head
 1.15.8.1 24-May-2006  yamt sync with head.
 1.15.6.1 01-Jun-2006  kardel Sync with head.
 1.15.4.1 09-Sep-2006  rpaulo sync with head
 1.18.14.1 17-Nov-2007  skrll Back port of:

date: 2007/05/25 15:09:50; author: yamt; state: Exp; lines: +4 -6
dumpsys: build a fake switchframe for postmortem debugging.
reviewed by Frank van der Linden.

Unfortunately struct switchframe changed in -current so the crashdumps
aren't compatible. *sigh*
 1.18.12.1 16-Sep-2008  bouyer Sync with the following revisions (requested by skrll in ticket #1196):
gnu/dist/gdb removed
gnu/usr.bin/gdb53 removed
distrib/cats/instkernel/Makefile 1.14.6.1
gnu/dist/gdb6/bfd/config.bfd 1.3.6.1
gnu/dist/gdb6/bfd/elfxx-sparc.c 1.1.1.2.6.1
gnu/dist/gdb6/bfd/elfxx-sparc.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/Makefile.in 1.2.2.1.2.2
gnu/dist/gdb6/gdb/alpha-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/alpha-tdep.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/alphabsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/alphabsd-nat.h 1.1.2.1
gnu/dist/gdb6/gdb/alphabsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/alphabsd-tdep.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/alphanbsd-nat.c 1.1.2.1
gnu/dist/gdb6/gdb/alphanbsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/amd64-nat.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/amd64bsd-nat.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/amd64nbsd-nat.c 1.1.1.2.6.3
gnu/dist/gdb6/gdb/amd64nbsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/arm-tdep.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/armbsd-tdep.c 1.1.2.1
gnu/dist/gdb6/gdb/armnbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/armnbsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/configure 1.1.1.2.6.1
gnu/dist/gdb6/gdb/configure.ac 1.1.1.2.6.1
gnu/dist/gdb6/gdb/i386bsd-nat.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/i386nbsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/m68kbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/mipsnbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/nbsd-thread.c 1.1.2.3
gnu/dist/gdb6/gdb/ppcnbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/ppcnbsd-tdep.c 1.3.6.1
gnu/dist/gdb6/gdb/sh-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/shnbsd-nat.c 1.1.1.2.6.3
gnu/dist/gdb6/gdb/shnbsd-tdep.c 1.1.1.2.6.4
gnu/dist/gdb6/gdb/shnbsd-tdep.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/sparc-nat.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/sparc64nbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/sparcnbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/tramp-frame.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/vaxbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/config/alpha/nbsd.mh 1.1.1.2.6.1
gnu/dist/gdb6/gdb/config/arm/nbsd.mt 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/arm/nbsdelf.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/i386/nbsd64.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/m68k/nbsdelf.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/mips/nbsd.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/powerpc/nbsd.mh 1.1.1.2.6.1
gnu/dist/gdb6/gdb/config/sh/nbsd.mh 1.1.1.1.6.2
gnu/dist/gdb6/gdb/config/sh/tm-nbsd.h 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/sparc/nbsd64.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/sparc/nbsdelf.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/vax/nbsdelf.mh 1.1.1.1.6.1
gnu/dist/gdb6/opcodes/configure 1.1.1.2.6.1
gnu/dist/gdb6/opcodes/configure.in 1.1.1.2.6.1
gnu/usr.bin/Makefile 1.126.4.1
gnu/usr.bin/gdb6/arch/alpha/config.h 1.3.4.1
gnu/usr.bin/gdb6/arch/alpha/defs.mk 1.2.6.1
gnu/usr.bin/gdb6/arch/alpha/init.c 1.2.6.1
gnu/usr.bin/gdb6/arch/alpha/nm.h 1.2.6.1
gnu/usr.bin/gdb6/arch/arm/defs.mk 1.2.6.2
gnu/usr.bin/gdb6/arch/arm/init.c 1.1.6.1
gnu/usr.bin/gdb6/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/arch/armeb/defs.mk 1.1.6.3
gnu/usr.bin/gdb6/arch/armeb/init.c 1.1.6.2
gnu/usr.bin/gdb6/arch/armeb/tm.h 1.1.6.2
gnu/usr.bin/gdb6/arch/armeb/version.c 1.1.6.2
gnu/usr.bin/gdb6/arch/i386/defs.mk 1.4.4.1
gnu/usr.bin/gdb6/arch/i386/init.c 1.3.6.1
gnu/usr.bin/gdb6/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/arch/m68000/init.c 1.1.6.2
gnu/usr.bin/gdb6/arch/m68000/tm.h 1.1.6.2
gnu/usr.bin/gdb6/arch/m68000/version.c 1.1.6.2
gnu/usr.bin/gdb6/arch/m68k/defs.mk 1.1.4.1
gnu/usr.bin/gdb6/arch/m68k/init.c 1.1.4.1
gnu/usr.bin/gdb6/arch/mipseb/config.h 1.3.4.1
gnu/usr.bin/gdb6/arch/mipseb/defs.mk 1.2.6.2
gnu/usr.bin/gdb6/arch/mipseb/init.c 1.2.6.2
gnu/usr.bin/gdb6/arch/mipsel/config.h 1.2.6.3
gnu/usr.bin/gdb6/arch/mipsel/defs.mk 1.2.6.3
gnu/usr.bin/gdb6/arch/mipsel/init.c 1.2.6.3
gnu/usr.bin/gdb6/arch/mipsel/tm.h 1.2.6.2
gnu/usr.bin/gdb6/arch/mipsel/version.c 1.2.6.2
gnu/usr.bin/gdb6/arch/powerpc/defs.mk 1.3.6.1
gnu/usr.bin/gdb6/arch/powerpc/init.c 1.3.6.1
gnu/usr.bin/gdb6/arch/sh3eb/config.h 1.2.2.2
gnu/usr.bin/gdb6/arch/sh3eb/defs.mk 1.2.8.3
gnu/usr.bin/gdb6/arch/sh3eb/init.c 1.1.8.3
gnu/usr.bin/gdb6/arch/sh3eb/nm.h 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3eb/tm.h 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3eb/version.c 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3el/config.h 1.2.2.2
gnu/usr.bin/gdb6/arch/sh3el/defs.mk 1.2.8.3
gnu/usr.bin/gdb6/arch/sh3el/init.c 1.1.8.3
gnu/usr.bin/gdb6/arch/sh3el/nm.h 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3el/tm.h 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3el/version.c 1.1.8.2
gnu/usr.bin/gdb6/arch/sparc/defs.mk 1.2.6.1
gnu/usr.bin/gdb6/arch/sparc/init.c 1.1.6.1
gnu/usr.bin/gdb6/arch/sparc64/defs.mk 1.2.6.1
gnu/usr.bin/gdb6/arch/sparc64/init.c 1.1.6.1
gnu/usr.bin/gdb6/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/arch/vax/init.c 1.1.6.2
gnu/usr.bin/gdb6/arch/vax/tm.h 1.1.6.2
gnu/usr.bin/gdb6/arch/vax/version.c 1.1.6.2
gnu/usr.bin/gdb6/arch/x86_64/defs.mk 1.2.6.1
gnu/usr.bin/gdb6/arch/x86_64/init.c 1.1.6.1
gnu/usr.bin/gdb6/bfd/arch/armeb/bfd.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/armeb/bfdver.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/armeb/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/m68000/bfd.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/m68000/bfdver.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/mipsel/bfd.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/mipsel/bfdver.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/mipsel/config.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/mipsel/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/sh3eb/bfd.h 1.1.8.3
gnu/usr.bin/gdb6/bfd/arch/sh3eb/bfdver.h 1.1.8.2
gnu/usr.bin/gdb6/bfd/arch/sh3eb/config.h 1.1.8.2
gnu/usr.bin/gdb6/bfd/arch/sh3eb/defs.mk 1.1.8.3
gnu/usr.bin/gdb6/bfd/arch/sh3el/bfd.h 1.1.8.3
gnu/usr.bin/gdb6/bfd/arch/sh3el/bfdver.h 1.1.8.2
gnu/usr.bin/gdb6/bfd/arch/sh3el/config.h 1.1.8.2
gnu/usr.bin/gdb6/bfd/arch/sh3el/defs.mk 1.1.8.3
gnu/usr.bin/gdb6/bfd/arch/vax/bfd.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/vax/bfdver.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/gdb/Makefile 1.5.2.1.2.2
gnu/usr.bin/gdb6/gdbtui/Makefile 1.2.6.1
gnu/usr.bin/gdb6/libiberty/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/armeb/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/mipsel/config.h 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/mipsel/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/sh3eb/config.h 1.1.8.2
gnu/usr.bin/gdb6/libiberty/arch/sh3eb/defs.mk 1.1.8.2
gnu/usr.bin/gdb6/libiberty/arch/sh3el/config.h 1.1.8.2
gnu/usr.bin/gdb6/libiberty/arch/sh3el/defs.mk 1.1.8.2
gnu/usr.bin/gdb6/libiberty/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/armeb/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/mipsel/config.h 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/mipsel/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/sh3eb/config.h 1.1.8.2
gnu/usr.bin/gdb6/opcodes/arch/sh3eb/defs.mk 1.1.8.3
gnu/usr.bin/gdb6/opcodes/arch/sh3el/config.h 1.1.8.2
gnu/usr.bin/gdb6/opcodes/arch/sh3el/defs.mk 1.1.8.3
gnu/usr.bin/gdb6/opcodes/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/armeb/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/mipsel/config.h 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/mipsel/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/sh3eb/config.h 1.1.8.2
gnu/usr.bin/gdb6/readline/arch/sh3eb/defs.mk 1.1.8.2
gnu/usr.bin/gdb6/readline/arch/sh3el/config.h 1.1.8.2
gnu/usr.bin/gdb6/readline/arch/sh3el/defs.mk 1.1.8.2
gnu/usr.bin/gdb6/readline/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/sim/arch/mipseb/cconfig.h 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipseb/config.h 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipseb/defs.mk 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipsel/cconfig.h 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipsel/config.h 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipsel/defs.mk 1.1.2.1
lib/libkvm/kvm_sparc64.c 1.10.18.2
lib/libpthread/pthread.c 1.48.6.4
lib/libpthread/pthread_barrier.c 1.6.18.1
lib/libpthread/pthread_cond.c 1.18.12.2
lib/libpthread/pthread_debug.h 1.8.18.1
lib/libpthread/pthread_int.h 1.34.4.5
lib/libpthread/pthread_lock.c 1.14.6.1
lib/libpthread/pthread_mutex.c 1.22.4.2
lib/libpthread/pthread_run.c 1.18.12.4
lib/libpthread/pthread_rwlock.c 1.13.6.2
lib/libpthread/pthread_sa.c 1.37.6.5
lib/libpthread/pthread_sig.c 1.47.4.8
lib/libpthread/pthread_sleep.c 1.7.6.2
lib/libpthread/sem.c 1.9.6.2
lib/libpthread/arch/sh3/pthread_md.h 1.3.6.1
regress/lib/libpthread/resolv/Makefile 1.1.12.1
regress/lib/libpthread/sigrunning/Makefile 1.1.2.1
regress/lib/libpthread/sigrunning/sigrunning.c 1.1.2.1
share/mk/bsd.own.mk 1.489.4.3
sys/arch/amd64/amd64/locore.S 1.18.14.1
sys/arch/amd64/amd64/machdep.c 1.44.2.3.2.1
sys/arch/amd64/conf/kern.ldscript 1.1.70.1
sys/arch/cats/conf/Makefile.cats.inc 1.17.30.1
sys/arch/shark/conf/Makefile.shark.inc 1.6.30.1
sys/arch/sparc64/conf/kern.ldscript 1.7.26.2
sys/arch/sparc64/conf/kern32.ldscript 1.6.26.2
sys/arch/sparc64/include/kcore.h 1.4.92.2
sys/arch/sparc64/sparc64/locore.s 1.232.4.4
sys/arch/sparc64/sparc64/machdep.c 1.193.4.3
sys/arch/sparc64/sparc64/pmap.c 1.184.2.1.2.4
sys/conf/newvers.sh 1.42.26.2
sys/kern/kern_sa.c 1.87.4.11
sys/kern/kern_synch.c 1.173.4.2
sys/sys/savar.h 1.20.10.2
tools/gdb/Makefile 1.9.4.1
tools/gdb/mknative-gdb 1.1.6.1

pullup the wrstuden-fixsa CVS branch to netbsd-4:
toolchain/35540 - GDB 6 support for pthreads.
port-sparc64/37534 - ktrace firefox gives
kernel trap 30: data access expection
GDB changes:
- delete gdb53
- enable gdb6 on all architectures
- add support for amd64 crash dumps
- add support for sparc64 crash dumps
- add support for /proc pid to executable filename for all archs
- enable thread support for all architectures
- add a note section to kernels to all platforms
- support detection/unwinding of signals for most architectures.
- Fix PTHREAD_UCONTEXT_TO_REG / PTHREAD_REG_TO_UCONTEXT on sh3.
- Apply fix from binutils-current so that sparc gdb can be cross built
on a 64bit host.
SA/pthread changes:
Pre-allocate memory needed for event delivery. Eliminates dropped
interrupts under load.
Deliver intra-process signals to running threads
Eliminate some deadlock scenarios
Fix intra-process signal delivery when delivering to a thread waiting
for signals. Makes afs work again!
 1.18.8.10 01-Feb-2007  ad Call spllower() from the idle loop, not Xspllower().
 1.18.8.9 30-Jan-2007  ad For now always call sched_unlock_idle/sched_lock_idle. They will be
removed by yamt's cpu_switchto() changes.
 1.18.8.8 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.18.8.7 19-Jan-2007  ad cpu_exit: be more conservative and only clear curlwp after TR has been
loaded.
 1.18.8.6 19-Jan-2007  ad - cpu_exit(): move 'cli' behind clearing curlwp to close a race with
lwp_free(). Noted by yamt@.
- Don't bother calling lwp_exit2() any more.
 1.18.8.5 14-Jan-2007  ad - Restore previous locking behaviour in cpu_switch(). Seems to fix what
look like corrupted trap frames.
- Micro-optimisation for AST check/clear.
 1.18.8.4 12-Jan-2007  ad Make amd64 build again.
 1.18.8.3 29-Dec-2006  ad Checkpoint work in progress.
 1.18.8.2 24-Oct-2006  ad - Redo LWP locking slightly and fix some races.
- Fix some locking botches.
- Make signal mask / stack per-proc for SA processes.
- Add _lwp_kill().
 1.18.8.1 20-Oct-2006  ad - Acquire/release sched_mutex in the correct places.
- Donate ci->ci_sched_mutex to newly scheduled LWPs.
 1.19.2.4 17-May-2007  yamt sync with head.
 1.19.2.3 10-Apr-2007  ad Sync with i386.
 1.19.2.2 03-Mar-2007  yamt adapt amd64.

XXX changes in identcpu.c is minmum for MONITOR.
XXX identcpu.c should be shared with i386.
 1.19.2.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.20.12.3 03-Oct-2007  garbled Sync with HEAD
 1.20.12.2 26-Jun-2007  garbled Sync with HEAD.
 1.20.12.1 22-May-2007  matt Update to HEAD.
 1.20.6.1 11-Jul-2007  mjf Sync with head.
 1.20.4.8 03-Dec-2007  ad Sync with HEAD.
 1.20.4.7 03-Dec-2007  ad Sync with HEAD.
 1.20.4.6 16-Nov-2007  ad - Don't bother entering the debugger for WARNING: SPL NOT LOWERED ...
It's nearly impossible to debug at that point. Just patch things
up and continue.
- Don't assign to ci_ilevel to drop the IPL, it can cause deadlock.
Use spllower() instead.
 1.20.4.5 23-Oct-2007  ad Sync with head.
 1.20.4.4 09-Oct-2007  ad Sync with head.
 1.20.4.3 23-Aug-2007  ad Add sse2_zero_page(), sse2_copy_page().
 1.20.4.2 23-Aug-2007  ad Save cpu_feature2, like i386.
 1.20.4.1 27-May-2007  ad Sync with head.
 1.25.10.3 23-Mar-2008  matt sync with HEAD
 1.25.10.2 09-Jan-2008  matt sync with HEAD
 1.25.10.1 06-Nov-2007  matt sync with HEAD
 1.25.8.8 09-Dec-2007  jmcneill Sync with HEAD.
 1.25.8.7 03-Dec-2007  joerg Sync with HEAD.
 1.25.8.6 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.25.8.5 21-Nov-2007  joerg Sync with HEAD.
 1.25.8.4 14-Nov-2007  joerg Sync with HEAD.
 1.25.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.25.8.2 02-Oct-2007  joerg Sync with HEAD.
 1.25.8.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.25.4.1 03-Sep-2007  skrll Sync with HEAD.
 1.26.2.6 08-Oct-2007  yamt fix off-by-one.
 1.26.2.5 07-Oct-2007  yamt rename PTDpaddr to PDPpaddr to match with i386.
(if you think it's a good idea to make gratuitous renames like this,
please do it for both of i386 and amd64 consistently.)
 1.26.2.4 07-Oct-2007  yamt remove some #ifdef _LOCORE and use genassym instead.
 1.26.2.3 06-Oct-2007  yamt sync with head.
 1.26.2.2 04-Oct-2007  yamt - move etext before rodata. define __data_start at the start of
.data section and use it instead of etext where appropriate.
- put .rodata.* into .rodata section as well.
- pmap_bootstrap: don't assume NBPD_L2 alignment.
- pmap_bootstrap: if DEBUG, print how many large pages and normal pages are
used to map kernel text.
 1.26.2.1 30-Sep-2007  yamt implement deferred pmap switching for amd64, and make amd64 use
x86 shared pmap code. it makes several i386 pmap improvements available
to amd64, including tlb shootdown reduction and bug fixes from Stephan Uphoff.
 1.27.2.5 16-Nov-2007  bouyer Initial domain0 support for xenamd64. The kernel boots multiuser, but
xen tools have not been tried yet.
In this process, cleanup some more the page table bootstrap, and properly
handle event counters for soft interrupts.
 1.27.2.4 13-Nov-2007  bouyer Sync with HEAD
 1.27.2.3 26-Oct-2007  bouyer Make amd64, i386 and xen kernels build and work again.
 1.27.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.27.2.1 17-Oct-2007  bouyer amd64 (aka x86-64) support for Xen. Based on the OpenBSD port done by
Mathieu Ropert in 2006.
DomU-only for now. An INSTALL_XEN3_DOMU kernel with a ramdisk will boot to
sysinst if you're lucky. Often it panics because a runable LWP has
a NULL stack (really, it's all of l->l_addr which is has been zeroed out
while the process was on the queue !)
TODO:
- bug fixes :)
- Most of the xpq_* functions should be shared with xen/i386
- The xen/i386 assembly bootstrap code should be remplaced with the C
version in xenamd64/amd64/xpmap.c
- see if a config(5) trick could allow to merge xenamd64 back to xen or amd64.
 1.29.2.4 18-Feb-2008  mjf Sync with HEAD.
 1.29.2.3 27-Dec-2007  mjf Sync with HEAD.
 1.29.2.2 08-Dec-2007  mjf Sync with HEAD.
 1.29.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.34.2.2 26-Dec-2007  ad Sync with head.
 1.34.2.1 08-Dec-2007  ad Sync with head.
 1.35.4.3 10-Jan-2008  bouyer Sync with HEAD
 1.35.4.2 08-Jan-2008  bouyer Sync with HEAD
 1.35.4.1 02-Jan-2008  bouyer Sync with HEAD
 1.39.6.4 17-Jan-2009  mjf Sync with HEAD.
 1.39.6.3 05-Jun-2008  mjf Sync with HEAD.

Also fix build.
 1.39.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.39.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.39.2.1 24-Mar-2008  keiichi sync with head.
 1.40.4.4 11-Aug-2010  yamt sync with head.
 1.40.4.3 11-Mar-2010  yamt sync with head
 1.40.4.2 04-May-2009  yamt sync with head.
 1.40.4.1 16-May-2008  yamt sync with head.
 1.40.2.2 04-Jun-2008  yamt sync with head
 1.40.2.1 18-May-2008  yamt sync with head.
 1.43.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.47.8.4 22-Apr-2010  snj Apply patch (requested by jym in ticket #1380):
Fix the NX regression issue observed on amd64 kernels, where per-page
execution right was disabled (therefore leading to the inability
of the kernel to detect fraudulent use of memory mappings marked as not
being executable).
 1.47.8.3 22-Apr-2010  snj Pull up following revision(s) (requested by jym in ticket #1376):
sys/arch/amd64/amd64/locore.S: revision 1.56
When kernel remaps to high memory in amd64 locore, the GDT used before
becomes invalid. As such, split it in two parts, one for use when system
boots in low memory, and one for use when it jumps to high memory.
 1.47.8.2 02-Feb-2009  snj branches: 1.47.8.2.2; 1.47.8.2.4;
Pull up following revision(s) (requested by ad in ticket #345):
sys/arch/amd64/amd64/locore.S: revision 1.50
Don't abort pageidlezero unless a realtime thread wants to run.
 1.47.8.1 17-Nov-2008  snj Pull up following revision(s) (requested by ad in ticket #74):
sys/arch/i386/isa/npx.c: revision 1.131
sys/arch/amd64/amd64/fpu.c: revision 1.28
sys/arch/i386/i386/genassym.cf: revision 1.77
sys/arch/i386/i386/autoconf.c: revision 1.93
sys/arch/amd64/amd64/locore.S: revision 1.48
sys/arch/amd64/amd64/machdep.c: revision 1.104
sys/arch/i386/i386/machdep.c: revision 1.646
sys/arch/amd64/amd64/genassym.cf: revision 1.38
sys/arch/i386/i386/locore.S: revision 1.79
PR port-amd64/38293 panic: fp_save ipi didn't
Fix race conditions in FPU IPI handling.
 1.47.8.2.4.1 20-May-2011  matt bring matt-nb5-mips64 up to date with netbsd-5-1-RELEASE (except compat).
 1.47.8.2.2.2 23-Apr-2010  snj Apply patch (requested by jym in ticket #1380):
Fix the NX regression issue observed on amd64 kernels, where per-page
execution right was disabled (therefore leading to the inability
of the kernel to detect fraudulent use of memory mappings marked as not
being executable).
 1.47.8.2.2.1 22-Apr-2010  snj Pull up following revision(s) (requested by jym in ticket #1376):
sys/arch/amd64/amd64/locore.S: revision 1.56
When kernel remaps to high memory in amd64 locore, the GDT used before
becomes invalid. As such, split it in two parts, one for use when system
boots in low memory, and one for use when it jumps to high memory.
 1.47.6.2 03-Mar-2009  skrll Sync with HEAD.
 1.47.6.1 19-Jan-2009  skrll Sync with HEAD.
 1.47.4.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.50.4.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.50.4.3 28-Mar-2011  jym Cure sync hiccups. Code with compile errors is not really useful, heh.
 1.50.4.2 01-Nov-2009  jym Sync with HEAD.
 1.50.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.55.4.3 31-May-2011  rmind sync with head
 1.55.4.2 05-Mar-2011  rmind sync with head
 1.55.4.1 30-May-2010  rmind sync with head
 1.55.2.3 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.55.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.55.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.64.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.65.8.3 29-Apr-2012  mrg sync to latest -current.
 1.65.8.2 04-Mar-2012  mrg sync to latest -current.
 1.65.8.1 18-Feb-2012  mrg merge to -current.
 1.65.4.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.65.4.3 30-Oct-2012  yamt sync with head
 1.65.4.2 23-May-2012  yamt sync with head.
 1.65.4.1 17-Apr-2012  yamt sync with head
 1.66.2.2 08-Aug-2017  martin Pull up following revision(s) (requested by maxv in ticket #1464):

sys/arch/i386/i386/trap.c: revision 1.288 (patch)
sys/arch/i386/i386/machdep.c: revision 1.783 (patch)
sys/arch/i386/i386/locore.S: revision 1.146 (patch)
sys/arch/amd64/amd64/locore.S: revision 1.122,1.124 (patch)
sys/arch/amd64/amd64/machdep.c revision 1.254 (patch)
sys/arch/amd64/amd64/trap.c: revision 1.95-1.96 (patch)

Remove the osyscall call gate and emulate it. There is a
one-instruction race in it that could panic the kernel.

Restore the ability to run netbsd 1.0 32-bit executables by checking
for the relevant lcall instruction in the trap handler and treating it
as a syscall.
 1.66.2.1 20-Apr-2012  riz branches: 1.66.2.1.4; 1.66.2.1.6;
Pull up following revision(s) (requested by jym in ticket #189):
sys/arch/x86/include/psl.h: revision 1.7
sys/arch/i386/i386/locore.S: revision 1.98
sys/arch/amd64/acpi/acpi_wakecode.S: revision 1.11
sys/arch/amd64/amd64/mptramp.S: revision 1.13
sys/arch/i386/acpi/acpi_wakecode.S: revision 1.15
sys/arch/i386/i386/mptramp.S: revision 1.23
sys/arch/amd64/amd64/locore.S: revision 1.68
Set the CR0_AM bit so processes can enable alignment check errors under
x86 through PSL_AC bit.
ATF test incoming shortly.
PSL_AC is user-settable.
 1.66.2.1.6.1 08-Aug-2017  martin Pull up following revision(s) (requested by maxv in ticket #1464):

sys/arch/i386/i386/trap.c: revision 1.288 (patch)
sys/arch/i386/i386/machdep.c: revision 1.783 (patch)
sys/arch/i386/i386/locore.S: revision 1.146 (patch)
sys/arch/amd64/amd64/locore.S: revision 1.122,1.124 (patch)
sys/arch/amd64/amd64/machdep.c revision 1.254 (patch)
sys/arch/amd64/amd64/trap.c: revision 1.95-1.96 (patch)

Remove the osyscall call gate and emulate it. There is a
one-instruction race in it that could panic the kernel.

Restore the ability to run netbsd 1.0 32-bit executables by checking
for the relevant lcall instruction in the trap handler and treating it
as a syscall.
 1.66.2.1.4.1 08-Aug-2017  martin Pull up following revision(s) (requested by maxv in ticket #1464):

sys/arch/i386/i386/trap.c: revision 1.288 (patch)
sys/arch/i386/i386/machdep.c: revision 1.783 (patch)
sys/arch/i386/i386/locore.S: revision 1.146 (patch)
sys/arch/amd64/amd64/locore.S: revision 1.122,1.124 (patch)
sys/arch/amd64/amd64/machdep.c revision 1.254 (patch)
sys/arch/amd64/amd64/trap.c: revision 1.95-1.96 (patch)

Remove the osyscall call gate and emulate it. There is a
one-instruction race in it that could panic the kernel.

Restore the ability to run netbsd 1.0 32-bit executables by checking
for the relevant lcall instruction in the trap handler and treating it
as a syscall.
 1.70.2.2 03-Dec-2017  jdolecek update from HEAD
 1.70.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.73.2.1 18-May-2014  rmind sync with head
 1.75.2.1 10-Aug-2014  tls Rebase.
 1.76.8.2 20-Jul-2017  snj Pull up following revision(s) (requested by maxv in ticket #1441):
sys/arch/i386/i386/trap.c: revision 1.288 via patch
sys/arch/i386/i386/machdep.c: revision 1.783 via patch
sys/arch/i386/i386/locore.S: revision 1.146 via patch
sys/arch/amd64/amd64/locore.S: revision 1.124 via patch
Remove the osyscall call gate on i386, and emulate it. There is a one-
instruction race in it that could panic the kernel.
 1.76.8.1 26-Apr-2017  martin Pull up following revision(s) (requested by bsiegert in ticket #1397):

sys/arch/amd64/amd64/locore.S 1.122 (via patch)
sys/arch/amd64/amd64/machdep.c 1.254 (via patch)
sys/arch/amd64/amd64/trap.c 1.95 (via patch)

Remove the call gate on amd64, it is useless and vulnerable.
 1.76.4.2 20-Jul-2017  snj Pull up following revision(s) (requested by maxv in ticket #1441):
sys/arch/i386/i386/trap.c: revision 1.288 via patch
sys/arch/i386/i386/machdep.c: revision 1.783 via patch
sys/arch/i386/i386/locore.S: revision 1.146 via patch
sys/arch/amd64/amd64/locore.S: revision 1.124 via patch
Remove the osyscall call gate on i386, and emulate it. There is a one-
instruction race in it that could panic the kernel.
 1.76.4.1 26-Apr-2017  martin Pull up following revision(s) (requested by bsiegert in ticket #1397):

sys/arch/amd64/amd64/locore.S 1.122 (via patch)
sys/arch/amd64/amd64/machdep.c 1.254 (via patch)
sys/arch/amd64/amd64/trap.c 1.95 (via patch)

Remove the call gate on amd64, it is useless and vulnerable.
 1.76.2.2 20-Jul-2017  snj Pull up following revision(s) (requested by maxv in ticket #1441):
sys/arch/i386/i386/trap.c: revision 1.288 via patch
sys/arch/i386/i386/machdep.c: revision 1.783 via patch
sys/arch/i386/i386/locore.S: revision 1.146 via patch
sys/arch/amd64/amd64/locore.S: revision 1.124 via patch
Remove the osyscall call gate on i386, and emulate it. There is a one-
instruction race in it that could panic the kernel.
 1.76.2.1 26-Apr-2017  martin Pull up following revision(s) (requested by bsiegert in ticket #1397):

sys/arch/amd64/amd64/locore.S 1.122 (via patch)
sys/arch/amd64/amd64/machdep.c 1.254 (via patch)
sys/arch/amd64/amd64/trap.c 1.95 (via patch)

Remove the call gate on amd64, it is useless and vulnerable.
 1.77.2.8 28-Aug-2017  skrll Sync with HEAD
 1.77.2.7 05-Feb-2017  skrll Sync with HEAD
 1.77.2.6 05-Dec-2016  skrll Sync with HEAD
 1.77.2.5 05-Oct-2016  skrll Sync with HEAD
 1.77.2.4 09-Jul-2016  skrll Sync with HEAD
 1.77.2.3 29-May-2016  skrll Sync with HEAD
 1.77.2.2 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.77.2.1 22-Sep-2015  skrll Sync with HEAD
 1.107.2.5 26-Apr-2017  pgoyette Sync with HEAD
 1.107.2.4 20-Mar-2017  pgoyette Sync with HEAD
 1.107.2.3 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.107.2.2 04-Nov-2016  pgoyette Sync with HEAD
 1.107.2.1 26-Jul-2016  pgoyette Sync with HEAD
 1.118.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.123.6.9 14-May-2019  martin Pull up following revision(s) (requested by maxv in ticket #1269):

sys/arch/amd64/amd64/locore.S: revision 1.181 (adapted)
sys/arch/amd64/amd64/amd64_trap.S: revision 1.47 (adapted)
sys/arch/x86/include/specialreg.h: revision 1.144 (adapted)
sys/arch/amd64/include/frameasm.h: revision 1.43 (adapted)
sys/arch/x86/x86/spectre.c: revision 1.27 (adapted)

Mitigation for INTEL-SA-00233: Microarchitectural Data Sampling (MDS).
It requires a microcode update, now available on the Intel website. The
microcode modifies the behavior of the VERW instruction, and makes it flush
internal CPU buffers. We hotpatch the return-to-userland path to add VERW.

Two sysctls are added:

machdep.mds.mitigated = {0/1} user-settable
machdep.mds.method = {string} constructed by the kernel

The kernel will automatically enable the mitigation if the updated
microcode is present. If the new microcode is not present, the user can
load it via cpuctl, and set machdep.mds.mitigated=1.
 1.123.6.8 10-Jul-2018  martin Pull up the following, requested by maxv in ticket #910:

sys/arch/amd64/amd64/locore.S r1.167 (patch)
sys/arch/i386/i386/locore.S r1.158 (patch)
sys/arch/x86/x86/fpu.c r1.44 (patch)

Don't switch the FPU when leaving a softint. This fixes
several problems when EagerFPU is enabled.
 1.123.6.7 23-Jun-2018  martin Pull up the following, via patch, requested by maxv in ticket #897:

sys/arch/amd64/amd64/locore.S 1.166 (patch)
sys/arch/i386/i386/locore.S 1.157 (patch)
sys/arch/x86/include/cpu.h 1.92 (patch)
sys/arch/x86/include/fpu.h 1.9 (patch)
sys/arch/x86/x86/fpu.c 1.33-1.39 (patch)
sys/arch/x86/x86/identcpu.c 1.72 (patch)
sys/arch/x86/x86/vm_machdep.c 1.34 (patch)
sys/arch/x86/x86/x86_machdep.c 1.116,1.117 (patch)

Support eager fpu switch, to work around INTEL-SA-00145.
Provide a sysctl machdep.fpu_eager, which gets automatically
initialized to 1 on affected CPUs.
 1.123.6.6 05-May-2018  martin Pull up following revision(s) (requested by maxv in ticket #786):

sys/arch/amd64/amd64/locore.S: revision 1.164,1.165

Adjust Xsyscall_svs to not use movq for 64bit immediates either.

Do not use movq for loading arbitrary 64bit immediates. The ISA
restricts it to 32bit immediates.
 1.123.6.5 22-Mar-2018  martin Pull up the following revisions, requested by maxv in ticket #652:

sys/arch/amd64/amd64/amd64_trap.S upto 1.39 (partial, patch)
sys/arch/amd64/amd64/db_machdep.c 1.6 (patch)
sys/arch/amd64/amd64/genassym.cf 1.65,1.66,1.67 (patch)
sys/arch/amd64/amd64/locore.S upto 1.159 (partial, patch)
sys/arch/amd64/amd64/machdep.c 1.299-1.302 (patch)
sys/arch/amd64/amd64/trap.c upto 1.113 (partial, patch)
sys/arch/amd64/amd64/amd64/vector.S upto 1.61 (partial, patch)
sys/arch/amd64/conf/GENERIC 1.477,1.478 (patch)
sys/arch/amd64/conf/kern.ldscript 1.26 (patch)
sys/arch/amd64/include/frameasm.h upto 1.37 (partial, patch)
sys/arch/amd64/include/param.h 1.25 (patch)
sys/arch/amd64/include/pmap.h 1.41,1.43,1.44 (patch)
sys/arch/x86/conf/files.x86 1.91,1.93 (patch)
sys/arch/x86/include/cpu.h 1.88,1.89 (patch)
sys/arch/x86/include/pmap.h 1.75 (patch)
sys/arch/x86/x86/cpu.c 1.144,1.146,1.148,1.149 (patch)
sys/arch/x86/x86/pmap.c upto 1.289 (partial, patch)
sys/arch/x86/x86/vm_machdep.c 1.31,1.32 (patch)
sys/arch/x86/x86/x86_machdep.c 1.104,1.106,1.108 (patch)
sys/arch/x86/x86/svs.c 1.1-1.14
sys/arch/xen/conf/files.compat 1.30 (patch)

Backport SVS. Not enabled yet.
 1.123.6.4 13-Mar-2018  martin Pullup the following revisions via patch, requested by maxv in ticket #629:

sys/arch/amd64/amd64/genassym.cf 1.63,1.64
sys/arch/amd64/amd64/locore.S 1.144
sys/arch/amd64/amd64/machdep.c 1.281-1.283
sys/arch/i386/i386/genassym.cf 1.105-1.106
sys/arch/i386/i386/locore.S 1.155
sys/arch/i386/i386/machdep.c 1.802 (adapted),1.803
sys/arch/x86/include/cpu.h 1.85
sys/arch/x86/x86/intr.c 1.115-1.116
sys/arch/x86/x86/pmap.c 1.275
sys/arch/x86/x86/sys_machdep.c 1.45
sys/arch/xen/x86/cpu.c 1.117

Stop sharing the double-fault stack.
Merge the TSS structures into one single cpu_tss structure, and
allocate it dynamically.
 1.123.6.3 07-Mar-2018  martin Pull up the following revisions (via patch), requested by maxv in ticket #610:

sys/arch/amd64/amd64/amd64_trap.S 1.8,1.10,1.12 (partial),1.13-1.15,
1.19 (partial),1.20,1.21,1.22,1.24
(via patch)
sys/arch/amd64/amd64/locore.S 1.129 (partial),1.132 (via patch)
sys/arch/amd64/amd64/trap.c 1.97 (partial),1.111 (via patch)
sys/arch/amd64/amd64/vector.S 1.54,1.55 (via patch)
sys/arch/amd64/include/frameasm.h 1.21,1.23 (via patch)
sys/arch/x86/x86/cpu.c 1.138 (via patch)
sys/arch/xen/conf/Makefile.xen 1.45 (via patch)

Rename and reorder several things in amd64_trap.S.
Compile amd64_trap.S as a file.
Introduce nmitrap and doubletrap.
Have the CPU clear PSL_D automatically in the syscall entry point.
 1.123.6.2 04-Sep-2017  snj Pull up following revision(s) (requested by maxv in ticket #257):
sys/compat/linux/arch/amd64/linux_machdep.c: 1.52
sys/arch/amd64/amd64/copy.S: 1.21-1.24
sys/arch/amd64/amd64/locore.S: 1.125
sys/arch/amd64/amd64/machdep.c: 1.256
Fix a bug in ucas_32 and ucas_64. There is a branch where they don't
initialize %rax.
--
style, reduces an incoming diff
00
Split comment, otherwise it is misleading. kcopy operates on kernel
memory, and must *not* be used with userland pages.
--
Move incq outside of the copy section. No functional change, reduces
my smap diff.
--
Remove dumb debug code and outdated comment.
--
Don't forget to clean l_md.md_flags, otherwise there may be MDL_COMPAT32,
in which case the kernel would always use iret (slower).
 1.123.6.1 05-Jul-2017  snj Pull up following revision(s) (requested by maxv in ticket #88):
sys/arch/amd64/amd64/locore.S: revision 1.124
sys/arch/i386/i386/locore.S: revision 1.146
sys/arch/i386/i386/machdep.c: revision 1.783
sys/arch/i386/i386/trap.c: revision 1.288
Remove the osyscall call gate on i386, and emulate it. There is a one-
instruction race in it that could panic the kernel.
 1.157.2.9 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.157.2.8 28-Jul-2018  pgoyette Sync with HEAD
 1.157.2.7 25-Jun-2018  pgoyette Sync with HEAD
 1.157.2.6 02-May-2018  pgoyette Synch with HEAD
 1.157.2.5 22-Apr-2018  pgoyette Sync with HEAD
 1.157.2.4 07-Apr-2018  pgoyette Sync with HEAD. 77 conflicts resolved - all of them $NetBSD$
 1.157.2.3 30-Mar-2018  pgoyette Extract compat_14 stuff into its own module
 1.157.2.2 30-Mar-2018  pgoyette Resolve conflicts between branch and HEAD
 1.157.2.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.166.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.166.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.166.2.1 10-Jun-2019  christos Sync with HEAD
 1.185.2.1 13-May-2023  martin Pull up following revision(s) (requested by manu in ticket #1632):

share/man/man8/man8.x86/boot.8: revision 1.27
sys/arch/i386/stand/efiboot/version: revision 1.3
share/man/man8/man8.x86/boot.8: revision 1.28 (via patch)
share/man/man8/man8.x86/boot.8: revision 1.29 (via patch)
sys/arch/i386/stand/lib/exec.c: revision 1.79
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.13
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.6
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.6
sys/arch/i386/stand/efiboot/boot.c: revision 1.22
sys/arch/amd64/amd64/locore.S: revision 1.219
sys/arch/i386/stand/efiboot/bootia32/startprog32.S: revision 1.3
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.12
sys/arch/amd64/conf/files.amd64: revision 1.121
sys/arch/amd64/conf/std.amd64: revision 1.13
share/man/man8/man8.x86/pxeboot.8: revision 1.6
sys/arch/i386/stand/efiboot/bootx64/startprog64.S: revision 1.4
sys/arch/amd64/amd64/locore.S: revision 1.220
share/man/man8/man8.x86/dosboot.8: revision 1.4
share/man/man4/options.4: revision 1.524

Add reloc keyworkd to let EFI bootstrap load amd64 kernel at any address

EFI bootstrap assumes it can copy the amd64 kernel to its ELF load
address (that is KERNTEXTOFF - KERNBASE = 0x200000), but it can
clash with previous UEFI memory allocation, as described here:
http://mail-index.netbsd.org/tech-kern/2023/04/07/msg028833.html

This change adds a reloc keyword for controling where the EFI
boostrap will copy the kernel image. Possible values are:
default - the default and prior behavior, copy at 0x200000.
none - do not copy and use the kernel image where it was loaded.
address - specify an explicit address where to copy the kernel.

This comes with an amd64 kernel patch that makes it self-relocatable.
It first discover where it was loaded in memory, and if this is
different than the expected 0x200000, hhe the kernel relocates
itself and start over at the right address.

Merge x86 boot options in x86/boot(8) and add undocumented UEFI options

We were supposed to keep the option list in x86/boot(8), x86/dosoot(8)
and x86/pxeboot(8) in sync, but it did not happen, hence it may work
better with all the options in x86/boot(8). Also add the undocumented
UEFI boot options.

Add a SELFRELOC kernel option for the sake of documentation clarity.
Instead of telling that x86/boot(8) reloc command needs a kernel able
to self relocate, we can tell it needs a kernel built with the
SELFRELOC option. This keeps the reader from wondering what could
make a kernel able to self relocate.

Remove XXX todo marker left by mistake

Raise the version for new feature (here reloc command)
Suggested by Masanobu SAITOH
 1.195.2.1 17-Jan-2020  ad Sync with head.
 1.200.4.2 16-Apr-2020  bouyer More #ifndef XEN -> #ifndef XENPV
 1.200.4.1 08-Apr-2020  bouyer Remove VM_GUEST_XEN and define only Xen subtypes:
VM_GUEST_XENPV
VM_GUEST_XENPVH
VM_GUEST_XENHVM
VM_GUEST_XENPVHVM

Set vm_guest in the start routine, if it is hypervisor-specific (e.g Xen PV).
If vm_guest was not set early and we detect Xen in identify_hypervisor(),
assume it is VM_GUEST_XENHVM. Refine to VM_GUEST_PVXENHVM in
hypervisor_match().
 1.214.4.4 01-Oct-2025  martin Pull up following revision(s) (requested by bouyer in ticket #1168):

sys/arch/i386/i386/locore.S: revision 1.202
sys/arch/i386/i386/locore.S: revision 1.203
sys/arch/i386/i386/locore.S: revision 1.204
sys/arch/amd64/amd64/locore.S: revision 1.231
sys/arch/amd64/amd64/locore.S: revision 1.232
sys/arch/amd64/amd64/locore.S: revision 1.233
sys/arch/xen/xen/hypervisor.c: revision 1.100
all via patch

Our PVH bootstrap code assumed that the hvm_start_info structure provided
by Xen is just after the end of the symbol case. With Xen 4.20 it's not
always the case, so:
- get the symbol table size from the first byte of the symbol table area
provided by Xen. As we don't know if there is a symbol table or not,
do a minimal sanity check on the size.
- if the hvm_start_info structure is not in the page after kernel_end or
esym, copy it there (this was already done in the genpvh case). While
there, if we copy we can easily compute the size and not assume it all fits
in one page.
With this, a NetBSD PVH dom0 can boot on Xen 4.20

Fix various typos, mainly in comments.

Fix some issues with symbol table detection on Xen PVH:
- the stack grows down so the last pushed value is at 0(%esp), not -4(%esp).
Pointed out by Joachim Kuebart.
- 0x3fffffff is 1GB-1, not 1MB-1. Test the symtab size against 16MB
(amd64 generic symbol table is just above 1MB these days)
- I got confused by cmp's arguments order between intel and gas syntax,
so the tests did the opposite of intended and the symtab was always
considered valid.
While there use unsigned conditions.
Should fix booting in PVH mode with netbsd-INSTALL (which is stripped)
 1.214.4.3 29-Mar-2025  martin Pull up following revision(s) (requested by imil in ticket #1074):

sys/arch/x86/x86/x86_machdep.c: revision 1.155
sys/arch/x86/include/cpu.h: revision 1.137
sys/arch/x86/x86/x86_machdep.c: revision 1.156
sys/arch/x86/include/cpu.h: revision 1.138
sys/arch/x86/x86/consinit.c: revision 1.40
sys/arch/x86/acpi/acpi_machdep.c: revision 1.37
sys/arch/x86/acpi/acpi_machdep.c: revision 1.38
sys/arch/amd64/amd64/machdep.c: revision 1.370
sys/arch/xen/xen/hypervisor.c: revision 1.97
sys/arch/xen/xen/hypervisor.c: revision 1.98
sys/arch/amd64/amd64/genassym.cf: revision 1.98
sys/arch/x86/x86/x86_autoconf.c: revision 1.88
sys/arch/x86/x86/x86_autoconf.c: revision 1.89
sys/arch/amd64/amd64/locore.S: revision 1.226
sys/arch/amd64/amd64/locore.S: revision 1.227
sys/arch/x86/x86/identcpu.c: revision 1.131

Add support for non-Xen PVH guests to amd64. Patch from
Emile 'iMil' Heitor in PR kern/57813, with some cosmetic tweaks by me.
Tested on bare metal, Xen PV and Xen PVH by me.

Get one more change from PR kern/57813, needed for non-Xen PVH.

Introduce vm_guest_is_pvh() and use it in place of
(vm_guest == VM_GUEST_XENPVH || vm_guest == VM_GUEST_GENPVH)
 1.214.4.2 18-Oct-2023  martin Pull up following revision(s) (requested by bouyer in ticket #427):

sys/arch/xen/include/hypervisor.h: revision 1.58
sys/arch/i386/i386/locore.S: revision 1.197
sys/arch/amd64/amd64/locore.S: revision 1.224

Xen's start_info_t is larger than 512 bytes these days, so bump the copy
size to a whole PAGE_SIZE, and CTASSERT() that start_info_t is smaller.

Luckily we didn't use yet the parts skipped
 1.214.4.1 13-May-2023  martin Pull up following revision(s) (requested by manu in ticket #159):

share/man/man8/man8.x86/boot.8: revision 1.27
sys/arch/i386/stand/efiboot/version: revision 1.3
share/man/man8/man8.x86/boot.8: revision 1.28
share/man/man8/man8.x86/boot.8: revision 1.29
sys/arch/i386/stand/lib/exec.c: revision 1.79
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.13
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.6
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.6
sys/arch/i386/stand/efiboot/boot.c: revision 1.22
sys/arch/amd64/amd64/locore.S: revision 1.219
sys/arch/i386/stand/efiboot/bootia32/startprog32.S: revision 1.3
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.12
sys/arch/amd64/conf/files.amd64: revision 1.121
sys/arch/amd64/conf/std.amd64: revision 1.13
share/man/man8/man8.x86/pxeboot.8: revision 1.6
sys/arch/i386/stand/efiboot/bootx64/startprog64.S: revision 1.4
sys/arch/amd64/amd64/locore.S: revision 1.220
share/man/man8/man8.x86/dosboot.8: revision 1.4
share/man/man4/options.4: revision 1.524

Add reloc keyworkd to let EFI bootstrap load amd64 kernel at any address

EFI bootstrap assumes it can copy the amd64 kernel to its ELF load
address (that is KERNTEXTOFF - KERNBASE = 0x200000), but it can
clash with previous UEFI memory allocation, as described here:
http://mail-index.netbsd.org/tech-kern/2023/04/07/msg028833.html

This change adds a reloc keyword for controling where the EFI
boostrap will copy the kernel image. Possible values are:
default - the default and prior behavior, copy at 0x200000.
none - do not copy and use the kernel image where it was loaded.
address - specify an explicit address where to copy the kernel.

This comes with an amd64 kernel patch that makes it self-relocatable.
It first discover where it was loaded in memory, and if this is
different than the expected 0x200000, hhe the kernel relocates
itself and start over at the right address.


Merge x86 boot options in x86/boot(8) and add undocumented UEFI options

We were supposed to keep the option list in x86/boot(8), x86/dosoot(8)
and x86/pxeboot(8) in sync, but it did not happen, hence it may work
better with all the options in x86/boot(8). Also add the undocumented
UEFI boot options.


Add a SELFRELOC kernel option for the sake of documentation clarity.
Instead of telling that x86/boot(8) reloc command needs a kernel able
to self relocate, we can tell it needs a kernel built with the
SELFRELOC option. This keeps the reader from wondering what could
make a kernel able to self relocate.

Remove XXX todo marker left by mistake

Raise the version for new feature (here reloc command)
Suggested by Masanobu SAITOH
 1.224.6.1 02-Aug-2025  perseant Sync with HEAD
 1.230.2.1 01-Oct-2025  martin Pull up following revision(s) (requested by bouyer in ticket #43):

sys/arch/i386/i386/locore.S: revision 1.202
sys/arch/i386/i386/locore.S: revision 1.203
sys/arch/i386/i386/locore.S: revision 1.204
sys/arch/amd64/amd64/locore.S: revision 1.231
sys/arch/amd64/amd64/locore.S: revision 1.232
sys/arch/amd64/amd64/locore.S: revision 1.233
sys/arch/xen/xen/hypervisor.c: revision 1.100

Our PVH bootstrap code assumed that the hvm_start_info structure provided
by Xen is just after the end of the symbol case. With Xen 4.20 it's not
always the case, so:
- get the symbol table size from the first byte of the symbol table area
provided by Xen. As we don't know if there is a symbol table or not,
do a minimal sanity check on the size.
- if the hvm_start_info structure is not in the page after kernel_end or
esym, copy it there (this was already done in the genpvh case). While
there, if we copy we can easily compute the size and not assume it all fits
in one page.

With this, a NetBSD PVH dom0 can boot on Xen 4.20

Fix some issues with symbol table detection on Xen PVH:
- the stack grows down so the last pushed value is at 0(%esp), not -4(%esp).
Pointed out by Joachim Kuebart.
- 0x3fffffff is 1GB-1, not 1MB-1. Test the symtab size against 16MB
(amd64 generic symbol table is just above 1MB these days)
- I got confused by cmp's arguments order between intel and gas syntax,
so the tests did the opposite of intended and the symtab was always
considered valid.
While there use unsigned conditions.

Should fix booting in PVH mode with netbsd-INSTALL (which is stripped)

Fix various typos, mainly in comments.
 1.376 30-Apr-2025  imil Fix build for XEN not defined
 1.375 30-Apr-2025  imil Introduce pvh_boot boolean to identify the real hypervisor when booting in PVH
mode.

As of now, sys/arch/x86/x86/identcpu.c / identify_hypervisor() returns in the
case of vm_guest being VM_GUEST_GENPVH, yet this VM type is not an actual
hypervisor but an information recorded in locore.S to drive boot method.
We need to investigate what type of hypervisor is really running the VM in
order to apply specifics, so instead of relying on vm_guest_is_pvh() which only
checks for VM_GUEST_XENPVH || VM_GUEST_GENPVH, pvh_boot informs on the boot
method while allowing to identify the real hypervisor.

Idea ok'd by bouyer@, tested on Xen domU, Xen dom0 with GENERIC PVH and
qemu GENERIC PVH boot.
 1.374 24-Apr-2025  riastradh x86: Make sure esp is aligned when delivering signal.

While here, use STACK_ALIGNBYTES consistently for the alignment mask
(or STACK_ALIGNBYTES32 in amd64 for the compat32 alignment mask).

PR kern/59327: user stack pointer is not aligned properly
 1.373 17-Mar-2025  riastradh x86: Set tf_trapno = T_ASTFLT on exec.

In most cases, the caller will already have tf_trapno=T_ASTFLT and
tf_err=2 -- the latter being the size of the SYSCALL instruction for
ERESTART handling. ERESTART handling is not relevant after exec, but
checking for AST on userret may be.

Hoping this will fix the i386 test bed! Aside from padding fields,
these (tf_trapno and tf_err) are the only two members of trapframe
that were newly zeroed on i386. The corresponding amd64 changes --
which zeroed many other registers -- worked in my testing, but
evidently that wasn't enough testing.

PR kern/59084: exec/spawn leaks register content
 1.372 16-Mar-2025  riastradh Clear trapframe on exec.

Do this for all architectures, even if the trapframe is fully
initialized -- makes it easier to audit and be confident it's
correct, and most likely (with the exception of sh3 which has an
intermediate call to ufetch_int in the middle) the compiler can
eliminate redundant stores in these routines.

PR kern/59084: exec/spawn leaks register content
 1.371 22-Jan-2025  riastradh amd64: Be more verbose about dump failures.

PR kern/59024: dump fails on raid0b
 1.370 02-Dec-2024  bouyer Add support for non-Xen PVH guests to amd64. Patch from
Emile 'iMil' Heitor in PR kern/57813, with some cosmetic tweaks by me.
Tested on bare metal, Xen PV and Xen PVH by me.
 1.369 27-Jun-2024  riastradh branches: 1.369.2;
x86: Defer x86_rndseed until after pmap_bootstrap.

Loading the random seed, which is what x86_rndseed does, requires
direct map access on KASLR kernels, which requires pmap_bootstrap to
have run.

This had been broken in

amd64/machdep.c 1.359
i386/machdep.c 1.832

because we apparently don't have any automatic test setup for KASLR
kernels, which we should address.

This change shouldn't cause any security regression on kernels that
previously owrked, because none of the logic that now happens before
x86_rndseed uses the entropy pool anyway (uvm_md_init,
init_x86_clusters, xen_parse_cmdline).

PR port-amd64/58366
 1.368 05-Mar-2024  thorpej Move the at-shutdown call to resettodr() from cpu_reboot() to kern_reboot().

It's a small step, but it's a step.
 1.367 16-Jul-2023  riastradh x86: Sprinkle extensive commentary about %fs/%gs initialization.

Plus some other side quests like the three-stage GDT metamorphosis
lifecycle.

No functional change intended.
 1.366 26-Oct-2022  riastradh branches: 1.366.2;
ddb/db_active.h: New home for extern db_active.

This can be included unconditionally, and db_active can then be
queried unconditionally; if DDB is not in the kernel, then db_active
is a constant zero. Reduces need for #include opt_ddb.h, #ifdef DDB.
 1.365 26-Oct-2022  riastradh sys: Put externs for time_adjtime and time_adjusted in .h files.

time_adjtime: sys/timex.h (defined in ntp code)
time_adjusted: sys/timevar.h (defined in non-ntp code)

(Not really sure this is a valuable distinction to maintain; there's
non-ntp code that uses time_adjtime too.)
 1.364 26-Oct-2022  riastradh sys/*: Get module_map consistently from sys/module.h.
 1.363 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.362 20-Aug-2022  riastradh x86: Split bootspace out of x86/pmap.h into new x86/bootspace.h.
 1.361 26-Dec-2021  riastradh sys: Skip suspendsched on cpu_reboot if we're in ddb.

If we're in ddb, the scheduler and all other CPUs are quiesced
anyway. But suspendsched will try to take an adaptive lock, which
causes it to crash and re-enter ddb, which isn't very useful for
rebooting.
 1.360 28-Oct-2021  riastradh x86: Move RNG initialization to after consinit.

This ensures we have the opportunity to get feedback about early
entropy.
 1.359 28-Oct-2021  riastradh x86: Process bootloader rndseed much sooner.
 1.358 24-Jan-2021  simonb Fix a tyop in a comment.
 1.357 07-Sep-2020  mrg branches: 1.357.2;
adjust some fallback code to be slightly less ugly and avoid
upsetting GCC 9.
 1.356 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.355 10-May-2020  maxv Reintroduce cpu_rng_early_sample(), but this time with embedded detection
for RDRAND/RDSEED, because TSC is not very strong.
 1.354 08-May-2020  riastradh Move cpu_rng_init a little later, just after cpu_init_msrs, on x86.

This way curcpu() and curlwp are available, so that we no longer need
any annoying conditionalization in kern_entropy.c.
 1.353 08-May-2020  riastradh Factor randomization out of slotspace_rand.

slotspace_rand becomes deterministic; the randomization moves into
the callers instead. Why?

There are two callers of slotspace_rand:

- x86/pmap.c pmap_bootstrap
- amd64/amd64.c init_slotspace

When the randomization was introduced, it used an x86-only
`cpu_earlyrng' abstraction that would hash rdseed/rdrand and rdtsc
output together. Except init_slotspace ran before cpu_probe, so
cpu_feature was not yet filled out, so during init_slotspace, the
only randomization was rdtsc.

In the course of the recent entropy overhaul, I replaced cpu_earlyrng
by entropy_extract, and moved cpu_init_rng much earlier -- but still
after cpu_probe -- in order to reduce the number of abstractions
lying around and the number of copies of rdrand/rdseed logic. In so
doing I added some annoying complication (see curcpu_available) to
kern_entropy.c to make it work early enough for init_slotspace, and
dropped the rdtsc.

For pmap_bootstrap that didn't substantively change anything. But
for init_slotspace, it removed the only randomization. To mitigate
this, this commit pulls the randomization out of slotspace_rand into
pmap_bootstrap and init_slotspace, so that

(a) init_slotspace can use rdtsc and a little private entropy pool in
order to restore the prior (weak) randomization it had, and

(b) pmap_bootstrap, which runs a little bit later, can continue to
use entropy_extract normally and get rdrand/rdseed too.

A subsequent commit will move cpu_init_rng just a wee bit later,
after cpu_init_msrs, so the kern_entropy.c complications can go away.
Perhaps someone else more wizardly with x86 can find a way to make
init_slotspace run a little later too, after cpu_probe and after
cpu_init_msrs and after cpu_rng_init, but I am not that wizardly.
 1.352 02-May-2020  bouyer Introduce Xen PVH support in GENERIC.
This is compiled in with
options XENPVHVM
x86 changes:
- add Xen section and xen pvh entry points to locore.S. Set vm_guest
to VM_GUEST_XENPVH in this entry point.
Most of the boot procedure (especially page table setup and switch to
paged mode) is shared with native.
- change some x86_delay() to delay_func(), which points to x86_delay() for
native/HVM, and xen_delay() for PVH

Xen changes:
- remove Xen bits from init_x86_64_ksyms() and init386_ksyms()
and move to xen_init_ksyms(), used for both PV and PVH
- set ISA no-legacy-devices property for PVH
- factor out code from Xen's cpu_bootconf() to xen_bootconf()
in xen_machdep.c
- set up a specific pvh_consinit() which starts with printk()
(which uses a simple hypercall that is available early) and switch to
xencons when we can use pmap_kenter_pa().
 1.351 02-May-2020  maxv Call kasan_early_init earlier, to unbreak KASAN after the recent RNG
changes. Will also prevent further trouble.
 1.350 30-Apr-2020  riastradh Simplify Intel RDRAND/RDSEED and VIA C3 RNG API.

Push it all into MD x86 code to keep it simpler, until we have other
examples on other CPUs. Simplify RDSEED-to-RDRAND fallback.
Eliminate cpu_earlyrng in favour of just using entropy_extract, which
is available early now.
 1.349 28-Apr-2020  jmcneill Detect PAT on the boot processor before cpu0 attaches so the early genfb
attach code can map the framebuffer with write combining.
 1.348 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.347 21-Apr-2020  jdolecek convert to newer HYPERVISOR_physdev_op() interface, now command and the
arg are separate arguments - this is needed for newer physdev_op commands

remove code for PHYSDEVOP_IRQ_UNMASK_NOTIFY, it is obsolete since
interface version 0x00030202 and is unsupported by newer versions of Xen

confirmed working on amd64 Dom0, i386 compile-tested only
 1.346 31-Jan-2020  maxv branches: 1.346.4;
constify
 1.345 09-Jan-2020  manu Rollback multiboot2 for amd64, as requested by core
 1.344 13-Dec-2019  ad branches: 1.344.2;
Break the global uvm_pageqlock into a per-page identity lock and a private
lock for use of the pagedaemon policy code. Discussed on tech-kern.

PR kern/54209: NetBSD 8 large memory performance extremely low
PR kern/54210: NetBSD-8 processes presumably not exiting
PR kern/54727: writing a large file causes unreasonable system behaviour
 1.343 10-Dec-2019  manu Add multiboot 2 support to amd64 kernel
 1.342 06-Dec-2019  maxv Fix a bunch of unimportant "Local variable hides global variable" warnings
from the LGTM bot.
 1.341 14-Nov-2019  maxv Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.
 1.340 14-Nov-2019  maxv Don't include "opt_kasan.h" when there's already <sys/asan.h> included.
 1.339 14-Nov-2019  maxv Add support for Kernel Memory Sanitizer (kMSan). It detects uninitialized
memory used by the kernel at run time, and just like kASan and kCSan, it
is an excellent feature. It has already detected 38 uninitialized variables
in the kernel during my testing, which I have since discreetly fixed.

We use two shadows:
- "shad", to track uninitialized memory with a bit granularity (1:1).
Each bit set to 1 in the shad corresponds to one uninitialized bit of
real kernel memory.
- "orig", to track the origin of the memory with a 4-byte granularity
(1:1). Each uint32_t cell in the orig indicates the origin of the
associated uint32_t of real kernel memory.

The memory consumption of these shadows is consequent, so at least 4GB of
RAM is recommended to run kMSan.

The compiler inserts calls to specific __msan_* functions on each memory
access, to manage both the shad and the orig and detect uninitialized
memory accesses that change the execution flow (like an "if" on an
uninitialized variable).

We mark as uninit several types of memory buffers (stack, pools, kmem,
malloc, uvm_km), and check each buffer passed to copyout, copyoutstr,
bwrite, if_transmit_lock and DMA operations, to detect uninitialized memory
that leaves the system. This allows us to detect kernel info leaks in a way
that is more efficient and also more user-friendly than KLEAK.

Contrary to kASan, kMSan requires comprehensive coverage, ie we cannot
tolerate having one non-instrumented function, because this could cause
false positives. kMSan cannot instrument ASM functions, so I converted
most of them to __asm__ inlines, which kMSan is able to instrument. Those
that remain receive special treatment.

Contrary to kASan again, kMSan uses a TLS, so we must context-switch this
TLS during interrupts. We use different contexts depending on the interrupt
level.

The orig tracks precisely the origin of a buffer. We use a special encoding
for the orig values, and pack together in each uint32_t cell of the orig:
- a code designating the type of memory (Stack, Pool, etc), and
- a compressed pointer, which points either (1) to a string containing
the name of the variable associated with the cell, or (2) to an area
in the kernel .text section which we resolve to a symbol name + offset.

This encoding allows us not to consume extra memory for associating
information with each cell, and produces a precise output, that can tell
for example the name of an uninitialized variable on the stack, the
function in which it was pushed on the stack, and the function where we
accessed this uninitialized variable.

kMSan is available with LLVM, but not with GCC.

The code is organized in a way that is similar to kASan and kCSan, so it
means that other architectures than amd64 can be supported.
 1.338 05-Nov-2019  maxv Add Kernel Concurrency Sanitizer (kCSan) support. This sanitizer allows us
to detect race conditions at runtime. It is a variation of TSan that is
easy to implement and more suited to kernel internals, albeit theoretically
less precise than TSan's happens-before.

We do basically two things:

- On every KCSAN_NACCESSES (=2000) memory accesses, we create a cell
describing the access, and delay the calling CPU (10ms).

- On all memory accesses, we verify if the memory we're reading/writing
is referenced in a cell already.

The combination of the two means that, if for example cpu0 does a read that
is selected and cpu1 does a write at the same address, kCSan will fire,
because cpu1's write collides with cpu0's read cell.

The coverage of the instrumentation is the same as that of kASan. Also, the
code is organized in a way similar to kASan, so it is easy to add support
for more architectures than amd64. kCSan is compatible with KCOV.

Reviewed by Kamil.
 1.337 12-Oct-2019  maxv 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.336 21-Aug-2019  skrll Spell pmap_bootstrap in comments correctly
 1.335 24-Jul-2019  bouyer branches: 1.335.2;
Remove XENPV-specific %ss/%cs handling, it doens't seem to be needed with
newer hypervisors (tested with 4.6 and 4.11)
 1.334 27-Jun-2019  christos Although this is correct, I will let maxv commit it. Still waiting.
 1.333 27-Jun-2019  christos don't cast void *
 1.332 12-Jun-2019  christos Add missing address check. This broke things like:

crash -w
w /l ipsec_debug 1

with an invalid address, because it found the first readonly segment and
returned EFAULT. I guess this never worked properly, but this got exposed
when maxv made text and rodata actually R/O?
 1.331 19-May-2019  maxv Rename

fpu_save_area_clear -> fpu_clear
fpu_save_area_reset -> fpu_sigreset

Clearer, and reduces a future diff. No real functional change.
 1.330 19-May-2019  maxv Misc changes in the x86 FPU code. Reduces a future diff. No real functional
change.
 1.329 24-Mar-2019  maxv Disable preemption when setting PCB_COMPAT32, to prevent a context switch
before cpu_fsgs_reload() finishes, otherwise we write garbage in the GDT.
On NetBSD-current it is harmless, however in NetBSD-8 it might cause
panics, because NetBSD-8 uses the old SegRegs model and under this model
we reload %fs and %gs during switches.
 1.328 24-Mar-2019  maxv Fix a tiny race in setregs and linux_setregs. Between the moment we set
pcb_flags to zero, and the moment cpu_segregs64_zero resets pcb_gs, we may
be preempted.

If this happens, and if the calling LWP was a 32bit thread, when switching
back to that LWP, the context switcher sees that PCB_COMPAT32 is not set in
pcb_flags and tries to perform a 64bit context switch; but pcb_gs contains
a 32bit GDT descriptor, and not a 64bit GS.base value. The wrmsr therefore
faults because the value is non-canonical, and this fault is fatal.

Rearrange the code so that the update of pcb_flags and pcb_gs/pcb_fs is non
interruptible. This fixes the problem, tested with a reproducer (which
therefore doesn't work anymore).

Likely fixes PR/53993.
 1.327 09-Mar-2019  maxv Start replacing the x86 PTE bits.
 1.326 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.325 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.324 27-Jan-2019  pgoyette Merge the [pgoyette-compat] branch
 1.323 10-Dec-2018  maxv Remove unused mbuf.h includes.
 1.322 15-Nov-2018  riastradh Make the direct-map API always available, but fail if KASAN or rump.

(Only for architectures that support it at all; on others,
__HAVE_MM_MD_DIRECT_MAPPED_PHYS/IO are still undefined and the
functions unimplemented.)

This gives modules like zfs an opportunity to use it.

While here, fix the one caller of mm_md_direct_mapped_phys that
ignored the return value (and make sure to call pmap_kremove/update
before uvm_km_free).
 1.321 11-Nov-2018  maxv Fix stack info leak. There is a big padding in struct sigframe_siginfo.

[ 224.006287] kleak: Possible leak in copyout: [len=920, leaked=92]
[ 224.016977] #0 0xffffffff80224d0a in kleak_note <netbsd>
[ 224.026268] #1 0xffffffff80224d8a in kleak_copyout <netbsd>
[ 224.026268] #2 0xffffffff802224b5 in sendsig_siginfo <netbsd>
[ 224.036261] #3 0xffffffff80b51564 in sendsig <netbsd>
[ 224.046475] #4 0xffffffff80b51282 in postsig <netbsd>
[ 224.046475] #5 0xffffffff80b2fc5d in lwp_userret <netbsd>
[ 224.056273] #6 0xffffffff8025a951 in mi_userret <netbsd>
[ 224.066277] #7 0xffffffff8025ab89 in syscall <netbsd>
 1.320 31-Oct-2018  maxv Move the MI parts of KASAN into kern/subr_asan.c. This file includes
machine/asan.h, which contains the MD functions. We use an include rather
than a plain C file, because we want GCC to optimize/inline some functions
into one single block.

The amd64 MD parts of KASAN are moved accordingly.

The naming convention we use is:

kasan_*
a generic kasan object, declared in subr_asan.c
kasan_md_*
an MD kasan object, declared in machine/asan.h, and used
in subr_asan.c
__md_*
an MD object, declared in machine/asan.h, and not used
outside

Overall this makes it easier to add KASAN support on more architectures.

Discussed with several people.
 1.319 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.318 29-Aug-2018  maxv clean up a little
 1.317 29-Aug-2018  maxv Simplify the ASLR stuff, we don't care about resizable areas now, and it
makes the code more complicated for no good reason.
 1.316 22-Aug-2018  maxv Add support for monitoring the stack with kASan. This allows us to detect
illegal memory accesses occuring there.

The compiler inlines a piece of code in each function that adds redzones
around the local variables and poisons them. The illegal accesses are then
detected using the usual kASan machinery.

The stack size is doubled, from 4 pages to 8 pages.

Several boot functions are marked with the __noasan flag, to prevent the
compiler from adding redzones in them (because we haven't yet initialized
kASan). The kasan_early_init function is called early at boot time to
quickly create the shadow for the current stack; after this is done, we
don't need __noasan anymore in the boot path.

We pass -fasan-shadow-offset=0xDFFF900000000000, because the compiler
wants to do
shad = shadow-offset + (addr >> 3)
and we do, in kasan_addr_to_shad
shad = KASAN_SHADOW_START + ((addr - CANONICAL_BASE) >> 3)
hence
shad = KASAN_SHADOW_START + (addr >> 3) - (CANONICAL_BASE >> 3)
= [KASAN_SHADOW_START - (CANONICAL_BASE >> 3)] + (addr >> 3)
implies
shadow-offset = KASAN_SHADOW_START - (CANONICAL_BASE >> 3)
= 0xFFFF800000000000 - (0xFFFF800000000000 >> 3)
= 0xDFFF900000000000

In UVM, we add a kasan_free (that is not preceded by a kasan_alloc). We
don't add poisoned redzones ourselves, but all the functions we execute
do, so we need to manually clear the poison before freeing the stack.

With the help of Kamil for the makefile stuff.
 1.315 20-Aug-2018  maxv Add support for kASan on amd64. Written by me, with some parts inspired
from Siddharth Muralee's initial work. This feature can detect several
kinds of memory bugs, and it's an excellent feature.

It can be enabled by uncommenting these three lines in GENERIC:

#makeoptions KASAN=1 # Kernel Address Sanitizer
#options KASAN
#no options SVS

The kernel is compiled without SVS, without DMAP and without PCPU area.
A shadow area is created at boot time, and it can cover the upper 128TB
of the address space. This area is populated gradually as we allocate
memory. With this design the memory consumption is kept at its lowest
level.

The compiler calls the __asan_* functions each time a memory access is
done. We verify whether this access is legal by looking at the shadow
area.

We declare our own special memcpy/memset/etc functions, because the
compiler's builtins don't add the __asan_* instrumentation.

Initially all the mappings are marked as valid. During dynamic
allocations, we add a redzone, which we mark as invalid. Any access on
it will trigger a kASan error message. Additionally, the compiler adds
a redzone on global variables, and we mark these redzones as invalid too.
The illegal-access detection works with a 1-byte granularity.

For now, we cover three areas:

- global variables
- kmem_alloc-ated areas
- malloc-ated areas

More will come, but that's a good start.
 1.314 12-Aug-2018  maxv More ASLR: randomize the location of the PTE area. The PTE slot is not
created in locore anymore, but a little later; by using the already
entered L4 page, rather than the recursive slot itself (which doesn't
exist yet).

In the prekern we still map the slot - the prekern behaves as an external
locore -, because we need it as part of the randomization/relocation
work. The kernel then removes this slot, and regenerates a randomized
one.

Tested on GENERIC and GENERIC_KASLR, Xen doesn't have it and dom0 still
boots fine.
 1.313 12-Aug-2018  maxv Move the PTE area from slot 255 to slot 509. I've never understood why we
put it on 255; the "kernel" half of the VM space begins on slot 256, so
if anything, the PTE area should have been above it, not below.

Virtually extend the user slots in slotspace, because we don't want
(randomized) kernel mappings to land on slot 255.

The prekern is updated accordingly.

Tested on GENERIC, GENERIC_KASLR and XEN3_DOM0.
 1.312 12-Aug-2018  maxv Randomize the main memory on Xen, same as native. Tested on amd64-dom0.
 1.311 12-Aug-2018  maxv Add a new area, SLAREA_HYPV, which indicates the slots used by the
hypervisor, in our case Xen.
 1.310 12-Aug-2018  maxv More ASLR: randomize the kernel main memory. VM_MIN_KERNEL_ADDRESS becomes
variable, and its location is chosen at boot time. There is room for
improvement, since for now we ask for an alignment of NBPD_L4.

This is enabled by default in GENERIC, but not in Xen. Tested extensively
on GENERIC and GENERIC_KASLR, XEN3_DOM0 still boots fine.
 1.309 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.308 22-Jul-2018  maxv Clean up dbregs; remove useless comments, remove arguments from prototypes,
style, add KASSERT and move x86_dbregspl into dbregs.c. No real functional
change.
 1.307 21-Jul-2018  maxv More ASLR. Randomize the location of the direct map at boot time on amd64.
This doesn't need "options KASLR" and works on GENERIC. Will soon be
enabled by default.

The location of the areas is abstracted in a slotspace structure. Ideally
we should always use this structure when touching the L4 slots, instead of
the current cocktail of global variables and constants.

machdep initializes the structure with the default values, and we then
randomize its dmap entry. Ideally machdep should randomize everything at
once, but in the case of the direct map its size is determined a little
later in the boot procedure, so we're forced to randomize its location
later too.
 1.306 12-Jul-2018  maxv Handle NMIs correctly when SVS is enabled. We store the kernel's CR3 at the
top of the NMI stack, and we unconditionally switch to it, because we don't
know with which page tables we received the NMI. Hotpatch the whole thing as
usual.

This restores the ability to use PMCs on Intel CPUs.
 1.305 20-Jun-2018  maxv branches: 1.305.2;
Add and use bootspace.smodule. Initialize it in locore/prekern to better
hide the specifics from the "upper" layers. This allows for greater
flexibility.
 1.304 08-May-2018  maxv Mitigation for the SS bug, CVE-2018-8897. We disabled dbregs a month ago
in -current and -8 so we are not particularly affected anymore.

The #DB handler runs on ist3, if we decide to process the exception we
copy the iret frame on the correct non-ist stack and continue as usual.
 1.303 04-Apr-2018  maxv Enable the SpectreV2 mitigation by default at boot time.
 1.302 17-Mar-2018  maxv Add missing opt_svs.h.
 1.301 22-Feb-2018  maxv branches: 1.301.2;
Remove svs_pgg_update(). Instead of manually changing PG_G on each page,
we can disable the global-paging mechanism in %cr4 with CR4_PGE. Do that.

In addition, install CR4_PGE when SVS is disabled manually (via the
sysctl).

Now, doing "sysctl -w machdep.svs_enabled=0" restores the performance
completely, exactly as if SVS hadn't been enabled in the first place.
 1.300 22-Feb-2018  maxv Mmh, add #ifdef SVS around svs_init().
 1.299 22-Feb-2018  maxv Improve the SVS initialization.

Declare x86_patch_window_open() and x86_patch_window_close(), and globalify
x86_hotpatch().

Introduce svs_enable() in x86/svs.c, that does the SVS hotpatching.

Change svs_init() to take a bool. This function gets called twice; early
when the system just booted (and nothing is initialized), lately when at
least pmap_kernel has been initialized.
 1.298 11-Feb-2018  maxv Move SVS into x86/svs.c
 1.297 04-Feb-2018  maxv Add a TODO list for SVS.
 1.296 26-Jan-2018  maxv Zero out the scratch value in the UTLS page during context switches. We
temporarily put %rax there when processing syscalls, and we wouldn't
want the new lwp to see the %rax value of the previous lwp.
 1.295 21-Jan-2018  maxv Unmap the kernel from userland in SVS, and leave only the needed
trampolines. As explained below, SVS should now completely mitigate
Meltdown on GENERIC kernels, even though it needs some more tweaking
for GENERIC_KASLR.

Until now the kernel entry points looked like:

FUNC(intr)
pushq $ERR
pushq $TRAPNO
INTRENTRY
... handle interrupt ...
INTRFASTEXIT
END(intr)

With this change they are split and become:

FUNC(handle)
... handle interrupt ...
INTRFASTEXIT
END(handle)

TEXT_USER_BEGIN
FUNC(intr)
pushq $ERR
pushq $TRAPNO
INTRENTRY
jmp handle
END(intr)
TEXT_USER_END

A new section is introduced, .text.user, that contains minimal kernel
entry/exit points. In order to choose what to put in this section, two
macros are introduced, TEXT_USER_BEGIN and TEXT_USER_END.

The section is mapped in userland with normal 4K pages.

In GENERIC, the section is 4K-page-aligned and embedded in .text, which
is mapped with large pages. That is to say, when an interrupt comes in,
the CPU has the user page tables loaded and executes the 'intr' functions
on 4K pages; after calling SVS_ENTER (in INTRENTRY) these 4K pages become
2MB large pages, and remain so when executing in kernel mode.

In GENERIC_KASLR, the section is 4K-page-aligned and independent from the
other kernel texts. The prekern just picks it up and maps it at a random
address.

In GENERIC, SVS should now completely mitigate Meltdown: what we put in
.text.user is not secret.

In GENERIC_KASLR, SVS would have to be improved a bit more: the
'jmp handle' instruction is actually secret, since it leaks the address
of the section we are jumping into. By exploiting Meltdown on Intel, this
theoretically allows a local user to reconstruct the address of the first
text section. But given that our KASLR produces several texts, and that
each section is not correlated with the others, the level of protection
KASLR provides is still good.
 1.294 21-Jan-2018  maxv Make it possible for SVS to map in the user page tables a 4K kernel page
contained in a 2MB large page. Will be used soon.
 1.293 20-Jan-2018  maxv Don't declare exceptions[] with IDTVEC, it's an array, not a function.
Rename it to x86_exceptions[], and move it to .rodata.
 1.292 20-Jan-2018  maxv Improve two comments and a KASSERT.
 1.291 18-Jan-2018  maxv Unmap the kernel heap from the user page tables (SVS).

This implementation is optimized and organized in such a way that we
don't need to copy the kernel stack to a safe place during user<->kernel
transitions. We create two VAs that point to the same physical page; one
will be mapped in userland and is offset in order to contain only the
trapframe, the other is mapped in the kernel and maps the entire stack.

Sent on tech-kern@ a week ago.
 1.290 12-Jan-2018  maxv Split svs_page_add in two, one half will be used for other purposes, and
update a comment.
 1.289 11-Jan-2018  maxv Introduce a new svs_page_add function, which can be used to map in the user
space a VA from the kernel space.

Use it to replace the PDIR_SLOT_PCPU slot: at boot time each CPU creates
its own slot which maps only its own pcpu_entry plus the common area (IDT+
LDT).

This way, the pcpu areas of the remote CPUs are not mapped in userland.
 1.288 11-Jan-2018  maxv Add ist0 to pcpu_entry.
 1.287 11-Jan-2018  maxv Initialize ist0 in cpu_init_tss. On amd64 this is the DDB stack, and it has
nothing to do with ci_intrstack. While here, style, and don't forget to
pass UVM_KMF_ZERO in uvm_km_alloc.
 1.286 11-Jan-2018  maxv Declare new SVS_* variants: SVS_ENTER_NOSTACK and SVS_LEAVE_NOSTACK. Use
SVS_ENTER_NOSTACK in the syscall entry point, and put it before the code
that touches curlwp. (curlwp is located in the direct map.)

Then, disable __HAVE_CPU_UAREA_ROUTINES (to be removed later). This moves
the kernel stack into pmap_kernel(), and not the direct map. That's a
change I've always wanted to make: because of the direct map we can't add
a redzone on the stack, and basically, a stack overflow can go very far
in memory without being detected (as far as erasing all of the system's
memory).

Finally, unmap the direct map from userland.
 1.285 07-Jan-2018  maxv Add a new option, SVS (for Separate Virtual Space), that unmaps kernel
pages when running in userland. For now, only the PTE area is unmapped.

Sent on tech-kern@.
 1.284 05-Jan-2018  maxv Add a __HAVE_PCPU_AREA option, enabled by default on native amd64 but not
Xen.

With this option, the CPU structures that must always be present in the
CPU's page tables are moved on L4 slot 384, which means address
0xffffc00000000000.

A new pcpu_area structure is defined. It contains shared structures (IDT,
LDT), and then an array of pcpu_entry structures, indexed by cpu_index(ci).
Theoretically the LDT should be in the array, but this will be done later.

During the boot procedure, cpu0 calls pmap_init_pcpu, which creates a
page tree that is able to map the pcpu_area structure entirely. cpu0 then
immediately maps the shared structures. Later, every CPU goes through
cpu_pcpuarea_init, which allocates physical pages and kenters the relevant
pcpu_entry to them. Finally, each pointer is replaced to point to pcpuarea.

The point of this change is to make sure that the structures that must
always be present in the page tables have their own L4 slot. Until now
their L4 slot was that of pmap_kernel, and making a distinction between
what must be mapped and what does not need to be was complicated.

Even in the non-speculative-bug case this change makes some sense: there
are several x86 instructions that leak the addresses of the CPU structures,
and putting these structures inside pmap_kernel actually offered a way to
compute the address of the kernel heap - which would have made ASLR on it
plainly useless, had we implemented that.

Note that, for now, pcpuarea does not contain rsp0.

Unfortunately this change adds many #ifdefs, and makes the code harder to
understand. There is also some duplication, but that will be solved later.
 1.283 04-Jan-2018  maxv Allocate the TSS area dynamically. This way cpu_info and cpu_tss can be
put in separate pages.
 1.282 04-Jan-2018  maxv Group the different TSSes into a cpu_tss structure. And pack this
structure to make sure there is no padding between 'tss' and 'iomap'.
 1.281 02-Jan-2018  maxv Stop sharing the double-fault stack. It is embedded in .data, and we won't
want that in the future. This has always been wrong anyway, even if it is
unlikely that two CPUs will double fault at the same time.
 1.280 31-Dec-2017  maxv 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.279 01-Dec-2017  maxv Don't even bother with the trap frame, and force the default values.
 1.278 27-Nov-2017  maxv Inline _FRAME_GREG, and mask only 16 bits of the segment registers,
otherwise the upper 48 bits may contain stack garbage. By the way, I find
it suspicious that we're not masking regs[_REG_RFLAGS] with PSL_USER in
process_write_regs.
 1.277 21-Nov-2017  maxv Remove unused variables.
 1.276 11-Nov-2017  maxv Modify the layout of the bootspace structure, in such a way that it can
contain several kernel segments of the same type (eg several .text
segments). Some parts are still a bit messy but will be cleaned up soon.

I cannot compile-test this change on i386, but it seems fine enough.

NOTE: you need to rebuild and reinstall a new prekern after this change.
 1.275 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.274 29-Oct-2017  maxv Use bootspace.head.va instead of the direct map. Otherwise there's the
assumption that the offsets contained in sh_offset in physical memory are
equal to the offsets in virtual memory, which won't be true in the future.
 1.273 29-Oct-2017  maxv Add a fifth region, called "head". On kaslr kernels it contains the ELF
Header and the ELF Section Headers. On normal kernels it is empty (the
headers are in the "boot" region).

Note: if you're using GENERIC_KASLR, you also need to rebuild the prekern.
 1.272 21-Oct-2017  maxv Improve our segregs model. Pass 3/3.

Treat %gs the same way we treat %ds/%es/%fs: restore it in INTRFASTEXIT
on 32bit LWPs.

On Xen however, its behavior does not change, because we need to do an
hypercall before INTR_RESTORE_GPRS, and that's too complicated for now.

As a side effect, this change fixes a bug in the ACPI wakeup code; %fs/%gs
were not restored on 32bit LWPs, and chances are they would segfault
shortly afterwards.

Support for USER_LDT on amd64 is almost complete now.
 1.271 19-Oct-2017  maxv Improve our segregs model. Pass 2/3.

Treat %fs the same way we treat %ds and %es. For a new 32bit LWP %fs is
set to GUDATA32_SEL, and always updated in INTRFASTEXIT.

This solves an important issue we had until now: we couldn't handle the
faults generated by the "movw $val,%fs" instructions, because they were
deep into the kernel context. Now %fs can fault only in INTRFASTEXIT,
which is safe.

Note that it also fixes a bug I believe affected the kernel: on AMD CPUs,
setting %fs to zero does not flush the internal register state, and
therefore we could leak the %fs base address when context-switching. This
being said, I couldn't trigger the issue on the AMD cpu I have. Whatever,
it's fixed now, since we first set %fs to GUDATA32 - which does flush the
register state.
 1.270 19-Oct-2017  maxv Improve our segregs model. Pass 1/3.

Right now, we are saving and restoring %ds/%es each time we enter/leave the
kernel. However, we let %fs/%gs live in the kernel space, and we rely on
the fact that when switching to an LWP, %fs/%gs are set right away (via
cpu_switchto or setregs).

It has two drawbacks: we are taking care of %ds/%es while they are
deprecated (useless) on 64bit LWPs, and we are restricting %fs/%gs while
they still have a meaning on 32bit LWPs.

Therefore, handle 32bit and 64bit LWPs differently:
* 64bit LWPs use fixed segregs, which are not taken care of.
* 32bit LWPs have dynamic segregs, always saved/restored.

For now, only %ds and %es are changed; %fs and %gs will be in the next
passes.

The trapframe is constructed as usual. In INTRFASTEXIT, we restore %ds/%es
depending on the %cs value. If %cs contains one of the two standard 64bit
selectors, don't do anything. Otherwise, restore everything.

When doing a context switch, just restore %ds/%es to their default values.
On a 32bit LWP they will be overwritten by INTRFASTEXIT; on a 64bit LWP
they won't be updated.

In the ACPI wakeup code, restore %ds/%es to the default 64bit user value.
 1.269 19-Oct-2017  maxv Always mask the 16 bits of the segregs in the trapframe. We don't zero-
extend the uint64_t's when building it, so we're leaking 48 bits of kernel
stack to userland.

Having said that, it appears that I unintentionally fixed most of this
issue in locore.S::rev1.127 - by building the frame with interrupts
disabled, we are implicitly guaranteeing that the structure doesn't get
overwritten by the kernel. Which means, we are leaking to userland data
that comes from userland anyway.

(still other places with this issue, but I'll fix them differently)
 1.268 17-Oct-2017  maxv Move %ds and %es into the GDT on 64bit LWPs.
 1.267 15-Oct-2017  maxv Mmh, don't forget to clear the TLS gdt slots on Xen. Otherwise, when doing
a lwp32->lwp64 context switch, the new lwp can use the slots to reconstruct
the address of the previous lwp's TLS space (and defeat ASLR?).
 1.266 15-Oct-2017  maxv Use two separate functions: cpu_segregs32_zero and cpu_segregs64_zero. The
way segment registers work on amd64 will diverge between 32bit and 64bit
LWPs.
 1.265 15-Oct-2017  maxv Add setusergs on Xen, and simplify.
 1.264 11-Oct-2017  maxv Use bootspace.
 1.263 08-Oct-2017  maxv KASLR: add workarounds to compute the bootinfo VAs (use the direct map),
and don't use large pages yet. Both will be fixed later.
 1.262 30-Sep-2017  maxv Add a bootspace structure. It describes the physical and virtual space
layout created by the early kernel bootstrap code. Start using it, and
eliminate several references to KERNBASE and other global symbols. While
here clean up xen-i386, it's really tiring.
 1.261 28-Sep-2017  maxv Clean up, and initialize the lwp0 fields in init_x86_64.
 1.260 25-Jul-2017  maxv Must not be from n32.
 1.259 22-Jul-2017  maxv Must be curlwp.
 1.258 22-Jul-2017  maxv Call _proc0_tss_ldt_init only once, and rename them.
 1.257 22-Jul-2017  maxv Initialize these kpm fields in pmap_bootstrap.
 1.256 14-Jul-2017  maxv Don't forget to clean l_md.md_flags, otherwise there may be MDL_COMPAT32,
in which case the kernel would always use iret (slower).
 1.255 24-Mar-2017  maxv branches: 1.255.4; 1.255.6;
Don't compile PMCs on Xen.
 1.254 23-Mar-2017  maxv Remove this call gate on amd64, it is useless and vulnerable.

Call gates do not modify %rflags, so interrupts are not disabled when
entering the gate. There is a small window where we are in kernel mode and
with a userland %gs, and if an interrupt happens here we will rejump into
the kernel but not switch to the kernel TLS.

Userland can simply perform a gate call in a loop, and hope that at some
point an interrupt will be received in this window - which necessarily will
be the case. With a specially-crafted %gs it is certainly enough to
escalate privileges.
 1.253 10-Mar-2017  maxv PMCs for amd64 - still disabled, like i386.
 1.252 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.251 05-Feb-2017  maxv Now that valid_user_selector only checks for LDT selectors, remove it. A
user may legitimately want to have one register in the GDT, and another in
the LDT.

Pass 2/2.
 1.250 05-Feb-2017  maxv In cpu_mcontext_validate, treat %cs differently depending on whether a user
LDT is set; just check the permission without checking the location (which
may change).

In valid_user_selector, don't check the length of the LDT. This is racy
because pm_ldt_len could be updated by another thread, and useless since
the length is already referenced in ldtr (ldt_alloc), which means that any
overflow will fault in userland.

Also, don't check the permission of the segment pointed to; this too is
racy, and we don't care either since the permissions are checked earlier
in x86_set_ldt1.

Pass 1/2.
 1.249 05-Feb-2017  maya Remove duplicate check. uvm_physseg_valid_p(upm) == false is also
our for loop exit condition, and will never happen. NFC
 1.248 05-Feb-2017  maya Fix off by one.

Fixes PR port-amd64/51944: sparse core dumps do not work
 1.247 05-Feb-2017  maya Match the iterator in sys/uvm/uvm_page.c:1866. NFC.
No matching KASSERT - this case is covered by the above
if (uvm_physseg_valid_p(upm) == false) break;
 1.246 26-Dec-2016  cherry branches: 1.246.2;
the i386 and amd64 boot time msgbuf init code is nearly identical.

Unify them into x86/x86_machdep.c:init_x86_msgbuf()

Boot tested on GENERIC (i386, amd64), XEN3_DOM0 (amd64)
 1.245 26-Dec-2016  cherry remove spurious printf()
 1.244 26-Dec-2016  cherry Make the msgbuf initialisation track closer to the original
pre-uvm_physseg.h one.

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

cvs diff -u -r 1.241 sys/arch/amd64/amd64/machdep.c
 1.243 23-Dec-2016  cherry "Make NetBSD great again!"

Introduce uvm_hotplug(9) to the kernel.

Many thanks, in no particular order to:

TNF, for funding the project.

Chuck Silvers - for multiple API reviews and feedback.
Nick Hudson - for testing on multiple architectures and bugfix patches.
Everyone who helped with boot testing.

KeK (http://www.kek.org.in) for hosting the primary developers.
 1.242 22-Dec-2016  bouyer Xen doens't need lapic so don't allocate a lapic VA/PA for Xen.
As a side effect this makes XEN3PAE boot again but I don't know why ...
 1.241 22-Dec-2016  cherry switch all ports to use uvm_init.c:uvm_md_init()

uvm_setpagesize() is now subsumed within this funciton.
 1.240 20-Dec-2016  maxv When the i386 port was designed, the bootstrap code needed little physical
memory, and taking it below the kernel image was fine: we had 160 free
pages, and never allocated more than 20. With amd64 however, we create a
direct map, and for this map we need a number of page table pages that is
mostly proportionate to the number of physical addresses available, which
implies that these 160 free pages may not be enough.

In particular, if the CPU does not support 1GB superpages, each 1GB chunk
of physical memory needs a 4k page in the direct map, which means that if
a machine has 160GB of ram, the bootstrap code allocates more than 160
pages, thereby overwriting the I/O mem area. If we push a little further,
if a machine has 512GB of ram, we allocate ~525 pages, and start
overwriting the kernel text, causing the system to go crazy at boot time.

Fix this moving the physical allocation area from below the kernel to above
it. avail_start is now beyond the kernel, and lowmem_rsvd indicates the
reserved low-memory pages. The area [lowmem_rsvd; IOM_BEGIN[ is
internalized into UVM, so there is no pa loss.

The only limit now is the pa of LAPIC, which is located at ~4GB of memory,
so it is perfectly fine.

This change theoretically adds va support for 512GB of ram; and it is a
prerequisite if we want to support more memory anyway.
 1.239 16-Dec-2016  maxv This can actually be enabled in Xen; my rev1.235 fixed the issue. Before
that kern_end was pointing to DUMMY PAGE, which was already kentered
earlier in xen_locore, causing pmap to panic.

This change adds support for kernel modules in Xen.
 1.238 15-Dec-2016  kamil 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.237 12-Dec-2016  pgoyette Make kernels w/o ACPICA compile. (Same "fix" as Martin made to i386...)
cvs: ----------------------------------------------------------------------
 1.236 11-Dec-2016  maxv Kenter local_apic_va to a fake physical page, because our x86
implementation expects this va to be valid even if no lapic is present;
which probably is a bug in itself, but let's just reproduce the old
behavior and rehide that bug.
 1.235 09-Dec-2016  maxv On amd64 we try to guarantee that VA = PA + KERNBASE in the bootstrap
memory. But we have a problem with the ISA I/O MEM, because its va is
located above the kernel and its pa below it, so it does not respect
the rule.

To compensate for that we make the map look like the ISA stuff is above
the kernel by applying an offset on the pa. The issue with this design is
that we systematically lose 96 pages of physical memory.

Fix this by applying the offset on the va instead. Now these 96 pages are
internalized into uvm, and the rule is respected until kern_end.
 1.234 25-Nov-2016  maxv Initialize the module map limits in amd64, not x86.

For the record: normally we could enable this code on Xen, since the
bootstrap layout is globally the same. But there appears to be an issue
in xen_locore, since any kenter in the area after kern_end triggers a
KASSERT because the va is already busy.
 1.233 17-Nov-2016  maxv Remap the pages with G until kern_end, and not just the preloaded modules.
This way the bootstrap tables, proc0's stack and the I/O mem area don't get
flushed each time userland needs a TLB shootdown.
 1.232 15-Nov-2016  maxv I actually came across the solution to this issue in the Intel SDM for a
totally unrelated reason a few weeks ago. The reason we need a particular
module_map on amd64 is because gcc makes us use RIP-relative addressing.

The offset field of the associated opcodes is a 32bit signed displacement,
which means we can access only up to 2GB around the current instruction.
And given that kernel_map is too far away from the kernel .text, it is not
RIP-addressable. Hence the module_map embedded into the bootstrap memory,
which is right above the kernel image.
 1.231 15-Nov-2016  maxv Initialize kern_end in amd64 instead of x86.
 1.230 27-Aug-2016  maxv Don't protect the second page, since it is not part of the IDT.
 1.229 27-Aug-2016  maxv Map the boot IDT, GDT and LDT in three different pages on x86. It is much
better this way, and it reduces the diff between x86 and Xen. Also, zero
them properly, otherwise we might end up with garbage in several slots.
 1.228 27-Aug-2016  maxv Remove idt_init.
 1.227 27-Aug-2016  maxv Rename this value, and use it.
 1.226 22-Jul-2016  maxv Remove pmap_prealloc_lowmem_ptps on amd64. This function creates levels in
the page tree so that the first 2MB of virtual memory can be kentered in
L1.

Strictly speaking, the kernel should never kenter a virtual page below
VM_MIN_KERNEL_ADDRESS, because then it wouldn't be available in userland.
It used to need the first 2MB in order to map the CPU trampoline and the
initial VAs used by the bootstrap code. Now, the CPU trampoline VA is
allocated with uvm_km_alloc and the VAs used by the bootstrap code are
allocated with pmap_bootstrap_valloc, and in either case the resulting VA
is above VM_MIN_KERNEL_ADDRESS.

The low levels in the page tree are therefore unused. By removing this
function, we are making sure no one will be tempted to map an area below
VM_MIN_KERNEL_ADDRESS in kernel mode, and particularly, we are making sure
NULL cannot be kentered.

In short, there is no way to map NULL in kernel mode anymore.
 1.225 20-Jul-2016  maxv This comment is wrong. In fact, we are in low physical memory, but in high
virtual memory, and only the latter matters. I'm not exactly sure why, but
it appears that the kernel modules must be placed above the kernel image.
Just make this comment more ambiguous, in case the next passer-by gets
inspired.
 1.224 16-Jul-2016  maxv Simplify the way physical pages are internalized into the VM system on x86.
Only two functions are called now: init_x86_clusters, which initializes the
memory clusters from the bootinfo, and init_x86_vm, which inserts the pages
from the clusters into VM.
 1.223 13-Jul-2016  maxv branches: 1.223.2;
Reorder some instructions, reduces the diff between amd64 and i386.
 1.222 13-Jul-2016  maxv Remove msgbuf_paddr.
 1.221 13-Jul-2016  maxv KNF
 1.220 02-Jul-2016  maxv Explain why we should use kernel_map instead of module_map, and why we
can't.

We should probably add some GCC flags in the modules makefiles to make
sure the relocations generated are not 32bit.

Related to PR/43438.
 1.219 01-Jul-2016  maxv Don't confuse between VM_PROT and UVM_PROT. This should be VM_PROT.
 1.218 01-Jul-2016  maxv Remove this area (unused).
 1.217 15-May-2016  maxv Explicitly mention MP_TRAMPOLINE in these comments, so that NXR links them.
 1.216 12-May-2016  maxv Split the {text+rodata} chunk in two separate chunks on x86. The
rodata segment now loses the large page optimization, gets mapped inside
the data segment, and therefore becomes RWX. It may break the build on
Xen.
 1.215 15-Feb-2016  riastradh Use KASSERTs supported by CTASSERTs, not __builtin_unreachable.

pcc has no __builtin_unreachable, and this is clearer anyway.
 1.214 22-Nov-2015  maxv KNF a bit, so I don't get scared each time I open a file
 1.213 15-Jul-2015  msaitoh Add comment (ACPI_WAKEUP_ADDR).
 1.212 24-Apr-2015  khorben Also use ACPI shutdown on Xen DOM0

No objection on port-xen@
ok gdt@
 1.211 12-May-2014  uebayasi branches: 1.211.2; 1.211.4; 1.211.6; 1.211.10;
Comments.
 1.210 12-May-2014  jakllsch revert previous; the 128 bytes is for the AMD64 redzone
 1.209 12-May-2014  uebayasi Don't reserve space (128) on signal stack for unknown reasons; the actual
space for struct sigframe_siginfo (+ alignment) is allocated just below.

Confirmed by the following tests:

tests/lib/libc/gen/t_siginfo
tests/lib/libc/sys/t_sigtimedwait
tests/lib/libc/sys/t_sigaction
tests/lib/libc/sys/t_sigqueue
 1.208 12-May-2014  uebayasi stmt;; -> stmt;
 1.207 23-Feb-2014  dsl branches: 1.207.2;
Determine whether the cpu supports xsave (and hence AVX).
The result is only written to sysctl nodes at the moment.
I see:
machdep.fpu_save = 3 (implies xsaveopt)
machdep.xsave_size = 832
machdep.xsave_features = 7
Completely common up the i386 and amd64 machdep sysctl creation.
 1.206 20-Feb-2014  dsl 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.205 15-Feb-2014  dsl 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.204 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.203 11-Feb-2014  dsl Move sys/arch/amd64/amd64/fpu.c and sys/arch/amd64/include/fpu.h
into sys/arch/x86 in preparation for using the same code for i386.
 1.202 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.201 09-Jan-2014  dholland Make the amd64 post-halt-press-a-key code match i386, and introduce
into both a message for the case where cngetc() doesn't work. If
there's no console attached, this won't accomplish anything; but if
there's a screen but no keyboard, or the keyboard's wedged, or
whatever, it might provide useful information.

Suggested back in 2009 by some stuff in PR 37924 and has been hanging
about in one of my trees ever since.
 1.200 01-Dec-2013  christos revert fpu/pcu changes until we figure out what's wrong; they cause random
freezes
 1.199 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.198 06-Nov-2013  mrg - move variables inside their #ifdef use
- remove unused and set-but-unused variables
- use __USE() in a particularly ugly case

with these, and a couple of other changes, amd64 gcc 4.8.1 world
is able to complete build.sh release.
 1.197 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.196 17-Oct-2013  christos remove unused variable, and move variable used only by XEN in the XEN ifdef.
 1.195 05-Jun-2013  christos branches: 1.195.2;
declaring mtrr_funcs once should be enough.
 1.194 12-Apr-2013  christos de-duplication police arrests sysctl.
 1.193 02-Apr-2013  taca Use printf_nolog() as i386 when print remaing bytes at crash dump to
prevent message buffer with cound down.
 1.192 12-Jan-2013  chs enable sparse dumps by default.
 1.191 13-Nov-2012  chs fix sparse crash dumps to contain enough data to be useful,
in particular the top-level page table pages.
use pmap_kremove_local() while writing crash dumps
to avoid spurious warning messages.
 1.190 03-Sep-2012  cherry branches: 1.190.2;
Revert to unmanaged x86 memory mapped isa and pci space.
This is a revert of commit r1.169:
http://mail-index.netbsd.org/source-changes/2011/11/06/msg028702.html

This should allow X to run on NetBSD/xen amd64 dom0, and fixes PR #46634
 1.189 15-Jul-2012  dsl Rename MDP_IRET to MDL_IRET since it is an lwp flag, not a proc one.
Add an MDL_COMPAT32 flag to the lwp's md_flags, set it for 32bit lwps
and use it to force 'return to user' with iret (as is done when
MDL_IRET is set).
Split the iret/sysret code paths much later.
Remove all the replicated code for 32bit system calls - which was only
needed so that iret was always used.
frameasm.h for XEN contains '#define swapgs', while XEN probable never
needs swapgs, this is likely to be confusing.
Add a SWAPGS which is a nop on XEN and swapgs otherwise.
(I've not yet checked all the swapgs in files that include frameasm.h)
Simple x86 programs still work.
Hijack 6.99.9 kernel bump (needed for compat32 modules)
 1.188 08-Jul-2012  dsl The MDP_USEDFPU (amd64 and sh3) and MDP_SSTEP (sh3) are lwp flags not
process ones, rename to MDL_xxx.
 1.187 27-Jun-2012  jym Retire XEN_COMPAT_030001 as detailed on port-xen@:

http://mail-index.netbsd.org/port-xen/2012/06/25/msg007431.html

The xen_p2m API comes next.

ok bouyer@.
Tested on i386 PAE and amd64 (Xen 3.3 on private test bed, and
Xen 3.4 for Amazon EC2).

FWIW, Amazon always reported:

hypervisor0 at mainbus0: Xen version 3.4.3-kaos_t1micro

multiple times for Europe and US West-1, so I guess they are now at
3.4 (32 and 64 bits).
 1.186 16-Jun-2012  dsl memseg_baseaddr() is only called from valid_user_selector() and
both only locally.
Make static, remove one of the functions, and remove the never-set args.
Code is still very dubious.
 1.185 16-Jun-2012  joerg Annotate tautological if, so that clang doesn't warn about the dt usage
later on.
 1.184 12-Jun-2012  bouyer If the user process provided a bogus signal handler address, kill it
now instead of trying to jump to the bogus address.
 1.183 21-May-2012  martin Calling _lwp_create() with a bogus ucontext could trigger a kernel
assertion failure (and thus a crash in DIAGNOSTIC kernels). Independently
discovered by YAMAMOTO Takashi and Joel Sing.

To avoid this, introduce a cpu_mcontext_validate() function and move all
sanity checks from cpu_setmcontext() there. Also untangle the netbsd32
compat mess slightly and add a cpu_mcontext32_validate() cousin there.

Add an exhaustive atf test case, based partly on code from Joel Sing.

Should finally fix the remaining open part of PR kern/43903.
 1.182 29-Apr-2012  christos tidy up...
 1.181 15-Apr-2012  christos Fix check_mcontext for PK_32 binaries. Makes gdb work for i386 binaries on
amd64.
 1.180 03-Mar-2012  mrg make i386 and amd64 cpu_reboot() more similar. in particular, bring
in the unmount/sync code from i386 to amd64, and call doshutdownhooks()
for i386. the amd64 changes avoid umass triggering an assert later
when sd@umass is trying to sync the cache.

XXX merge x86 cpu_reboot(), but there's non-trivially different still.
 1.179 02-Mar-2012  bouyer Follow locore.S and move FPU handling from x86_64_switch_context() to
x86_64_tls_switch(); raise IPL to IPL_HIGH in x86_64_switch_context()
and test ci_fpcurlwp to decide to disable FPU or not.
Change the Xen i386 context switch code to be like the amd64 one.
 1.178 23-Feb-2012  chs move XEN CPU feature masking into cpu_probe() so that it's applied
to all CPUs, not just the boot CPU.
 1.177 19-Feb-2012  matt Remove extern variables defined in headers.
 1.176 19-Feb-2012  rmind Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.
 1.175 27-Jan-2012  para branches: 1.175.2;
extending vmem(9) to be able to allocated resources for it's own needs.
simplifying uvm_map handling (no special kernel entries anymore no relocking)
make malloc(9) a thin wrapper around kmem(9)
(with private interface for interrupt safety reasons)

releng@ acknowledged
 1.174 12-Jan-2012  cherry relocate pte_lock initialisation to the earliest points after %fs is first usable in the XEN bootpath
 1.173 12-Dec-2011  mrg implement bdev_size(9) wrapper around d_psize() routine, so we can take
the device lock in relevant places. avoid doing so while actually dumping.

tested i386 crash dumps still work, and that all touched files compile.

fixes PR#45705.
 1.172 04-Dec-2011  chs map all of physical memory using large pages.
ported from openbsd years ago by Murray Armfield,
updated for changes since then by me.
 1.171 20-Nov-2011  yamt branches: 1.171.2;
revert machdep.c rev. 1.168 because it's likely to have the same problem
as i386's one.
http://mail-index.NetBSD.org/source-changes-d/2011/11/19/msg004283.html
 1.170 10-Nov-2011  jym Turn the 'i386_use_pae' variable into simply 'use_pae'. Technically
speaking we are also running with PAE enabled in long mode under amd64,
so this variable will be used in various places across x86 machdep to
branch at runtime to functions that require extra handling for PAE mode.
 1.169 06-Nov-2011  cherry DTRT with macros and use xen's info page when initialising pmap_pa_start and pmap_pa_end.
 1.168 31-Oct-2011  yamt branches: 1.168.2;
dumpsys_seg: don't overwrite the previous mapping
 1.167 31-Aug-2011  christos fix reversed test.
 1.166 31-Aug-2011  christos on xen we don't initialize memory segment maps, so no sparse dumps for now.
 1.165 27-Aug-2011  christos Implement sparse dumps for amd64 (copied from i386). Disabled for now via
sysctl.
XXX: most of the code can be merged.
 1.164 11-Aug-2011  cherry Hide the MD details of specific IPIs behind semantically pleasing functions. This cleans up a couple of #ifdef XEN/#endif pairs
 1.163 10-Aug-2011  cherry xen ipi infrastructure
 1.162 17-Jul-2011  jym CR4_PAE is always set to 1 under amd64, so indicate that PAE mode is
enabled. Can be useful for 32-bits test runs on amd64 hosts.
 1.161 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.160 04-Mar-2011  joerg branches: 1.160.2;
Refactor ps_strings access. Based on PK_32, write either the normal
version or the 32bit compat layout in execve1. Introduce a new function
copyin_psstrings for reading it back from userland and converting it to
the native layout. Refactor procfs to share most of the code with the
kern.proc_args sysctl handler.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.
 1.159 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.158 11-Jan-2011  jruoho branches: 1.158.2; 1.158.4;
Restore the interrupt level in cpu_reboot() before calling the
acpi_enter_sleep_state() function.
 1.157 15-Nov-2010  uebayasi struct lwp * and struct proc * derefs.
 1.156 12-Nov-2010  uebayasi Pull in uvm/uvm.h where UVM's page level interface is used.
 1.155 10-Nov-2010  uebayasi Use more VM_PHYSMEM_*() accessors. No functional changes.
 1.154 24-Oct-2010  jruoho Simplify acpi_enter_sleep_state() and guard it against NULL pointer
dereferences. Try to avoid referencing the global acpi_softc, which should
really be static or at least internal to acpi(4).
 1.153 21-Oct-2010  yamt cpu_setmcontext: add a comment
 1.152 21-Oct-2010  yamt cpu_fsgs_zero: clear %fs and %gs even in the case of !PK_32.
 1.151 21-Oct-2010  yamt cpu_fsgs_zero: always clear tf_fs and tf_gs.
 1.150 21-Oct-2010  yamt don't forget to call nmi_init.
 1.149 22-Sep-2010  jakllsch Avoid fault if acpi_softc is NULL at attempted power-off.
XXX at least some of this should be factored off into arch/x86.
 1.148 07-Aug-2010  jruoho Do not try to disable ACPI if we can not enter to legacy mode. While it is
safe to call AcpiDisable() even if a system operates only in ACPI mode, this
leads to unpleasantly verbose error messages in ACPICA.
 1.147 31-Jul-2010  joerg Add machdep.fpu_present, machdep.sse and machdep.sse2 sysctls for
compatibility with i386 and compat32.
 1.146 07-Jul-2010  chs add the guts of TLS support on amd64. based on joerg's patch,
reworked by me to support 32-bit processes as well.
we now keep %fs and %gs loaded with the user values
while in the kernel, which means we don't need to
reload them when returning to user mode.
 1.145 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.144 18-Apr-2010  jym This patch fixes the NX regression issue observed on amd64 kernels, where
per-page execution right was disabled (therefore leading to the inability
of the kernel to detect fraudulent use of memory mappings marked as not
being executable).

- replace cpu_feature and ci_feature_flags variables by cpu_feature and
ci_feat_val arrays. This makes it cleaner and brings kernel code closer
to the design of cpuctl(8). A warning will be raised for each CPU that
does not expose the same features as the Boot Processor (BP).

- the blacklist of CPU features is now a macro defined in the
specialreg.h header, instead of hardcoding it inside MD initialization
code; fix comments.

- replace checks against CPUID_TSC with the cpu_hascounter() function.

- clean up the code in init_x86_64(), as cpu_feature variables are set
inside cpu_probe().

- use cpu_init_msrs() for i386. It will be eventually used later for NX
feature under i386 PAE kernels.

- remove code that checks for CPUID_NOX in amd64 mptramp.S, this is already
performed by cpu_hatch() through cpu_init_msrs().

- remove cpu_signature and feature_flags members from struct mpbios_proc
(they were never used).

This patch was tested with i386 MONOLITHIC, XEN3PAE_DOM0 and XEN3_DOM0 under
a native i386 host, and amd64 GENERIC, XEN3_DOM0 via QEMU virtual machines.

XXX Should kernel rev be bumped?

XXX A similar patch should be pulled-up for NetBSD-5, hopefully tomorrow.
 1.143 01-Mar-2010  jym branches: 1.143.2;
Do not forget that ptoa() casts the result to vaddr_t, which is bad
for paddr_t values under i386 PAE. Use ctob() instead.

Although amd64 is not affected by this vaddr_t vs paddr_t issue (both
having the same size), for the sake of completeness, switch to
ctob() when manipulating paddr_t/psize_t entities in amd64 machdep.c.

Compile tested for i386 and amd64. No regression expected.
 1.142 08-Feb-2010  joerg 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.141 31-Dec-2009  jym branches: 1.141.2;
Use banner() instead of amd64's custom use of printf's for copyright
notice and total/available memory.
 1.140 10-Dec-2009  matt 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.139 29-Nov-2009  rmind Replace l_addr with uvm_lwp_getuarea() in various MD code, mostly cpu_lwp_fork().
 1.138 26-Nov-2009  matt Kill proc0paddr. Use lwp0.l_addr instead.
 1.137 21-Nov-2009  rmind Use lwp_getpcb() on x86 MD code, clean from struct user usage.
 1.136 07-Nov-2009  cegger Add a flags argument to pmap_kenter_pa(9).
Patch showed on tech-kern@ http://mail-index.netbsd.org/tech-kern/2009/11/04/msg006434.html
No objections.
 1.135 27-Oct-2009  rmind Make pcb_ldt_sel, in amd64, an unused field. Unlike in i386, it was
missed during clean-up of LDT handling.
 1.134 19-Oct-2009  bouyer Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.133 05-Oct-2009  rmind Remove X86_IPI_WRITE_MSR (and msr_ipifuncs.c), replace all uses in drivers
with xc_broadcast(). AMD K8 PowerNow driver tested by <jakllsch>, thanks!

Closes PR/37665.
 1.132 18-Aug-2009  jmcneill Switch to ACPICA 20090730, and update for API changes.
 1.131 15-Aug-2009  matt Include <sys/exec_aout.h> explicitly instead of relying on <sys/exec.h> to
do it for us.
 1.130 22-Mar-2009  ad Set up module_map correctly so that the system does not panic if it
becomes full.
 1.129 21-Mar-2009  ad 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.128 26-Feb-2009  jmcneill PR# port-i386/40751: power button does not work after halt
PR# kern/37506: Have to hold power button for 5 seconds to turn off Laptop
after "halt" command.

Transfer the system from ACPI to Legacy mode if RB_HALT is set.
 1.127 17-Feb-2009  jmcneill Just like i386 cpu_startup, for console drivers that require uvm and pmap
to be initialized, call consinit for a third time here.
 1.126 17-Feb-2009  cegger nuke unused global variable
 1.125 13-Feb-2009  apb Use "defopt MODULAR" in sys/conf/files, and #include "opt_modular.h"
in all kernel sources that use the MODULAR option.
Proposed in tech-kern on 18 Jan 2009.
 1.124 13-Feb-2009  bouyer Prepare for PCI frontend support in Xen3 domUs:
call x86_bus_space_init() and x86_bus_space_mallocok() if we have ISA or PCI
devices configured; not only for non-Xen or dom0 Xen
On Xen, always call PHYSDEVOP_SET_IOPL on context switch
on amd64, also call PHYSDEVOP_SET_IOPL from x86_64_proc0_tss_ldt_init()
 1.123 27-Jan-2009  christos branches: 1.123.2;
remove extra variable
 1.122 27-Jan-2009  christos factor out common reset code.
 1.121 27-Jan-2009  ad Make previous compile.
 1.120 27-Jan-2009  christos Attempt to force resets using two more methods:
1. Reset Control register at I/O port 0xcf9
2. Fast A20 and Init register at I/O port 0x92

Requested by ad@
 1.119 21-Jan-2009  cegger buildfix: re-adapt to major()/minor() returning a 32bit value.
 1.118 15-Jan-2009  joerg Fix typo in comment.
 1.117 11-Jan-2009  cegger make this compile
 1.116 11-Jan-2009  christos merge christos-time_t
 1.115 18-Dec-2008  cegger branches: 1.115.2;
remove unused malloc.h
 1.114 15-Dec-2008  cegger cleanup BIOS memmap code:
- get rid of some nested externs
- reduce dependency on global variables
- some preparations for upcoming pmem(9)
 1.113 30-Nov-2008  martin As discussed on tech-kern: mutex_init is too heavyweight for early bootstrap
phases, so move the initialization of the ksyms mutex back into main via
a function called ksyms_init. Rename the existing (but quite different)
ksyms_init* variations into ksyms_addsyms_elf() and ksyms_addsyms_explicit()
and adapt machdep code accordingly.
 1.112 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.111 16-Nov-2008  bouyer Make sure xen_idt is writable before trying to write to it (issue previously
masked by defined(COMPAT_10) || defined(COMPAT_IBCS2)). Make amd64xen kernel
boot again.
 1.110 14-Nov-2008  ad Remove unneeded ifdefs.
 1.109 14-Nov-2008  cegger merge BIOS memmap code from i386/i386/machdep.c:init386() and amd64/amd64/machdep.c:init_x86_64 into x86/x86/x86_machdep.c
 1.108 12-Nov-2008  ad Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.
 1.107 12-Nov-2008  cegger reduce diff to i386/i386/machdep.c:init386()
- introduce add_mem_cluster() as done in i386
- apply rev. 1.480 from i386/i386/machdep.c: fixes PR 17199 for amd64
- apply rev. 1.492 from i386/i386/machdep.c: fixes PR 13399 for amd64
 1.106 12-Nov-2008  cegger cosmetic change (mostly to reduce diff to i386/i386/machdep.c:initi386):
#if DEBUG_MEMLOAD -> #ifdef DEBUG_MEMLOAD
use PRIx64 rather %qx
No functional changes intended.
 1.105 11-Nov-2008  ad PR port-i386/39299 FPU use in signal handlers is unsafe
 1.104 11-Nov-2008  ad PR port-amd64/38293 panic: fp_save ipi didn't

Fix race conditions in FPU IPI handling.
 1.103 11-Nov-2008  dyoung It is not appropriate to call pmf_system_shutdown(9) from
doshutdownhooks(9): shutdown hooks registered by shutdownhook_establish(9)
expect to be called with interrupts disabled, but shutdown hooks
registered with pmf_device_register1(9) expect to be called with
interrupts enabled. So I have made two changes:

1 Do not call pmf_system_shutdown() from doshutdownhooks(). Instead,
change every call to doshutdownhooks() to a call to doshutdownhooks()
followed by a call to pmf_system_shutdown(). No functional change
is intended by this change.

2 Make i386 re-enable interrupts briefly while it calls
pmf_system_shutdown(). I leave it to others either to fix the
other ports, or to factor out some MI shutdown code, as joerg@
suggests, and fix that. Note that a functional change *is* intended
by this change.

I hope that this patch will stop us from flip-flopping between
calling doshutdownhooks() and pmf_system_shutdown() sometimes with
and sometimes without interrupts enabled.
 1.102 21-Oct-2008  cegger branches: 1.102.2; 1.102.4;
introduce two macros: xendomain_is_dom0() and xendomain_is_privileged(). Use them.
 1.101 15-Oct-2008  wrstuden Merge wrstuden-revivesa into HEAD.
 1.100 18-Sep-2008  christos Define a PSL_CLEARSIG macro for the psl flags to be cleared on signal delivery
and use it everywhere.
 1.99 26-Aug-2008  cegger Xen: Mark NMI and machine check handlers as interrupt gates.
 1.98 05-Aug-2008  drochner Disable interrupts before shutdownhooks are run, as all other ports.
shutdownhooks need to use polling functions (and most do).
 1.97 02-Jul-2008  ad branches: 1.97.2;
Replce exec_map with a pool. Proposed on tech-kern@, reviewed by chs@.
 1.96 29-Jun-2008  bouyer Proper FPU exeptions support for Xen. Should fix FPU issues reported by
various users.
 1.95 05-Jun-2008  ad branches: 1.95.2;
Leave interrupts on for the shutdownhooks. Should fix the panics on
shutdown.
 1.94 21-May-2008  ad PR port-amd64/38708 lkm_map issues on amd64

lkm_map should not be marked pageable.
 1.93 11-May-2008  ad Simplify x86 identcpu code, and share between i386/amd64.
 1.92 05-May-2008  ad branches: 1.92.2;
Export tsc_freq via sysctl.
 1.91 29-Apr-2008  ad Get spl framework and interrupt gates working before breaking into DDB
on boot. PR port-amd64/30828.
 1.90 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.89 27-Apr-2008  ad branches: 1.89.2;
- Rename crit_enter/crit_exit to kpreempt_disable/kpreempt_enable.
DragonflyBSD uses the crit names for something quite different.
- Add a kpreempt_disabled function for diagnostic assertions.
- Add inline versions of kpreempt_enable/kpreempt_disable for primitives.
- Make some more changes for preemption safety to the x86 pmap.
 1.88 24-Apr-2008  ad Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.
 1.87 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.86 16-Apr-2008  cegger branches: 1.86.2;
use POSIX integer types
 1.85 12-Feb-2008  joerg branches: 1.85.6;
Don't sleep for 0.5s before powering down the machine with ACPI.
 1.84 16-Jan-2008  ad Always set up lkm_map.
 1.83 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.82 08-Jan-2008  yamt change the layout in u-area and reduce UPAGES.
 1.81 05-Jan-2008  yamt allocate dedicated stacks for NMI. PR/37662.
 1.80 05-Jan-2008  yamt remove no longer necessary cpu_maxproc.
 1.79 05-Jan-2008  yamt - make amd64 use per-cpu tss.
- fix iopl syscall for amd64+xen.
 1.78 04-Jan-2008  dsl Change the way that the trap/intr/syscall frames and the __gregset_t[]
indexes are defined so that only a single list of the registers is used.
The code no longer relies on the two structures matching.
There should be no binary change.
 1.77 28-Dec-2007  dogcow XEN only gets defined in opt_xen.h; move the ifndef check after the include.
 1.76 27-Dec-2007  joerg opt_physmem.h only exists for !Xen.
 1.75 26-Dec-2007  joerg Remove #if 0'ed microtime from the simulator days.
 1.74 26-Dec-2007  joerg Add PHYSMEM_MAX_ADDR and PHYSMEM_MAX_SIZE options. This limit physical
memory based on overall size (useful for debugging to keep core dumps
small) or maximum address (when using devices with bus dma limits).
Contrary to REALBASEMEM and REALEXTMEM, they still use the BIOS memory
map and can therefore deal with fragmented memory.
 1.73 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.72 09-Dec-2007  jmcneill branches: 1.72.2;
Merge jmcneill-pm branch.
 1.71 03-Dec-2007  ad branches: 1.71.2; 1.71.4;
Interrupt handling changes, in discussion since February:

- Reduce available SPL levels for hardware devices to none, vm, sched, high.
- Acquire kernel_lock only for interrupts at IPL_VM.
- Implement threaded soft interrupts.
 1.70 24-Nov-2007  bouyer Xen loads the symbol table 4 bytes after _end, not eight.
Now the kernel properly finds the symbol table.
 1.69 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.68 20-Nov-2007  xtraeme Put back again softintr_init() that was removed in rev 1.67, this fixes
the panics that people reported on current-users.

Tested and verified by Greg Oster.
 1.67 19-Nov-2007  ad IPL_IPI -> IPL_HIGH
 1.66 12-Nov-2007  ad Merge cpu_need_resched() from vmlocking:

- Always do an aston(), even if not sending an IPI. May help with xine.
- Post asts on cpu_onproc, not ci_curlwp.
 1.65 26-Oct-2007  joerg branches: 1.65.2;
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.64 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.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 26-Sep-2007  ad branches: 1.62.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.61 29-Aug-2007  ad branches: 1.61.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.60 08-Jul-2007  pooka branches: 1.60.4; 1.60.8; 1.60.10;
Initialize the link context in a signal frame to the receiving lwp's
link context instead of NULL. Otherwise, if we got a signal while the
lwp had a link context set, the link context would be set to NULL upon
return from signal delivery.

christos@tech-kern: "I think you are right."
 1.59 25-May-2007  yamt dumpsys: build a fake switchframe for postmortem debugging.
reviewed by Frank van der Linden.
 1.58 21-May-2007  fvdl Revert fs/gs changes until I figure out issues with them.
 1.57 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.56 17-May-2007  fvdl Fix broken constraint in asm.
 1.55 13-May-2007  fvdl Initialize a few PCB fields explicity in more places.
 1.54 11-May-2007  fvdl Don't save/restore %fs and %gs in trapframe. The kernel won't touch them.
Instead, save/restore them on context switch. For 32bit processes, save/restore
the selector values only, for 64bit processes, save/restore the appropriate
MSRs. Iff the defaults have been changed.
 1.53 20-Mar-2007  xtraeme branches: 1.53.4;
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.52 04-Mar-2007  yamt branches: 1.52.2; 1.52.4; 1.52.6;
fix fallout from caddr_t changes.
 1.51 04-Mar-2007  christos Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.50 22-Feb-2007  thorpej TRUE -> true, FALSE -> false
 1.49 18-Feb-2007  ad Sync signal delivery routines with i386. sendsig_reset() was not being
called, and so delivered signals were not being masked.

From cube@, with minor mods by me.
 1.48 17-Feb-2007  pavel Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.
 1.47 09-Feb-2007  ad branches: 1.47.2;
Merge newlock2 to head.
 1.46 16-Jan-2007  christos remove CPUID2MODEL, since it is defined in specialreg.h
 1.45 06-Jan-2007  pavel PR port-i386/34186 by Wolfgang Stukenbrock:
mapping of msgbuf during startup may map invalid physical adresses

Apply a similar patch as in the i386 case.
The amd64 version was supplied by Blair Sadewitz, thanks.
 1.44 23-Oct-2006  pooka branches: 1.44.2;
apply const where necessary
 1.43 21-Oct-2006  mrg in cpu_dumpconf(), don't panic() if we can't bdevsw_lookup() the
dumpdev. this occurs when we try to set the dumpdev to a device
with no driver loaded. this fixes PR#34872.

in sys_swapctl, if bdevsw_lookup() fails, set dumpdev = NODEV
before calling cpu_dumpconf(). (this also fixes PR#34872.)

XXX: cpu_dumpconf() should probably be changed to take a dumpdev
XXX: and return an error in such cases, but that is a much more
XXX: intrusive change.

XXX2: this is only run-tested on sparc64 and compile tested on a
XXX2: couple of platforms.
 1.42 05-Oct-2006  chs in cpu_reboot(), only halt the other CPUs after we've done the powerdown stuff.
the ACPI code may end up removing some pmap entries, which wants the other
CPUs to still be running to handle TLB invalidations.
 1.41 27-Sep-2006  cube 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.40 19-Aug-2006  dsl branches: 1.40.2; 1.40.4;
de __P()
 1.39 07-Jun-2006  kardel convert to timecounters (from branch simonb-timecounters)
 1.38 21-Jan-2006  fvdl branches: 1.38.2; 1.38.4; 1.38.6; 1.38.12;
GDT data and code entries for 32bit mode should use VM_MAXUSER_ADDRESS32
 1.37 30-Dec-2005  jmmv branches: 1.37.2;
Add a 'struct bootinfo' to represent the bootinfo structure used in the
kernel by x86 platforms (instead of a simple char *). This way, the code
in, e.g., lookup_bootinfo, is a bit easier to understand.

While here, move the lookup_bootinfo function used in x86 platforms (amd64,
i386 and xen) to a common file (x86/x86_machdep.c), as it was exactly the
same in all of them.
 1.36 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.35 11-Dec-2005  christos merge ktrace-lwp.
 1.34 15-May-2005  fvdl branches: 1.34.2;
Optionally include saving and restoring the 64bit %gs and %fs base register
values in the PCB. Do this in pmap_activate for now (XXX not a good place
for it, but a convenient one).
 1.33 25-Apr-2005  lukem Move the MI printing of `copyright' to the MD cpu_startup() code
where the printing of `version' is already performed.
This has the benefit of allowing the copyright to be available
via dmesg(8) on platforms which need the `msgbuf' to be setup
in cpu_startup() before printed output is remembered.
 1.32 01-Apr-2005  yamt merge yamt-km branch.
- don't use managed mappings/backing objects for wired memory allocations.
save some resources like pv_entry. also fix (most of) PR/27030.
- simplify kernel memory management API.
- simplify pmap bootstrap of some ports.
- some related cleanups.
 1.31 20-Oct-2004  thorpej branches: 1.31.4; 1.31.6; 1.31.10;
Move boot device detection code from i386 and amd64 ports to x86_autoconf.c.
Rename i386_alldisks and x86_64_alldisks to x86_alldisks, adjust other
references to compensate.
 1.30 05-Aug-2004  cube boothowto is already available through sys/systm.h, and is actually
declared elsewhere; don't duplicate it.
 1.29 16-Jun-2004  fvdl Start at the top of the double fault stack, not the bottom.
 1.28 16-Jun-2004  fvdl Remove IDT protection while doing unsetgate too.
 1.27 15-Jun-2004  fvdl Make the IDT read-only. It's only mapped R/W when really needed. Could
catch disasters such as overwriting it. Should probably be made
conditional on DIAGNOSTIC later, but there's no time-critical code
involved here.

Move the double fault stack away from the IPI stack. It's now shared
between CPUs, but that's not a big deal; double faults are fatal
and can't be recovered from.
 1.26 03-May-2004  toshii #include acpi.h and some others to be able to powerdown via acpi.
 1.25 28-Mar-2004  drochner branches: 1.25.2;
We should ensure stack alignment _after_ subtracting sizeof(sigframe).
Should fix PR bin/24948 by Wolfgang S. Rupprecht.
(nuke getframe() completely because its interface doesn't support this,
and it it used at one place only anyway)
 1.24 25-Mar-2004  drochner always use siginfo-style signal delivery for native programs
 1.23 24-Mar-2004  atatat Tango on sysctl_createv() and flags. The flags have all been renamed,
and sysctl_createv() now uses more arguments.
 1.22 23-Mar-2004  drochner initialize the old "int 0x80" syscall only for COMPAT_16/NETBSD32,
and the very old callgate for COMPAT_10/IBCS2
 1.21 01-Mar-2004  drochner set MDP_IRET in cpu_setmcontext() - the normal (fast)
syscall exit is not able to propagate all register
arguments
 1.20 13-Feb-2004  wiz Uppercase CPU, plural is CPUs.
 1.19 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.18 06-Dec-2003  fvdl Segment registers are only 16 bits wide, so only check 16 bits worth of
them for validity in check_mcontext.
 1.17 04-Dec-2003  atatat Dynamic sysctl.

Gone are the old kern_sysctl(), cpu_sysctl(), hw_sysctl(),
vfs_sysctl(), etc, routines, along with sysctl_int() et al. Now all
nodes are registered with the tree, and nodes can be added (or
removed) easily, and I/O to and from the tree is handled generically.

Since the nodes are registered with the tree, the mapping from name to
number (and back again) can now be discovered, instead of having to be
hard coded. Adding new nodes to the tree is likewise much simpler --
the new infrastructure handles almost all the work for simple types,
and just about anything else can be done with a small helper function.

All existing nodes are where they were before (numerically speaking),
so all existing consumers of sysctl information should notice no
difference.

PS - I'm sorry, but there's a distinct lack of documentation at the
moment. I'm working on sysctl(3/8/9) right now, and I promise to
watch out for buses.
 1.16 04-Dec-2003  keihan netbsd.org -> NetBSD.org

All "netbsd.org" is now gone from src/sys/arch.
 1.15 01-Dec-2003  fvdl Don't use an alternate stack for the trace/breakpoint trap. It can be
called from userspace, and that messes things up.

Thanks to Mark Kettenis to pointing out that not using an alt stack
solved the "loop on gdb sig continuation" issue.
 1.14 19-Oct-2003  fvdl Don't use err and trapno from a copied in mcontext.
 1.13 17-Oct-2003  fvdl Put the ucontext pointer in %r15 for signal delivery, so that it is
saved across the handler call.
 1.12 15-Oct-2003  drochner fix typo (harmless as long as pmap_update() is a noop)
 1.11 14-Oct-2003  fvdl Proper checks for kmem reads beyond _end
 1.10 13-Oct-2003  fvdl Do checks on passed in context values (sigreturn/setcontext) explicitly;
can't rely on catching the trap on iret for a few reasons.
 1.9 08-Oct-2003  fvdl Adapt for ksiginfo changes.
 1.8 06-Oct-2003  fvdl SIGINFO support.
Todo: 32bit compat support (COMPAT_NETBSD32 will not compile right now,
as it won't on other platforms).
 1.7 26-Sep-2003  simonb Fix "constify sendsig/trapsignal" fallout for non-siginfo'd archs. Test
compiled on most architectures.
 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 14-Jul-2003  lukem __KERNEL_RCSID()
 1.4 23-Jun-2003  martin branches: 1.4.2;
Make sure to include opt_foo.h if a defflag option FOO is used.
 1.3 07-May-2003  fvdl Set up lkm_map in range of kernel text.
 1.2 04-May-2003  fvdl Correct save FP state for signals.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.4.2.7 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.4.2.6 01-Apr-2005  skrll Sync with HEAD.
 1.4.2.5 02-Nov-2004  skrll Sync with HEAD.
 1.4.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.4.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.4.2.2 12-Aug-2004  skrll Sync with HEAD.
 1.4.2.1 03-Aug-2004  skrll Sync with HEAD
 1.25.2.1 22-Jun-2004  tron Pull up revision 1.26 (requested by toshii in ticket #518):
 1.31.10.1 22-Nov-2008  bouyer Pull up following revision(s) (requested by cegger in ticket #1979):
sys/arch/amd64/amd64/machdep.c: revision 1.106, 1.107 via patch
cosmetic change (mostly to reduce diff to i386/i386/machdep.c:initi386):
use PRIx64 rather %qx
No functional changes intended.
reduce diff to i386/i386/machdep.c:init386()
- introduce add_mem_cluster() as done in i386
- apply rev. 1.480 from i386/i386/machdep.c: fixes PR 17199 for amd64
- apply rev. 1.492 from i386/i386/machdep.c: fixes PR 13399 for amd64
 1.31.6.1 13-Feb-2005  yamt - use new apis.
- simplify pmap bootstrap and pv_page allocation.
 1.31.4.1 29-Apr-2005  kent sync with -current
 1.34.2.9 27-Feb-2008  yamt sync with head.
 1.34.2.8 21-Jan-2008  yamt sync with head
 1.34.2.7 07-Dec-2007  yamt sync with head
 1.34.2.6 15-Nov-2007  yamt sync with head.
 1.34.2.5 27-Oct-2007  yamt sync with head.
 1.34.2.4 03-Sep-2007  yamt sync with head.
 1.34.2.3 26-Feb-2007  yamt sync with head.
 1.34.2.2 30-Dec-2006  yamt sync with head.
 1.34.2.1 21-Jun-2006  yamt sync with head.
 1.37.2.1 01-Feb-2006  yamt sync with head.
 1.38.12.1 19-Jun-2006  chap Sync with head.
 1.38.6.2 03-Sep-2006  yamt sync with head.
 1.38.6.1 26-Jun-2006  yamt sync with head.
 1.38.4.1 30-Apr-2006  kardel retire cc_microtime code
 1.38.2.1 09-Sep-2006  rpaulo sync with head
 1.40.4.2 10-Dec-2006  yamt sync with head.
 1.40.4.1 22-Oct-2006  yamt sync with head
 1.40.2.8 01-Feb-2007  ad Sync with head.
 1.40.2.7 30-Jan-2007  ad Remove support for SA. Ok core@.
 1.40.2.6 12-Jan-2007  ad Sync with head.
 1.40.2.5 11-Jan-2007  ad Checkpoint work in progress.
 1.40.2.4 29-Dec-2006  ad Checkpoint work in progress.
 1.40.2.3 18-Nov-2006  ad Sync with head.
 1.40.2.2 17-Nov-2006  ad Checkpoint work in progress.
 1.40.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.44.2.7 12-Jun-2012  riz Pull up following revision(s) (requested by spz in ticket #1450):
sys/arch/amd64/amd64/machdep.c: revision 1.184
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.77
If the user process provided a bogus signal handler address, kill it
now instead of trying to jump to the bogus address.
 1.44.2.6 18-Oct-2009  bouyer Pull up following revision(s) (requested by mlelstv in ticket #1363):
sys/arch/i386/isa/npx.c: revision 1.132 via patch
sys/arch/amd64/amd64/fpu.c: revision 1.29 via patch
sys/arch/amd64/amd64/machdep.c: revision 1.105 via patch
sys/arch/i386/i386/machdep.c: revision 1.647 via patch
PR port-i386/39299 FPU use in signal handlers is unsafe
Ensure FP state is reset, if FP is used in a signal handler.
Fixes PR kern/39299 for 32bit code.
 1.44.2.5 22-Nov-2008  bouyer Pull up following revision(s) (requested by cegger in ticket #1233):
sys/arch/amd64/amd64/machdep.c: revision 1.106, 1.107 via patch
cosmetic change (mostly to reduce diff to i386/i386/machdep.c:initi386):
use PRIx64 rather %qx
No functional changes intended.
reduce diff to i386/i386/machdep.c:init386()
- introduce add_mem_cluster() as done in i386
- apply rev. 1.480 from i386/i386/machdep.c: fixes PR 17199 for amd64
- apply rev. 1.492 from i386/i386/machdep.c: fixes PR 13399 for amd64
 1.44.2.4 16-Sep-2008  bouyer Sync with the following revisions (requested by skrll in ticket #1196):
gnu/dist/gdb removed
gnu/usr.bin/gdb53 removed
distrib/cats/instkernel/Makefile 1.14.6.1
gnu/dist/gdb6/bfd/config.bfd 1.3.6.1
gnu/dist/gdb6/bfd/elfxx-sparc.c 1.1.1.2.6.1
gnu/dist/gdb6/bfd/elfxx-sparc.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/Makefile.in 1.2.2.1.2.2
gnu/dist/gdb6/gdb/alpha-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/alpha-tdep.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/alphabsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/alphabsd-nat.h 1.1.2.1
gnu/dist/gdb6/gdb/alphabsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/alphabsd-tdep.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/alphanbsd-nat.c 1.1.2.1
gnu/dist/gdb6/gdb/alphanbsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/amd64-nat.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/amd64bsd-nat.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/amd64nbsd-nat.c 1.1.1.2.6.3
gnu/dist/gdb6/gdb/amd64nbsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/arm-tdep.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/armbsd-tdep.c 1.1.2.1
gnu/dist/gdb6/gdb/armnbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/armnbsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/configure 1.1.1.2.6.1
gnu/dist/gdb6/gdb/configure.ac 1.1.1.2.6.1
gnu/dist/gdb6/gdb/i386bsd-nat.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/i386nbsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/m68kbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/mipsnbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/nbsd-thread.c 1.1.2.3
gnu/dist/gdb6/gdb/ppcnbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/ppcnbsd-tdep.c 1.3.6.1
gnu/dist/gdb6/gdb/sh-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/shnbsd-nat.c 1.1.1.2.6.3
gnu/dist/gdb6/gdb/shnbsd-tdep.c 1.1.1.2.6.4
gnu/dist/gdb6/gdb/shnbsd-tdep.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/sparc-nat.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/sparc64nbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/sparcnbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/tramp-frame.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/vaxbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/config/alpha/nbsd.mh 1.1.1.2.6.1
gnu/dist/gdb6/gdb/config/arm/nbsd.mt 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/arm/nbsdelf.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/i386/nbsd64.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/m68k/nbsdelf.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/mips/nbsd.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/powerpc/nbsd.mh 1.1.1.2.6.1
gnu/dist/gdb6/gdb/config/sh/nbsd.mh 1.1.1.1.6.2
gnu/dist/gdb6/gdb/config/sh/tm-nbsd.h 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/sparc/nbsd64.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/sparc/nbsdelf.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/vax/nbsdelf.mh 1.1.1.1.6.1
gnu/dist/gdb6/opcodes/configure 1.1.1.2.6.1
gnu/dist/gdb6/opcodes/configure.in 1.1.1.2.6.1
gnu/usr.bin/Makefile 1.126.4.1
gnu/usr.bin/gdb6/arch/alpha/config.h 1.3.4.1
gnu/usr.bin/gdb6/arch/alpha/defs.mk 1.2.6.1
gnu/usr.bin/gdb6/arch/alpha/init.c 1.2.6.1
gnu/usr.bin/gdb6/arch/alpha/nm.h 1.2.6.1
gnu/usr.bin/gdb6/arch/arm/defs.mk 1.2.6.2
gnu/usr.bin/gdb6/arch/arm/init.c 1.1.6.1
gnu/usr.bin/gdb6/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/arch/armeb/defs.mk 1.1.6.3
gnu/usr.bin/gdb6/arch/armeb/init.c 1.1.6.2
gnu/usr.bin/gdb6/arch/armeb/tm.h 1.1.6.2
gnu/usr.bin/gdb6/arch/armeb/version.c 1.1.6.2
gnu/usr.bin/gdb6/arch/i386/defs.mk 1.4.4.1
gnu/usr.bin/gdb6/arch/i386/init.c 1.3.6.1
gnu/usr.bin/gdb6/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/arch/m68000/init.c 1.1.6.2
gnu/usr.bin/gdb6/arch/m68000/tm.h 1.1.6.2
gnu/usr.bin/gdb6/arch/m68000/version.c 1.1.6.2
gnu/usr.bin/gdb6/arch/m68k/defs.mk 1.1.4.1
gnu/usr.bin/gdb6/arch/m68k/init.c 1.1.4.1
gnu/usr.bin/gdb6/arch/mipseb/config.h 1.3.4.1
gnu/usr.bin/gdb6/arch/mipseb/defs.mk 1.2.6.2
gnu/usr.bin/gdb6/arch/mipseb/init.c 1.2.6.2
gnu/usr.bin/gdb6/arch/mipsel/config.h 1.2.6.3
gnu/usr.bin/gdb6/arch/mipsel/defs.mk 1.2.6.3
gnu/usr.bin/gdb6/arch/mipsel/init.c 1.2.6.3
gnu/usr.bin/gdb6/arch/mipsel/tm.h 1.2.6.2
gnu/usr.bin/gdb6/arch/mipsel/version.c 1.2.6.2
gnu/usr.bin/gdb6/arch/powerpc/defs.mk 1.3.6.1
gnu/usr.bin/gdb6/arch/powerpc/init.c 1.3.6.1
gnu/usr.bin/gdb6/arch/sh3eb/config.h 1.2.2.2
gnu/usr.bin/gdb6/arch/sh3eb/defs.mk 1.2.8.3
gnu/usr.bin/gdb6/arch/sh3eb/init.c 1.1.8.3
gnu/usr.bin/gdb6/arch/sh3eb/nm.h 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3eb/tm.h 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3eb/version.c 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3el/config.h 1.2.2.2
gnu/usr.bin/gdb6/arch/sh3el/defs.mk 1.2.8.3
gnu/usr.bin/gdb6/arch/sh3el/init.c 1.1.8.3
gnu/usr.bin/gdb6/arch/sh3el/nm.h 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3el/tm.h 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3el/version.c 1.1.8.2
gnu/usr.bin/gdb6/arch/sparc/defs.mk 1.2.6.1
gnu/usr.bin/gdb6/arch/sparc/init.c 1.1.6.1
gnu/usr.bin/gdb6/arch/sparc64/defs.mk 1.2.6.1
gnu/usr.bin/gdb6/arch/sparc64/init.c 1.1.6.1
gnu/usr.bin/gdb6/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/arch/vax/init.c 1.1.6.2
gnu/usr.bin/gdb6/arch/vax/tm.h 1.1.6.2
gnu/usr.bin/gdb6/arch/vax/version.c 1.1.6.2
gnu/usr.bin/gdb6/arch/x86_64/defs.mk 1.2.6.1
gnu/usr.bin/gdb6/arch/x86_64/init.c 1.1.6.1
gnu/usr.bin/gdb6/bfd/arch/armeb/bfd.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/armeb/bfdver.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/armeb/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/m68000/bfd.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/m68000/bfdver.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/mipsel/bfd.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/mipsel/bfdver.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/mipsel/config.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/mipsel/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/sh3eb/bfd.h 1.1.8.3
gnu/usr.bin/gdb6/bfd/arch/sh3eb/bfdver.h 1.1.8.2
gnu/usr.bin/gdb6/bfd/arch/sh3eb/config.h 1.1.8.2
gnu/usr.bin/gdb6/bfd/arch/sh3eb/defs.mk 1.1.8.3
gnu/usr.bin/gdb6/bfd/arch/sh3el/bfd.h 1.1.8.3
gnu/usr.bin/gdb6/bfd/arch/sh3el/bfdver.h 1.1.8.2
gnu/usr.bin/gdb6/bfd/arch/sh3el/config.h 1.1.8.2
gnu/usr.bin/gdb6/bfd/arch/sh3el/defs.mk 1.1.8.3
gnu/usr.bin/gdb6/bfd/arch/vax/bfd.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/vax/bfdver.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/gdb/Makefile 1.5.2.1.2.2
gnu/usr.bin/gdb6/gdbtui/Makefile 1.2.6.1
gnu/usr.bin/gdb6/libiberty/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/armeb/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/mipsel/config.h 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/mipsel/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/sh3eb/config.h 1.1.8.2
gnu/usr.bin/gdb6/libiberty/arch/sh3eb/defs.mk 1.1.8.2
gnu/usr.bin/gdb6/libiberty/arch/sh3el/config.h 1.1.8.2
gnu/usr.bin/gdb6/libiberty/arch/sh3el/defs.mk 1.1.8.2
gnu/usr.bin/gdb6/libiberty/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/armeb/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/mipsel/config.h 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/mipsel/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/sh3eb/config.h 1.1.8.2
gnu/usr.bin/gdb6/opcodes/arch/sh3eb/defs.mk 1.1.8.3
gnu/usr.bin/gdb6/opcodes/arch/sh3el/config.h 1.1.8.2
gnu/usr.bin/gdb6/opcodes/arch/sh3el/defs.mk 1.1.8.3
gnu/usr.bin/gdb6/opcodes/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/armeb/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/mipsel/config.h 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/mipsel/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/sh3eb/config.h 1.1.8.2
gnu/usr.bin/gdb6/readline/arch/sh3eb/defs.mk 1.1.8.2
gnu/usr.bin/gdb6/readline/arch/sh3el/config.h 1.1.8.2
gnu/usr.bin/gdb6/readline/arch/sh3el/defs.mk 1.1.8.2
gnu/usr.bin/gdb6/readline/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/sim/arch/mipseb/cconfig.h 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipseb/config.h 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipseb/defs.mk 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipsel/cconfig.h 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipsel/config.h 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipsel/defs.mk 1.1.2.1
lib/libkvm/kvm_sparc64.c 1.10.18.2
lib/libpthread/pthread.c 1.48.6.4
lib/libpthread/pthread_barrier.c 1.6.18.1
lib/libpthread/pthread_cond.c 1.18.12.2
lib/libpthread/pthread_debug.h 1.8.18.1
lib/libpthread/pthread_int.h 1.34.4.5
lib/libpthread/pthread_lock.c 1.14.6.1
lib/libpthread/pthread_mutex.c 1.22.4.2
lib/libpthread/pthread_run.c 1.18.12.4
lib/libpthread/pthread_rwlock.c 1.13.6.2
lib/libpthread/pthread_sa.c 1.37.6.5
lib/libpthread/pthread_sig.c 1.47.4.8
lib/libpthread/pthread_sleep.c 1.7.6.2
lib/libpthread/sem.c 1.9.6.2
lib/libpthread/arch/sh3/pthread_md.h 1.3.6.1
regress/lib/libpthread/resolv/Makefile 1.1.12.1
regress/lib/libpthread/sigrunning/Makefile 1.1.2.1
regress/lib/libpthread/sigrunning/sigrunning.c 1.1.2.1
share/mk/bsd.own.mk 1.489.4.3
sys/arch/amd64/amd64/locore.S 1.18.14.1
sys/arch/amd64/amd64/machdep.c 1.44.2.3.2.1
sys/arch/amd64/conf/kern.ldscript 1.1.70.1
sys/arch/cats/conf/Makefile.cats.inc 1.17.30.1
sys/arch/shark/conf/Makefile.shark.inc 1.6.30.1
sys/arch/sparc64/conf/kern.ldscript 1.7.26.2
sys/arch/sparc64/conf/kern32.ldscript 1.6.26.2
sys/arch/sparc64/include/kcore.h 1.4.92.2
sys/arch/sparc64/sparc64/locore.s 1.232.4.4
sys/arch/sparc64/sparc64/machdep.c 1.193.4.3
sys/arch/sparc64/sparc64/pmap.c 1.184.2.1.2.4
sys/conf/newvers.sh 1.42.26.2
sys/kern/kern_sa.c 1.87.4.11
sys/kern/kern_synch.c 1.173.4.2
sys/sys/savar.h 1.20.10.2
tools/gdb/Makefile 1.9.4.1
tools/gdb/mknative-gdb 1.1.6.1

pullup the wrstuden-fixsa CVS branch to netbsd-4:
toolchain/35540 - GDB 6 support for pthreads.
port-sparc64/37534 - ktrace firefox gives
kernel trap 30: data access expection
GDB changes:
- delete gdb53
- enable gdb6 on all architectures
- add support for amd64 crash dumps
- add support for sparc64 crash dumps
- add support for /proc pid to executable filename for all archs
- enable thread support for all architectures
- add a note section to kernels to all platforms
- support detection/unwinding of signals for most architectures.
- Fix PTHREAD_UCONTEXT_TO_REG / PTHREAD_REG_TO_UCONTEXT on sh3.
- Apply fix from binutils-current so that sparc gdb can be cross built
on a 64bit host.
SA/pthread changes:
Pre-allocate memory needed for event delivery. Eliminates dropped
interrupts under load.
Deliver intra-process signals to running threads
Eliminate some deadlock scenarios
Fix intra-process signal delivery when delivering to a thread waiting
for signals. Makes afs work again!
 1.44.2.3 20-Apr-2007  bouyer branches: 1.44.2.3.2; 1.44.2.3.6;
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.44.2.2 10-Feb-2007  tron Pull up following revision(s) (requested by chs in ticket #411):
sys/arch/amd64/amd64/machdep.c: revision 1.46
remove CPUID2MODEL, since it is defined in specialreg.h
 1.44.2.1 07-Feb-2007  tron Pull up following revision(s) (requested by pavel in ticket #397):
sys/arch/amd64/amd64/machdep.c: revision 1.45
sys/arch/amd64/amd64/pmap.c: revision 1.28
PR port-i386/34186 by Wolfgang Stukenbrock:
mapping of msgbuf during startup may map invalid physical adresses
Apply a similar patch as in the i386 case.
The amd64 version was supplied by Blair Sadewitz, thanks.
 1.44.2.3.6.1 12-Jun-2012  riz Pull up following revision(s) (requested by spz in ticket #1450):
sys/arch/amd64/amd64/machdep.c: revision 1.184
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.77
If the user process provided a bogus signal handler address, kill it
now instead of trying to jump to the bogus address.
 1.44.2.3.2.1 17-Nov-2007  skrll Back port of:

date: 2007/05/25 15:09:50; author: yamt; state: Exp; lines: +4 -6
dumpsys: build a fake switchframe for postmortem debugging.
reviewed by Frank van der Linden.

Unfortunately struct switchframe changed in -current so the crashdumps
aren't compatible. *sigh*
 1.47.2.6 17-May-2007  yamt sync with head.
 1.47.2.5 10-Apr-2007  ad Sync with i386.
 1.47.2.4 24-Mar-2007  yamt sync with head.
 1.47.2.3 12-Mar-2007  rmind Sync with HEAD.
 1.47.2.2 03-Mar-2007  yamt adapt amd64.

XXX changes in identcpu.c is minmum for MONITOR.
XXX identcpu.c should be shared with i386.
 1.47.2.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.52.6.1 29-Mar-2007  reinoud Pullup to -current
 1.52.4.1 11-Jul-2007  mjf Sync with head.
 1.52.2.12 03-Dec-2007  ad Sync with HEAD.
 1.52.2.11 03-Dec-2007  ad Sync with HEAD.
 1.52.2.10 01-Nov-2007  ad - Fix interactivity problems under high load. Beacuse soft interrupts
are being stacked on top of regular LWPs, more often than not aston()
was being called on a soft interrupt thread instead of a user thread,
meaning that preemption was not happening on EOI.

- Don't use bool in a couple of data structures. Sub-word writes are not
always atomic and may clobber other fields in the containing word.

- For SCHED_4BSD, make p_estcpu per thread (l_estcpu). Rework how the
dynamic priority level is calculated - it's much better behaved now.

- Kill the l_usrpri/l_priority split now that priorities are no longer
directly assigned by tsleep(). There are three fields describing LWP
priority:

l_priority: Dynamic priority calculated by the scheduler.
This does not change for kernel/realtime threads,
and always stays within the correct band. Eg for
timeshared LWPs it never moves out of the user
priority range. This is basically what l_usrpri
was before.

l_inheritedprio: Lent to the LWP due to priority inheritance
(turnstiles).

l_kpriority: A boolean value set true the first time an LWP
sleeps within the kernel. This indicates that the LWP
should get a priority boost as compensation for blocking.
lwp_eprio() now does the equivalent of sched_kpri() if
the flag is set. The flag is cleared in userret().

- Keep track of scheduling class (OTHER, FIFO, RR) in struct lwp, and use
this to make decisions in a few places where we previously tested for a
kernel thread.

- Partially fix itimers and usr/sys/intr time accounting in the presence
of software interrupts.

- Use kthread_create() to create idle LWPs. Move priority definitions
from the various modules into sys/param.h.

- newlwp -> lwp_create
 1.52.2.9 23-Oct-2007  ad Sync with head.
 1.52.2.8 10-Oct-2007  ad Share cpu_intr_p() between amd64/i386.
 1.52.2.7 09-Oct-2007  ad Sync with head.
 1.52.2.6 09-Oct-2007  ad Sync with head.
 1.52.2.5 23-Aug-2007  ad More calls to pmap_update().
 1.52.2.4 21-Aug-2007  ad amd64 changes, as yet untested:

- Adapt to vmlocking branch.
- Apply TLB shootdown and pv allocation changes to the pmap.
- Make it build.
 1.52.2.3 15-Jul-2007  ad Sync with head.
 1.52.2.2 27-May-2007  ad Sync with head.
 1.52.2.1 10-Apr-2007  ad Sync with head.
 1.53.4.3 03-Oct-2007  garbled Sync with HEAD
 1.53.4.2 26-Jun-2007  garbled Sync with HEAD.
 1.53.4.1 22-May-2007  matt Update to HEAD.
 1.60.10.3 23-Mar-2008  matt sync with HEAD
 1.60.10.2 09-Jan-2008  matt sync with HEAD
 1.60.10.1 06-Nov-2007  matt sync with HEAD
 1.60.8.13 09-Dec-2007  jmcneill Sync with HEAD.
 1.60.8.12 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.60.8.11 21-Nov-2007  joerg Sync with HEAD.
 1.60.8.10 14-Nov-2007  joerg Sync with HEAD.
 1.60.8.9 28-Oct-2007  joerg Sync with HEAD.
 1.60.8.8 28-Oct-2007  joerg Make the reset of FS/GS base in cpu_init_msrs optional. We don't want
that in the ACPI resume path.
 1.60.8.7 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.60.8.6 02-Oct-2007  joerg Sync with HEAD.
 1.60.8.5 08-Sep-2007  joerg Split init_x86_64 into smaller pieces and statically allocate low
memory pages for real mode use similiar to init386.
 1.60.8.4 08-Sep-2007  joerg Catch up with i386 and fix the build of GENERIC.
 1.60.8.3 08-Sep-2007  joerg Start to revamp the ACPI wake code (i386 only, amd64 gets minimal fixes
to keep being compilable):

- In init386 and the amd64 equivalent, just reserve the low-level code.
Do not map and don't copy the wakecode yet. This avoids the conflicts
with the MP tramp code as well. The wakecode is expected to be less
than one page long, which is way too much space.
acpi_md_get_npages_of_wakecode and acpi_md_install_wakecode are
dropped, acpi_wakeup_paddr is set instead of the reserved address.
- Split the wakecode into the essential low-level part to setup
protected mode with paging and valid CS and DS (which stays as
wakecode) and the rest. Inline beepon and beepoff as they are used
exactly once.
- Split the acpi_restorecpu and acpi_savecpu assembly from apci_wakeup.c
and merge acpi_restorecpu with the second half dropped from wakecode.
Most registers are not exported, just those needed to be patched into
wakecode. Don't bother to save or restore %eax, it is overriden
anyway.
- Don't bother to save and restore eflags in acpi_md_sleep, they are
handled correctly by the assembly. Don't play games with cr3 either,
we modify the pmap of the running processes. Copy the wakecode
directly before patching it, after the identity mapping has been
setup.
- Drop clear_reg and acpi_printcpu.
- Add an commented out broadcast IPI to halt the other CPUs explicitly.
 1.60.8.2 06-Sep-2007  jmcneill Add work-in-progress amd64 wakecode. Doesn't yet reach long mode..
 1.60.8.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.60.4.1 03-Sep-2007  skrll Sync with HEAD.
 1.61.2.3 07-Oct-2007  yamt rename PTDpaddr to PDPpaddr to match with i386.
(if you think it's a good idea to make gratuitous renames like this,
please do it for both of i386 and amd64 consistently.)
 1.61.2.2 06-Oct-2007  yamt sync with head.
 1.61.2.1 30-Sep-2007  yamt implement deferred pmap switching for amd64, and make amd64 use
x86 shared pmap code. it makes several i386 pmap improvements available
to amd64, including tlb shootdown reduction and bug fixes from Stephan Uphoff.
 1.62.2.10 22-Nov-2007  bouyer Disable debug messages
 1.62.2.9 21-Nov-2007  bouyer Sync with HEAD
 1.62.2.8 19-Nov-2007  bouyer On Xen, initialize cpu_feature here.
 1.62.2.7 16-Nov-2007  bouyer Initial domain0 support for xenamd64. The kernel boots multiuser, but
xen tools have not been tried yet.
In this process, cleanup some more the page table bootstrap, and properly
handle event counters for soft interrupts.
 1.62.2.6 13-Nov-2007  bouyer Sync with HEAD
 1.62.2.5 26-Oct-2007  bouyer Make amd64, i386 and xen kernels build and work again.
 1.62.2.4 25-Oct-2007  bouyer Sync with HEAD.
 1.62.2.3 21-Oct-2007  bouyer Factorise some Xen pmap code in x86_xpmap.c.
More xpmap_{ptom,mtop} -> xpmap_{ptom,mtop}_masked

The xenamd64 kernel is now good enough to complete a sysinst install from
xennet to xbd.
 1.62.2.2 20-Oct-2007  bouyer Xen handle %cs and %ss its own way. Don't check the values passed from
setmcontext, just reset them to sane values. This fixes signal handlers.
 1.62.2.1 17-Oct-2007  bouyer amd64 (aka x86-64) support for Xen. Based on the OpenBSD port done by
Mathieu Ropert in 2006.
DomU-only for now. An INSTALL_XEN3_DOMU kernel with a ramdisk will boot to
sysinst if you're lucky. Often it panics because a runable LWP has
a NULL stack (really, it's all of l->l_addr which is has been zeroed out
while the process was on the queue !)
TODO:
- bug fixes :)
- Most of the xpq_* functions should be shared with xen/i386
- The xen/i386 assembly bootstrap code should be remplaced with the C
version in xenamd64/amd64/xpmap.c
- see if a config(5) trick could allow to merge xenamd64 back to xen or amd64.
 1.65.2.4 18-Feb-2008  mjf Sync with HEAD.
 1.65.2.3 27-Dec-2007  mjf Sync with HEAD.
 1.65.2.2 08-Dec-2007  mjf Sync with HEAD.
 1.65.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.71.4.1 11-Dec-2007  yamt sync with head.
 1.71.2.1 26-Dec-2007  ad Sync with head.
 1.72.2.3 19-Jan-2008  bouyer Sync with HEAD
 1.72.2.2 08-Jan-2008  bouyer Sync with HEAD
 1.72.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.85.6.5 17-Jan-2009  mjf Sync with HEAD.
 1.85.6.4 28-Sep-2008  mjf Sync with HEAD.
 1.85.6.3 02-Jul-2008  mjf Sync with HEAD.
 1.85.6.2 29-Jun-2008  mjf Sync with HEAD.
 1.85.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.86.2.3 17-Jun-2008  yamt sync with head.
 1.86.2.2 04-Jun-2008  yamt sync with head
 1.86.2.1 18-May-2008  yamt sync with head.
 1.89.2.6 09-Oct-2010  yamt sync with head
 1.89.2.5 11-Aug-2010  yamt sync with head.
 1.89.2.4 11-Mar-2010  yamt sync with head
 1.89.2.3 19-Aug-2009  yamt sync with head.
 1.89.2.2 04-May-2009  yamt sync with head.
 1.89.2.1 16-May-2008  yamt sync with head.
 1.92.2.7 28-Sep-2008  skrll Adapt the SA COMPAT_NETBSD32 stuff to this branch.
 1.92.2.6 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.92.2.5 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.92.2.4 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.92.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.92.2.2 14-May-2008  wrstuden Per discussion with ad at n dot o, revert signal mask handling
changes.

The l_sigstk changes are most likely totally un-needed as SA will
never use a signal stack - we send an upcall (or will as other
diffs are brought in).

The l_sigmask changes were too controvertial. In all honesty, I
think it's probably best to revert them. The main reason they were
there is the fact that in an SA process, we don't mask signals per
kernel thread, we mask them per user thread. In the kernel, we want
them all to get turned into upcalls. Thus the normal state of
l_sigmask in an SA process is for it to always be empty.

While we are in the process of delivering a signal, we want to
temporarily mask a signal (so we don't recursively exhaust our
upcall stacks). However signal delivery is rare (important, but
rare), and delivering back-to-back signals is even rarer. So rather
than cause every user of a signal mask to be prepared for this very
rare case, we will just add a second check later in the signal
delivery code. Said change is not in this diff.

This also un-compensates all of our compatability code for dealing
with SA. SA is a NetBSD-specific thing, so there's no need for
Irix, Linux, Solaris, SVR4 and so on to cope with it.

As previously, everything other than kern_sa.c compiles in i386
GENERIC as of this checkin. I will switch to ALL soon for compile
testing.
 1.92.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.95.2.1 03-Jul-2008  simonb Sync with head.
 1.97.2.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.97.2.1 19-Oct-2008  haad Sync with HEAD.
 1.102.4.14 12-Jun-2012  riz Pull up following revision(s) (requested by spz in ticket #1773):
sys/arch/amd64/amd64/machdep.c: revision 1.184
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.77
If the user process provided a bogus signal handler address, kill it
now instead of trying to jump to the bogus address.
 1.102.4.13 22-Apr-2010  snj branches: 1.102.4.13.2;
Apply patch (requested by jym in ticket #1380):
Fix the NX regression issue observed on amd64 kernels, where per-page
execution right was disabled (therefore leading to the inability
of the kernel to detect fraudulent use of memory mappings marked as not
being executable).
 1.102.4.12 01-Dec-2009  snj Apply patch (requested by bouyer in ticket 1158):
On amd64, add a third free list distinct from the default free list, holding
RAM between 16Mb and 4Gb. This helps preventing bus_dma(9) memory
allocation failures for 32bit DMA on large-memory machines.
 1.102.4.11 03-Oct-2009  snj Pull up following revision(s) (requested by bouyer in ticket #1054):
sys/arch/amd64/amd64/machdep.c: revision 1.124
sys/arch/i386/i386/machdep.c: revision 1.660
Prepare for PCI frontend support in Xen3 domUs:
call x86_bus_space_init() and x86_bus_space_mallocok() if we have ISA or PCI
devices configured; not only for non-Xen or dom0 Xen
On Xen, always call PHYSDEVOP_SET_IOPL on context switch
on amd64, also call PHYSDEVOP_SET_IOPL from x86_64_proc0_tss_ldt_init()
 1.102.4.10 04-Apr-2009  snj branches: 1.102.4.10.2; 1.102.4.10.4;
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.102.4.9 02-Mar-2009  snj Pull up following revision(s) (requested by jmcneill in ticket #526):
sys/arch/amd64/amd64/machdep.c: revision 1.128
sys/arch/i386/i386/machdep.c: revision 1.663
PR# port-i386/40751: power button does not work after halt
PR# kern/37506: Have to hold power button for 5 seconds to turn off Laptop
after "halt" command.
Transfer the system from ACPI to Legacy mode if RB_HALT is set.
 1.102.4.8 02-Feb-2009  snj Pull up following revision(s) (requested by ad in ticket #396):
sys/arch/amd64/amd64/machdep.c: revision 1.123
remove extra variable
 1.102.4.7 02-Feb-2009  snj Pull up following revision(s) (requested by ad in ticket #396):
sys/arch/amd64/amd64/machdep.c: revision 1.122
sys/arch/i386/i386/machdep.c: revision 1.657
sys/arch/x86/include/cpufunc.h: revision 1.11
sys/arch/x86/x86/x86_machdep.c: revision 1.28
factor out common reset code.
 1.102.4.6 02-Feb-2009  snj Pull up following revision(s) (requested by ad in ticket #396):
sys/arch/amd64/amd64/machdep.c: revision 1.121
sys/arch/i386/i386/machdep.c: revision 1.656
Make previous compile.
 1.102.4.5 02-Feb-2009  snj Pull up following revision(s) (requested by ad in ticket #396):
sys/arch/amd64/amd64/machdep.c: revision 1.120
Attempt to force resets using two more methods:
1. Reset Control register at I/O port 0xcf9
2. Fast A20 and Init register at I/O port 0x92
Requested by ad@
 1.102.4.4 20-Nov-2008  snj Pull up following revision(s) (requested by ad in ticket #71):
sys/arch/i386/isa/npx.c: revision 1.132
sys/arch/amd64/amd64/fpu.c: revision 1.29
sys/arch/amd64/amd64/machdep.c: revision 1.105
sys/arch/i386/i386/machdep.c: revision 1.647
PR port-i386/39299 FPU use in signal handlers is unsafe
 1.102.4.3 18-Nov-2008  snj Pull up following revision(s) (requested by cegger in ticket #51):
sys/arch/amd64/amd64/machdep.c: revision 1.107
reduce diff to i386/i386/machdep.c:init386()
- introduce add_mem_cluster() as done in i386
- apply rev. 1.480 from i386/i386/machdep.c: fixes PR 17199 for amd64
- apply rev. 1.492 from i386/i386/machdep.c: fixes PR 13399 for amd64
 1.102.4.2 18-Nov-2008  snj Pull up following revision(s) (requested by cegger in ticket #51):
sys/arch/amd64/amd64/machdep.c: revision 1.106
cosmetic change (mostly to reduce diff to i386/i386/machdep.c:initi386):
use PRIx64 rather %qx
No functional changes intended.
 1.102.4.1 17-Nov-2008  snj Pull up following revision(s) (requested by ad in ticket #74):
sys/arch/i386/isa/npx.c: revision 1.131
sys/arch/amd64/amd64/fpu.c: revision 1.28
sys/arch/i386/i386/genassym.cf: revision 1.77
sys/arch/i386/i386/autoconf.c: revision 1.93
sys/arch/amd64/amd64/locore.S: revision 1.48
sys/arch/amd64/amd64/machdep.c: revision 1.104
sys/arch/i386/i386/machdep.c: revision 1.646
sys/arch/amd64/amd64/genassym.cf: revision 1.38
sys/arch/i386/i386/locore.S: revision 1.79
PR port-amd64/38293 panic: fp_save ipi didn't
Fix race conditions in FPU IPI handling.
 1.102.4.13.2.1 12-Jun-2012  riz Pull up following revision(s) (requested by spz in ticket #1773):
sys/arch/amd64/amd64/machdep.c: revision 1.184
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.77
If the user process provided a bogus signal handler address, kill it
now instead of trying to jump to the bogus address.
 1.102.4.10.4.2 20-May-2011  matt bring matt-nb5-mips64 up to date with netbsd-5-1-RELEASE (except compat).
 1.102.4.10.4.1 21-Apr-2010  matt sync to netbsd-5
 1.102.4.10.2.2 12-Jun-2012  riz Pull up following revision(s) (requested by spz in ticket #1773):
sys/arch/amd64/amd64/machdep.c: revision 1.184
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.77
If the user process provided a bogus signal handler address, kill it
now instead of trying to jump to the bogus address.
 1.102.4.10.2.1 23-Apr-2010  snj Apply patch (requested by jym in ticket #1380):
Fix the NX regression issue observed on amd64 kernels, where per-page
execution right was disabled (therefore leading to the inability
of the kernel to detect fraudulent use of memory mappings marked as not
being executable).
 1.102.2.3 28-Apr-2009  skrll Sync with HEAD.
 1.102.2.2 03-Mar-2009  skrll Sync with HEAD.
 1.102.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.115.2.3 04-Jan-2009  christos merge diffs.
 1.115.2.2 30-Dec-2008  christos dev_t format
 1.115.2.1 18-Dec-2008  christos file machdep.c was added on branch christos-time_t on 2008-12-30 19:38:39 +0000
 1.123.2.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.123.2.5 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.123.2.4 10-Jan-2011  jym Sync with HEAD
 1.123.2.3 24-Oct-2010  jym Sync with HEAD
 1.123.2.2 01-Nov-2009  jym Sync with HEAD.
 1.123.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.141.2.7 10-Nov-2010  uebayasi Fix thinko; make vm_physseg ptr swap really work.
 1.141.2.6 10-Nov-2010  uebayasi Always use VM_PHYSMEM_PTR().
 1.141.2.5 06-Nov-2010  uebayasi Sync with HEAD.
 1.141.2.4 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.141.2.3 17-Aug-2010  uebayasi Sync with HEAD.
 1.141.2.2 30-Apr-2010  uebayasi Sync with HEAD.
 1.141.2.1 28-Apr-2010  uebayasi Always use struct vm_physseg *vm_physmem_ptrs[] in MD code.
 1.143.2.4 05-Mar-2011  rmind sync with head
 1.143.2.3 30-May-2010  rmind sync with head
 1.143.2.2 25-Apr-2010  rmind - Invent mm_md_getva() and mm_md_relva() routines, provided by MD and
indicated with __HAVE_MM_MD_PREFER_VA. It will be used to deal with
cache aliasing issues and thus fix little MIPS, ARM and friends.

- Convert dev_mem_readwrite() to use unmanaged mappings. Fix a missed
offset addition in a case of direct map. Sprinkle various comments in
the memory device driver.

- Add missing direct map handling on hp700 and vax. Make checks across
m68k ports more consistent, reduce the diffs. Fix kernacc check miss
on news68k. Minor off-by-one fix for alpha. Add MEMC_PHYS_BASE for
mmap() case check on acorn26. Misc clean-up.
 1.143.2.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.158.4.1 05-Mar-2011  bouyer Sync with HEAD
 1.158.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.160.2.3 20-Aug-2011  cherry PAE MP support (preliminary), amd64 per-cpu L4 model redesigned, i386 pmap_pa_start/end fixup
 1.160.2.2 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.160.2.1 03-Jun-2011  cherry Initial import of xen MP sources, with kernel and userspace tests.
- this is a source priview.
- boots to single user.
- spurious interrupt and pmap related panics are normal
 1.168.2.7 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.168.2.6 23-Jan-2013  yamt sync with head
 1.168.2.5 16-Jan-2013  yamt sync with (a bit old) head
 1.168.2.4 30-Oct-2012  yamt sync with head
 1.168.2.3 23-May-2012  yamt sync with head.
 1.168.2.2 17-Apr-2012  yamt sync with head
 1.168.2.1 10-Nov-2011  yamt sync with head
 1.171.2.7 02-Jun-2012  mrg sync to latest -current.
 1.171.2.6 29-Apr-2012  mrg sync to latest -current.
 1.171.2.5 06-Mar-2012  mrg sync to -current
 1.171.2.4 06-Mar-2012  mrg sync to -current
 1.171.2.3 04-Mar-2012  mrg sync to latest -current.
 1.171.2.2 24-Feb-2012  mrg sync to -current.
 1.171.2.1 18-Feb-2012  mrg merge to -current.
 1.175.2.10 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.175.2.9 08-Aug-2017  martin Pull up following revision(s) (requested by maxv in ticket #1464):

sys/arch/i386/i386/trap.c: revision 1.288 (patch)
sys/arch/i386/i386/machdep.c: revision 1.783 (patch)
sys/arch/i386/i386/locore.S: revision 1.146 (patch)
sys/arch/amd64/amd64/locore.S: revision 1.122,1.124 (patch)
sys/arch/amd64/amd64/machdep.c revision 1.254 (patch)
sys/arch/amd64/amd64/trap.c: revision 1.95-1.96 (patch)

Remove the osyscall call gate and emulate it. There is a
one-instruction race in it that could panic the kernel.

Restore the ability to run netbsd 1.0 32-bit executables by checking
for the relevant lcall instruction in the trap handler and treating it
as a syscall.
 1.175.2.8 20-Apr-2013  bouyer branches: 1.175.2.8.2;
Pull up following revision(s) (requested by taca in ticket #866):
sys/arch/amd64/amd64/machdep.c: revision 1.193
Use printf_nolog() as i386 when print remaing bytes at crash dump to
prevent message buffer with cound down.
 1.175.2.7 03-Sep-2012  riz branches: 1.175.2.7.2;
Pull up following revision(s) (requested by cherry in ticket #539):
sys/arch/amd64/amd64/machdep.c: revision 1.190
Revert to unmanaged x86 memory mapped isa and pci space.
This is a revert of commit r1.169:
http://mail-index.netbsd.org/source-changes/2011/11/06/msg028702.html
This should allow X to run on NetBSD/xen amd64 dom0, and fixes PR #46634
 1.175.2.6 12-Jun-2012  riz branches: 1.175.2.6.2;
Pull up following revision(s) (requested by spz in ticket #337):
sys/arch/amd64/amd64/machdep.c: revision 1.184
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.77
If the user process provided a bogus signal handler address, kill it
now instead of trying to jump to the bogus address.
 1.175.2.5 21-May-2012  riz Pull up following revision(s) (requested by martin in ticket #274):
sys/arch/amd64/amd64/process_machdep.c: revision 1.20
sys/kern/sys_lwp.c: revision 1.54
sys/arch/sparc64/sparc64/machdep.c: revision 1.267
sys/arch/mips/mips/cpu_subr.c: revision 1.16
sys/arch/vax/vax/machdep.c: revision 1.188
sys/sys/lwp.h: revision 1.161
sys/arch/sparc64/sparc64/netbsd32_machdep.c: revision 1.98
sys/arch/alpha/alpha/machdep.c: revision 1.339
sys/compat/sys/ucontext.h: revision 1.6
sys/arch/hppa/hppa/hppa_machdep.c: revision 1.28
distrib/sets/lists/tests/mi: revision 1.469
sys/arch/powerpc/powerpc/sig_machdep.c: revision 1.42
tests/lib/libc/sys/t_lwp_create.c: revision 1.1
tests/lib/libc/sys/Makefile: revision 1.23
sys/arch/arm/arm/sig_machdep.c: revision 1.42
sys/arch/amd64/include/mcontext.h: revision 1.15
sys/arch/amd64/amd64/machdep.c: revision 1.183
sys/arch/sh3/sh3/sh3_machdep.c: revision 1.99
sys/arch/i386/i386/machdep.c: revision 1.727
sys/compat/netbsd32/netbsd32_lwp.c: revision 1.13
sys/arch/sparc/sparc/machdep.c: revision 1.319
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.76
sys/arch/m68k/m68k/sig_machdep.c: revision 1.49
sys/sys/ucontext.h: revision 1.16
sys/arch/mips/mips/netbsd32_machdep.c: revision 1.9
lib/libc/sys/_lwp_create.2: revision 1.5
Calling _lwp_create() with a bogus ucontext could trigger a kernel
assertion failure (and thus a crash in DIAGNOSTIC kernels). Independently
discovered by YAMAMOTO Takashi and Joel Sing.
To avoid this, introduce a cpu_mcontext_validate() function and move all
sanity checks from cpu_setmcontext() there. Also untangle the netbsd32
compat mess slightly and add a cpu_mcontext32_validate() cousin there.
Add an exhaustive atf test case, based partly on code from Joel Sing.
Should finally fix the remaining open part of PR kern/43903.
 1.175.2.4 07-May-2012  riz Pull up following revision(s) (requested by christos in ticket #212):
sys/arch/amd64/amd64/machdep.c: revision 1.181
Fix check_mcontext for PK_32 binaries. Makes gdb work for i386 binaries on
amd64.
 1.175.2.3 22-Mar-2012  riz Pull up following revision(s) (requested by mrg in ticket #126):
sys/arch/amd64/amd64/machdep.c: revision 1.180
sys/arch/i386/i386/machdep.c: revision 1.724
make i386 and amd64 cpu_reboot() more similar. in particular, bring
in the unmount/sync code from i386 to amd64, and call doshutdownhooks()
for i386. the amd64 changes avoid umass triggering an assert later
when sd@umass is trying to sync the cache.
XXX merge x86 cpu_reboot(), but there's non-trivially different still.
 1.175.2.2 05-Mar-2012  sborrill Pull up the following revisions(s) (requested by bouyer in ticket #80):
sys/arch/xen/x86/x86_xpmap.c: revision 1.42
sys/arch/x86/include/specialreg.h: revision 1.56
sys/arch/amd64/amd64/machdep.c: revision 1.179
sys/arch/i386/i386/locore.S: revision 1.97
sys/arch/i386/i386/machdep.c: revision 1.723 via patch
sys/arch/x86/include/cpu.h: revision 1.49

Fix possible FPU registers corruption on context switches.
Fix type of pointers passed to some hypercalls.
 1.175.2.1 23-Feb-2012  riz Pull up following revision(s) (requested by chs in ticket #38):
sys/arch/amd64/amd64/machdep.c: revision 1.178
sys/arch/x86/x86/identcpu.c: revision 1.30
sys/arch/i386/i386/machdep.c: revision 1.720
move XEN CPU feature masking into cpu_probe() so that it's applied
to all CPUs, not just the boot CPU.
 1.175.2.8.2.2 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.175.2.8.2.1 08-Aug-2017  martin Pull up following revision(s) (requested by maxv in ticket #1464):

sys/arch/i386/i386/trap.c: revision 1.288 (patch)
sys/arch/i386/i386/machdep.c: revision 1.783 (patch)
sys/arch/i386/i386/locore.S: revision 1.146 (patch)
sys/arch/amd64/amd64/locore.S: revision 1.122,1.124 (patch)
sys/arch/amd64/amd64/machdep.c revision 1.254 (patch)
sys/arch/amd64/amd64/trap.c: revision 1.95-1.96 (patch)

Remove the osyscall call gate and emulate it. There is a
one-instruction race in it that could panic the kernel.

Restore the ability to run netbsd 1.0 32-bit executables by checking
for the relevant lcall instruction in the trap handler and treating it
as a syscall.
 1.175.2.7.2.3 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.175.2.7.2.2 08-Aug-2017  martin Pull up following revision(s) (requested by maxv in ticket #1464):

sys/arch/i386/i386/trap.c: revision 1.288 (patch)
sys/arch/i386/i386/machdep.c: revision 1.783 (patch)
sys/arch/i386/i386/locore.S: revision 1.146 (patch)
sys/arch/amd64/amd64/locore.S: revision 1.122,1.124 (patch)
sys/arch/amd64/amd64/machdep.c revision 1.254 (patch)
sys/arch/amd64/amd64/trap.c: revision 1.95-1.96 (patch)

Remove the osyscall call gate and emulate it. There is a
one-instruction race in it that could panic the kernel.

Restore the ability to run netbsd 1.0 32-bit executables by checking
for the relevant lcall instruction in the trap handler and treating it
as a syscall.
 1.175.2.7.2.1 20-Apr-2013  bouyer Pull up following revision(s) (requested by taca in ticket #866):
sys/arch/amd64/amd64/machdep.c: revision 1.193
Use printf_nolog() as i386 when print remaing bytes at crash dump to
prevent message buffer with cound down.
 1.175.2.6.2.1 01-Nov-2012  matt sync with netbsd-6-0-RELEASE.
 1.190.2.5 03-Dec-2017  jdolecek update from HEAD
 1.190.2.4 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.190.2.3 23-Jun-2013  tls resync from head
 1.190.2.2 25-Feb-2013  tls resync with head
 1.190.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.195.2.1 18-May-2014  rmind sync with head
 1.207.2.1 10-Aug-2014  tls Rebase.
 1.211.10.3 04-Dec-2018  martin Pull up following revision(s) (requested by maxv in ticket #1662):

sys/arch/amd64/amd64/machdep.c: revision 1.321

Fix stack info leak. There is a big padding in struct sigframe_siginfo.

[ 224.006287] kleak: Possible leak in copyout: [len=920, leaked=92]
[ 224.016977] #0 0xffffffff80224d0a in kleak_note <netbsd>
[ 224.026268] #1 0xffffffff80224d8a in kleak_copyout <netbsd>
[ 224.026268] #2 0xffffffff802224b5 in sendsig_siginfo <netbsd>
[ 224.036261] #3 0xffffffff80b51564 in sendsig <netbsd>
[ 224.046475] #4 0xffffffff80b51282 in postsig <netbsd>
[ 224.046475] #5 0xffffffff80b2fc5d in lwp_userret <netbsd>
[ 224.056273] #6 0xffffffff8025a951 in mi_userret <netbsd>
[ 224.066277] #7 0xffffffff8025ab89 in syscall <netbsd>
 1.211.10.2 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.211.10.1 26-Apr-2017  martin Pull up following revision(s) (requested by bsiegert in ticket #1397):

sys/arch/amd64/amd64/locore.S 1.122 (via patch)
sys/arch/amd64/amd64/machdep.c 1.254 (via patch)
sys/arch/amd64/amd64/trap.c 1.95 (via patch)

Remove the call gate on amd64, it is useless and vulnerable.
 1.211.6.3 04-Dec-2018  martin Pull up following revision(s) (requested by maxv in ticket #1662):

sys/arch/amd64/amd64/machdep.c: revision 1.321

Fix stack info leak. There is a big padding in struct sigframe_siginfo.

[ 224.006287] kleak: Possible leak in copyout: [len=920, leaked=92]
[ 224.016977] #0 0xffffffff80224d0a in kleak_note <netbsd>
[ 224.026268] #1 0xffffffff80224d8a in kleak_copyout <netbsd>
[ 224.026268] #2 0xffffffff802224b5 in sendsig_siginfo <netbsd>
[ 224.036261] #3 0xffffffff80b51564 in sendsig <netbsd>
[ 224.046475] #4 0xffffffff80b51282 in postsig <netbsd>
[ 224.046475] #5 0xffffffff80b2fc5d in lwp_userret <netbsd>
[ 224.056273] #6 0xffffffff8025a951 in mi_userret <netbsd>
[ 224.066277] #7 0xffffffff8025ab89 in syscall <netbsd>
 1.211.6.2 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.211.6.1 26-Apr-2017  martin Pull up following revision(s) (requested by bsiegert in ticket #1397):

sys/arch/amd64/amd64/locore.S 1.122 (via patch)
sys/arch/amd64/amd64/machdep.c 1.254 (via patch)
sys/arch/amd64/amd64/trap.c 1.95 (via patch)

Remove the call gate on amd64, it is useless and vulnerable.
 1.211.4.10 28-Aug-2017  skrll Sync with HEAD
 1.211.4.9 05-Feb-2017  skrll Sync with HEAD
 1.211.4.8 05-Dec-2016  skrll Sync with HEAD
 1.211.4.7 05-Oct-2016  skrll Sync with HEAD
 1.211.4.6 09-Jul-2016  skrll Sync with HEAD
 1.211.4.5 29-May-2016  skrll Sync with HEAD
 1.211.4.4 19-Mar-2016  skrll Sync with HEAD
 1.211.4.3 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.211.4.2 22-Sep-2015  skrll Sync with HEAD
 1.211.4.1 06-Jun-2015  skrll Sync with HEAD
 1.211.2.3 04-Dec-2018  martin Pull up following revision(s) (requested by maxv in ticket #1662):

sys/arch/amd64/amd64/machdep.c: revision 1.321

Fix stack info leak. There is a big padding in struct sigframe_siginfo.

[ 224.006287] kleak: Possible leak in copyout: [len=920, leaked=92]
[ 224.016977] #0 0xffffffff80224d0a in kleak_note <netbsd>
[ 224.026268] #1 0xffffffff80224d8a in kleak_copyout <netbsd>
[ 224.026268] #2 0xffffffff802224b5 in sendsig_siginfo <netbsd>
[ 224.036261] #3 0xffffffff80b51564 in sendsig <netbsd>
[ 224.046475] #4 0xffffffff80b51282 in postsig <netbsd>
[ 224.046475] #5 0xffffffff80b2fc5d in lwp_userret <netbsd>
[ 224.056273] #6 0xffffffff8025a951 in mi_userret <netbsd>
[ 224.066277] #7 0xffffffff8025ab89 in syscall <netbsd>
 1.211.2.2 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.211.2.1 26-Apr-2017  martin Pull up following revision(s) (requested by bsiegert in ticket #1397):

sys/arch/amd64/amd64/locore.S 1.122 (via patch)
sys/arch/amd64/amd64/machdep.c 1.254 (via patch)
sys/arch/amd64/amd64/trap.c 1.95 (via patch)

Remove the call gate on amd64, it is useless and vulnerable.
 1.223.2.5 26-Apr-2017  pgoyette Sync with HEAD
 1.223.2.4 20-Mar-2017  pgoyette Sync with HEAD
 1.223.2.3 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.223.2.2 26-Jul-2016  pgoyette Sync with HEAD
 1.223.2.1 20-Jul-2016  pgoyette Adapt the machine/arch dependent code to the new {b,c}devsw reference
counting.

XXX Most of these will require testing by someone other than myself, as
I have a limited selection of hardware!
 1.246.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.255.6.9 05-Apr-2019  martin Pull up following revision(s) (requested by maxv):

sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.120
sys/compat/linux/arch/amd64/linux_machdep.c: revision 1.57
sys/compat/linux32/arch/amd64/linux32_machdep.c: revision 1.44
sys/arch/amd64/amd64/machdep.c: revision 1.328
sys/arch/amd64/amd64/machdep.c: revision 1.329

Fix a tiny race in setregs and linux_setregs. Between the moment we set
pcb_flags to zero, and the moment cpu_segregs64_zero resets pcb_gs, we may
be preempted.

If this happens, and if the calling LWP was a 32bit thread, when switching
back to that LWP, the context switcher sees that PCB_COMPAT32 is not set in
pcb_flags and tries to perform a 64bit context switch; but pcb_gs contains
a 32bit GDT descriptor, and not a 64bit GS.base value. The wrmsr therefore
faults because the value is non-canonical, and this fault is fatal.

Rearrange the code so that the update of pcb_flags and pcb_gs/pcb_fs is non
interruptible. This fixes the problem, tested with a reproducer (which
therefore doesn't work anymore).

Likely fixes PR/53993.

Disable preemption when setting PCB_COMPAT32, to prevent a context switch
before cpu_fsgs_reload() finishes, otherwise we write garbage in the GDT.

On NetBSD-current it is harmless, however in NetBSD-8 it might cause
panics, because NetBSD-8 uses the old SegRegs model and under this model
we reload %fs and %gs during switches.
 1.255.6.8 29-Nov-2018  martin Pull up following revision(s) (requested by maxv in ticket #1111):

sys/arch/amd64/amd64/machdep.c: revision 1.321

Fix stack info leak. There is a big padding in struct sigframe_siginfo.

[ 224.006287] kleak: Possible leak in copyout: [len=920, leaked=92]
[ 224.016977] #0 0xffffffff80224d0a in kleak_note <netbsd>
[ 224.026268] #1 0xffffffff80224d8a in kleak_copyout <netbsd>
[ 224.026268] #2 0xffffffff802224b5 in sendsig_siginfo <netbsd>
[ 224.036261] #3 0xffffffff80b51564 in sendsig <netbsd>
[ 224.046475] #4 0xffffffff80b51282 in postsig <netbsd>
[ 224.046475] #5 0xffffffff80b2fc5d in lwp_userret <netbsd>
[ 224.056273] #6 0xffffffff8025a951 in mi_userret <netbsd>
[ 224.066277] #7 0xffffffff8025ab89 in syscall <netbsd>
 1.255.6.7 09-Jun-2018  martin Pullup the following revisions, requested by maxv in ticket #865:

sys/arch/amd64/amd64/machdep.c 1.303 (patch)
sys/arch/amd64/conf/GENERIC 1.492 (patch)
sys/arch/amd64/conf/files.amd64 1.103 (patch)
sys/arch/i386/i386/machdep.c 1.806 (patch)
sys/arch/i386/conf/GENERIC 1.1179 (patch)
sys/arch/i386/conf/files.i386 1.393 (patch)
sys/arch/x86/include/cpu.h 1.91 (patch)
sys/arch/x86/include/specialreg.h upto 1.126 (patch)
sys/arch/x86/x86/x86_machdep.c upto 1.115 (patch, adapted)
sys/arch/x86/x86/spectre.c upto 1.19 (patch, adapted,
no IBRS,
SpectreV2 mitigations not
enabled by default)

Backport the hardware SpectreV2 and SpectreV4 mitigations.
 1.255.6.6 22-Mar-2018  martin Pull up the following revisions, requested by maxv in ticket #652:

sys/arch/amd64/amd64/amd64_trap.S upto 1.39 (partial, patch)
sys/arch/amd64/amd64/db_machdep.c 1.6 (patch)
sys/arch/amd64/amd64/genassym.cf 1.65,1.66,1.67 (patch)
sys/arch/amd64/amd64/locore.S upto 1.159 (partial, patch)
sys/arch/amd64/amd64/machdep.c 1.299-1.302 (patch)
sys/arch/amd64/amd64/trap.c upto 1.113 (partial, patch)
sys/arch/amd64/amd64/amd64/vector.S upto 1.61 (partial, patch)
sys/arch/amd64/conf/GENERIC 1.477,1.478 (patch)
sys/arch/amd64/conf/kern.ldscript 1.26 (patch)
sys/arch/amd64/include/frameasm.h upto 1.37 (partial, patch)
sys/arch/amd64/include/param.h 1.25 (patch)
sys/arch/amd64/include/pmap.h 1.41,1.43,1.44 (patch)
sys/arch/x86/conf/files.x86 1.91,1.93 (patch)
sys/arch/x86/include/cpu.h 1.88,1.89 (patch)
sys/arch/x86/include/pmap.h 1.75 (patch)
sys/arch/x86/x86/cpu.c 1.144,1.146,1.148,1.149 (patch)
sys/arch/x86/x86/pmap.c upto 1.289 (partial, patch)
sys/arch/x86/x86/vm_machdep.c 1.31,1.32 (patch)
sys/arch/x86/x86/x86_machdep.c 1.104,1.106,1.108 (patch)
sys/arch/x86/x86/svs.c 1.1-1.14
sys/arch/xen/conf/files.compat 1.30 (patch)

Backport SVS. Not enabled yet.
 1.255.6.5 16-Mar-2018  martin Pull up the following revisions (via patch), requested by maxv in #635:

sys/arch/amd64/amd64/gdt.c 1.39-1.45 (patch)
sys/arch/amd64/amd64/amd64/machdep.c 1.284,1.287,1.288 (patch)
sys/arch/amd64/amd64/include/param.h 1.23 (patch)
sys/arch/amd64/include/types.h 1.53 (patch)
sys/arch/x86/include/cpu.h 1.87 (patch)
sys/arch/x86/include/pmap.h 1.73,1.74 (patch)
sys/arch/x86/x86/cpu.c 1.142 (patch)
sys/arch/x86/x86/intr.c 1.117 (partial),1.120 (patch)
sys/arch/x86/x86/pmap.c 1.276 (patch)

Initialize ist0 in cpu_init_tss.
Backport __HAVE_PCPU_AREA.
 1.255.6.4 13-Mar-2018  martin Pullup the following revisions via patch, requested by maxv in ticket #629:

sys/arch/amd64/amd64/genassym.cf 1.63,1.64
sys/arch/amd64/amd64/locore.S 1.144
sys/arch/amd64/amd64/machdep.c 1.281-1.283
sys/arch/i386/i386/genassym.cf 1.105-1.106
sys/arch/i386/i386/locore.S 1.155
sys/arch/i386/i386/machdep.c 1.802 (adapted),1.803
sys/arch/x86/include/cpu.h 1.85
sys/arch/x86/x86/intr.c 1.115-1.116
sys/arch/x86/x86/pmap.c 1.275
sys/arch/x86/x86/sys_machdep.c 1.45
sys/arch/xen/x86/cpu.c 1.117

Stop sharing the double-fault stack.
Merge the TSS structures into one single cpu_tss structure, and
allocate it dynamically.
 1.255.6.3 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.255.6.2 30-Nov-2017  martin Pull up following revision(s) (requested by maxv in ticket #401):
sys/arch/amd64/amd64/machdep.c: revision 1.267
Mmh, don't forget to clear the TLS gdt slots on Xen. Otherwise, when doing
a lwp32->lwp64 context switch, the new lwp can use the slots to reconstruct
the address of the previous lwp's TLS space (and defeat ASLR?).
 1.255.6.1 04-Sep-2017  snj Pull up following revision(s) (requested by maxv in ticket #257):
sys/compat/linux/arch/amd64/linux_machdep.c: 1.52
sys/arch/amd64/amd64/copy.S: 1.21-1.24
sys/arch/amd64/amd64/locore.S: 1.125
sys/arch/amd64/amd64/machdep.c: 1.256
Fix a bug in ucas_32 and ucas_64. There is a branch where they don't
initialize %rax.
--
style, reduces an incoming diff
00
Split comment, otherwise it is misleading. kcopy operates on kernel
memory, and must *not* be used with userland pages.
--
Move incq outside of the copy section. No functional change, reduces
my smap diff.
--
Remove dumb debug code and outdated comment.
--
Don't forget to clean l_md.md_flags, otherwise there may be MDL_COMPAT32,
in which case the kernel would always use iret (slower).
 1.255.4.1 27-Apr-2017  pgoyette Restore all work from the former pgoyette-localcount branch (which is
now abandoned doe to cvs merge botch).

The branch now builds, and installs via anita. There are still some
problems (cgd is non-functional and all atf tests time-out) but they
will get resolved soon.
 1.301.2.9 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.301.2.8 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.301.2.7 30-Sep-2018  pgoyette Ssync with HEAD
 1.301.2.6 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.301.2.5 28-Jul-2018  pgoyette Sync with HEAD
 1.301.2.4 25-Jun-2018  pgoyette Sync with HEAD
 1.301.2.3 21-May-2018  pgoyette Sync with HEAD
 1.301.2.2 07-Apr-2018  pgoyette Sync with HEAD. 77 conflicts resolved - all of them $NetBSD$
 1.301.2.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.305.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.305.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.305.2.1 10-Jun-2019  christos Sync with HEAD
 1.335.2.1 29-Apr-2020  martin Pull up following revision(s) (requested by jmcneill in ticket #868):

sys/arch/x86/x86/pmap.c: revision 1.384
sys/arch/amd64/amd64/machdep.c: revision 1.349

Detect PAT on the boot processor before cpu0 attaches so the early genfb
attach code can map the framebuffer with write combining.
 1.344.2.2 29-Feb-2020  ad Sync with head.
 1.344.2.1 17-Jan-2020  ad Sync with head.
 1.346.4.4 25-Apr-2020  bouyer Sync with bouyer-xenpvh-base2 (HEAD)
 1.346.4.3 18-Apr-2020  bouyer Centralize initialisations of delay_func and initclock_func
in x86_machdep.c and export from <x86/machdep.h>
Introduce a x86_dummy_initclock() and a x86_cpu_initclock_func pointer,
to be used later for Xen HVM native clock support.
rename rtclock_tval to x86_rtclock_tval and export from <x86/machdep.h>,
for the benefit of lapic.c
 1.346.4.2 16-Apr-2020  bouyer More #ifndef XEN -> #ifndef XENPV
 1.346.4.1 09-Apr-2020  bouyer For RB_POWERDONW, call HYPERVISOR_shutdown() in all cases where the
hypercall page is available. A PVHHVM domU now properly exits on
halt -p
 1.357.2.1 03-Apr-2021  thorpej Sync with HEAD.
 1.366.2.1 29-Mar-2025  martin Pull up following revision(s) (requested by imil in ticket #1074):

sys/arch/x86/x86/x86_machdep.c: revision 1.155
sys/arch/x86/include/cpu.h: revision 1.137
sys/arch/x86/x86/x86_machdep.c: revision 1.156
sys/arch/x86/include/cpu.h: revision 1.138
sys/arch/x86/x86/consinit.c: revision 1.40
sys/arch/x86/acpi/acpi_machdep.c: revision 1.37
sys/arch/x86/acpi/acpi_machdep.c: revision 1.38
sys/arch/amd64/amd64/machdep.c: revision 1.370
sys/arch/xen/xen/hypervisor.c: revision 1.97
sys/arch/xen/xen/hypervisor.c: revision 1.98
sys/arch/amd64/amd64/genassym.cf: revision 1.98
sys/arch/x86/x86/x86_autoconf.c: revision 1.88
sys/arch/x86/x86/x86_autoconf.c: revision 1.89
sys/arch/amd64/amd64/locore.S: revision 1.226
sys/arch/amd64/amd64/locore.S: revision 1.227
sys/arch/x86/x86/identcpu.c: revision 1.131

Add support for non-Xen PVH guests to amd64. Patch from
Emile 'iMil' Heitor in PR kern/57813, with some cosmetic tweaks by me.
Tested on bare metal, Xen PV and Xen PVH by me.

Get one more change from PR kern/57813, needed for non-Xen PVH.

Introduce vm_guest_is_pvh() and use it in place of
(vm_guest == VM_GUEST_XENPVH || vm_guest == VM_GUEST_GENPVH)
 1.369.2.1 02-Aug-2025  perseant Sync with HEAD
 1.40 22-Dec-2018  cherry Move mainbus(4) driver files in various x86 sub-archs to name prefixed
versions. This allows us to further modularise them by unifying common
bus probe code in x86/x86/mainbus.c to be introduced next.

This commit has no functional changes. It is done for ease of
visibility of newer diffs in the queue.
 1.39 02-Dec-2018  cherry make

options NO_PCI_MSI_MSIX

work again for arch/x86/
 1.38 23-May-2017  nonaka branches: 1.38.8; 1.38.10;
x86: Add preliminary x2APIC support.

x2APIC is used only when x2APIC is enabled in BIOS/UEFI.
LAPIC ID is not supported above 256.
 1.37 21-Jun-2016  nonaka Pass bus_dma(9) tag to allow for porting sdhc(4) at acpi.
 1.36 05-Aug-2015  mrg allow MPVERBOSE to be set to a value that sets the "mp_verbose" variable.
 1.35 27-Apr-2015  knakahara add x86 MD MSI/MSI-X support code.
 1.34 31-Jul-2013  soren branches: 1.34.6;
Blocking memory space accesses on the SIS 85C496 chipset turned out to be
a bit too heavy-handed and similar cases are unlikely to crop up again,
so simplify by eliminating pci_bus_flags().

Closes PR port-i386/20410.
 1.33 17-May-2011  dyoung branches: 1.33.4; 1.33.14; 1.33.18;
PCI_FLAGS_IO_ENABLED and PCI_FLAGS_MEM_ENABLED changed their functional
role in NetBSD (drivers are no longer supposed to write these to
pa_flags) without changing name. Correct that.

Rename PCI_FLAGS_IO_ENABLED to PCI_FLAGS_IO_OKAY and
PCI_FLAGS_MEM_ENABLED to PCI_FLAGS_MEM_OKAY, thus making their names
consistent with the other PCI flags and poisoning 3rd-party driver
sources that use the flags in the old bad way.

This patch produces no binary changes in this set of PCI kernels when
they are compiled w/o 'options DIAGNOSTIC' and w/ -V MKREPRO=yes:

algor P4032 P5064 P6032
alpha GENERIC
amd64 GENERIC XEN3_DOM0
arc GENERIC
atari HADES MILAN-PCIIDE
bebox GENERIC
cats GENERIC
cobalt GENERIC
evbarm-el ADI_BRH ARMADILLO9 CP3100 GEMINI GEMINI_MASTER GEMINI_SLAVE
evbarm-el GUMSTIX HDL_G IMX31LITE INTEGRATOR IQ31244 IQ80310 IQ80321
evbarm-el IXDP425 IXM1200 KUROBOX_PRO
evbarm-el LUBBOCK MARVELL_NAS NAPPI NSLU2 SHEEVAPLUG SMDK2800 TEAMASA_NPWR
evbarm-el TEAMASA_NPWR_FC TS7200 TWINTAIL ZAO425
evbmips-el AP30 DBAU1500 DBAU1550 MALTA MERAKI MTX-1 OMSAL400 RB153 WGT624V3
evbmips64-el XLSATX
evbppc EV64260 MPC8536DS MPC8548CDS OPENBLOCKS200 OPENBLOCKS266
evbppc OPENBLOCKS266_OPT P2020RDB PMPPC RB800 WALNUT
hp700 GENERIC
i386 ALL XEN3_DOM0 XEN3_DOMU
ibmnws GENERIC
iyonix GENERIC
landisk GENERIC
macppc GENERIC
mvmeppc GENERIC
netwinder GENERIC
ofppc GENERIC
prep GENERIC
sandpoint GENERIC
sbmips-el GENERIC
sgimips GENERIC32_IP2x GENERIC32_IP3x
sparc GENERIC_SUN4U KRUPS
sparc64 GENERIC
 1.32 22-Feb-2011  dholland Fix build in admittedly quixotic case with IPMI but no PCI or ACPI.
(ACPI currently doesn't work without PCI, fwiw.)
 1.31 28-Apr-2010  dyoung branches: 1.31.2; 1.31.4;
On x86, change the bus_space_tag_t to a pointer to a struct
bus_space_tag. For now, bus_space_tag's only member is
bst_type, the type of space, which is either X86_BUS_SPACE_IO
or X86_BUS_SPACE_MEM. In the future, new bus_space_tag members
will refer to override-functions installed by a new function,
bus_space_tag_create(9).

Add pointers to constant struct bus_space_tag, x86_bus_space_io and
x86_bus_space_mem. Use them to replace most uses of X86_BUS_SPACE_IO
and X86_BUS_SPACE_MEM.

Add an x86-specific bus_space_is_equal(9) implementation that compares
the two tags' bst_type.
 1.30 15-Feb-2010  dyoung branches: 1.30.2;
Don't use the global variable pci_mode, but use a local copy of
the return value of pci_mode_detect(), instead.
 1.29 18-Aug-2009  jmcneill branches: 1.29.2;
Switch to ACPICA 20090730, and update for API changes.
 1.28 13-Jun-2009  tsutsui Apply fixes from jmcneill@ for PR port-i386/38729
(ACPI kernel booted under qemu cannot detect devices):
- make MP SCANPCI function for ACPI_SCANPCI and MPBIOS_SCANPCI
return a number of attached PCI busses
- if no valid PCI busses are attached in the MP SCANPCI function,
try to probe and attach pci0 at mainbus as well as kernels
with no SCANPCI options

"Feel free to check it in" from jmcneill@.
Tested in pkgsrc qemu-0.9.1 (both i386 and x86_64) on NetBSD/i386.

Note original jmcneill's patch was posted on March:
http://mail-index.NetBSD.org/port-i386/2009/03/24/msg001281.html
and I also applied it to amd64:
http://mail-index.NetBSD.org/port-i386/2009/03/24/msg001283.html
but x86 MP attach functions have been reorganized by dyoung@ on April:
http://mail-index.NetBSD.org/source-changes/2009/04/17/msg219992.html
so I've modified the original patches to adapt the changes.
(mpacpi_scan_pci() and mpbios_scan_pci() have been merged into
common mp_pci_scan() in new arch/x86/x86/mp.c)
For netbsd-5 and netbsd-5-0 branches, the original patches should be
applied cleanly, and they have been tested by abs@ on a selection of
i386 boxes and in qemu.
 1.27 17-Apr-2009  dyoung Introduce sys/arch/x86/x86/mp.c for common x86 MP configuration code.
mpacpi_scan_pci() and mpbios_scan_pci() are identical code, so replace
them with mp_pci_scan().

Introduce mp_pci_childdetached(), which helps us to detach root PCI
buses that were enumerated either by MP BIOS or by ACPI.

Let us detach and re-attach PCI buses from mainbus0 on i386. This is
necessarily a work-in-progress, because testing detach and re-attach
is very difficult: to detach and re-attach the entire PCI tree on most
x86 computers that I own is not possible because some essential device
attaches under the PCI subtree: the console, com0, NIC, or storage
controller always attaches in the PCI tree.
 1.26 10-Nov-2008  cegger branches: 1.26.4;
mainbus_attach: reduce diff a little between i386 and amd64
 1.25 09-Nov-2008  cegger Nuke last parameter from mpaci_scan_apics() and mpbios_scan().
It is unused.
 1.24 18-May-2008  jmcneill branches: 1.24.4; 1.24.6; 1.24.8; 1.24.12;
Add support for PCI_BUS_FIXUP and PCI_ADDR_FIXUP on amd64.
 1.23 29-Apr-2008  ad branches: 1.23.2;
Minor correction to previous.
 1.22 29-Apr-2008  ad Recognise two new boot flags:

-1 disable MP
-2 disable ACPI
 1.21 01-Apr-2008  cegger branches: 1.21.2; 1.21.4;
convert to CFATTACH_DECL_NEW
OK matt and mrg
 1.20 09-Dec-2007  jmcneill branches: 1.20.10;
Merge jmcneill-pm branch.
 1.19 01-Dec-2007  jmcneill branches: 1.19.2; 1.19.4;
aprintify
 1.18 17-Oct-2007  garbled branches: 1.18.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.17 03-Jul-2007  briggs branches: 1.17.8; 1.17.10;
Add (commented-out) support for IPMI on amd64--pretty much copied straight
from i386.
 1.16 04-Jun-2007  xtraeme Ansify, de-__P(), unregister.
 1.15 05-Mar-2007  drochner branches: 1.15.2; 1.15.4; 1.15.10;
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.14 26-Nov-2006  cube branches: 1.14.2; 1.14.4; 1.14.8;
Introduce acpi_check() to inform the caller whether the acpi driver is
still enabled, as it could have been disabled through USERCONF.

Use it in amd64 and i386 mainbus code and skip all ACPI processing in case
it is disabled.
 1.13 04-Jul-2006  he branches: 1.13.4; 1.13.6;
The declaration of mpacpi_active needs to be unconditional because
there's an unconditional use.
 1.12 04-Jul-2006  christos Apply fvdl's acpi pci interrupt configuration code.
- MPACPI is no more.
- MPACPI_SCANPCI -> ACPI_SCANPCI
 1.11 16-Feb-2006  kochi branches: 1.11.2; 1.11.10;
including acpi_madt.h is not necessary
 1.10 11-Dec-2005  christos branches: 1.10.2; 1.10.4; 1.10.6;
merge ktrace-lwp.
 1.9 01-Jun-2005  drochner branches: 1.9.2;
update for acpi busname removal
 1.8 30-Aug-2004  drochner Phase out the use of a string as first "attach args" member to control
which bustype should be attached with a specific call to config_found()
(from a "mainbus" or a bus bridge).
Do it for isa/eisa/mca and pci/agp for now. These buses all attach to
an mi interface attribute "isabus", "eisabus" etc., and the autoconf
framework now allows to specify an interface attribute on config_found()
and config_search(), which limits the search of matching config data
to these which attach to that specific attribute.
So we basically have to call config_found_ia(..., "foobus", ...) where
such a bus is attached.
As a consequence, where a "mainbus" or alike also attaches other
devices (eg CPUs) which do not attach to a specific attribute yet,
we need at least pass an attribute name (different from "foobus") so
that the foo bus is not found at these places. This made some minor
changes necessary which are not obviously related to the mentioned buses.
 1.7 14-Jul-2003  lukem __KERNEL_RCSID()
 1.6 15-Jun-2003  fvdl branches: 1.6.2;
Handle 64bit DMA addresses on PCI for platforms that can (currently only
enabled on amd64). Add a dmat64 field to various PCI attach structures,
and pass it down where needed. Implement a simple new function called
pci_dma64_available(pa) to test if 64bit DMA addresses may be used.
This returns 1 iff _PCI_HAVE_DMA64 is defined in <machine/pci_machdep.h>,
and there is more than 4G of memory.
 1.5 29-May-2003  fvdl Add the options MPBIOS_SCANPCI and MPACPI_SCANPCI to configure PCI roots
with the MPBIOS/ACPI bus information, by walking through the buses, and
descending down every bus that hasn't been marked configured yet.
 1.4 15-May-2003  fvdl Add #if NACPI around acpi attach args.
 1.3 11-May-2003  fvdl include <machine/mpacpi.h>
 1.2 11-May-2003  fvdl ACPI support. Wakeup code still to be done.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.6.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.6.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.6.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.6.2.2 03-Sep-2004  skrll Sync with HEAD
 1.6.2.1 03-Aug-2004  skrll Sync with HEAD
 1.9.2.5 21-Jan-2008  yamt sync with head
 1.9.2.4 07-Dec-2007  yamt sync with head
 1.9.2.3 03-Sep-2007  yamt sync with head.
 1.9.2.2 30-Dec-2006  yamt sync with head.
 1.9.2.1 21-Jun-2006  yamt sync with head.
 1.10.6.1 22-Apr-2006  simonb Sync with head.
 1.10.4.1 09-Sep-2006  rpaulo sync with head
 1.10.2.1 18-Feb-2006  yamt sync with head.
 1.11.10.1 13-Jul-2006  gdamore Merge from HEAD.
 1.11.2.1 11-Aug-2006  yamt sync with head
 1.13.6.1 10-Dec-2006  yamt sync with head.
 1.13.4.1 12-Jan-2007  ad Sync with head.
 1.14.8.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.14.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.14.2.2 21-Jun-2009  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1327):
sys/arch/amd64/amd64/mainbus.c: revision 1.28 via patch
sys/arch/x86/x86/mp.c: revision 1.2 via patch
sys/arch/i386/i386/mainbus.c: revision 1.85 via patch
sys/arch/x86/x86/mpacpi.c: patch
sys/arch/x86/x86/mpbios.c patch
Apply fixes from jmcneill@ for PR port-i386/38729
(ACPI kernel booted under qemu cannot detect devices):
- make MP SCANPCI function for ACPI_SCANPCI and MPBIOS_SCANPCI
return a number of attached PCI busses
- if no valid PCI busses are attached in the MP SCANPCI function,
try to probe and attach pci0 at mainbus as well as kernels
with no SCANPCI options
"Feel free to check it in" from jmcneill@.
Tested in pkgsrc qemu-0.9.1 (both i386 and x86_64) on NetBSD/i386.
Note original jmcneill's patch was posted on March:
http://mail-index.NetBSD.org/port-i386/2009/03/24/msg001281.html
and I also applied it to amd64:
http://mail-index.NetBSD.org/port-i386/2009/03/24/msg001283.html
but x86 MP attach functions have been reorganized by dyoung@ on April:
http://mail-index.NetBSD.org/source-changes/2009/04/17/msg219992.html
so I've modified the original patches to adapt the changes.
(mpacpi_scan_pci() and mpbios_scan_pci() have been merged into
common mp_pci_scan() in new arch/x86/x86/mp.c)
For netbsd-5 and netbsd-5-0 branches, the original patches should be
applied cleanly, and they have been tested by abs@ on a selection of
i386 boxes and in qemu.
 1.14.2.1 19-Dec-2007  ghen Pull up following revision(s) (requested by briggs in ticket #989):
sys/arch/amd64/conf/GENERIC: revision 1.151
sys/arch/x86/x86/ipmi.c: revision 1.12
sys/dev/DEVNAMES: revision 1.228
sys/arch/amd64/amd64/bios32.c: revision 1.6
sys/arch/x86/x86/ipmi.c: revision 1.8
sys/arch/amd64/conf/files.amd64: revision 1.39 via patch
sys/arch/amd64/amd64/mainbus.c: revision 1.17
Use PRIx64 for a 64-bit quantity instead of llx in a debug print.
Add (commented-out) support for IPMI on amd64--pretty much copied straight
from i386.
Check for duplicate sensor names in the IPMI table. If a duplicate name
is found, try to make it unique by appending a count (1-99) to the sensor
description (truncating, if necessary).
 1.15.10.2 03-Oct-2007  garbled Sync with HEAD
 1.15.10.1 26-Jun-2007  garbled Sync with HEAD.
 1.15.4.1 11-Jul-2007  mjf Sync with head.
 1.15.2.3 03-Dec-2007  ad Sync with HEAD.
 1.15.2.2 15-Jul-2007  ad Sync with head.
 1.15.2.1 09-Jun-2007  ad Sync with head.
 1.17.10.2 09-Jan-2008  matt sync with HEAD
 1.17.10.1 06-Nov-2007  matt sync with HEAD
 1.17.8.3 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.17.8.2 01-Dec-2007  jmcneill Sync with HEAD.
 1.17.8.1 06-Nov-2007  joerg Refactor PNP API:
- Make suspend/resume directly a device functionality. It consists of
three layers (class logic, device logic, bus logic), all of them being
optional. This replaces D0/D3 transitions.
- device_is_active returns true if the device was not disabled and was
not suspended (even partially), device_is_enabled returns true if the
device was enabled.
- Change pnp_global_transition into pnp_system_suspend and
pnp_system_resume. Before running any suspend/resume handlers, check
that all currently attached devices support power management and bail
out otherwise. The latter is not done for the shutdown/panic case.
- Make the former bus-specific generic network handlers a class handler.
- Make PNP message like volume up/down/toogle PNP events. Each device
can register what events they are interested in and whether the handler
should be global or not.
- Introduce device_active API for devices to mark themselve in use from
either the system or the device. Use this to implement the idle handling
for audio and input devices. This is intended to replace most ad-hoc
watchdogs as well.
- Fix somes situations in which audio resume would lose mixer settings.
- Make USB host controllers better deal with suspend in the light of
shared interrupts.
- Flush filesystem cache on suspend.
- Flush disk caches on suspend. Put ATA disks into standby on suspend as
well.
- Adopt drivers to use the new PNP API.
- Fix a critical bug in the generic cardbus layer that made D0->D3
break.
- Fix ral(4) to set if_stop.
- Convert cbb(4) to the new PNP API.
- Apply the PCI Express SCI fix on resume again.
 1.18.2.2 27-Dec-2007  mjf Sync with HEAD.
 1.18.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.19.4.1 11-Dec-2007  yamt sync with head.
 1.19.2.1 26-Dec-2007  ad Sync with head.
 1.20.10.3 17-Jan-2009  mjf Sync with HEAD.
 1.20.10.2 02-Jun-2008  mjf Sync with HEAD.
 1.20.10.1 03-Apr-2008  mjf Sync with HEAD.
 1.21.4.6 11-Aug-2010  yamt sync with head.
 1.21.4.5 11-Mar-2010  yamt sync with head
 1.21.4.4 19-Aug-2009  yamt sync with head.
 1.21.4.3 20-Jun-2009  yamt sync with head
 1.21.4.2 04-May-2009  yamt sync with head.
 1.21.4.1 16-May-2008  yamt sync with head.
 1.21.2.1 18-May-2008  yamt sync with head.
 1.23.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.24.12.1 21-Apr-2010  matt sync to netbsd-5
 1.24.8.1 19-Jun-2009  snj Pull up following revision(s) (requested by tsutsui in ticket #819):
sys/arch/amd64/amd64/mainbus.c: revision 1.28 via patch
sys/arch/i386/i386/mainbus.c: revision 1.85 via patch
sys/arch/x86/x86/mpacpi.c: patch
sys/arch/x86/x86/mpbios.c: patch
Apply fixes from jmcneill@ for PR port-i386/38729
(ACPI kernel booted under qemu cannot detect devices):
- make MP SCANPCI function for ACPI_SCANPCI and MPBIOS_SCANPCI
return a number of attached PCI busses
- if no valid PCI busses are attached in the MP SCANPCI function,
try to probe and attach pci0 at mainbus as well as kernels
with no SCANPCI options
 1.24.6.2 28-Apr-2009  skrll Sync with HEAD.
 1.24.6.1 19-Jan-2009  skrll Sync with HEAD.
 1.24.4.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.26.4.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.26.4.5 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.26.4.4 24-Oct-2010  jym Sync with HEAD
 1.26.4.3 01-Nov-2009  jym Sync with HEAD.
 1.26.4.2 23-Jul-2009  jym Sync with HEAD.
 1.26.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.29.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.30.2.3 31-May-2011  rmind sync with head
 1.30.2.2 05-Mar-2011  rmind sync with head
 1.30.2.1 30-May-2010  rmind sync with head
 1.31.4.1 05-Mar-2011  bouyer Sync with HEAD
 1.31.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.33.18.1 28-Aug-2013  rmind sync with head
 1.33.14.2 03-Dec-2017  jdolecek update from HEAD
 1.33.14.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.33.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.34.6.4 28-Aug-2017  skrll Sync with HEAD
 1.34.6.3 09-Jul-2016  skrll Sync with HEAD
 1.34.6.2 22-Sep-2015  skrll Sync with HEAD
 1.34.6.1 06-Jun-2015  skrll Sync with HEAD
 1.38.10.1 10-Jun-2019  christos Sync with HEAD
 1.38.8.1 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.21 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.20 08-Feb-2011  rmind branches: 1.20.2;
Remove clause 3 (UCB advertising clause) from the University of Utah
copyright. Confirmed by Mike Hibler, mike at cs.utah.edu - thanks!
Also, merge UCB and Utah copyright texts back into one, as they
originally were.

Extra verification by snj@.
 1.19 29-Mar-2009  rmind branches: 1.19.2; 1.19.4; 1.19.6; 1.19.8;
Reduce some differences between i386 and amd64.
Mainly cosmetical changes - no functional changes intended.
 1.18 28-Mar-2009  rmind mmrw: add missing pmap_update().
 1.17 29-Jan-2009  joerg branches: 1.17.2;
x86/pmap.c declares vmmap as void *, match.
 1.16 12-Nov-2008  ad Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.
 1.15 25-Sep-2008  ad branches: 1.15.2;
PR kern/39298 dd brings system to knees

Make /dev/zero and friends MPSAFE.
 1.14 05-Sep-2008  tron Compile NetBSD/amd64 kernels with "-Wextra". Patches contributed by
Juan RP in PR port-amd64/39266.
 1.13 13-Feb-2008  joerg branches: 1.13.6; 1.13.10; 1.13.12; 1.13.16;
ANSIfy.
 1.12 16-Jan-2008  ad Always set up lkm_map.
 1.11 18-Oct-2007  yamt branches: 1.11.2; 1.11.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.10 04-Mar-2007  yamt branches: 1.10.2; 1.10.18; 1.10.20; 1.10.22; 1.10.24;
fix fallout from caddr_t changes.
 1.9 04-Mar-2007  christos Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.8 30-Oct-2006  elad branches: 1.8.4;
Move i386/amd64 common code (check_pa_acc()) to x86.

I didn't know what header to put the prototype in, so it's both in
i386/mem.c and amd64/mem.c; probably can be moved later.

Tested on amd64, assumed working on i386. :)

yamt@ okay
 1.7 23-Jul-2006  ad branches: 1.7.4; 1.7.6;
Use the LWP cached credentials where sane.
 1.6 14-May-2006  elad integrate kauth.
 1.5 11-Dec-2005  christos branches: 1.5.4; 1.5.6; 1.5.8; 1.5.10; 1.5.12;
merge ktrace-lwp.
 1.4 14-Oct-2003  fvdl branches: 1.4.16;
Proper checks for kmem reads beyond _end
 1.3 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.2 14-Jul-2003  lukem __KERNEL_RCSID()
 1.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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.6 27-Feb-2008  yamt sync with head.
 1.4.16.5 21-Jan-2008  yamt sync with head
 1.4.16.4 27-Oct-2007  yamt sync with head.
 1.4.16.3 03-Sep-2007  yamt sync with head.
 1.4.16.2 30-Dec-2006  yamt sync with head.
 1.4.16.1 21-Jun-2006  yamt sync with head.
 1.5.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.5.10.3 12-May-2006  elad include sys/kauth.h where appropriate.
 1.5.10.2 10-Mar-2006  elad generic_authorize() -> kauth_authorize_generic().
 1.5.10.1 08-Mar-2006  elad Adapt to kernel authorization KPI.

I expect *some* lossage here...
 1.5.8.2 11-Aug-2006  yamt sync with head
 1.5.8.1 24-May-2006  yamt sync with head.
 1.5.6.1 01-Jun-2006  kardel Sync with head.
 1.5.4.1 09-Sep-2006  rpaulo sync with head
 1.7.6.1 10-Dec-2006  yamt sync with head.
 1.7.4.1 18-Nov-2006  ad Sync with head.
 1.8.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.10.24.1 25-Oct-2007  bouyer Sync with HEAD.
 1.10.22.1 04-Oct-2007  yamt - move etext before rodata. define __data_start at the start of
.data section and use it instead of etext where appropriate.
- put .rodata.* into .rodata section as well.
- pmap_bootstrap: don't assume NBPD_L2 alignment.
- pmap_bootstrap: if DEBUG, print how many large pages and normal pages are
used to map kernel text.
 1.10.20.2 23-Mar-2008  matt sync with HEAD
 1.10.20.1 06-Nov-2007  matt sync with HEAD
 1.10.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.10.2.1 23-Oct-2007  ad Sync with head.
 1.11.8.1 19-Jan-2008  bouyer Sync with HEAD
 1.11.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.13.16.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.13.16.1 19-Oct-2008  haad Sync with HEAD.
 1.13.12.2 10-Oct-2008  skrll Sync with HEAD.
 1.13.12.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.13.10.1 04-May-2009  yamt sync with head.
 1.13.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.13.6.2 28-Sep-2008  mjf Sync with HEAD.
 1.13.6.1 29-Mar-2008  mjf Add a mem_init() function for each architecture that requests a device
node for /dev/mem, /dev/null, /dev/zero, etc.

This will disappear when I move this code (and others) to be a
pseudo-device. When we have machine-independent mem code this will all be
unnecessary anyway.
 1.15.2.3 28-Apr-2009  skrll Sync with HEAD.
 1.15.2.2 03-Mar-2009  skrll Sync with HEAD.
 1.15.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.17.2.4 27-Aug-2011  jym Add/remove files, like in HEAD.
 1.17.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.17.2.2 01-Nov-2009  jym Sync with HEAD.
 1.17.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.19.8.1 17-Feb-2011  bouyer Sync with HEAD
 1.19.6.1 06-Jun-2011  jruoho Sync with HEAD.
 1.19.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.19.2.2 15-Nov-2010  uebayasi Revert xmd(4).
 1.19.2.1 30-Oct-2010  uebayasi Implement pmap_physload_device(9) to replace xmd(4) MD backend.
Implement pmap_mmap(9) and use it from mem(4) and xmd(4).
 1.20.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.4 22-Jan-2008  joerg GC i8254_microtime.
 1.3 11-Dec-2005  christos branches: 1.3.50; 1.3.56; 1.3.64;
merge ktrace-lwp.
 1.2 07-Aug-2003  agc branches: 1.2.16;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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.2.16.1 04-Feb-2008  yamt sync with head.
 1.3.64.1 23-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.28 14-Nov-2019  maxv Add support for Kernel Memory Sanitizer (kMSan). It detects uninitialized
memory used by the kernel at run time, and just like kASan and kCSan, it
is an excellent feature. It has already detected 38 uninitialized variables
in the kernel during my testing, which I have since discreetly fixed.

We use two shadows:
- "shad", to track uninitialized memory with a bit granularity (1:1).
Each bit set to 1 in the shad corresponds to one uninitialized bit of
real kernel memory.
- "orig", to track the origin of the memory with a 4-byte granularity
(1:1). Each uint32_t cell in the orig indicates the origin of the
associated uint32_t of real kernel memory.

The memory consumption of these shadows is consequent, so at least 4GB of
RAM is recommended to run kMSan.

The compiler inserts calls to specific __msan_* functions on each memory
access, to manage both the shad and the orig and detect uninitialized
memory accesses that change the execution flow (like an "if" on an
uninitialized variable).

We mark as uninit several types of memory buffers (stack, pools, kmem,
malloc, uvm_km), and check each buffer passed to copyout, copyoutstr,
bwrite, if_transmit_lock and DMA operations, to detect uninitialized memory
that leaves the system. This allows us to detect kernel info leaks in a way
that is more efficient and also more user-friendly than KLEAK.

Contrary to kASan, kMSan requires comprehensive coverage, ie we cannot
tolerate having one non-instrumented function, because this could cause
false positives. kMSan cannot instrument ASM functions, so I converted
most of them to __asm__ inlines, which kMSan is able to instrument. Those
that remain receive special treatment.

Contrary to kASan again, kMSan uses a TLS, so we must context-switch this
TLS during interrupts. We use different contexts depending on the interrupt
level.

The orig tracks precisely the origin of a buffer. We use a special encoding
for the orig values, and pack together in each uint32_t cell of the orig:
- a code designating the type of memory (Stack, Pool, etc), and
- a compressed pointer, which points either (1) to a string containing
the name of the variable associated with the cell, or (2) to an area
in the kernel .text section which we resolve to a symbol name + offset.

This encoding allows us not to consume extra memory for associating
information with each cell, and produces a precise output, that can tell
for example the name of an uninitialized variable on the stack, the
function in which it was pushed on the stack, and the function where we
accessed this uninitialized variable.

kMSan is available with LLVM, but not with GCC.

The code is organized in a way that is similar to kASan and kCSan, so it
means that other architectures than amd64 can be supported.
 1.27 05-Nov-2019  maxv Add Kernel Concurrency Sanitizer (kCSan) support. This sanitizer allows us
to detect race conditions at runtime. It is a variation of TSan that is
easy to implement and more suited to kernel internals, albeit theoretically
less precise than TSan's happens-before.

We do basically two things:

- On every KCSAN_NACCESSES (=2000) memory accesses, we create a cell
describing the access, and delay the calling CPU (10ms).

- On all memory accesses, we verify if the memory we're reading/writing
is referenced in a cell already.

The combination of the two means that, if for example cpu0 does a read that
is selected and cpu1 does a write at the same address, kCSan will fire,
because cpu1's write collides with cpu0's read cell.

The coverage of the instrumentation is the same as that of kASan. Also, the
code is organized in a way similar to kASan, so it is easy to add support
for more architectures than amd64. kCSan is compatible with KCOV.

Reviewed by Kamil.
 1.26 26-Nov-2017  maxv branches: 1.26.4;
Hide a bunch of raw symbols.
 1.25 28-Sep-2017  maxv Pack the useful variables at the end of the trampoline page; eliminates
a hard-coded dependency on KERNBASE. Note that I cannot test this change
on i386 right now, but it seems fine enough.
 1.24 22-Jul-2017  maxv Clean up, it is easier to debug with qemu+gdb anyway.
 1.23 25-Jul-2016  maxv Unused.
 1.22 12-May-2016  maxv branches: 1.22.2;
KNF, and reduce the diff between amd64 and i386.
 1.21 11-May-2016  maxv There is a bug in the way the secondary CPUs are launched on amd64.

When CPU0 is launched, EFER_NXE is enabled in it, and it allows it to
handle pages that have the NOX bit. When the secondary CPUs are
launched, however, EFER_NXE is enabled only after paging is set in their
%cr0. And therefore, between the moment when paging is enabled and the
moment when EFER_NXE is enabled, the secondary CPUs cannot access pages
that have the NOX bit - they crash if they try to.

The funny thing is that in order to enable EFER_NXE, the secondary CPUs
give a look at cpu_feature[2], which is in the DATA segment, which in
turn could have the NOX bit. In other words, the secondary CPUs crash if
the DATA segment is mapped with the NOX bit.

Fix this by enabling EFER_NXE in the secondary CPUs before enabling
paging. CPU0 initializes nox_flag to the 32bit version of PG_NX if NOX
is supported; the secondary CPUs then use nox_flag to know whether NOX
is supported.

nox_flag will be used for other purposes soon.
 1.20 07-May-2016  maxv clarify
 1.19 09-Dec-2015  maxv KNF, and use C-style comments. Also, remove fusword/susword.
 1.18 22-Nov-2015  maxv KNF a bit, so I don't get scared each time I open a file
 1.17 15-Jan-2014  joerg branches: 1.17.6;
LLVM doesn't support data32/addr32, but is smart enough to figure the
necessary prefixes out.
 1.16 11-Jan-2014  jakllsch remove unused and undefined .globl
 1.15 22-Jun-2013  uebayasi branches: 1.15.2;
A few END() markers.
 1.14 20-Apr-2012  rmind branches: 1.14.2;
- 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.13 19-Apr-2012  jym Set the CR0_AM bit so processes can enable alignment check errors under
x86 through PSL_AC bit.

ATF test incoming shortly.
 1.12 20-Apr-2010  jym branches: 1.12.8; 1.12.12; 1.12.14;
Enable the NX bit feature early in the MP trampoline code (do not rely on
cpu_init_msrs() to do it). Having NX bit set on a page will raise a #GP
on fetch if NXE is not enabled, which can happen early when structures
(like idlelwp) are allocated with just rw- rights.
 1.11 18-Apr-2010  jym This patch fixes the NX regression issue observed on amd64 kernels, where
per-page execution right was disabled (therefore leading to the inability
of the kernel to detect fraudulent use of memory mappings marked as not
being executable).

- replace cpu_feature and ci_feature_flags variables by cpu_feature and
ci_feat_val arrays. This makes it cleaner and brings kernel code closer
to the design of cpuctl(8). A warning will be raised for each CPU that
does not expose the same features as the Boot Processor (BP).

- the blacklist of CPU features is now a macro defined in the
specialreg.h header, instead of hardcoding it inside MD initialization
code; fix comments.

- replace checks against CPUID_TSC with the cpu_hascounter() function.

- clean up the code in init_x86_64(), as cpu_feature variables are set
inside cpu_probe().

- use cpu_init_msrs() for i386. It will be eventually used later for NX
feature under i386 PAE kernels.

- remove code that checks for CPUID_NOX in amd64 mptramp.S, this is already
performed by cpu_hatch() through cpu_init_msrs().

- remove cpu_signature and feature_flags members from struct mpbios_proc
(they were never used).

This patch was tested with i386 MONOLITHIC, XEN3PAE_DOM0 and XEN3_DOM0 under
a native i386 host, and amd64 GENERIC, XEN3_DOM0 via QEMU virtual machines.

XXX Should kernel rev be bumped?

XXX A similar patch should be pulled-up for NetBSD-5, hopefully tomorrow.
 1.10 27-Nov-2009  rmind branches: 1.10.2; 1.10.4;
- Use uvm_lwp_setuarea() instead of directly setting address to lwp_t::l_addr.
- Replace most remaining uses of l_addr with uvm_lwp_getuarea() or lwp_getpcb().
- Amend assembly in ports where it accesses PCB via struct user.
- Rename L_ADDR to L_PCB in few places. Reduce sys/user.h inclusions.
 1.9 13-May-2008  ad branches: 1.9.8; 1.9.12; 1.9.14; 1.9.16;
Be more conservative during AP startup. Don't let the AP access the lapic
or do any setup until the boot processor has finished the init sequence,
and add a few more delays.
 1.8 11-May-2008  ad - Decouple the APIC ID from cpu_info[].
- Probe TSC frequency on each AP when hatching.
 1.7 28-Apr-2008  martin branches: 1.7.2;
Remove clause 3 and 4 from TNF licenses
 1.6 03-Apr-2008  christos branches: 1.6.2; 1.6.4;
make this compile with MPDEBUG. parts missing
 1.5 18-Oct-2007  yamt branches: 1.5.16;
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.4 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.3 17-May-2007  yamt branches: 1.3.8; 1.3.10; 1.3.12; 1.3.14;
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.2 24-Jul-2006  drochner branches: 1.2.10; 1.2.14; 1.2.16; 1.2.22;
Set the "NXE" bit (if available) early, before the cpu_info struct
is accessed. Without this, the (secondary) CPU chokes on the NX bit in
the PTE.
 1.1 26-Apr-2003  fvdl branches: 1.1.18; 1.1.32; 1.1.36;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.36.1 11-Aug-2006  yamt sync with head
 1.1.32.1 09-Sep-2006  rpaulo sync with head
 1.1.18.3 27-Oct-2007  yamt sync with head.
 1.1.18.2 03-Sep-2007  yamt sync with head.
 1.1.18.1 30-Dec-2006  yamt sync with head.
 1.2.22.1 22-May-2007  matt Update to HEAD.
 1.2.16.1 11-Jul-2007  mjf Sync with head.
 1.2.14.2 23-Oct-2007  ad Sync with head.
 1.2.14.1 27-May-2007  ad Sync with head.
 1.2.10.1 03-Mar-2007  yamt adapt amd64.

XXX changes in identcpu.c is minmum for MONITOR.
XXX identcpu.c should be shared with i386.
 1.3.14.1 25-Oct-2007  bouyer Sync with HEAD.
 1.3.12.3 07-Oct-2007  yamt remove some #ifdef _LOCORE and use genassym instead.
 1.3.12.2 04-Oct-2007  yamt remove LARGEPAGES option. always use large pages if available.
 1.3.12.1 01-Oct-2007  yamt fix LARGEPAGES + MP. PR/23450 from Wojciech Puchar.
 1.3.10.1 06-Nov-2007  matt sync with HEAD
 1.3.8.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.5.16.2 02-Jun-2008  mjf Sync with HEAD.
 1.5.16.1 03-Apr-2008  mjf Sync with HEAD.
 1.6.4.3 11-Aug-2010  yamt sync with head.
 1.6.4.2 11-Mar-2010  yamt sync with head
 1.6.4.1 16-May-2008  yamt sync with head.
 1.6.2.1 18-May-2008  yamt sync with head.
 1.7.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.9.16.1 20-May-2011  matt bring matt-nb5-mips64 up to date with netbsd-5-1-RELEASE (except compat).
 1.9.14.1 23-Apr-2010  snj Apply patch (requested by jym in ticket #1380):
Fix the NX regression issue observed on amd64 kernels, where per-page
execution right was disabled (therefore leading to the inability
of the kernel to detect fraudulent use of memory mappings marked as not
being executable).
 1.9.12.1 24-Oct-2010  jym Sync with HEAD
 1.9.8.1 22-Apr-2010  snj Apply patch (requested by jym in ticket #1380):
Fix the NX regression issue observed on amd64 kernels, where per-page
execution right was disabled (therefore leading to the inability
of the kernel to detect fraudulent use of memory mappings marked as not
being executable).
 1.10.4.1 30-May-2010  rmind sync with head
 1.10.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.12.14.2 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.12.14.1 20-Apr-2012  riz Pull up following revision(s) (requested by jym in ticket #189):
sys/arch/x86/include/psl.h: revision 1.7
sys/arch/i386/i386/locore.S: revision 1.98
sys/arch/amd64/acpi/acpi_wakecode.S: revision 1.11
sys/arch/amd64/amd64/mptramp.S: revision 1.13
sys/arch/i386/acpi/acpi_wakecode.S: revision 1.15
sys/arch/i386/i386/mptramp.S: revision 1.23
sys/arch/amd64/amd64/locore.S: revision 1.68
Set the CR0_AM bit so processes can enable alignment check errors under
x86 through PSL_AC bit.
ATF test incoming shortly.
PSL_AC is user-settable.
 1.12.12.1 29-Apr-2012  mrg sync to latest -current.
 1.12.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.12.8.1 23-May-2012  yamt sync with head.
 1.14.2.2 03-Dec-2017  jdolecek update from HEAD
 1.14.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.15.2.1 18-May-2014  rmind sync with head
 1.17.6.4 28-Aug-2017  skrll Sync with HEAD
 1.17.6.3 05-Oct-2016  skrll Sync with HEAD
 1.17.6.2 29-May-2016  skrll Sync with HEAD
 1.17.6.1 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.22.2.1 26-Jul-2016  pgoyette Sync with HEAD
 1.26.4.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.142 24-Apr-2025  riastradh x86: Make sure esp is aligned when delivering signal.

While here, use STACK_ALIGNBYTES consistently for the alignment mask
(or STACK_ALIGNBYTES32 in amd64 for the compat32 alignment mask).

PR kern/59327: user stack pointer is not aligned properly
 1.141 20-Aug-2022  riastradh branches: 1.141.10;
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.140 06-Nov-2021  thorpej COMPAT_NETBSD32 is all about running the 32-bit flavor of native
binaries on a 64-bit platform[*], as such:
- Make the logic about which "sendsig" flavor to call MI (as it is in the
native 64-bit environment) and follow the same rules as the native 32-bit
environment.
- Make COMPAT_NETBSD32 x COMPAT_16 work the same as it would in the
native 32-bit environment by providing a netbsd32_sendsig_sigcontext_16_hook,
rather than overriding the entire sendsig logic with a netbsd32_sendsig_hook.
- In netbsd32___sigaction_sigtramp(), make sure the compat_netbsd32_16
module is loaded if the trampoline version specifies a sigcontext style
handler, otherwise return EINVAL so that libc can try again with siginfo
style.

[*] ...except for arm32, which uses it to mean "run 32-bit OABI binaries
from the 32-bit EABI environment". Doing it this way was arguably a mistake,
but we are stuck with it for now, so support it by providing a machine-
dependent override for netbsd32_sendsig() that also disables the corresponding
logic in netbsd32___sigaction_sigtramp().

Fixes PR kern/56487.
 1.139 01-Nov-2021  thorpej Use "stack_t" instead of "struct sigaltstack", as the former is the
newer standardized name. NFC.
 1.138 27-Oct-2021  thorpej Use the signal trampoline version constants from <sys/signal.h>.
 1.137 20-Nov-2020  thorpej malloc(9) -> kmem(9)
 1.136 25-Apr-2020  bouyer branches: 1.136.2;
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.135 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.134 23-Apr-2020  christos use shortcut variables for readability.
 1.133 12-Dec-2019  pgoyette branches: 1.133.6;
Rather than keeping a separate mutex, condvar, and pserialize for each
module hook, we can share a common set of synchronization structures.
This cuts the amount of cacheline_aligned data for these structures by
50%.

Note that we still have a per-hook localcount, since we need to count
individual references.

As discussed with riastradh@

Welcome to 9.99.22 !
 1.132 27-Nov-2019  rin Add support for PT_[GS]ETXMMREGS requests for COMPAT_NETBSD32 on amd64.

For this purpose, PT_[GS]ETXMMREGS are added to amd64/ptrace.h. These
are intended for internal usage for COMPAT_NETBSD32, and therefore not
exposed to userland.

Thanks to kamil, mgorny, and pgoyette for their kind review!

XXX
pullup to netbsd-9
 1.131 20-Nov-2019  pgoyette Move all non-emulation-specific coredump code into the coredump module,
and remove all #ifdef COREDUMP conditional compilation. Now, the
coredump module is completely separated from the emulation modules, and
they can all be independently loaded and unloaded.

Welcome to 9.99.18 !
 1.130 20-Nov-2019  rin Fix netbsd32_process_write_dbregs() for amd64:

- Zero-clear regs64 so that random values are not written into the
preserved registers.
- Cast 32-bit registers (int) to u_int, in order to avoid undesired
sign extension when filled into 64-bit registers (long).

XXX
pullup to netbsd-9
 1.129 10-Nov-2019  chs in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
 1.128 26-Sep-2019  christos - promote regs from int to u_int in comparisons with unsigned constants
- cast -1 to __greg32_t which is unsigned and the LHS.
 1.127 21-Aug-2019  maxv Style and remove dead stuff.
 1.126 21-Aug-2019  maxv Don't depend on #ifdef USER_LDT in cpu_mcontext32_validate(), but rather on
whether the proc uses a user-set LDT. Same as check_sigcontext32().
 1.125 20-Jul-2019  christos branches: 1.125.2;
Restore the ability to debug a 32 bit process from a 64 bit debugger:
- add a function to validate a 64 bit context in 32 bit mode to write registers
- remove 32 bit checks from read and write register functions
- check for pc to fit in 32 bits.
proposed in tech-kern, ok maxv.
 1.124 26-Jun-2019  mgorny 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.123 04-Jun-2019  mgorny compat32: Implement PT_GETDBREGS and PT_SETDBREGS

Uncomment and improve the implementation of compat32 support for
PT_GETDBREGS and PT_SETDBREGS requests.

The new implementation uses x86_dbregs_read() and x86_dbregs_write()
function instead of accessing pcb directly. While this might be
a little slower, it guarantees that the needed pcb field is allocated
correctly.

Furthermore, the code introduces necessary sanity checks
for PT_SETDBREGS arguments.
 1.122 04-Jun-2019  mgorny compat32: Translate userland PT_* request values into kernel codes

Currently, the compat32 passes PT_* request values to kernel functions
without translation. This works fine for low PT_* requests that happen
to have the same values both on i386 and amd64. However, for requests
higher than PT_SETFPREGS, the value passed from userland (matching i386
const) does not match the correct kernel (amd64) request. As a result,
e.g. when compat32 process calls PT_GETDBREGS, kernel actually processes
it as PT_SETSTEP.

To resolve this, introduce support for compat32 PT_* request
translation. The interface is based on PTRACE_TRANSLATE_REQUEST32 macro
that is defined to a mapping function on architectures needing it.
In case of amd64, this function maps userland i386 PT_* values into
appropriate amd64 PT_* values.

For the time being, the two additional PT_GETXMMREGS and PT_SETXMMREGS
requests are unsupported due to lack of matching free amd64 constant.
 1.121 19-May-2019  maxv Rename

fpu_save_area_clear -> fpu_clear
fpu_save_area_reset -> fpu_sigreset

Clearer, and reduces a future diff. No real functional change.
 1.120 24-Mar-2019  maxv Disable preemption when setting PCB_COMPAT32, to prevent a context switch
before cpu_fsgs_reload() finishes, otherwise we write garbage in the GDT.
On NetBSD-current it is harmless, however in NetBSD-8 it might cause
panics, because NetBSD-8 uses the old SegRegs model and under this model
we reload %fs and %gs during switches.
 1.119 01-Mar-2019  pgoyette Rename the MODULE_*_HOOK() macros to MODULE_HOOK_*() as briefly
discussed on irc.

NFCI intended.

Ride the earlier kernel bump - it;s getting crowded.
 1.118 27-Jan-2019  pgoyette Merge the [pgoyette-compat] branch
 1.117 27-Nov-2018  maxv Fix widespread leak in the sendsig_siginfo() functions. sigframe_siginfo
has padding, so zero it out properly. While here I'm also zeroing out some
other things in several ports, for safety. Same problem in netbsd32, so
fix that too.

I can't compile-test on each architecture, but there should be no
breakage (tm).

Overall this fixes at least 14 info leaks. Prompted by the discovery by
KLEAK of a leak in amd64's sendsig_siginfo.
 1.116 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.115 07-Dec-2017  christos branches: 1.115.2; 1.115.4;
Save maxv@ some work and put back the compat_13_sigreturn changes that allow
amd64 to run ancient i386 binaries.
 1.114 07-Dec-2017  christos Keep fs/gs the same for the signal context; otherwise calling things
like __lwp_getprivate_fast() from a signal handler (that uses %gs) die.

Merge context building code.
 1.113 02-Dec-2017  maxv Remove a piece of COMPAT_13, that I mistakenly didn't commit three
hours ago (in my change to drop COMPAT_13 on amd64).
 1.112 19-Oct-2017  maxv Always mask the 16 bits of the segregs in the trapframe. We don't zero-
extend the uint64_t's when building it, so we're leaking 48 bits of kernel
stack to userland.

Having said that, it appears that I unintentionally fixed most of this
issue in locore.S::rev1.127 - by building the frame with interrupts
disabled, we are implicitly guaranteeing that the structure doesn't get
overwritten by the kernel. Which means, we are leaking to userland data
that comes from userland anyway.

(still other places with this issue, but I'll fix them differently)
 1.111 15-Oct-2017  maxv Use two separate functions: cpu_segregs32_zero and cpu_segregs64_zero. The
way segment registers work on amd64 will diverge between 32bit and 64bit
LWPs.
 1.110 15-Oct-2017  maxv Make sure the 32bit LWPs don't have MDL_IRET set. That's not a problem
right now, but will be in the future.
 1.109 17-Sep-2017  maxv Remove the second argument from USERMODE and KERNELMODE, it is unused
now that we don't have vm86 anymore.
 1.108 31-Aug-2017  maxv check sc_eip in the ldt branch too
 1.107 25-Jul-2017  maxv This branch must be static, otherwise there is a condition under which
the KASSERT in startlwp32 would be triggered.
 1.106 22-Jul-2017  maxv Branch for USER_LDT.
 1.105 01-Jun-2017  chs branches: 1.105.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.
 1.104 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.103 14-Feb-2017  maxv Check %eip with USER_LDT too.
 1.102 09-Feb-2017  maxv No, do not just copy code from i386 and expect it to work on amd64. There
are several structural differences. At least two issues here: segment
registers that could fault in kernel mode with userland TLS, and a non-
canonical %eip on iret.

Not even tested, but just obvious. By the way, I believe this function is
still buggy since we don't call cpu_fsgs_reload while %fs/%gs could have
been reloaded.
 1.101 06-Feb-2017  maxv In cpu_mcontext32_validate, allow the registers to have different locations
if the LDT is user-set.

I am intentionally not allowing this in check_sigcontext32, because I don't
think Wine uses it.
 1.100 06-Feb-2017  maxv Add the USER_LDT sysarch options in netbsd32. We don't translate 'desc',
since if we ever implement USER_LDT we will only allow 8-byte-sized
entries, which have the same layout on amd64 and i386.
 1.99 05-Feb-2017  maxv Remove #if 0 on USER_LDT.
 1.98 15-Dec-2016  kamil branches: 1.98.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.97 19-Oct-2016  skrll PR kern/51514: ptrace(2) fails for 32-bit process on 64-bit kernel

Updated from the original patch in the PR by me.
 1.96 02-Sep-2016  maxv Fix argument (does not compile anyway).
 1.95 26-Nov-2015  martin branches: 1.95.2;
We never exec(2) with a kernel vmspace, so do not test for that, but instead
KASSERT() that we don't.
When calculating the load address for the interpreter (e.g. ld.elf_so),
we need to take into account wether the exec'd process will run with
topdown memory or bottom up. We can not use the current vmspace's flags
to test for that, as this happens too early. Luckily the execpack already
knows what the new state will be later, so instead of testing the current
vmspace, pass the info as additional argument to struct emul
e_vm_default_addr.
Fix all such functions and adopt all callers.
 1.94 22-Nov-2015  maxv KNF a bit, so I don't get scared each time I open a file
 1.93 14-Dec-2014  christos Move the empty sigreturn functions to their own files to allow the compat
module to load by itself.
 1.92 15-Feb-2014  dsl branches: 1.92.4; 1.92.6; 1.92.8; 1.92.12;
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.91 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.90 11-Feb-2014  dsl Move sys/arch/amd64/amd64/fpu.c and sys/arch/amd64/include/fpu.h
into sys/arch/x86 in preparation for using the same code for i386.
 1.89 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.88 25-Jan-2014  christos provide propert address defaults for topdown and bottomup allocation
 1.87 04-Jan-2014  dsl Remove __HAVE_PROCESS_XFPREGS and add the extra parameter for the size
of the fp save area to all the process_read_fpregs() and
process_write_fpregs() functions.
None of the functions have been modified to use the new parameters.
The size is set for all the writes, but some of the arch-specific reads
just pass NULL.
The amd64 (and i386) need variable sized fp register save areas in order
to support AVX and other enhanced register areas.
These functions are rarely called - so the extra argument won't matter.
 1.86 01-Jan-2014  dsl Change the type of the 'cookie' that holds the state of the core dump file
from 'void *' to the actual type 'struct coredump_iostate *'.
In most of the code the contents of the structure are still unknown.
This just stops the wrong type of pointer being passed to the 'void *'
parameter.
I hope I've found everything, amd64 GENERIC and i386 GENERIC & ALL compile.
 1.85 01-Dec-2013  christos revert fpu/pcu changes until we figure out what's wrong; they cause random
freezes
 1.84 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.83 02-Nov-2013  christos sprinkle __diagused
 1.82 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.81 25-Jun-2013  dsl branches: 1.81.2;
Improve the dodgy code that writes the FP regs into core dumps of 32bit apps.
(I'm not pretending it is correct yet!)
The 'struct fpreg32' (written to coredumps) is shorter than 'struct save87'
so netbsd32_process_read_fpregs() hadn't better write to the extra items.
Doing so overwrites stack in coredump_note() in core_elf32.c - I'm amazed
it doesn't cause a panic!
Also correct (I think) the code and data addresses associated with the FP
unit.
This probably wants pulling up.
 1.80 31-Dec-2012  dsl Move the two fields used to save some i387 state on the last fpu trap
into their own sub-structure of the pcb (from 'struct savefpu').
They only (seem) to be used in some code that generates core dumps
for 32bit processes (code that might be broken as well!).
'struct safefpu' is now identical to 'struct fxsave64'. One (or both)
needs extending to support AVX - might need to be dynamically sized.
Removed all the __aligned(16) except for the one in struct pcb itself.
Only the copy used for the fsave instruction need be aligned.
 1.79 15-Jul-2012  dsl branches: 1.79.2;
Rename MDP_IRET to MDL_IRET since it is an lwp flag, not a proc one.
Add an MDL_COMPAT32 flag to the lwp's md_flags, set it for 32bit lwps
and use it to force 'return to user' with iret (as is done when
MDL_IRET is set).
Split the iret/sysret code paths much later.
Remove all the replicated code for 32bit system calls - which was only
needed so that iret was always used.
frameasm.h for XEN contains '#define swapgs', while XEN probable never
needs swapgs, this is likely to be confusing.
Add a SWAPGS which is a nop on XEN and swapgs otherwise.
(I've not yet checked all the swapgs in files that include frameasm.h)
Simple x86 programs still work.
Hijack 6.99.9 kernel bump (needed for compat32 modules)
 1.78 08-Jul-2012  dsl The MDP_USEDFPU (amd64 and sh3) and MDP_SSTEP (sh3) are lwp flags not
process ones, rename to MDL_xxx.
 1.77 12-Jun-2012  bouyer If the user process provided a bogus signal handler address, kill it
now instead of trying to jump to the bogus address.
 1.76 21-May-2012  martin Calling _lwp_create() with a bogus ucontext could trigger a kernel
assertion failure (and thus a crash in DIAGNOSTIC kernels). Independently
discovered by YAMAMOTO Takashi and Joel Sing.

To avoid this, introduce a cpu_mcontext_validate() function and move all
sanity checks from cpu_setmcontext() there. Also untangle the netbsd32
compat mess slightly and add a cpu_mcontext32_validate() cousin there.

Add an exhaustive atf test case, based partly on code from Joel Sing.

Should finally fix the remaining open part of PR kern/43903.
 1.75 19-Feb-2012  rmind Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.
 1.74 04-Mar-2011  joerg branches: 1.74.4; 1.74.8; 1.74.10;
Refactor ps_strings access. Based on PK_32, write either the normal
version or the 32bit compat layout in execve1. Introduce a new function
copyin_psstrings for reading it back from userland and converting it to
the native layout. Refactor procfs to share most of the code with the
kern.proc_args sysctl handler.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.
 1.73 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.72 23-Feb-2011  joerg C&P error
 1.71 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.70 07-Feb-2011  chs move macros for validating fs/gs to segments.h and use them
in the linux32 code as well.
 1.69 26-Jan-2011  njoly Do mask the upper 16 bits, when sanity checking fs/gs register values.
Fix my own PR/43842.
 1.68 17-Nov-2010  dholland branches: 1.68.2; 1.68.4;
Fix build with COMPAT_13.
 1.67 05-Sep-2010  chs accept the LDT selector in check_sigcontext32() too.
 1.66 05-Sep-2010  chs in check_mcontext32(), accept the LDT selector for 32-bit user code
as well as the GDT selector. fixes PR 43835.
 1.65 08-Aug-2010  chs Fix several panics that can be caused by applications using
bad segment register values with setcontext() or sigreturn().
 1.64 07-Jul-2010  chs add the guts of TLS support on amd64. based on joerg's patch,
reworked by me to support 32-bit processes as well.
we now keep %fs and %gs loaded with the user values
while in the kernel, which means we don't need to
reload them when returning to user mode.
 1.63 11-May-2010  joerg Fix indentation
 1.62 23-Apr-2010  rmind Remove lwp_uc_pool, replace it with kmem(9), plus add some consistency.
As discussed, a while ago, with ad@.
 1.61 10-Dec-2009  matt branches: 1.61.2; 1.61.4;
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.60 21-Nov-2009  rmind Use lwp_getpcb() on x86 MD code, clean from struct user usage.
 1.59 25-Sep-2009  mlelstv Ensure FP state is reset, if FP is used in a signal handler.
Fixes PR kern/39299 for 32bit code.
 1.58 16-Aug-2009  pgoyette Repair more fallout from the exec_aout.h change.

No guarantee that these are the "right" things to do, but they do allow
building of port-amd64 again.
 1.57 18-Dec-2008  cegger branches: 1.57.2;
malloc -> kmem
 1.56 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.55 15-Oct-2008  wrstuden branches: 1.55.2; 1.55.4; 1.55.6; 1.55.8;
Merge wrstuden-revivesa into HEAD.
 1.54 13-Oct-2008  sborrill Ensure optional MTRR sections are built if MTRR is enabled (missing #include
"opt_mtrr.h").
Fix build due to changes in revision 1.4 of sys/arch/x86/include/mtrr.h
 1.53 19-Sep-2008  pgoyette Fix apparent (and obvious) typo in previous.
 1.52 18-Sep-2008  dsl Clear all the correct flags when calling a signal handler.
 1.51 21-May-2008  ad branches: 1.51.4;
Remove unneeded playing about with kernel_lock.
 1.50 24-Apr-2008  ad branches: 1.50.2; 1.50.4;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.
 1.49 21-Apr-2008  tls Work around PR38480 by making it possible to omit options MTRR from
amd64 INSTALL kernels -- and doing so. At least you can now get an
INSTALL kernel onto a box with this odd MTRR configuration to debug it.
 1.48 16-Apr-2008  cegger branches: 1.48.2;
use POSIX integer types
 1.47 15-Jan-2008  joerg branches: 1.47.6;
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.46 24-Dec-2007  hamajima Add compat_13_netbsd32_sigreturn() for 32bits programs with COMPAT_13+EXEC_AOUT.
 1.45 20-Dec-2007  dsl 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.44 17-Oct-2007  garbled branches: 1.44.2; 1.44.4; 1.44.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.43 08-Jul-2007  pooka branches: 1.43.10;
Initialize the link context in a signal frame to the receiving lwp's
link context instead of NULL. Otherwise, if we got a signal while the
lwp had a link context set, the link context would be set to NULL upon
return from signal delivery.

christos@tech-kern: "I think you are right."
 1.42 04-Jun-2007  xtraeme Ansify, de-__P(), unregister.
 1.41 21-May-2007  fvdl Revert fs/gs changes until I figure out issues with them.
 1.40 11-May-2007  fvdl Don't save/restore %fs and %gs in trapframe. The kernel won't touch them.
Instead, save/restore them on context switch. For 32bit processes, save/restore
the selector values only, for 64bit processes, save/restore the appropriate
MSRs. Iff the defaults have been changed.
 1.39 16-Apr-2007  ad branches: 1.39.2;
Share the sysarch stuff between the x86 ports. PR kern/36046.
 1.38 16-Mar-2007  dsl Use NETBSD32PTR64() and NETBSD32PTR32() throughout.
 1.37 04-Mar-2007  yamt branches: 1.37.2; 1.37.4; 1.37.6;
fix fallout from caddr_t changes.
 1.36 04-Mar-2007  christos Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.35 19-Feb-2007  cube Introduce a new member to struct emul, e_startlwp, to be used by
sys__lwp_create. It allows using the said syscall under COMPAT_NETBSD32.

The libpthread regression tests now pass on amd64 and sparc64.
 1.34 18-Feb-2007  ad Sync signal delivery routines with i386. sendsig_reset() was not being
called, and so delivered signals were not being masked.

From cube@, with minor mods by me.
 1.33 17-Feb-2007  pavel Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.
 1.32 09-Feb-2007  ad branches: 1.32.2;
Merge newlock2 to head.
 1.31 26-Dec-2006  elad Make machdep scope architecture-agnostic by removing all arch-specific
requests and centralizing them all. The result is that some of these
are not used on some architectures, but the documentation was updated
to reflect that.
 1.30 21-Nov-2006  christos branches: 1.30.2;
adjust limits takes struct proc again.
 1.29 21-Nov-2006  christos From Nicolas Joly:

> It seems that 32bits programs, running under compat_netbsd32, using
> setrlimit force all other programs to have their maximum data size
> fixed at 3GB, where native 64bits apps used 8GB previously.

I tracked this one to the `netbsd32_adjust_limits()' function (called
when creating a new process under compat_netbsd32), where data and
stack limits are set without checking for shared `p_limit' structure
(p_limit->p_refcnt > 1). This explain the side effect where processes
have their limits changed when a compat_netbsd32 (or compat_linux32)
program is run.

The fix is to use `dosetrlimit()' to ensure the needed copy-on-write
behaviour for shared structure.
 1.28 23-Oct-2006  pooka apply const where necessary
 1.27 19-Sep-2006  elad Lose (void *) casts on the machdep scope authorization wrapper. Update
documentation.
 1.26 08-Sep-2006  elad branches: 1.26.2;
First take at security model abstraction.

- Add a few scopes to the kernel: system, network, and machdep.

- Add a few more actions/sub-actions (requests), and start using them as
opposed to the KAUTH_GENERIC_ISSUSER place-holders.

- Introduce a basic set of listeners that implement our "traditional"
security model, called "bsd44". This is the default (and only) model we
have at the moment.

- Update all relevant documentation.

- Add some code and docs to help folks who want to actually use this stuff:

* There's a sample overlay model, sitting on-top of "bsd44", for
fast experimenting with tweaking just a subset of an existing model.

This is pretty cool because it's *really* straightforward to do stuff
you had to use ugly hacks for until now...

* And of course, documentation describing how to do the above for quick
reference, including code samples.

All of these changes were tested for regressions using a Python-based
testsuite that will be (I hope) available soon via pkgsrc. Information
about the tests, and how to write new ones, can be found on:

http://kauth.linbsd.org/kauthwiki

NOTE FOR DEVELOPERS: *PLEASE* don't add any code that does any of the
following:

- Uses a KAUTH_GENERIC_ISSUSER kauth(9) request,
- Checks 'securelevel' directly,
- Checks a uid/gid directly.

(or if you feel you have to, contact me first)

This is still work in progress; It's far from being done, but now it'll
be a lot easier.

Relevant mailing list threads:

http://mail-index.netbsd.org/tech-security/2006/01/25/0011.html
http://mail-index.netbsd.org/tech-security/2006/03/24/0001.html
http://mail-index.netbsd.org/tech-security/2006/04/18/0000.html
http://mail-index.netbsd.org/tech-security/2006/05/15/0000.html
http://mail-index.netbsd.org/tech-security/2006/08/01/0000.html
http://mail-index.netbsd.org/tech-security/2006/08/25/0000.html

Many thanks to YAMAMOTO Takashi, Matt Thomas, and Christos Zoulas for help
stablizing kauth(9).

Full credit for the regression tests, making sure these changes didn't break
anything, goes to Matt Fleming and Jaime Fournier.

Happy birthday Randi! :)
 1.25 30-Aug-2006  cube branches: 1.25.2;
Let this compile under "no options COREDUMP".
 1.24 23-Jul-2006  ad Use the LWP cached credentials where sane.
 1.23 14-May-2006  elad integrate kauth.
 1.22 29-Mar-2006  cube Add the netbsd32 MD bits for sparc64 and amd64 to support SA.

Many thanks to all who helped for that little project, notably Martin
Husemann for teaching me a bit about the very special sparc64 world.
 1.21 12-Mar-2006  cube branches: 1.21.2;
Support the generation of coredumps for 32-bits binaries under
COMPAT_NETBSD32. They haven't worked for 5 years.

Silently agreed by the tech-kern readers.

XXX sparc64 MD glue still lacking.
XXX The FPU registers on i386 are not dumped correctly, according to my
XXX tests. It shouldn't be much work for someone who has the slightest
XXX idea of how that stuff is supposed to be laid out on i386.
 1.20 14-Jan-2006  hamajima branches: 1.20.2; 1.20.4; 1.20.6; 1.20.8;
fix compile error for ktrace-lwp.
 1.19 11-Jan-2006  cube Add support for VM_TOPDOWN, and use it unconditionally (just like i386).

For COMPAT_NETBSD32 binaries, use VM_TOPDOWN layout too, and sync some
parameters with their i386 counterpart.

OK'd by fvdl@.
 1.18 11-Dec-2005  christos branches: 1.18.2;
merge ktrace-lwp.
 1.17 03-Jul-2005  cube branches: 1.17.2;
Constify machine32 and machine_arch32.
 1.16 03-Jul-2005  cube Make COMPAT_NETBSD32 emulate hw.machine. While it might seem wrong to do
so, it introduces breakage because a lot of applications make assumptions
from its value. It's especially bad in the sparc64 case, where 64-bits
instructions can be used in 32-bits addressing mode. However, there are
other means to know the capabilities of the CPU.
 1.15 10-Jun-2005  matt Rework the coredump code to have no explicit knownledge of how coredump
i/o is done. Instead, pass an opaque cookie which is then passed to a
new routine, coredump_write, which does the actual i/o. This allows the
method of doing i/o to change without affecting any future MD code.
Also, make netbsd32_core.c [re]use core_netbsd.c (in a similar manner that
core_elf64.c uses core_elf32.c) and eliminate that code duplication.
cpu_coredump{,32} is now called twice, first with a NULL iocookie to fill
the core structure and a second to actually write md parts of the coredump.
All i/o is nolonger random access and is suitable for shipping over a stream.
 1.14 02-Jun-2005  drochner remove __UNCONST which is not needed anymore
 1.13 01-Jun-2005  blymn Cast away const for siginfo structure as the function prototype does not
have const.
 1.12 26-Mar-2005  fvdl Fix some things regarding COMPAT_NETBSD32 and limits/VM addresses.

* For sparc64 and amd64, define *SIZ32 VM constants.
* Add a new function pointer to struct emul, pointing at a function
that will return the default VM map address. The default function
is uvm_map_defaultaddr, which just uses the VM_DEFAULT_ADDRESS
macro. This gives emulations control over the default map address,
and allows things to be mapped at the right address (in 32bit range)
for COMPAT_NETBSD32.
* Add code to adjust the data and stack limits when a COMPAT_NETBSD32
or COMPAT_SVR4_32 binary is executed.
* Don't use USRSTACK in kern_resource.c, use p_vmspace->vm_minsaddr
instead (emulations might have set it differently)
* Since this changes struct emul, bump kernel version to 3.99.2

Tested on amd64, compile-tested on sparc64.
 1.11 17-Sep-2004  skrll branches: 1.11.4; 1.11.6; 1.11.10;
There's no need to pass a proc value when using UIO_SYSSPACE with
vn_rdwr(9) and uiomove(9).

OK'd by Jason Thorpe
 1.10 25-Mar-2004  drochner remove sigcontext-style signal delivery code
 1.9 20-Feb-2004  drochner Provide a dummy cpu_exec_aout_makecmds() to make a kernel
with COMPAT_NETBSD32+COMPAT_AOUT link.
netbsd-1.3/i386 binaries are running now.
 1.8 11-Feb-2004  matt 32-bit corefiles should use a MID for i386, not xf86_64.
 1.7 21-Oct-2003  fvdl Fix int vs. NULL comparison.
 1.6 13-Oct-2003  fvdl Define a 32bit compat version of the siginfo sendsig, and rename the
old one to reflect it's COMPAT_16 status.
 1.5 26-Sep-2003  christos Add needed header file.
 1.4 26-Sep-2003  christos catch up with const sigset_t *
 1.3 14-Jul-2003  lukem __KERNEL_RCSID()
 1.2 23-Jun-2003  martin branches: 1.2.2;
Make sure to include opt_foo.h if a defflag option FOO is used.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.2.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.2.2.4 01-Apr-2005  skrll Sync with HEAD.
 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.11.10.1 18-Sep-2005  tron Pull up following revision(s) (requested by fvdl in ticket #798):
sys/compat/sunos/sunos_exec.c: revision 1.47
sys/compat/pecoff/pecoff_emul.c: revision 1.11
sys/arch/sparc64/sparc64/netbsd32_machdep.c: revision 1.45
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.12
sys/sys/proc.h: revision 1.198
sys/compat/mach/mach_exec.c: revision 1.56
sys/compat/freebsd/freebsd_exec.c: revision 1.27
sys/arch/sparc64/include/vmparam.h: revision 1.27
sys/kern/kern_resource.c: revision 1.91
sys/compat/netbsd32/netbsd32_netbsd.c: revision 1.88
sys/compat/osf1/osf1_exec.c: revision 1.39
sys/compat/svr4_32/svr4_32_resource.c: revision 1.5
sys/compat/ultrix/ultrix_misc.c: revision 1.99
sys/compat/svr4_32/svr4_32_exec.h: revision 1.9
sys/kern/exec_elf32.c: revision 1.103
sys/compat/aoutm68k/aoutm68k_exec.c: revision 1.19
sys/compat/sunos32/sunos32_exec.c: revision 1.20
sys/compat/hpux/hpux_exec.c: revision 1.46
sys/compat/darwin/darwin_exec.c: revision 1.40
sys/kern/sysv_shm.c: revision 1.83
sys/uvm/uvm_extern.h: revision 1.99
sys/uvm/uvm_mmap.c: revision 1.89
sys/kern/kern_exec.c: revision 1.195
sys/compat/netbsd32/netbsd32.h: revision 1.31
sys/arch/sparc64/sparc64/svr4_32_machdep.c: revision 1.20
sys/compat/svr4/svr4_exec.c: revision 1.56
sys/compat/irix/irix_exec.c: revision 1.41
sys/compat/ibcs2/ibcs2_exec.c: revision 1.63
sys/compat/svr4_32/svr4_32_exec.c: revision 1.16
sys/arch/amd64/include/vmparam.h: revision 1.8
sys/compat/linux/common/linux_exec.c: revision 1.73
Fix some things regarding COMPAT_NETBSD32 and limits/VM addresses.
* For sparc64 and amd64, define *SIZ32 VM constants.
* Add a new function pointer to struct emul, pointing at a function
that will return the default VM map address. The default function
is uvm_map_defaultaddr, which just uses the VM_DEFAULT_ADDRESS
macro. This gives emulations control over the default map address,
and allows things to be mapped at the right address (in 32bit range)
for COMPAT_NETBSD32.
* Add code to adjust the data and stack limits when a COMPAT_NETBSD32
or COMPAT_SVR4_32 binary is executed.
* Don't use USRSTACK in kern_resource.c, use p_vmspace->vm_minsaddr
instead (emulations might have set it differently)
* Since this changes struct emul, bump kernel version to 3.99.2
Tested on amd64, compile-tested on sparc64.
 1.11.6.1 26-Mar-2005  yamt sync with head.
 1.11.4.1 29-Apr-2005  kent sync with -current
 1.17.2.5 21-Jan-2008  yamt sync with head
 1.17.2.4 03-Sep-2007  yamt sync with head.
 1.17.2.3 26-Feb-2007  yamt sync with head.
 1.17.2.2 30-Dec-2006  yamt sync with head.
 1.17.2.1 21-Jun-2006  yamt sync with head.
 1.18.2.1 15-Jan-2006  yamt sync with head.
 1.20.8.4 12-May-2006  elad include sys/kauth.h where appropriate.
 1.20.8.3 19-Apr-2006  elad sync with head - hopefully this will work
 1.20.8.2 10-Mar-2006  elad generic_authorize() -> kauth_authorize_generic().
 1.20.8.1 08-Mar-2006  elad Adapt to kernel authorization KPI.

I expect *some* lossage here...
 1.20.6.6 14-Sep-2006  yamt sync with head.
 1.20.6.5 03-Sep-2006  yamt sync with head.
 1.20.6.4 11-Aug-2006  yamt sync with head
 1.20.6.3 24-May-2006  yamt sync with head.
 1.20.6.2 01-Apr-2006  yamt sync with head.
 1.20.6.1 13-Mar-2006  yamt sync with head.
 1.20.4.2 01-Jun-2006  kardel Sync with head.
 1.20.4.1 22-Apr-2006  simonb Sync with head.
 1.20.2.1 09-Sep-2006  rpaulo sync with head
 1.21.2.2 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.21.2.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.25.2.6 30-Jan-2007  ad Remove support for SA. Ok core@.
 1.25.2.5 12-Jan-2007  ad Sync with head.
 1.25.2.4 11-Jan-2007  ad Checkpoint work in progress.
 1.25.2.3 18-Nov-2006  ad Sync with head.
 1.25.2.2 17-Nov-2006  ad Checkpoint work in progress.
 1.25.2.1 20-Oct-2006  ad The signal mask/stack will be per-LWP shortly.
 1.26.2.2 10-Dec-2006  yamt sync with head.
 1.26.2.1 22-Oct-2006  yamt sync with head
 1.30.2.4 12-Jun-2012  riz Pull up following revision(s) (requested by spz in ticket #1450):
sys/arch/amd64/amd64/machdep.c: revision 1.184
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.77
If the user process provided a bogus signal handler address, kill it
now instead of trying to jump to the bogus address.
 1.30.2.3 18-Oct-2009  bouyer Pull up following revision(s) (requested by mlelstv in ticket #1363):
sys/arch/i386/isa/npx.c: revision 1.132 via patch
sys/arch/amd64/amd64/fpu.c: revision 1.29 via patch
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.59 via patch
sys/arch/amd64/amd64/machdep.c: revision 1.105 via patch
sys/arch/i386/i386/machdep.c: revision 1.647 via patch
PR port-i386/39299 FPU use in signal handlers is unsafe
Ensure FP state is reset, if FP is used in a signal handler.
Fixes PR kern/39299 for 32bit code.
 1.30.2.2 18-Nov-2008  bouyer Pull up following revision(s) (requested by sborrill in ticket #1173):
sys/arch/x86/include/mtrr.h: revision 1.4
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.54
sys/arch/x86/x86/mtrr_i686.c: revision 1.18
hack around PR#38480:
- rename MTRR_I686_NVAR to MTRR_I686_NVAR_MAX, still set to 8
- store mtrr VCNT value into i686_mtrr_vcnt. if it is less than 8,
zero out the relevant parts of mtrr_raw[].msraddr
- replace all usage of MTRR_I686_NVAR with either i686_mtrr_vcnt or
with MTRR_I686_NVAR_MAX as appropriate
- in i686_mtrr_reload() and mtrr_init_first() don't use mtrr_raw[]
addresses of 0
still needs a bunch of reworking to handle VCNT > 8 case.
Ensure optional MTRR sections are built if MTRR is enabled (missing
Fix build due to changes in revision 1.4 of sys/arch/x86/include/mtrr.h
 1.30.2.1 06-Jan-2007  bouyer branches: 1.30.2.1.6;
Pull up following revision(s) (requested by elad in ticket #316):
share/examples/secmodel/secmodel_example.c: revision 1.10 via patch
sys/arch/i386/i386/sys_machdep.c: revision 1.79
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.31
share/man/man9/secmodel_bsd44.9: revision 1.9
sys/arch/vax/vax/mem.c: revision 1.34 via patch
sys/arch/sh3/sh3/mem.c: revision 1.23 via patch
sys/arch/sh5/sh5/mem.c: revision 1.14 via patch
sys/secmodel/bsd44/secmodel_bsd44_suser.c: revision 1.22 via patch
sys/arch/powerpc/powerpc/mem.c: revision 1.27 via patch
sys/arch/x86/x86/x86_machdep.c: revision 1.5
sys/arch/alpha/alpha/machdep.c: revision 1.291
sys/arch/arm/arm32/mem.c: revision 1.17 via patch
sys/secmodel/bsd44/secmodel_bsd44_securelevel.c: revision 1.20
sys/sys/kauth.h: revision 1.29 via patch
sys/arch/amd64/amd64/sys_machdep.c: revision 1.10
share/man/man9/kauth.9: revision 1.43 via patch
sys/arch/xen/i386/sys_machdep.c: revision 1.10
sys/kern/kern_auth.c: revision 1.35
sys/arch/pc532/pc532/mem.c: revision 1.43 via patch
Make machdep scope architecture-agnostic by removing all arch-specific
requests and centralizing them all. The result is that some of these
are not used on some architectures, but the documentation was updated
to reflect that.
 1.30.2.1.6.1 12-Jun-2012  riz Pull up following revision(s) (requested by spz in ticket #1450):
sys/arch/amd64/amd64/machdep.c: revision 1.184
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.77
If the user process provided a bogus signal handler address, kill it
now instead of trying to jump to the bogus address.
 1.32.2.5 17-May-2007  yamt sync with head.
 1.32.2.4 07-May-2007  yamt sync with head.
 1.32.2.3 24-Mar-2007  yamt sync with head.
 1.32.2.2 12-Mar-2007  rmind Sync with HEAD.
 1.32.2.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.37.6.1 18-Mar-2007  reinoud First attempt to bring branch in sync with HEAD
 1.37.4.1 11-Jul-2007  mjf Sync with head.
 1.37.2.4 15-Jul-2007  ad Sync with head.
 1.37.2.3 09-Jun-2007  ad Sync with head.
 1.37.2.2 27-May-2007  ad Sync with head.
 1.37.2.1 10-Apr-2007  ad Sync with head.
 1.39.2.3 03-Oct-2007  garbled Sync with HEAD
 1.39.2.2 26-Jun-2007  garbled Sync with HEAD.
 1.39.2.1 22-May-2007  matt Update to HEAD.
 1.43.10.3 23-Mar-2008  matt sync with HEAD
 1.43.10.2 09-Jan-2008  matt sync with HEAD
 1.43.10.1 06-Nov-2007  matt sync with HEAD
 1.44.8.2 19-Jan-2008  bouyer Sync with HEAD
 1.44.8.1 02-Jan-2008  bouyer Sync with HEAD
 1.44.4.1 26-Dec-2007  ad Sync with head.
 1.44.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.47.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.47.6.2 28-Sep-2008  mjf Sync with HEAD.
 1.47.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.48.2.2 04-Jun-2008  yamt sync with head
 1.48.2.1 18-May-2008  yamt sync with head.
 1.50.4.6 28-Sep-2008  skrll Adapt the SA COMPAT_NETBSD32 stuff to this branch.
 1.50.4.5 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.50.4.4 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.50.4.3 23-May-2008  wrstuden Re-add userret hook. Add a new define, SA_NO_USERRET, which
indicates that upcall support should NOT be included. Add this
for all non-netbsd emulations. They will never be SA apps, so
let's make the invarient pretty blatant.

NetBSD code should include both sys/sa.h and sys/savar.h.
 1.50.4.2 14-May-2008  wrstuden Per discussion with ad at n dot o, revert signal mask handling
changes.

The l_sigstk changes are most likely totally un-needed as SA will
never use a signal stack - we send an upcall (or will as other
diffs are brought in).

The l_sigmask changes were too controvertial. In all honesty, I
think it's probably best to revert them. The main reason they were
there is the fact that in an SA process, we don't mask signals per
kernel thread, we mask them per user thread. In the kernel, we want
them all to get turned into upcalls. Thus the normal state of
l_sigmask in an SA process is for it to always be empty.

While we are in the process of delivering a signal, we want to
temporarily mask a signal (so we don't recursively exhaust our
upcall stacks). However signal delivery is rare (important, but
rare), and delivering back-to-back signals is even rarer. So rather
than cause every user of a signal mask to be prepared for this very
rare case, we will just add a second check later in the signal
delivery code. Said change is not in this diff.

This also un-compensates all of our compatability code for dealing
with SA. SA is a NetBSD-specific thing, so there's no need for
Irix, Linux, Solaris, SVR4 and so on to cope with it.

As previously, everything other than kern_sa.c compiles in i386
GENERIC as of this checkin. I will switch to ALL soon for compile
testing.
 1.50.4.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.50.2.5 09-Oct-2010  yamt sync with head
 1.50.2.4 11-Aug-2010  yamt sync with head.
 1.50.2.3 11-Mar-2010  yamt sync with head
 1.50.2.2 19-Aug-2009  yamt sync with head.
 1.50.2.1 04-May-2009  yamt sync with head.
 1.51.4.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.51.4.1 19-Oct-2008  haad Sync with HEAD.
 1.55.8.2 20-May-2011  matt bring matt-nb5-mips64 up to date with netbsd-5-1-RELEASE (except compat).
 1.55.8.1 21-Apr-2010  matt sync to netbsd-5
 1.55.6.3 12-Jun-2012  riz Pull up following revision(s) (requested by spz in ticket #1773):
sys/arch/amd64/amd64/machdep.c: revision 1.184
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.77
If the user process provided a bogus signal handler address, kill it
now instead of trying to jump to the bogus address.
 1.55.6.2 07-Sep-2010  bouyer Pull up following revision(s) (requested by chs in ticket #1449):
sys/arch/amd64/amd64/netbsd32_machdep.c: revisions 1.66, 1.67
sys/arch/amd64/include/segments.h: revision 1.21
in check_mcontext32(), accept the LDT selector for 32-bit user code
as well as the GDT selector. fixes PR 43835.
accept the LDT selector in check_sigcontext32() too.
 1.55.6.1 16-Jul-2010  riz Apply patches (requested by chs in ticket #1424):
sys/arch/amd64/amd64/netbsd32_machdep.c: patch
sys/arch/i386/i386/trap.c: patch
Fix several panics that can be caused by applications using
bad segment register values with setcontext() or sigreturn().
 1.55.4.4 12-Jun-2012  riz Pull up following revision(s) (requested by spz in ticket #1773):
sys/arch/amd64/amd64/machdep.c: revision 1.184
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.77
If the user process provided a bogus signal handler address, kill it
now instead of trying to jump to the bogus address.
 1.55.4.3 07-Sep-2010  bouyer branches: 1.55.4.3.2;
Pull up following revision(s) (requested by chs in ticket #1449):
sys/arch/amd64/amd64/netbsd32_machdep.c: revisions 1.66, 1.67
sys/arch/amd64/include/segments.h: revision 1.21
in check_mcontext32(), accept the LDT selector for 32-bit user code
as well as the GDT selector. fixes PR 43835.
accept the LDT selector in check_sigcontext32() too.
 1.55.4.2 16-Jul-2010  riz Apply patches (requested by chs in ticket #1424):
sys/arch/amd64/amd64/netbsd32_machdep.c: patch
sys/arch/i386/i386/trap.c: patch
Fix several panics that can be caused by applications using
bad segment register values with setcontext() or sigreturn().
 1.55.4.1 03-Oct-2009  snj Pull up following revision(s) (requested by mlelstv in ticket #1048):
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.59
Ensure FP state is reset, if FP is used in a signal handler.
Fixes PR kern/39299 for 32bit code.
 1.55.4.3.2.1 12-Jun-2012  riz Pull up following revision(s) (requested by spz in ticket #1773):
sys/arch/amd64/amd64/machdep.c: revision 1.184
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.77
If the user process provided a bogus signal handler address, kill it
now instead of trying to jump to the bogus address.
 1.55.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.57.2.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.57.2.3 10-Jan-2011  jym Sync with HEAD
 1.57.2.2 24-Oct-2010  jym Sync with HEAD
 1.57.2.1 01-Nov-2009  jym Sync with HEAD.
 1.61.4.2 05-Mar-2011  rmind sync with head
 1.61.4.1 30-May-2010  rmind sync with head
 1.61.2.3 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.61.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.61.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.68.4.2 05-Mar-2011  bouyer Sync with HEAD
 1.68.4.1 08-Feb-2011  bouyer Sync with HEAD
 1.68.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.74.10.2 12-Jun-2012  riz Pull up following revision(s) (requested by spz in ticket #337):
sys/arch/amd64/amd64/machdep.c: revision 1.184
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.77
If the user process provided a bogus signal handler address, kill it
now instead of trying to jump to the bogus address.
 1.74.10.1 21-May-2012  riz Pull up following revision(s) (requested by martin in ticket #274):
sys/arch/amd64/amd64/process_machdep.c: revision 1.20
sys/kern/sys_lwp.c: revision 1.54
sys/arch/sparc64/sparc64/machdep.c: revision 1.267
sys/arch/mips/mips/cpu_subr.c: revision 1.16
sys/arch/vax/vax/machdep.c: revision 1.188
sys/sys/lwp.h: revision 1.161
sys/arch/sparc64/sparc64/netbsd32_machdep.c: revision 1.98
sys/arch/alpha/alpha/machdep.c: revision 1.339
sys/compat/sys/ucontext.h: revision 1.6
sys/arch/hppa/hppa/hppa_machdep.c: revision 1.28
distrib/sets/lists/tests/mi: revision 1.469
sys/arch/powerpc/powerpc/sig_machdep.c: revision 1.42
tests/lib/libc/sys/t_lwp_create.c: revision 1.1
tests/lib/libc/sys/Makefile: revision 1.23
sys/arch/arm/arm/sig_machdep.c: revision 1.42
sys/arch/amd64/include/mcontext.h: revision 1.15
sys/arch/amd64/amd64/machdep.c: revision 1.183
sys/arch/sh3/sh3/sh3_machdep.c: revision 1.99
sys/arch/i386/i386/machdep.c: revision 1.727
sys/compat/netbsd32/netbsd32_lwp.c: revision 1.13
sys/arch/sparc/sparc/machdep.c: revision 1.319
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.76
sys/arch/m68k/m68k/sig_machdep.c: revision 1.49
sys/sys/ucontext.h: revision 1.16
sys/arch/mips/mips/netbsd32_machdep.c: revision 1.9
lib/libc/sys/_lwp_create.2: revision 1.5
Calling _lwp_create() with a bogus ucontext could trigger a kernel
assertion failure (and thus a crash in DIAGNOSTIC kernels). Independently
discovered by YAMAMOTO Takashi and Joel Sing.
To avoid this, introduce a cpu_mcontext_validate() function and move all
sanity checks from cpu_setmcontext() there. Also untangle the netbsd32
compat mess slightly and add a cpu_mcontext32_validate() cousin there.
Add an exhaustive atf test case, based partly on code from Joel Sing.
Should finally fix the remaining open part of PR kern/43903.
 1.74.8.2 02-Jun-2012  mrg sync to latest -current.
 1.74.8.1 24-Feb-2012  mrg sync to -current.
 1.74.4.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.74.4.4 23-Jan-2013  yamt sync with head
 1.74.4.3 30-Oct-2012  yamt sync with head
 1.74.4.2 23-May-2012  yamt sync with head.
 1.74.4.1 17-Apr-2012  yamt sync with head
 1.79.2.3 03-Dec-2017  jdolecek update from HEAD
 1.79.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.79.2.1 25-Feb-2013  tls resync with head
 1.81.2.1 18-May-2014  rmind sync with head
 1.92.12.1 30-Jan-2019  martin Pull up following revision(s) (requested by maxv in ticket #1677):

sys/arch/hppa/hppa/sig_machdep.c: revision 1.26
sys/arch/arm/arm/sig_machdep.c: revision 1.51
sys/arch/i386/i386/machdep.c: revision 1.813
sys/arch/alpha/alpha/machdep.c: revision 1.352
sys/arch/m68k/m68k/sig_machdep.c: revision 1.50
sys/arch/usermode/target/i386/cpu_i386.c: revision 1.8
sys/arch/sparc64/sparc64/machdep.c: revision 1.289
sys/arch/sparc64/sparc64/netbsd32_machdep.c: revision 1.111
sys/arch/powerpc/powerpc/sig_machdep.c: revision 1.46
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.117
sys/arch/sh3/sh3/sh3_machdep.c: revision 1.106
sys/arch/mips/mips/netbsd32_machdep.c: revision 1.16
sys/arch/mips/mips/sig_machdep.c: revision 1.24
sys/arch/usermode/target/x86_64/cpu_x86_64.c: revision 1.7
sys/arch/vax/vax/sig_machdep.c: revision 1.23

Fix widespread leak in the sendsig_siginfo() functions. sigframe_siginfo
has padding, so zero it out properly. While here I'm also zeroing out some
other things in several ports, for safety. Same problem in netbsd32, so
fix that too.

I can't compile-test on each architecture, but there should be no
breakage (tm).

Overall this fixes at least 14 info leaks. Prompted by the discovery by
KLEAK of a leak in amd64's sendsig_siginfo.
 1.92.8.1 30-Jan-2019  martin Pull up following revision(s) (requested by maxv in ticket #1677):

sys/arch/hppa/hppa/sig_machdep.c: revision 1.26
sys/arch/arm/arm/sig_machdep.c: revision 1.51
sys/arch/i386/i386/machdep.c: revision 1.813
sys/arch/alpha/alpha/machdep.c: revision 1.352
sys/arch/m68k/m68k/sig_machdep.c: revision 1.50
sys/arch/usermode/target/i386/cpu_i386.c: revision 1.8
sys/arch/sparc64/sparc64/machdep.c: revision 1.289
sys/arch/sparc64/sparc64/netbsd32_machdep.c: revision 1.111
sys/arch/powerpc/powerpc/sig_machdep.c: revision 1.46
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.117
sys/arch/sh3/sh3/sh3_machdep.c: revision 1.106
sys/arch/mips/mips/netbsd32_machdep.c: revision 1.16
sys/arch/mips/mips/sig_machdep.c: revision 1.24
sys/arch/usermode/target/x86_64/cpu_x86_64.c: revision 1.7
sys/arch/vax/vax/sig_machdep.c: revision 1.23

Fix widespread leak in the sendsig_siginfo() functions. sigframe_siginfo
has padding, so zero it out properly. While here I'm also zeroing out some
other things in several ports, for safety. Same problem in netbsd32, so
fix that too.

I can't compile-test on each architecture, but there should be no
breakage (tm).

Overall this fixes at least 14 info leaks. Prompted by the discovery by
KLEAK of a leak in amd64's sendsig_siginfo.
 1.92.6.6 28-Aug-2017  skrll Sync with HEAD
 1.92.6.5 05-Feb-2017  skrll Sync with HEAD
 1.92.6.4 05-Dec-2016  skrll Sync with HEAD
 1.92.6.3 05-Oct-2016  skrll Sync with HEAD
 1.92.6.2 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.92.6.1 06-Apr-2015  skrll Sync with HEAD
 1.92.4.1 30-Jan-2019  martin Pull up following revision(s) (requested by maxv in ticket #1677):

sys/arch/hppa/hppa/sig_machdep.c: revision 1.26
sys/arch/arm/arm/sig_machdep.c: revision 1.51
sys/arch/i386/i386/machdep.c: revision 1.813
sys/arch/alpha/alpha/machdep.c: revision 1.352
sys/arch/m68k/m68k/sig_machdep.c: revision 1.50
sys/arch/usermode/target/i386/cpu_i386.c: revision 1.8
sys/arch/sparc64/sparc64/machdep.c: revision 1.289
sys/arch/sparc64/sparc64/netbsd32_machdep.c: revision 1.111
sys/arch/powerpc/powerpc/sig_machdep.c: revision 1.46
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.117
sys/arch/sh3/sh3/sh3_machdep.c: revision 1.106
sys/arch/mips/mips/netbsd32_machdep.c: revision 1.16
sys/arch/mips/mips/sig_machdep.c: revision 1.24
sys/arch/usermode/target/x86_64/cpu_x86_64.c: revision 1.7
sys/arch/vax/vax/sig_machdep.c: revision 1.23

Fix widespread leak in the sendsig_siginfo() functions. sigframe_siginfo
has padding, so zero it out properly. While here I'm also zeroing out some
other things in several ports, for safety. Same problem in netbsd32, so
fix that too.

I can't compile-test on each architecture, but there should be no
breakage (tm).

Overall this fixes at least 14 info leaks. Prompted by the discovery by
KLEAK of a leak in amd64's sendsig_siginfo.
 1.95.2.3 20-Mar-2017  pgoyette Sync with HEAD
 1.95.2.2 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.95.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.98.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.105.2.3 05-Apr-2019  martin Pull up following revision(s) (requested by maxv):

sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.120
sys/compat/linux/arch/amd64/linux_machdep.c: revision 1.57
sys/compat/linux32/arch/amd64/linux32_machdep.c: revision 1.44
sys/arch/amd64/amd64/machdep.c: revision 1.328
sys/arch/amd64/amd64/machdep.c: revision 1.329

Fix a tiny race in setregs and linux_setregs. Between the moment we set
pcb_flags to zero, and the moment cpu_segregs64_zero resets pcb_gs, we may
be preempted.

If this happens, and if the calling LWP was a 32bit thread, when switching
back to that LWP, the context switcher sees that PCB_COMPAT32 is not set in
pcb_flags and tries to perform a 64bit context switch; but pcb_gs contains
a 32bit GDT descriptor, and not a 64bit GS.base value. The wrmsr therefore
faults because the value is non-canonical, and this fault is fatal.

Rearrange the code so that the update of pcb_flags and pcb_gs/pcb_fs is non
interruptible. This fixes the problem, tested with a reproducer (which
therefore doesn't work anymore).

Likely fixes PR/53993.

Disable preemption when setting PCB_COMPAT32, to prevent a context switch
before cpu_fsgs_reload() finishes, otherwise we write garbage in the GDT.

On NetBSD-current it is harmless, however in NetBSD-8 it might cause
panics, because NetBSD-8 uses the old SegRegs model and under this model
we reload %fs and %gs during switches.
 1.105.2.2 27-Jan-2019  martin Pull up following revision(s) (requested by maxv in ticket #1173):
sys/arch/hppa/hppa/sig_machdep.c: revision 1.26
sys/arch/arm/arm/sig_machdep.c: revision 1.51
sys/arch/i386/i386/machdep.c: revision 1.813
sys/arch/alpha/alpha/machdep.c: revision 1.352
sys/arch/m68k/m68k/sig_machdep.c: revision 1.50
sys/arch/usermode/target/i386/cpu_i386.c: revision 1.8
sys/arch/sparc64/sparc64/machdep.c: revision 1.289
sys/arch/sparc64/sparc64/netbsd32_machdep.c: revision 1.111
sys/arch/powerpc/powerpc/sig_machdep.c: revision 1.46
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.117
sys/arch/sh3/sh3/sh3_machdep.c: revision 1.106
sys/arch/mips/mips/netbsd32_machdep.c: revision 1.16
sys/arch/mips/mips/sig_machdep.c: revision 1.24
sys/arch/riscv/riscv/sig_machdep.c: revision 1.2
sys/arch/usermode/target/x86_64/cpu_x86_64.c: revision 1.7
sys/arch/vax/vax/sig_machdep.c: revision 1.23

Fix widespread leak in the sendsig_siginfo() functions. sigframe_siginfo
has padding, so zero it out properly. While here I'm also zeroing out some
other things in several ports, for safety. Same problem in netbsd32, so
fix that too.

I can't compile-test on each architecture, but there should be no
breakage (tm).

Overall this fixes at least 14 info leaks. Prompted by the discovery by
KLEAK of a leak in amd64's sendsig_siginfo.
 1.105.2.1 21-Dec-2017  snj Pull up following revision(s) (requested by christos in ticket #444):
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.114
Keep fs/gs the same for the signal context; otherwise calling things
like __lwp_getprivate_fast() from a signal handler (that uses %gs) die.
Merge context building code.
 1.115.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.115.4.1 10-Jun-2019  christos Sync with HEAD
 1.115.2.19 25-Jan-2019  pgoyette Move the netbsd32_machine32_hook into the main kernel with most of
the other hooks.

Although this hook might better belong in compat/netbsd32/ code,
there are some machines without a netbsd32 module (for example, i386
and sgimips) which still have consumers/users of this hook. :(
 1.115.2.18 24-Jan-2019  pgoyette Rework placement of the new netbsd32_machine32_hook
 1.115.2.17 24-Jan-2019  pgoyette Replace weak symbol definition for machine32 with a hook. Our in-kernel
linker doesn't handle weak symbols, so this prevented us from loading the
compat_linux32 module.

XXX There don't seem to be any other consumers of machine32 (nor does
XXX there seem to be any consumers of machine_arch32), even though it
XXX is defined for aarch64, arm32, and riscv).
 1.115.2.16 22-Jan-2019  pgoyette Convert the MODULE_{,VOID_}HOOK_CALL macros to do everything in-line
rather than defining an intermediate hook##call function. Almost
all of the hooks are called only once, and although we lose the
ability of doing things like

if (MODULE_HOOK_CALL(...) == 0) ...

we simplify things quite a bit. With this change, we no longer need
to have both declaration and definition macros, and the definition
no longer needs to have both prototype argument list and a "real"
argument list.

FWIW, the above if now needs to written as

int ret;

MODULE_HOOK_CALL(..., ret);
if (ret == 0) ...

with appropriate use of braces {}.
 1.115.2.15 21-Jan-2019  pgoyette No need to declare the hook_call() function for void hooks. So
remove and simplify.
 1.115.2.14 14-Jan-2019  pgoyette Create a variant of the HOOK macros that handles hook routines of
type void, and use them where appropriate.
 1.115.2.13 13-Jan-2019  pgoyette Remove the HOOK2 versions of the MODULE_HOOK macros. There were
only a few uses, and using them led to some lack of clarity in the
code. Instead, we now use two separate hooks, with names that
make it clear(er) what we're doing.

This also positions us to start unraveling some of the rtsock_50
mess, which will need (at least) five hooks.
 1.115.2.12 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.115.2.11 29-Sep-2018  pgoyette In MODULE_HOOK_CALL_DECL we don't need to provide the actual argument
list for calling the hook function, nor do we need to provide the
default value (for when the hook has not been set).
 1.115.2.10 29-Sep-2018  pgoyette Allocate the netbsd32_sendsig_hook in the main compat_netbsd32 code
(where it call be called) and not in a subsidiary module which may
not even exist.
 1.115.2.9 29-Sep-2018  pgoyette Remove some spurious declarations.
 1.115.2.8 27-Sep-2018  pgoyette Make sure we pick up the definition of COMPAT_NETBSD32
 1.115.2.7 24-Sep-2018  pgoyette Adjust declaration of netbsd32_sendsig_siginfo() too.

Remove the attempted initialization of the former function pointer; this
is now handled by the "default" argument in MODULE_HOOK_CALL() macro.
 1.115.2.6 24-Sep-2018  pgoyette Make the netbsd32_sendsig_siginfo() routine return an int, to conform
to the MP-safe HOOKs mechanism.
 1.115.2.5 24-Sep-2018  pgoyette Provide required args when calling the default (un-hooked) routine.
 1.115.2.4 24-Sep-2018  pgoyette Convert yet another function pointer to the MP-safe mechanism
 1.115.2.3 14-Sep-2018  pgoyette OMG it builds!

Finish rearranging the amd64 MD compat_netbsd32 code.

XXX Other architectures will be dealt with later.
 1.115.2.2 14-Sep-2018  pgoyette Work in progress - get the arch-specific netbsd32_machdep.c code to
build as a module.

XXX Doesn't work when the code is built-in to the kernel.
 1.115.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.125.2.2 27-Nov-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #488):

sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.126

Don't depend on #ifdef USER_LDT in cpu_mcontext32_validate(), but rather on
whether the proc uses a user-set LDT. Same as check_sigcontext32().
 1.125.2.1 21-Nov-2019  martin Pull up following revision(s) (requested by rin in ticket #460):

sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.130

Fix netbsd32_process_write_dbregs() for amd64:
- Zero-clear regs64 so that random values are not written into the
preserved registers.
- Cast 32-bit registers (int) to u_int, in order to avoid undesired
sign extension when filled into 64-bit registers (long).

XXX
pullup to netbsd-9
 1.133.6.1 25-Apr-2020  bouyer Sync with bouyer-xenpvh-base2 (HEAD)
 1.136.2.1 14-Dec-2020  thorpej Sync w/ HEAD.
 1.141.10.1 02-Aug-2025  perseant Sync with HEAD
 1.5 20-Dec-2023  thorpej Remove unnecessary <sys/malloc.h>.
 1.4 19-Jul-2020  maxv don't include opt_user_ldt.h when it is not needed
 1.3 13-Nov-2019  pgoyette Clean-up unnecessary inclusions of opt_coredump.h
 1.2 27-Jan-2019  pgoyette branches: 1.2.4;
Merge the [pgoyette-compat] branch
 1.1 14-Sep-2018  pgoyette branches: 1.1.2;
file netbsd32_machdep_13.c was initially added on branch pgoyette-compat.
 1.1.2.2 27-Sep-2018  pgoyette Add empty init/fini routines so MI code can call them.
 1.1.2.1 14-Sep-2018  pgoyette Work in progress - get the arch-specific netbsd32_machdep.c code to
build as a module.

XXX Doesn't work when the code is built-in to the kernel.
 1.2.4.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.2.4.2 10-Jun-2019  christos Sync with HEAD
 1.2.4.1 27-Jan-2019  christos file netbsd32_machdep_13.c was added on branch phil-wifi on 2019-06-10 22:05:47 +0000
 1.8 20-Dec-2023  thorpej Remove unnecessary <sys/malloc.h>.
 1.7 06-Nov-2021  thorpej COMPAT_NETBSD32 is all about running the 32-bit flavor of native
binaries on a 64-bit platform[*], as such:
- Make the logic about which "sendsig" flavor to call MI (as it is in the
native 64-bit environment) and follow the same rules as the native 32-bit
environment.
- Make COMPAT_NETBSD32 x COMPAT_16 work the same as it would in the
native 32-bit environment by providing a netbsd32_sendsig_sigcontext_16_hook,
rather than overriding the entire sendsig logic with a netbsd32_sendsig_hook.
- In netbsd32___sigaction_sigtramp(), make sure the compat_netbsd32_16
module is loaded if the trampoline version specifies a sigcontext style
handler, otherwise return EINVAL so that libc can try again with siginfo
style.

[*] ...except for arm32, which uses it to mean "run 32-bit OABI binaries
from the 32-bit EABI environment". Doing it this way was arguably a mistake,
but we are stuck with it for now, so support it by providing a machine-
dependent override for netbsd32_sendsig() that also disables the corresponding
logic in netbsd32___sigaction_sigtramp().

Fixes PR kern/56487.
 1.6 27-Oct-2021  thorpej Use the signal trampoline version constants from <sys/signal.h>.
 1.5 12-Dec-2019  pgoyette Rather than keeping a separate mutex, condvar, and pserialize for each
module hook, we can share a common set of synchronization structures.
This cuts the amount of cacheline_aligned data for these structures by
50%.

Note that we still have a per-hook localcount, since we need to count
individual references.

As discussed with riastradh@

Welcome to 9.99.22 !
 1.4 13-Nov-2019  pgoyette Clean-up unnecessary inclusions of opt_coredump.h
 1.3 01-Mar-2019  pgoyette branches: 1.3.4;
Rename the MODULE_*_HOOK() macros to MODULE_HOOK_*() as briefly
discussed on irc.

NFCI intended.

Ride the earlier kernel bump - it;s getting crowded.
 1.2 27-Jan-2019  pgoyette Merge the [pgoyette-compat] branch
 1.1 14-Sep-2018  pgoyette branches: 1.1.2;
file netbsd32_machdep_16.c was initially added on branch pgoyette-compat.
 1.1.2.12 23-Jan-2019  pgoyette Convert the macros for setting and unsetting a hook to generate
in-line code rather than using an intermediary hook##set routine.
Hooks are set and unset only in one place, so the intermediary
routine provides no benefit. IMHO using the macro at the point-
of-call is more readable than using it elsewhere in the code and
then calling the generated intermediary routine (for which you
won't even find its declaration or definition unless you remember
to search for the HOOK_SET macro instead).

NFC intended, will verify with a bulk build and an atf test run.
 1.1.2.11 14-Jan-2019  pgoyette Create a variant of the HOOK macros that handles hook routines of
type void, and use them where appropriate.
 1.1.2.10 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.1.2.9 29-Sep-2018  pgoyette Allocate the netbsd32_sendsig_hook in the main compat_netbsd32 code
(where it call be called) and not in a subsidiary module which may
not even exist.
 1.1.2.8 29-Sep-2018  pgoyette Wrap long line, KNF
 1.1.2.7 25-Sep-2018  pgoyette In the xxx_fini() routine we need to _un_set the hook!
 1.1.2.6 25-Sep-2018  pgoyette Make the replacement/hook function return an int, to match the
expectations of the MP-safe HOOK mechanism.
 1.1.2.5 25-Sep-2018  pgoyette And use proper macro names
 1.1.2.4 25-Sep-2018  pgoyette If we're going to use the MP-safe HOOK macros, it helps to define them
by including the proper header!
 1.1.2.3 24-Sep-2018  pgoyette Convert yet another function pointer to the MP-safe mechanism
 1.1.2.2 14-Sep-2018  pgoyette OMG it builds!

Finish rearranging the amd64 MD compat_netbsd32 code.

XXX Other architectures will be dealt with later.
 1.1.2.1 14-Sep-2018  pgoyette Work in progress - get the arch-specific netbsd32_machdep.c code to
build as a module.

XXX Doesn't work when the code is built-in to the kernel.
 1.3.4.4 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.3.4.3 08-Apr-2020  martin Merge changes from current as of 20200406
 1.3.4.2 10-Jun-2019  christos Sync with HEAD
 1.3.4.1 01-Mar-2019  christos file netbsd32_machdep_16.c was added on branch phil-wifi on 2019-06-10 22:05:47 +0000
 1.9 14-Jul-2018  maxv Drop NENTRY() from the x86 kernels, use ENTRY(). With PMCs (and other hardware
tracing facilities) we have a much better ways of monitoring the CPU activity
than GPROF, without software modification.

Also I think GPROF has never worked, because the 'start' functions of both
i386 and amd64 use ENTRY(), and it would have caused a function call while the
kernel was not yet relocated.
 1.8 01-Nov-2017  maxv branches: 1.8.2; 1.8.4;
More END(). In linux_sigcode.S we only provide symbols, not defined as
functions.
 1.7 28-Apr-2008  martin branches: 1.7.44;
Remove clause 3 and 4 from TNF licenses
 1.6 11-Dec-2005  christos branches: 1.6.74; 1.6.76; 1.6.78;
merge ktrace-lwp.
 1.5 26-Mar-2004  drochner the whole sigcode business is COMPAT_16 only
 1.4 25-Mar-2004  drochner Native code doesn't need sigcode. Never.
So replace it by a dummy setting sigcode=esigcode=0, just to get
COMPAT_16+COMPAT_NETBSD32 kernels linking.
 1.3 25-Mar-2004  drochner clean up the .globl confusion
 1.2 14-May-2003  fvdl branches: 1.2.2;
Add RCS Id and/or copyright notice.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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.78.1 16-May-2008  yamt sync with head.
 1.6.76.1 18-May-2008  yamt sync with head.
 1.6.74.1 02-Jun-2008  mjf Sync with HEAD.
 1.7.44.1 03-Dec-2017  jdolecek update from HEAD
 1.8.4.1 10-Jun-2019  christos Sync with HEAD
 1.8.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.34 05-Oct-2023  ad Arrange to update cached LWP credentials in userret() rather than during
syscall/trap entry, eliminating a test+branch on every syscall/trap.

This wasn't possible in the 3.99.x timeframe when l->l_cred came about
because there wasn't a reliable/timely way to force an ONPROC LWP running on
a remote CPU into the kernel (which is just about the only new thing in
this scheme).
 1.33 07-Mar-2015  christos add dtrace hooks
 1.32 16-May-2014  njoly branches: 1.32.4;
Do not compute code value more than once. Remove unneeded before
trace_enter()/trace_exit() calls.

This fix some cases where tracing show unexpected SYSRET number value
because some syscalls, such as setcontext(2), modified the trapframe
register values.
 1.31 20-Dec-2010  matt branches: 1.31.18; 1.31.22; 1.31.32;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.
 1.30 21-Nov-2009  rmind branches: 1.30.4;
Use lwp_getpcb() on x86 MD code, clean from struct user usage.
 1.29 21-Oct-2008  ad branches: 1.29.8;
Provide a small inline wrapper for sysent::sy_call() and use it to store
the active syscall description in struct lwp. To be used at some future
point to prevent unloading of modules that provide syscalls, while the
syscalls are in use.
 1.28 28-Apr-2008  martin branches: 1.28.2; 1.28.6;
Remove clause 3 and 4 from TNF licenses
 1.27 24-Apr-2008  ad branches: 1.27.2;
- Retire SYCALL_MPSAFE. With the exceptions of darwin and irix emulations,
all system calls are now MPSAFE.
- Remove unneeded acquire/release of kernel_lock.
 1.26 11-Mar-2008  ad branches: 1.26.2;
Make context switch + syscall counters optionally per-CPU and accumulate
in schedclock() at "about 16 hz".
 1.25 24-Feb-2008  dsl Set p->p_trace_enabled in fork and whenever the controlling falgs change
instead of doing it in syscall_intern().
Note that syscall_intern() must still be called when the flags change
since many ports use a different copy of the syscall entry code when
tracing is enabled.
 1.24 06-Feb-2008  dsl branches: 1.24.2; 1.24.6;
Remove the 'args' parameter to 'trace_exit()' it is no longer used.
Instead of passing the (un)real system call code and syscall table pointer,
just pass the number of arguments - which is what ktrace really wants.
Ride forthcoming 4.99.53
 1.23 05-Jan-2008  dsl Don't pass 'curlwp' into trace_enter() and trace_exit().
 1.22 31-Dec-2007  ad Remove systrace. Ok core@.
 1.21 09-Nov-2007  dsl branches: 1.21.6;
Don't intercept sys_syscall and sys___syscall here, just call the MI code.
 1.20 04-Nov-2007  dsl branches: 1.20.2;
Kill netbsd32_syscall_fancy and optimise other code paths.
Current gcc manages to compile this without spilling any locals onto the
stack.
 1.19 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.18 15-Aug-2007  ad branches: 1.18.2; 1.18.6;
Changes to make ktrace LKM friendly and reduce ifdef KTRACE. Proposed
on tech-kern.
 1.17 04-Mar-2007  yamt branches: 1.17.2; 1.17.10; 1.17.14; 1.17.18;
fix fallout from caddr_t changes.
 1.16 04-Mar-2007  christos Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.15 17-Feb-2007  pavel Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.
 1.14 09-Feb-2007  ad branches: 1.14.2;
Merge newlock2 to head.
 1.13 19-Jul-2006  ad branches: 1.13.4;
- Hold a reference to the process credentials in each struct lwp.
- Update the reference on syscall and user trap if p_cred has changed.
- Collect accounting flags in the LWP, and collate on LWP exit.
 1.12 07-Mar-2006  thorpej branches: 1.12.2;
Syscall debug tracing is handled by trace_enter() / trace_exit(). Change
trace_is_enabled() to return TRUE if SYSCALL_DEBUG is defined, and g/c
all of the SYSCALL_DEBUG handling from individual system call dispatch
routines.
 1.11 07-Mar-2006  thorpej Clean up fallout proc_is_traced_p() change:
- proc_is_traced_p() -> trace_is_enabled(), to match trace_enter() and
trace_exit().
- trace_is_enabled() becomes a real function.
- Remove unnecessary include files from various files that used to care
about KTRACE and SYSTRACE, but do no more.
 1.10 05-Mar-2006  christos Add a proc_is_traced_p() macro and use it, instead of copying the same code
in many places. Idea from thorpej.
 1.9 05-Mar-2006  christos branches: 1.9.2;
implement PT_SYSCALL
 1.8 20-Jan-2006  cube branches: 1.8.2; 1.8.4;
ktrace-lwp fallout for SYSCALL_DEBUG. From Vasily Levchenko.
 1.7 11-Dec-2005  christos branches: 1.7.2;
merge ktrace-lwp.
 1.6 01-Jul-2005  christos branches: 1.6.2;
PR/29607: Christian Biere systrace doesn't handle interrupted syscalls properly
Instead of jumping to the default "bad" case, jump to the error handling
switch, so that we can deal with ERESTART/EJUSTRETURN properly.
 1.5 13-Feb-2004  drochner grab the kernel lock during 32-bit syscalls too
 1.4 31-Oct-2003  simonb Don't pass the (unused) return value args to the
trace_enter()/systrace_enter() functions.
 1.3 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.2 14-Jul-2003  lukem __KERNEL_RCSID()
 1.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.2.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 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.6.2.9 17-Mar-2008  yamt sync with head.
 1.6.2.8 27-Feb-2008  yamt sync with head.
 1.6.2.7 11-Feb-2008  yamt sync with head.
 1.6.2.6 21-Jan-2008  yamt sync with head
 1.6.2.5 15-Nov-2007  yamt sync with head.
 1.6.2.4 03-Sep-2007  yamt sync with head.
 1.6.2.3 26-Feb-2007  yamt sync with head.
 1.6.2.2 30-Dec-2006  yamt sync with head.
 1.6.2.1 21-Jun-2006  yamt sync with head.
 1.7.2.1 01-Feb-2006  yamt sync with head.
 1.8.4.1 22-Apr-2006  simonb Sync with head.
 1.8.2.1 09-Sep-2006  rpaulo sync with head
 1.9.2.3 11-Aug-2006  yamt sync with head
 1.9.2.2 13-Mar-2006  yamt sync with head.
 1.9.2.1 05-Mar-2006  yamt file netbsd32_syscall.c was added on branch yamt-pdpolicy on 2006-03-13 09:06:51 +0000
 1.12.2.2 07-Mar-2006  thorpej Syscall debug tracing is handled by trace_enter() / trace_exit(). Change
trace_is_enabled() to return TRUE if SYSCALL_DEBUG is defined, and g/c
all of the SYSCALL_DEBUG handling from individual system call dispatch
routines.
 1.12.2.1 07-Mar-2006  thorpej file netbsd32_syscall.c was added on branch elad-kernelauth on 2006-03-07 07:21:51 +0000
 1.13.4.3 30-Jan-2007  ad Remove support for SA. Ok core@.
 1.13.4.2 11-Jan-2007  ad Checkpoint work in progress.
 1.13.4.1 17-Nov-2006  ad Checkpoint work in progress.
 1.14.2.2 12-Mar-2007  rmind Sync with HEAD.
 1.14.2.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.17.18.3 11-Nov-2007  joerg Sync with HEAD.
 1.17.18.2 04-Nov-2007  jmcneill Sync with HEAD.
 1.17.18.1 16-Aug-2007  jmcneill Sync with HEAD.
 1.17.14.1 03-Sep-2007  skrll Sync with HEAD.
 1.17.10.1 03-Oct-2007  garbled Sync with HEAD
 1.17.2.2 03-Dec-2007  ad Sync with HEAD.
 1.17.2.1 20-Aug-2007  ad Sync with HEAD.
 1.18.6.1 13-Nov-2007  bouyer Sync with HEAD
 1.18.2.3 23-Mar-2008  matt sync with HEAD
 1.18.2.2 09-Jan-2008  matt sync with HEAD
 1.18.2.1 06-Nov-2007  matt sync with HEAD
 1.20.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.20.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.21.6.2 08-Jan-2008  bouyer Sync with HEAD
 1.21.6.1 02-Jan-2008  bouyer Sync with HEAD
 1.24.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.24.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.24.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.24.2.1 24-Mar-2008  keiichi sync with head.
 1.26.2.1 18-May-2008  yamt sync with head.
 1.27.2.3 11-Mar-2010  yamt sync with head
 1.27.2.2 04-May-2009  yamt sync with head.
 1.27.2.1 16-May-2008  yamt sync with head.
 1.28.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.28.2.2 15-Oct-2008  wrstuden Remove some now-unneeded includes. Matches previous changes to i386 code.
 1.28.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.29.8.2 10-Jan-2011  jym Sync with HEAD
 1.29.8.1 24-Oct-2010  jym Sync with HEAD
 1.30.4.1 05-Mar-2011  rmind sync with head
 1.31.32.1 10-Aug-2014  tls Rebase.
 1.31.22.1 18-May-2014  rmind sync with head
 1.31.18.2 03-Dec-2017  jdolecek update from HEAD
 1.31.18.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.32.4.1 06-Apr-2015  skrll Sync with HEAD
 1.44 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.43 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.42 12-Oct-2007  ad branches: 1.42.2;
crit_enter/crit_exit are now available.
 1.41 01-Sep-2007  yamt branches: 1.41.2;
revert a part of the previous. (typo in a comment)
 1.40 01-Sep-2007  yamt reduce cosmetic differences between i386 and amd64 pmaps.
(whitespace, ansify, etc.)
no functional changes are intended.
 1.39 30-Aug-2007  ad Grr. Add a couple more #ifdef MULTIPROCESSOR.
 1.38 29-Aug-2007  ad 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.37 04-Jun-2007  xtraeme branches: 1.37.4; 1.37.8; 1.37.10;
Ansify, de-__P(), unregister.
 1.36 21-May-2007  fvdl Revert fs/gs changes until I figure out issues with them.
 1.35 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.34 11-May-2007  fvdl Don't save/restore %fs and %gs in trapframe. The kernel won't touch them.
Instead, save/restore them on context switch. For 32bit processes, save/restore
the selector values only, for 64bit processes, save/restore the appropriate
MSRs. Iff the defaults have been changed.
 1.33 12-Mar-2007  ad branches: 1.33.2; 1.33.6; 1.33.8;
Pass an ipl argument to pool_init/POOL_INIT to be used when initializing
the pool's lock.
 1.32 04-Mar-2007  yamt branches: 1.32.2;
fix fallout from caddr_t changes.
 1.31 04-Mar-2007  christos Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.30 22-Feb-2007  thorpej TRUE -> true, FALSE -> false
 1.29 21-Feb-2007  thorpej 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.28 06-Jan-2007  pavel branches: 1.28.2;
PR port-i386/34186 by Wolfgang Stukenbrock:
mapping of msgbuf during startup may map invalid physical adresses

Apply a similar patch as in the i386 case.
The amd64 version was supplied by Blair Sadewitz, thanks.
 1.27 05-Jul-2006  drochner branches: 1.27.4; 1.27.8;
obey VM_PROT_EXECUTE in pmap_kenter_pa (just use protection_codes[])
 1.26 21-May-2006  dan branches: 1.26.2;
initialise a few "off"s to appease gcc4
these only turned up with -O2 and/or -march=nocona, not with default flags
 1.25 15-May-2006  dogcow branches: 1.25.2;
remove bitrotted functions that have never been used, and have been
cargo-culted from one port to another.
 1.24 24-Dec-2005  perry branches: 1.24.4; 1.24.6; 1.24.8; 1.24.12;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.23 11-Dec-2005  christos merge ktrace-lwp.
 1.22 04-Aug-2005  fvdl In pmap_map(), do not do TLB shootdowns. It is only used for kernel dumps,
at which point other CPUs are likely halted, and the addresses mappped
are temporary anyway.
 1.21 04-Jul-2005  blymn branches: 1.21.2;
Reverse renaming of variable (pd_ents -> pdes) since the clashing
declaration in pmap.h was not used so it was removed from there.
 1.20 01-Jun-2005  blymn Rename function variables that shadowed globals.
 1.19 29-May-2005  chs in pmap_enter(), preset the mod/ref bits based on the flags argument.
fixes 25640.
 1.18 17-May-2005  fvdl Get the pcb_flags test right for the 64bit FS base case.
 1.17 15-May-2005  fvdl Optionally include saving and restoring the 64bit %gs and %fs base register
values in the PCB. Do this in pmap_activate for now (XXX not a good place
for it, but a convenient one).
 1.16 01-Apr-2005  yamt merge yamt-km branch.
- don't use managed mappings/backing objects for wired memory allocations.
save some resources like pv_entry. also fix (most of) PR/27030.
- simplify kernel memory management API.
- simplify pmap bootstrap of some ports.
- some related cleanups.
 1.15 01-Jan-2005  yamt branches: 1.15.2; 1.15.4; 1.15.8;
for in-kernel maps,
- allocate kva for vm_map_entry from the map itsself and
remove the static limit, MAX_KMAPENT.
- keep merged entries for later splitting to fix allocate-to-free problem.
PR/24039.
 1.14 10-Aug-2004  drochner The amd64 address space layout is different.
We can't assume that kernel addresses are below
VM_MAX_KERNEL_ADDRESS.
 1.13 08-Aug-2004  yamt reduce gratuitous whitespace/comment differences from i386.
 1.12 15-Jun-2004  fvdl Implement pmap_changeprot_local
 1.11 04-Jun-2004  sekiya Use the SPLAY_* macros. Copied from the i386 pmap, okay'ed by fvdl@
 1.10 31-May-2004  sekiya Make pmap_collect() a NOP -- due to the way we deal with the four-level pte,
invalidating the entire address space results in multi-minute system hangs.

Okay'ed by fvdl@
 1.9 19-Feb-2004  drochner branches: 1.9.2;
use no-execute page permissions if supported
 1.8 13-Feb-2004  wiz Uppercase CPU, plural is CPUs.
 1.7 14-Jul-2003  lukem __KERNEL_RCSID()
 1.6 23-Jun-2003  martin branches: 1.6.2;
Make sure to include opt_foo.h if a defflag option FOO is used.
 1.5 27-May-2003  fvdl Another pair of locks to pacify UVM (XXX -- not needed).
 1.4 10-May-2003  thorpej Back out the following chagne:
http://mail-index.netbsd.org/source-changes/2003/05/08/0068.html

There were some side-effects that I didn't anticipate, and fixing them
is proving to be more difficult than I thought, do just eject for now.
Maybe one day we can look at this again.

Fixes PR kern/21517.
 1.3 08-May-2003  thorpej Simplify the way the bounds of the managed kernel virtual address
space is advertised to UVM by making virtual_avail and virtual_end
first-class exported variables by UVM. Machine-dependent code is
responsible for initializing them before main() is called. Anything
that steals KVA must adjust these variables accordingly.

This reduces the number of instances of this info from 3 to 1, and
simplifies the pmap(9) interface by removing the pmap_virtual_space()
function call, and removing two arguments from pmap_steal_memory().

This also eliminates some kludges such as having to burn kernel_map
entries on space used by the kernel and stolen KVA.

This also eliminates use of VM_{MIN,MAX}_KERNEL_ADDRESS from MI code,
this giving MD code greater flexibility over the bounds of the managed
kernel virtual address space if a given port's specific platforms can
vary in this regard (this is especially true of the evb* ports).
 1.2 07-May-2003  fvdl Fix some locking nits found by LOCKDEBUG. Somewhat ugly, since they're
not really needed. But, they're not called very frequently.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.6.2.7 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.6.2.6 01-Apr-2005  skrll Sync with HEAD.
 1.6.2.5 17-Jan-2005  skrll Sync with HEAD.
 1.6.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.6.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.6.2.2 12-Aug-2004  skrll Sync with HEAD.
 1.6.2.1 03-Aug-2004  skrll Sync with HEAD
 1.9.2.2 08-Jun-2005  tron Pull up revision 1.19 (requested by chs in ticket #1980):
in pmap_enter(), preset the mod/ref bits based on the flags argument.
fixes 25640.
 1.9.2.1 01-Jun-2004  jmc branches: 1.9.2.1.2;
Pullup rev 1.10 (requested by sekiya in ticket #429)

Make pmap_collect() a NOP -- due to the way we deal with the four-level pte,
invalidating the entire address space results in multi-minute system hangs.
 1.9.2.1.2.1 08-Jun-2005  tron Pull up revision 1.19 (requested by chs in ticket #1980):
in pmap_enter(), preset the mod/ref bits based on the flags argument.
fixes 25640.
 1.15.8.3 30-Apr-2009  snj Apply patch (requested by bouyer in ticket #2012):
Fix a pmap race.
 1.15.8.2 14-Feb-2006  tron branches: 1.15.8.2.2;
Apply patch (requested by chs in ticket #1166):
Preallocate additional pv_entry structures in the pmap to allow
malloc() bootstrapping to succeed.
 1.15.8.1 06-Jun-2005  tron branches: 1.15.8.1.2;
Pull up revision 1.19 (requested by chs in ticket #424):
in pmap_enter(), preset the mod/ref bits based on the flags argument.
fixes 25640.
 1.15.8.2.2.1 30-Apr-2009  snj Apply patch (requested by bouyer in ticket #2012):
Fix a pmap race.
 1.15.8.1.2.1 30-Apr-2009  snj Apply patch (requested by bouyer in ticket #2012):
Fix a pmap race.
 1.15.4.1 13-Feb-2005  yamt - use new apis.
- simplify pmap bootstrap and pv_page allocation.
 1.15.2.1 29-Apr-2005  kent sync with -current
 1.21.2.5 27-Oct-2007  yamt sync with head.
 1.21.2.4 03-Sep-2007  yamt sync with head.
 1.21.2.3 26-Feb-2007  yamt sync with head.
 1.21.2.2 30-Dec-2006  yamt sync with head.
 1.21.2.1 21-Jun-2006  yamt sync with head.
 1.24.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.24.8.2 11-Aug-2006  yamt sync with head
 1.24.8.1 24-May-2006  yamt sync with head.
 1.24.6.1 01-Jun-2006  kardel Sync with head.
 1.24.4.1 09-Sep-2006  rpaulo sync with head
 1.25.2.1 19-Jun-2006  chap Sync with head.
 1.26.2.1 13-Jul-2006  gdamore Merge from HEAD.
 1.27.8.1 07-Feb-2007  tron Pull up following revision(s) (requested by pavel in ticket #397):
sys/arch/amd64/amd64/machdep.c: revision 1.45
sys/arch/amd64/amd64/pmap.c: revision 1.28
PR port-i386/34186 by Wolfgang Stukenbrock:
mapping of msgbuf during startup may map invalid physical adresses
Apply a similar patch as in the i386 case.
The amd64 version was supplied by Blair Sadewitz, thanks.
 1.27.4.1 12-Jan-2007  ad Sync with head.
 1.28.2.5 17-May-2007  yamt sync with head.
 1.28.2.4 24-Mar-2007  yamt sync with head.
 1.28.2.3 12-Mar-2007  rmind Sync with HEAD.
 1.28.2.2 03-Mar-2007  yamt adapt amd64.

XXX changes in identcpu.c is minmum for MONITOR.
XXX identcpu.c should be shared with i386.
 1.28.2.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.32.2.13 23-Oct-2007  ad Sync with head.
 1.32.2.12 09-Oct-2007  ad Sync with head.
 1.32.2.11 09-Oct-2007  ad Sync with head.
 1.32.2.10 09-Oct-2007  ad Sync with head.
 1.32.2.9 01-Sep-2007  ad Use pool_cache for allocating a few more types of objects.
 1.32.2.8 26-Aug-2007  yamt revert a debug printf which slipped in mistakenly.
 1.32.2.7 23-Aug-2007  ad - pmap_clear_attrs: merge shootdown reduction from i386.
- pmap_unwire: merge fix from i386, the PTE was not being updated atomically.
 1.32.2.6 23-Aug-2007  ad Pull a few more minor changes from the i386 pmap. In particular, try to
avoid issuing shootdowns if modified PTEs haven't been referenced by an
MMU. This is a stopgap until the two pmaps are merged..
 1.32.2.5 23-Aug-2007  ad Misc. fixes to previous.
 1.32.2.4 21-Aug-2007  ad amd64 changes, as yet untested:

- Adapt to vmlocking branch.
- Apply TLB shootdown and pv allocation changes to the pmap.
- Make it build.
 1.32.2.3 09-Jun-2007  ad Sync with head.
 1.32.2.2 27-May-2007  ad Sync with head.
 1.32.2.1 13-Mar-2007  ad Sync with head.
 1.33.8.4 16-Oct-2007  garbled Sync with HEAD
 1.33.8.3 03-Oct-2007  garbled Sync with HEAD
 1.33.8.2 26-Jun-2007  garbled Sync with HEAD.
 1.33.8.1 22-May-2007  matt Update to HEAD.
 1.33.6.1 18-Apr-2007  thorpej Convert i386 and amd64 to the new atomic ops API.
 1.33.2.1 11-Jul-2007  mjf Sync with head.
 1.37.10.1 06-Nov-2007  matt sync with HEAD
 1.37.8.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.37.8.3 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.37.8.2 06-Sep-2007  jmcneill lo32_paddr is a paddr_t, not vaddr_t
 1.37.8.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.37.4.1 03-Sep-2007  skrll Sync with HEAD.
 1.41.2.1 30-Sep-2007  yamt implement deferred pmap switching for amd64, and make amd64 use
x86 shared pmap code. it makes several i386 pmap improvements available
to amd64, including tlb shootdown reduction and bug fixes from Stephan Uphoff.
 1.42.2.6 25-Oct-2007  bouyer Sync with HEAD.
 1.42.2.5 21-Oct-2007  bouyer Protect xpq_* usage with splvm()
Make sure xen_current_user_pgd really reflects what's in the hypervisor.
 1.42.2.4 21-Oct-2007  bouyer Factorise some Xen pmap code in x86_xpmap.c.
More xpmap_{ptom,mtop} -> xpmap_{ptom,mtop}_masked

The xenamd64 kernel is now good enough to complete a sysinst install from
xennet to xbd.
 1.42.2.3 20-Oct-2007  bouyer Don't forget to mask pte entries with PG_FRAME to properly ignore the highter
reseved bits (xpmap_mtop doesn't do it).
Use xpmap_{mtop,ptom}_masked() in more places, it's a couple less instructions
than the non-masked versions.
 1.42.2.2 18-Oct-2007  bouyer pmap_extract(): make sure to mask the PTE flags from the returned value.
While there, use xpmap_mtop_masked() in more places.
 1.42.2.1 17-Oct-2007  bouyer amd64 (aka x86-64) support for Xen. Based on the OpenBSD port done by
Mathieu Ropert in 2006.
DomU-only for now. An INSTALL_XEN3_DOMU kernel with a ramdisk will boot to
sysinst if you're lucky. Often it panics because a runable LWP has
a NULL stack (really, it's all of l->l_addr which is has been zeroed out
while the process was on the queue !)
TODO:
- bug fixes :)
- Most of the xpq_* functions should be shared with xen/i386
- The xen/i386 assembly bootstrap code should be remplaced with the C
version in xenamd64/amd64/xpmap.c
- see if a config(5) trick could allow to merge xenamd64 back to xen or amd64.
 1.4 07-Aug-2006  xtraeme * Do not change struct powernow_pst_s (I added another member in my
previous patch) and this MUST be of that size, otherwise the tables
won't be found.

* powernow_k8.c moved into x86/x86, it should work both i386 and amd64.

* Added more DPRINTFs needed to found the first problem.

* Create "machdep.powernow.frequency" again, I can't remember why I
removed frequency... it should work with estd now.

* Do not try to call k[78]_powernow_init() if cpu is not AMD (thanks
to christos).

And more things I can't remember, but this time it will work in
Athlon 64 cpus and it won't crash in EM64T cpus.
 1.3 07-Aug-2006  cube Correctly free freq_names and cstate.

XXX This code is bogus anyway. Global variables vs. MP systems, anyone?
 1.2 06-Aug-2006  xtraeme Free freq_names if k[78]pnow_current_state is NULL, pointed out
by cube.
 1.1 06-Aug-2006  xtraeme AMD PowerNow!/Cool`n'Quiet driver for NetBSD/amd64,
adapted from OpenBSD.

Tested on a few machines:

http://bigbird.dohd.org:3021/NetBSD/dmesg
http://www.bsd.org.il/netbsd/acpi/dmesg

Thanks to cube, elad and others for testing and fixes.

Enabled by default on GENERIC.
 1.6 21-Aug-2022  mlelstv Adapt to pmap/bootspace migrations.
 1.5 12-Aug-2018  maxv More ASLR: randomize the location of the PTE area. The PTE slot is not
created in locore anymore, but a little later; by using the already
entered L4 page, rather than the recursive slot itself (which doesn't
exist yet).

In the prekern we still map the slot - the prekern behaves as an external
locore -, because we need it as part of the randomization/relocation
work. The kernel then removes this slot, and regenerates a randomized
one.

Tested on GENERIC and GENERIC_KASLR, Xen doesn't have it and dom0 still
boots fine.
 1.4 12-Aug-2018  maxv Move the PTE area from slot 255 to slot 509. I've never understood why we
put it on 255; the "kernel" half of the VM space begins on slot 256, so
if anything, the PTE area should have been above it, not below.

Virtually extend the user slots in slotspace, because we don't want
(randomized) kernel mappings to land on slot 255.

The prekern is updated accordingly.

Tested on GENERIC, GENERIC_KASLR and XEN3_DOM0.
 1.3 02-Aug-2018  maxv Add a "version" field in the prekern_args structure. The kernel checks it,
and if it's not happy it returns back to the prekern.
 1.2 02-Aug-2018  maxv Don't forget to call init_slotspace when we're booted via the prekern.
 1.1 08-Oct-2017  maxv branches: 1.1.2; 1.1.4; 1.1.6;
Add the prekern entry point in the kernel.
 1.1.6.1 10-Jun-2019  christos Sync with HEAD
 1.1.4.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.1.2.2 03-Dec-2017  jdolecek update from HEAD
 1.1.2.1 08-Oct-2017  jdolecek file prekern.c was added on branch tls-maxphys on 2017-12-03 11:35:47 +0000
 1.50 20-Nov-2023  simonb Note some large xstate stack objects what Somebody(tm) should look at
when they find some round tuits.
 1.49 19-Oct-2020  christos _KERNEL_OPT police
 1.48 15-Oct-2020  mgorny Fix the machine-dependent ptrace requests to respect LWP number

Fix the machine-dependent ptrace register-related requests (e.g.
PT_GETXMMREGS, PT_GETXSTATE on x86) to correctly respect the LWP number
passed as the data argument. Before this change, these requests
did not operate on the requested LWP of a multithreaded program.

This change required moving ptrace_update_lwp() out of unit scope,
and changing ptrace_machdep_dorequest() function to take a pointer
to pointer as the second argument, consistently with ptrace_regs().

I am planning to extend the ATF ptrace() register tests in the future
to check for regressions in multithreaded programs, as time permits.

Reviewed by kamil.
 1.47 27-Nov-2019  rin Add support for PT_[GS]ETXMMREGS requests for COMPAT_NETBSD32 on amd64.

For this purpose, PT_[GS]ETXMMREGS are added to amd64/ptrace.h. These
are intended for internal usage for COMPAT_NETBSD32, and therefore not
exposed to userland.

Thanks to kamil, mgorny, and pgoyette for their kind review!

XXX
pullup to netbsd-9
 1.46 27-Nov-2019  rin Rename process_machdep_validxstate() to process_machdep_validfpu(), as
this function will be used to check validity of XMM registers also.
 1.45 27-Nov-2019  rin Use bool for "write" in ptrace_machdep_dorequest() for clarity.
No functional changes.
 1.44 06-Aug-2019  kamil Do not dereference user pointer in ptrace_machdep_dorequest()/amd64

Always use copyin(9) for reading user memory.

This fixes SMAP crash on some amd64 machines.

Reported by <msaitoh>
 1.43 24-Jul-2019  bouyer branches: 1.43.2;
Remove XENPV-specific %ss/%cs handling, it doens't seem to be needed with
newer hypervisors (tested with 4.6 and 4.11)
 1.42 20-Jul-2019  christos Restore the ability to debug a 32 bit process from a 64 bit debugger:
- add a function to validate a 64 bit context in 32 bit mode to write registers
- remove 32 bit checks from read and write register functions
- check for pc to fit in 32 bits.
proposed in tech-kern, ok maxv.
 1.41 27-Jun-2019  christos don't cast void *
 1.40 26-Jun-2019  mgorny 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.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 01-Dec-2017  maxv branches: 1.38.4;
Don't even bother with the trap frame, and force the default values.
 1.37 27-Nov-2017  maxv Inline _FRAME_GREG, and mask only 16 bits of the segment registers,
otherwise the upper 48 bits may contain stack garbage. By the way, I find
it suspicious that we're not masking regs[_REG_RFLAGS] with PSL_USER in
process_write_regs.
 1.36 19-Oct-2017  maxv Make sure we don't go farther with 32bit LWPs. There appears to be some
confusion in the code - in part introduced by myself -, and clearly this
place is not supposed to handle 32bit LWPs.

Right now we're returning EINVAL, but verily we would need to redirect
these calls to their netbsd32 counterparts.
 1.35 13-Aug-2017  maxv Mmh, restore %cs and %ss on Xen. Otherwise (unpriv) userland could set a
non-three ring, causing the hypervisor to send a fatal interrupt to the
kernel.
 1.34 13-Aug-2017  maxv Remove unused include, remove dead code, KNF, and fix off-by-one.
 1.33 08-Aug-2017  maxv Mmh, don't overwrite tf_err and tf_trapno. Looks like it can be used to
exploit the intel sysret vulnerability once again.
 1.32 23-Feb-2017  kamil branches: 1.32.6;
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.31 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.30 15-Dec-2016  kamil branches: 1.30.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.29 15-Feb-2014  dsl branches: 1.29.6; 1.29.10;
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.28 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.27 11-Feb-2014  dsl Move sys/arch/amd64/amd64/fpu.c and sys/arch/amd64/include/fpu.h
into sys/arch/x86 in preparation for using the same code for i386.
 1.26 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.25 04-Jan-2014  dsl Remove __HAVE_PROCESS_XFPREGS and add the extra parameter for the size
of the fp save area to all the process_read_fpregs() and
process_write_fpregs() functions.
None of the functions have been modified to use the new parameters.
The size is set for all the writes, but some of the arch-specific reads
just pass NULL.
The amd64 (and i386) need variable sized fp register save areas in order
to support AVX and other enhanced register areas.
These functions are rarely called - so the extra argument won't matter.
 1.24 12-Dec-2013  dsl Since regs->fxstate is actually of type 'struct fxsave64' use a structure
copy instead of a 'not obviously incorrect' memcpy().
 1.23 01-Dec-2013  christos revert fpu/pcu changes until we figure out what's wrong; they cause random
freezes
 1.22 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.21 08-Jul-2012  dsl branches: 1.21.2; 1.21.4;
The MDP_USEDFPU (amd64 and sh3) and MDP_SSTEP (sh3) are lwp flags not
process ones, rename to MDL_xxx.
 1.20 21-May-2012  martin Calling _lwp_create() with a bogus ucontext could trigger a kernel
assertion failure (and thus a crash in DIAGNOSTIC kernels). Independently
discovered by YAMAMOTO Takashi and Joel Sing.

To avoid this, introduce a cpu_mcontext_validate() function and move all
sanity checks from cpu_setmcontext() there. Also untangle the netbsd32
compat mess slightly and add a cpu_mcontext32_validate() cousin there.

Add an exhaustive atf test case, based partly on code from Joel Sing.

Should finally fix the remaining open part of PR kern/43903.
 1.19 20-Dec-2011  jmcneill branches: 1.19.2;
from http://www.freshbsd.org/commit/openbsd/ae7f934ae5bdf57dcf3431ba55fd1da93b8f1963

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

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

ok rmind@
 1.18 20-Dec-2010  matt branches: 1.18.8; 1.18.12;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.
 1.17 21-Nov-2009  rmind branches: 1.17.4;
Use lwp_getpcb() on x86 MD code, clean from struct user usage.
 1.16 28-Apr-2008  martin branches: 1.16.14;
Remove clause 3 and 4 from TNF licenses
 1.15 16-Apr-2008  cegger branches: 1.15.2; 1.15.4;
use POSIX integer types
 1.14 15-Jan-2008  joerg branches: 1.14.6;
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.13 05-Jan-2008  dsl Do not assume that 'struct reg' and 'struct trapframe' have the same
layout. Instead copy the fields individually.
 1.12 17-Oct-2007  garbled branches: 1.12.2; 1.12.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.11 04-Jun-2007  xtraeme branches: 1.11.10;
Ansify, de-__P(), unregister.
 1.10 04-Mar-2007  christos branches: 1.10.2; 1.10.4; 1.10.10;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.9 23-Oct-2006  pooka branches: 1.9.4;
apply const where necessary
 1.8 24-Dec-2005  perry branches: 1.8.20; 1.8.22;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.7 11-Dec-2005  christos merge ktrace-lwp.
 1.6 01-Jun-2005  scw branches: 1.6.2;
Declare the second arg of process_write_{fp,}regs() to be const.
This permits sh5 to continue to re-use those functions in cpu_setmcontext()
with the recent change to Makefile.kern.inc (revision 1.62).
 1.5 15-May-2005  fvdl Optionally include saving and restoring the 64bit %gs and %fs base register
values in the PCB. Do this in pmap_activate for now (XXX not a good place
for it, but a convenient one).
 1.4 30-Nov-2003  fvdl Keep mxcsr and mxcsr_mask across the fake init in process_read_fpregs.
From Mark Kettenis.
 1.3 23-Oct-2003  fvdl Call check_mcontext to validate a register set passed in by ptrace.
 1.2 14-Jul-2003  lukem __KERNEL_RCSID()
 1.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.2.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 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.6.2.4 21-Jan-2008  yamt sync with head
 1.6.2.3 03-Sep-2007  yamt sync with head.
 1.6.2.2 30-Dec-2006  yamt sync with head.
 1.6.2.1 21-Jun-2006  yamt sync with head.
 1.8.22.1 10-Dec-2006  yamt sync with head.
 1.8.20.1 18-Nov-2006  ad Sync with head.
 1.9.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.10.10.1 26-Jun-2007  garbled Sync with HEAD.
 1.10.4.1 11-Jul-2007  mjf Sync with head.
 1.10.2.1 09-Jun-2007  ad Sync with head.
 1.11.10.3 23-Mar-2008  matt sync with HEAD
 1.11.10.2 09-Jan-2008  matt sync with HEAD
 1.11.10.1 06-Nov-2007  matt sync with HEAD
 1.12.8.2 19-Jan-2008  bouyer Sync with HEAD
 1.12.8.1 08-Jan-2008  bouyer Sync with HEAD
 1.12.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.14.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.15.4.2 11-Mar-2010  yamt sync with head
 1.15.4.1 16-May-2008  yamt sync with head.
 1.15.2.1 18-May-2008  yamt sync with head.
 1.16.14.2 10-Jan-2011  jym Sync with HEAD
 1.16.14.1 24-Oct-2010  jym Sync with HEAD
 1.17.4.1 05-Mar-2011  rmind sync with head
 1.18.12.2 02-Jun-2012  mrg sync to latest -current.
 1.18.12.1 18-Feb-2012  mrg merge to -current.
 1.18.8.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.18.8.3 30-Oct-2012  yamt sync with head
 1.18.8.2 23-May-2012  yamt sync with head.
 1.18.8.1 17-Apr-2012  yamt sync with head
 1.19.2.1 21-May-2012  riz Pull up following revision(s) (requested by martin in ticket #274):
sys/arch/amd64/amd64/process_machdep.c: revision 1.20
sys/kern/sys_lwp.c: revision 1.54
sys/arch/sparc64/sparc64/machdep.c: revision 1.267
sys/arch/mips/mips/cpu_subr.c: revision 1.16
sys/arch/vax/vax/machdep.c: revision 1.188
sys/sys/lwp.h: revision 1.161
sys/arch/sparc64/sparc64/netbsd32_machdep.c: revision 1.98
sys/arch/alpha/alpha/machdep.c: revision 1.339
sys/compat/sys/ucontext.h: revision 1.6
sys/arch/hppa/hppa/hppa_machdep.c: revision 1.28
distrib/sets/lists/tests/mi: revision 1.469
sys/arch/powerpc/powerpc/sig_machdep.c: revision 1.42
tests/lib/libc/sys/t_lwp_create.c: revision 1.1
tests/lib/libc/sys/Makefile: revision 1.23
sys/arch/arm/arm/sig_machdep.c: revision 1.42
sys/arch/amd64/include/mcontext.h: revision 1.15
sys/arch/amd64/amd64/machdep.c: revision 1.183
sys/arch/sh3/sh3/sh3_machdep.c: revision 1.99
sys/arch/i386/i386/machdep.c: revision 1.727
sys/compat/netbsd32/netbsd32_lwp.c: revision 1.13
sys/arch/sparc/sparc/machdep.c: revision 1.319
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.76
sys/arch/m68k/m68k/sig_machdep.c: revision 1.49
sys/sys/ucontext.h: revision 1.16
sys/arch/mips/mips/netbsd32_machdep.c: revision 1.9
lib/libc/sys/_lwp_create.2: revision 1.5
Calling _lwp_create() with a bogus ucontext could trigger a kernel
assertion failure (and thus a crash in DIAGNOSTIC kernels). Independently
discovered by YAMAMOTO Takashi and Joel Sing.
To avoid this, introduce a cpu_mcontext_validate() function and move all
sanity checks from cpu_setmcontext() there. Also untangle the netbsd32
compat mess slightly and add a cpu_mcontext32_validate() cousin there.
Add an exhaustive atf test case, based partly on code from Joel Sing.
Should finally fix the remaining open part of PR kern/43903.
 1.21.4.1 18-May-2014  rmind sync with head
 1.21.2.2 03-Dec-2017  jdolecek update from HEAD
 1.21.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.29.10.2 20-Mar-2017  pgoyette Sync with HEAD
 1.29.10.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.29.6.2 28-Aug-2017  skrll Sync with HEAD
 1.29.6.1 05-Feb-2017  skrll Sync with HEAD
 1.30.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.32.6.1 17-Mar-2018  martin Pull up the following revisions, requested by maxv in ticket #637:

sys/arch/amd64/amd64/process_machdep.c 1.33,1.34,1.35 (patch)
sys/arch/amd64/include/types.h 1.55 (patch)
sys/arch/x86/x86/vm_machdep.c 1.33 (patch)

- Reduce the number of places where segment register faults can
occur.
- Remove __HAVE_CPU_UAREA_ROUTINES.
 1.38.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.38.4.1 10-Jun-2019  christos Sync with HEAD
 1.43.2.2 18-Oct-2020  martin Pull up following revision(s) (requested by kamil in ticket #1117):

sys/arch/sh3/include/ptrace.h: revision 1.19
sys/arch/amd64/amd64/process_machdep.c: revision 1.48
sys/arch/sh3/sh3/process_machdep.c: revision 1.23
sys/arch/sh3/sh3/process_machdep.c: revision 1.24
sys/arch/i386/i386/process_machdep.c: revision 1.95
sys/arch/x86/x86/fpu.c (apply patch)
sys/kern/sys_ptrace_common.c: revision 1.84
sys/arch/powerpc/powerpc/process_machdep.c: revision 1.40
sys/sys/ptrace.h: revision 1.71
sys/arch/powerpc/powerpc/process_machdep.c: revision 1.41
(all via patch, adapted)

Fix s87_tw reconstruction to correctly indicate register states

Fix the code reconstructing s87_tw (full tag word) from fx_sw (abridged
tag word) to correctly represent all register states. The previous code
only distinguished between empty/non-empty registers, and assigned
'regular value' to all non-empty registers. The new code explicitly
distinguishes the two other tag word values: empty and special.

Fix the machine-dependent ptrace register-related requests (e.g.
PT_GETXMMREGS, PT_GETXSTATE on x86) to correctly respect the LWP number
passed as the data argument. Before this change, these requests
did not operate on the requested LWP of a multithreaded program.
This change required moving ptrace_update_lwp() out of unit scope,
and changing ptrace_machdep_dorequest() function to take a pointer
to pointer as the second argument, consistently with ptrace_regs().

I am planning to extend the ATF ptrace() register tests in the future
to check for regressions in multithreaded programs, as time permits.

Reviewed by kamil.

Add missing 'error' declaration
 1.43.2.1 06-Aug-2019  martin Pull up following revision(s) (requested by kamil in ticket #19):

sys/arch/amd64/amd64/process_machdep.c: revision 1.44

Do not dereference user pointer in ptrace_machdep_dorequest()/amd64

Always use copyin(9) for reading user memory.

This fixes SMAP crash on some amd64 machines.

Reported by <msaitoh>
 1.16 08-Jul-2010  rmind Unify i386 and amd64 procfs MD code into x86.
 1.15 18-Apr-2010  jym This patch fixes the NX regression issue observed on amd64 kernels, where
per-page execution right was disabled (therefore leading to the inability
of the kernel to detect fraudulent use of memory mappings marked as not
being executable).

- replace cpu_feature and ci_feature_flags variables by cpu_feature and
ci_feat_val arrays. This makes it cleaner and brings kernel code closer
to the design of cpuctl(8). A warning will be raised for each CPU that
does not expose the same features as the Boot Processor (BP).

- the blacklist of CPU features is now a macro defined in the
specialreg.h header, instead of hardcoding it inside MD initialization
code; fix comments.

- replace checks against CPUID_TSC with the cpu_hascounter() function.

- clean up the code in init_x86_64(), as cpu_feature variables are set
inside cpu_probe().

- use cpu_init_msrs() for i386. It will be eventually used later for NX
feature under i386 PAE kernels.

- remove code that checks for CPUID_NOX in amd64 mptramp.S, this is already
performed by cpu_hatch() through cpu_init_msrs().

- remove cpu_signature and feature_flags members from struct mpbios_proc
(they were never used).

This patch was tested with i386 MONOLITHIC, XEN3PAE_DOM0 and XEN3_DOM0 under
a native i386 host, and amd64 GENERIC, XEN3_DOM0 via QEMU virtual machines.

XXX Should kernel rev be bumped?

XXX A similar patch should be pulled-up for NetBSD-5, hopefully tomorrow.
 1.14 18-Jan-2010  rmind branches: 1.14.2; 1.14.4;
Reduce the difference between i386 and amd64 procfs MD code.
Prepare for the merge, no functional changes intended.
 1.13 18-Jan-2010  njoly Do not check more than 32 bits against ci_feature_flags, to avoid printing
bogus data on /proc/cpuinfo flags line.
 1.12 16-Aug-2009  yamt reduce differences between x86 ports.
 1.11 11-Jun-2008  njoly branches: 1.11.10;
Update linux cpuinfo vendor_id/model_name field, to show expected
output.
 1.10 11-Jun-2008  njoly Remove extra column in linux cpuinfo output.
 1.9 11-May-2008  ad branches: 1.9.2;
Share cpu.h between the x86 ports.
 1.8 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.7 12-Nov-2007  ad branches: 1.7.14; 1.7.16; 1.7.18; 1.7.20;
- cpu_vendor was both an int and char[] on amd64 - fix it.
- Run the errata check/patch on all CPUs, not just the boot processor.
 1.6 25-Nov-2006  elad branches: 1.6.8; 1.6.26; 1.6.28; 1.6.32; 1.6.34;
Remove dead code. __HAVE_PROCFS_MACHDEP is not defined for amd64.
 1.5 24-Aug-2006  manu branches: 1.5.2; 1.5.4;
Tweak i386 version of procfs_machdep to get Linux's /proc/cpuinfo working
 1.4 11-Dec-2005  christos branches: 1.4.4; 1.4.8;
merge ktrace-lwp.
 1.3 14-Jul-2003  lukem branches: 1.3.16;
__KERNEL_RCSID()
 1.2 14-May-2003  fvdl branches: 1.2.2;
Add RCS Id and/or copyright notice.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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.3.16.2 15-Nov-2007  yamt sync with head.
 1.3.16.1 30-Dec-2006  yamt sync with head.
 1.4.8.1 03-Sep-2006  yamt sync with head.
 1.4.4.1 09-Sep-2006  rpaulo sync with head
 1.5.4.1 10-Dec-2006  yamt sync with head.
 1.5.2.1 12-Jan-2007  ad Sync with head.
 1.6.34.1 19-Nov-2007  mjf Sync with HEAD.
 1.6.32.1 13-Nov-2007  bouyer Sync with HEAD
 1.6.28.1 09-Jan-2008  matt sync with HEAD
 1.6.26.1 14-Nov-2007  joerg Sync with HEAD.
 1.6.8.1 03-Dec-2007  ad Sync with HEAD.
 1.7.20.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.7.18.5 11-Aug-2010  yamt sync with head.
 1.7.18.4 11-Mar-2010  yamt sync with head
 1.7.18.3 19-Aug-2009  yamt sync with head.
 1.7.18.2 04-May-2009  yamt sync with head.
 1.7.18.1 16-May-2008  yamt sync with head.
 1.7.16.2 17-Jun-2008  yamt sync with head.
 1.7.16.1 18-May-2008  yamt sync with head.
 1.7.14.2 29-Jun-2008  mjf Sync with HEAD.
 1.7.14.1 02-Jun-2008  mjf Sync with HEAD.
 1.9.2.1 18-Jun-2008  simonb Sync with head.
 1.11.10.2 24-Oct-2010  jym Sync with HEAD
 1.11.10.1 01-Nov-2009  jym Sync with HEAD.
 1.14.4.2 05-Mar-2011  rmind sync with head
 1.14.4.1 30-May-2010  rmind sync with head
 1.14.2.3 17-Aug-2010  uebayasi Sync with HEAD.
 1.14.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.14.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.7 15-Aug-2017  maxv Reduce the diff between amd64 and i386, and style.
 1.6 29-Jun-2014  jakllsch branches: 1.6.4;
drop trailing whitespace
 1.5 01-Jul-2011  dyoung branches: 1.5.12; 1.5.26;
#include <sys/bus.h> instead of <machine/bus.h>.
 1.4 20-Dec-2010  matt Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.
 1.3 15-Dec-2009  snj branches: 1.3.4;
Move to 2-clause license. Approved by HAYAKAWA Koichi (copyright holder).
 1.2 18-May-2008  jmcneill branches: 1.2.12;
Add support for PCI_BUS_FIXUP and PCI_ADDR_FIXUP on amd64.
 1.1 21-Dec-2005  rjs branches: 1.1.18; 1.1.76; 1.1.78; 1.1.80; 1.1.82;
Add boilerplate for cardbus support.
 1.1.82.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.1.80.2 11-Mar-2010  yamt sync with head
 1.1.80.1 04-May-2009  yamt sync with head.
 1.1.78.1 18-May-2008  yamt sync with head.
 1.1.76.1 02-Jun-2008  mjf Sync with HEAD.
 1.1.18.2 21-Jun-2006  yamt sync with head.
 1.1.18.1 21-Dec-2005  yamt file rbus_machdep.c was added on branch yamt-lazymbuf on 2006-06-21 14:48:19 +0000
 1.2.12.3 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.2.12.2 10-Jan-2011  jym Sync with HEAD
 1.2.12.1 24-Oct-2010  jym Sync with HEAD
 1.3.4.1 05-Mar-2011  rmind sync with head
 1.5.26.1 10-Aug-2014  tls Rebase.
 1.5.12.2 03-Dec-2017  jdolecek update from HEAD
 1.5.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.6.4.1 28-Aug-2017  skrll Sync with HEAD
 1.49 01-Mar-2023  riastradh x86: Expand on comments on ordering around stores to ci_curlwp.

No functional change intended.

PR kern/57240
 1.48 07-Sep-2022  knakahara NetBSD/x86: Raise the number of interrupt sources per CPU from 32 to 56.

There has been no objection for three years.
https://mail-index.netbsd.org/port-amd64/2019/09/22/msg003012.html
Implemented by nonaka@n.o, updated by me.
 1.47 29-Aug-2020  maxv 'doreti_checkast' isn't global anymore, localify.
 1.46 17-May-2020  ad comments
 1.45 02-May-2020  maxv Remove unused.
 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 08-Jan-2020  ad branches: 1.43.4;
Hopefully fix some problems seen with MP support on non-x86, in particular
where curcpu() is defined as curlwp->l_cpu:

- mi_switch(): undo the ~2007ish optimisation to unlock curlwp before
calling cpu_switchto(). It's not safe to let other actors mess with the
LWP (in particular l->l_cpu) while it's still context switching. This
removes l->l_ctxswtch.

- Move the LP_RUNNING flag into l->l_flag and rename to LW_RUNNING since
it's now covered by the LWP's lock.

- Ditch lwp_exit_switchaway() and just call mi_switch() instead. Everything
is in cache anyway so it wasn't buying much by trying to avoid saving old
state. This means cpu_switchto() will never be called with prevlwp ==
NULL.

- Remove some KERNEL_LOCK handling which hasn't been needed for years.
 1.42 14-Nov-2019  maxv branches: 1.42.2;
Add support for Kernel Memory Sanitizer (kMSan). It detects uninitialized
memory used by the kernel at run time, and just like kASan and kCSan, it
is an excellent feature. It has already detected 38 uninitialized variables
in the kernel during my testing, which I have since discreetly fixed.

We use two shadows:
- "shad", to track uninitialized memory with a bit granularity (1:1).
Each bit set to 1 in the shad corresponds to one uninitialized bit of
real kernel memory.
- "orig", to track the origin of the memory with a 4-byte granularity
(1:1). Each uint32_t cell in the orig indicates the origin of the
associated uint32_t of real kernel memory.

The memory consumption of these shadows is consequent, so at least 4GB of
RAM is recommended to run kMSan.

The compiler inserts calls to specific __msan_* functions on each memory
access, to manage both the shad and the orig and detect uninitialized
memory accesses that change the execution flow (like an "if" on an
uninitialized variable).

We mark as uninit several types of memory buffers (stack, pools, kmem,
malloc, uvm_km), and check each buffer passed to copyout, copyoutstr,
bwrite, if_transmit_lock and DMA operations, to detect uninitialized memory
that leaves the system. This allows us to detect kernel info leaks in a way
that is more efficient and also more user-friendly than KLEAK.

Contrary to kASan, kMSan requires comprehensive coverage, ie we cannot
tolerate having one non-instrumented function, because this could cause
false positives. kMSan cannot instrument ASM functions, so I converted
most of them to __asm__ inlines, which kMSan is able to instrument. Those
that remain receive special treatment.

Contrary to kASan again, kMSan uses a TLS, so we must context-switch this
TLS during interrupts. We use different contexts depending on the interrupt
level.

The orig tracks precisely the origin of a buffer. We use a special encoding
for the orig values, and pack together in each uint32_t cell of the orig:
- a code designating the type of memory (Stack, Pool, etc), and
- a compressed pointer, which points either (1) to a string containing
the name of the variable associated with the cell, or (2) to an area
in the kernel .text section which we resolve to a symbol name + offset.

This encoding allows us not to consume extra memory for associating
information with each cell, and produces a precise output, that can tell
for example the name of an uninitialized variable on the stack, the
function in which it was pushed on the stack, and the function where we
accessed this uninitialized variable.

kMSan is available with LLVM, but not with GCC.

The code is organized in a way that is similar to kASan and kCSan, so it
means that other architectures than amd64 can be supported.
 1.41 12-Oct-2019  maxv 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.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 26-Dec-2018  cherry Xen can use the native splraise(9) functions.

There is no need for a slower C version.
 1.37 25-Dec-2018  cherry Excise XEN specific code out of x86/x86/intr.c into xen/x86/xen_intr.c

While at it, separate the source function tracking so that the interrupt
paths are truly independant.

Use weak symbol exporting to provision for future PVHVM co-existence
of both files, but with independant paths. Introduce assembler code
such that in a unified scenario, native interrupts get first priority
in spllower(), followed by XEN event callbacks. IPL management and
semantics are unchanged - native handlers and xen callbacks are
expected to maintain their ipl related semantics.

In summary, after this commit, native and XEN now have completely
unrelated interrupt handling mechanisms, including
intr_establish_xname() and assembler stubs and intr handler
management.

Happy Christmas!
 1.36 22-Aug-2018  maxv Explicitly unpoison the stack when entering a softint.

Softints are the only place where we "discard" a part of the stack: we may
have left the thread without allowing the asan instrumentation to clear
the poison, and in this case, we can get false positives when we hit a
poisoned area of the stack while executing another handler within the same
softint thread.

(I was actually getting a rare false positive in ip6intr.)
 1.35 14-Jul-2018  maxv Drop NENTRY() from the x86 kernels, use ENTRY(). With PMCs (and other hardware
tracing facilities) we have a much better ways of monitoring the CPU activity
than GPROF, without software modification.

Also I think GPROF has never worked, because the 'start' functions of both
i386 and amd64 use ENTRY(), and it would have caused a function call while the
kernel was not yet relocated.
 1.34 04-Apr-2018  christos branches: 1.34.2;
Rename Xpreempt{recurse,resume} -> X{recurse,resume}_preempt so that
they fit the pattern. Also the debugger trap sniffer matches them
without adding special entries...
XXX: pullup-8.
 1.33 02-Apr-2018  mlelstv typo
 1.32 02-Apr-2018  christos use the right end macro: IDTVEC_END(name) instead of END(Xname)
 1.31 28-Nov-2017  maxv branches: 1.31.2;
style
 1.30 22-Nov-2015  maxv branches: 1.30.10;
KNF a bit, so I don't get scared each time I open a file
 1.29 27-Nov-2014  uebayasi branches: 1.29.2;
Comments.
 1.28 12-Jan-2014  joerg Try to reserve space in a way that results in the same allocation for
both LLVM and GNU as.
 1.27 22-Jun-2013  uebayasi branches: 1.27.2;
Use END() to set ELF symbol size. Set some type info too.
 1.26 10-Nov-2012  cherry Remove e a redundant layer of function calling in the event handling path
 1.25 02-Nov-2012  yamt fix a comment
 1.24 18-Mar-2011  joerg branches: 1.24.4; 1.24.14;
Remove static branch prediction hints. They pessimize code for all CPUs
but Pentium IV. Discussed with ad@ and dsl@
 1.23 27-Nov-2009  rmind branches: 1.23.4; 1.23.6;
- Use uvm_lwp_setuarea() instead of directly setting address to lwp_t::l_addr.
- Replace most remaining uses of l_addr with uvm_lwp_getuarea() or lwp_getpcb().
- Amend assembly in ports where it accesses PCB via struct user.
- Rename L_ADDR to L_PCB in few places. Reduce sys/user.h inclusions.
 1.22 25-Nov-2009  rmind Remove IPL_LPT and IPL_IPI aliases, use the actual IPLs.
Fix some broken comments.
 1.21 02-Apr-2009  enami So that profile kernel runs again,
- Adjust the size of functions used to patch.
- Fix the jump offset of mcount call when patching functions.

Approved by Andrew Doran.
 1.20 01-Jul-2008  bouyer branches: 1.20.4; 1.20.6; 1.20.10;
Raise ci_idepth (and switch to interrupt stack on i386) becore calling
xenevt_event().
 1.19 28-Apr-2008  ad branches: 1.19.2; 1.19.4;
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.18 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.17 13-Feb-2008  ad branches: 1.17.6; 1.17.8; 1.17.10;
spllower: change address mode slightly to work around a bug in qemu.
PR port-amd64/37714.
 1.16 10-Jan-2008  ad - Fix a memory order problem with non-interlocked mutex release.
- Give kernel_lock its own cache line.
 1.15 21-Dec-2007  dsl Change the xen CLI() and STI() defines to only use one scratch register.
As well as saving an instruction, in one place it saves a push/pop pair.
 1.14 04-Dec-2007  ad branches: 1.14.4;
softintr_ret: fix it to work properly after yesterday's change to mi_switch.
 1.13 03-Dec-2007  ad branches: 1.13.2;
Interrupt handling changes, in discussion since February:

- Reduce available SPL levels for hardware devices to none, vm, sched, high.
- Acquire kernel_lock only for interrupts at IPL_VM.
- Implement threaded soft interrupts.
 1.12 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.11 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.10 18-Oct-2007  yamt branches: 1.10.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.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 29-Aug-2007  ad branches: 1.8.2; 1.8.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.7 17-May-2007  yamt branches: 1.7.4; 1.7.8; 1.7.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.6 09-Feb-2007  ad branches: 1.6.2; 1.6.6; 1.6.8; 1.6.14;
Merge newlock2 to head.
 1.5 05-Sep-2006  ad branches: 1.5.2;
Add an SPLLOWER() macro.
 1.4 11-Dec-2005  christos branches: 1.4.4; 1.4.8;
merge ktrace-lwp.
 1.3 28-Jun-2004  fvdl branches: 1.3.12;
Updaing ci_ilevel and testing ci_ipending must be done with all interrupts
off, or priority inversion can occur, which can lead to IPI deadlocks.
Leaves interrupts off for a bit longer, sadly, but with no noticeable
effects on the systems I tested on.

From YAMAMOTO Takashi.
 1.2 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.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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.3.12.8 27-Feb-2008  yamt sync with head.
 1.3.12.7 21-Jan-2008  yamt sync with head
 1.3.12.6 07-Dec-2007  yamt sync with head
 1.3.12.5 15-Nov-2007  yamt sync with head.
 1.3.12.4 27-Oct-2007  yamt sync with head.
 1.3.12.3 03-Sep-2007  yamt sync with head.
 1.3.12.2 26-Feb-2007  yamt sync with head.
 1.3.12.1 30-Dec-2006  yamt sync with head.
 1.4.8.1 14-Sep-2006  yamt sync with head.
 1.4.4.1 09-Sep-2006  rpaulo sync with head
 1.5.2.4 01-Feb-2007  ad - Don't patch stuff if it's a profiling kernel.
- Move Xspllower label to show up better in profile output.
 1.5.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.5.2.2 14-Jan-2007  ad - Restore previous locking behaviour in cpu_switch(). Seems to fix what
look like corrupted trap frames.
- Micro-optimisation for AST check/clear.
 1.5.2.1 20-Oct-2006  ad Make ASTs per-LWP.
 1.6.14.2 03-Oct-2007  garbled Sync with HEAD
 1.6.14.1 22-May-2007  matt Update to HEAD.
 1.6.8.1 11-Jul-2007  mjf Sync with head.
 1.6.6.7 03-Dec-2007  ad Sync with HEAD.
 1.6.6.6 03-Dec-2007  ad Sync with HEAD.
 1.6.6.5 16-Nov-2007  ad softintr_ret keeps the IPL raised until returning to doreti/splx in order
to avoid recursing. To keep the IPL raised it adjusts ci_mtx_oldspl before
dropping curlwp->l_mutex. That's not safe if the current CPU holds more than
one spin mutex, and can lead to "WARNING: SPL NOT LOWERED...". Fix it.
 1.6.6.4 23-Oct-2007  ad Sync with head.
 1.6.6.3 23-Aug-2007  ad Fix some more bugs.
 1.6.6.2 21-Aug-2007  ad amd64 changes, as yet untested:

- Adapt to vmlocking branch.
- Apply TLB shootdown and pv allocation changes to the pmap.
- Make it build.
 1.6.6.1 27-May-2007  ad Sync with head.
 1.6.2.2 04-Apr-2007  ad Sync with i386:

If cmpxchg8b fails, don't immediatley enter Xspllower - retry first.
 1.6.2.1 23-Mar-2007  ad - Decouple intr.h from cpu.h.
- Define splraise in spl.S. As a side effect it becomes "preemption safe".
- Make softintr_schedule a function in softintr.c.
- Make softintr a function in spl.S, and remove the unneeded lock prefix.
 1.7.10.3 23-Mar-2008  matt sync with HEAD
 1.7.10.2 09-Jan-2008  matt sync with HEAD
 1.7.10.1 06-Nov-2007  matt sync with HEAD
 1.7.8.5 09-Dec-2007  jmcneill Sync with HEAD.
 1.7.8.4 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.7.8.3 11-Nov-2007  joerg Sync with HEAD.
 1.7.8.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.7.8.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.7.4.1 03-Sep-2007  skrll Sync with HEAD.
 1.8.4.5 16-Nov-2007  bouyer Initial domain0 support for xenamd64. The kernel boots multiuser, but
xen tools have not been tried yet.
In this process, cleanup some more the page table bootstrap, and properly
handle event counters for soft interrupts.
 1.8.4.4 13-Nov-2007  bouyer Sync with HEAD
 1.8.4.3 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.8.4.2 21-Oct-2007  bouyer Check for ASTs on exit from interrupt.
 1.8.4.1 17-Oct-2007  bouyer amd64 (aka x86-64) support for Xen. Based on the OpenBSD port done by
Mathieu Ropert in 2006.
DomU-only for now. An INSTALL_XEN3_DOMU kernel with a ramdisk will boot to
sysinst if you're lucky. Often it panics because a runable LWP has
a NULL stack (really, it's all of l->l_addr which is has been zeroed out
while the process was on the queue !)
TODO:
- bug fixes :)
- Most of the xpq_* functions should be shared with xen/i386
- The xen/i386 assembly bootstrap code should be remplaced with the C
version in xenamd64/amd64/xpmap.c
- see if a config(5) trick could allow to merge xenamd64 back to xen or amd64.
 1.8.2.2 07-Oct-2007  yamt remove some #ifdef _LOCORE and use genassym instead.
 1.8.2.1 30-Sep-2007  yamt implement deferred pmap switching for amd64, and make amd64 use
x86 shared pmap code. it makes several i386 pmap improvements available
to amd64, including tlb shootdown reduction and bug fixes from Stephan Uphoff.
 1.10.2.4 18-Feb-2008  mjf Sync with HEAD.
 1.10.2.3 27-Dec-2007  mjf Sync with HEAD.
 1.10.2.2 08-Dec-2007  mjf Sync with HEAD.
 1.10.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.13.2.2 26-Dec-2007  ad Sync with head.
 1.13.2.1 04-Dec-2007  ad Pull the vmlocking changes into a new branch.
 1.14.4.2 10-Jan-2008  bouyer Sync with HEAD
 1.14.4.1 02-Jan-2008  bouyer Sync with HEAD
 1.17.10.3 11-Mar-2010  yamt sync with head
 1.17.10.2 04-May-2009  yamt sync with head.
 1.17.10.1 16-May-2008  yamt sync with head.
 1.17.8.1 18-May-2008  yamt sync with head.
 1.17.6.2 02-Jul-2008  mjf Sync with HEAD.
 1.17.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.19.4.1 03-Jul-2008  simonb Sync with head.
 1.19.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.20.10.4 28-Mar-2011  jym Cure sync hiccups. Code with compile errors is not really useful, heh.
 1.20.10.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.20.10.2 01-Nov-2009  jym Sync with HEAD.
 1.20.10.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.20.6.1 03-Apr-2009  snj Pull up following revision(s) (requested by enami in ticket #645):
common/lib/libc/arch/i386/atomic/atomic.S: revision 1.17
sys/arch/amd64/amd64/spl.S: revision 1.21
sys/arch/x86/x86/patch.c: revision 1.17
So that profile kernel runs again,
- Adjust the size of functions used to patch.
- Fix the jump offset of mcount call when patching functions.
Approved by Andrew Doran.
 1.20.4.1 28-Apr-2009  skrll Sync with HEAD.
 1.23.6.1 06-Jun-2011  jruoho Sync with HEAD.
 1.23.4.1 21-Apr-2011  rmind sync with head
 1.24.14.3 03-Dec-2017  jdolecek update from HEAD
 1.24.14.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.24.14.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.24.4.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.24.4.1 16-Jan-2013  yamt sync with (a bit old) head
 1.27.2.1 18-May-2014  rmind sync with head
 1.29.2.1 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.30.10.1 05-Apr-2018  martin Pull up following revision(s) (requested by christos in ticket #696):

sys/arch/amd64/amd64/vector.S: revision 1.62 (patch)
sys/arch/x86/include/intr.h: revision 1.55
sys/arch/i386/i386/vector.S: revision 1.77
sys/arch/i386/i386/db_interface.c: revision 1.82 (patch)
sys/arch/amd64/amd64/spl.S: revision 1.34 (patch)
sys/arch/amd64/amd64/db_interface.c: revision 1.33 (patch)
sys/arch/x86/x86/intr.c: revision 1.125
sys/arch/i386/i386/spl.S: revision 1.43 (patch)
sys/arch/i386/i386/machdep.c: revision 1.805 (patch)
sys/arch/x86/x86/lapic.c: revision 1.66 (patch)

Rename the DDB IPI IDT vectors for consistency. ok maxv@

Rename Xpreempt{recurse,resume} -> X{recurse,resume}_preempt so that
they fit the pattern. Also the debugger trap sniffer matches them
without adding special entries...

XXX: pullup-8.
 1.31.2.5 18-Jan-2019  pgoyette Synch with HEAD
 1.31.2.4 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.31.2.3 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.31.2.2 28-Jul-2018  pgoyette Sync with HEAD
 1.31.2.1 07-Apr-2018  pgoyette Sync with HEAD. 77 conflicts resolved - all of them $NetBSD$
 1.34.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.34.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.34.2.1 10-Jun-2019  christos Sync with HEAD
 1.42.2.1 17-Jan-2020  ad Sync with head.
 1.43.4.7 15-Apr-2020  bouyer On amd64, always use the cmpxchg8b version of spllower. All x86_64 host should
have it and we already rely on it in lock stubs.
On i386, always use i686_mutex_spin_exit and cx8_spllower for Xen;
Xen doesn't run on CPUs on CPUs lacking the required instructions anyway.
Skip x86_patch only for XENPV, and adjust for changes in assembly functions.
Tested on Xen PV and PVHVM, and on bare metal core i5.
 1.43.4.6 12-Apr-2020  bouyer Get rid of xen-specific ci_x* interrupt handling:
- use the general SIR mechanism, reserving 3 more slots for IPL_VM, IPL_SCHED
and IPL_HIGH
- remove specific handling from C sources, or change to ipending
- convert IPL number to SIR number in various places
- Remove XUNMASK/XPENDING in assembly or change to IUNMASK/IPENDING
- remove Xen-specific ci_xsources, ci_xmask, ci_xunmask, ci_xpending from
struct cpu_info
- for now remove a KASSERT that there are no pending interrupts in
idle_block(). We can get there with some software interrupts pending
in autoconf XXX needs to be looked at.
 1.43.4.5 11-Apr-2020  bouyer Move softint and preemtion-related functions out of x86/x86/intr.c to
its own file, x86/x86/x86_softintr.c
Add x86/x86/x86_softintr.c for native and XenPV
Make sure XenPV also check ci_ioending, which is used for softints.
Switch XenPV to fast softints and allow kernel preemption.
kpreempt_disable() before calling pmap_changeprot_local()
run xen_wallclock_time() and xen_global_systime_ns() at splshed() to
avoid being interrupted.

XXX amd64 lock stubs are racy for XPENDING
 1.43.4.4 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.43.4.3 10-Apr-2020  bouyer spllower(): Also check Xen pending events
hypervisor_pvhvm_callback(): exit via Xdoreti, so that pending interrupts
are checked.
disable __HAVE_FAST_SOFTINTS only for XENPV, it now works for PVHVM.
We still have to disable PREEMPTION, until we support MULTIPROCESSOR
 1.43.4.2 09-Apr-2020  bouyer Fix a second place where %eax is used with the wrong value.
 1.43.4.1 09-Apr-2020  bouyer restore %eax before using it. This bug caused event handlers to be called
spuriously at high spl or in a reentrant manner.
Now a amd64 PVHVM domU can checkout pkgsrc and build packages without panic.
 1.13 16-Apr-2007  ad Share the sysarch stuff between the x86 ports. PR kern/36046.
 1.12 04-Mar-2007  christos branches: 1.12.2; 1.12.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.11 09-Feb-2007  ad branches: 1.11.2;
Merge newlock2 to head.
 1.10 26-Dec-2006  elad Make machdep scope architecture-agnostic by removing all arch-specific
requests and centralizing them all. The result is that some of these
are not used on some architectures, but the documentation was updated
to reflect that.
 1.9 19-Sep-2006  elad branches: 1.9.2;
Lose (void *) casts on the machdep scope authorization wrapper. Update
documentation.
 1.8 08-Sep-2006  elad branches: 1.8.2;
First take at security model abstraction.

- Add a few scopes to the kernel: system, network, and machdep.

- Add a few more actions/sub-actions (requests), and start using them as
opposed to the KAUTH_GENERIC_ISSUSER place-holders.

- Introduce a basic set of listeners that implement our "traditional"
security model, called "bsd44". This is the default (and only) model we
have at the moment.

- Update all relevant documentation.

- Add some code and docs to help folks who want to actually use this stuff:

* There's a sample overlay model, sitting on-top of "bsd44", for
fast experimenting with tweaking just a subset of an existing model.

This is pretty cool because it's *really* straightforward to do stuff
you had to use ugly hacks for until now...

* And of course, documentation describing how to do the above for quick
reference, including code samples.

All of these changes were tested for regressions using a Python-based
testsuite that will be (I hope) available soon via pkgsrc. Information
about the tests, and how to write new ones, can be found on:

http://kauth.linbsd.org/kauthwiki

NOTE FOR DEVELOPERS: *PLEASE* don't add any code that does any of the
following:

- Uses a KAUTH_GENERIC_ISSUSER kauth(9) request,
- Checks 'securelevel' directly,
- Checks a uid/gid directly.

(or if you feel you have to, contact me first)

This is still work in progress; It's far from being done, but now it'll
be a lot easier.

Relevant mailing list threads:

http://mail-index.netbsd.org/tech-security/2006/01/25/0011.html
http://mail-index.netbsd.org/tech-security/2006/03/24/0001.html
http://mail-index.netbsd.org/tech-security/2006/04/18/0000.html
http://mail-index.netbsd.org/tech-security/2006/05/15/0000.html
http://mail-index.netbsd.org/tech-security/2006/08/01/0000.html
http://mail-index.netbsd.org/tech-security/2006/08/25/0000.html

Many thanks to YAMAMOTO Takashi, Matt Thomas, and Christos Zoulas for help
stablizing kauth(9).

Full credit for the regression tests, making sure these changes didn't break
anything, goes to Matt Fleming and Jaime Fournier.

Happy birthday Randi! :)
 1.7 23-Jul-2006  ad branches: 1.7.4;
Use the LWP cached credentials where sane.
 1.6 14-May-2006  elad integrate kauth.
 1.5 11-Dec-2005  christos branches: 1.5.4; 1.5.6; 1.5.8; 1.5.10; 1.5.12;
merge ktrace-lwp.
 1.4 15-May-2005  fvdl branches: 1.4.2;
Start at implementing USER_LDT. Doesn't compile yet (but it didn't previously
either).
 1.3 01-Apr-2005  yamt merge yamt-km branch.
- don't use managed mappings/backing objects for wired memory allocations.
save some resources like pv_entry. also fix (most of) PR/27030.
- simplify kernel memory management API.
- simplify pmap bootstrap of some ports.
- some related cleanups.
 1.2 14-Jul-2003  lukem branches: 1.2.8; 1.2.10;
__KERNEL_RCSID()
 1.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.2.4 01-Apr-2005  skrll Sync with HEAD.
 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.2.10.1 13-Feb-2005  yamt - use new apis.
- simplify pmap bootstrap and pv_page allocation.
 1.2.8.1 29-Apr-2005  kent sync with -current
 1.4.2.4 03-Sep-2007  yamt sync with head.
 1.4.2.3 26-Feb-2007  yamt sync with head.
 1.4.2.2 30-Dec-2006  yamt sync with head.
 1.4.2.1 21-Jun-2006  yamt sync with head.
 1.5.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.5.10.3 12-May-2006  elad include sys/kauth.h where appropriate.
 1.5.10.2 10-Mar-2006  elad generic_authorize() -> kauth_authorize_generic().
 1.5.10.1 08-Mar-2006  elad Adapt to kernel authorization KPI.

I expect *some* lossage here...
 1.5.8.3 14-Sep-2006  yamt sync with head.
 1.5.8.2 11-Aug-2006  yamt sync with head
 1.5.8.1 24-May-2006  yamt sync with head.
 1.5.6.1 01-Jun-2006  kardel Sync with head.
 1.5.4.1 09-Sep-2006  rpaulo sync with head
 1.7.4.3 30-Jan-2007  ad Remove support for SA. Ok core@.
 1.7.4.2 12-Jan-2007  ad Sync with head.
 1.7.4.1 18-Nov-2006  ad Sync with head.
 1.8.2.1 22-Oct-2006  yamt sync with head
 1.9.2.1 06-Jan-2007  bouyer Pull up following revision(s) (requested by elad in ticket #316):
share/examples/secmodel/secmodel_example.c: revision 1.10 via patch
sys/arch/i386/i386/sys_machdep.c: revision 1.79
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.31
share/man/man9/secmodel_bsd44.9: revision 1.9
sys/arch/vax/vax/mem.c: revision 1.34 via patch
sys/arch/sh3/sh3/mem.c: revision 1.23 via patch
sys/arch/sh5/sh5/mem.c: revision 1.14 via patch
sys/secmodel/bsd44/secmodel_bsd44_suser.c: revision 1.22 via patch
sys/arch/powerpc/powerpc/mem.c: revision 1.27 via patch
sys/arch/x86/x86/x86_machdep.c: revision 1.5
sys/arch/alpha/alpha/machdep.c: revision 1.291
sys/arch/arm/arm32/mem.c: revision 1.17 via patch
sys/secmodel/bsd44/secmodel_bsd44_securelevel.c: revision 1.20
sys/sys/kauth.h: revision 1.29 via patch
sys/arch/amd64/amd64/sys_machdep.c: revision 1.10
share/man/man9/kauth.9: revision 1.43 via patch
sys/arch/xen/i386/sys_machdep.c: revision 1.10
sys/kern/kern_auth.c: revision 1.35
sys/arch/pc532/pc532/mem.c: revision 1.43 via patch
Make machdep scope architecture-agnostic by removing all arch-specific
requests and centralizing them all. The result is that some of these
are not used on some architectures, but the documentation was updated
to reflect that.
 1.11.2.3 07-May-2007  yamt sync with head.
 1.11.2.2 12-Mar-2007  rmind Sync with HEAD.
 1.11.2.1 03-Mar-2007  yamt adapt amd64.

XXX changes in identcpu.c is minmum for MONITOR.
XXX identcpu.c should be shared with i386.
 1.12.4.1 11-Jul-2007  mjf Sync with head.
 1.12.2.1 27-May-2007  ad Sync with head.
 1.46 16-Apr-2009  rmind - Add macros to handle (some) trapframe registers for common x86 code.
- Merge i386 and amd64 syscall.c into x86. No functional changes intended.

Proposed on (port-i386 & port-amd64). Unfortunately, I cannot merge these
lists into the single port-x86. :(
 1.45 29-Mar-2009  rmind Reduce some differences between i386 and amd64.
Mainly cosmetical changes - no functional changes intended.
 1.44 21-Oct-2008  ad branches: 1.44.2; 1.44.4; 1.44.8;
Provide a small inline wrapper for sysent::sy_call() and use it to store
the active syscall description in struct lwp. To be used at some future
point to prevent unloading of modules that provide syscalls, while the
syscalls are in use.
 1.43 15-Oct-2008  wrstuden Merge wrstuden-revivesa into HEAD.
 1.42 28-Apr-2008  martin branches: 1.42.2; 1.42.6;
Remove clause 3 and 4 from TNF licenses
 1.41 24-Apr-2008  ad branches: 1.41.2;
- Retire SYCALL_MPSAFE. With the exceptions of darwin and irix emulations,
all system calls are now MPSAFE.
- Remove unneeded acquire/release of kernel_lock.
 1.40 21-Apr-2008  ad Unneeded kernel_lock frobbing.
 1.39 11-Mar-2008  ad branches: 1.39.2;
Make context switch + syscall counters optionally per-CPU and accumulate
in schedclock() at "about 16 hz".
 1.38 24-Feb-2008  dsl Set p->p_trace_enabled in fork and whenever the controlling falgs change
instead of doing it in syscall_intern().
Note that syscall_intern() must still be called when the flags change
since many ports use a different copy of the syscall entry code when
tracing is enabled.
 1.37 06-Feb-2008  dsl branches: 1.37.2; 1.37.6;
Remove the 'args' parameter to 'trace_exit()' it is no longer used.
Instead of passing the (un)real system call code and syscall table pointer,
just pass the number of arguments - which is what ktrace really wants.
Ride forthcoming 4.99.53
 1.36 05-Jan-2008  dsl Don't pass 'curlwp' into trace_enter() and trace_exit().
 1.35 05-Jan-2008  dsl Reorder the amd64 trapframe (swap rcx/r10 and add 4 spare slots after r9).
This allows the syscall code to pass the syscall args directly from the
trapframe instead of copying them to a separate structure.
It is still possible that some lurking code still assumes that
'struct trapframe', 'struct mcontext' and 'struct reg' all have the
registers in the same order, but I've fixed enough of them to get gdb working.
 1.34 31-Dec-2007  ad Remove systrace. Ok core@.
 1.33 09-Nov-2007  dsl branches: 1.33.6;
Don't intercept sys_syscall and sys___syscall here, just call the MI code.
 1.32 03-Nov-2007  dsl branches: 1.32.2;
Remove now-redundant #if
 1.31 01-Nov-2007  dsl Kill syscall_fancy().
With a the result of trace_is_enabled() cached in p->p_trace_enabled the
cost of 2 correctly predicted branches is insignificant.
Reorder prologue slightly, should reduce memory stalls.
 1.30 28-Oct-2007  dsl Add support for the SYSCALL_STATS and SYSCALL_TIMES options.
 1.29 27-Oct-2007  dsl Instead of having 2 copies of the sycall entry code, reprocess the file
to generate syscall_plain() with #defines to remove the trace calls.
Join the club of making micro-optimisations to this code to speed up
benchmarks of empty system calls (eg getpid()):
- Use __predict_false() to get fewer branches in the 'normal' path.
- Just copy all the arguments from the stack frame to 'args', since the
jump indirect for the switch statement is basically unpredicatable.
- Keep the (rather pointless) test for 0 arguments - just for higher
benchmark scores.
NB system call timing are dominated by other factors! I measured getppid()
as faster than getpid(), sometimes open("foo", -1) was also faster.
I also suspect that if trace_is_enabled(p) were a simple bit test (that
could be inlined), then the cost of the tests would be unmeasurable and
the syscall_plain/fancy fiasco could be expunged completely.
 1.28 27-Oct-2007  dsl Remove some gratuitous differences between syscall_fancy and syscall_plain.
 1.27 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.26 29-Aug-2007  ad branches: 1.26.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.25 15-Aug-2007  ad branches: 1.25.2;
Changes to make ktrace LKM friendly and reduce ifdef KTRACE. Proposed
on tech-kern.
 1.24 04-Mar-2007  yamt branches: 1.24.2; 1.24.10; 1.24.14; 1.24.18;
fix fallout from caddr_t changes.
 1.23 04-Mar-2007  christos Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.22 09-Feb-2007  ad branches: 1.22.2;
Merge newlock2 to head.
 1.21 26-Aug-2006  ad branches: 1.21.2;
Don't grab the kernel lock for MPSAFE syscalls.
 1.20 19-Jul-2006  ad - Hold a reference to the process credentials in each struct lwp.
- Update the reference on syscall and user trap if p_cred has changed.
- Collect accounting flags in the LWP, and collate on LWP exit.
 1.19 07-Mar-2006  thorpej branches: 1.19.2;
Syscall debug tracing is handled by trace_enter() / trace_exit(). Change
trace_is_enabled() to return TRUE if SYSCALL_DEBUG is defined, and g/c
all of the SYSCALL_DEBUG handling from individual system call dispatch
routines.
 1.18 07-Mar-2006  thorpej Clean up fallout proc_is_traced_p() change:
- proc_is_traced_p() -> trace_is_enabled(), to match trace_enter() and
trace_exit().
- trace_is_enabled() becomes a real function.
- Remove unnecessary include files from various files that used to care
about KTRACE and SYSTRACE, but do no more.
 1.17 06-Mar-2006  he Another instance of syscall_fancy which is only defined when KTRACE
or SYSTRACE is defined, so enclose its use in the same conditional.
 1.16 05-Mar-2006  christos Add a proc_is_traced_p() macro and use it, instead of copying the same code
in many places. Idea from thorpej.
 1.15 05-Mar-2006  christos branches: 1.15.2;
implement PT_SYSCALL
 1.14 11-Dec-2005  christos branches: 1.14.4; 1.14.6;
merge ktrace-lwp.
 1.13 01-Dec-2005  manu Linux does not use retval[1]
 1.12 13-Nov-2005  riz syscall_fancy() is only used if either KTRACE or SYSTRACE is defined,
so only compile it if one or the other is defined. An amd64 INSTALL
kernel now compiles again. :)

Approved by matt@ .
 1.11 01-Nov-2005  christos Split the linux syscall out to make the code easier to read and maintain.
 1.10 01-Nov-2005  manu Linux does not seems to set rdx on syscall exit.
 1.9 01-Jul-2005  christos branches: 1.9.2; 1.9.4;
PR/29607: Christian Biere systrace doesn't handle interrupted syscalls properly
Instead of jumping to the default "bad" case, jump to the error handling
switch, so that we can deal with ERESTART/EJUSTRETURN properly.
 1.8 17-May-2005  fvdl Translate linux errno in the syscall_fancy case as well.
 1.7 16-May-2005  fvdl Translate error numbers in the COMPAT_LINUX case.
 1.6 03-May-2005  manu First work on COMPAT_LINUX/amd64
Process startup and dynamiclinking work, but processes hang due to
Linux arch_prctl(2) not being really supported yet.
 1.5 31-Oct-2003  simonb Don't pass the (unused) return value args to the
trace_enter()/systrace_enter() functions.
 1.4 14-Oct-2003  fvdl Pass the right argument pointer to trace_enter/trace_exit.
 1.3 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.2 14-Jul-2003  lukem __KERNEL_RCSID()
 1.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.2.6 11-Dec-2005  christos Sync with head.
 1.1.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.2.4 21-Sep-2004  skrll Adapt to branch.
 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.9.4.1 02-Nov-2005  yamt sync with head.
 1.9.2.9 17-Mar-2008  yamt sync with head.
 1.9.2.8 27-Feb-2008  yamt sync with head.
 1.9.2.7 11-Feb-2008  yamt sync with head.
 1.9.2.6 21-Jan-2008  yamt sync with head
 1.9.2.5 15-Nov-2007  yamt sync with head.
 1.9.2.4 03-Sep-2007  yamt sync with head.
 1.9.2.3 26-Feb-2007  yamt sync with head.
 1.9.2.2 30-Dec-2006  yamt sync with head.
 1.9.2.1 21-Jun-2006  yamt sync with head.
 1.14.6.1 22-Apr-2006  simonb Sync with head.
 1.14.4.1 09-Sep-2006  rpaulo sync with head
 1.15.2.4 03-Sep-2006  yamt sync with head.
 1.15.2.3 11-Aug-2006  yamt sync with head
 1.15.2.2 13-Mar-2006  yamt sync with head.
 1.15.2.1 05-Mar-2006  yamt file syscall.c was added on branch yamt-pdpolicy on 2006-03-13 09:06:51 +0000
 1.19.2.2 07-Mar-2006  thorpej Syscall debug tracing is handled by trace_enter() / trace_exit(). Change
trace_is_enabled() to return TRUE if SYSCALL_DEBUG is defined, and g/c
all of the SYSCALL_DEBUG handling from individual system call dispatch
routines.
 1.19.2.1 07-Mar-2006  thorpej file syscall.c was added on branch elad-kernelauth on 2006-03-07 07:21:51 +0000
 1.21.2.3 30-Jan-2007  ad Remove support for SA. Ok core@.
 1.21.2.2 11-Jan-2007  ad Checkpoint work in progress.
 1.21.2.1 17-Nov-2006  ad Checkpoint work in progress.
 1.22.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.24.18.6 11-Nov-2007  joerg Sync with HEAD.
 1.24.18.5 04-Nov-2007  jmcneill Sync with HEAD.
 1.24.18.4 29-Oct-2007  joerg Sync with HEAD.
 1.24.18.3 28-Oct-2007  joerg Sync with HEAD.
 1.24.18.2 03-Sep-2007  jmcneill Sync with HEAD.
 1.24.18.1 16-Aug-2007  jmcneill Sync with HEAD.
 1.24.14.1 03-Sep-2007  skrll Sync with HEAD.
 1.24.10.1 03-Oct-2007  garbled Sync with HEAD
 1.24.2.3 03-Dec-2007  ad Sync with HEAD.
 1.24.2.2 23-Aug-2007  ad - Remove most calls to get kernel_lock during fault handling.
- By default start new LWPs without kernel_lock. Those returning to
userspace don't need it.
 1.24.2.1 20-Aug-2007  ad Sync with HEAD.
 1.25.2.3 23-Mar-2008  matt sync with HEAD
 1.25.2.2 09-Jan-2008  matt sync with HEAD
 1.25.2.1 06-Nov-2007  matt sync with HEAD
 1.26.4.1 13-Nov-2007  bouyer Sync with HEAD
 1.32.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.32.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.33.6.2 08-Jan-2008  bouyer Sync with HEAD
 1.33.6.1 02-Jan-2008  bouyer Sync with HEAD
 1.37.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.37.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.37.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.37.2.1 24-Mar-2008  keiichi sync with head.
 1.39.2.1 18-May-2008  yamt sync with head.
 1.41.2.2 04-May-2009  yamt sync with head.
 1.41.2.1 16-May-2008  yamt sync with head.
 1.42.6.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.42.6.1 19-Oct-2008  haad Sync with HEAD.
 1.42.2.2 14-Oct-2008  wrstuden Add a new vp-private flag, SAVP_FLAG_DELIVERING. This flag indicates
that the vp is in the process of delivering a new-thread upcall.
This is a BLOCKED or NEWPROC upcall. Do NOT generate any BLOCKED
upcalls while this is set. Set it at the end of sa_switchcall()
and clear it at syscall entry. Sadly, I have found no other
way to handle this. The old SA interface has no way for
userland to acknowledge that it got the upcall, so use syscall
entry as the indicator that libpthread got it.

This addresses the issue seen on current-users with firefox
dying with a blockedgen != unbockedgen error. The problem is we
deliver a BLOCKED upcall, but between the end of userret()
and when the CPU indicates that it's running in user mode, we take
a page fault. Said page fault blocks, blocking upcall delivery.
The original block, however, was short-lived, and the UNBLOCK
happens shortly. It happens before libpthread actually notices
the BLOCKED upcall. Boom!

Unfortunately a LOCKDEBUG/DIAGNOSTIC kernel still dies before
firefox opens. However this new issue is with uvm code calling
mtsleep when not holding a correct lock; sa_switch() is exploding
at KASSERT(lwp_locked(l, NULL)); before it's done _anything_.

Also, while here, add sa_system_disabled. This is an integer
that we examine when starting SA for a proc. If it's non-zero,
we error out. Once this is hooked into sysctl, you'll be able to
disable SA w/o recompiling.
 1.42.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.44.8.2 01-Nov-2009  jym Sync with HEAD.
 1.44.8.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.44.4.1 04-Feb-2012  bouyer Apply patch, requested by jmcneill in ticket #1668:
sys/arch/amd64/amd64/syscall.c patch
sys/arch/i386/i386/syscall.c patch
sys/arch/i386/i386/trap.c patch
sys/kern/kern_sig.c patch
sys/kern/kern_sleepq.c patch
sys/kern/kern_subr.c patch
sys/kern/sys_process.c patch
sys/secmodel/bsd44/secmodel_bsd44_suser.c patch
sys/sys/proc.h patch
sys/sys/ptrace.h patch

arch/i386/i386/machdep.c, arch/amd64/amd64/machdep.c (from
arch/x86/x86/machdep.c) by christos:
Remove code that was used to avoid register spills. setcontext(2) can change
the registers, so re-fetching will produce the wrong result for trace_exit().
arch/i386/i386/trap.c by reinoud:
Fix the illegal instruction return address. It was using the value of the
cpu's %cr2 register but thats not valid:

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

And this is thus NOT the illegal instruction address!
kern/kern_sig.c by christos:
PR kern/45327: Jared McNeill: ptrace: siginfo doesn't work with traced processes
When saving the signal in p->p_xstat, clear it from the pending mask, but
don't remove it from the siginfo queue, so that next time the debugger
delivers it, the original information is found.
When posting a signal from the debugger l->l_sigpendset is not set, so we
use the process pending signal and add it back to the process pending set.
Split sigget into sigget() and siggetinfo(). When a signal comes from the
debugger (l->l_sigpendset == NULL), using siggetinfo() try to fetch the
siginfo information from l->l_sigpend and then from p->p_sigpend if it
was not found. This allows us to pass siginfo information for traps from
the debugger.
don't delete signal from the debugger.
kern/kern_sleepq.c by christos:
PR kern/40594: Antti Kantee: Don't call issignal() here to determine what errno
to set for the interrupted syscall, because issignal() will consume the signal
and it will not be delivered to the process afterwards. Instead call
sigispending() (which now returns the first pending signal) and does not
consume the signal.
We need to process SA_STOP signals immediately, and not deliver them to
the process. Instead of re-structuring the code to do that, call issignal()
like before in that case. (tail -F /file^Zfg should not get interrupted).
kern/kern_subr.c by jmcneill, christos:
PR kern/45312: ptrace: PT_SETREGS can't alter system calls

Add a new PT_SYSCALLEMU request that cancels the current syscall, for
use with PT_SYSCALL.
For PT_SYSCALLEMU, no need to stop again on syscall exit.
ifdef unused variable with -UPTRACE

kern/sys_process.c, sys/proc.h, sys/ptrace.h, secmodel/bsd44/secmodel_bsd44_suser.c by jmcneill, christos:
PR kern/43681: PT_SYSCALL appears to be broken

sys_ptrace: For PT_CONTINUE/PT_SYSCALL/PT_DETACH, modify the p_trace_enabled
flag of the target process, not the calling process.
Process the signal now, otherwise calling issignal() and ignoring
the return will lose the signal if it came from the debugger
(issignal() clears p->p_xstat)
PR kern/45312: ptrace: PT_SETREGS can't alter system calls

Add a new PT_SYSCALLEMU request that cancels the current syscall, for
use with PT_SYSCALL.
PR kern/45330: ptrace: signals can alter syscall return values

process_stoptrace: defer signal processing to userret, ok christos@
 1.44.2.1 28-Apr-2009  skrll Sync with HEAD.
 1.130 20-Jun-2025  bouyer Remove #ifndef XENPV around x86_disable_intr()/enable_intr() in trap().
This was added by ad@ in trap.c 1.46 (in Apr 2008) as part of the
kernel preemption work. AFAIK trap() is always called with events
enabled on Xen, so I can't see why Xen wouldn't need x86_disable_intr()
when bare metal needs it.

Pointed out by riastradh@ in PR port-xen/58561, but it may be completely
irrelevant to the panic reported here.
 1.129 05-Oct-2023  ad branches: 1.129.6;
Arrange to update cached LWP credentials in userret() rather than during
syscall/trap entry, eliminating a test+branch on every syscall/trap.

This wasn't possible in the 3.99.x timeframe when l->l_cred came about
because there wasn't a reliable/timely way to force an ONPROC LWP running on
a remote CPU into the kernel (which is just about the only new thing in
this scheme).
 1.128 05-Sep-2020  maxv x86: rename PGEX_X -> PGEX_I

To match the x86 specification and the other OSes.
 1.127 09-Mar-2020  pgoyette Rework previous, so that the real syscall code is not invoked from within
the module_hook code. Otherwise, if the syscall just happens to be exit()
we will exit while still holding a reference to the hook's localcount, and
nothing will ever release that reference. Attempts to manually unload the
module will hang indefinitely, as will modstat(8).

XXX pullup-9
 1.126 08-Mar-2020  pgoyette Fix another left-over from last year's [pgoyette-compat] work. This
allows recognition of the oosyscall sequence for amd64.

Fixes PR kern/55038

XXX pullup-9
 1.125 21-Nov-2019  ad mi_userret(): take care of calling preempt(), set spc_curpriority directly,
and remove MD code that does the same.
 1.124 18-Sep-2019  kamil Avoid VLA to appease stack-protector

This has been reproduced with -O0 and -fsanitize=undefined.
 1.123 21-Aug-2019  maxv Style and cleanup.
 1.122 21-Aug-2019  maxv Remove the single-step check, it is wrong. There is no way we could
single-step on these entry points. If there were, we would be running
with the wrong GS.base, and we would have died long before.
 1.121 13-Jul-2019  mlelstv branches: 1.121.2;
Use common code for SMEP/SMAP panic to print more information and
allow debugging.
 1.120 15-May-2019  christos print also ksi_code.
 1.119 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.118 08-Mar-2019  msaitoh s/ the the / the /
 1.117 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.116 03-Feb-2019  mrg - add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily
 1.115 27-Jan-2019  pgoyette Merge the [pgoyette-compat] branch
 1.114 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.113 25-Feb-2018  maxv branches: 1.113.2; 1.113.4;
Mmh. We shouldn't read %cr2 here. %cr2 is initialized by the CPU only
during page faults (T_PAGEFLT), so here we're reading a value that comes
from a previous page fault.

That's a real problem; if you launch an unprivileged process, set up a
signal handler, make it sleep 10 seconds, and trigger a T_ALIGNFLT fault,
you get in si_addr the address of another LWP's page - and perhaps this
can be used to defeat userland ASLR.

This bug has been there since 2003.
 1.112 25-Feb-2018  maxv Fix handling of segment register faults when running with SVS. The behavior
is changed also in the non-SVS case.

I've put a documentation in amd64_trap.S. Basically, the problem with SVS
is that if iret faults, we already have a full trapframe pushed on the
stack and the CPU will push another frame on this stack (nested), but it
hits the redzone below the stack since it is still running with the user
page table loaded.

To fix that, we pop a good part of the trapframe earlier in intrfastexit.
If iret faults, the current %rsp has enough room for an iret frame, and
the CPU can push that without problem. We then switch back to the outer
iret frame (the frame the CPU was trying to pop by executing iret, but that
it didn't pop for real because iret faulted), call INTRENTRY, and handle
the trap as if it had been received from userland directly.
 1.111 20-Jan-2018  maxv Fix the double-fault handler. We're executing on ist1 and must not jump
out of it, so don't enable interrupts. And use the SVS_*_ALTSTACK macros.

While here, fix the NMI handler too: it should use SVS_LEAVE_ALTSTACK.
 1.110 10-Jan-2018  maxv Restrict the check: SMAP faults are always protection violations, as the
SDM points out, so make sure we have PGEX_P. This way NULL dereferences -
which are caused by an unmapped VA, and therefore are not protection
violations - don't take this branch, and don't display a misleading
"SMAP" in ddb.

Adding a PGEX_P check, or not, does not essentially change anything from
a security point of view, it's just a matter of what gets displayed when
a fatal fault comes in.

I didn't put PGEX_P until now, because initially when I wrote the SMAP
implementation Qemu did not always receive the fault if the PGEX_P check
was there, while a native i5 would. I'm unable to reproduce this issue
with a recent Qemu, so I assume I did something wrong when testing in the
first place.
 1.109 09-Dec-2017  christos adjust for new hexdump signature
 1.108 08-Dec-2017  christos make the TRAP_SIGDEBUG code less intrusive.
 1.107 07-Dec-2017  christos Put back the old syscall glue for netbsd32 binaries, and also TRAP_SIGDEBUG
while I am at it.
 1.106 07-Dec-2017  riastradh Attempt to clarify panic messages for null pointer access/execute.
 1.105 02-Dec-2017  maxv Drop COMPAT_10 on amd64. The support for it comes down to one ifdef in
trap.c - code that is incorrect anyway, there were originally three lcall
LDT slots, and here only one instruction is decoded.

Given that one of these slots was used by BSDi's syscall, also remove the
references to COMPAT_NOMID to make clear we don't support that (it already
is not enabled).

Note: for some reason, COMPAT_10 does not even compile, because there are
"multiple definitions of _KERNEL_OPT_COMPAT_...", and I don't really
understand where this comes from.
 1.104 21-Oct-2017  maxv Use labels instead of disassembling *(%rip). intrfastexit is now the
only place where the segregs can fault.
 1.103 21-Oct-2017  maxv Handle by default.
 1.102 17-Oct-2017  maxv Add support for SMAP on amd64.

PSL_AC is cleared from %rflags in each kernel entry point. In the copy
sections, a copy window is opened and the kernel can touch userland
pages. This window is closed when the kernel is done, either at the end
of the copy sections or in the fault-recover functions.

This implementation is not optimized yet, due to the fact that INTRENTRY
is a macro, and we can't hotpatch macros.

Sent on tech-kern@ a month or two ago, tested on a Kabylake.
 1.101 17-Sep-2017  maxv Remove the second argument from USERMODE and KERNELMODE, it is unused
now that we don't have vm86 anymore.
 1.100 15-Sep-2017  maxv Obviously, I was being absolutely dumb here; it's XEN, not Xen.
 1.99 03-Sep-2017  maxv Declare onfault_restore, and be stricter with SMEP.
 1.98 03-Sep-2017  maxv Treat page faults from iretq/etc as fatal, otherwise we could hide kernel
stack bugs. Note that it would be good to call check_swapgs from trap0e,
but a few things need to be fixed before that.
 1.97 03-Sep-2017  maxv Remove useless debug code, and split trap() into smaller functions, easier
to understand. NMIs take another, faster path now. No functional change
beyond that.
 1.96 24-Apr-2017  chs branches: 1.96.4;
restore the ability to run netbsd 1.0 32-bit executables
by checking for the relevant lcall instruction in the trap handler
and treating it as a syscall.
 1.95 23-Mar-2017  maxv Remove this call gate on amd64, it is useless and vulnerable.

Call gates do not modify %rflags, so interrupts are not disabled when
entering the gate. There is a small window where we are in kernel mode and
with a userland %gs, and if an interrupt happens here we will rejump into
the kernel but not switch to the kernel TLS.

Userland can simply perform a gate call in a loop, and hope that at some
point an interrupt will be received in this window - which necessarily will
be the case. With a specially-crafted %gs it is certainly enough to
escalate privileges.
 1.94 18-Mar-2017  maxv Mmh, allow iret to be handled when an #SS fault (T_STKFLT) happens. Even
if the sdm is far from being clear, it appears that iret can trigger an #SS
fault if %ss points to a writable but non-present segment; in which case
the kernel would panic, thinking the fault was internal to it.

In particular, userland can create a broken segment in the ldt with
USER_LDT, update its %ss with setcontext and trigger the panic. I don't
think amd64 is affected since USER_LDT does not exist there, and the
changes on tf_ss seem correct - but I'm still adding T_STKFLT for safety.
 1.93 09-Mar-2017  chs improve readability of TRAP_SIGDEBUG info and add fsbase/gsbase.
 1.92 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.91 17-Feb-2017  kamil Add new si_code TRAP_DBREG

It replaces previous TRAP_HWWPT and is designed to be used for debug
register traps (both watchpoints and breakpoints).

TRAP_HWWPT wasn't documented in siginfo(2) neither noted in doc/CHANGES -
- document it and add new entry in CHANGES. This move is a step towards
switch the watchpoint ptrace(2) api to PT_*DBREGS.

This code was introduced recently and has no impact on stable releases.

Sponsored by <The NetBSD Foundation>
 1.90 14-Feb-2017  maxv Add most of my USER_LDT code for amd64, but disable it and put a comment
about why Wine still does not work.

Nothing changes, but at least it is a step forward.
 1.89 18-Jan-2017  kamil Embed hardware trap and its type that fired (x86), information for tracers

Now x86 throws SIGTRAP on hardware exception with:
- si_code TRAP_HWWPT - dedicated for hw assisted watchpoint interface
- si_trap - unchanged (T_TRCTRAP)
- si_trap2 - watchpoint number that fired
- si_trap3 - watchpoint specific event description

x86 returns in si_trap3 one of the field from <x86/dbregs.h>
- X86_HW_WATCHPOINT_EVENT_FIRED - watchpoint fired
- X86_HW_WATCHPOINT_EVENT_FIRED_AND_SSTEP - watchpoint fired under PT_STEP

Othe changes:
- restrict more code from <x86/dbregs.h> to _KERNEL

Sponsored bt <The NetBSD Foundation>
 1.88 15-Dec-2016  kamil branches: 1.88.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.87 26-Oct-2016  christos print some more stuff
 1.86 25-Sep-2016  maxv Revert my previous change. It is too severe: a fault might be happening in
the kernel page if the map is pageable - implying it is not pmap_kernel. I
thought it wouldn't be the case.
 1.85 16-Sep-2016  maxv Put two KASSERTs, to make sure the fault is happening in the correct
half of the vm space when using special copy functions. It can detect
bugs where the kernel would fault when copying a kernel buffer which
it wrongly believes comes from userland.
 1.84 11-Aug-2016  maxv Reduce the diff, and typo.
 1.83 13-Dec-2015  maxv branches: 1.83.2;
Implement amd64 support for SMEP - Supervisor Mode Execution Protection.

Now, on CPUs that support this feature, if the kernel tries to execute
an instruction located in userland, the CPU will trigger a page fault.

Tested on amd64 (Intel Core i5).
 1.82 28-Nov-2015  dholland If the kernel jumps to NULL, print where it came from instead of trying
to dereference and faulting again.
 1.81 22-Nov-2015  maxv KNF a bit, so I don't get scared each time I open a file
 1.80 27-Feb-2015  christos Tidy up error handling, and return SIGBUS for mmap past the end of file
as required by the spec.
 1.79 18-Oct-2014  snj branches: 1.79.2;
src is too big these days to tolerate superfluous apostrophes. It's
"its", people!
 1.78 11-Mar-2014  para branches: 1.78.4; 1.78.6; 1.78.10;
mark a diagnostic only variable
 1.77 12-Feb-2014  dsl Change the argument to fpudna() to be the trapframe.
Move the checks for fpu traps in kernel into x86/fpu.c.
Remove the code from amd64/trap.c related to fpu traps (they've not gone
there for ages - expect to panic in kernel mode).
In fpudna():
- Don't actually enable hardware interrupts unless we need to
allow in IPIs.
- There is no point in enabling them when they are blocked in software
(by splhigh()).
- Keep the splhigh() to avoid a load of the KASSERTS() firing.
 1.76 11-Feb-2014  dsl Move sys/arch/amd64/amd64/fpu.c and sys/arch/amd64/include/fpu.h
into sys/arch/x86 in preparation for using the same code for i386.
 1.75 14-Jan-2013  christos branches: 1.75.2;
print the lid too.
 1.74 28-Aug-2012  christos branches: 1.74.2;
don't undef TRAP_SIGDEBUG
 1.73 15-Jul-2012  dsl Rename MDP_IRET to MDL_IRET since it is an lwp flag, not a proc one.
Add an MDL_COMPAT32 flag to the lwp's md_flags, set it for 32bit lwps
and use it to force 'return to user' with iret (as is done when
MDL_IRET is set).
Split the iret/sysret code paths much later.
Remove all the replicated code for 32bit system calls - which was only
needed so that iret was always used.
frameasm.h for XEN contains '#define swapgs', while XEN probable never
needs swapgs, this is likely to be confusing.
Add a SWAPGS which is a nop on XEN and swapgs otherwise.
(I've not yet checked all the swapgs in files that include frameasm.h)
Simple x86 programs still work.
Hijack 6.99.9 kernel bump (needed for compat32 modules)
 1.72 30-Jun-2012  rmind trap: move out info printing to trap_print() on amd64, reduce the differences
between amd64 and i386, add lowest kernel stack address.
 1.71 22-May-2012  dsl Treat traps in kernel mode during the 'return to user' iret sequence
as user faults.
Based heavily in the i386 code with the correct opcode bytes inserted.
iret path tested, arranging for segment register errors is harder.
User %fs and %gs (32bit apps) are loaded much earlier and any errors
will generate kernel panics - there is probably code to try to stop
the invalid values being set.
 1.70 19-Feb-2012  rmind Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.
 1.69 04-Feb-2012  reinoud branches: 1.69.2;
Fix address of SIGILL instruction on amd64 as previously fixed on i386. It
used to return the effective address of the faulted memory access but on
SIGILL its obviously wrong since there is no MMU fault.

Instead return the instruction counter register.
OK by releng
 1.68 06-Nov-2011  cherry branches: 1.68.4;
Use the right format strings with printf
 1.67 05-Oct-2011  njoly branches: 1.67.2;
Remove extra space.
 1.66 03-Apr-2011  dyoung branches: 1.66.2;
Clean up excessive #ifdef'age of NMI trap handling for amd64/i386/xen.
Handle NMI in all Xen kernels.
 1.65 20-Dec-2010  matt branches: 1.65.2;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.
 1.64 26-Jul-2010  christos follow suit with the i386, and correct the siginfo codes for integer overflow
and zerodivide.
 1.63 07-Jul-2010  chs clean up the check for tracing into a syscall handler.
 1.62 23-Apr-2010  rmind Remove lwp_uc_pool, replace it with kmem(9), plus add some consistency.
As discussed, a while ago, with ad@.
 1.61 23-Feb-2010  cegger branches: 1.61.2;
dtrace kernel hooks

ok darran@
 1.60 21-Nov-2009  rmind branches: 1.60.2;
Use lwp_getpcb() on x86 MD code, clean from struct user usage.
 1.59 29-Jul-2009  rmind Reduce the difference between i386 and amd64 trap handler.
No functional changes intended.
 1.58 29-Jul-2009  rmind T_ASTFLT|T_USER: check for LP_OWEUPC in l_lpflag, not l_flag. Also, flag
unset was on p->p_flag. Luckily, it did not corrupt the p_flag, because
we don't have LW_ flag matching LP_OWEUPC.
 1.57 16-Jul-2009  christos a little more diagnostic
 1.56 16-Jul-2009  christos handle protection fault properly.
 1.55 28-Mar-2009  rmind Change amd64 fault handler to check instruction pointer for copyin/out et al
functions, like in i386. Avoids setting pcb_onfault, saves few instructions.
 1.54 24-Feb-2009  yamt - rewrite x86 nmi dispatcher so that establish and disesablish are safe
on a running system.
- adapt existing users of the api. (elan)
- adapt tprof_pmi driver to use the api.
 1.53 14-Nov-2008  ad branches: 1.53.4;
Remove unneeded ifdefs.
 1.52 15-Oct-2008  wrstuden branches: 1.52.2; 1.52.4; 1.52.6;
Merge wrstuden-revivesa into HEAD.
 1.51 01-Jun-2008  ad branches: 1.51.4;
Make trap counters per-cpu, like syscalls.
 1.50 30-May-2008  ad PR kern/38663 Kernel preemption can't be enabled on x86 because of amd64
FPU handling

Adjust FPU trap handling to be preemption safe.
 1.49 30-May-2008  ad Since breakpoints don't work, dump basic info about the trap before
entering the debugger. Sometimes ddb only makes the situation worse.
 1.48 30-May-2008  ad Don't try to resolve pagefaults from interrupt mode; it can result in a
LOCKDEBUG panic, or the machine getting really confused. Instead, panic
at the earliest oppertunity.
 1.47 28-Apr-2008  martin branches: 1.47.2;
Remove clause 3 and 4 from TNF licenses
 1.46 28-Apr-2008  ad Make kernel pagefault handling preeemption safe.
 1.45 16-Apr-2008  cegger branches: 1.45.2; 1.45.4;
use POSIX integer types
 1.44 16-Jan-2008  ad branches: 1.44.6;
Remove options MATH_EMULATE.
 1.43 02-Jan-2008  ad Merge vmlocking2 to head.
 1.42 01-Jan-2008  yamt a simple performance monitor based profiler, inspired from linux oprofile.
 1.41 01-Jan-2008  yamt always consider T_NMI as !T_USER regardless of trapframe.
 1.40 03-Dec-2007  ad branches: 1.40.4;
Merge from vmlocking.
 1.39 02-Dec-2007  ad branches: 1.39.2;
Don't clear ci_want_resched in MD code; it's done in mi_switch().
 1.38 24-Nov-2007  christos preserve cr2 on pcb for the benefit of linux emulation.
 1.37 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.36 15-Nov-2007  ad Remove support for 80386 level CPUs. PR port-i386/36163.
 1.35 24-Oct-2007  ad branches: 1.35.2;
Make ras_lookup() lockless.
 1.34 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.33 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.32 04-Jun-2007  xtraeme branches: 1.32.8; 1.32.10; 1.32.12; 1.32.14;
Ansify, de-__P(), unregister.
 1.31 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.30 04-Mar-2007  christos branches: 1.30.2; 1.30.4; 1.30.10;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.29 20-Feb-2007  ad trap(): after handling a copy fault from the kernel, call
KERNEL_UNLOCK_ONE(), not KERNEL_UNLOCK_LAST().
 1.28 09-Feb-2007  ad branches: 1.28.2;
Merge newlock2 to head.
 1.27 23-Jul-2006  ad branches: 1.27.4; 1.27.8; 1.27.14;
Use the LWP cached credentials where sane.
 1.26 19-Jul-2006  ad - Hold a reference to the process credentials in each struct lwp.
- Update the reference on syscall and user trap if p_cred has changed.
- Collect accounting flags in the LWP, and collate on LWP exit.
 1.25 14-May-2006  elad integrate kauth.
 1.24 02-May-2006  drochner comment out FPU DNA handling; this cannot be reached tbomk
because that trap is dealt with in fpu.c
 1.23 15-Mar-2006  drochner branches: 1.23.2;
adapt to uvm_fault() interface cleanup: kill the useless 3rd argument
 1.22 27-Dec-2005  chs branches: 1.22.4; 1.22.6; 1.22.8; 1.22.10;
use panic() instead of cpu_reboot() for unhandled kernel traps.
 1.21 11-Dec-2005  christos merge ktrace-lwp.
 1.20 20-May-2005  fvdl branches: 1.20.2;
If p->emul->e_usertrap is set, call it for T_USER|T_PAGEFAULT traps to
do possible work.
 1.19 28-Aug-2004  jdolecek branches: 1.19.10; 1.19.12;
use uvm_grow() to update stack segment size on stack page fault instead
of MD code
 1.18 23-Mar-2004  drochner -don't refer to oosyscall() unless COMPAT_10 or COMPAT_IBCS2 is defined
-improve diagnostic message on bus errors in the TRAP_SIGDEBUG case
 1.17 14-Mar-2004  cl add kernel part of concurrency support for SA on MP systems
- move per VP data into struct sadata_vp referenced from l->l_savp
* VP id
* lock on VP data
* LWP on VP
* recently blocked LWP on VP
* queue of LWPs woken which ran on this VP before sleep
* faultaddr
* LWP cache for upcalls
* upcall queue
- add current concurrency and requested concurrency variables
- make process exit run LWP on all VPs
- make signal delivery consider all VPs
- make timer events consider all VPs
- add sa_newsavp to allocate new sadata_vp structure
- add sa_increaseconcurrency to prepare new VP
- make sys_sa_setconcurrency request new VP or wakeup idle VP
- make sa_yield lower current concurrency
- set sa_cpu = VP id in upcalls
- maintain cached LWPs per VP
 1.16 19-Feb-2004  drochner use no-execute page permissions if supported
 1.15 05-Nov-2003  fvdl Remove extraneous (
 1.14 04-Nov-2003  dsl Remove p_nras from struct proc - use LIST_EMPTY(&p->p_raslist) instead.
Remove p_raslock and rename p_lwplock p_lock (one lock is enough).
Simplify window test when adding a ras and correct test on VM_MAXUSER_ADDRESS.
Avoid unpredictable branch in i386 locore.S
(pad fields left in struct proc to avoid kernel bump)
 1.13 21-Oct-2003  fvdl Correct argument to preempt().
 1.12 08-Oct-2003  fvdl Adapt for ksiginfo changes.
 1.11 06-Oct-2003  fvdl SIGINFO support.
Todo: 32bit compat support (COMPAT_NETBSD32 will not compile right now,
as it won't on other platforms).
 1.10 26-Sep-2003  christos fix fallout from frame to frame * conversion.
 1.9 16-Sep-2003  cl add MD part of SA/pthread pagefault handling on amd64
 1.8 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.7 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.6 14-Jul-2003  lukem __KERNEL_RCSID()
 1.5 23-Jun-2003  martin branches: 1.5.2;
Make sure to include opt_foo.h if a defflag option FOO is used.
 1.4 27-May-2003  christos make this compile again with -DDEBUG
 1.3 11-May-2003  yamt remove L_BIGLOCK check for kernel-mode pagefaults in trap().
syscall() and its variants actually does copyin() without biglock.

ok'ed by Frank van der Linden.
 1.2 04-May-2003  fvdl unifdef bus/segv/ill logging.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.5.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.5.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.5.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.5.2.2 03-Sep-2004  skrll Sync with HEAD
 1.5.2.1 03-Aug-2004  skrll Sync with HEAD
 1.19.12.1 16-Oct-2006  ghen Pull up following revision(s) (requested by tron in ticket #1550):
sys/arch/amd64/amd64/trap.c: revision 1.22
use panic() instead of cpu_reboot() for unhandled kernel traps.
 1.19.10.1 16-Oct-2006  ghen Pull up following revision(s) (requested by tron in ticket #1550):
sys/arch/amd64/amd64/trap.c: revision 1.22
use panic() instead of cpu_reboot() for unhandled kernel traps.
 1.20.2.7 21-Jan-2008  yamt sync with head
 1.20.2.6 07-Dec-2007  yamt sync with head
 1.20.2.5 27-Oct-2007  yamt sync with head.
 1.20.2.4 03-Sep-2007  yamt sync with head.
 1.20.2.3 26-Feb-2007  yamt sync with head.
 1.20.2.2 30-Dec-2006  yamt sync with head.
 1.20.2.1 21-Jun-2006  yamt sync with head.
 1.22.10.4 12-May-2006  elad include sys/kauth.h where appropriate.
 1.22.10.3 11-May-2006  elad sync with head
 1.22.10.2 19-Apr-2006  elad sync with head - hopefully this will work
 1.22.10.1 08-Mar-2006  elad Adapt to kernel authorization KPI.

I expect *some* lossage here...
 1.22.8.3 11-Aug-2006  yamt sync with head
 1.22.8.2 24-May-2006  yamt sync with head.
 1.22.8.1 01-Apr-2006  yamt sync with head.
 1.22.6.2 01-Jun-2006  kardel Sync with head.
 1.22.6.1 22-Apr-2006  simonb Sync with head.
 1.22.4.1 09-Sep-2006  rpaulo sync with head
 1.23.2.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.27.14.1 22-Aug-2012  bouyer Apply patch, requested by spz in ticket #1454:
sys/arch/amd64/amd64/trap.c: patch

Fix potential stack frame corruption
 1.27.8.1 22-Aug-2012  bouyer Apply patch, requested by spz in ticket #1454:
sys/arch/amd64/amd64/trap.c: patch

Fix potential stack frame corruption
 1.27.4.7 30-Jan-2007  ad Remove support for SA. Ok core@.
 1.27.4.6 11-Jan-2007  ad Checkpoint work in progress.
 1.27.4.5 29-Dec-2006  ad Checkpoint work in progress.
 1.27.4.4 17-Nov-2006  ad Checkpoint work in progress.
 1.27.4.3 21-Oct-2006  ad - Remove sched_lock assertion.
- Update for need_proftick() change.
 1.27.4.2 20-Oct-2006  ad On second thought, don't set ksi.ksi_lid here - do it in trapsignal().
 1.27.4.1 20-Oct-2006  ad - Save the LWP ID for traps.
- Remove sched_lock assertion.
 1.28.2.3 12-Mar-2007  rmind Sync with HEAD.
 1.28.2.2 03-Mar-2007  yamt adapt amd64.

XXX changes in identcpu.c is minmum for MONITOR.
XXX identcpu.c should be shared with i386.
 1.28.2.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.30.10.2 26-Jun-2007  garbled Sync with HEAD.
 1.30.10.1 22-May-2007  matt Update to HEAD.
 1.30.4.1 11-Jul-2007  mjf Sync with head.
 1.30.2.7 03-Dec-2007  ad Sync with HEAD.
 1.30.2.6 03-Dec-2007  ad Sync with HEAD.
 1.30.2.5 01-Nov-2007  ad trap

- Don't clear ci_want_resched here.
- Don't acquire kernel_lock for delayed profiling updates.
 1.30.2.4 23-Oct-2007  ad Sync with head.
 1.30.2.3 23-Aug-2007  ad - Remove most calls to get kernel_lock during fault handling.
- By default start new LWPs without kernel_lock. Those returning to
userspace don't need it.
 1.30.2.2 09-Jun-2007  ad Sync with head.
 1.30.2.1 27-May-2007  ad Sync with head.
 1.32.14.4 18-Nov-2007  bouyer Sync with HEAD
 1.32.14.3 13-Nov-2007  bouyer Sync with HEAD
 1.32.14.2 25-Oct-2007  bouyer Sync with HEAD.
 1.32.14.1 17-Oct-2007  bouyer amd64 (aka x86-64) support for Xen. Based on the OpenBSD port done by
Mathieu Ropert in 2006.
DomU-only for now. An INSTALL_XEN3_DOMU kernel with a ramdisk will boot to
sysinst if you're lucky. Often it panics because a runable LWP has
a NULL stack (really, it's all of l->l_addr which is has been zeroed out
while the process was on the queue !)
TODO:
- bug fixes :)
- Most of the xpq_* functions should be shared with xen/i386
- The xen/i386 assembly bootstrap code should be remplaced with the C
version in xenamd64/amd64/xpmap.c
- see if a config(5) trick could allow to merge xenamd64 back to xen or amd64.
 1.32.12.1 30-Sep-2007  yamt implement deferred pmap switching for amd64, and make amd64 use
x86 shared pmap code. it makes several i386 pmap improvements available
to amd64, including tlb shootdown reduction and bug fixes from Stephan Uphoff.
 1.32.10.3 23-Mar-2008  matt sync with HEAD
 1.32.10.2 09-Jan-2008  matt sync with HEAD
 1.32.10.1 06-Nov-2007  matt sync with HEAD
 1.32.8.6 09-Dec-2007  jmcneill Sync with HEAD.
 1.32.8.5 03-Dec-2007  joerg Sync with HEAD.
 1.32.8.4 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.32.8.3 21-Nov-2007  joerg Sync with HEAD.
 1.32.8.2 28-Oct-2007  joerg Sync with HEAD.
 1.32.8.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.35.2.3 18-Feb-2008  mjf Sync with HEAD.
 1.35.2.2 08-Dec-2007  mjf Sync with HEAD.
 1.35.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.39.2.2 08-Dec-2007  ad Sync with head.
 1.39.2.1 04-Dec-2007  ad Pull the vmlocking changes into a new branch.
 1.40.4.2 19-Jan-2008  bouyer Sync with HEAD
 1.40.4.1 02-Jan-2008  bouyer 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.4.6 11-Aug-2010  yamt sync with head.
 1.45.4.5 11-Mar-2010  yamt sync with head
 1.45.4.4 19-Aug-2009  yamt sync with head.
 1.45.4.3 18-Jul-2009  yamt sync with head.
 1.45.4.2 04-May-2009  yamt sync with head.
 1.45.4.1 16-May-2008  yamt sync with head.
 1.45.2.2 04-Jun-2008  yamt sync with head
 1.45.2.1 18-May-2008  yamt sync with head.
 1.47.2.4 24-Jun-2008  wrstuden Hand-merge files that didn't merge right in recent sync w/ current.
 1.47.2.3 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.47.2.2 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.47.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.51.4.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.51.4.1 19-Oct-2008  haad Sync with HEAD.
 1.52.6.4 15-Jun-2012  bouyer Fix build fallout from ticket #1772 for Xen kernels
 1.52.6.3 12-Jun-2012  riz Pull up following revision(s) (requested by spz in ticket #1772):
sys/arch/amd64/amd64/trap.c: revision 1.71 via patch
sys/arch/amd64/amd64/vector.S: revision 1.41 via patch
sys/arch/amd64/include/frameasm.h: patch

Treat traps in kernel mode during the 'return to user' iret sequence
as user faults.
Based heavily in the i386 code with the correct opcode bytes inserted.
iret path tested, arranging for segment register errors is harder.
User %fs and %gs (32bit apps) are loaded much earlier and any errors
will generate kernel panics - there is probably code to try to stop
the invalid values being set.
If we get a fault setting the user %gs, or on a iret that is returning
to userspace, we must do a 'swapgs' to reload the kernel %gs_base.
Also save the %ds, %es, %fs, %gs selector values in the frame so
they can be restored if we finally return to user (probably after
an application SIGSEGV handler has fixed the error).
Without this any such fault leaves the kernel running with the wrong
%gs offset and it will most likely fault again early in trap().
Repeats until the stack tramples on something important.
iret change works, invalid %gs is a little harder to arrange.
 1.52.6.2 14-Aug-2009  snj Pull up following revision(s) (requested by rmind in ticket #897):
sys/arch/amd64/amd64/trap.c: revision 1.58
T_ASTFLT|T_USER: check for LP_OWEUPC in l_lpflag, not l_flag. Also, flag
unset was on p->p_flag. Luckily, it did not corrupt the p_flag, because
we don't have LW_ flag matching LP_OWEUPC.
 1.52.6.1 21-Jul-2009  snj branches: 1.52.6.1.2;
Pull up following revision(s) (requested by rmind in ticket #865):
sys/arch/amd64/amd64/trap.c: revisions 1.56, 1.57
handle protection fault properly.
 1.52.6.1.2.1 21-Apr-2010  matt sync to netbsd-5
 1.52.4.4 15-Jun-2012  bouyer Fix build fallout from ticket #1772 for Xen kernels
 1.52.4.3 12-Jun-2012  riz Pull up following revision(s) (requested by spz in ticket #1772):
sys/arch/amd64/amd64/trap.c: revision 1.71 via patch
sys/arch/amd64/amd64/vector.S: revision 1.41 via patch
sys/arch/amd64/include/frameasm.h: patch

Treat traps in kernel mode during the 'return to user' iret sequence
as user faults.
Based heavily in the i386 code with the correct opcode bytes inserted.
iret path tested, arranging for segment register errors is harder.
User %fs and %gs (32bit apps) are loaded much earlier and any errors
will generate kernel panics - there is probably code to try to stop
the invalid values being set.
If we get a fault setting the user %gs, or on a iret that is returning
to userspace, we must do a 'swapgs' to reload the kernel %gs_base.
Also save the %ds, %es, %fs, %gs selector values in the frame so
they can be restored if we finally return to user (probably after
an application SIGSEGV handler has fixed the error).
Without this any such fault leaves the kernel running with the wrong
%gs offset and it will most likely fault again early in trap().
Repeats until the stack tramples on something important.
iret change works, invalid %gs is a little harder to arrange.
 1.52.4.2 14-Aug-2009  snj branches: 1.52.4.2.2;
Pull up following revision(s) (requested by rmidn in ticket #897):
sys/arch/amd64/amd64/trap.c: revision 1.58
T_ASTFLT|T_USER: check for LP_OWEUPC in l_lpflag, not l_flag. Also, flag
unset was on p->p_flag. Luckily, it did not corrupt the p_flag, because
we don't have LW_ flag matching LP_OWEUPC.
 1.52.4.1 21-Jul-2009  snj Pull up following revision(s) (requested by rmind in ticket #865):
sys/arch/amd64/amd64/trap.c: revisions 1.56, 1.57
handle protection fault properly.
 1.52.4.2.2.2 15-Jun-2012  bouyer Fix build fallout from ticket #1772 for Xen kernels
 1.52.4.2.2.1 12-Jun-2012  riz Pull up following revision(s) (requested by spz in ticket #1772):
sys/arch/amd64/amd64/trap.c: revision 1.71 via patch
sys/arch/amd64/amd64/vector.S: revision 1.41 via patch
sys/arch/amd64/include/frameasm.h: patch

Treat traps in kernel mode during the 'return to user' iret sequence
as user faults.
Based heavily in the i386 code with the correct opcode bytes inserted.
iret path tested, arranging for segment register errors is harder.
User %fs and %gs (32bit apps) are loaded much earlier and any errors
will generate kernel panics - there is probably code to try to stop
the invalid values being set.
If we get a fault setting the user %gs, or on a iret that is returning
to userspace, we must do a 'swapgs' to reload the kernel %gs_base.
Also save the %ds, %es, %fs, %gs selector values in the frame so
they can be restored if we finally return to user (probably after
an application SIGSEGV handler has fixed the error).
Without this any such fault leaves the kernel running with the wrong
%gs offset and it will most likely fault again early in trap().
Repeats until the stack tramples on something important.
iret change works, invalid %gs is a little harder to arrange.
 1.52.2.3 28-Apr-2009  skrll Sync with HEAD.
 1.52.2.2 03-Mar-2009  skrll Sync with HEAD.
 1.52.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.53.4.6 02-May-2011  jym Sync with head.
 1.53.4.5 10-Jan-2011  jym Sync with HEAD
 1.53.4.4 24-Oct-2010  jym Sync with HEAD
 1.53.4.3 01-Nov-2009  jym Sync with HEAD.
 1.53.4.2 23-Jul-2009  jym Sync with HEAD.
 1.53.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.60.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.60.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.61.2.3 21-Apr-2011  rmind sync with head
 1.61.2.2 05-Mar-2011  rmind sync with head
 1.61.2.1 30-May-2010  rmind sync with head
 1.65.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.66.2.1 09-Sep-2011  cherry Use appropriate format strings.
 1.67.2.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.67.2.4 23-Jan-2013  yamt sync with head
 1.67.2.3 30-Oct-2012  yamt sync with head
 1.67.2.2 17-Apr-2012  yamt sync with head
 1.67.2.1 10-Nov-2011  yamt sync with head
 1.68.4.3 02-Jun-2012  mrg sync to latest -current.
 1.68.4.2 24-Feb-2012  mrg sync to -current.
 1.68.4.1 18-Feb-2012  mrg merge to -current.
 1.69.2.3 08-Aug-2017  martin Pull up following revision(s) (requested by maxv in ticket #1464):

sys/arch/i386/i386/trap.c: revision 1.288 (patch)
sys/arch/i386/i386/machdep.c: revision 1.783 (patch)
sys/arch/i386/i386/locore.S: revision 1.146 (patch)
sys/arch/amd64/amd64/locore.S: revision 1.122,1.124 (patch)
sys/arch/amd64/amd64/machdep.c revision 1.254 (patch)
sys/arch/amd64/amd64/trap.c: revision 1.95-1.96 (patch)

Remove the osyscall call gate and emulate it. There is a
one-instruction race in it that could panic the kernel.

Restore the ability to run netbsd 1.0 32-bit executables by checking
for the relevant lcall instruction in the trap handler and treating it
as a syscall.
 1.69.2.2 25-Mar-2017  snj Pull up following revision(s) (requested by maxv in ticket #1446):
sys/arch/amd64/amd64/trap.c: revision 1.94
sys/arch/i386/i386/trap.c: revision 1.287
Mmh, allow iret to be handled when an #SS fault (T_STKFLT) happens. Even
if the sdm is far from being clear, it appears that iret can trigger an #SS
fault if %ss points to a writable but non-present segment; in which case
the kernel would panic, thinking the fault was internal to it.
In particular, userland can create a broken segment in the ldt with
USER_LDT, update its %ss with setcontext and trigger the panic. I don't
think amd64 is affected since USER_LDT does not exist there, and the
changes on tf_ss seem correct - but I'm still adding T_STKFLT for safety.
 1.69.2.1 03-Jun-2012  jdc branches: 1.69.2.1.4; 1.69.2.1.6;
Pull up revisions:
src/sys/arch/amd64/include/frameasm.h revision 1.17-1.19
src/sys/arch/amd64/amd64/vector.S revision 1.40-1.41
src/sys/arch/amd64/amd64/trap.c revision 1.71
(requested by dsl in ticket #280).

Move all the XEN differences to a single conditional.
Merge the XEN/non-XEN versions of INTRFASTEXIT and
INTR_RECURSE_HWFRAME by using extra defines.
Split INTRENTRY so that code can insert extra instructions
inside user/kernel conditional.

Add a ';' that got deleted in a slight tidyup.

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

Let the user of INTRENTRY_L() place a label on the 'swapgs' used
when faulting from user space.

If we get a fault setting the user %gs, or on a iret that is returning
to userspace, we must do a 'swapgs' to reload the kernel %gs_base.
Also save the %ds, %es, %fs, %gs selector values in the frame so
they can be restored if we finally return to user (probably after
an application SIGSEGV handler has fixed the error).
Without this any such fault leaves the kernel running with the wrong
%gs offset and it will most likely fault again early in trap().
Repeats until the stack tramples on something important.
iret change works, invalid %gs is a little harder to arrange.

Treat traps in kernel mode during the 'return to user' iret sequence
as user faults.
Based heavily in the i386 code with the correct opcode bytes inserted.
iret path tested, arranging for segment register errors is harder.
User %fs and %gs (32bit apps) are loaded much earlier and any errors
will generate kernel panics - there is probably code to try to stop
the invalid values being set.
 1.69.2.1.6.2 08-Aug-2017  martin Pull up following revision(s) (requested by maxv in ticket #1464):

sys/arch/i386/i386/trap.c: revision 1.288 (patch)
sys/arch/i386/i386/machdep.c: revision 1.783 (patch)
sys/arch/i386/i386/locore.S: revision 1.146 (patch)
sys/arch/amd64/amd64/locore.S: revision 1.122,1.124 (patch)
sys/arch/amd64/amd64/machdep.c revision 1.254 (patch)
sys/arch/amd64/amd64/trap.c: revision 1.95-1.96 (patch)

Remove the osyscall call gate and emulate it. There is a
one-instruction race in it that could panic the kernel.

Restore the ability to run netbsd 1.0 32-bit executables by checking
for the relevant lcall instruction in the trap handler and treating it
as a syscall.
 1.69.2.1.6.1 25-Mar-2017  snj Pull up following revision(s) (requested by maxv in ticket #1446):
sys/arch/amd64/amd64/trap.c: revision 1.94
sys/arch/i386/i386/trap.c: revision 1.287
Mmh, allow iret to be handled when an #SS fault (T_STKFLT) happens. Even
if the sdm is far from being clear, it appears that iret can trigger an #SS
fault if %ss points to a writable but non-present segment; in which case
the kernel would panic, thinking the fault was internal to it.
In particular, userland can create a broken segment in the ldt with
USER_LDT, update its %ss with setcontext and trigger the panic. I don't
think amd64 is affected since USER_LDT does not exist there, and the
changes on tf_ss seem correct - but I'm still adding T_STKFLT for safety.
 1.69.2.1.4.2 08-Aug-2017  martin Pull up following revision(s) (requested by maxv in ticket #1464):

sys/arch/i386/i386/trap.c: revision 1.288 (patch)
sys/arch/i386/i386/machdep.c: revision 1.783 (patch)
sys/arch/i386/i386/locore.S: revision 1.146 (patch)
sys/arch/amd64/amd64/locore.S: revision 1.122,1.124 (patch)
sys/arch/amd64/amd64/machdep.c revision 1.254 (patch)
sys/arch/amd64/amd64/trap.c: revision 1.95-1.96 (patch)

Remove the osyscall call gate and emulate it. There is a
one-instruction race in it that could panic the kernel.

Restore the ability to run netbsd 1.0 32-bit executables by checking
for the relevant lcall instruction in the trap handler and treating it
as a syscall.
 1.69.2.1.4.1 25-Mar-2017  snj Pull up following revision(s) (requested by maxv in ticket #1446):
sys/arch/amd64/amd64/trap.c: revision 1.94
sys/arch/i386/i386/trap.c: revision 1.287
Mmh, allow iret to be handled when an #SS fault (T_STKFLT) happens. Even
if the sdm is far from being clear, it appears that iret can trigger an #SS
fault if %ss points to a writable but non-present segment; in which case
the kernel would panic, thinking the fault was internal to it.
In particular, userland can create a broken segment in the ldt with
USER_LDT, update its %ss with setcontext and trigger the panic. I don't
think amd64 is affected since USER_LDT does not exist there, and the
changes on tf_ss seem correct - but I'm still adding T_STKFLT for safety.
 1.74.2.3 03-Dec-2017  jdolecek update from HEAD
 1.74.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.74.2.1 25-Feb-2013  tls resync with head
 1.75.2.1 18-May-2014  rmind sync with head
 1.78.10.3 26-Apr-2017  martin Pull up following revision(s) (requested by chs in ticket #1410):
sys/arch/amd64/amd64/trap.c: revision 1.96
restore the ability to run netbsd 1.0 32-bit executables
by checking for the relevant lcall instruction in the trap handler
and treating it as a syscall.
 1.78.10.2 26-Apr-2017  martin Pull up following revision(s) (requested by bsiegert in ticket #1397):

sys/arch/amd64/amd64/locore.S 1.122 (via patch)
sys/arch/amd64/amd64/machdep.c 1.254 (via patch)
sys/arch/amd64/amd64/trap.c 1.95 (via patch)

Remove the call gate on amd64, it is useless and vulnerable.
 1.78.10.1 25-Mar-2017  snj Pull up following revision(s) (requested by maxv in ticket #1391):
sys/arch/amd64/amd64/trap.c: revision 1.94
sys/arch/i386/i386/trap.c: revision 1.287
Mmh, allow iret to be handled when an #SS fault (T_STKFLT) happens. Even
if the sdm is far from being clear, it appears that iret can trigger an #SS
fault if %ss points to a writable but non-present segment; in which case
the kernel would panic, thinking the fault was internal to it.
In particular, userland can create a broken segment in the ldt with
USER_LDT, update its %ss with setcontext and trigger the panic. I don't
think amd64 is affected since USER_LDT does not exist there, and the
changes on tf_ss seem correct - but I'm still adding T_STKFLT for safety.
 1.78.6.3 26-Apr-2017  martin Pull up following revision(s) (requested by chs in ticket #1410):
sys/arch/amd64/amd64/trap.c: revision 1.96
restore the ability to run netbsd 1.0 32-bit executables
by checking for the relevant lcall instruction in the trap handler
and treating it as a syscall.
 1.78.6.2 26-Apr-2017  martin Pull up following revision(s) (requested by bsiegert in ticket #1397):

sys/arch/amd64/amd64/locore.S 1.122 (via patch)
sys/arch/amd64/amd64/machdep.c 1.254 (via patch)
sys/arch/amd64/amd64/trap.c 1.95 (via patch)

Remove the call gate on amd64, it is useless and vulnerable.
 1.78.6.1 25-Mar-2017  snj Pull up following revision(s) (requested by maxv in ticket #1391):
sys/arch/amd64/amd64/trap.c: revision 1.94
sys/arch/i386/i386/trap.c: revision 1.287
Mmh, allow iret to be handled when an #SS fault (T_STKFLT) happens. Even
if the sdm is far from being clear, it appears that iret can trigger an #SS
fault if %ss points to a writable but non-present segment; in which case
the kernel would panic, thinking the fault was internal to it.
In particular, userland can create a broken segment in the ldt with
USER_LDT, update its %ss with setcontext and trigger the panic. I don't
think amd64 is affected since USER_LDT does not exist there, and the
changes on tf_ss seem correct - but I'm still adding T_STKFLT for safety.
 1.78.4.3 26-Apr-2017  martin Pull up following revision(s) (requested by chs in ticket #1410):
sys/arch/amd64/amd64/trap.c: revision 1.96
restore the ability to run netbsd 1.0 32-bit executables
by checking for the relevant lcall instruction in the trap handler
and treating it as a syscall.
 1.78.4.2 26-Apr-2017  martin Pull up following revision(s) (requested by bsiegert in ticket #1397):

sys/arch/amd64/amd64/locore.S 1.122 (via patch)
sys/arch/amd64/amd64/machdep.c 1.254 (via patch)
sys/arch/amd64/amd64/trap.c 1.95 (via patch)

Remove the call gate on amd64, it is useless and vulnerable.
 1.78.4.1 25-Mar-2017  snj Pull up following revision(s) (requested by maxv in ticket #1391):
sys/arch/amd64/amd64/trap.c: revision 1.94
sys/arch/i386/i386/trap.c: revision 1.287
Mmh, allow iret to be handled when an #SS fault (T_STKFLT) happens. Even
if the sdm is far from being clear, it appears that iret can trigger an #SS
fault if %ss points to a writable but non-present segment; in which case
the kernel would panic, thinking the fault was internal to it.
In particular, userland can create a broken segment in the ldt with
USER_LDT, update its %ss with setcontext and trigger the panic. I don't
think amd64 is affected since USER_LDT does not exist there, and the
changes on tf_ss seem correct - but I'm still adding T_STKFLT for safety.
 1.79.2.6 28-Aug-2017  skrll Sync with HEAD
 1.79.2.5 05-Feb-2017  skrll Sync with HEAD
 1.79.2.4 05-Dec-2016  skrll Sync with HEAD
 1.79.2.3 05-Oct-2016  skrll Sync with HEAD
 1.79.2.2 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.79.2.1 06-Apr-2015  skrll Sync with HEAD
 1.83.2.4 26-Apr-2017  pgoyette Sync with HEAD
 1.83.2.3 20-Mar-2017  pgoyette Sync with HEAD
 1.83.2.2 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.83.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.88.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.96.4.4 14-Apr-2018  martin Pullup the following revisions via patch, requested by maxv in ticket #748:

sys/arch/amd64/amd64/copy.S 1.29 (adapted, via patch)
sys/arch/amd64/amd64/amd64_trap.S 1.16,1.19 (partial) (via patch)
sys/arch/amd64/amd64/trap.c 1.102,1.106 (partial),1.110 (via patch)
sys/arch/amd64/include/frameasm.h 1.22,1.24 (via patch)
sys/arch/x86/x86/cpu.c 1.137 (via patch)
sys/arch/x86/x86/patch.c 1.23,1.26 (partial) (via patch)

Backport of SMAP support.
 1.96.4.3 08-Apr-2018  snj Pull up following revision(s) (requested by maxv in ticket #705):
sys/arch/amd64/amd64/trap.c: 1.113
Mmh. We shouldn't read %cr2 here. %cr2 is initialized by the CPU only
during page faults (T_PAGEFLT), so here we're reading a value that comes
from a previous page fault.
That's a real problem; if you launch an unprivileged process, set up a
signal handler, make it sleep 10 seconds, and trigger a T_ALIGNFLT fault,
you get in si_addr the address of another LWP's page - and perhaps this
can be used to defeat userland ASLR.
This bug has been there since 2003.
 1.96.4.2 22-Mar-2018  martin Pull up the following revisions, requested by maxv in ticket #652:

sys/arch/amd64/amd64/amd64_trap.S upto 1.39 (partial, patch)
sys/arch/amd64/amd64/db_machdep.c 1.6 (patch)
sys/arch/amd64/amd64/genassym.cf 1.65,1.66,1.67 (patch)
sys/arch/amd64/amd64/locore.S upto 1.159 (partial, patch)
sys/arch/amd64/amd64/machdep.c 1.299-1.302 (patch)
sys/arch/amd64/amd64/trap.c upto 1.113 (partial, patch)
sys/arch/amd64/amd64/amd64/vector.S upto 1.61 (partial, patch)
sys/arch/amd64/conf/GENERIC 1.477,1.478 (patch)
sys/arch/amd64/conf/kern.ldscript 1.26 (patch)
sys/arch/amd64/include/frameasm.h upto 1.37 (partial, patch)
sys/arch/amd64/include/param.h 1.25 (patch)
sys/arch/amd64/include/pmap.h 1.41,1.43,1.44 (patch)
sys/arch/x86/conf/files.x86 1.91,1.93 (patch)
sys/arch/x86/include/cpu.h 1.88,1.89 (patch)
sys/arch/x86/include/pmap.h 1.75 (patch)
sys/arch/x86/x86/cpu.c 1.144,1.146,1.148,1.149 (patch)
sys/arch/x86/x86/pmap.c upto 1.289 (partial, patch)
sys/arch/x86/x86/vm_machdep.c 1.31,1.32 (patch)
sys/arch/x86/x86/x86_machdep.c 1.104,1.106,1.108 (patch)
sys/arch/x86/x86/svs.c 1.1-1.14
sys/arch/xen/conf/files.compat 1.30 (patch)

Backport SVS. Not enabled yet.
 1.96.4.1 07-Mar-2018  martin Pull up the following revisions (via patch), requested by maxv in ticket #610:

sys/arch/amd64/amd64/amd64_trap.S 1.8,1.10,1.12 (partial),1.13-1.15,
1.19 (partial),1.20,1.21,1.22,1.24
(via patch)
sys/arch/amd64/amd64/locore.S 1.129 (partial),1.132 (via patch)
sys/arch/amd64/amd64/trap.c 1.97 (partial),1.111 (via patch)
sys/arch/amd64/amd64/vector.S 1.54,1.55 (via patch)
sys/arch/amd64/include/frameasm.h 1.21,1.23 (via patch)
sys/arch/x86/x86/cpu.c 1.138 (via patch)
sys/arch/xen/conf/Makefile.xen 1.45 (via patch)

Rename and reorder several things in amd64_trap.S.
Compile amd64_trap.S as a file.
Introduce nmitrap and doubletrap.
Have the CPU clear PSL_D automatically in the syscall entry point.
 1.113.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.113.4.1 10-Jun-2019  christos Sync with HEAD
 1.113.2.2 21-Sep-2018  pgoyette Make a note that the code does not exist in loadable modules, only in
built-in compat modules.
 1.113.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.121.2.3 10-Mar-2020  martin Pull up following revision(s) (requested by pgoyette in ticket #778):

sys/compat/netbsd32/netbsd32_mod.c: revision 1.20
sys/arch/amd64/amd64/trap.c: revision 1.127

Rework previous, so that the real syscall code is not invoked from within
the module_hook code. Otherwise, if the syscall just happens to be exit()
we will exit while still holding a reference to the hook's localcount, and
nothing will ever release that reference. Attempts to manually unload the
module will hang indefinitely, as will modstat(8).

XXX pullup-9
 1.121.2.2 09-Mar-2020  martin Fix merge botch in previous.
 1.121.2.1 08-Mar-2020  martin Pull up following revision(s) (requested by pgoyette in ticket #762):

sys/arch/amd64/amd64/trap.c: revision 1.126
sys/compat/netbsd32/netbsd32_mod.c: revision 1.17
sys/compat/netbsd32/netbsd32_mod.c: revision 1.18
sys/sys/compat_stub.h: revision 1.23

Fix another left-over from last year's [pgoyette-compat] work. This
allows recognition of the oosyscall sequence for amd64.

Fixes PR kern/55038
XXX pullup-9

-

fix indentation. NFCI
 1.129.6.1 02-Aug-2025  perseant Sync with HEAD
 1.80 12-Sep-2022  knakahara Update register name at fault. Pointed out by hgutch@n.o, thanks.

In vetor.S:r1.78
 1.79 07-Sep-2022  knakahara NetBSD/x86: Raise the number of interrupt sources per CPU from 32 to 56.

There has been no objection for three years.
https://mail-index.netbsd.org/port-amd64/2019/09/22/msg003012.html
Implemented by nonaka@n.o, updated by me.
 1.78 24-May-2022  bouyer Some devices (e.g. ixg in MSI-X mode) don't to have their handlers called
when no interrupt are pending. So add an extra ih_pending field
to struct intrhand, which is incremeted when the handler is not called because
of IPL level and reset to 0 when called. Check this in Xen's resume
assembly to call only handlers that are really pending.
 1.77 17-May-2020  ad Flag EOI on TLB shootdown IPIs after the shootdown has been processed.
 1.76 01-May-2020  maxv Explicitly align to 8 bytes, found by kUBSan.

Reported-by: syzbot+f1e1561ed739db869d44@syzkaller.appspotmail.com
 1.75 27-Apr-2020  bouyer Limit the amount of code in TEXT_USER_BEGIN/TEXT_USER_END for
hypervisor_pvhvm_callback, for the benefit of SVS. Suggested by maxv@
 1.74 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.73 30-Dec-2019  thorpej branches: 1.73.6;
Fix a problem with intr_unmask() that can cause a forever-loop:
- When handling the source-is-masked case in the interrupt vector, set the
interrupt bit in a new ci_imasked field and ensure the bit is cleared
from ci_ipending.
- In intr_unmask(), transfer the bit from ci_imasked to ci_ipending for
non-level-sensitive interrupts (the PIC does the work for us in the
level-sensitive case), and only force pending interrupts to be processed
in this case. (In all cases, make sure the now-unmasked bit is cleared
from ci_imasked.)

Before, the bit was left in ci_ipending so as not to use edge-triggered
interrupts while the source is masked, but Xspllower() relies on the
pending bits getting cleared.

Tested by forcing all wm(4) interrupts on my test system though an
intr_mask() / softint / intr_unmask() cycle and exercising the network
heavily.
 1.72 22-Dec-2019  thorpej Add intr_mask() and corresponding intr_unmask() calls that allow specific
interrupt lines / sources to be masked as needed (rather than making a
set of sources by IPL as with spl*()).
 1.71 17-Nov-2019  maxv Disable KCOV - by raising the interrupt level - in the TLB IPI handler,
because this is only noise.
 1.70 07-Mar-2019  nonaka Use IDTVEC instead of NENTRY for handle_hyperv_hypercall.
 1.69 15-Feb-2019  nonaka Added Microsoft Hyper-V support. It ported from OpenBSD and FreeBSD.

graphical console is not work on Gen.2 VM yet. To use the serial console,
enter "consdev com,0x3f8,115200" on efiboot.
 1.68 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.67 13-Feb-2019  cherry In preparation for debut-ing PVHVM mode:

- Make the struct intrstub uniform across native and XEN.
- Introduce vector callback entrypoints for PVHVM mode.
 1.66 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.65 25-Dec-2018  cherry Excise XEN specific code out of x86/x86/intr.c into xen/x86/xen_intr.c

While at it, separate the source function tracking so that the interrupt
paths are truly independant.

Use weak symbol exporting to provision for future PVHVM co-existence
of both files, but with independant paths. Introduce assembler code
such that in a unified scenario, native interrupts get first priority
in spllower(), followed by XEN event callbacks. IPL management and
semantics are unchanged - native handlers and xen callbacks are
expected to maintain their ipl related semantics.

In summary, after this commit, native and XEN now have completely
unrelated interrupt handling mechanisms, including
intr_establish_xname() and assembler stubs and intr handler
management.

Happy Christmas!
 1.64 14-Jul-2018  maxv Drop NENTRY() from the x86 kernels, use ENTRY(). With PMCs (and other hardware
tracing facilities) we have a much better ways of monitoring the CPU activity
than GPROF, without software modification.

Also I think GPROF has never worked, because the 'start' functions of both
i386 and amd64 use ENTRY(), and it would have caused a function call while the
kernel was not yet relocated.
 1.63 20-Jun-2018  maxv branches: 1.63.2;
Put these arrays in .rodata, they aren't supposed to be executable.
 1.62 03-Apr-2018  christos Rename the DDB IPI IDT vectors for consistency. ok maxv@
 1.61 16-Mar-2018  maxv Rename "handle_" -> "Xhandle_", and add the function names (introduced by
SVS) in db_machdep.c.

Should fix the DDB part of PR/53060.
 1.60 17-Feb-2018  maxv branches: 1.60.2;
Define legacy_stubs in a macro.
 1.59 17-Feb-2018  maxv Rename i8259_stubs -> legacy_stubs. We will want the entries to have the
same name, eg:

legacy_stubs
-> Xintr_legacy0, Xrecurse_legacy0, Xresume_legacy0
-> Xintr_legacy1, Xrecurse_legacy1, Xresume_legacy1
...
 1.58 09-Feb-2018  maxv Define INTRSTUB_ARRAY, simplifies a lot.
 1.57 27-Jan-2018  maxv Declare and use INTR_RECURSE_ENTRY, an optimized version of INTRENTRY.
When processing deferred interrupts, we are always entering the new
handler in kernel mode, so there is no point performing the userland
checks.

Saves several instructions.
 1.56 21-Jan-2018  maxv Unmap the kernel from userland in SVS, and leave only the needed
trampolines. As explained below, SVS should now completely mitigate
Meltdown on GENERIC kernels, even though it needs some more tweaking
for GENERIC_KASLR.

Until now the kernel entry points looked like:

FUNC(intr)
pushq $ERR
pushq $TRAPNO
INTRENTRY
... handle interrupt ...
INTRFASTEXIT
END(intr)

With this change they are split and become:

FUNC(handle)
... handle interrupt ...
INTRFASTEXIT
END(handle)

TEXT_USER_BEGIN
FUNC(intr)
pushq $ERR
pushq $TRAPNO
INTRENTRY
jmp handle
END(intr)
TEXT_USER_END

A new section is introduced, .text.user, that contains minimal kernel
entry/exit points. In order to choose what to put in this section, two
macros are introduced, TEXT_USER_BEGIN and TEXT_USER_END.

The section is mapped in userland with normal 4K pages.

In GENERIC, the section is 4K-page-aligned and embedded in .text, which
is mapped with large pages. That is to say, when an interrupt comes in,
the CPU has the user page tables loaded and executes the 'intr' functions
on 4K pages; after calling SVS_ENTER (in INTRENTRY) these 4K pages become
2MB large pages, and remain so when executing in kernel mode.

In GENERIC_KASLR, the section is 4K-page-aligned and independent from the
other kernel texts. The prekern just picks it up and maps it at a random
address.

In GENERIC, SVS should now completely mitigate Meltdown: what we put in
.text.user is not secret.

In GENERIC_KASLR, SVS would have to be improved a bit more: the
'jmp handle' instruction is actually secret, since it leaks the address
of the section we are jumping into. By exploiting Meltdown on Intel, this
theoretically allows a local user to reconstruct the address of the first
text section. But given that our KASLR produces several texts, and that
each section is not correlated with the others, the level of protection
KASLR provides is still good.
 1.55 20-Jan-2018  maxv Compile amd64_trap.S as a file instead of including it.
 1.54 20-Jan-2018  maxv Start with .text not to inherit the last section of amd64_trap.S, and
remove outdated #define.
 1.53 08-Nov-2017  maxv Don't fall through.
 1.52 30-Oct-2017  maxv Always use END() markers when declaring functions in assembly, so that ld
can compute the size of the functions. A few remain.

While here, fix a bug in the INTRSTUB macro: we are falling through
resume_, but it is aligned, so it looks like we're executing the inter-
function padding - which probably happens to contain NOPs, but that's
still bad.
 1.51 15-Aug-2017  maxv Rename intrddb -> intrddbipi, like i386.
 1.50 16-Jul-2017  cherry branches: 1.50.2;
Unify the xen and native x86/ interrupt setup functions and
spl traversal data structures.

This is towards PVHVM.
 1.49 23-May-2017  nonaka branches: 1.49.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.48 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.47 19-Aug-2016  maxv Unused.
 1.46 07-Aug-2016  maxv KNF a little.
 1.45 22-Nov-2015  maxv branches: 1.45.2;
KNF a bit, so I don't get scared each time I open a file
 1.44 25-Jun-2013  uebayasi branches: 1.44.10;
Split these to improve diffability.
 1.43 22-Jun-2013  uebayasi Use END()/IDTVEC_END() to set ELF symbol size. Set some type info too.
 1.42 02-Nov-2012  yamt comment
 1.41 22-May-2012  dsl branches: 1.41.2;
If we get a fault setting the user %gs, or on a iret that is returning
to userspace, we must do a 'swapgs' to reload the kernel %gs_base.
Also save the %ds, %es, %fs, %gs selector values in the frame so
they can be restored if we finally return to user (probably after
an application SIGSEGV handler has fixed the error).
Without this any such fault leaves the kernel running with the wrong
%gs offset and it will most likely fault again early in trap().
Repeats until the stack tramples on something important.
iret change works, invalid %gs is a little harder to arrange.
 1.40 07-May-2012  dsl Rejig the way TRAP() and ZTRAP() are defined and add Z/TRAP_NJ() that
excludes the 'jmp alltraps'.
Use the _NJ versions for trap entries with non-standard code.
Move all the KDTRACE_HOOKS code into a single block inside the
IDTVEC(trap03) code. This removes a mis-predicted from every
trap when KDTRACE_HOOKS are enabled.
Add a few blank lines, need some comments as well :-)
No functional changes intended.
 1.39 21-Apr-2012  christos Alignment fault traps push the error code automatically, so don't use ZTRAP!
 1.38 12-Jun-2011  rmind branches: 1.38.2; 1.38.6; 1.38.8;
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.37 18-Mar-2011  joerg branches: 1.37.2;
Remove static branch prediction hints. They pessimize code for all CPUs
but Pentium IV. Discussed with ad@ and dsl@
 1.36 12-Jan-2011  joerg branches: 1.36.2;
Allow use of traditional CPP to be set on a per platform base in sys.mk.
Honour this for dependency processing in bsd.dep.mk. Switch i386 and
amd64 assembly to use ISO C90 preprocessor concat and drop the
-traditional-cpp on this platform.
 1.35 20-Dec-2010  matt Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.
 1.34 07-Jul-2010  chs add the guts of TLS support on amd64. based on joerg's patch,
reworked by me to support 32-bit processes as well.
we now keep %fs and %gs loaded with the user values
while in the kernel, which means we don't need to
reload them when returning to user mode.
 1.33 23-Feb-2010  cegger branches: 1.33.2;
dtrace kernel hooks

ok darran@
 1.32 23-Feb-2010  cegger include opt_xen.h
 1.31 09-Jul-2009  rmind branches: 1.31.2;
- Fix rare crashe in the intr_lapic_tlb_bcast() handler: save and setup
%fs on i386, %gs on amd64 registers, before using them. Otherwise, it
might be invalid/garbage, eg. IPI can interrupt userspace.

- Explicitly initialize per-CPU emap generation number.

Thanks <drochner> for reporting and testing of patch.
 1.30 28-Jun-2009  rmind Ephemeral mapping (emap) implementation. Concept is based on the idea that
activity of other threads will perform the TLB flush for the processes using
emap as a side effect. To track that, global and per-CPU generation numbers
are used. This idea was suggested by Andrew Doran; various improvements to
it by me. Notes:

- For now, zero-copy on pipe is not yet enabled.
- TCP socket code would likely need more work.
- Additional UVM loaning improvements are needed.

Proposed on <tech-kern>, silence there.
Quickly reviewed by <ad>.
 1.29 25-Nov-2008  ad branches: 1.29.4;
trap07: do NOT enable interrupts before calling fpudna or we could be
preempted.
 1.28 29-Jun-2008  bouyer branches: 1.28.2; 1.28.4; 1.28.6;
Proper FPU exeptions support for Xen. Should fix FPU issues reported by
various users.
 1.27 01-Jun-2008  ad branches: 1.27.2;
Make trap counters per-cpu, like syscalls.
 1.26 30-May-2008  ad PR kern/38663 Kernel preemption can't be enabled on x86 because of amd64
FPU handling

Adjust FPU trap handling to be preemption safe.
 1.25 30-May-2008  ad Shuffle copyright.
 1.24 30-May-2008  ad Avoid mispredicted branches.
 1.23 25-May-2008  bouyer Fix pasto: CLI -> STI
 1.22 13-May-2008  ad PR port-amd64/38478 (panic on boot when attaching cpu17)

Don't 'sti' before returning from an interrupt that is masked in software.
We could recurse and burn stack.
 1.21 28-Apr-2008  martin branches: 1.21.2;
Remove clause 3 and 4 from TNF licenses
 1.20 28-Apr-2008  ad Make the trap stubs preemption safe.
 1.19 01-Jan-2008  yamt branches: 1.19.6; 1.19.8; 1.19.10;
make the nmi handler safer.

XXX should use IST.
 1.18 21-Dec-2007  dsl Change the xen CLI() and STI() defines to only use one scratch register.
As well as saving an instruction, in one place it saves a push/pop pair.
 1.17 03-Dec-2007  ad branches: 1.17.4;
Merge from vmlocking.
 1.16 03-Dec-2007  ad branches: 1.16.2;
Interrupt handling changes, in discussion since February:

- Reduce available SPL levels for hardware devices to none, vm, sched, high.
- Acquire kernel_lock only for interrupts at IPL_VM.
- Implement threaded soft interrupts.
 1.15 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.14 18-Oct-2007  yamt branches: 1.14.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.13 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.12 17-Sep-2007  ad branches: 1.12.2; 1.12.4;
Don't subtract CR4_PGE from %cr4, just clear it. Otherwise bad things could
happen if we are unlucky and interrupt tlbflushg().
 1.11 29-Aug-2007  ad 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.10 09-Feb-2007  ad branches: 1.10.6; 1.10.14; 1.10.18; 1.10.22; 1.10.24;
Merge newlock2 to head.
 1.9 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.8 11-Dec-2005  christos branches: 1.8.20; 1.8.22;
merge ktrace-lwp.
 1.7 31-May-2005  chs branches: 1.7.2;
remove vestigal {,e}intr{names,cnt} symbols now that vmstat doesn't need them.
 1.6 23-Oct-2004  yamt to determine if an interrupt needs to grab the kernel lock or not,
check interrupt's own ipl rather than cpu's current ipl.
 1.5 28-Jun-2004  fvdl Updaing ci_ilevel and testing ci_ipending must be done with all interrupts
off, or priority inversion can occur, which can lead to IPI deadlocks.
Leaves interrupts off for a bit longer, sadly, but with no noticeable
effects on the systems I tested on.

From YAMAMOTO Takashi.
 1.4 15-Jun-2004  fvdl A double fault always pushes a 0.
 1.3 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.2 04-May-2003  fvdl branches: 1.2.2;
Follow i386, and mask deferred level-triggered interrupts at the ioapic.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.2.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.2.2.4 02-Nov-2004  skrll Sync with HEAD.
 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.7.2.6 21-Jan-2008  yamt sync with head
 1.7.2.5 07-Dec-2007  yamt sync with head
 1.7.2.4 27-Oct-2007  yamt sync with head.
 1.7.2.3 03-Sep-2007  yamt sync with head.
 1.7.2.2 26-Feb-2007  yamt sync with head.
 1.7.2.1 30-Dec-2006  yamt sync with head.
 1.8.22.1 10-Dec-2006  yamt sync with head.
 1.8.20.3 14-Jan-2007  ad - Restore previous locking behaviour in cpu_switch(). Seems to fix what
look like corrupted trap frames.
- Micro-optimisation for AST check/clear.
 1.8.20.2 12-Jan-2007  ad Sync with head.
 1.8.20.1 20-Oct-2006  ad Make ASTs per-LWP.
 1.10.24.2 09-Jan-2008  matt sync with HEAD
 1.10.24.1 06-Nov-2007  matt sync with HEAD
 1.10.22.5 09-Dec-2007  jmcneill Sync with HEAD.
 1.10.22.4 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.10.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.10.22.2 02-Oct-2007  joerg Sync with HEAD.
 1.10.22.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.10.18.1 03-Sep-2007  skrll Sync with HEAD.
 1.10.14.1 03-Oct-2007  garbled Sync with HEAD
 1.10.6.10 03-Dec-2007  ad Sync with HEAD.
 1.10.6.9 03-Dec-2007  ad Sync with HEAD.
 1.10.6.8 16-Nov-2007  ad - Don't bother entering the debugger for WARNING: SPL NOT LOWERED ...
It's nearly impossible to debug at that point. Just patch things
up and continue.
- Don't assign to ci_ilevel to drop the IPL, it can cause deadlock.
Use spllower() instead.
 1.10.6.7 23-Oct-2007  ad Sync with head.
 1.10.6.6 09-Oct-2007  ad Sync with head.
 1.10.6.5 29-Aug-2007  ad Fix error in previous.
 1.10.6.4 29-Aug-2007  ad In the TLB shootdown handlers, don't ack the request until the invalidation
is complete. We could end up loading bogus translations due to a speculative
load if the calling CPU recycles a PDE/PTE, and these may not be shot down
before the handler returns. Pointed out by yamt. I think this is very
unlikely to happen but it's better to be on the safe side. To be revisted
later, as the invalidations are time consuming and it would be nice to
release the caller sooner rather than later.
 1.10.6.3 26-Aug-2007  yamt netisr.h is no longer necessary.
 1.10.6.2 23-Aug-2007  ad Misc. fixes to previous.
 1.10.6.1 21-Aug-2007  ad amd64 changes, as yet untested:

- Adapt to vmlocking branch.
- Apply TLB shootdown and pv allocation changes to the pmap.
- Make it build.
 1.12.4.6 16-Nov-2007  bouyer Initial domain0 support for xenamd64. The kernel boots multiuser, but
xen tools have not been tried yet.
In this process, cleanup some more the page table bootstrap, and properly
handle event counters for soft interrupts.
 1.12.4.5 15-Nov-2007  bouyer Pass the correct pointer to do_hypervisor_callback(), fixes the system
vs user time reports.
 1.12.4.4 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.12.4.3 21-Oct-2007  bouyer Check for ASTs on exit from interrupt.
 1.12.4.2 18-Oct-2007  bouyer Pass the right address to do_hypervisor_callback()/xen_failsafe_handler()
for struct intrframe*.
 1.12.4.1 17-Oct-2007  bouyer amd64 (aka x86-64) support for Xen. Based on the OpenBSD port done by
Mathieu Ropert in 2006.
DomU-only for now. An INSTALL_XEN3_DOMU kernel with a ramdisk will boot to
sysinst if you're lucky. Often it panics because a runable LWP has
a NULL stack (really, it's all of l->l_addr which is has been zeroed out
while the process was on the queue !)
TODO:
- bug fixes :)
- Most of the xpq_* functions should be shared with xen/i386
- The xen/i386 assembly bootstrap code should be remplaced with the C
version in xenamd64/amd64/xpmap.c
- see if a config(5) trick could allow to merge xenamd64 back to xen or amd64.
 1.12.2.4 08-Oct-2007  ad intr_lapic_tlb_mcast: ci_tlbstate is a 32-bit int.
 1.12.2.3 07-Oct-2007  yamt remove some #ifdef _LOCORE and use genassym instead.
 1.12.2.2 30-Sep-2007  yamt Xintr_lapic_tlb_mcast: fix size of cpumasks.
 1.12.2.1 30-Sep-2007  yamt implement deferred pmap switching for amd64, and make amd64 use
x86 shared pmap code. it makes several i386 pmap improvements available
to amd64, including tlb shootdown reduction and bug fixes from Stephan Uphoff.
 1.14.2.3 18-Feb-2008  mjf Sync with HEAD.
 1.14.2.2 27-Dec-2007  mjf Sync with HEAD.
 1.14.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.16.2.2 26-Dec-2007  ad Sync with head.
 1.16.2.1 08-Dec-2007  ad Sync with head.
 1.17.4.1 02-Jan-2008  bouyer Sync with HEAD
 1.19.10.5 11-Aug-2010  yamt sync with head.
 1.19.10.4 11-Mar-2010  yamt sync with head
 1.19.10.3 18-Jul-2009  yamt sync with head.
 1.19.10.2 04-May-2009  yamt sync with head.
 1.19.10.1 16-May-2008  yamt sync with head.
 1.19.8.2 04-Jun-2008  yamt sync with head
 1.19.8.1 18-May-2008  yamt sync with head.
 1.19.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.19.6.2 02-Jul-2008  mjf Sync with HEAD.
 1.19.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.21.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.21.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.27.2.1 03-Jul-2008  simonb Sync with head.
 1.28.6.2 12-Jun-2012  riz Pull up following revision(s) (requested by spz in ticket #1772):
sys/arch/amd64/amd64/trap.c: revision 1.71 via patch
sys/arch/amd64/amd64/vector.S: revision 1.41 via patch
sys/arch/amd64/include/frameasm.h: patch

Treat traps in kernel mode during the 'return to user' iret sequence
as user faults.
Based heavily in the i386 code with the correct opcode bytes inserted.
iret path tested, arranging for segment register errors is harder.
User %fs and %gs (32bit apps) are loaded much earlier and any errors
will generate kernel panics - there is probably code to try to stop
the invalid values being set.
If we get a fault setting the user %gs, or on a iret that is returning
to userspace, we must do a 'swapgs' to reload the kernel %gs_base.
Also save the %ds, %es, %fs, %gs selector values in the frame so
they can be restored if we finally return to user (probably after
an application SIGSEGV handler has fixed the error).
Without this any such fault leaves the kernel running with the wrong
%gs offset and it will most likely fault again early in trap().
Repeats until the stack tramples on something important.
iret change works, invalid %gs is a little harder to arrange.
 1.28.6.1 25-Nov-2008  snj branches: 1.28.6.1.2; 1.28.6.1.6;
Pull up following revision(s) (requested by ad in ticket #126):
sys/arch/amd64/amd64/vector.S: revision 1.29
trap07: do NOT enable interrupts before calling fpudna or we could be
preempted.
 1.28.6.1.6.1 12-Jun-2012  riz Pull up following revision(s) (requested by spz in ticket #1772):
sys/arch/amd64/amd64/trap.c: revision 1.71 via patch
sys/arch/amd64/amd64/vector.S: revision 1.41 via patch
sys/arch/amd64/include/frameasm.h: patch

Treat traps in kernel mode during the 'return to user' iret sequence
as user faults.
Based heavily in the i386 code with the correct opcode bytes inserted.
iret path tested, arranging for segment register errors is harder.
User %fs and %gs (32bit apps) are loaded much earlier and any errors
will generate kernel panics - there is probably code to try to stop
the invalid values being set.
If we get a fault setting the user %gs, or on a iret that is returning
to userspace, we must do a 'swapgs' to reload the kernel %gs_base.
Also save the %ds, %es, %fs, %gs selector values in the frame so
they can be restored if we finally return to user (probably after
an application SIGSEGV handler has fixed the error).
Without this any such fault leaves the kernel running with the wrong
%gs offset and it will most likely fault again early in trap().
Repeats until the stack tramples on something important.
iret change works, invalid %gs is a little harder to arrange.
 1.28.6.1.2.1 12-Jun-2012  riz Pull up following revision(s) (requested by spz in ticket #1772):
sys/arch/amd64/amd64/trap.c: revision 1.71 via patch
sys/arch/amd64/amd64/vector.S: revision 1.41 via patch
sys/arch/amd64/include/frameasm.h: patch

Treat traps in kernel mode during the 'return to user' iret sequence
as user faults.
Based heavily in the i386 code with the correct opcode bytes inserted.
iret path tested, arranging for segment register errors is harder.
User %fs and %gs (32bit apps) are loaded much earlier and any errors
will generate kernel panics - there is probably code to try to stop
the invalid values being set.
If we get a fault setting the user %gs, or on a iret that is returning
to userspace, we must do a 'swapgs' to reload the kernel %gs_base.
Also save the %ds, %es, %fs, %gs selector values in the frame so
they can be restored if we finally return to user (probably after
an application SIGSEGV handler has fixed the error).
Without this any such fault leaves the kernel running with the wrong
%gs offset and it will most likely fault again early in trap().
Repeats until the stack tramples on something important.
iret change works, invalid %gs is a little harder to arrange.
 1.28.4.1 19-Jan-2009  skrll Sync with HEAD.
 1.28.2.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.29.4.5 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.29.4.4 28-Mar-2011  jym Cure sync hiccups. Code with compile errors is not really useful, heh.
 1.29.4.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.29.4.2 01-Nov-2009  jym Sync with HEAD.
 1.29.4.1 23-Jul-2009  jym Sync with HEAD.
 1.31.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.31.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.33.2.4 17-Mar-2011  rmind - Fix tlbflushg() to behave like tlbflush(), if page global extension (PGE)
is not (yet) enabled. This fixes the issue of stale TLB entry, experienced
early on boot, when PGE is not yet set on primary CPU.
- Rewrite i386/amd64 TLB interrupt handlers in C (only stubs are in assembly),
which simplifies and unifies (under x86) code, plus fixes few bugs.
- cpu_attach: remove assignment to cpus_running, as primary CPU might not be
attached first, which causes reset (and thus missed secondary CPUs).
 1.33.2.3 05-Mar-2011  rmind sync with head
 1.33.2.2 26-Apr-2010  rmind Slight simplification to TLB shootdown handler on i386 and amd64.
 1.33.2.1 26-Apr-2010  rmind Partly rewrite amd64 TLB shutdown handler for the changes in x86 pmap.
At this point, branch seems to pass preliminar stress tests on amd64.
 1.36.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.37.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.38.8.2 03-Jun-2012  jdc Pull up revisions:
src/sys/arch/amd64/include/frameasm.h revision 1.17-1.19
src/sys/arch/amd64/amd64/vector.S revision 1.40-1.41
src/sys/arch/amd64/amd64/trap.c revision 1.71
(requested by dsl in ticket #280).

Move all the XEN differences to a single conditional.
Merge the XEN/non-XEN versions of INTRFASTEXIT and
INTR_RECURSE_HWFRAME by using extra defines.
Split INTRENTRY so that code can insert extra instructions
inside user/kernel conditional.

Add a ';' that got deleted in a slight tidyup.

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

Let the user of INTRENTRY_L() place a label on the 'swapgs' used
when faulting from user space.

If we get a fault setting the user %gs, or on a iret that is returning
to userspace, we must do a 'swapgs' to reload the kernel %gs_base.
Also save the %ds, %es, %fs, %gs selector values in the frame so
they can be restored if we finally return to user (probably after
an application SIGSEGV handler has fixed the error).
Without this any such fault leaves the kernel running with the wrong
%gs offset and it will most likely fault again early in trap().
Repeats until the stack tramples on something important.
iret change works, invalid %gs is a little harder to arrange.

Treat traps in kernel mode during the 'return to user' iret sequence
as user faults.
Based heavily in the i386 code with the correct opcode bytes inserted.
iret path tested, arranging for segment register errors is harder.
User %fs and %gs (32bit apps) are loaded much earlier and any errors
will generate kernel panics - there is probably code to try to stop
the invalid values being set.
 1.38.8.1 23-Apr-2012  riz Pull up following revision(s) (requested by jym in ticket #194):
sys/arch/amd64/amd64/vector.S: revision 1.39
Alignment fault traps push the error code automatically, so don't use ZTRAP!
 1.38.6.2 02-Jun-2012  mrg sync to latest -current.
 1.38.6.1 29-Apr-2012  mrg sync to latest -current.
 1.38.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.38.2.3 16-Jan-2013  yamt sync with (a bit old) head
 1.38.2.2 30-Oct-2012  yamt sync with head
 1.38.2.1 23-May-2012  yamt sync with head.
 1.41.2.3 03-Dec-2017  jdolecek update from HEAD
 1.41.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.41.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.44.10.4 28-Aug-2017  skrll Sync with HEAD
 1.44.10.3 05-Dec-2016  skrll Sync with HEAD
 1.44.10.2 05-Oct-2016  skrll Sync with HEAD
 1.44.10.1 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.45.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.49.2.4 09-Mar-2019  martin Pull up following revision(s) via patch (requested by nonaka in ticket #1210):

sys/dev/hyperv/vmbusvar.h: revision 1.1
sys/dev/hyperv/hvs.c: revision 1.1
sys/dev/hyperv/if_hvn.c: revision 1.1
sys/dev/hyperv/vmbusic.c: revision 1.1
sys/arch/x86/x86/lapic.c: revision 1.69
sys/arch/x86/isa/clock.c: revision 1.34
sys/arch/x86/include/intrdefs.h: revision 1.22
sys/arch/i386/conf/GENERIC: revision 1.1201
sys/arch/x86/x86/hyperv.c: revision 1.1
sys/arch/x86/include/cpu.h: revision 1.105
sys/arch/x86/x86/x86_machdep.c: revision 1.124
sys/arch/i386/conf/GENERIC: revision 1.1203
sys/arch/amd64/amd64/genassym.cf: revision 1.74
sys/arch/i386/conf/GENERIC: revision 1.1204
sys/arch/amd64/conf/GENERIC: revision 1.520
sys/arch/x86/x86/hypervreg.h: revision 1.1
sys/arch/amd64/amd64/vector.S: revision 1.69
sys/dev/hyperv/hvshutdown.c: revision 1.1
sys/dev/hyperv/hvshutdown.c: revision 1.2
sys/dev/usb/if_urndisreg.h: file removal
sys/arch/x86/x86/cpu.c: revision 1.167
sys/arch/x86/conf/files.x86: revision 1.107
sys/dev/usb/if_urndis.c: revision 1.20
sys/dev/hyperv/vmbusicreg.h: revision 1.1
sys/dev/hyperv/hvheartbeat.c: revision 1.1
sys/dev/hyperv/vmbusicreg.h: revision 1.2
sys/dev/hyperv/hvheartbeat.c: revision 1.2
sys/dev/hyperv/files.hyperv: revision 1.1
sys/dev/ic/rndisreg.h: revision 1.1
sys/arch/i386/i386/genassym.cf: revision 1.111
sys/dev/ic/rndisreg.h: revision 1.2
sys/dev/hyperv/hyperv_common.c: revision 1.1
sys/dev/hyperv/hvtimesync.c: revision 1.1
sys/dev/hyperv/hypervreg.h: revision 1.1
sys/dev/hyperv/hvtimesync.c: revision 1.2
sys/dev/hyperv/vmbusicvar.h: revision 1.1
sys/dev/hyperv/if_hvnreg.h: revision 1.1
sys/arch/x86/x86/lapic.c: revision 1.70
sys/arch/amd64/amd64/vector.S: revision 1.70
sys/dev/ic/ndisreg.h: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.516
sys/dev/hyperv/hypervvar.h: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.518
sys/arch/amd64/conf/GENERIC: revision 1.519
sys/arch/i386/conf/files.i386: revision 1.400
sys/dev/acpi/vmbus_acpi.c: revision 1.1
sys/dev/hyperv/vmbus.c: revision 1.1
sys/dev/hyperv/vmbus.c: revision 1.2
sys/arch/x86/x86/intr.c: revision 1.144
sys/arch/i386/i386/vector.S: revision 1.83
sys/arch/amd64/conf/files.amd64: revision 1.112

separate RNDIS definitions from urndis(4) for use with Hyper-V NetVSC.

-

Added Microsoft Hyper-V support. It ported from OpenBSD and FreeBSD.
graphical console is not work on Gen.2 VM yet. To use the serial console,
enter "consdev com,0x3f8,115200" on efiboot.

-

Add __diagused.

-

PR/53984: Partial revert of modify lapic_calibrate_timer() in lapic.c r1.69.

-

Update Hyper-V related drivers description.

-

Remove unused definition.

-

Rename the MODULE_*_HOOK() macros to MODULE_HOOK_*() as briefly
discussed on irc.
NFCI intended.

-

commented out hvkvp entry.

-

fix typo. pointed out by pgoyette@n.o.

-

Use IDTVEC instead of NENTRY for handle_hyperv_hypercall.

-

Rename the MODULE_*_HOOK() macros to MODULE_HOOK_*() as briefly
discussed on irc.
 1.49.2.3 05-Apr-2018  martin Pull up following revision(s) (requested by christos in ticket #696):

sys/arch/amd64/amd64/vector.S: revision 1.62 (patch)
sys/arch/x86/include/intr.h: revision 1.55
sys/arch/i386/i386/vector.S: revision 1.77
sys/arch/i386/i386/db_interface.c: revision 1.82 (patch)
sys/arch/amd64/amd64/spl.S: revision 1.34 (patch)
sys/arch/amd64/amd64/db_interface.c: revision 1.33 (patch)
sys/arch/x86/x86/intr.c: revision 1.125
sys/arch/i386/i386/spl.S: revision 1.43 (patch)
sys/arch/i386/i386/machdep.c: revision 1.805 (patch)
sys/arch/x86/x86/lapic.c: revision 1.66 (patch)

Rename the DDB IPI IDT vectors for consistency. ok maxv@

Rename Xpreempt{recurse,resume} -> X{recurse,resume}_preempt so that
they fit the pattern. Also the debugger trap sniffer matches them
without adding special entries...

XXX: pullup-8.
 1.49.2.2 22-Mar-2018  martin Pull up the following revisions, requested by maxv in ticket #652:

sys/arch/amd64/amd64/amd64_trap.S upto 1.39 (partial, patch)
sys/arch/amd64/amd64/db_machdep.c 1.6 (patch)
sys/arch/amd64/amd64/genassym.cf 1.65,1.66,1.67 (patch)
sys/arch/amd64/amd64/locore.S upto 1.159 (partial, patch)
sys/arch/amd64/amd64/machdep.c 1.299-1.302 (patch)
sys/arch/amd64/amd64/trap.c upto 1.113 (partial, patch)
sys/arch/amd64/amd64/amd64/vector.S upto 1.61 (partial, patch)
sys/arch/amd64/conf/GENERIC 1.477,1.478 (patch)
sys/arch/amd64/conf/kern.ldscript 1.26 (patch)
sys/arch/amd64/include/frameasm.h upto 1.37 (partial, patch)
sys/arch/amd64/include/param.h 1.25 (patch)
sys/arch/amd64/include/pmap.h 1.41,1.43,1.44 (patch)
sys/arch/x86/conf/files.x86 1.91,1.93 (patch)
sys/arch/x86/include/cpu.h 1.88,1.89 (patch)
sys/arch/x86/include/pmap.h 1.75 (patch)
sys/arch/x86/x86/cpu.c 1.144,1.146,1.148,1.149 (patch)
sys/arch/x86/x86/pmap.c upto 1.289 (partial, patch)
sys/arch/x86/x86/vm_machdep.c 1.31,1.32 (patch)
sys/arch/x86/x86/x86_machdep.c 1.104,1.106,1.108 (patch)
sys/arch/x86/x86/svs.c 1.1-1.14
sys/arch/xen/conf/files.compat 1.30 (patch)

Backport SVS. Not enabled yet.
 1.49.2.1 07-Mar-2018  martin Pull up the following revisions (via patch), requested by maxv in ticket #610:

sys/arch/amd64/amd64/amd64_trap.S 1.8,1.10,1.12 (partial),1.13-1.15,
1.19 (partial),1.20,1.21,1.22,1.24
(via patch)
sys/arch/amd64/amd64/locore.S 1.129 (partial),1.132 (via patch)
sys/arch/amd64/amd64/trap.c 1.97 (partial),1.111 (via patch)
sys/arch/amd64/amd64/vector.S 1.54,1.55 (via patch)
sys/arch/amd64/include/frameasm.h 1.21,1.23 (via patch)
sys/arch/x86/x86/cpu.c 1.138 (via patch)
sys/arch/xen/conf/Makefile.xen 1.45 (via patch)

Rename and reorder several things in amd64_trap.S.
Compile amd64_trap.S as a file.
Introduce nmitrap and doubletrap.
Have the CPU clear PSL_D automatically in the syscall entry point.
 1.50.2.2 16-Jul-2017  cherry 2302716
 1.50.2.1 16-Jul-2017  cherry file vector.S was added on branch perseant-stdc-iso10646 on 2017-07-16 14:02:49 +0000
 1.60.2.5 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.60.2.4 28-Jul-2018  pgoyette Sync with HEAD
 1.60.2.3 25-Jun-2018  pgoyette Sync with HEAD
 1.60.2.2 07-Apr-2018  pgoyette Sync with HEAD. 77 conflicts resolved - all of them $NetBSD$
 1.60.2.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.63.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.63.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.63.2.1 10-Jun-2019  christos Sync with HEAD
 1.73.6.6 18-Apr-2020  bouyer If possible, register a per-cpu callback via HVMOP_set_evtchn_upcall_vector.
From FreeBSD. This requires acking the interrupt in hypervisor_pvhvm_callback.

Don't try to use x86_cpu_idle_xen() for PVHVM, it cause the domU to hang.
FreeBSD doesn't seem to use it either.
 1.73.6.5 16-Apr-2020  bouyer amd64: Xhypervisor_pvhvm_callback has to be in text.user for SVS.
Thanks to maxv@ for helping me with this.
Enable SVS again.
While there, increase ci_idepth before calling do_hypervisor_callback,
and don't touch ci_idepth while looping over pending events.
 1.73.6.4 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.
 1.73.6.3 12-Apr-2020  bouyer Get rid of xen-specific ci_x* interrupt handling:
- use the general SIR mechanism, reserving 3 more slots for IPL_VM, IPL_SCHED
and IPL_HIGH
- remove specific handling from C sources, or change to ipending
- convert IPL number to SIR number in various places
- Remove XUNMASK/XPENDING in assembly or change to IUNMASK/IPENDING
- remove Xen-specific ci_xsources, ci_xmask, ci_xunmask, ci_xpending from
struct cpu_info
- for now remove a KASSERT that there are no pending interrupts in
idle_block(). We can get there with some software interrupts pending
in autoconf XXX needs to be looked at.
 1.73.6.2 11-Apr-2020  bouyer Merge back hypervisor_callback and hypervisor_pvhvm_callback, there's no
issues calling Xdoreti in the PV case.
 1.73.6.1 10-Apr-2020  bouyer spllower(): Also check Xen pending events
hypervisor_pvhvm_callback(): exit via Xdoreti, so that pending interrupts
are checked.
disable __HAVE_FAST_SOFTINTS only for XENPV, it now works for PVHVM.
We still have to disable PREEMPTION, until we support MULTIPROCESSOR
 1.40 30-Mar-2009  rmind Merge i386 and amd64 vm_machdep.c into x86. No functional changes intended.
Note: some #ifdefs will be removed with macros.
 1.39 29-Mar-2009  rmind Reduce some differences between i386 and amd64.
Mainly cosmetical changes - no functional changes intended.
 1.38 28-Mar-2009  rmind kvtop: change return type to paddr_t.
 1.37 20-Dec-2008  ad branches: 1.37.2;
- Kill NOREDZONE.
- Make the redzone conditional on DIAGNOSTIC.
- Give amd64 an additional page for the uarea. 2 is not enough.
 1.36 18-Dec-2008  cegger remove unused malloc.h
 1.35 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.34 19-Oct-2008  christos branches: 1.34.2; 1.34.4;
fix typo
 1.33 27-May-2008  ad branches: 1.33.4;
cpu_lwp_fork: set tf_trapno=T_ASTFLT in case the LWP gets an aston() before
returning to userspace for the first time.
 1.32 21-Apr-2008  tls branches: 1.32.2; 1.32.4;
Don't use mtrr functions if not options MTRR. There are many more instances
of this bug, particularly in the COMPAT_FOO32 code.
 1.31 16-Apr-2008  cegger branches: 1.31.2;
use POSIX integer types
 1.30 15-Jan-2008  joerg branches: 1.30.6;
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.29 08-Jan-2008  yamt change the layout in u-area and reduce UPAGES.
 1.28 05-Jan-2008  yamt - make amd64 use per-cpu tss.
- fix iopl syscall for amd64+xen.
 1.27 18-Oct-2007  yamt branches: 1.27.2; 1.27.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.26 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.25 17-Aug-2007  ad branches: 1.25.2; 1.25.4; 1.25.6;
cpu_lwp_fork: don't rely on struct mdlwp being zeroed in advance.
 1.24 04-Jun-2007  xtraeme branches: 1.24.4; 1.24.8;
Ansify, de-__P(), unregister.
 1.23 02-Jun-2007  njoly Revert fs/gs changes for now.

This make clone(2) work again under NPTL compat linux emulation.

ok by fvdl.
 1.22 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.21 13-May-2007  fvdl Initialize a few PCB fields explicity in more places.
 1.20 04-Mar-2007  christos branches: 1.20.2; 1.20.4; 1.20.10;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.19 22-Feb-2007  thorpej TRUE -> true, FALSE -> false
 1.18 18-Feb-2007  cube Fix a couple missed occurrences of P_32 -> PK_32.
 1.17 17-Feb-2007  pavel Change the process/lwp flags seen by userland via sysctl back to the
P_*/L_* naming convention, and rename the in-kernel flags to avoid
conflict. (P_ -> PK_, L_ -> LW_ ). Add back the (now unused) LSDEAD
constant.

Restores source compatibility with pre-newlock2 tools like ps or top.

Reviewed by Andrew Doran.
 1.16 09-Feb-2007  ad branches: 1.16.2;
Merge newlock2 to head.
 1.15 30-Aug-2006  cube branches: 1.15.2;
Let this compile under "no options COREDUMP".
 1.14 10-May-2006  skrll Fix a bunch of cast lvalues.
 1.13 11-Dec-2005  christos branches: 1.13.4; 1.13.6; 1.13.8; 1.13.10; 1.13.12;
merge ktrace-lwp.
 1.12 04-Aug-2005  fvdl Missed commit from the linux compat changes dealing with setting fs and gs:
copy the PCB fs and gs on fork.
 1.11 10-Jun-2005  matt branches: 1.11.2;
Rework the coredump code to have no explicit knownledge of how coredump
i/o is done. Instead, pass an opaque cookie which is then passed to a
new routine, coredump_write, which does the actual i/o. This allows the
method of doing i/o to change without affecting any future MD code.
Also, make netbsd32_core.c [re]use core_netbsd.c (in a similar manner that
core_elf64.c uses core_elf32.c) and eliminate that code duplication.
cpu_coredump{,32} is now called twice, first with a NULL iocookie to fill
the core structure and a second to actually write md parts of the coredump.
All i/o is nolonger random access and is suitable for shipping over a stream.
 1.10 01-Apr-2005  yamt merge yamt-km branch.
- don't use managed mappings/backing objects for wired memory allocations.
save some resources like pv_entry. also fix (most of) PR/27030.
- simplify kernel memory management API.
- simplify pmap bootstrap of some ports.
- some related cleanups.
 1.9 17-Sep-2004  skrll branches: 1.9.4; 1.9.6;
There's no need to pass a proc value when using UIO_SYSSPACE with
vn_rdwr(9) and uiomove(9).

OK'd by Jason Thorpe
 1.8 28-Aug-2004  thorpej Garbage-collect pagemove(); nothing use it anymore (YAY!!!)
 1.7 28-Jun-2004  fvdl Set the double fault stack pointer at the end of the stack.
 1.6 15-Jun-2004  fvdl Make the IDT read-only. It's only mapped R/W when really needed. Could
catch disasters such as overwriting it. Should probably be made
conditional on DIAGNOSTIC later, but there's no time-critical code
involved here.

Move the double fault stack away from the IPI stack. It's now shared
between CPUs, but that's not a big deal; double faults are fatal
and can't be recovered from.
 1.5 12-Jan-2004  jdolecek finish previous (removal of 'reaper' kernel thread):
* move tss_free() call to the new cpu_lwp_free()
* g/c cpu_wait()

fixes PR kern/24067 by Nicolas Joly
 1.4 04-Jan-2004  jdolecek Rearrange process exit path to avoid need to free resources from different
process context ('reaper').

From within the exiting process context:
* deactivate pmap and free vmspace while we can still block
* introduce MD cpu_lwp_free() - this cleans all MD-specific context (such
as FPU state), and is the last potentially blocking operation;
all of cpu_wait(), and most of cpu_exit(), is now folded into cpu_lwp_free()
* process is now immediatelly marked as zombie and made available for pickup
by parent; the remaining last lwp continues the exit as fully detached
* MI (rather than MD) code bumps uvmexp.swtch, cpu_exit() is now same
for both 'process' and 'lwp' exit

uvm_lwp_exit() is modified to never block; the u-area memory is now
always just linked to the list of available u-areas. Introduce (blocking)
uvm_uarea_drain(), which is called to release the excessive u-area memory;
this is called by parent within wait4(), or by pagedaemon on memory shortage.
uvm_uarea_free() is now private function within uvm_glue.c.

MD process/lwp exit code now always calls lwp_exit2() immediatelly after
switching away from the exiting lwp.

g/c now unneeded routines and variables, including the reaper kernel thread
 1.3 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.2 14-Jul-2003  lukem __KERNEL_RCSID()
 1.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.2.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.2.5 01-Apr-2005  skrll 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-Sep-2004  skrll Sync with HEAD
 1.1.2.1 03-Aug-2004  skrll Sync with HEAD
 1.9.6.1 13-Feb-2005  yamt - use new apis.
- simplify pmap bootstrap and pv_page allocation.
 1.9.4.1 29-Apr-2005  kent sync with -current
 1.11.2.6 21-Jan-2008  yamt sync with head
 1.11.2.5 27-Oct-2007  yamt sync with head.
 1.11.2.4 03-Sep-2007  yamt sync with head.
 1.11.2.3 26-Feb-2007  yamt sync with head.
 1.11.2.2 30-Dec-2006  yamt sync with head.
 1.11.2.1 21-Jun-2006  yamt sync with head.
 1.13.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.13.10.1 11-May-2006  elad sync with head
 1.13.8.2 03-Sep-2006  yamt sync with head.
 1.13.8.1 24-May-2006  yamt sync with head.
 1.13.6.1 01-Jun-2006  kardel Sync with head.
 1.13.4.1 09-Sep-2006  rpaulo sync with head
 1.15.2.2 19-Jan-2007  ad - cpu_exit(): move 'cli' behind clearing curlwp to close a race with
lwp_free(). Noted by yamt@.
- Don't bother calling lwp_exit2() any more.
 1.15.2.1 29-Dec-2006  ad Checkpoint work in progress.
 1.16.2.4 17-May-2007  yamt sync with head.
 1.16.2.3 12-Mar-2007  rmind Sync with HEAD.
 1.16.2.2 03-Mar-2007  yamt adapt amd64.

XXX changes in identcpu.c is minmum for MONITOR.
XXX identcpu.c should be shared with i386.
 1.16.2.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.20.10.3 03-Oct-2007  garbled Sync with HEAD
 1.20.10.2 26-Jun-2007  garbled Sync with HEAD.
 1.20.10.1 22-May-2007  matt Update to HEAD.
 1.20.4.1 11-Jul-2007  mjf Sync with head.
 1.20.2.4 23-Oct-2007  ad Sync with head.
 1.20.2.3 20-Aug-2007  ad Sync with HEAD.
 1.20.2.2 09-Jun-2007  ad Sync with head.
 1.20.2.1 27-May-2007  ad Sync with head.
 1.24.8.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.24.8.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.24.4.1 03-Sep-2007  skrll Sync with HEAD.
 1.25.6.1 25-Oct-2007  bouyer Sync with HEAD.
 1.25.4.1 04-Oct-2007  yamt remove LARGEPAGES option. always use large pages if available.
 1.25.2.3 23-Mar-2008  matt sync with HEAD
 1.25.2.2 09-Jan-2008  matt sync with HEAD
 1.25.2.1 06-Nov-2007  matt sync with HEAD
 1.27.8.2 19-Jan-2008  bouyer Sync with HEAD
 1.27.8.1 08-Jan-2008  bouyer Sync with HEAD
 1.27.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.30.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.30.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.31.2.2 04-Jun-2008  yamt sync with head
 1.31.2.1 18-May-2008  yamt sync with head.
 1.32.4.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.32.2.1 04-May-2009  yamt sync with head.
 1.33.4.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.33.4.1 19-Oct-2008  haad Sync with HEAD.
 1.34.4.1 16-Feb-2009  snj Pull up following revision(s) (requested by ad in ticket #355):
sys/arch/amd64/amd64/vm_machdep.c: revision 1.37
sys/arch/amd64/include/param.h: revision 1.10
- Kill NOREDZONE.
- Make the redzone conditional on DIAGNOSTIC.
- Give amd64 an additional page for the uarea. 2 is not enough.
 1.34.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.34.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.37.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.195 21-Oct-2025  pgoyette Add Realtek 8126 to comment for rge*
 1.194 06-Oct-2025  riastradh x86: Wire up PCI resource manager if enabled.

Enable in your kernel config with `options PCI_RESOURCE'.

Adapted from a patch by mlelstv@.

PR port-amd64/59118: Thinkpad T495s - iwm PCI BAR is zero
 1.193 18-Aug-2025  andvar Fix various typos, mainly in comments:
s/invaid/invalid/
s/instad/instead/
s/wich/with/
s/tranform/transform/
s/tranmist/transmit/
s/tranceiver/transceiver/
s/Tranparent/Transparent/
s/tranlated/translated/
s/tranfer/transfer/
s/tranmissions/transmissions/
s/condtions/conditions/
s/Recient/Recent/
 1.192 03-Apr-2025  bouyer branches: 1.192.2;
Add gscan(4), a driver for USB to CAN bus adapters.
This driver supports the Geschwister Schneider USB to CAN adapter, and
clones supported by the open-source candleLight firmware.

Add gscan to evbarm GENERIC (which already supports CAN family and the
sunxican(4) driver by default), and to amd64 ALL.
 1.191 27-Mar-2025  riastradh virtio(4): Consolidate kernel configs.

No functional change intended.

Leave `# XXX ?' comments where I don't know why the driver in
question is excluded. (Typical reason is that PAGE_SIZE is not 4096
but I didn't investigate -- if you do investigate, please either
update the comment if you determine a reason, or enable the driver if
you don't.)

PR kern/59211: vio9p(4): missing from various GENERICs and MAKEDEVs
 1.190 26-Aug-2024  riastradh acpivmgenid(4): New driver for virtual machine generation ID.

Added to amd64/ALL and i386/ALL kernel configurations, and made
available as a loadable module acpivmgenid.kmod on x86, for now.

TBD: Add to all ACPI-supporting GENERIC kernels.

PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork
 1.189 16-Jul-2024  riastradh viocon(4): Add to various kernel configs.
 1.188 30-Apr-2024  andvar branches: 1.188.2;
viac7temp(4): rewrite temperature sensor to read value from MSR instead of using
documented cpuid instruction and eax register.

This approach is adapted from linux via-cputemp.c, no official documentation is
currently available. However, msr value seems to work on all tested CPUs while
documented cpuid instruction typically reports 0, even for my C7-D CPU.
msr value seems to have temperature in Celsius in lower 24-bits without fraction
(thus "msr & 0xffffff;" is used).

Tested on my personal systems based on CPUs below (i386 and amd64):
C7-D 1.6GHz (i386 only), Nano X2 L4350E, Nano X2 U4300, U2300 Nano, KX-U6580.
Also got one response via email which was based on Nano X2 L4050 (VE-900).
Nano reports independent values for each core.
KX-U6580 seems to show the same value for all cores but more testing is needed.

Since it works on amd64 capable CPUs, adding driver to GENERIC kernel config.
Also moving viac7temp man page to x86 instead of i386 (with updates).
In theory the change should add support for all VIA Nano CPUs and Zhaoxin CPUs
at least up to KX-6000(G) series.

In the future I may need to introduce amd64 kernel module as well.

Plan to pullup to at least netbsd-10.

Patch mainly reviewed by riastradh.
 1.187 02-Apr-2024  charlotte dk(4): Add support for discovering Atari TOS partitions as wedges

Any partitioning scheme which conforms to the Atari AHDI 3.00 spec should be
recognized by the new DKWEDGE_METHOD_TOS.
 1.186 21-Mar-2024  riastradh acpihed(4): New driver for PNP0C33 to notify apei(4).

PNP0C33 denotes the ACPI Hardware Error Device, which exists only to
be a vector for event notifications.

PR kern/58046
 1.185 20-Mar-2024  riastradh apei(4): New driver for ACPI Platform Error Interfaces.

For now it is wired up only in x86 ALL kernels, and built as a module
for x86 and Arm. Once it gets a little more testing on machines with
APEI, I would like to flip it on by default.

PR kern/58046
 1.184 29-Jan-2024  christos PR/57889: Ricardo Branco: ext2fs does not have user immutable and append
file flags, only system ones. Restrict those to the superuser. Before
the behavior was controlled by EXT2FS_SYSTEM_FLAGS. Make that behavior the
default.
 1.183 13-Dec-2023  andvar Removing obsolete TTY_DEBUG option from ALL kernels.
 1.182 05-Dec-2023  thorpej Add btvmei + btvmeii and vme to ALL.
 1.181 04-Oct-2023  rin igc(4): Added to kernel config files for tested platforms

I.e., aarch64, amd64, and evbppc/DHT, at the moment.

Please feel free to add to other config files, and report us back
if you find problems :)
 1.180 02-Sep-2023  andvar newsmips/sn(4): rename SONIC_DEBUG to SNDEBUG for consistency.

nix this option from i386/amd64 ALL configs, it isn't used anywhere anymore.
 1.179 18-Jul-2023  riastradh acpiec(4): New ACPIEC_DEBUG option.

Value is bit mask of debug messages to enable.

Enable in x86/ALL kernels.

No functional change intended when the option is off.
 1.178 07-Jul-2023  riastradh amd64/ALL: Turn on heartbeat checks.
 1.177 09-Feb-2023  abs Adjust _all_ cinclude of *.local files

- Ensure always at end
- Use tab rather than spaces
- Add consistent comment
"Pull in optional local configuration - always at end"

The only functional change is that a local file which tried to
override an existing setting (eg with "no foo") would have failed
in some cases before, but now will work
 1.176 22-Dec-2022  jakllsch Add missing virtio devices to x86 ALL kernels
 1.175 22-Dec-2022  nat Driver for DaynaPORT SCSI/Link (dse.4).

Written by Hiroshi Noguchi, of which an updated version was posted to
port-mac68k in 2001.

Attachments were added to kernel configs for platforms that already had
the Cabletron (se.4) driver added, although other platorms may benefit.

Reviewed on tech-net by Izumi Tsutsui.
 1.174 24-Sep-2022  riastradh branches: 1.174.4;
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.173 07-Aug-2022  simonb UFS/LFS dirhash:
- Enable UFS_DIRHASH if the architecture or kernel model specific config
file can use 128MB of RAM or more.
- Remove experimental tag from UFS_DIRHASH; it's been with RUMP kernel
and by a number of NetBSD developers for years.
- Add LFS_DIRHASH if LFS was enabled.
- Be somewhat consistent with FS options order.
 1.172 29-May-2022  rin Add missing Hyper-V devices from GENERIC.
 1.171 13-May-2022  msaitoh Add MFI_DEBUG and MFII_DEBUG.
 1.170 07-May-2022  rin Add MODULAR_DEFAULT_VERBOSE.
 1.169 23-Dec-2021  hannken Disable amdgpu as it uses floating point arithmetics and subr_kcov
doesnt handle it.

Ok: riastradh@
 1.168 25-Nov-2021  ryo add missing options EXEC_ELF32
 1.167 29-Jun-2021  nia Remove uscanner(4) driver

This exists for compatibility with a Linux interface which was apparently
deprecated in Linux 2.6. There are various mailing list threads going
back to 2004 where the usefulness of this driver is discussed, but
the conclusion is that scanner software has all moved to using ugen(4)
instead, and enabling this driver will not help you scan things.
 1.166 01-Mar-2021  jakllsch branches: 1.166.4;
add rge(4) to x86 ALL kernels
 1.165 13-Dec-2020  martin Add atppc* at acpi?
 1.164 27-Sep-2020  roy branches: 1.164.2;
vether: Add to kernel configurations

It's only enabled if the kernel enabled bridge AND tap.
Otherwise it's commented out.
 1.163 08-Sep-2020  yamaguchi Added iavf(4) that is based on OpenBSD's iavf(4) implementation

reviewed by msaitoh@n.o and knakahara@n.o
 1.162 26-Aug-2020  riastradh Clarify wg(4)'s relation to WireGuard, pending further discussion.

Still planning to replace wgconfig(8) and wg-keygen(8) by one wg(8)
tool compatible with wireguard-tools; update wg(4) for the minor
changes from the 2018-06-30 spec to the 2020-06-01 spec; &c. This just
clarifies the current state of affairs as it exists in the development
tree for now.

Mark the man page EXPERIMENTAL for extra clarity.
 1.161 20-Aug-2020  riastradh Add wg(4) to amd64/ALL.
 1.160 01-Aug-2020  jdolecek remove CISS_NO_INTERRUPT_HACK from ALL kernel config too, it's no longer
supported in ciss(4)
 1.159 01-Aug-2020  maxv Remove references to BRIDGE_IPF, it is now compiled in by default.
 1.158 26-Jul-2020  jdolecek Add driver for Intel XMM7360 LTE modem, based upon Linux driver available
at https://github.com/xmm7360/xmm7360-pci

This version works on Linux, OpenBSD, and NetBSD.

OpenBSD port written for genua GmbH

Modem requires python script from the master site to initialize the network,
it will be added to pkgsrc shortly
 1.157 19-Jul-2020  maxv Compile USER_LDT by default, but, put it behind a privileged sysctl that
defaults to disabled. To enable:

# sysctl -w machdep.user_ldt=1
 1.156 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.155 29-Jun-2020  riastradh Make padlock(4) compile on amd64.
 1.154 24-Jun-2020  thorpej Add amdccp at pci.
 1.153 07-Jun-2020  maxv Add fault(4).
 1.152 30-May-2020  jdolecek add bwfm* at pci?, which is present in GENERIC
 1.151 25-May-2020  yamaguchi Obsolete VIOIF_SOFTINT_INTR

The kernel option is introduced to realize softint-based if_input.
Since the same scheme has been implemented in if_percpuq_enqueue(),
the option is no longer needed.

pointed out by ozaki-r@n.o.
 1.150 16-May-2020  maya Remove uyap, USB YAP phone firmware loader.

And the associated ezload EZ-USB code, which is only used by uyap.
It could theoretically be used by other drivers, but none of them are
in tree.

I suspect that this device isn't in use, as phone technology has improved
a lot since 2001 when uyap(4) was added to the tree.

Proposed with no objections on netbsd-users on 13 April 2020
 1.149 25-Apr-2020  simonb Add uxrcom.
 1.148 13-Apr-2020  jdolecek remove wd* at umass?, it was dropped
 1.147 25-Mar-2020  jdolecek branches: 1.147.2;
remove 'file-system SMBFS' and 'pseudo-device nsmb' from all kernel configs
to prepare for their eventual removal
 1.146 09-Feb-2020  jmcneill Retire azalia(4).
 1.145 08-Feb-2020  maxv Retire KLEAK.

KLEAK was a nice feature and served its purpose; it allowed us to detect
dozens of info leaks on the kernel->userland boundary, and thanks to it we
tackled a good part of the infoleak problem 1.5 years ago.

Nowadays however, we have kMSan, which can detect uninitialized memory in
the kernel. kMSan supersedes KLEAK: it can detect what KLEAK was able to
detect, but in addition, (1) it operates in all of the kernel and not just
the kernel->userland boundary, (2) it requires no user interaction, and (3)
it is deterministic and not statistical.

That makes kMSan the feature of choice to detect info leaks nowadays;
people interested in detecting info leaks should boot a kMSan kernel and
just wait for the magic to happen.

KLEAK was a good ride, and a fun project, but now is time for it to go.

Discussed with several people, including Thomas Barabosch.
 1.144 03-Feb-2020  maya Remove more urio(4) traces.

Pointed out by maxv, thanks.
 1.143 29-Jan-2020  maya remove urio(4), a driver for the Rio500 MP3 player.

At this point it is highly unlikely this 1999 device still has users,
but it still comes up in the context of maxv's USB-fuzzing (and any device
could pretend to be a urio(4)), so it's best to get rid of it.

Renamed all major entries to obsolete, as was done in previous removals.

This still requires an update to sanitizers, but they're located in
"external", perhaps it should be first committed upstream?

Proposed on tech-kern a month ago.
 1.142 25-Jan-2020  thorpej Retire "le* at pci?" from the shipped kernel configs:
- If the config had both an le@pci and a pcn, simply remove le@pci
(pcn would match at a higher priority anyway).
- If the config had le@pci enabled, but no pcn, change le@pci to pcn.
- If the config had le@pci commented out, but no pcn, change le@pci
to pcn and leave it commented out.

The pcn driver supports more chips than le@pci and does DMA directly
to/from mbufs rather than memory copies.
 1.141 20-Jan-2020  thorpej Remove FDDI support.
 1.140 19-Jan-2020  riastradh Remove filemon(4).

Discussed on tech-kern:
https://mail-index.NetBSD.org/tech-kern/2020/01/13/msg025938.html

This was never (intentionally) enabled by default, and the design has
some shortcomings. You can get mostly the same results with ktrace,
as in usr.bin/make/filemon/filemon_ktrace.c which is now used instead
of filemon for make's meta mode.

If applications require higher performance than ktrace, or nesting
that ktrace doesn't support, we might consider adding something back
into the vfs system calls themselves, without hijacking the syscall
table. (Might want a more reliable output format too, e.g. one that
can handle newlines in file names.)
 1.139 19-Jan-2020  thorpej Remove Token Ring support.
 1.138 19-Jan-2020  thorpej Remove HIPPI support and the esh(4) driver that uses it. There have not
been any users of HIPPI for some time, and it is unlikely to be resurrected.
 1.137 19-Jan-2020  thorpej Remove the strip(4) - Starmode Radio IP - pseudo-device driver. It is
long since obsolete.
 1.136 17-Jan-2020  maya Remove uyurex(4).

This is a driver for a "nonsense machine" made by the art group Maywa-Denki
in 2008. It was disabled by default.

Unfortunately even so it draws development attention (flaws found in the
code, MP-ification needs) and it is best not to continue to maintain this
driver.

Proposed without objections on tech-kern.
 1.135 01-Jan-2020  ryo branches: 1.135.2;
add aq(4)
 1.134 23-Dec-2019  maxv Revert the removal of filemon.
 1.133 18-Dec-2019  maxv Retire filemon, discussed on tech-kern@.
 1.132 15-Dec-2019  riastradh Add vhci to x86/ALL.
 1.131 10-Dec-2019  yamaguchi Ported driver for Intel Ethernet 700 series

reviewed by msaitoh and knakahara
 1.130 20-Nov-2019  hikaru Add opencrypto driver for Intel QuickAssist.
 1.129 10-Nov-2019  chs add ips driver.
 1.128 01-Nov-2019  msaitoh Port SMSC LAN87xx 10/100 Ethernet PHY driver from FreeBSD with some cleanup
and IFM_NONE support.
 1.127 30-Oct-2019  msaitoh Add jmphy(4) from OpenBSD.
 1.126 28-Oct-2019  ozaki-r Add vio9p to some kernel configs
 1.125 08-Oct-2019  maxv No I/O ports for TPM-ISA, only MMIO, so remove commented-out options.
 1.124 07-Oct-2019  msaitoh Add support IC Plus IP1000* PHYs. PR/kern 42314 first reported by
Tomokazu HARADA and patch provided by Andrius V.
 1.123 03-Oct-2019  tnn also add mcx(4) to ALL
 1.122 19-Aug-2019  ozaki-r Add MBUFTRACE to ALL configs
 1.121 09-Aug-2019  rin xhci(4) is considered stable enough. So, remove misleading comments.

XXX
pullup to netbsd-9
 1.120 24-Jul-2019  tnn branches: 1.120.2;
add ssdfb(4) to ALL
 1.119 07-May-2019  mrg obsolete moscom(4). it was never in any default configs, did
not work for some cases.

umcs(4) supports everything it does plus one additional chipset,
has been in default configurations since netbsd 7.
 1.118 26-Apr-2019  sevan Use veriexec.config to reduce duplication
 1.117 12-Apr-2019  msaitoh Add the following debug options:

AI_DEBUG
ATHN_DEBUG
ATU_DEBUG
AXEN_DEBUG
BGE_DEBUG
BNX_DEBUG
BWFM_DEBUG
CAS_DEBUG
CBB_DEBUG
CMALO_DEBUG
EF_DEBUG
IWN_DEBUG
IX_DEBUG
LII_DEBUG
MSK_DEBUG
OTUS_DEBUG
RUM_DEBUG
RUN_DEBUG
UMB_DEBUG
UPGT_DEBUG
URAL_DEBUG
URNDIS_DEBUG
URTW_DEBUG
URTWN_DEBUG
WPI_DEBUG
ZYD_DEBUG
 1.116 24-Feb-2019  kamil Enable kUBSan kASan and KCOV in NetBSD/amd64 kernel=ALL

Add disabled KLEAK as it conflicts right now with KCOV, using the same
compiler instrumentation.
 1.115 06-Feb-2019  rin Add ure(4) to kernel config files. Also add PHY drivers where necessary.
 1.114 27-Jan-2019  maxv Remove the satlink driver. It was disabled everywhere, had no man page and
no use either. Spotted by thorpej in PR/21345, ok christos.
 1.113 29-Dec-2018  maxv Retire compat_ibcs2, as discussed on tech-kern@. FreeBSD did the same
recently.
 1.112 19-Dec-2018  maxv Remove compat_svr4 and compat_svr4_32, as discussed on tech-kern@ recently,
but also as discussed several times in the past.
 1.111 14-Dec-2018  jakllsch add cardbus malo(4) to x86 GENERIC and ALL kernels
 1.110 12-Dec-2018  maxv Remove references to "lmc" in the kernel configurations.
 1.109 09-Dec-2018  jdolecek remove 'NOT WORKING' for ena(4) - while it was not yet confirmed working
on x86, it already is confirmed working on aarm64 so chances are high
it will work for x86 too
 1.108 24-Nov-2018  bouyer Add mpii(4), a driver for LSI Megaraid Fusion controllers.
Ported from OpenBSD. This driver is MP-safe.
Note that the earlier fusion controllers (Megaraid 2208, codenamed Thunderbold)
are also supported by mfi(4). mpii will take precedence if both drivers
are enabled.
Tested on a
mfii0 at pci6 dev 0 function 0: "PERC H740P Adapter ", firmware 50.3.0-1512, 819
2MB cache
mfii0: interrupting at ioapic2 pin 2
scsibus0 at mfii0: 64 targets, 8 luns per target
scsibus0: waiting 2 seconds for devices to settle...
sd0 at scsibus0 target 0 lun 0: <DELL, PERC H740P Adp, 5.03> disk fixed
sd0: fabricating a geometry
sd0: 99 GB, 102399 cyl, 64 head, 32 sec, 512 bytes/sect x 209714688 sectors
sd0: tagged queueing
sd1 at scsibus0 target 1 lun 0: <DELL, PERC H740P Adp, 5.03> disk fixed
sd1: fabricating a geometry
sd1: 22254 GB, 22788608 cyl, 64 head, 32 sec, 512 bytes/sect x 46671069696 sectors
sd1: fabricating a geometry

It supports bioctl(8) ioctls, as well as sensors for the BBU and logical
drives.

Sponsored by LIP6.
 1.107 23-Sep-2018  maxv Remove ISDN from the kernel. It has remained unmaintained for a long time,
is of poor quality, and is now an obstacle to MP-ification. It was removed
ten years ago from FreeBSD for the same reason.

This retires a big user of the mbuf API, and will ease maintenance of the
kernel.
 1.106 22-Sep-2018  maxv Remove isic(4). It is part of ISDN, which we are now retiring.
 1.105 22-Sep-2018  maxv Remove iwic(4). It is part of ISDN, which we are now retiring. This driver
was still marked as experimental (its man page dates back to 2002).
 1.104 22-Sep-2018  maxv Remove the "ifritz" driver (no man page). It is part of ISDN, which we are
retiring.
 1.103 22-Sep-2018  maxv Remove ifpci(4). It is part of ISDN, which we are retiring.
 1.102 21-Sep-2018  maxv Remove iavc(4).
 1.101 06-Sep-2018  maxv Retire the 'midway' driver. Discussed on tech-net@ recently and also three
years ago, part of removing the network ATM code.
 1.100 27-Aug-2018  riastradh Add amdgpu to amd64/ALL.
 1.99 25-Aug-2018  rin Add (commented out) mue(4) to where appropriate.
Also add MII/PHY drivers for USB NICs if missing.
 1.98 25-Aug-2018  maxv Retire NDIS. It appears that it has never worked, after 13 years it was
still marked as "experimental", and nowadays it may be one more obstacle
to MPification of the network stack.

Discussed on tech-net@.
 1.97 14-Aug-2018  maxv Replace references to etherip by l2tp. Etherip was already not enabled
anyway.
 1.96 01-Aug-2018  khorben Build the umb(4) driver in the ALL kernels (amd64, i386)

As suggested by Robert Swindells; thank you!
 1.95 26-Jul-2018  maxv Retire XENDEBUG_LOW, and switch its only user to XENDEBUG.
 1.94 13-Jul-2018  maxv Remove the X86PMC code I had written, replaced by tprof. Many defines
become unused in specialreg.h, so remove them. We don't want to add
defines all the time, there are countless PMCs on many generations, and
it's better to just inline the event/unit values.
 1.93 12-Jul-2018  maya Add entries for viadrmums to amd64 kernel configs too.

Commented out for GENERIC, same as i386.
 1.92 10-Jul-2018  maya Remove unused macro.
 1.91 10-Jul-2018  maya Remove viadrm(4), superseded by viadrmums.

Aside from viadrm using older drm code, it's also dysfunctional right now.
See PR port-i386/53364.
 1.90 16-Jun-2018  jdolecek branches: 1.90.2;
uncomment ena(4) now that it compiles; even though it's not working yet, this
ensures it's included in eventual subsystem rototils
 1.89 07-Jun-2018  thorpej Revert changes that pinned-down i2c parent specs. The i2c subsystem
has been enhanced to make this unnecessary.
 1.88 19-May-2018  jdolecek add config glue for ena(4)
 1.87 15-May-2018  thorpej Fully specifiy the location of indirectly-configured I2C devices. In
particular, the parent spec must not be wild-carded, as doing so doesn't
work well on systems where more than one I2C bus is present.

N.B. The x86 platforms are sort of a mess, here... legacy indirect
config and ACPI direct config sort of smashed together with the
same config file directives.
 1.86 01-May-2018  maya Fix ALL configs following MPVERBOSE becoming a defparam

XXX i386 ALL kernel build is failing
 1.85 08-Apr-2018  mrg turn on GCC spectre v2 mitigation options.

XXX: amd64 ALL doesn't build for me right now
 1.84 29-Mar-2018  maxv Remove TCPREASS_DEBUG. It was introduced 20 years ago when the reassembler
was being developed, but it's irrelevant today. Makes the code clearer.
 1.83 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.82 25-Feb-2018  pgoyette branches: 1.82.2;
As requested by chuq@, add the new imc devices to the i386 and amd64
ALL kernels.
 1.81 12-Feb-2018  joerg Add a new option CISS_NO_INTERRUPT_HACK for driving ciss(4) by callouts.
This is intended as workaround for certain Xen issues with dom0 kernels
and will likely want to have a high HZ value as well for decent
performance.
 1.80 27-Jan-2018  pgoyette Update amdzentemp(4) attachment info. Also for ALL, remove duplicate
entry for amdtemp(4).
 1.79 25-Jan-2018  christos add amdzentemp
 1.78 13-Jan-2018  christos added commented out AUTOFS pseudo-device entries
 1.77 10-Jan-2018  knakahara add ipsec(4) interface to amd64/GENERIC and amd64/ALL configs.
 1.76 09-Jan-2018  christos Merge autofs support from: Tomohiro Kusumi
XXX: Does not work yet
 1.75 10-Dec-2017  bouyer Add dwiic, ihidev and ims
 1.74 02-Dec-2017  maxv Drop COMPAT_10 on amd64. The support for it comes down to one ifdef in
trap.c - code that is incorrect anyway, there were originally three lcall
LDT slots, and here only one instruction is decoded.

Given that one of these slots was used by BSDi's syscall, also remove the
references to COMPAT_NOMID to make clear we don't support that (it already
is not enabled).

Note: for some reason, COMPAT_10 does not even compile, because there are
"multiple definitions of _KERNEL_OPT_COMPAT_...", and I don't really
understand where this comes from.
 1.73 02-Dec-2017  maxv Remove options that do not exist on amd64.
 1.72 25-Nov-2017  jmcneill Add qemufwcfg (QEMU Firmware Configuration device)
 1.71 14-Sep-2017  mrg clean up COMPAT_* options for native netbsd code:
- new series of files that are useful for saying "i want everything
since netbsd 1.4", etc.
- use the fact COMPAT_* options have future dependancies to remove
many redundant options.

removes about 3000 lines total across kernel configuration files.
tested about 30 random kernels in the changed list.
 1.70 13-Sep-2017  sevan Remove support for VERIFIED_EXEC_FP_RMD160, VERIFIED_EXEC_FP_SHA1, and VERIFIED_EXEC_FP_MD5 options.
These algorithms are either broken or on their way to being broken.

Discussed on tech-security
http://mail-index.netbsd.org/tech-security/2017/08/21/msg000936.html

ok riastradh
 1.69 03-Sep-2017  maxv Remove useless debug code, and split trap() into smaller functions, easier
to understand. NMIs take another, faster path now. No functional change
beyond that.
 1.68 30-Aug-2017  maxv Don't allow userland to create 286/386 call gates anymore - they are not
used by Wine. While here, don't allow it to overwrite the static entries
either, don't allow unknown entry types, remove LDT_DEBUG, and style.
 1.67 13-Aug-2017  christos Add ALPS pms support
 1.66 12-Aug-2017  maxv Remove support for vm86 on i386. It is bug-friendly, and there is no point
in having kernel support for this: the instruction set of the CPU is small,
and it can easily be emulated in userland entirely. There are also several
assumptions in the code that are not respected, and the slightest confusion
in the trap frame can lead to ring0 exploits.

vm86 has received zero maintenance. As far as I can tell, it was added
20 years ago in order to make doscmd work. But doscmd has not been
maintained either, and was removed from pkgsrc in 2011. dosbox can be used
instead: it does not require kernel support, and will produce better
results than our flimsy implementation.

Pass 1. (many pieces still in the tree)
 1.65 09-Aug-2017  maxv Remove references to compat_ibcs2.
 1.64 29-Jul-2017  maxv Remove DEBUG_HPUX (does not exist).
 1.63 29-Jul-2017  maxv Remove IBCS2_DEBUG (does not exist).
 1.62 28-Jul-2017  maxv Remove TCP_COMPAT_42 from the config files. Pass 1.
 1.61 28-Jul-2017  riastradh Add some more bogus compat options to amd64/ALL for compile-testing.
 1.60 14-Jun-2017  pgoyette Add wsbell
 1.59 27-May-2017  bouyer branches: 1.59.2;
Add options CAN and pseudo-device canloop to ALL kernel configs.
Add the same commented out to i386/amd64 GENERIC and OLIMEXLIME2 (A20-based).
Also add commented out awincan0 in OLIMEXLIME2.
 1.58 25-May-2017  para follow u3ginit driver rename to umodeswitch
 1.57 26-Apr-2017  christos Catch up with GENERIC changes.
 1.56 18-Apr-2017  riastradh branches: 1.56.2;
gson@ informs me the Alea I and II have the same USB product id.

Thus, ualea(4) should work for both of them. Rename USB product id
ARANEUS ALEA_II to ARANEUS ALEA to reflect this.

No functional change intended, except perhaps via usbdevs.
 1.55 17-Apr-2017  riastradh New rndsource driver for Araneus Alea II TRNG USB devices.

Disabled by default in x86/GENERIC and usbdevices.config pending
review and testing without rump ugenhc in the way, but enabled in
x86/ALL for compile-testing.

(Hi gson! Finally found a round tuit in my pocket, next to a certain
rectangular one.)
 1.54 08-Mar-2017  maxv A few changes:
* Use markers to reduce false sharing.
* Remove XENDEBUG_SYNC and several debug messages, they are just useless.
* Remove xen_vcpu_*. They are unused and not optimized: if we really
wanted to flush ranges we should pack the VAs in a mmuext_op array
instead of performing several hypercalls in a loop.
* Start removing PG_k.
* KNF, reorder, simplify and remove stupid comments.
 1.53 26-Feb-2017  rin Add DKWEDGE_METHOD_RDB option, which is enabled for x86, commented out for
other platforms by default.
 1.52 19-Feb-2017  rin PR kern/51208
Add DISKLABEL_EI option (and also FFS_EI if missing), commented out except for
ALL on amd64 and i386.
 1.51 18-Feb-2017  maxv PERFCTRS -> PMC (not implemented anyway)
 1.50 16-Feb-2017  knakahara add l2tp(4) to amd64/GENERIC and amd64/ALL config.
 1.49 12-Jan-2017  ryo branches: 1.49.2;
white space police
 1.48 27-Dec-2016  pgoyette Add BIOHIST (and belatedly, UVMHIST) to the ALL kernels for i386 and amd64.

XXX Perhaps it should be added to others as well? Perhaps just as comments?
 1.47 23-Dec-2016  maya add SCTP_DEBUG to ALL kernels
 1.46 18-Dec-2016  dholland Whitespace.
 1.45 15-Dec-2016  ozaki-r Add SCTP to ALL configs to keep it buildable anyway
 1.44 13-Dec-2016  christos wildcard speaker attachments, now that we can handle many of them.
 1.43 10-Dec-2016  christos remove VAUDIOSPEAKER for now, will be done differently.
 1.42 09-Dec-2016  christos kill PCPPISPEAKER
 1.41 08-Dec-2016  nat Add a synthesized pc beeper and keyboard bell for platforms with an audio
device.
 1.40 26-Nov-2016  christos mention PAX_SEGVGUARD dependency on FILEASSOC
 1.39 11-Oct-2016  ozaki-r Add IFA_STATS to ALLs
 1.38 07-Aug-2016  christos rename ifmpls to mpls, so we don't have if_ifmpls...
 1.37 27-Jul-2016  msaitoh Add sdtemp(4)
 1.36 11-Jul-2016  msaitoh branches: 1.36.2;
Add gpioiic into amd64/conf/ALL
 1.35 08-May-2016  skrll More options
 1.34 01-May-2016  nonaka Added nvme(4) for Non-Volatile Memory Host Controller Interface devices.
Ported from OpenBSD.
 1.33 10-Nov-2015  tnn Add "pseudo-device iscsi" to ALL and as a commented out hint in XEN3_*
 1.32 25-Oct-2015  khorben Remove references to SPLASHSCREEN_PROGRESS

To my knowledge this feature is no longer supported at the moment. The
manual page for wsdisplay(4) should probably also be updated to reflect
this situation.
 1.31 26-Sep-2015  maxv Disable PAX_SEGVGUARD.

We actually have a big problem: the fileassocs are never deleted.
Therefore, if a user generates a lot of buggy binaries and launches them
all, the kernel will allocate memory again again and again for all these
entries and will never free them (unless the files are deleted from the
disk). Which means that a user can too easily put the kernel under memory
pressure.
 1.30 08-Aug-2015  maxv Remove KMEMSTATS.
 1.29 03-May-2015  pgoyette Update to include the tco driver (it was previously included as part of
ichlpcib).
 1.28 28-Apr-2015  rjs Add DCCP.
 1.27 06-Mar-2015  riastradh Fix tabbing of drm lines.
 1.26 06-Mar-2015  riastradh Fix commented nouveau in amd64/GENERIC. Add nouveau to amd64/ALL.

Remove NV_DEBUG from amd64/ALL -- it breaks nouveau, and I can't find
any use of it in src/sys outside arch/atari/dev/nvram.c, which surely
has no relevance to amd64.

(Nouveau has an internal NV_DEBUG(...) macro for debug messages.)
 1.25 13-Feb-2015  nonaka iwm(4) works now, but 2.4GHz only.

> iwm0 at pci2 dev 0 function 0: Intel Dual Band Wireless AC 3160 (rev. 0x83)
> iwm0: interrupting at ioapic0 pin 18
> iwm0: hw rev: 0x160, fw ver 25.228 (API ver 9), address XX:XX:XX:XX:XX:XX
> iwm0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
> iwm0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps
 1.24 19-Dec-2014  ozaki-r Add SOFTINT_INTR to ALL
 1.23 16-Nov-2014  manu branches: 1.23.2;
Remove unused extended attributes kernel options

As Masao Uebayashi pointed to me, UFS_EXTATTR_AUTOSTART, LFS_EXTATTR_AUTOSTART
and UFS_EXTATTR_AUTOCREATE are not used anywhere in the code. Remove them
as they have been obsolete for a long time:
UFS_EXTATTR_AUTOSTART was replaced by mount -o extattr
LFS_EXTATTR_AUTOSTART was created to match obsolete UFS_EXTATTR_AUTOSTART
UFS_EXTATTR_AUTOCREATE was replaced by sysctl vfs.ffs.extattr_autocreate
 1.22 02-Nov-2014  christos propagate drm changes
 1.21 18-Oct-2014  uebayasi Install agp_* drivers where pchb(4) is installed except INSTALL_FLOPPY.

XXX
Config around agp(4) is done in quite wrong direction.
"pchb <- (agpbus) <- agp <- agp_*"
should be:
"pchb <- (pcibus) <- agp_* <- (agpbus) <- agp"
 1.20 19-Sep-2014  christos Add HDAUDIOVERBOSE
 1.19 19-Sep-2014  christos Disable BSDLABEL and MBR DKWEDGE methods again since sysinst does not work
with wedges.
 1.18 24-Aug-2014  jnemeth Create an "options MODULAR_DEFAULT_AUTOLOAD" config option and add
it to all kernel configs that contain "options MODULAR". This
option turns on module autoloading by default (which is the current
default). This allows people who don't want module autoloading on
by default to disable it by simply removing/commentting this line.
 1.17 23-Aug-2014  dholland Add options COMPAT_44, which controls mostly MD code but should be in
here anyway.
 1.16 23-Aug-2014  dholland Systematize (and in many cases, fix) the comments on options COMPAT_NN.

There are quite a few configs that are missing some COMPAT_NN options
in ways that don't make sense; this should probably get cleaned up
too, but for the time being I've not added or removed anything.
 1.15 18-Aug-2014  christos branches: 1.15.2;
- Enable Wedge support for MBR/BSDLABEL where it was commented out.
- Add apple partition support where it was missing
- Add comments where missing
 1.14 16-Aug-2014  apb Add "options COMPAT_70" to all kernel configuration files that
already had "options COMPAT_60".
 1.13 25-Jul-2014  dholland branches: 1.13.2;
Fix description of DIAGNOSTIC in x86 kernels.
 1.12 02-Jul-2014  ozaki-r Add NET_MPSAFE to ALL
 1.11 29-Jun-2014  tsutsui Add gffb(4) at pci.
 1.10 24-Jun-2014  maxv Remove dead code. The kernel already checks for PT_INTERP sections, and puts
their content into "itp". There's no need for re-reading the whole binary and
trying to find this section again. Just use "itp".

DEBUG_FREEBSD_ELF is now unused, so remove its references in amd64/conf/ALL
and i386/conf/ALL.
 1.9 10-Jun-2014  hikaru Add VMware VMXNET3 ethernet driver from OpenBSD, vmx(4).
 1.8 02-Jun-2014  dholland add MPVERBOSE, noted missing in PR 48733.
 1.7 25-Apr-2014  riastradh branches: 1.7.2; 1.7.4;
Add applesmc(4) to {i386,amd64}/ALL.
 1.6 21-Apr-2014  chs add malo at pcmcia.
 1.5 08-Apr-2014  riastradh Remove FFS_NO_SNAPSHOT from x86/ALL so we do compile the snapshot code.
 1.4 08-Apr-2014  riastradh Add COMPAT_NETBSD32 and COMPAT_LINUX32 to amd64/ALL.
 1.3 08-Apr-2014  christos add ixg
 1.2 24-Mar-2014  szptvlfn branches: 1.2.2;
fix manual section numbering of sysctl.
thanks wiz@
 1.1 20-Mar-2014  christos First attempt at an ALL kernel based on the i386 one
 1.2.2.1 10-Aug-2014  tls Rebase.
 1.7.4.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.7.4.1 25-Apr-2014  yamt file ALL was added on branch yamt-pagecache on 2014-05-22 11:39:28 +0000
 1.7.2.2 18-May-2014  rmind sync with head
 1.7.2.1 25-Apr-2014  rmind file ALL was added on branch rmind-smpnet on 2014-05-18 17:44:54 +0000
 1.13.2.5 05-Apr-2017  snj Pull up following revision(s) (requested by skrll in ticket #1395):
share/man/man4/axe.4: netbsd-7-nhusb
share/man/man4/axen.4: netbsd-7-nhusb
share/man/man4/cdce.4: netbsd-7-nhusb
share/man/man4/uaudio.4: netbsd-7-nhusb
share/man/man4/ucom.4: netbsd-7-nhusb
share/man/man4/uep.4: netbsd-7-nhusb
share/man/man4/urtw.4: netbsd-7-nhusb
share/man/man4/usb.4: netbsd-7-nhusb
share/man/man4/uyap.4: netbsd-7-nhusb
share/man/man4/xhci.4: netbsd-7-nhusb
share/man/man9/usbdi.9: netbsd-7-nhusb
sys/arch/amd64/conf/ALL: netbsd-7-nhusb
sys/arch/amd64/conf/GENERIC: netbsd-7-nhusb
sys/arch/amiga/dev/slhci_zbus.c: netbsd-7-nhusb
sys/arch/arm/allwinner/awin_otg.c: netbsd-7-nhusb
sys/arch/arm/allwinner/awin_usb.c: netbsd-7-nhusb
sys/arch/arm/amlogic/amlogic_dwctwo.c: netbsd-7-nhusb
sys/arch/arm/at91/at91ohci.c: netbsd-7-nhusb
sys/arch/arm/broadcom/bcm2835_dwctwo.c: netbsd-7-nhusb
sys/arch/arm/broadcom/bcm53xx_usb.c: netbsd-7-nhusb
sys/arch/arm/ep93xx/epohci.c: netbsd-7-nhusb
sys/arch/arm/gemini/obio_ehci.c: netbsd-7-nhusb
sys/arch/arm/imx/files.imx23: netbsd-7-nhusb
sys/arch/arm/imx/imxusb.c: netbsd-7-nhusb
sys/arch/arm/imx/imxusbreg.h: netbsd-7-nhusb
sys/arch/arm/omap/obio_ohci.c: netbsd-7-nhusb
sys/arch/arm/omap/omap3_ehci.c: netbsd-7-nhusb
sys/arch/arm/omap/omapl1x_ohci.c: netbsd-7-nhusb
sys/arch/arm/omap/tiotg.c: netbsd-7-nhusb
sys/arch/arm/s3c2xx0/ohci_s3c24x0.c: netbsd-7-nhusb
sys/arch/arm/samsung/exynos_usb.c: netbsd-7-nhusb
sys/arch/arm/xscale/pxa2x0_ohci.c: netbsd-7-nhusb
sys/arch/arm/zynq/zynq_usb.c: netbsd-7-nhusb
sys/arch/hpcarm/dev/nbp_slhci.c: netbsd-7-nhusb
sys/arch/hpcmips/dev/plumohci.c: netbsd-7-nhusb
sys/arch/i386/conf/ALL: netbsd-7-nhusb
sys/arch/i386/conf/GENERIC: netbsd-7-nhusb
sys/arch/i386/pci/gcscehci.c: netbsd-7-nhusb
sys/arch/luna68k/conf/GENERIC: netbsd-7-nhusb
sys/arch/mips/adm5120/dev/ahci.c: netbsd-7-nhusb
sys/arch/mips/adm5120/dev/ahcivar.h: netbsd-7-nhusb
sys/arch/mips/alchemy/dev/ohci_aubus.c: netbsd-7-nhusb
sys/arch/mips/atheros/dev/ehci_arbus.c: netbsd-7-nhusb
sys/arch/mips/atheros/dev/ohci_arbus.c: netbsd-7-nhusb
sys/arch/mips/conf/files.adm5120: netbsd-7-nhusb
sys/arch/mips/ralink/ralink_ehci.c: netbsd-7-nhusb
sys/arch/mips/ralink/ralink_ohci.c: netbsd-7-nhusb
sys/arch/mips/rmi/rmixl_ehci.c: netbsd-7-nhusb
sys/arch/mips/rmi/rmixl_ohci.c: netbsd-7-nhusb
sys/arch/playstation2/dev/ohci_sbus.c: netbsd-7-nhusb
sys/arch/powerpc/booke/dev/pq3ehci.c: netbsd-7-nhusb
sys/arch/powerpc/ibm4xx/dev/dwctwo_plb.c: netbsd-7-nhusb
sys/arch/x68k/dev/slhci_intio.c: netbsd-7-nhusb
sys/conf/files: netbsd-7-nhusb
sys/dev/cardbus/ehci_cardbus.c: netbsd-7-nhusb
sys/dev/cardbus/ohci_cardbus.c: netbsd-7-nhusb
sys/dev/cardbus/uhci_cardbus.c: netbsd-7-nhusb
sys/dev/ic/sl811hs.c: netbsd-7-nhusb
sys/dev/ic/sl811hsvar.h: netbsd-7-nhusb
sys/dev/isa/slhci_isa.c: netbsd-7-nhusb
sys/dev/marvell/ehci_mv.c: netbsd-7-nhusb
sys/dev/pci/ehci_pci.c: netbsd-7-nhusb
sys/dev/pci/ohci_pci.c: netbsd-7-nhusb
sys/dev/pci/uhci_pci.c: netbsd-7-nhusb
sys/dev/pci/xhci_pci.c: netbsd-7-nhusb
sys/dev/pcmcia/slhci_pcmcia.c: netbsd-7-nhusb
sys/dev/usb/Makefile.usbdevs: netbsd-7-nhusb
sys/dev/usb/TODO: netbsd-7-nhusb
sys/dev/usb/TODO.usbmp: netbsd-7-nhusb
sys/dev/usb/aubtfwl.c: netbsd-7-nhusb
sys/dev/usb/auvitek.c: netbsd-7-nhusb
sys/dev/usb/auvitek_audio.c: netbsd-7-nhusb
sys/dev/usb/auvitek_dtv.c: netbsd-7-nhusb
sys/dev/usb/auvitek_i2c.c: netbsd-7-nhusb
sys/dev/usb/auvitek_video.c: netbsd-7-nhusb
sys/dev/usb/auvitekvar.h: netbsd-7-nhusb
sys/dev/usb/ehci.c: netbsd-7-nhusb
sys/dev/usb/ehcireg.h: netbsd-7-nhusb
sys/dev/usb/ehcivar.h: netbsd-7-nhusb
sys/dev/usb/emdtv.c: netbsd-7-nhusb
sys/dev/usb/emdtv_dtv.c: netbsd-7-nhusb
sys/dev/usb/emdtv_ir.c: netbsd-7-nhusb
sys/dev/usb/emdtvvar.h: netbsd-7-nhusb
sys/dev/usb/ezload.c: netbsd-7-nhusb
sys/dev/usb/ezload.h: netbsd-7-nhusb
sys/dev/usb/files.usb: netbsd-7-nhusb
sys/dev/usb/hid.c: netbsd-7-nhusb
sys/dev/usb/hid.h: netbsd-7-nhusb
sys/dev/usb/if_athn_usb.c: netbsd-7-nhusb
sys/dev/usb/if_athn_usb.h: netbsd-7-nhusb
sys/dev/usb/if_atu.c: netbsd-7-nhusb
sys/dev/usb/if_atureg.h: netbsd-7-nhusb
sys/dev/usb/if_aue.c: netbsd-7-nhusb
sys/dev/usb/if_auereg.h: netbsd-7-nhusb
sys/dev/usb/if_axe.c: netbsd-7-nhusb
sys/dev/usb/if_axen.c: netbsd-7-nhusb
sys/dev/usb/if_axenreg.h: netbsd-7-nhusb
sys/dev/usb/if_axereg.h: netbsd-7-nhusb
sys/dev/usb/if_cdce.c: netbsd-7-nhusb
sys/dev/usb/if_cdcereg.h: netbsd-7-nhusb
sys/dev/usb/if_cue.c: netbsd-7-nhusb
sys/dev/usb/if_cuereg.h: netbsd-7-nhusb
sys/dev/usb/if_kue.c: netbsd-7-nhusb
sys/dev/usb/if_kuereg.h: netbsd-7-nhusb
sys/dev/usb/if_otus.c: netbsd-7-nhusb
sys/dev/usb/if_otusvar.h: netbsd-7-nhusb
sys/dev/usb/if_rum.c: netbsd-7-nhusb
sys/dev/usb/if_rumreg.h: netbsd-7-nhusb
sys/dev/usb/if_rumvar.h: netbsd-7-nhusb
sys/dev/usb/if_run.c: netbsd-7-nhusb
sys/dev/usb/if_runvar.h: netbsd-7-nhusb
sys/dev/usb/if_smsc.c: netbsd-7-nhusb
sys/dev/usb/if_smscreg.h: netbsd-7-nhusb
sys/dev/usb/if_smscvar.h: netbsd-7-nhusb
sys/dev/usb/if_udav.c: netbsd-7-nhusb
sys/dev/usb/if_udavreg.h: netbsd-7-nhusb
sys/dev/usb/if_upgt.c: netbsd-7-nhusb
sys/dev/usb/if_upgtvar.h: netbsd-7-nhusb
sys/dev/usb/if_upl.c: netbsd-7-nhusb
sys/dev/usb/if_ural.c: netbsd-7-nhusb
sys/dev/usb/if_uralreg.h: netbsd-7-nhusb
sys/dev/usb/if_uralvar.h: netbsd-7-nhusb
sys/dev/usb/if_url.c: netbsd-7-nhusb
sys/dev/usb/if_urlreg.h: netbsd-7-nhusb
sys/dev/usb/if_urndis.c: netbsd-7-nhusb
sys/dev/usb/if_urndisreg.h: netbsd-7-nhusb
sys/dev/usb/if_urtw.c: netbsd-7-nhusb
sys/dev/usb/if_urtwn.c: netbsd-7-nhusb
sys/dev/usb/if_urtwn_data.h: netbsd-7-nhusb
sys/dev/usb/if_urtwnreg.h: netbsd-7-nhusb
sys/dev/usb/if_urtwnvar.h: netbsd-7-nhusb
sys/dev/usb/if_urtwreg.h: netbsd-7-nhusb
sys/dev/usb/if_zyd.c: netbsd-7-nhusb
sys/dev/usb/if_zydreg.h: netbsd-7-nhusb
sys/dev/usb/irmce.c: netbsd-7-nhusb
sys/dev/usb/moscom.c: netbsd-7-nhusb
sys/dev/usb/motg.c: netbsd-7-nhusb
sys/dev/usb/motgvar.h: netbsd-7-nhusb
sys/dev/usb/ohci.c: netbsd-7-nhusb
sys/dev/usb/ohcireg.h: netbsd-7-nhusb
sys/dev/usb/ohcivar.h: netbsd-7-nhusb
sys/dev/usb/pseye.c: netbsd-7-nhusb
sys/dev/usb/slurm.c: netbsd-7-nhusb
sys/dev/usb/stuirda.c: netbsd-7-nhusb
sys/dev/usb/u3g.c: netbsd-7-nhusb
sys/dev/usb/uark.c: netbsd-7-nhusb
sys/dev/usb/uatp.c: netbsd-7-nhusb
sys/dev/usb/uaudio.c: netbsd-7-nhusb
sys/dev/usb/uberry.c: netbsd-7-nhusb
sys/dev/usb/ubsa.c: netbsd-7-nhusb
sys/dev/usb/ubsa_common.c: netbsd-7-nhusb
sys/dev/usb/ubsavar.h: netbsd-7-nhusb
sys/dev/usb/ubt.c: netbsd-7-nhusb
sys/dev/usb/uchcom.c: netbsd-7-nhusb
sys/dev/usb/ucom.c: netbsd-7-nhusb
sys/dev/usb/ucomvar.h: netbsd-7-nhusb
sys/dev/usb/ucycom.c: netbsd-7-nhusb
sys/dev/usb/udl.c: netbsd-7-nhusb
sys/dev/usb/udl.h: netbsd-7-nhusb
sys/dev/usb/udsbr.c: netbsd-7-nhusb
sys/dev/usb/udsir.c: netbsd-7-nhusb
sys/dev/usb/uep.c: netbsd-7-nhusb
sys/dev/usb/uftdi.c: netbsd-7-nhusb
sys/dev/usb/uftdireg.h: netbsd-7-nhusb
sys/dev/usb/ugen.c: netbsd-7-nhusb
sys/dev/usb/ugensa.c: netbsd-7-nhusb
sys/dev/usb/uhci.c: netbsd-7-nhusb
sys/dev/usb/uhcireg.h: netbsd-7-nhusb
sys/dev/usb/uhcivar.h: netbsd-7-nhusb
sys/dev/usb/uhid.c: netbsd-7-nhusb
sys/dev/usb/uhidev.c: netbsd-7-nhusb
sys/dev/usb/uhidev.h: netbsd-7-nhusb
sys/dev/usb/uhmodem.c: netbsd-7-nhusb
sys/dev/usb/uhso.c: netbsd-7-nhusb
sys/dev/usb/uhub.c: netbsd-7-nhusb
sys/dev/usb/uipad.c: netbsd-7-nhusb
sys/dev/usb/uipaq.c: netbsd-7-nhusb
sys/dev/usb/uirda.c: netbsd-7-nhusb
sys/dev/usb/uirdavar.h: netbsd-7-nhusb
sys/dev/usb/ukbd.c: netbsd-7-nhusb
sys/dev/usb/ukbdmap.c: netbsd-7-nhusb
sys/dev/usb/ukyopon.c: netbsd-7-nhusb
sys/dev/usb/ukyopon.h: netbsd-7-nhusb
sys/dev/usb/ulpt.c: netbsd-7-nhusb
sys/dev/usb/umass.c: netbsd-7-nhusb
sys/dev/usb/umass_isdata.c: netbsd-7-nhusb
sys/dev/usb/umass_isdata.h: netbsd-7-nhusb
sys/dev/usb/umass_quirks.c: netbsd-7-nhusb
sys/dev/usb/umass_quirks.h: netbsd-7-nhusb
sys/dev/usb/umass_scsipi.c: netbsd-7-nhusb
sys/dev/usb/umass_scsipi.h: netbsd-7-nhusb
sys/dev/usb/umassvar.h: netbsd-7-nhusb
sys/dev/usb/umcs.c: netbsd-7-nhusb
sys/dev/usb/umct.c: netbsd-7-nhusb
sys/dev/usb/umidi.c: netbsd-7-nhusb
sys/dev/usb/umidi_quirks.c: netbsd-7-nhusb
sys/dev/usb/umidi_quirks.h: netbsd-7-nhusb
sys/dev/usb/umodem.c: netbsd-7-nhusb
sys/dev/usb/umodem_common.c: netbsd-7-nhusb
sys/dev/usb/umodemvar.h: netbsd-7-nhusb
sys/dev/usb/ums.c: netbsd-7-nhusb
sys/dev/usb/uplcom.c: netbsd-7-nhusb
sys/dev/usb/urio.c: netbsd-7-nhusb
sys/dev/usb/urio.h: netbsd-7-nhusb
sys/dev/usb/usb.c: netbsd-7-nhusb
sys/dev/usb/usb.h: netbsd-7-nhusb
sys/dev/usb/usb_mem.c: netbsd-7-nhusb
sys/dev/usb/usb_mem.h: netbsd-7-nhusb
sys/dev/usb/usb_quirks.c: netbsd-7-nhusb
sys/dev/usb/usb_quirks.h: netbsd-7-nhusb
sys/dev/usb/usb_subr.c: netbsd-7-nhusb
sys/dev/usb/usbdevices.config: netbsd-7-nhusb
sys/dev/usb/usbdevs: netbsd-7-nhusb
sys/dev/usb/usbdevs.h: netbsd-7-nhusb
sys/dev/usb/usbdevs_data.h: netbsd-7-nhusb
sys/dev/usb/usbdi.c: netbsd-7-nhusb
sys/dev/usb/usbdi.h: netbsd-7-nhusb
sys/dev/usb/usbdi_util.c: netbsd-7-nhusb
sys/dev/usb/usbdi_util.h: netbsd-7-nhusb
sys/dev/usb/usbdivar.h: netbsd-7-nhusb
sys/dev/usb/usbhid.h: netbsd-7-nhusb
sys/dev/usb/usbhist.h: netbsd-7-nhusb
sys/dev/usb/usbroothub.c: netbsd-7-nhusb
sys/dev/usb/usbroothub.h: netbsd-7-nhusb
sys/dev/usb/usbroothub_subr.c: delete
sys/dev/usb/usbroothub_subr.h: delete
sys/dev/usb/uscanner.c: netbsd-7-nhusb
sys/dev/usb/uslsa.c: netbsd-7-nhusb
sys/dev/usb/usscanner.c: netbsd-7-nhusb
sys/dev/usb/ustir.c: netbsd-7-nhusb
sys/dev/usb/uthum.c: netbsd-7-nhusb
sys/dev/usb/utoppy.c: netbsd-7-nhusb
sys/dev/usb/uts.c: netbsd-7-nhusb
sys/dev/usb/uvideo.c: netbsd-7-nhusb
sys/dev/usb/uvisor.c: netbsd-7-nhusb
sys/dev/usb/uvscom.c: netbsd-7-nhusb
sys/dev/usb/uyap.c: netbsd-7-nhusb
sys/dev/usb/uyap_firmware.h: netbsd-7-nhusb
sys/dev/usb/uyurex.c: netbsd-7-nhusb
sys/dev/usb/x1input_rdesc.h: netbsd-7-nhusb
sys/dev/usb/xhci.c: netbsd-7-nhusb
sys/dev/usb/xhcireg.h: netbsd-7-nhusb
sys/dev/usb/xhcivar.h: netbsd-7-nhusb
sys/dev/usb/xinput_rdesc.h: netbsd-7-nhusb
sys/external/bsd/common/conf/files.linux: netbsd-7-nhusb
sys/external/bsd/common/include/linux/err.h: netbsd-7-nhusb
sys/external/bsd/common/include/linux/kernel.h: netbsd-7-nhusb
sys/external/bsd/common/include/linux/workqueue.h: netbsd-7-nhusb
sys/external/bsd/common/linux/linux_work.c: netbsd-7-nhusb
sys/external/bsd/drm2/dist/drm/radeon/atombios_encoders.c: netbsd-7-nhusb
sys/external/bsd/drm2/dist/drm/radeon/radeon_legacy_encoders.c: netbsd-7-nhusb
sys/external/bsd/drm2/drm/files.drmkms: netbsd-7-nhusb
sys/external/bsd/drm2/i915drm/files.i915drmkms: netbsd-7-nhusb
sys/external/bsd/drm2/include/linux/err.h: delete
sys/external/bsd/drm2/include/linux/workqueue.h: delete
sys/external/bsd/drm2/linux/files.drmkms_linux: netbsd-7-nhusb
sys/external/bsd/drm2/linux/linux_work.c: delete
sys/external/bsd/dwc2/dwc2.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dwc2.h: netbsd-7-nhusb
sys/external/bsd/dwc2/dwc2var.h: netbsd-7-nhusb
sys/external/bsd/dwc2/dwctwo2netbsd: netbsd-7-nhusb
sys/external/bsd/dwc2/conf/files.dwc2: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_core.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_core.h: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_coreintr.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hcd.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hcd.h: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hcdddma.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hcdintr.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hcdqueue.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hw.h: netbsd-7-nhusb
sys/modules/drmkms_linux/Makefile: netbsd-7-nhusb
sys/modules/i915drmkms/Makefile: netbsd-7-nhusb
sys/rump/dev/lib/libugenhc/ugenhc.c: netbsd-7-nhusb
sys/rump/dev/lib/libusb/Makefile: netbsd-7-nhusb
sys/rump/dev/lib/libusb/USB.ioconf: netbsd-7-nhusb
sys/rump/dev/lib/libusb/usb_at_ugenhc.c: delete
sys/rump/dev/lib/libusb/opt/opt_usb.h: delete
sys/rump/dev/lib/libusb/opt/opt_usbverbose.h: delete
sys/sys/mbuf.h: netbsd-7-nhusb
usr.sbin/usbdevs/usbdevs.8: netbsd-7-nhusb
usr.sbin/usbdevs/usbdevs.c: netbsd-7-nhusb
Merge netbsd-7-nhusb:
- API / infrastructure changes to support memory management changes.
- Memory management improvements and bug fixes.
- HCDs should now be MP safe
- conversion to KERNHIST based debug
- FS/LS isoc support on ehci(4).
- conversion to kmem(9)
- Some USB 3 support - mostly from Takahiro HAYASHI (t-hash).
- interrupt transfers now get proper DMA operations
- general bug fixes
- kern/48308
- uhub status notification improvements
- umass(4) probe fix (applied to HEAD already)
- ohci(4) short transfer fix
- Change the SOFTINT level from NET to SERIAL for the USB softint handler.
This gives the callback a chance of running when another softint handler
at SOFTINT_NET has blocked holding a lock, e.g. softnet_lock and most of
the network stack.
- kern/49065 - ifconfig tun0 ... sequence locks up system / lockup:
softnet_lock held across usb xfr
- kern/50491 - unkillable wait in usbd_transfer while using usmsc0
on raspberry pi 2
- kern/51395 - USB Ethernet makes xhci hang
- Various improvements to slhci(4)
- Various improvements to dwc2(4)
 1.13.2.4 09-Dec-2016  snj Pull up following revision(s) (requested by msaitoh in ticket #1297):
sys/arch/amd64/conf/ALL: revision 1.37
sys/arch/amd64/conf/GENERIC: revision 1.436
sys/arch/amd64/conf/XEN3_DOM0: revision 1.120
sys/arch/i386/conf/ALL: revision 1.400
sys/arch/i386/conf/GENERIC: revision 1.1138
sys/arch/i386/conf/XEN3_DOM0: revision 1.99
Add sdtemp(4)
--
Add ichsmb(4), spdmem(4) and sdtemp(4).
 1.13.2.3 15-May-2015  snj branches: 1.13.2.3.4;
Pull up following revision(s) (requested by jnemeth in ticket #762):
share/man/man4/options.4: revision 1.442
sys/arch/amd64/conf/ALL: revision 1.18
sys/arch/amd64/conf/GENERIC: revision 1.396
sys/arch/dreamcast/conf/GENERIC: revision 1.119
sys/arch/epoc32/conf/GENERIC: revision 1.6
sys/arch/evbarm/conf/BCM5301X: revision 1.24
sys/arch/evbarm/conf/BCM56340: revision 1.9
sys/arch/evbarm/conf/IMX23_OLINUXINO: revision 1.9
sys/arch/evbarm/conf/std.beagle: revision 1.13
sys/arch/evbarm/conf/std.kobo: revision 1.2
sys/arch/evbarm/conf/std.netwalker: revision 1.10
sys/arch/evbppc/conf/P2020DS: revision 1.25
sys/arch/evbppc/conf/RB800: revision 1.30
sys/arch/evbppc/conf/TWRP1025: revision 1.18
sys/arch/hp300/conf/GENERIC: revision 1.187
sys/arch/hpcsh/conf/GENERIC: revision 1.104
sys/arch/i386/conf/GENERIC: revision 1.1111
sys/arch/i386/conf/MONOLITHIC: revision 1.17
sys/arch/landisk/conf/GENERIC: revision 1.43
sys/arch/luna68k/conf/GENERIC: revision 1.117
sys/arch/macppc/conf/GENERIC: revision 1.316
sys/arch/macppc/conf/GENERIC_601: revision 1.5
sys/arch/mmeye/conf/MMEYE_WLF: revision 1.16
sys/arch/news68k/conf/GENERIC: revision 1.123
sys/arch/sandpoint/conf/GENERIC: revision 1.85
sys/arch/shark/conf/GENERIC: revision 1.119
sys/arch/sparc/conf/GENERIC: revision 1.246
sys/arch/sparc64/conf/GENERIC: revision 1.174
sys/arch/sun3/conf/GENERIC3X: revision 1.125
sys/arch/sun3/conf/GENERIC: revision 1.169
sys/arch/x68k/conf/GENERIC: revision 1.177
sys/arch/zaurus/conf/GENERIC: revision 1.62
sys/conf/files: revision 1.1099
sys/kern/kern_module.c: revisions 1.98, 1.99
Create an "options MODULAR_DEFAULT_AUTOLOAD" config option and add
it to all kernel configs that contain "options MODULAR". This
option turns on module autoloading by default (which is the current
default). This allows people who don't want module autoloading on
by default to disable it by simply removing/commentting this line.
--
fix typo. (s/MODULE_DEFAULT_AUTOLOAD/MODULAR_DEFAULT_AUTOLOAD/)
 1.13.2.2 18-Mar-2015  snj Apply patch (requested by christos in ticket #542):
- Enable intel and radeon DRM/KMS drivers in GENERIC
- Disable all of the old DRM drivers in GENERIC
- Remove the separate DRMKMS kernel
 1.13.2.1 18-Nov-2014  snj Pull up following revision(s) (requested by manu in ticket #251):
sys/arch/acorn26/conf/GENERIC: revision 1.81
sys/arch/acorn32/conf/GENERIC: revision 1.116
sys/arch/alpha/conf/GENERIC: revision 1.362
sys/arch/amd64/conf/ALL: revision 1.23
sys/arch/amd64/conf/GENERIC: revision 1.404
sys/arch/amd64/conf/XEN3_DOM0: revision 1.112
sys/arch/amd64/conf/XEN3_DOMU: revision 1.60
sys/arch/amiga/conf/GENERIC.in: revision 1.129
sys/arch/amiga/conf/GENERIC: revision 1.311
sys/arch/amigappc/conf/GENERIC: revision 1.24
sys/arch/arc/conf/GENERIC: revision 1.184
sys/arch/bebox/conf/GENERIC: revision 1.145
sys/arch/cats/conf/GENERIC: revision 1.155
sys/arch/cesfic/conf/GENERIC: revision 1.65
sys/arch/cobalt/conf/GENERIC: revision 1.147
sys/arch/dreamcast/conf/GENERIC: revision 1.121
sys/arch/emips/conf/GENERIC: revision 1.15
sys/arch/epoc32/conf/GENERIC: revision 1.8
sys/arch/ews4800mips/conf/GENERIC: revision 1.51
sys/arch/hp300/conf/GENERIC: revision 1.190
sys/arch/hpcmips/conf/GENERIC: revision 1.229
sys/arch/hpcsh/conf/GENERIC: revision 1.106
sys/arch/hppa/conf/GENERIC: revision 1.6
sys/arch/i386/conf/ALL: revision 1.389
sys/arch/i386/conf/GENERIC: revision 1.1118
sys/arch/i386/conf/XEN3_DOM0: revision 1.93
sys/arch/i386/conf/XEN3_DOMU: revision 1.65
sys/arch/ibmnws/conf/GENERIC: revision 1.46
sys/arch/iyonix/conf/GENERIC: revision 1.88
sys/arch/landisk/conf/GENERIC: revision 1.45
sys/arch/luna68k/conf/GENERIC: revision 1.119
sys/arch/mac68k/conf/GENERIC: revision 1.220
sys/arch/macppc/conf/GENERIC: revision 1.320
sys/arch/macppc/conf/MAMBO: revision 1.24
sys/arch/macppc/conf/POWERMAC_G5: revision 1.25
sys/arch/mipsco/conf/GENERIC: revision 1.88
sys/arch/mmeye/conf/GENERIC: revision 1.120
sys/arch/mvme68k/conf/GENERIC: revision 1.94
sys/arch/mvmeppc/conf/GENERIC: revision 1.24
sys/arch/netwinder/conf/GENERIC: revision 1.126
sys/arch/news68k/conf/GENERIC: revision 1.125
sys/arch/newsmips/conf/GENERIC: revision 1.129
sys/arch/next68k/conf/GENERIC: revision 1.139
sys/arch/ofppc/conf/GENERIC: revision 1.157
sys/arch/pmax/conf/GENERIC64: revision 1.21
sys/arch/pmax/conf/GENERIC: revision 1.185
sys/arch/prep/conf/GENERIC: revision 1.174
sys/arch/rs6000/conf/GENERIC: revision 1.33
sys/arch/sandpoint/conf/GENERIC: revision 1.88
sys/arch/sbmips/conf/GENERIC: revision 1.101
sys/arch/sgimips/conf/GENERIC32_IP12: revision 1.28
sys/arch/sgimips/conf/GENERIC32_IP2x: revision 1.104
sys/arch/sgimips/conf/GENERIC32_IP3x: revision 1.106
sys/arch/shark/conf/GENERIC: revision 1.121
sys/arch/sparc/conf/GENERIC: revision 1.248
sys/arch/sparc/conf/TADPOLE3GX: revision 1.65
sys/arch/sparc64/conf/GENERIC: revision 1.177
sys/arch/sparc64/conf/NONPLUS64: revision 1.44
sys/arch/sun2/conf/GENERIC: revision 1.94
sys/arch/sun3/conf/GENERIC: revision 1.171
sys/arch/vax/conf/GENERIC: revision 1.193
sys/arch/vax/conf/VAX780: revision 1.19
sys/arch/x68k/conf/GENERIC: revision 1.179
sys/arch/zaurus/conf/GENERIC: revision 1.65
sys/ufs/files.ufs: revision 1.38
Remove unused extended attributes kernel options

As Masao Uebayashi pointed to me, UFS_EXTATTR_AUTOSTART, LFS_EXTATTR_AUTOSTART
and UFS_EXTATTR_AUTOCREATE are not used anywhere in the code. Remove them
as they have been obsolete for a long time:
UFS_EXTATTR_AUTOSTART was replaced by mount -o extattr
LFS_EXTATTR_AUTOSTART was created to match obsolete UFS_EXTATTR_AUTOSTART
UFS_EXTATTR_AUTOCREATE was replaced by sysctl vfs.ffs.extattr_autocreate
 1.13.2.3.4.1 18-Jan-2017  skrll Sync with netbsd-5
 1.15.2.3 03-Dec-2017  jdolecek update from HEAD
 1.15.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.15.2.1 18-Aug-2014  tls file ALL was added on branch tls-maxphys on 2014-08-20 00:02:42 +0000
 1.23.2.9 28-Aug-2017  skrll Sync with HEAD
 1.23.2.8 05-Feb-2017  skrll Sync with HEAD
 1.23.2.7 05-Dec-2016  skrll Sync with HEAD
 1.23.2.6 05-Oct-2016  skrll Sync with HEAD
 1.23.2.5 29-May-2016  skrll Sync with HEAD
 1.23.2.4 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.23.2.3 22-Sep-2015  skrll Sync with HEAD
 1.23.2.2 06-Jun-2015  skrll Sync with HEAD
 1.23.2.1 06-Apr-2015  skrll Sync with HEAD
 1.36.2.5 26-Apr-2017  pgoyette Sync with HEAD
 1.36.2.4 20-Mar-2017  pgoyette Sync with HEAD
 1.36.2.3 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.36.2.2 04-Nov-2016  pgoyette Sync with HEAD
 1.36.2.1 06-Aug-2016  pgoyette Sync with HEAD
 1.49.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.56.2.1 02-May-2017  pgoyette Sync with HEAD - tag prg-localcount2-base1
 1.59.2.6 07-Dec-2018  martin Pull up following revision(s) (requested by bouyer in ticket #1129):

sys/arch/amd64/conf/XEN3_DOM0: revision 1.159
sys/arch/amd64/conf/GENERIC: revision 1.508
sys/arch/i386/conf/ALL: revision 1.458
sys/dev/ic/mfi.c: revision 1.60
sys/dev/pci/mpiireg.h: revision 1.1
distrib/sets/lists/man/mi: revision 1.1628
sys/dev/pci/mfii.c: revision 1.1,1.2 (adapted)
sys/arch/i386/conf/GENERIC: revision 1.1194
sys/dev/pci/mpii.c: revision 1.13
sys/dev/ic/mfireg.h: revision 1.9
share/man/man4/mfii.4: revision 1.1
share/man/man4/Makefile: revision 1.673 (patch)
sys/dev/pci/files.pci: revision 1.410
share/man/man4/mfii.4: revision 1.2
sys/arch/amd64/conf/ALL: revision 1.108
sys/arch/i386/conf/XEN3PAE_DOM0: revision 1.8 (patch, in XEN3_DOM0)

Add some definitions from OpenBSD, needed by the upcoming mfii driver.
No functionnal change.

-

Move registers definitions to a separate file, needed for the upcomning mpii
driver. No functionnal change.

-

Add mpii(4), a driver for LSI Megaraid Fusion controllers.
Ported from OpenBSD. This driver is MP-safe.

Note that the earlier fusion controllers (Megaraid 2208, codenamed Thunderbold)
are also supported by mfi(4). mpii will take precedence if both drivers
are enabled.

Tested on a
mfii0 at pci6 dev 0 function 0: "PERC H740P Adapter ", firmware 50.3.0-1512, 819
2MB cache
mfii0: interrupting at ioapic2 pin 2
scsibus0 at mfii0: 64 targets, 8 luns per target
scsibus0: waiting 2 seconds for devices to settle...
sd0 at scsibus0 target 0 lun 0: <DELL, PERC H740P Adp, 5.03> disk fixed
sd0: fabricating a geometry
sd0: 99 GB, 102399 cyl, 64 head, 32 sec, 512 bytes/sect x 209714688 sectors
sd0: tagged queueing
sd1 at scsibus0 target 1 lun 0: <DELL, PERC H740P Adp, 5.03> disk fixed
sd1: fabricating a geometry
sd1: 22254 GB, 22788608 cyl, 64 head, 32 sec, 512 bytes/sect x 46671069696 sectors
sd1: fabricating a geometry

It supports bioctl(8) ioctls, as well as sensors for the BBU and logical
drives.

Sponsored by LIP6.

-

Add my name in copyright list

-

add a man page for the new mpii, mostly from OpenBSD.

-

Sort SEE ALSO. Fix date. Whitespace fixes.
 1.59.2.5 11-Apr-2018  martin Pull up following revision(s) (requested by mrg in ticket #731):
sys/arch/i386/conf/files.i386: revision 1.392
sys/arch/i386/conf/GENERIC: revision 1.1175
sys/arch/i386/conf/GENERIC: revision 1.1176
sys/arch/amd64/conf/files.amd64: revision 1.102
sys/arch/i386/conf/GENERIC: revision 1.1177
share/man/man4/options.4: revision 1.485 (patch)
sys/arch/i386/conf/Makefile.i386: revision 1.190
sys/arch/amd64/conf/GENERIC: revision 1.487
sys/arch/amd64/conf/ALL: revision 1.85
sys/arch/amd64/conf/GENERIC: revision 1.488
sys/arch/amd64/conf/GENERIC: revision 1.489
sys/arch/amd64/conf/Makefile.amd64: revision 1.67
sys/arch/i386/conf/ALL: revision 1.437

add an SPECTRE_V2_GCC_MITIGATION option to x86 kernels, that turns
on the GCC spectre v2 mitigation options.
XXX: pullup-8.
XXX: turn on in all kernels.

actually do what the previous change said:
don't turn on the new 'SPECTRE_V2_GCC_MITIGATION' option yet.

turn on GCC spectre v2 mitigation options.
XXX: amd64 ALL doesn't build for me right now
 1.59.2.4 09-Apr-2018  bouyer Pull up following revision(s) (requested by spz in ticket #708):
sys/conf/files: revision 1.1194
sys/dev/ic/cissvar.h: revision 1.7
sys/dev/ic/ciss.c: revision 1.38
sys/dev/pci/ciss_pci.c: revision 1.14
sys/arch/amd64/conf/ALL: revision 1.81
Add a new option CISS_NO_INTERRUPT_HACK for driving ciss(4) by callouts.
This is intended as workaround for certain Xen issues with dom0 kernels
and will likely want to have a high HZ value as well for decent
performance.
 1.59.2.3 11-Feb-2018  snj Pull up following revision(s) (requested by ozaki-r in ticket #536):
distrib/sets/lists/base/shl.mi: 1.825
distrib/sets/lists/comp/mi: 1.2168-1.2169
distrib/sets/lists/comp/shl.mi: 1.310
distrib/sets/lists/debug/mi: 1.234
distrib/sets/lists/debug/shl.mi: 1.188
distrib/sets/lists/man/mi: 1.1570
distrib/sets/lists/tests/mi: 1.772
etc/mtree/NetBSD.dist.tests: 1.150
share/man/man4/Makefile: 1.650
share/man/man4/ipsec.4: 1.42-1.43
share/man/man4/ipsecif.4: 1.1-1.5
sys/arch/amd64/conf/ALL: 1.77
sys/arch/amd64/conf/GENERIC: 1.480
sys/conf/files: 1.1191
sys/net/Makefile: 1.34
sys/net/files.net: 1.14
sys/net/if.c: 1.404
sys/net/if.h: 1.248
sys/net/if_gif.c: 1.135
sys/net/if_ipsec.c: 1.1-1.3
sys/net/if_ipsec.h: 1.1
sys/net/if_l2tp.c: 1.16
sys/net/if_types.h: 1.28
sys/netinet/in.c: 1.214
sys/netinet/in.h: 1.103
sys/netinet/in_gif.c: 1.92
sys/netinet/ip_var.h: 1.122
sys/netinet6/in6.c: 1.257
sys/netinet6/in6.h: 1.88
sys/netinet6/in6_gif.c: 1.90
sys/netinet6/ip6_var.h: 1.75
sys/netipsec/Makefile: 1.6
sys/netipsec/files.netipsec: 1.13
sys/netipsec/ipsec.h: 1.62
sys/netipsec/ipsecif.c: 1.1
sys/netipsec/ipsecif.h: 1.1
sys/netipsec/key.c: 1.246-1.247
sys/netipsec/key.h: 1.34
sys/rump/net/Makefile.rumpnetcomp: 1.20
sys/rump/net/lib/libipsec/IPSEC.ioconf: 1.1
sys/rump/net/lib/libipsec/Makefile: 1.1
sys/rump/net/lib/libipsec/ipsec_component.c: 1.1
tests/net/Makefile: 1.34
tests/net/if_ipsec/Makefile: 1.1
tests/net/if_ipsec/t_ipsec.sh: 1.1-1.2
Don't touch an SP without a reference to it
unify processing to check nesting count for some tunnel protocols.
add ipsec(4) interface, which is used for route-based VPN.
man and ATF are added later, please see man for details.
reviewed by christos@n.o, joerg@n.o and ozaki-r@n.o, thanks.
https://mail-index.netbsd.org/tech-net/2017/12/18/msg006557.html
ipsec(4) interface supports rump now.
add ipsec(4) interface ATF.
add ipsec(4) interface man as ipsecif.4.
add ipsec(4) interface to amd64/GENERIC and amd64/ALL configs.
apply in{,6}_tunnel_validate() to gif(4).
Spell IPsec that way. Simplify macro usage. Sort SEE ALSO. Bump
date for previous.
Improve wording and macro use.
Some parts are not clear to me, so someone with knowledge of ipsecif(4)
should improve this some more.
Improve ipsecif.4. Default port ipsec(4) NAT-T is tested now.
pointed out by wiz@n.o and suggested by ozaki-r@n.o, thanks.
Change the prefix of test names to ipsecif_ to distinguish from tests for ipsec(4)
New sentence, new line. Remove empty macro.
Fix PR kern/52920. Pointed out by David Binderman, thanks.
Improve wording, and put a new drawing, from me and Kengo Nakahara.
apply a little more #ifdef INET/INET6. fixes !INET6 builds.
 1.59.2.2 05-Feb-2018  martin Pull up following revision(s) (requested by pgoyette in ticket #524):

distrib/sets/lists/man/mi 1.1574
distrib/sets/lists/modules/md.amd64 1.73
distrib/sets/lists/modules/md.i386 1.76
share/man/man4/amdtemp.4 1.11
share/man/man4/man4.x86/Makefile 1.17
share/man/man4/man4.x86/amdsmn.4 1.1-1.3
share/man/man4/man4.x86/amdzentemp.4 1.1-1.6
sys/arch/amd64/conf/ALL 1.79,1.80
sys/arch/amd64/conf/GENERIC 1.482,1.484
sys/arch/amd64/conf/XEN3_DOM0 1.146,1.147
sys/arch/x86/pci/amdsmn.c 1.1-1.2
sys/arch/x86/pci/amdsmn.h 1.1
sys/arch/x86/pci/amdzentemp.c 1.1-1.7
sys/arch/x86/pci/files.pci 1.22,1.23
sys/modules/amdzentemp/amdzentemp.ioconf 1.2


Add amdzentemp from FreeBSD via Ian Clark.

man pages for amdsmn and amdzentemp.

Some clean-up on the HISTORY and AUTHORS sections, and addition of a BUGS
section to document the fact that we don't yet handle the required temp
offset, nor do we expose the available thermal-trip value.

Add missing article 'a'

KNF: Put back the blank line following the empty variable declarations
Put back the variable declaration, too, and mark it __diagused
Otherwise a DIAGNOSTIC kernel will complain about the variable being
undeclared.

Correct placement of __diagused attribute.

Modularize the amdsmn(4) driver, and update dependency for amdzentemp(4),
Create amdsmn(4) amd amdzentemp(4) modules for X86.
 1.59.2.1 09-Sep-2017  snj Pull up following revision(s) (requested by maxv in ticket #258):
sys/arch/amd64/conf/ALL: 1.68
sys/arch/i386/conf/ALL: 1.428
sys/arch/i386/i386/i386_trap.S: 1.12
sys/arch/i386/i386/locore.S: 1.149-1.150
sys/arch/x86/x86/sys_machdep.c: 1.38
Remove undocumented hack.
--
Switch to the temporary stack right away when booted via multiboot. GRUB
happens to give a correct stack, but it is not guaranteed by the spec. This
temporary stack will be reset later, which is fine.
Fixes PR/50245.
--
Pfff, use %ss and not %ds. The latter is controlled by userland, the former
contains the kernel value (flat); FreeBSD fixed this too a few weeks ago.
As I said earlier, this dtrace code is complete bullshit.
--
Don't allow userland to create 286/386 call gates anymore - they are not
used by Wine. While here, don't allow it to overwrite the static entries
either, don't allow unknown entry types, remove LDT_DEBUG, and style.
 1.82.2.12 18-Jan-2019  pgoyette Synch with HEAD
 1.82.2.11 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.82.2.10 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.82.2.9 30-Sep-2018  pgoyette Ssync with HEAD
 1.82.2.8 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.82.2.7 28-Jul-2018  pgoyette Sync with HEAD
 1.82.2.6 25-Jun-2018  pgoyette Sync with HEAD
 1.82.2.5 21-May-2018  pgoyette Sync with HEAD
 1.82.2.4 02-May-2018  pgoyette Synch with HEAD
 1.82.2.3 16-Apr-2018  pgoyette Sync with HEAD, resolve some conflicts
 1.82.2.2 30-Mar-2018  pgoyette Resolve conflicts between branch and HEAD
 1.82.2.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.90.2.4 21-Apr-2020  martin Sync with HEAD
 1.90.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.90.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.90.2.1 10-Jun-2019  christos Sync with HEAD
 1.120.2.4 07-Jul-2020  martin Pull up following revision(s) (requested by jmcneill in ticket #980):

sys/dev/pci/if_aq.c: revision 1.4
sys/dev/pci/if_aq.c: revision 1.5
sys/arch/amd64/conf/GENERIC: revision 1.553
sys/dev/pci/files.pci: revision 1.419
sys/arch/amd64/conf/XEN3_DOM0: revision 1.170
sys/dev/pci/if_aq.c: revision 1.9
share/man/man4/Makefile: revision 1.693
sys/dev/pci/pcidevs: revision 1.1411
share/man/man4/aq.4: revision 1.1
share/man/man4/aq.4: revision 1.3
sys/arch/i386/conf/ALL: revision 1.479
share/man/man4/aq.4: revision 1.4
sys/dev/pci/if_aq.c: revision 1.10
sys/dev/pci/files.pci: revision 1.421
sys/dev/pci/if_aq.c: revision 1.11
sys/dev/pci/if_aq.c: revision 1.12
sys/dev/pci/if_aq.c: revision 1.13
sys/dev/pci/if_aq.c: revision 1.14
sys/dev/pci/if_aq.c: revision 1.15
sys/dev/pci/if_aq.c: revision 1.16
sys/dev/pci/pcidevs: revision 1.1408
sys/arch/amd64/conf/ALL: revision 1.135
sys/net/ethertypes.h: revision 1.19
sys/arch/i386/conf/GENERIC: revision 1.1218
distrib/sets/lists/man/mi: revision 1.1668
sys/dev/pci/if_aq.c: revision 1.1
sys/dev/pci/if_aq.c: revision 1.2
sys/dev/pci/pcidevs: revision 1.1395
sys/dev/pci/if_aq.c: revision 1.3
sys/arch/evbarm/conf/GENERIC64: revision 1.125

Add the ETHERTYPE_QINQ for 802.1ad VLAN stacking

add Aquantia AQC 10G network adapters
add support Aquantia AQC seriese 10G network adapters.

this driver is based on the FreeBSD version https://github.com/Aquantia/aqtion-freebsd ,
but drastically rewritten for NetBSD.

add aq(4)

Add Aquantia AQC100, AQC100S and D100.

add support VLAN HW filter

set/clear IFF_OACTIVE flag only on txring 0

make counters per queue

support internal PHY temperature sensor

Found by kUBSan:
- Use unsigned to avoid undefined behavior in aq_hw_init().
- Cast to unsigned to avoid undefined behavior in aq_set_mac_addr().

fix descriptions of register map in comment

return the ifmedia active status correctly even while the link is not up after attach.
pointed out by msaitoh@. thanks.

On FIBRE devices, there are times when linkstat interrupt doesn't occur?
reported from Andrius V. thanks.
- use polling instead of linkstat interrupt when FIBRE
- add AQ_FORCE_POLL_LINKSTAT options (not by default)

sort product table, and tabify

add support AQC100S and D100.
not tested, but they are probably the same as the AQC100.
 1.120.2.3 25-Nov-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #478):

sys/dev/mii/smscphy.c: revision 1.1
sys/arch/amd64/conf/ALL: revision 1.127
sys/arch/amd64/conf/ALL: revision 1.128
sys/dev/mii/files.mii: revision 1.52
sys/dev/mii/files.mii: revision 1.53
sys/arch/i386/conf/ALL: revision 1.473
share/man/man4/mii.4: revision 1.29
sys/arch/i386/conf/ALL: revision 1.474
sys/arch/amd64/conf/GENERIC: revision 1.543
sys/arch/amd64/conf/GENERIC: revision 1.544
sys/dev/mii/jmphyreg.h: revision 1.1
share/man/man4/Makefile: revision 1.687
share/man/man4/smscphy.4: revision 1.1
share/man/man4/Makefile: revision 1.688
sys/dev/mii/jmphy.c: revision 1.1
sys/dev/DEVNAMES: revision 1.324
sys/dev/DEVNAMES: revision 1.325
distrib/sets/lists/man/mi: revision 1.1661
sys/arch/i386/conf/GENERIC: revision 1.1214
distrib/sets/lists/man/mi: revision 1.1662
sys/arch/i386/conf/GENERIC: revision 1.1215
share/man/man4/jmphy.4: revision 1.1
share/man/man4/jme.4: revision 1.8

Add jmphy(4) from OpenBSD.

Add jmphy.4.

Port SMSC LAN87xx 10/100 Ethernet PHY driver from FreeBSD with some cleanup
and IFM_NONE support.
 1.120.2.2 25-Nov-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #476):

sys/dev/pci/if_stgereg.h: revision 1.6
sys/arch/amd64/conf/ALL: revision 1.124
sys/dev/mii/files.mii: revision 1.51
share/man/man4/vge.4: revision 1.8
share/man/man4/vge.4: revision 1.9
distrib/sets/lists/man/mi: revision 1.1656
sys/arch/i386/conf/ALL: revision 1.471
share/man/man4/mii.4: revision 1.28
sys/dev/pci/if_stge.c: revision 1.71
sys/dev/mii/ipgphy.c: revision 1.1
sys/dev/mii/ipgphy.c: revision 1.2
share/man/man4/Makefile: revision 1.684
sys/dev/mii/ipgphy.c: revision 1.3
sys/dev/mii/ipgphyreg.h: revision 1.1
sys/dev/mii/ipgphy.c: revision 1.4
sys/dev/mii/ipgphyreg.h: revision 1.2
sys/dev/mii/ipgphy.c: revision 1.5
sys/dev/mii/ipgphyreg.h: revision 1.3
sys/dev/DEVNAMES: revision 1.322
sys/arch/i386/conf/GENERIC: revision 1.1211
sys/arch/amd64/conf/GENERIC: revision 1.537
share/man/man4/ipgphy.4: revision 1.1
share/man/man4/ipgphy.4: revision 1.2

Add support IC Plus IP1000* PHYs. PR/kern 42314 first reported by

Tomokazu HARADA and patch provided by Andrius V.

New sentence, new line.
Fix date. Add RCS Id.

KNF. No functional change.

STGE_PhyCtrl is not PHY register but MAC register, so use ukphy_status()
for IP1000A device.

- Use auto-negotiation when forcing 1000BASE-T.
- Add XXX comment for strange pause setting code. I suspect this is wrong.
- On my environments, 1000BASE-T half duplex doesn't work, so we might remove
IFM_1000T_HDX from this device in future.
- Define IPGPHY_SCR's address.
- Whitespace fix.

Add missing NetBSD RCS Id. Reported by Andrius V.
 1.120.2.1 09-Aug-2019  martin Pull up following revision(s) (requested by rin in ticket #35):

sys/arch/amd64/conf/ALL: revision 1.121
sys/arch/i386/conf/XEN3PAE_DOM0: revision 1.14
sys/arch/amd64/conf/XEN3_DOM0: revision 1.168
sys/arch/i386/conf/GENERIC: revision 1.1210
sys/arch/amd64/conf/GENERIC: revision 1.534

xhci(4) is considered stable enough. So, remove misleading comments.

XXX
pullup to netbsd-9
 1.135.2.3 29-Feb-2020  ad Sync with head.
 1.135.2.2 25-Jan-2020  ad Sync with head.
 1.135.2.1 17-Jan-2020  ad Sync with head.
 1.147.2.1 20-Apr-2020  bouyer Sync with HEAD
 1.164.2.2 03-Apr-2021  thorpej Sync with HEAD.
 1.164.2.1 14-Dec-2020  thorpej Sync w/ HEAD.
 1.166.4.1 01-Aug-2021  thorpej Sync with HEAD.
 1.174.4.5 09-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #939):

distrib/sets/lists/debug/module.md.amd64: revision 1.18
sys/modules/Makefile: revision 1.292
lib/libc/gen/arc4random.c: revision 1.34
lib/libc/gen/arc4random.c: revision 1.35
lib/libc/gen/arc4random.c: revision 1.36
lib/libc/gen/arc4random.c: revision 1.37
sys/kern/kern_entropy.c: revision 1.70
lib/libc/gen/arc4random.c: revision 1.38
sys/kern/kern_entropy.c: revision 1.71
lib/libc/gen/getentropy.3: revision 1.8
distrib/sets/lists/modules/md.amd64: revision 1.103
share/man/man4/rnd.4: revision 1.42
share/man/man4/rnd.4: revision 1.44
lib/libc/include/arc4random.h: revision 1.1
distrib/sets/lists/man/mi: revision 1.1786
sys/arch/i386/conf/GENERIC: revision 1.1258
sys/modules/acpivmgenid/acpivmgenid.ioconf: revision 1.1
sys/arch/amd64/conf/ALL: revision 1.190
distrib/sets/lists/debug/mi: revision 1.446
sys/arch/i386/conf/ALL: revision 1.521
lib/libc/gen/Makefile.inc: revision 1.219
distrib/sets/lists/debug/module.md.i386: revision 1.12
sys/dev/acpi/acpi_vmgenid.c: revision 1.1
sys/dev/acpi/acpi_vmgenid.c: revision 1.2
lib/libc/include/reentrant.h: revision 1.22
sys/arch/evbarm/conf/GENERIC64: revision 1.219
share/man/man4/Makefile: revision 1.735
distrib/sets/lists/modules/md.i386: revision 1.100
distrib/sets/lists/tests/mi: revision 1.1334
lib/libc/gen/arc4random.3: revision 1.22
sys/dev/acpi/files.acpi: revision 1.133
lib/libc/gen/arc4random.3: revision 1.23
tests/lib/libc/gen/t_arc4random.c: revision 1.1
sys/sys/entropy.h: revision 1.6
sys/arch/amd64/conf/GENERIC: revision 1.614
sys/modules/acpivmgenid/Makefile: revision 1.1
share/man/man4/acpivmgenid.4: revision 1.1
lib/libc/gen/Makefile.inc: revision 1.220
tests/lib/libc/gen/Makefile: revision 1.56
share/man/man4/acpivmgenid.4: revision 1.2
share/man/man4/acpivmgenid.4: revision 1.3

(all via patch)

Catch up with all the lint warnings since exit on warning was disabled.

Disable 'missing header declaration' and 'nested extern' warnings for now.
acpivmgenid(4): New driver for virtual machine generation ID.

Added to amd64/ALL and i386/ALL kernel configurations, and made
available as a loadable module acpivmgenid.kmod on x86, for now.
TBD: Add to all ACPI-supporting GENERIC kernels.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

entropy(9): Factor out subroutines to reset and gather entropy.
`Reset' means we keep the data in the pool, but assume it had zero
entropy. `Gather' means we request samples from all on-demand
sources and wait for the synchronous ones to complete.

No functional change intended, other than to expose new symbols --
just preparation to expose these to acpivmgenid(4), so it can use
these when the VM host notifies us that we, the guest, have been
cloned.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

acpivmgenid(4): Reset and gather entropy on VM clone notification.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

arc4random(3): Reseed if system entropy epoch changes.
This can happen, for example, if the system is a VM instance, and the
VM is cloned.

This incurs the cost of a system call on every arc4random call, which
is unfortunate, but
1. we don't currently have a (machine-independent) mechanism for
exposing a read-only page to userland shared by the kernel to
enable a cheaper access path to the entropy epoch; and
2. the algorithm here -- a simple application of ChaCha -- is likely
also a bottleneck and could be much cheaper by
(a) using sys/crypto/chacha for machine-dependent vectorized
ChaCha code, and
(b) filling a buffer (somewhere between a cipher block and a page)
in a batch at a time, instead of running ChaCha to generate
only 32 bytes at a time.
So although this might be a performance hit, the security benefit is
worthwhile and we have a clear path to do better than reversing the
performance hit later.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

acpivmgenid(4): Nix BUGS that have been squashed.
Reference kern.entropy.epoch for the remaining bug (which is a
performance issue, not a security issue).
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

entropy(9): Allow unprivileged reads of sysctl kern.entropy.epoch.

Applications need this in order to know when to reseed. (We should
also expose it through a page shared read-only with userland for
cheaper access, but until we do, let's let applications get at it
through sysctl.)
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

arc4random.c: Fix test program.

This isn't wired up anywhere, but let's reduce the bitrot. It was
helpful in reminding me that kern.entropy.epoch was, for reasons I
can't remember, restricted to privileged access.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

amd64, evbarm, i386: Add acpivmgenid(4) to GENERIC.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

rnd(4): Document kern.entropy.epoch is unprivileged and elaborate.
Cross-reference acpivmgenid(4).
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

arc4random(3): Note that arc4random respects kern.entropy.epoch.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork
Add debug info for new acpivmgenid module

arc4random(3): Add automatic tests.

This verifies that:
- arc4random zeroes its state and reseeds itself on fork
- arc4random reseeds itself on entropy consolidation (e.g., VM clone)
- arc4random falls back to global state if it can't allocate local
state because address space limits cause mmap to fail

NOTE: This adds a new libc symbol __arc4random_global, but it's in
the reserved namespace and only used by t_arc4random, so no libc
minor bump.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

getentropy(3): Note intent to reseed on VM clone, and caveats.

Tidy markup and pacify some mandoc -Tlint complaints while here.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

Bump dates on man pages recently updated to mention VM clones.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

arc4random(3): Pacify some of lint's complaints.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

arc4random: suppress another lint warning
 1.174.4.4 09-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #936):

sys/dev/acpi/apei_einjvar.h: revision 1.1
sys/dev/acpi/apei_cper.h: revision 1.2
distrib/sets/lists/debug/module.md.i386: revision 1.9
sys/dev/acpi/apei_hest.c: revision 1.1
sys/modules/apei/Makefile: revision 1.1
sys/dev/acpi/apei_hest.c: revision 1.2
distrib/sets/lists/modules/md.amd64: revision 1.101
sys/dev/acpi/apei_hest.c: revision 1.3
distrib/sets/lists/modules/md.amd64: revision 1.102
sys/modules/apei/apei.ioconf: revision 1.1
sys/dev/acpi/apei_bert.c: revision 1.1
distrib/sets/lists/man/mi: revision 1.1785
sys/dev/acpi/apei_bertvar.h: revision 1.1
sys/dev/acpi/apei.c: revision 1.1
sys/dev/acpi/apei.c: revision 1.2
sys/dev/acpi/apei.c: revision 1.3
sys/modules/Makefile: revision 1.283
sys/modules/Makefile: revision 1.284
sys/dev/acpi/apei_reg.c: revision 1.1
sys/dev/acpi/apei_hestvar.h: revision 1.1
distrib/sets/lists/debug/module.md.i386: revision 1.10
sys/dev/acpi/apei_reg.c: revision 1.2
sys/dev/acpi/apei_reg.c: revision 1.3
sys/dev/acpi/apei_reg.h: revision 1.1
sys/dev/acpi/apei_reg.h: revision 1.2
sys/dev/acpi/apei_reg.h: revision 1.3
sys/dev/acpi/acpi_hed.c: revision 1.1
sys/dev/acpi/apei_einj.c: revision 1.1
sys/dev/acpi/apeivar.h: revision 1.1
sys/dev/acpi/apei_einj.c: revision 1.2
sys/dev/acpi/apei_einj.c: revision 1.3
sys/dev/acpi/apei_einj.c: revision 1.4
sys/dev/acpi/apei_einj.c: revision 1.5
share/man/man4/Makefile: revision 1.734
sys/dev/acpi/apei_einj.c: revision 1.6
sys/dev/acpi/apei_einj.c: revision 1.7
sys/dev/acpi/files.acpi: revision 1.131
sys/dev/acpi/files.acpi: revision 1.132
sys/dev/acpi/apei_interp.c: revision 1.1
sys/dev/acpi/apei_interp.c: revision 1.2
share/man/man4/acpihed.4: revision 1.1
sys/dev/acpi/apei_mapreg.c: revision 1.1
sys/dev/acpi/apei_interp.c: revision 1.3
share/man/man4/acpihed.4: revision 1.2
distrib/sets/lists/modules/md.i386: revision 1.98
sys/dev/acpi/apei_mapreg.c: revision 1.2
sys/dev/acpi/apei_interp.h: revision 1.1
sys/dev/acpi/apei_interp.c: revision 1.4
distrib/sets/lists/modules/md.i386: revision 1.99
sys/modules/acpihed/Makefile: revision 1.1
sys/dev/acpi/apei_mapreg.c: revision 1.3
sys/dev/acpi/apei_interp.h: revision 1.2
sys/arch/amd64/conf/ALL: revision 1.185
sys/dev/acpi/apei_mapreg.h: revision 1.1
sys/dev/acpi/apei_mapreg.c: revision 1.4
sys/arch/amd64/conf/ALL: revision 1.186
sys/dev/acpi/apei_erstvar.h: revision 1.1
sys/dev/acpi/apei_erst.c: revision 1.1
sys/dev/acpi/apei_erst.c: revision 1.2
sys/dev/acpi/apei_erst.c: revision 1.3
sys/arch/i386/conf/ALL: revision 1.516
share/man/man4/apei.4: revision 1.1
sys/arch/i386/conf/ALL: revision 1.517
share/man/man4/apei.4: revision 1.2
distrib/sets/lists/debug/module.md.amd64: revision 1.15
sys/modules/acpihed/acpihed.ioconf: revision 1.1
sys/dev/acpi/apei_hed.h: revision 1.1
distrib/sets/lists/debug/module.md.amd64: revision 1.16
sys/dev/acpi/apei_cper.h: revision 1.1

(all via patch)

apei(4): New driver for ACPI Platform Error Interfaces.

For now it is wired up only in x86 ALL kernels, and built as a module
for x86 and Arm. Once it gets a little more testing on machines with
APEI, I would like to flip it on by default.
PR kern/58046

apei(4): Pacify -Wsign-compare.
Assert that the parsing made forward progress too while here.
PR kern/58046

apei(4): Tweak some comments about the APEI interpreter language.
No functional change intended.
PR kern/58046

apei(4): Fix parsing checks for TRIGGER_ERROR action table.
The TableSize is size of the header plus the body, not just the body.
PR kern/58046
apei(4): Note some TODOs for EINJ and HEST.
No functional change intended, comments only.
PR kern/58046

acpihed(4): New driver for PNP0C33 to notify apei(4).
PNP0C33 denotes the ACPI Hardware Error Device, which exists only to
be a vector for event notifications.
PR kern/58046

acpihed(4): fix name in Dt, use Ql
apei(4): Plug memory leak on teardown of instruction interpreter.
PR kern/58046
apei(4): Fix indexing of multi-unit register access.
PR kern/58046

apei(4): Fix register chunk counting.
Now it will actually read and write the registers!
Have been updating and reloading the wrong module to test this, oops.
PR kern/58046

apei(4): Allow pre-mapping I/O registers too.
PR kern/58046

apei(4): Pre-map registers when compiling interpreter.
This way we don't have to worry about mapping them in nasty contexts
where access to uvm_km_alloc may not be allowed. Paves the way to
use ERST for saving dmesg on crash.
Exception: ACPI_ERST_MOVE_DATA still needs to do AcpiOsMapMemory.
We'll need to reserve a couple pages to avoid that.
PR kern/58046

apei(4): Simplify EINJ/ERST register access now that it's pre-mapped.
PR kern/58046
apei(4): Make sure to initialize *fatalp in apei_gesb_report.
PR kern/58046

apei: fix typos in comments

apei: fix typos in comments and snprintb bitfmt

apei(4): Fix uninitialized stack access in error branch.
PR kern/58046

apei(4), acpihed(4): Wire up man pages to build.
PR kern/58046: Missing APEI (ACPI Platform Error Interface) support
 1.174.4.3 20-Jun-2024  martin Pull up following revision(s) (requested by andvar in ticket #700):

sys/arch/i386/conf/GENERIC: revision 1.1256
share/man/man4/man4.x86/viac7temp.4: revision 1.1
sys/arch/x86/x86/viac7temp.c: revision 1.11
share/man/man4/man4.x86/Makefile: revision 1.24
share/man/man4/man4.i386/viac7temp.4: file removal
share/man/man4/man4.i386/Makefile: revision 1.81
distrib/sets/lists/man/mi: revision 1.1773
sys/arch/amd64/conf/GENERIC: revision 1.612
sys/arch/amd64/conf/ALL: revision 1.188
sys/arch/i386/conf/ALL: revision 1.519

viac7temp(4): rewrite temperature sensor to read value from MSR instead of using
documented cpuid instruction and eax register.

This approach is adapted from linux via-cputemp.c, no official documentation is
currently available. However, msr value seems to work on all tested CPUs while
documented cpuid instruction typically reports 0, even for my C7-D CPU.
msr value seems to have temperature in Celsius in lower 24-bits without fraction
(thus "msr & 0xffffff;" is used).

Tested on my personal systems based on CPUs below (i386 and amd64):
C7-D 1.6GHz (i386 only), Nano X2 L4350E, Nano X2 U4300, U2300 Nano, KX-U6580.
Also got one response via email which was based on Nano X2 L4050 (VE-900).

Nano reports independent values for each core.

KX-U6580 seems to show the same value for all cores but more testing is needed.

Since it works on amd64 capable CPUs, adding driver to GENERIC kernel config.

Also moving viac7temp man page to x86 instead of i386 (with updates).

In theory the change should add support for all VIA Nano CPUs and Zhaoxin CPUs
at least up to KX-6000(G) series.

In the future I may need to introduce amd64 kernel module as well.

Patch mainly reviewed by riastradh.
 1.174.4.2 08-Oct-2023  martin Pull up following revision(s) (requested by rin in ticket #393):

sys/dev/pci/igc/if_igc.c up to 1.3
sys/dev/pci/igc/if_igc.h up to 1.2
sys/dev/pci/igc/igc_api.c up to 1.2
sys/dev/pci/igc/igc_api.h up to 1.2
sys/dev/pci/igc/igc_base.c up to 1.2
sys/dev/pci/igc/igc_base.h up to 1.2
sys/dev/pci/igc/igc_defines.h up to 1.2
sys/dev/pci/igc/igc_evcnt.h up to 1.1
sys/dev/pci/igc/igc_hw.h up to 1.2
sys/dev/pci/igc/igc_i225.c up to 1.2
sys/dev/pci/igc/igc_i225.h up to 1.2
sys/dev/pci/igc/igc_mac.c up to 1.2
sys/dev/pci/igc/igc_mac.h up to 1.2
sys/dev/pci/igc/igc_nvm.c up to 1.2
sys/dev/pci/igc/igc_nvm.h up to 1.2
sys/dev/pci/igc/igc_phy.c up to 1.2
sys/dev/pci/igc/igc_phy.h up to 1.2
sys/dev/pci/igc/igc_regs.h up to 1.2
distrib/sets/lists/man/mi: revision 1.1766
sys/arch/amd64/conf/GENERIC: revision 1.606
sys/arch/evbppc/conf/DHT: revision 1.5
sys/arch/evbarm/conf/GENERIC64: revision 1.213
share/man/man4/Makefile: revision 1.733
sys/arch/amd64/conf/ALL: revision 1.181
share/man/man4/igc.4: revision 1.1
sys/dev/pci/files.pci: revision 1.447
sys/arch/amd64/conf/XEN3_DOM0: revision 1.200
doc/CHANGES (apply patch)

Add igc(4) for Intel I225/I226 series ethernet devices
 1.174.4.1 30-Jul-2023  martin Pull up following revision(s) (requested by riastradh in ticket #259):

sys/dev/acpi/acpi_ec.c: revision 1.102
sys/dev/acpi/acpi_ec.c: revision 1.103
sys/dev/acpi/acpi_ec.c: revision 1.104
sys/dev/acpi/acpi_ec.c: revision 1.105
sys/dev/acpi/acpi_ec.c: revision 1.106
sys/dev/acpi/acpi_ec.c: revision 1.107
sys/dev/acpi/acpi_ec.c: revision 1.108
sys/dev/acpi/acpi_ec.c: revision 1.90
sys/dev/acpi/acpi_ec.c: revision 1.91
sys/dev/acpi/acpi_ec.c: revision 1.92
sys/dev/acpi/acpi_ec.c: revision 1.93
sys/dev/acpi/acpi_ec.c: revision 1.94
sys/dev/acpi/files.acpi: revision 1.128
sys/dev/acpi/acpi_ec.c: revision 1.95
sys/dev/acpi/acpi_ec.c: revision 1.96
sys/dev/acpi/acpi_ec.c: revision 1.97
sys/arch/amd64/conf/ALL: revision 1.179
sys/dev/acpi/acpi_ec.c: revision 1.98
sys/dev/acpi/acpi_ec.c: revision 1.99
sys/dev/acpi/acpi_ec.c: revision 1.87
sys/dev/acpi/acpi_ec.c: revision 1.88
sys/dev/acpi/acpi_ec.c: revision 1.89
sys/arch/i386/conf/ALL: revision 1.511
sys/dev/acpi/acpi_ec.c: revision 1.100
sys/dev/acpi/acpi_ec.c: revision 1.101

acpiec(4): Record device_t self.

Not used yet, to be used soon for device_printf and to allow making
some of the internal functions a little more type-safe later.
acpiec(4): New ACPIEC_DEBUG option.

Value is bit mask of debug messages to enable.

Enable in x86/ALL kernels.

No functional change intended when the option is off.

acpiec(4): Clarify lock order and sprinkle lock assertions.
No functional change intended.

acpiec(4): Sprinkle comments.
Note where this code is abusing cv_wait and needs a loop to handle
spurious wakeups.
No functional change intended.

acpiec(4): Assert state is free when we start a transaction.
No functional change intended.

acpiec(4): Set sc_got_sci only when a transaction is over.

Before, when the acpiec thread noticed an SCI had been requested and
entered acpiec_gpe_state_machine to send the query command, it would
see the SCI is still requested -- because it had yet to acknowledge
it by setting the query command! -- and think the EC was asking for a
_second_ SCI.

So once the first SCI transaction was over, it would start a second
one, even though the EC hadn't asked for another -- and this would
wedge on some ECs.

Now, acpiec_gpe_state_machine waits to see what state we transition
to before taking the SCI bit to mean we need to notify the acpiec
thread to handle another query.

That way, when the acpiec thread enters acpiec_gpe_state_machine with
EC_STATE_QUERY, it can send the query command first, with the side
effect of clearing the SCI bit in subsequent reads of the status
register, and it won't think another SCI has been requested until it
returns to EC_STATE_FREE and sees the SCI bit set again in the status
register.

Possibly relevant PRs:
PR kern/53135
PR kern/52763
PR kern/57162

acpiec(4): Fix cv_wait loop around sc->sc_got_sci.

That is, make it actually loop as required, so it gracefully handles
spurious wakeups instead of barging into invalid states.

acpiec(4): Fix interrupt wait loop in acpiec_gpe_query thread.

acpiec(4): Fix cv_timedwait abuse in acpiec_read/write.

acpiec(4): Don't touch sc->sc_state outside sc->sc_mtx.

acpiec(4): Merge returns in acpiec_read/write.
No functional change intended.

acpiec(4): Factor wait logic out.
No functional change intended.

acpiec(4): Pass softc, not device_t, to acpiec_gpe_state_machine.
Simpler, type-safer.
No functional change intended.

acpiec(4): Pass softc, not device_t, to acpiec_callout.
Simpler.
No functional change intended.

acpiec(4): Pass softc, not device_t, to acpiec_gpe_handler.
Simpler.
No functional change intended.

acpiec(4): Pass softc, not device_t, to acpiec_lock/unlock.
Simpler, type-safer.
No functional change intended.

acpiec(4): Pass softc, not device_t, to acpiec_read/write.
Simpler, type-safer.
No functional change intended.

acpiec(4): Pass softc, not device_t, to acpiec_gpe_query thread.
Simpler.
No functional change intended.

acpiec(4): Pass softc, not device_t, to acpiec_space_handler.
Better to keep the device_t isolated to public interfaces. Simpler
internally this way.
No functional change intended.

acpiec(4): Factor out if (state == FREE) cv_signal(sc_cv).

In principle this could have a functional change, but at worst, it is
to signal more wakeups than needed, which should always be safe.
acpiec(4): Take a lock around acpiec_cold updates.

Otherwise we race with readers -- probably harmlessly, but let's
avoid the appearance of problems.
XXX Maybe acpiec_suspend and acpiec_shutdown should interrupt
transactions and force them to fail promptly?
XXX This looks bad because acpiec_cold is global and sc->sc_mtx
doesn't look like it's global, but we expect to have only one
acpiec(4) device anyway from what I understand. Maybe we should move
acpiec_cold into the softc?

acpiec(4): One more debug message about read/write polling timeout.
 1.188.2.1 02-Aug-2025  perseant Sync with HEAD
 1.192.2.1 20-Oct-2025  martin Pull up following revision(s) (requested by riastradh in ticket #66):

sys/arch/x86/include/mpacpi.h: revision 1.12
sys/arch/x86/x86/mpacpi.c: revision 1.112
sys/arch/amd64/conf/ALL: revision 1.194
sys/arch/i386/conf/ALL: revision 1.524
sys/arch/x86/acpi/acpi_machdep.c: revision 1.40
sys/arch/i386/conf/GENERIC: revision 1.1261
sys/dev/acpi/acpi_mcfg.h: revision 1.6
sys/arch/amd64/conf/GENERIC: revision 1.618

x86: Wire up PCI resource manager if enabled.

Enable in your kernel config with `options PCI_RESOURCE'.

Adapted from a patch by mlelstv@.
PR port-amd64/59118: Thinkpad T495s - iwm PCI BAR is zero
 1.9 02-Nov-2014  christos make DRMKMS the default on GENERIC and comment out the legacy drivers.
 1.8 26-Jul-2014  riastradh branches: 1.8.2; 1.8.4;
Rename radeondrmkms to just plain radeon.

radeondrmkmsfb will stay as is until the name radeonfb is available
(currently taken by legacy dev/pci/radeonfb.c).
 1.7 25-Jul-2014  dholland Fix description of DIAGNOSTIC in x86 kernels.
 1.6 25-Jul-2014  riastradh Hook up radeondrmkmsfb code.

Builds, not testable yet.
 1.5 24-Jul-2014  riastradh Rework Intel framebuffer attachment.

Turns out genfb_softc must be at the start of its own device_private,
so we can't have it in the middle of a structure, and certainly can't
have potentially multiple genfbs per graphics device. Failing to do
this is why entering ddb didn't work with an i915drmkms console.

Instead of putting a genfb_softc into each drm_fb_helper, put a
device_t into each drm_fb_helper and create a new intelfb(4) device
for each Intel framebuffer. This will be more flexible, too, in case
we want accelerated framebuffers later on. (XXX Need to adapt the
radeon code, which I'm disabling until that happens to avoid breaking
the build.)

While here, defer disabling VGA, vga_cndetach, and genfb_attach until
we're actually ready to do them all together along with the mode
switch. This should reduce the amount of time during which the
screen is blanked, in case it hangs.
 1.4 16-Jul-2014  riastradh First whack at radeon driver.

No hardware to test yet, but it builds.
 1.3 16-Jul-2014  riastradh Make it build and boot on my test machines.

Screen blanks on boot on the Ivy Bridge system with

DRM error in cpt_serr_int_handler: PCH transcoder A FIFO underrun

But after that everything is OK. Appears to be an upstream problem.
To investigate...

I think there's a cache flushing issue somewhere -- there are little
display artefacts on my T60.
 1.2 18-Mar-2014  riastradh branches: 1.2.2; 1.2.4; 1.2.6;
Merge riastradh-drm2 to HEAD.
 1.1 30-Jan-2014  riastradh branches: 1.1.2;
file DRMKMS was initially added on branch riastradh-drm2.
 1.1.2.1 30-Jan-2014  riastradh Redo amd64/NO_DRM config and add amd64/DRMKMS.
 1.2.6.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.2.6.1 18-Mar-2014  yamt file DRMKMS was added on branch yamt-pagecache on 2014-05-22 11:39:28 +0000
 1.2.4.2 18-May-2014  rmind sync with head
 1.2.4.1 18-Mar-2014  rmind file DRMKMS was added on branch rmind-smpnet on 2014-05-18 17:44:54 +0000
 1.2.2.1 10-Aug-2014  tls Rebase.
 1.8.4.3 03-Dec-2017  jdolecek update from HEAD
 1.8.4.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.8.4.1 26-Jul-2014  tls file DRMKMS was added on branch tls-maxphys on 2014-08-20 00:02:42 +0000
 1.8.2.1 18-Mar-2015  snj Apply patch (requested by christos in ticket #542):
- Enable intel and radeon DRM/KMS drivers in GENERIC
- Disable all of the old DRM drivers in GENERIC
- Remove the separate DRMKMS kernel
 1.2 02-Jan-2008  jmmv branches: 1.2.2;
Remove this; objections from joerg@ and ad@, and I agree with them that
additional kernel configs are not the way to go because they are not
flexible at all. Plus ad@ is working on a real solution (bootprop).
 1.1 01-Jan-2008  jmmv Add a trimmed-down configuration file for the VMware Fusion virtual machine
suitable for the subset of hardware devices it provides.
 1.2.2.3 08-Jan-2008  bouyer Sync with HEAD
 1.2.2.2 02-Jan-2008  bouyer Sync with HEAD
 1.2.2.1 02-Jan-2008  bouyer file FUSION was added on branch bouyer-xeni386 on 2008-01-02 21:47:04 +0000
 1.619 21-Oct-2025  pgoyette Add Realtek 8126 to comment for rge*
 1.618 06-Oct-2025  riastradh x86: Wire up PCI resource manager if enabled.

Enable in your kernel config with `options PCI_RESOURCE'.

Adapted from a patch by mlelstv@.

PR port-amd64/59118: Thinkpad T495s - iwm PCI BAR is zero
 1.617 04-Aug-2025  skrll Add a port of the FreeBSD driver for the VMware PV SCSI controller found
in VMware's ESXi product.

Tested on ESXi/Arm such that an installation from ISO succeeds and boots.
 1.616 27-Mar-2025  riastradh branches: 1.616.2;
x86: Enable vio9p(4) out of the box.

PR kern/59211: vio9p(4): missing from various GENERICs and MAKEDEVs
 1.615 27-Mar-2025  riastradh virtio(4): Consolidate kernel configs.

No functional change intended.

Leave `# XXX ?' comments where I don't know why the driver in
question is excluded. (Typical reason is that PAGE_SIZE is not 4096
but I didn't investigate -- if you do investigate, please either
update the comment if you determine a reason, or enable the driver if
you don't.)

PR kern/59211: vio9p(4): missing from various GENERICs and MAKEDEVs
 1.614 27-Aug-2024  riastradh amd64, evbarm, i386: Add acpivmgenid(4) to GENERIC.

PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork
 1.613 16-Jul-2024  riastradh viocon(4): Add to various kernel configs.
 1.612 30-Apr-2024  andvar branches: 1.612.2;
viac7temp(4): rewrite temperature sensor to read value from MSR instead of using
documented cpuid instruction and eax register.

This approach is adapted from linux via-cputemp.c, no official documentation is
currently available. However, msr value seems to work on all tested CPUs while
documented cpuid instruction typically reports 0, even for my C7-D CPU.
msr value seems to have temperature in Celsius in lower 24-bits without fraction
(thus "msr & 0xffffff;" is used).

Tested on my personal systems based on CPUs below (i386 and amd64):
C7-D 1.6GHz (i386 only), Nano X2 L4350E, Nano X2 U4300, U2300 Nano, KX-U6580.
Also got one response via email which was based on Nano X2 L4050 (VE-900).
Nano reports independent values for each core.
KX-U6580 seems to show the same value for all cores but more testing is needed.

Since it works on amd64 capable CPUs, adding driver to GENERIC kernel config.
Also moving viac7temp man page to x86 instead of i386 (with updates).
In theory the change should add support for all VIA Nano CPUs and Zhaoxin CPUs
at least up to KX-6000(G) series.

In the future I may need to introduce amd64 kernel module as well.

Plan to pullup to at least netbsd-10.

Patch mainly reviewed by riastradh.
 1.611 21-Apr-2024  riastradh apei(4), acpihed(4): Enable in x86 GENERIC.

Let's just see how this works out in practice. Might need to reduce
the overhead of each GHES on machines with thousands of them, but
we'll see.

PR kern/58046
 1.610 02-Apr-2024  charlotte Mention DKWEDGE_METHOD_TOS in several kernel config files
 1.609 29-Jan-2024  christos PR/57889: Ricardo Branco: ext2fs does not have user immutable and append
file flags, only system ones. Restrict those to the superuser. Before
the behavior was controlled by EXT2FS_SYSTEM_FLAGS. Make that behavior the
default.
 1.608 23-Oct-2023  msaitoh eqos(4): Disable eqos(4) by default because it's not stable on x86.
 1.607 20-Oct-2023  msaitoh eqos(4): Add initial support for Intel Elkhart Lake internal Ethernet devices.

- Only tested on PSE SGMII 1G Ethernet MAC with MaxLinear GPY115.
- I don't know why dmat64 doesn't work. eqos_attach() have a special
code if EQOS_HW_FEATURE_ADDR64_32BIT(sc) is true, but it seems it doesn't
work.
- TODO:
Multiqueue support.
Detach support.
 1.606 04-Oct-2023  rin igc(4): Added to kernel config files for tested platforms

I.e., aarch64, amd64, and evbppc/DHT, at the moment.

Please feel free to add to other config files, and report us back
if you find problems :)
 1.605 09-Aug-2023  andvar viadrmums(4): build legacy VIA DRM UMS driver module for amd64.

This driver is not built-in by default, thus loadable module can help (un)lucky
owners of 64-bit capable VIA (Nano/Eden) systems or early AMD/Intel systems
with some VIA chipsets, which include VIA integrated graphics.
I also boldly added product IDs for few later models from VX8xx/VX9xx chipsets
without 3D support (DX9_0) to "expand" the driver support to more systems.
Tested successfully basic functionality on VX800, and partially successfully
on VX900 (on VX900 Xorg failed to initialize due to openchrome related issues,
viadrmums attaches and it is by used the driver).
Didn't test on VX855, I don't have one.

Pull up to netbsd-10 is needed.
 1.604 15-Jul-2023  riastradh amd64: Enable HEARTBEAT option, not just a HEARTBEAT option comment.
 1.603 15-Jul-2023  riastradh x86: Enable HEARTBEAT by default in GENERIC.
 1.602 12-Apr-2023  riastradh ichsmb(4), tco(4): Add support for TCO on newer Intel chipsets.

TCO (`Total Cost of Ownership', Intel's bizarre name for a watchdog
timer) used to hang off the Intel I/O platform controller hub's (ICH)
low-pin-count interface bridge (LPC IB), or ichlpcib(4). On newer
devices, it hangs off the ICH SMBus instead.

Tested on INTEL 100SERIES_SMB (works) and INTEL 100SERIES_LP_SMB
(doesn't work, still not sure why).

XXX kernel revbump: This breaks the module ABI -- tco(4) modules
older than the change to make ta_has_rcba into ta_version will
incorrectly attach at buses they do not understand. (However, the
tco(4) driver is statically built into GENERIC, so maybe it's safe
for pullup since the module wouldn't have worked anyway.)
 1.601 09-Feb-2023  abs Adjust _all_ cinclude of *.local files

- Ensure always at end
- Use tab rather than spaces
- Add consistent comment
"Pull in optional local configuration - always at end"

The only functional change is that a local file which tried to
override an existing setting (eg with "no foo") would have failed
in some cases before, but now will work
 1.600 09-Feb-2023  abs Ensure GENERIC.local is always at the end of GENERIC

Where a GENERIC config had an existing inclusion of GENERIC.local,
ensure it is always at the end of the file, with a consistent
comment:

# Pull in optional local configuration
cinclude "arch/landisk/conf/GENERIC.local"

This allows GENERIC.local to correctly override all options

(This pass does not affect any GENERIC which did not already have
an include of GENERIC.local)
 1.599 29-Sep-2022  riastradh branches: 1.599.4;
swwdog(4): Add to GENERIC kernels.

Plus a handful of others that I'm familiar with. Lots of special-
purpose kernels should probably have this too but I'm not going
through all the arm, mips, and ppc evaluation board kernels to see
which ones are relevant.

Omitted from systems I know to be very small:
- sun2/GENERIC
- dreamcast/GENERIC
Feel free to remove it from others that need to be kept smaller.

Compile-tested a few of these just in case:
- alpha/GENERIC
- amd64/GENERIC
- evbmips/OCTEON
- i386/GENERIC
- riscv/GENERIC

PR kern/29702
 1.598 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.597 01-Sep-2022  bouyer Add commented out experimental PVH dom0 options and pseudo-device
 1.596 07-Aug-2022  simonb UFS/LFS dirhash:
- Enable UFS_DIRHASH if the architecture or kernel model specific config
file can use 128MB of RAM or more.
- Remove experimental tag from UFS_DIRHASH; it's been with RUMP kernel
and by a number of NetBSD developers for years.
- Add LFS_DIRHASH if LFS was enabled.
- Be somewhat consistent with FS options order.
 1.595 16-Apr-2022  nia x86: Enable HDAUDIOVERBOSE (as on arm) in order for AUDIO_GETDEV
to return human-readable data. Especially now that HDMI/DP audio
is enabled by default, it helps to be able to tell two devices
apart in audiocfg/aiomixer.
 1.594 24-Mar-2022  manu Add initial support for Intel GPIO chips
 1.593 31-Oct-2021  simonb options<space><tab>
 1.592 16-Oct-2021  jmcneill Enable com and lpt at ACPI attachments.
 1.591 15-Oct-2021  jmcneill Swap fdc@isa for fdc@acpi as the former takes over a second to probe.
 1.590 09-Sep-2021  jakllsch Enable WSDISPLAY_CUSTOM_OUTPUT and WSDISPLAY_CUSTOM_BORDER on
amd64 GENERIC as i386 GENERIC already does.
 1.589 17-May-2021  yamaguchi Add a new link-aggregation pseudo interface named lagg(4)

- FreeBSD's lagg(4) based implementation
- MP-safe and MP-scalable
 1.588 10-Mar-2021  wiz branches: 1.588.4; 1.588.6;
drm(4): allow limiting maximum X/Y resolution

With some drivers (at least radeon(4)), in some cases the driver
does not choose the resolution correctly. The options
DRM_MAX_RESOLUTION_HORIZONTAL and DRM_MAX_RESOLUTION_VERTICAL allow
limiting the maximum resolution in X and Y direction.
 1.587 10-Mar-2021  msaitoh Add micphy(4).
 1.586 05-Mar-2021  gdt GENERIC: comment typo fix (spacing)
 1.585 04-Mar-2021  gdt GENERIC: Tiny comment adjustment (NFC)

While making XEN3_DOM0 more like GENERIC, I noticed a few differences
where GENERIC was off -- trivial things like missing spaces in
comments, inconsistent comment workding. This fixes those, both
because they are valid fixes in their own right once noticed, and to
make the diff to XEN smaller.
 1.584 01-Mar-2021  jakllsch enable rge(4) on x86 and evbarm64
 1.583 24-Jan-2021  jmcneill Attach dwiic(4) to AMD FCH I2C controllers. These busses are separate
from the SMBus that we attach to piixpm(4) today, and support direct
config via ACPI.
 1.582 20-Jan-2021  nia remove compat_ossaudio from kernel modules

this is only useful with compat_linux and gets autoloaded when
compat_linux is loaded, so there's no reason to bake it into kernels
any more.
 1.581 16-Jan-2021  thorpej Enable tpm @ acpi (now that it can match TPM 1.2 devices, which are not,
as the comment implies, experimental).
 1.580 27-Sep-2020  roy branches: 1.580.2;
vether: Add to kernel configurations

It's only enabled if the kernel enabled bridge AND tap.
Otherwise it's commented out.
 1.579 08-Sep-2020  yamaguchi Added iavf(4) that is based on OpenBSD's iavf(4) implementation

reviewed by msaitoh@n.o and knakahara@n.o
 1.578 30-Aug-2020  dholland typo in comment
 1.577 17-Aug-2020  christos remove commented out MEMORY_DISK_* entries
 1.576 17-Aug-2020  christos correct MEMORY_DISK_* option docs
 1.575 16-Aug-2020  jdolecek make COMPAT_LINUX option disabled by default

leave the option enabled only in amd64/i386 ALL kernels to make
sure it continues to be compilable also when included in kernel
 1.574 01-Aug-2020  maxv Remove references to BRIDGE_IPF, it is now compiled in by default.
 1.573 19-Jul-2020  maxv Compile USER_LDT by default, but, put it behind a privileged sysctl that
defaults to disabled. To enable:

# sysctl -w machdep.user_ldt=1
 1.572 14-Jul-2020  yamaguchi Enable PCPU_IDT option by default
 1.571 24-Jun-2020  thorpej Add amdccp at pci.
 1.570 18-Jun-2020  maxv style
 1.569 07-Jun-2020  maxv Add fault(4).
 1.568 16-May-2020  christos Add ACL support for FFS. From FreeBSD.
 1.567 02-May-2020  bouyer Introduce Xen PVH support in GENERIC.
This is compiled in with
options XENPVHVM
x86 changes:
- add Xen section and xen pvh entry points to locore.S. Set vm_guest
to VM_GUEST_XENPVH in this entry point.
Most of the boot procedure (especially page table setup and switch to
paged mode) is shared with native.
- change some x86_delay() to delay_func(), which points to x86_delay() for
native/HVM, and xen_delay() for PVH

Xen changes:
- remove Xen bits from init_x86_64_ksyms() and init386_ksyms()
and move to xen_init_ksyms(), used for both PV and PVH
- set ISA no-legacy-devices property for PVH
- factor out code from Xen's cpu_bootconf() to xen_bootconf()
in xen_machdep.c
- set up a specific pvh_consinit() which starts with printk()
(which uses a simple hypercall that is available early) and switch to
xencons when we can use pmap_kenter_pa().
 1.566 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.565 15-Apr-2020  maxv Introduce POOL_NOCACHE, simple option to cancel pool_caches and go directly
to the pool layer. It is taken out of POOL_QUARANTINE.

Advertise POOL_NOCACHE for kMSan rather than POOL_QUARANTINE. With kMSan
we are only interested in the no-caching effect, not the quarantine. This
reduces memory pressure on kMSan kernels.
 1.564 28-Mar-2020  isaki branches: 1.564.2;
Reduce default AUDIO_BLK_MS from 40msec to 10msec on all platform except m68k
(m68k uses 40msec default as before). And remove the option from GENERIC.
- It's not good idea to set such parameter in individual GENERICs.
- 4msec is (probably no problem for most modern real hardware but)
too aggressive to be default.
- 10msec is too severe for antique machines but it's hard to draw a line.
 1.563 17-Feb-2020  nisimura add kse(4) for i386/amd64 GENERIC
 1.562 09-Feb-2020  jmcneill Retire azalia(4).
 1.561 08-Feb-2020  maxv Retire KLEAK.

KLEAK was a nice feature and served its purpose; it allowed us to detect
dozens of info leaks on the kernel->userland boundary, and thanks to it we
tackled a good part of the infoleak problem 1.5 years ago.

Nowadays however, we have kMSan, which can detect uninitialized memory in
the kernel. kMSan supersedes KLEAK: it can detect what KLEAK was able to
detect, but in addition, (1) it operates in all of the kernel and not just
the kernel->userland boundary, (2) it requires no user interaction, and (3)
it is deterministic and not statistical.

That makes kMSan the feature of choice to detect info leaks nowadays;
people interested in detecting info leaks should boot a kMSan kernel and
just wait for the magic to happen.

KLEAK was a good ride, and a fun project, but now is time for it to go.

Discussed with several people, including Thomas Barabosch.
 1.560 25-Jan-2020  thorpej Retire "le* at pci?" from the shipped kernel configs:
- If the config had both an le@pci and a pcn, simply remove le@pci
(pcn would match at a higher priority anyway).
- If the config had le@pci enabled, but no pcn, change le@pci to pcn.
- If the config had le@pci commented out, but no pcn, change le@pci
to pcn and leave it commented out.

The pcn driver supports more chips than le@pci and does DMA directly
to/from mbufs rather than memory copies.
 1.559 24-Jan-2020  nia Set AUDIO_BLK_MS=4 - unlikely to cause significant overhead on non-m68k.

Several of us have been setting this in /etc/sysctl.conf for months, to
get better performance from applications that require synced audio, etc.

It's also mentioned as a good value with low overhead on most archs here:
https://mail-index.netbsd.org/tech-kern/2019/12/07/msg025830.html

We could probably go lower, but this is low enough to make most/all
software run well, removing frame drops. It's also low enough to get
emulators/mednafen to stop complaining in the console.
 1.558 20-Jan-2020  thorpej Remove FDDI support.
 1.557 19-Jan-2020  thorpej Remove Token Ring support.
 1.556 19-Jan-2020  thorpej Remove HIPPI support and the esh(4) driver that uses it. There have not
been any users of HIPPI for some time, and it is unlikely to be resurrected.
 1.555 19-Jan-2020  thorpej Remove the strip(4) - Starmode Radio IP - pseudo-device driver. It is
long since obsolete.
 1.554 09-Jan-2020  manu Rollback multiboot2 for amd64, as requested by core
 1.553 01-Jan-2020  ryo branches: 1.553.2;
add aq(4)
 1.552 26-Dec-2019  msaitoh Add cas(4).
 1.551 14-Dec-2019  maxv Disable multiboot for now, too much breakage.
 1.550 10-Dec-2019  yamaguchi Ported driver for Intel Ethernet 700 series

reviewed by msaitoh and knakahara
 1.549 10-Dec-2019  manu Add multiboot 2 support to amd64 kernel
 1.548 05-Dec-2019  sevan Enable pciverbose option to make use of the pcidevs database by default.

ok ad, mrg
 1.547 20-Nov-2019  hikaru Add opencrypto driver for Intel QuickAssist.
 1.546 14-Nov-2019  maxv Add support for Kernel Memory Sanitizer (kMSan). It detects uninitialized
memory used by the kernel at run time, and just like kASan and kCSan, it
is an excellent feature. It has already detected 38 uninitialized variables
in the kernel during my testing, which I have since discreetly fixed.

We use two shadows:
- "shad", to track uninitialized memory with a bit granularity (1:1).
Each bit set to 1 in the shad corresponds to one uninitialized bit of
real kernel memory.
- "orig", to track the origin of the memory with a 4-byte granularity
(1:1). Each uint32_t cell in the orig indicates the origin of the
associated uint32_t of real kernel memory.

The memory consumption of these shadows is consequent, so at least 4GB of
RAM is recommended to run kMSan.

The compiler inserts calls to specific __msan_* functions on each memory
access, to manage both the shad and the orig and detect uninitialized
memory accesses that change the execution flow (like an "if" on an
uninitialized variable).

We mark as uninit several types of memory buffers (stack, pools, kmem,
malloc, uvm_km), and check each buffer passed to copyout, copyoutstr,
bwrite, if_transmit_lock and DMA operations, to detect uninitialized memory
that leaves the system. This allows us to detect kernel info leaks in a way
that is more efficient and also more user-friendly than KLEAK.

Contrary to kASan, kMSan requires comprehensive coverage, ie we cannot
tolerate having one non-instrumented function, because this could cause
false positives. kMSan cannot instrument ASM functions, so I converted
most of them to __asm__ inlines, which kMSan is able to instrument. Those
that remain receive special treatment.

Contrary to kASan again, kMSan uses a TLS, so we must context-switch this
TLS during interrupts. We use different contexts depending on the interrupt
level.

The orig tracks precisely the origin of a buffer. We use a special encoding
for the orig values, and pack together in each uint32_t cell of the orig:
- a code designating the type of memory (Stack, Pool, etc), and
- a compressed pointer, which points either (1) to a string containing
the name of the variable associated with the cell, or (2) to an area
in the kernel .text section which we resolve to a symbol name + offset.

This encoding allows us not to consume extra memory for associating
information with each cell, and produces a precise output, that can tell
for example the name of an uninitialized variable on the stack, the
function in which it was pushed on the stack, and the function where we
accessed this uninitialized variable.

kMSan is available with LLVM, but not with GCC.

The code is organized in a way that is similar to kASan and kCSan, so it
means that other architectures than amd64 can be supported.
 1.545 05-Nov-2019  maxv Add Kernel Concurrency Sanitizer (kCSan) support. This sanitizer allows us
to detect race conditions at runtime. It is a variation of TSan that is
easy to implement and more suited to kernel internals, albeit theoretically
less precise than TSan's happens-before.

We do basically two things:

- On every KCSAN_NACCESSES (=2000) memory accesses, we create a cell
describing the access, and delay the calling CPU (10ms).

- On all memory accesses, we verify if the memory we're reading/writing
is referenced in a cell already.

The combination of the two means that, if for example cpu0 does a read that
is selected and cpu1 does a write at the same address, kCSan will fire,
because cpu1's write collides with cpu0's read cell.

The coverage of the instrumentation is the same as that of kASan. Also, the
code is organized in a way similar to kASan, so it is easy to add support
for more architectures than amd64. kCSan is compatible with KCOV.

Reviewed by Kamil.
 1.544 01-Nov-2019  msaitoh Port SMSC LAN87xx 10/100 Ethernet PHY driver from FreeBSD with some cleanup
and IFM_NONE support.
 1.543 30-Oct-2019  msaitoh Add jmphy(4) from OpenBSD.
 1.542 28-Oct-2019  ozaki-r Add vio9p to some kernel configs
 1.541 25-Oct-2019  martin Add support for Nuvoton NCT5104D GPIO chips, as found on PC Engines APU
systems. From Andrew Doran in PR kern/54648.
 1.540 25-Oct-2019  martin whitespace
 1.539 25-Oct-2019  martin Add missing onewire temperature sensors, suggested by Andrew Doran.
 1.538 08-Oct-2019  maxv No I/O ports for TPM-ISA, only MMIO, so remove commented-out options.
 1.537 07-Oct-2019  msaitoh Add support IC Plus IP1000* PHYs. PR/kern 42314 first reported by
Tomokazu HARADA and patch provided by Andrius V.
 1.536 03-Oct-2019  tnn add mcx(4) to GENERIC

Tested on dual-port ConnectX-4 with 25 Gbit/s AOC
 1.535 14-Sep-2019  maxv Add vHCI, a driver which allows to send and receive USB packets directly
from userland via /dev/vhci. Using this, it becomes possible to test and
fuzz the USB stack and all the USB drivers without having the associated
hardware.

The vHCI device has four ports independently addressable.

For each xfer on each port, we create two packets: a setup packet (which
indicates mostly the type of request) and a data packet (which contains
the raw data). These packets are processed by read and write operations
on /dev/vhci: userland poll-reads it to fetch usb_device_request_t
structures, and dispatches the requests depending on bRequest and
bmRequestType.

A few ioctls are available:

VHCI_IOC_GET_INFO - Get the current status
VHCI_IOC_SET_PORT - Choose a vHCI port
VHCI_IOC_USB_ATTACH - Attach a USB device on the current port
VHCI_IOC_USB_DETACH - Detach the USB device on the current port

vHCI has already allowed me to automatically find several bugs in the USB
stack and its drivers.
 1.534 09-Aug-2019  rin xhci(4) is considered stable enough. So, remove misleading comments.

XXX
pullup to netbsd-9
 1.533 07-Aug-2019  maxv Sync with reality.
 1.532 01-Aug-2019  msaitoh Add ena(4).
 1.531 24-Jul-2019  msaitoh branches: 1.531.2;
USE <SPACE>+<TAB>
 1.530 17-Jun-2019  kamil Register UBSAN_ALWAYS_FATAL in kernel configs for kUBSan
 1.529 15-Jun-2019  maxv Add KASAN_PANIC, an option to turn KASAN warning into kernel panics,
requested by Siddharth. While here clarify a little.
 1.528 24-May-2019  nonaka Added drivers for Hyper-V Synthetic Keyboard and Video device.
 1.527 06-May-2019  sevan Use filesystems.config to reduce duplication
 1.526 26-Apr-2019  sevan Enable BUFQ_PRIOCSCAN, CARP, Veriexec by default in GENERIC kernel configs.
On ports without a GENERIC kernel config enable in individul files, e.g evbmips.
Omit on:
atari, dreamcast, emips, epoc32, evbppc/VIRTEX*, ia64, luna68x, mvme68k,
mvmeppc, playstation2, riscv, sun2, sun3, x68k, zaurus due to resource
constraints or port infancy.
 1.525 25-Apr-2019  msaitoh Add gem(4).
 1.524 18-Apr-2019  maya Follow arm64 and provide two sizes of fonts, so a larger one is chosen
for larger displays.
 1.523 18-Apr-2019  christos Yes, we support FFS_EI but not DISKLABEL_EI... How does that make sense?
 1.522 13-Apr-2019  maxv Introduce POOL_QUARANTINE, a feature that creates a window during which a
freed buffer cannot be reallocated. This greatly helps detecting
use-after-frees, because they are not short-lived anymore.

We maintain a per-pool fifo of 128 buffers. On each pool_put, we do a real
free of the oldest buffer, and insert the new buffer. Before insertion, we
mark the buffer as invalid with KASAN. On each pool_cache_put, we destruct
the object, so it lands in pool_put, and the quarantine is handled there.

POOL_QUARANTINE can be used in conjunction with KASAN to detect more
use-after-free bugs.
 1.521 28-Mar-2019  maxv Move NVMM in the "any" class, so that it can be enabled in GENERIC. Add
missing files in files.nvmm, and add NVMM (commented out) in the amd64
GENERIC. Remove the "caveats" section in the man page.
 1.520 01-Mar-2019  nonaka fix typo. pointed out by pgoyette@n.o.
 1.519 01-Mar-2019  pgoyette Rename the MODULE_*_HOOK() macros to MODULE_HOOK_*() as briefly
discussed on irc.

NFCI intended.

Ride the earlier kernel bump - it;s getting crowded.
 1.518 01-Mar-2019  nonaka Update Hyper-V related drivers description.
 1.517 23-Feb-2019  kamil Add KCOV - kernel code coverage tracing device

The KCOV driver implements collection of code coverage inside the kernel.
It can be enabled on a per process basis from userland, allowing the kernel
program counter to be collected during syscalls triggered by the same
process.

The device is oriented towards kernel fuzzers, in particular syzkaller.

Currently the only supported coverage type is -fsanitize-coverage=trace-pc.

The KCOV driver was initially developed in Linux. A driver based on the
same concept was then implemented in FreeBSD and OpenBSD.

Documentation is borrowed from OpenBSD and ATF tests from FreeBSD.

This patch has been prepared by Siddharth Muralee, improved by <maxv>
and polished by myself before importing into the mainline tree.

All ATF tests pass.
 1.516 15-Feb-2019  nonaka Added Microsoft Hyper-V support. It ported from OpenBSD and FreeBSD.

graphical console is not work on Gen.2 VM yet. To use the serial console,
enter "consdev com,0x3f8,115200" on efiboot.
 1.515 01-Jan-2019  maya Add commented out amdgpu.

(Builds, untested on hardware)
 1.514 25-Dec-2018  mlelstv Make ipmi driver available to other platforms.
Add ACPI attachment.
 1.513 14-Dec-2018  jakllsch add cardbus malo(4) to x86 GENERIC and ALL kernels
 1.512 12-Dec-2018  maxv Remove references to "lmc" in the kernel configurations.
 1.511 11-Dec-2018  maya revert previous, nouveau apparently works for some people.
 1.510 11-Dec-2018  maya disable nouveau. it hasn't been functional since the import of new drmkms
code.
 1.509 02-Dec-2018  maxv Introduce KLEAK, a new feature that can detect kernel information leaks.

It works by tainting memory sources with marker values, letting the data
travel through the kernel, and scanning the kernel<->user frontier for
these marker values. Combined with compiler instrumentation and rotation
of the markers, it is able to yield relevant results with little effort.

We taint the pools and the stack, and scan copyout/copyoutstr. KLEAK is
supported on amd64 only for now, but it is not complicated to add more
architectures (just a matter of having the address of .text, and a stack
unwinder).

A userland tool is provided, that allows to execute a command in rounds
and monitor the leaks generated all the while.

KLEAK already detected directly 12 kernel info leaks, and prompted changes
that in total fixed 25+ leaks.

Based on an idea developed jointly with Thomas Barabosch (of Fraunhofer
FKIE).
 1.508 24-Nov-2018  bouyer Add mpii(4), a driver for LSI Megaraid Fusion controllers.
Ported from OpenBSD. This driver is MP-safe.
Note that the earlier fusion controllers (Megaraid 2208, codenamed Thunderbold)
are also supported by mfi(4). mpii will take precedence if both drivers
are enabled.
Tested on a
mfii0 at pci6 dev 0 function 0: "PERC H740P Adapter ", firmware 50.3.0-1512, 819
2MB cache
mfii0: interrupting at ioapic2 pin 2
scsibus0 at mfii0: 64 targets, 8 luns per target
scsibus0: waiting 2 seconds for devices to settle...
sd0 at scsibus0 target 0 lun 0: <DELL, PERC H740P Adp, 5.03> disk fixed
sd0: fabricating a geometry
sd0: 99 GB, 102399 cyl, 64 head, 32 sec, 512 bytes/sect x 209714688 sectors
sd0: tagged queueing
sd1 at scsibus0 target 1 lun 0: <DELL, PERC H740P Adp, 5.03> disk fixed
sd1: fabricating a geometry
sd1: 22254 GB, 22788608 cyl, 64 head, 32 sec, 512 bytes/sect x 46671069696 sectors
sd1: fabricating a geometry

It supports bioctl(8) ioctls, as well as sensors for the BBU and logical
drives.

Sponsored by LIP6.
 1.507 17-Nov-2018  uwe Add commented out options WSEMUL_DEFAULT="\"vt100\""

If WSEMUL_SUN is enabled it becomes the default emulation which is
most likely not what we want here.
 1.506 07-Oct-2018  maxv Make it clear that you need to disable SVS if you enable USER_LDT. I could
make SVS compatible with it, but there has to be someone doing Wine work
first, to justify the effort.
 1.505 06-Sep-2018  maxv Retire the 'midway' driver. Discussed on tech-net@ recently and also three
years ago, part of removing the network ATM code.
 1.504 20-Aug-2018  maxv Add support for kASan on amd64. Written by me, with some parts inspired
from Siddharth Muralee's initial work. This feature can detect several
kinds of memory bugs, and it's an excellent feature.

It can be enabled by uncommenting these three lines in GENERIC:

#makeoptions KASAN=1 # Kernel Address Sanitizer
#options KASAN
#no options SVS

The kernel is compiled without SVS, without DMAP and without PCPU area.
A shadow area is created at boot time, and it can cover the upper 128TB
of the address space. This area is populated gradually as we allocate
memory. With this design the memory consumption is kept at its lowest
level.

The compiler calls the __asan_* functions each time a memory access is
done. We verify whether this access is legal by looking at the shadow
area.

We declare our own special memcpy/memset/etc functions, because the
compiler's builtins don't add the __asan_* instrumentation.

Initially all the mappings are marked as valid. During dynamic
allocations, we add a redzone, which we mark as invalid. Any access on
it will trigger a kASan error message. Additionally, the compiler adds
a redzone on global variables, and we mark these redzones as invalid too.
The illegal-access detection works with a 1-byte granularity.

For now, we cover three areas:

- global variables
- kmem_alloc-ated areas
- malloc-ated areas

More will come, but that's a good start.
 1.503 14-Aug-2018  maxv Replace references to etherip by l2tp. Etherip was already not enabled
anyway.
 1.502 13-Aug-2018  mrg use dev/usb/usbdevices.config, gaining these missing drivers:
slurm(4), uthum(4), umcs(4), uark(4), upgt(4), and usmsc(4).
 1.501 12-Aug-2018  sevan Remove commented out BPFJIT & SLJIT options as they are provided as loadable
modules already.

Heads up by <leot> <christos>
 1.500 10-Aug-2018  sevan Add snippet for bpfjit(4) as both i386 and amd64 are listed as supported.
Ideally BPFJIT should be enabled by default for use with NPF but I haven't
raised the question (no access to email at the moment) hence both are disabled.
 1.499 03-Aug-2018  kamil Register kUBSan in the GENERIC amd64 kernel config

Tested with GCC.
 1.498 01-Aug-2018  maxv Unreference IPF/PF from the x86 config files (amd64, i386, xen), and enable
NPF instead when wanted.
 1.497 31-Jul-2018  khorben Add a port of the umb(4) driver from OpenBSD

The umb(4) driver provides support for USB MBIM (Mobile Broadband
Interface Model) devices.

MBIM devices establish connections via cellular networks such as GPRS,
UMTS, and LTE. They appear as a regular point-to-point network interface, transporting raw IP frames.

Required configuration parameters like PIN and APN have to be set with
umbctl(8), a new tool specific to this driver. The IP address is configured
automatically; the default route and DNS server information have to be set
separately.

The driver is not fully functional yet, it is therefore still marked as
experimental and disabled by default. Any help welcome to complete it!

Tested on NetBSD/amd64, with a Sierra Wireless EM7345 LTE modem on a Lenovo
ThinkPad T440s. No functional change expected otherwise.
 1.496 13-Jul-2018  maxv Remove the X86PMC code I had written, replaced by tprof. Many defines
become unused in specialreg.h, so remove them. We don't want to add
defines all the time, there are countless PMCs on many generations, and
it's better to just inline the event/unit values.
 1.495 12-Jul-2018  maya Add entries for viadrmums to amd64 kernel configs too.

Commented out for GENERIC, same as i386.
 1.494 10-Jul-2018  maya Remove viadrm(4), superseded by viadrmums.

Aside from viadrm using older drm code, it's also dysfunctional right now.
See PR port-i386/53364.
 1.493 07-Jun-2018  thorpej branches: 1.493.2;
Revert changes that pinned-down i2c parent specs. The i2c subsystem
has been enhanced to make this unnecessary.
 1.492 22-May-2018  maxv Clarify the parameters for the SpectreV2 mitigation.

Add:
machdep.spectre_v2.swmitigated
Rename:
machdep.spectre_v2.mitigated -> machdep.spectre_v2.hwmitigated

Change the method string, to combine both the hardware and software
mitigations. swmitigated is set at compile time, hwmitigated can be
set by the user.

Examples:

spectre_v2.swmitigated = 1
spectre_v2.hwmitigated = 0
spectre_v2.method = [GCC retpoline]

spectre_v2.swmitigated = 0
spectre_v2.hwmitigated = 0
spectre_v2.method = (none)

spectre_v2.swmitigated = 1
spectre_v2.hwmitigated = 1
spectre_v2.method = [GCC retpoline] + [Intel IBRS]
 1.491 15-May-2018  thorpej Fully specifiy the location of indirectly-configured I2C devices. In
particular, the parent spec must not be wild-carded, as doing so doesn't
work well on systems where more than one I2C bus is present.

N.B. The x86 platforms are sort of a mess, here... legacy indirect
config and ACPI direct config sort of smashed together with the
same config file directives.
 1.490 11-May-2018  maya Enable bwfm at pci.
 1.489 08-Apr-2018  mrg turn on GCC spectre v2 mitigation options.

XXX: amd64 ALL doesn't build for me right now
 1.488 07-Apr-2018  mrg actually do what the previous change said:
don't turn on the new 'SPECTRE_V2_GCC_MITIGATION' option yet.
 1.487 07-Apr-2018  mrg add an SPECTRE_V2_GCC_MITIGATION option to x86 kernels, that turns
on the GCC spectre v2 mitigation options.

XXX: pullup-8.
XXX: turn on in all kernels.
 1.486 22-Mar-2018  rin Add njs(4) at pci(4) and cardbus(4).
 1.485 26-Feb-2018  maxv branches: 1.485.2;
Enable SVS by default.
 1.484 27-Jan-2018  pgoyette Update amdzentemp(4) attachment info. Also for ALL, remove duplicate
entry for amdtemp(4).
 1.483 26-Jan-2018  maxv Add etherip, so that we at least know it exists on amd64.
 1.482 25-Jan-2018  christos add amdzentemp
 1.481 13-Jan-2018  christos added commented out AUTOFS pseudo-device entries
 1.480 10-Jan-2018  knakahara add ipsec(4) interface to amd64/GENERIC and amd64/ALL configs.
 1.479 09-Jan-2018  christos Merge autofs support from: Tomohiro Kusumi
XXX: Does not work yet
 1.478 07-Jan-2018  maxv Don't enable SVS yet.
 1.477 07-Jan-2018  maxv Add a new option, SVS (for Separate Virtual Space), that unmaps kernel
pages when running in userland. For now, only the PTE area is unmapped.

Sent on tech-kern@.
 1.476 31-Dec-2017  christos explain that a.out never shipped on x86_64 and put back compat_nomid
 1.475 10-Dec-2017  bouyer Add dwiic, ihidev and ims
 1.474 09-Dec-2017  riastradh Attach wsmouse at wsmousedev on x86 so modular mice have a hope.

As noted on tech-kern:

https://mail-index.NetBSD.org/tech-kern/2017/12/08/msg022708.html
 1.473 05-Dec-2017  dholland Add missing wsbell, commented out with a note that it's apparently only
a module by default.

This way people making their own configs have half a prayer of
realizing they might need to turn it on, instead of just not getting
beeps any more for no clear reason.

XXX: Wasn't the agreement after the last round of module flamage that
XXX: things shouldn't be module-only in GENERIC?
 1.472 05-Dec-2017  dholland Sort the file system options by which fs they apply to.
 1.471 02-Dec-2017  maxv Drop COMPAT_13 on amd64, already not enabled. Reduces the number of
critical places.
 1.470 02-Dec-2017  maxv Drop COMPAT_10 on amd64. The support for it comes down to one ifdef in
trap.c - code that is incorrect anyway, there were originally three lcall
LDT slots, and here only one instruction is decoded.

Given that one of these slots was used by BSDi's syscall, also remove the
references to COMPAT_NOMID to make clear we don't support that (it already
is not enabled).

Note: for some reason, COMPAT_10 does not even compile, because there are
"multiple definitions of _KERNEL_OPT_COMPAT_...", and I don't really
understand where this comes from.
 1.469 25-Nov-2017  jmcneill Add qemufwcfg (QEMU Firmware Configuration device)
 1.468 06-Nov-2017  rin Revive commented out DISKLABEL_EI option to kernel configuration files
that contain FFS_EI option.
 1.467 19-Oct-2017  jmcneill add bwfm
 1.466 14-Sep-2017  mrg clean up COMPAT_* options for native netbsd code:
- new series of files that are useful for saying "i want everything
since netbsd 1.4", etc.
- use the fact COMPAT_* options have future dependancies to remove
many redundant options.

removes about 3000 lines total across kernel configuration files.
tested about 30 random kernels in the changed list.
 1.465 13-Sep-2017  sevan Remove support for VERIFIED_EXEC_FP_RMD160, VERIFIED_EXEC_FP_SHA1, and VERIFIED_EXEC_FP_MD5 options.
These algorithms are either broken or on their way to being broken.

Discussed on tech-security
http://mail-index.netbsd.org/tech-security/2017/08/21/msg000936.html

ok riastradh
 1.464 13-Aug-2017  christos Add ALPS pms support
 1.463 04-Aug-2017  maxv Revert my changes, and re-enable COMPAT_NOMID, COMPAT_09 and COMPAT_43.
Several compat options happen to be dependent on the compat_43_* functions,
the availability of which is (wrongfully) controlled with COMPAT_43. Same
for COMPAT_09.
 1.462 28-Jul-2017  maxv After a careful review, and all things considered, disable compat43 by
default on amd64. The use case is limited, the potential for damage too
high, and it is safer to run a BSD4.3 binary on i386 since the kernel does
not have to go through netbsd32 - which may not correctly reproduce i386.
 1.461 22-Jul-2017  maxv Add USER_LDT, commented out for now.
 1.460 12-Jul-2017  maxv Enable PMCs by default.
 1.459 27-May-2017  bouyer branches: 1.459.2;
Add options CAN and pseudo-device canloop to ALL kernel configs.
Add the same commented out to i386/amd64 GENERIC and OLIMEXLIME2 (A20-based).
Also add commented out awincan0 in OLIMEXLIME2.
 1.458 25-May-2017  para follow u3ginit driver rename to umodeswitch
 1.457 18-Apr-2017  riastradh gson@ informs me the Alea I and II have the same USB product id.

Thus, ualea(4) should work for both of them. Rename USB product id
ARANEUS ALEA_II to ARANEUS ALEA to reflect this.

No functional change intended, except perhaps via usbdevs.
 1.456 17-Apr-2017  riastradh New rndsource driver for Araneus Alea II TRNG USB devices.

Disabled by default in x86/GENERIC and usbdevices.config pending
review and testing without rump ugenhc in the way, but enabled in
x86/ALL for compile-testing.

(Hi gson! Finally found a round tuit in my pocket, next to a certain
rectangular one.)
 1.455 10-Mar-2017  maxv PMCs for amd64 - still disabled, like i386.
 1.454 26-Feb-2017  rin Comment out DISKLABEL_RDB as it is too specific for general usage.
(Also add commented out that entry for GENERIC on amd64; I forgot it)
 1.453 26-Feb-2017  maya Remove commented DISKLABEL_EI for strictly little endian architectures

It will never be useful.
 1.452 19-Feb-2017  rin PR kern/51208
Add DISKLABEL_EI option (and also FFS_EI if missing), commented out except for
ALL on amd64 and i386.
 1.451 16-Feb-2017  knakahara add l2tp(4) to amd64/GENERIC and amd64/ALL config.
 1.450 12-Jan-2017  ryo branches: 1.450.2;
white space police
 1.449 31-Dec-2016  christos Add commented out TCP_SIGNATURE
 1.448 18-Dec-2016  dholland Whitespace.
 1.447 13-Dec-2016  christos wildcard speaker attachments, now that we can handle many of them.
 1.446 10-Dec-2016  christos remove VAUDIOSPEAKER for now, will be done differently.
 1.445 09-Dec-2016  christos kill PCPPISPEAKER
 1.444 08-Dec-2016  nat Add a synthesized pc beeper and keyboard bell for platforms with an audio
device.
 1.443 26-Nov-2016  christos mention PAX_SEGVGUARD dependency on FILEASSOC
 1.442 26-Nov-2016  dholland 1.6 was the first amd64 release. (although it didn't really work too well
before -5)
 1.441 26-Nov-2016  dholland Note that really old compat is only useful for running 32-bit binaries.

XXX: someone please indicate what the oldest possible extant x86_64
binaries are; I can't find an authoritative source.
 1.440 25-Nov-2016  dholland fileassoc is used by PaX as well as veriexec - update note accordingly.
 1.439 25-Nov-2016  dholland sort iwm* before iwn*
 1.438 25-Nov-2016  dholland The compat options should all be in one block.
 1.437 07-Aug-2016  christos rename ifmpls to mpls, so we don't have if_ifmpls...
 1.436 27-Jul-2016  msaitoh Add sdtemp(4)
 1.435 21-Jun-2016  nonaka branches: 1.435.2;
add sdhc(4) at acpi to i386 and amd64 GENERIC kernel config.
 1.434 14-Jun-2016  pgoyette Re-arrange PAX_ASLR options to keep the _DEBUG next to the main option.
 1.433 14-May-2016  christos Turn on MPROTECT on GENERIC and both MPROTECT and ASLR on XEN*
 1.432 01-May-2016  nonaka Added nvme(4) for Non-Volatile Memory Host Controller Interface devices.
Ported from OpenBSD.
 1.431 23-Apr-2016  skrll Merge nick-nhusb

- API / infrastructure changes to support memory management changes.
- Memory management improvements and bug fixes.
- HCDs should now be MP safe
- conversion to KERNHIST based debug
- FS/LS isoc support on ehci(4).
- conversion to kmem(9)
- Some USB 3 support - mostly from Takahiro HAYASHI (t-hash).
- interrupt transfers now get proper DMA operations
- general bug fixes
- kern/48308
- uhub status notification improvements
- umass(4) probe fix (applied to HEAD already)
- ohci(4) short transfer fix
 1.430 13-Apr-2016  riastradh Enable nouveau by default again in x86 GENERIC.
 1.429 10-Apr-2016  christos We don't need TRAP_SIGDEBUG
 1.428 10-Apr-2016  christos - Turn on ASLR by default
- Add PAX_MPROTECT_DEBUG flag
 1.427 19-Mar-2016  gdt Disable uscanner in all kernel configs

As discussed on current-users@, SANE uses ugen via libusb and not
uscanner, so users are not well served by having uscanner. Consensus
is that addressing how to adjust permissions for scanners should not
block restoring basic functionionality.

(Compile-tested only, but there are multiple reports of this being the
right approach.)
 1.426 16-Mar-2016  christos Add PAX_SEGVGUARD disabled.
 1.425 05-Mar-2016  riastradh Revert to disabling nouveau by default in x86 GENERIC.

Haven't had time to debug the issues that seem to affect pretty much
everyone. Maybe soon!
 1.424 13-Feb-2016  riastradh Add nouveau to x86 GENERIC kernels.
 1.423 30-Jan-2016  christos compile full symbol table for CTF so FBT can get function arguments.
 1.422 22-Jan-2016  riz Enable KDTRACE_HOOKS on i386 and amd64 GENERIC.
 1.421 10-Jan-2016  christos scsibus at scsi should work; if it does not...
 1.420 10-Jan-2016  christos PR/50636: Ryo ONODERA: Add scsibus to vioscsi
 1.419 05-Jan-2016  msaitoh Add ismt(4).
 1.418 30-Oct-2015  christos add vioscsi
 1.417 21-Sep-2015  nonaka PR/50261: Added newer Toshiba hotkeys support.
 1.416 27-Aug-2015  nonaka Added rtwn(4) for Realtek RTL8188CE/RTL8192CE PCIe 802.11b/g/n wireless network
devices. Ported from OpenBSD.
 1.415 13-Aug-2015  msaitoh Compile ixv(4) by default.
 1.414 08-Aug-2015  maxv Remove KMEMSTATS.
 1.413 03-May-2015  pgoyette Update to include the tco driver (it was previously included as part of
ichlpcib).
 1.412 23-Apr-2015  pgoyette Add a space after "options" and before the <tab> for conformity
with other options. Among other things, this allows one to
remove the # comment character without breaking the vertical
alignment.
 1.411 10-Mar-2015  msaitoh Modify to make Intel Intel 10G Ethernet (ixg(4)) virtual function ixv(4)
compilable. Not completed yet. It's required to use MSI-X.
 1.410 06-Mar-2015  riastradh Fix tabbing of drm lines.
 1.409 06-Mar-2015  riastradh Fix commented nouveau in amd64/GENERIC. Add nouveau to amd64/ALL.

Remove NV_DEBUG from amd64/ALL -- it breaks nouveau, and I can't find
any use of it in src/sys outside arch/atari/dev/nvram.c, which surely
has no relevance to amd64.

(Nouveau has an internal NV_DEBUG(...) macro for debug messages.)
 1.408 13-Feb-2015  nonaka iwm(4) works now, but 2.4GHz only.

> iwm0 at pci2 dev 0 function 0: Intel Dual Band Wireless AC 3160 (rev. 0x83)
> iwm0: interrupting at ioapic0 pin 18
> iwm0: hw rev: 0x160, fw ver 25.228 (API ver 9), address XX:XX:XX:XX:XX:XX
> iwm0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
> iwm0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps
 1.407 07-Feb-2015  pooka Add a driver for Intel Centrino 7260 and similar wireless cards.
Supported devices should more or less match ones supported
by the Linux iwlwifi mvm driver. Sponsored by genua mbh for OpenBSD.

This is probably the world's first Canadian cross device driver: it was
created for OpenBSD by writing and porting a NetBSD driver which was
developed in a rump kernel in Linux userspace.

Note: I don't have access to the hardware anymore, so this version is
not tested and not enabled by default. While I tried to be careful in
adding the NetBSD bits back, it's probable that there's a snafu or two.
Feel free to send private email in case you have the hardware and there
are issues.
 1.406 19-Dec-2014  msaitoh Sync gpio related lines with i386/conf/GENERIC.
 1.405 12-Dec-2014  christos Add options to run a.out i386 binaries (commented out)
 1.404 16-Nov-2014  manu branches: 1.404.2;
Remove unused extended attributes kernel options

As Masao Uebayashi pointed to me, UFS_EXTATTR_AUTOSTART, LFS_EXTATTR_AUTOSTART
and UFS_EXTATTR_AUTOCREATE are not used anywhere in the code. Remove them
as they have been obsolete for a long time:
UFS_EXTATTR_AUTOSTART was replaced by mount -o extattr
LFS_EXTATTR_AUTOSTART was created to match obsolete UFS_EXTATTR_AUTOSTART
UFS_EXTATTR_AUTOCREATE was replaced by sysctl vfs.ffs.extattr_autocreate
 1.403 12-Nov-2014  manu Support for UFS1 extended attributes in GENERIC and GENERIC-like kernels

This change just brings UFS1 extended attribute *support* in the kernel,
extended attributes are not enabled unless three conditions are met:
1) filesystem is UFS1 (newfs -O1)
2) .attribute/system and .attribute/user directories are created at fs root
3) filesystem is mounted with -o extattr

Some GENERIC kernels are obviously memory constrained, the extended
attributes options were not enabled for them, but just added commented out.
(kernel were considered memory constrained if QUOTA option was disabled)
 1.402 02-Nov-2014  christos make DRMKMS the default on GENERIC and comment out the legacy drivers.
 1.401 26-Oct-2014  tls Add viornd(4), a driver for the VirtIO entropy source available on
QEMU, KVM, and Google Compute Engine. From OpenBSD.
 1.400 18-Oct-2014  uebayasi Install agp_* drivers where pchb(4) is installed except INSTALL_FLOPPY.

XXX
Config around agp(4) is done in quite wrong direction.
"pchb <- (agpbus) <- agp <- agp_*"
should be:
"pchb <- (pcibus) <- agp_* <- (agpbus) <- agp"
 1.399 19-Sep-2014  christos Add HDAUDIOVERBOSE
 1.398 19-Sep-2014  christos Disable BSDLABEL and MBR DKWEDGE methods again since sysinst does not work
with wedges.
 1.397 18-Sep-2014  wiz Add commented out KDTRACE_HOOKS line.
 1.396 24-Aug-2014  jnemeth Create an "options MODULAR_DEFAULT_AUTOLOAD" config option and add
it to all kernel configs that contain "options MODULAR". This
option turns on module autoloading by default (which is the current
default). This allows people who don't want module autoloading on
by default to disable it by simply removing/commentting this line.
 1.395 23-Aug-2014  dholland Systematize (and in many cases, fix) the comments on options COMPAT_NN.

There are quite a few configs that are missing some COMPAT_NN options
in ways that don't make sense; this should probably get cleaned up
too, but for the time being I've not added or removed anything.
 1.394 18-Aug-2014  christos - Enable Wedge support for MBR/BSDLABEL where it was commented out.
- Add apple partition support where it was missing
- Add comments where missing
 1.393 16-Aug-2014  apb Add "options COMPAT_70" to all kernel configuration files that
already had "options COMPAT_60".
 1.392 25-Jul-2014  dholland branches: 1.392.2;
Fix description of DIAGNOSTIC in x86 kernels.
 1.391 16-Jun-2014  dsl Comment out the xhci entries.
The driver really doesn't work well enough to be generally useful.
 1.390 12-Jun-2014  alnsn Revert the previous (comment only change).
 1.389 12-Jun-2014  alnsn Add a comment about disabling INET6. Should fix kern/48901.
 1.388 10-Jun-2014  hikaru Add VMware VMXNET3 ethernet driver from OpenBSD, vmx(4).
 1.387 29-May-2014  christos enable IPSEC
 1.386 21-Apr-2014  chs add malo at pcmcia.
 1.385 08-Apr-2014  riastradh Enable options VND_COMPRESSION in amd64/GENERIC.
 1.384 08-Apr-2014  christos add ixg
 1.383 24-Mar-2014  szptvlfn branches: 1.383.2;
fix manual section numbering of sysctl.
thanks wiz@
 1.382 19-Mar-2014  nonaka Add a driver for Realtek RTS5209/RTS5229 Card Reader.
Ported from OpenBSD.
 1.381 26-Oct-2013  nonaka Add driver for ASIX AX88178a and AX88179 Ethernet interface.
Ported from OpenBSD.
 1.380 23-Oct-2013  matt Add xhci device
 1.379 30-Jun-2013  rmind G/C PFIL_HOOKS from the kernel configs.
 1.378 10-Jun-2013  kardel branches: 1.378.2;
adjust soekrisgpio driver to NetBSD
 1.377 05-Jun-2013  christos remove obsolete networking options
 1.376 04-Jun-2013  christos sync drm with i386
 1.375 28-May-2013  kiyohara Add udsir.
 1.374 03-May-2013  jakllsch Enable sdhc* at cardbus? in amd64 GENERIC. As it is already in i386
GENERIC. sdhc(4) has had working detach support for a while now too.
 1.373 27-Apr-2013  christos more bogus number removal
 1.372 27-Apr-2013  christos the bogus number police
 1.371 27-Apr-2013  christos remove confusing numeric locators where they are unused.
 1.370 06-Apr-2013  martin athn at pci has been successfully tested
 1.369 30-Mar-2013  christos patches for new wifi devices.
 1.368 02-Mar-2013  christos Under FAST_IPSEC, IPSEC_ESP is mandatory; GC it.
 1.367 01-Mar-2013  joerg Retire OSI network stack. OK core@
 1.366 20-Dec-2012  christos fix cut-n-paste.
 1.365 17-Oct-2012  apb Add "options COMPAT_60" to all kernel configuration files
that already had "options COMPAT_50".
 1.364 23-Sep-2012  chs add vmt entry to GENERIC.
standardize commented pfsync and npf entries.
 1.363 01-Sep-2012  jakllsch branches: 1.363.2;
Rename RT2500USB driver to ural(4) as it was originally in OpenBSD,
as ural(4) and ral(4) do not actually share any code.

Enable ural(4) in hpcarm WZERO3 kernel too, as it will now build.

Fixes PR#43520.
 1.362 01-Sep-2012  jakllsch back out unintentional change in 1.352.
 1.361 27-Aug-2012  dholland whitespace
 1.360 24-Aug-2012  dholland Restore comment heading lost during the MODULAR thrashing.
 1.359 01-Aug-2012  matt Enable FFS_EI (let's be more endian tolerant).
 1.358 30-Jul-2012  degroote Add malo(4) entry in various kernel configuration
 1.357 14-Jun-2012  riz Add urtw(4) to i386/amd64 GENERIC.
 1.356 05-Jun-2012  abs Adjust the WSDISPLAY_COMPAT_USL comment to mention wsconscfg, to at least
give a hint that its not just for third party compat. No functional change.
 1.355 30-May-2012  nonaka Add a driver for Ralink Technology RT2700U/RT2800U/RT3000U USB IEEE
802.11a/b/g/n wireless network devices, ported from OpenBSD by FUKAUMI Naoki,
arranged by me.
 1.354 19-Apr-2012  bouyer Add mpii(4), a driver for LSI Logic Fusion-MPT Message Passing Interface II
SAS controllers. Ported from OpenBSD.
 1.353 13-Apr-2012  cegger Replace amdtempbus with amdnb_miscbus.
This allows us to have independent drivers on the same device (northbridge f3)
each coming with a certain functionality/feature.
This way we do not need to mess with amdtemp(4) to utilize other features.
 1.352 07-Apr-2012  christos add apple autodiscovery.
 1.351 25-Mar-2012  nonaka Added urtwn(4), a driver for Realtek RTL8188CU/RTL8192CU USB IEEE 802.11b/g/n wireless network devices.
 1.350 10-Mar-2012  joerg P1003_1B_SEMAPHORE is no longer optional.
 1.349 28-Feb-2012  mbalmer Add commented out DDB_COMMANDONENTER example, enable pwdog(4).
 1.348 22-Jan-2012  christos branches: 1.348.2;
add a tpm driver from bsssd.sourceforge.net
 1.347 17-Jan-2012  veego Back out all changes for rev 1.346 which are not related to PR/45850
Should fix the reported build problem from Paul Goyette
 1.346 17-Jan-2012  christos PR/45850: Pierre Pronchery: USB multi-touch panels are not supported
 1.345 16-Jan-2012  jmcneill add irmce(4), cir@irmce, and cir@emdtv
 1.344 15-Jan-2012  jmcneill add & enable digital tv capture support
 1.343 13-Jan-2012  cegger Support CPU microcode loading via cpuctl(8).
Implemented and enabled via CPU_UCODE kernel config option
for x86 and Xen Dom0.
Tested on different AMD machines with different
CPU families.

ok wiz@ for the manpages
ok releng@
ok core@ via releng@
 1.342 31-Dec-2011  christos Add an ipad
 1.341 18-Dec-2011  dholland WABPL is no longer considered experimental (has not been for some time)
so update its comment in config files.
 1.340 22-Nov-2011  tls branches: 1.340.2;

The rnd pseudo-device is not really optional, because it is in the same
source file as the entropy-pool code itself. Move it to std. This
will be cleaned up more when I split the sources up as they should be.

This fixes build breaks on several ports. Thanks to Havard Eidnes for
pointing them out.
 1.339 13-Nov-2011  mbalmer Add commented out entry for gpiopwm(4).
 1.338 30-Oct-2011  hannken branches: 1.338.2;
Import of the virtio driver written by MINOURA Makoto <minoura@netbsd.org>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.

Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.

See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.
 1.337 30-Aug-2011  mbalmer Add gpio entries, commented out, since I am working with them as modules atm.
 1.336 30-Aug-2011  jmcneill revert previous
 1.335 30-Aug-2011  jruoho Comment out the legacy bktr(4) from the GENERICs.
 1.334 18-Aug-2011  jakllsch Attach amdtemp(4) at pchb(4) instead of in place of pchb(4).

Should fix PR#45268.
 1.333 11-Aug-2011  mbalmer Add commented out sample entry for pwdog(4).
 1.332 09-Aug-2011  jmcneill remove commented out entries for emdtv, auvitek, and dtv
 1.331 08-Aug-2011  jmcneill remove dtv (available as a module)
 1.330 08-Aug-2011  jakllsch Add P1003_1B_SEMAPHORE to match i386.
 1.329 08-Aug-2011  jakllsch Finish reverting premature modularization of amd64 kernels.
 1.328 30-Jul-2011  jmcneill add PCKBD_CNATTACH_MAY_FAIL to be consistent with i386
 1.327 23-Jul-2011  jakllsch Enable or note aubtfwl(4) wherever ubt(4) is enabled or noted.
 1.326 21-Jul-2011  jakllsch Add wmieeepc(4) to amd64 GENERIC.
 1.325 21-Jul-2011  jakllsch Add dtv* at dtvbus? because I'll get weird looks if I introduce a #if NDTV > 0,
and also if I don't un-Break the build.
 1.324 20-Jul-2011  jakllsch Add cxdtv(4) and urndis(4). Also, two slight cosmetic changes.
 1.323 13-Jul-2011  jruoho A driver for HP 3D DriverGuard; a LIS3LV02DL-based accelerometer. Tested on
HP NC4400. Like aps(4), this is commented out in the GENERIC kernels.
 1.322 03-Jul-2011  bouyer Add back DIAGNOSTIC option to x86 GENERIC kernels, as discussed on tech-kern.
This will have to be commented out on release branches.
 1.321 21-Jun-2011  jruoho By default, enable wmihp(4) instead of hpqlb(4), as it has a better chance
of working with a greater number of HP laptops. Ok cegger@.
 1.320 14-Jun-2011  jruoho Try to attach hpet(4) also via a specific HPET table. Fixes PR kern/43702.
 1.319 28-May-2011  ryo branches: 1.319.2;
many whitespace cleanup.
 1.318 01-Apr-2011  jruoho Enable acpicpu(4) by default.
 1.317 06-Mar-2011  bouyer merge the bouyer-quota2 branch. This adds a new on-disk format
to store disk quota usage and limits, integrated with ffs
metadata. Usage is checked by fsck_ffs (no more quotacheck)
and is covered by the WAPBL journal. Enabled with kernel
option QUOTA2 (added where QUOTA was enabled in kernel config files),
turned on with tunefs(8) on a per-filesystem
basis. mount_mfs(8) can also turn quotas on.

See http://mail-index.netbsd.org/tech-kern/2011/02/19/msg010025.html
for details.
 1.316 04-Mar-2011  jruoho Move INTEL_ONDEMAND_CLOCKMOD -- or odcm(4) -- to the cpufeaturebus.
 1.315 27-Feb-2011  jruoho Move acpicpu(4) from "acpinodebus" to "cpufeaturebus".
 1.314 24-Feb-2011  jruoho Move PowerNow! to the cpufeaturebus.
 1.313 23-Feb-2011  jruoho Move ENHANCED_SPEEDSTEP, or henceforth est(4), to the cpufeaturebus.
 1.312 23-Feb-2011  jmcneill add alc@pci
 1.311 21-Feb-2011  pooka Put coredumps back as a built-in. Until it can autoload or something,
there's no point in causing user-visible (and test-visible)
regressions.
 1.310 20-Feb-2011  jruoho Modularize coretemp(4). Ok jmcneill@.
 1.309 19-Feb-2011  jmcneill add VCONS_DRAW_INTR
 1.308 18-Feb-2011  christos add ifmpls since MPLS was added
 1.307 16-Feb-2011  jym Per mrg@ request, add MFS as default builtin, for things like init(8).

XXX should be replaced by TMPFS eventually.
 1.306 16-Feb-2011  jruoho Add (commented) aps(4) from i386 GENERIC.
 1.305 16-Feb-2011  jym Build certain file-systems and options(7) as module(7). 32 and 64 bits
support are still builtin, as well as FFS, NFS, TMPFS, and most COMPAT
code. Saves approx. 750kiB.

Reflect this in INSTALL kernel, where we have to support more file systems
statically.

See http://mail-index.netbsd.org/port-amd64/2011/02/13/msg001318.html
 1.304 14-Feb-2011  hannken Initial implementation of ibmhawk(4) driver for sensors behind the IBM Hawk
on-board Integrated Systems Management Processor found on some eServers.

Tested on an IBM eServer x335.
 1.303 13-Feb-2011  jym Missing MPLS options (commented out).
 1.302 11-Feb-2011  jmcneill attach drm hw drivers to 'drm' not 'vga'
 1.301 06-Feb-2011  jmcneill - add support for using compressed images as splash images
- retire SPLASHSCREEN_PROGRESS and SPLASHSCREEN_IMAGE options
 1.300 26-Jan-2011  pooka Add bwi from PR kern/40279. There is no know case of testing the
driver on amd64/i386, but if it doesn't work at least we're more
likely to get a PR instead of people wondering about lacking driver
support.
 1.299 17-Jan-2011  jmcneill branches: 1.299.2;
add acpiwdrt
 1.298 09-Jan-2011  jruoho branches: 1.298.2;
Add a dummy-driver for ACPI fans.
 1.297 09-Jan-2011  jruoho Remove APM. (Already commented out.)
 1.296 05-Jan-2011  jruoho Add a driver for ACPI power meters.
 1.295 03-Jan-2011  tsutsui Xref module(7) in comments.
 1.294 27-Dec-2010  jmcneill add 'uaudio* at usbifif?' so uaudio can attach to something other than
a hub
 1.293 27-Nov-2010  christos add ihphy
 1.292 23-Nov-2010  hannken Remove unused count from pseudo-device md.
 1.291 13-Nov-2010  jnemeth Add new et(4)/etphy(4) devices.
 1.290 10-Nov-2010  dholland <space><tab>

I went and wrote a gizmo to automate this a while back, but I seem to
have *lost* the thing. grr.
 1.289 05-Nov-2010  gsutre Merge ACPI Fujitsu Driver. Provides support for hotkeys and other
built-in components through vendor-specific ACPI devices.

ok jruoho@
 1.288 03-Nov-2010  christos add otus
 1.287 24-Oct-2010  jruoho Add acpiwmi(4) mappings for MSI laptops.

XXX: It may be necessary to fix PR # 43659 before this works on all models.
 1.286 12-Oct-2010  gsutre Merge ACPI display driver. Provides generic support for brightness
control and output switching, through ACPI video extensions.

TODO: use wsconsctl(8) instead of sysctl(8) for brightness control.

ok jruoho@
also discussed with cegger@ and jmcneill@
 1.285 22-Aug-2010  rmind Import NPF - a packet filter. Some features:

- Designed to be fully MP-safe and highly efficient.

- Tables/IP sets (hash or red-black tree) for high performance lookups.

- Stateful filtering and Network Address Port Translation (NAPT).
Framework for application level gateways (ALGs).

- Packet inspection engine called n-code processor - inspired by BPF -
supporting generic RISC-like and specific CISC-like instructions for
common patterns (e.g. IPv4 address matching). See npf_ncode(9) manual.

- Convenient userland utility npfctl(8) with npf.conf(8).

NOTE: This is not yet a fully capable alternative to PF or IPFilter.
Further work (support for binat/rdr, return-rst/return-icmp, common ALGs,
state saving/restoring, logging, etc) is in progress.

Thanks a lot to Matt Thomas for various useful comments and code review.
Aye by: board@
 1.284 08-Aug-2010  chs add more (commented-out) spdmem instances for HP xw-series workstations.
 1.283 23-Jul-2010  jakllsch Almost entirely rework Intel Firmware Hub random number generator support.

This introduces fwhrng(4) which attaches via ichlpcib(4), replacing
the rnd(4) support in pchb(4).
 1.282 18-Jul-2010  jruoho Merge a driver for ACPI CPUs with basic support for processor power states,
also known as C-states. The code is modular and provides an easy way to add
the remaining functionality later (namely throttling and P-states).

Remarks:

1. Commented out in the GENERICs; more testing exposure is needed.

2. The C3-state is disabled for the time being because it turns off
timers, among them the local APIC timer. This may not be universally
true on all x86 processors; define ACPICPU_ENABLE_C3 to test.

3. The algorithm used to choose a power state may need tuning. When
evaluating the appropriate state, the implementation uses the
previous sleep time as an indicator. Additional hints would include
for example the system load.

Also bus master activity is evaluated when choosing a state. The
usb(4) stack is notorious for such activity even when unused.
Typically it must be disabled in order to reach the C3-state,
but it may also prevent the use of C2.

4. While no extensive empirical measurements have been carried out, the
power savings are somewhere between 1-2 W with C1 and C2, depending
on the processor, firmware, and load. With C3 even up to 4 W can be
saved. The less something ticks, the more power is saved.

ok jmcneill@, joerg@, and discussed with various people.
 1.281 02-Jun-2010  dholland Remove orphaned heading "Mice"
 1.280 02-Jun-2010  dholland COMPAT_43 should not be sorted between COMPAT_40 and COMPAT_50.
 1.279 22-May-2010  plunky add btmagic(4) where other Bluetooth drivers are listed
 1.278 08-May-2010  mrg enable IPFILTER_COMPAT in all kernels that have ipfilter already.
canonicalise several of the ipf option segments in various files
(this mostly means adding commented out IPFILTER_DEFAULT_BLOCK,
or adding commented or uncommented IPFILTER_LOG or IPFILTER_LOOKUP
option statements.)

i built about 20 of these kernels to check, but not all of them.
 1.277 16-Apr-2010  pooka Remove unused count (invariably "4") from pseudo-device fss.
 1.276 09-Apr-2010  ahoka revert last change, amd64 doesnt have monolith so dont remove pad.
 1.275 09-Apr-2010  ahoka Remove pad from GENERIC, add to MONOLITH, we have it as a module now.
 1.274 08-Apr-2010  jruoho Add WMI mappings for HP laptops. Requested by cegger@.
Thanks to apb@ and cegger@ for initial testing.

XXX: This conflicts with hpqlb(4). Someone with the suitable hardware needs
to complete the list of hotkeys before -- and if -- this can replace
hpqlb(4). For now, the driver was left uncommented in the GENERICs.
 1.273 08-Apr-2010  jruoho Add wmidell(4).
 1.272 28-Mar-2010  dholland sort a couple things
 1.271 07-Mar-2010  plunky branches: 1.271.2;
add uhso(4) device where appropriate
- follow the lead of other USB driver declarations wrt commented out
- (cross-)build tested all these kernels
 1.270 06-Mar-2010  cnst remove aiboost(4) from GENERICs, since it cannot win in autoconf(9) over aibs(4); ok pgoyette
 1.269 22-Feb-2010  pgoyette Correct spelling of smscmon and add (commented out) to GENERICs
 1.268 22-Feb-2010  ahoka Add SPLASH example, like in i386.
 1.267 21-Feb-2010  cnst New wbsio(4) driver for Winbond Super I/O attachment of lm(4) on any port.

http://mail-index.netbsd.org/tech-kern/2010/02/17/msg007338.html

Reviewed by <pgoyette>, <tech-kern>.
 1.266 09-Feb-2010  cnst New aibs(4) driver for ASUSTeK AI Booster (ACPI ATK0110) hardware monitor
with limit support.

http://thread.gmane.org/gmane.os.netbsd.devel.kernel/35654

Reviewed by <pgoyette>, <jruoho> and <tech-kern>.
 1.265 08-Feb-2010  pgoyette Add flags to all instances of lm(4), add a reference to man page
 1.264 06-Feb-2010  pgoyette branches: 1.264.2;
Add acpismbus enries - commented out!
 1.263 31-Jan-2010  jruoho Remove ACPICA_PEDANTIC.
 1.262 07-Jan-2010  tnn uhmodem(4) is superseded by u3g(4) and u3ginit(4).
Prepare for uhmodem(4) removal by not building it anymore.
This may fix PR kern/41174.
 1.261 07-Jan-2010  martin Add the u3ginit driver to all configs which have the u3g driver
 1.260 23-Dec-2009  pooka unifdef -D UGEN_BULK_RA_WB

Default behaviour unchanged, the feature must still be explicitly
enabled for a ugen fd.
 1.259 05-Dec-2009  pooka Remove the portalfs kernel file system driver. Replace mount_portal(8)
with a version based on puffs. User functionality remains the same.
 1.258 03-Dec-2009  sborrill Add udl(4)
 1.257 02-Oct-2009  jmcneill PR# kern/42139: ACPI WMI: new driver

Import acpiwmi(4) from Jukka Ruohonen. From the PR:

Attached is a driver that implements ACPI WMI API:

http://www.microsoft.com/whdc/system/pnppwr/wmi/wmi-acpi.mspx

The WMI is used to provide a generic interface for OEMs to use certain
platform/laptop-specific additions to the standard ACPI in a somewhat
portable way. These can be hotkeys for additional buttons, different event
handlers (wireless kill switch, lid switch, etc.), and so on. At least HP
and Acer use it by default nowadays.

The benefit of this interface would be portability. For an example, instead
of hpqlb(4) that works only with certain HP models, we could have a generic
HP WMI-driver that should work in theory across all HP laptops. On many new
laptops WMI may also be the only way to access laptop/manufacturer-specific
features.
 1.256 30-Sep-2009  jmcneill Need sdmmc* at wb?
 1.255 30-Sep-2009  jmcneill wss@acpi doesn't make much sense on amd64, so remove it
 1.254 30-Sep-2009  jmcneill add and enable wb(4)
 1.253 20-Sep-2009  christos add toshide
 1.252 07-Sep-2009  jmcneill Switch on hdaudio(4)
 1.251 07-Sep-2009  jmcneill Refer to hdaudio as 'High Definition Audio', not
'Intel High Definition Audio' as many vendors implement the HD audio spec.
 1.250 06-Sep-2009  sborrill hdaudio(4) is a standards-compliant driver for Intel High Definition Audio.
It will replace azalia(4) after testing.

To use, comment out azalia in your kernel configuration and uncomment the
hdaudio and hdafg lines so it reads:

# Intel High Definition Audio
hdaudio* at pci? dev ? function ?
hdafg* at hdaudiobus?

You should also:
cd /dev
sh MAKEDEV audio
 1.249 09-Aug-2009  christos put back drm.
 1.248 09-Aug-2009  christos remove drm stuff for now
 1.247 09-Aug-2009  christos add spic and drm to generic
 1.246 27-Jul-2009  kiyohara Support Marvell Hercules-I/II SATA Controllers.
 1.245 19-Jul-2009  kiyohara Support siisata@cardbus.
It tested on amd64 and i386 only.
 1.244 22-May-2009  christos add uhmodem, uncomment wd* at umass
 1.243 27-Apr-2009  joerg Add commented out hpet@ichlpcib entry.
 1.242 21-Apr-2009  nonaka Added SD/MMC support from OpenBSD.
tested on i386, amd64 at current-users ML by pgoyette@.
tested on zaurus by myself.
 1.241 20-Apr-2009  cegger add ale(4)
 1.240 10-Apr-2009  perry add (commented out) options LOCKDEBUG
 1.239 06-Mar-2009  cegger add age(4) and atphy(4)
 1.238 16-Feb-2009  jmcneill Add and enable genfb(4)
 1.237 29-Jan-2009  ad branches: 1.237.2;
Enable BUFQ_PRIOCSCAN by default.
 1.236 11-Jan-2009  christos merge christos-time_t
 1.235 14-Dec-2008  jmcneill branches: 1.235.2;
add options PMS_ELANTECH_TOUCHPAD
 1.234 24-Nov-2008  ad Remove softdep, pass 1. We are focused on improving journalling.

Proposed on tech-kern@.
 1.233 12-Nov-2008  ad Comment out P1003_1B_SEMAPHORE. The ksem module will now be autoloaded from
the file system if POSIX semaphores are used.
 1.232 12-Nov-2008  ad Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.
 1.231 19-Oct-2008  joerg branches: 1.231.2; 1.231.4;
Add u3g entries in kernels that have ugensa as well.
 1.230 11-Oct-2008  bouyer jme(4), a driver for JMicron Technologies JME250 Gigabit Ethernet and
JME260 Fast Ethernet PCI Express controllers.
Written with a lot of cut-n-paste from the FreeBSD jme(4) driver.
No support for jumbo ethernet frames yet (but should come soon).
Thanks to JMicron Technologies for providing me sample boards and
documentation for this work.
 1.229 07-Oct-2008  pgoyette Move all platforms to new dbCool driver in preparation for removal of
chip-specific drivers
 1.228 07-Oct-2008  rmind Add a note that SysV IPC parameters could be changed dynamically.
 1.227 30-Sep-2008  jmcneill Remove esl(4)
 1.226 09-Sep-2008  ober Adding iwn(4) to GENERIC
 1.225 09-Sep-2008  jmcneill Add uvideo(4)
 1.224 06-Sep-2008  jmcneill Enable video(4) and pseye(4)
 1.223 25-Aug-2008  cegger GENERIC: add auacer(4) which is already in XEN3_DOM0
XEN3_DOM0: add azalia(4) which is already in GENERIC
 1.222 21-Aug-2008  bouyer Enable ipmi(4) by default in GENERIC and related kernels.
 1.221 10-Aug-2008  cube Accept filters are cool, but it's not a reason to select them twice.
 1.220 10-Aug-2008  tls Add accept filters to GENERIC kernels where they exist.
 1.219 10-Aug-2008  cegger Add accept filters per request from port-xen:
http://mail-index.netbsd.org/port-xen/2008/08/10/msg004087.html

pseudo-device entries were copied from sys/arch/i386/conf/GENERIC, rev. 1.904
 1.218 31-Jul-2008  joerg Include VGA_POST by default in GENERIC and ALL on x86 now that the code
is conditional.
 1.217 31-Jul-2008  simonb Add "options WAPBL" to standard GENERIC/INSTALL type configs.
 1.216 26-May-2008  jmcneill branches: 1.216.2; 1.216.4;
Add uberry.
 1.215 25-May-2008  agc Re-enable INCLUDE_CONFIG_FILE in the GENERIC kernel config files for
i386, amd64 and usermode - it is necessary for retrieving information
on kernel configuration for running kernels - cf config -x.
 1.214 23-May-2008  jnemeth add siisata(4) -- SiI SteelVine SATA2
 1.213 18-May-2008  cegger acpidalb(4): Driver for PNP0C32 Hotkeys aka "Direct Application Launch Buttons".
"awesome" jmcneill
 1.212 18-May-2008  bjs second instance of PCI_INTR_FIXUP -> PCI_ADDR_FIXUP, change comment to
match.
 1.211 18-May-2008  jmcneill Add commented out entries for PCI_BUS_FIXUP and PCI_ADDR_FIXUP
 1.210 05-May-2008  ad branches: 1.210.2;
The kernel is too large. Reduce size by commenting out eye candy options:

{ACPI,MII,PCI,USB}VERBOSE

Also remove INCLUDE_CONFIG_FILE, because it doesn't make sense in GENERIC.
 1.209 02-May-2008  ad - Give x86 BIOS boot the ability to load new style modules and pass them
into the kernel. Based on a patch by jmcneill@, with many fixes and
improvements by me.

- Put MEMORY_DISK_DYNAMIC and MODULAR into the GENERIC kernels, so that
you can load miniroot.kmod from the boot blocks and boot into the
installer!
 1.208 01-May-2008  cegger hpqlb(4): driver for HP Quick Launch buttons - found on HP Pavilion Notebooks
 1.207 30-Apr-2008  ad Shuffle ioapic/mainbus/cpu into std.amd64 like i386.
 1.206 29-Apr-2008  ad Require MULTIPROCESSOR. PR kern/38537.
 1.205 22-Apr-2008  cegger branches: 1.205.2;
amdtemp(4): Driver for AMD CPU Temperature Sensors. Adopted from OpenBSD's kate(4).
Changes beyond OpenBSD's driver:
- Improved support for AMD K8
- Added support for AMD Barcelona, AMD Phenom and AMD Griffin
Tested on various single and multi-socket machines.
Review and OK xtreame
 1.204 03-Apr-2008  xtraeme branches: 1.204.2;
Add finsio(4) entry (commented out).
 1.203 31-Mar-2008  jmcneill Enable asus(4)
 1.202 31-Mar-2008  njoly Revert unexpected DDB_ONPANIC change introduced in last revision.
 1.201 29-Mar-2008  cube Add and enable lii(4) in amd64 configurations, too, as it is very likely
the hw is used on amd64-capable otherboards, although it is not confirmed
yet.
 1.200 29-Feb-2008  jmmv Remove GENERIC.local from the repository

Make all the kernels that currently include their corresponding GENERIC.local
file use the cinclude directive instead of include. This way config(1) will
not complain if the file cannot be found.

After doing this, remove the GENERIC.local files from the repository so that
the user will not see modified files during updates, and local changes to
them cannot end up in the repository by mistake.

Discussed in tech-kern@ earlier this month. No strong objections.
 1.199 30-Jan-2008  ad branches: 1.199.2; 1.199.6;
Crank maxusers to 64.
 1.198 07-Jan-2008  martti Fixed option indentation, it should be

option<space><tab>
makeoption<space><tab>
 1.197 01-Jan-2008  jmmv Revert previous by removing the apm entry. Even though the driver seems
to work, we do not build any userland support for it; see 1.183's commit
message. Per jmcneill@'s request.
 1.196 01-Jan-2008  jmmv Add the ACPI apm emulation device.
 1.195 01-Jan-2008  jmmv Add and enable piixpm. Confirmed working under VMware Fusion.
 1.194 31-Dec-2007  ad Remove systrace. Ok core@.
 1.193 30-Dec-2007  joerg Enable wedge autodiscovery and wedge support for GPT. Both MBR and BSD
disklabel support is *not* enabled, but documented.
 1.192 29-Dec-2007  xtraeme Update itesio(4) comments.
 1.191 26-Dec-2007  elad Compile in by default (disabled) PaX ASLR for amd64 and i386.
 1.190 26-Dec-2007  joerg Add PHYSMEM_MAX_ADDR and PHYSMEM_MAX_SIZE options. This limit physical
memory based on overall size (useful for debugging to keep core dumps
small) or maximum address (when using devices with bus dma limits).
Contrary to REALBASEMEM and REALEXTMEM, they still use the BIOS memory
map and can therefore deal with fragmented memory.
 1.189 24-Dec-2007  kiyohara Remove white-spaces.
 1.188 23-Dec-2007  jmcneill Add sony* at acpi?
 1.187 21-Dec-2007  dsl Enable LINUX and LINUX32 emulation.
 1.186 21-Dec-2007  jmcneill Add thinkpad at acpi
 1.185 20-Dec-2007  ad Remove GENERIC.MP config and enable SMP by default on amd64.
 1.184 17-Dec-2007  riz Add drvctl(4)
 1.183 11-Dec-2007  jmcneill Disable apm@acpi on amd64, since we don't create /dev/apmctl, build apmd,
or provide machine/apmvar.h. Ok ad@
 1.182 10-Dec-2007  wiz Add acpiecdt and add a comment explaining it (from i386/GENERIC).
 1.181 10-Dec-2007  jmcneill branches: 1.181.2;
Revert previous, thanks wiz!
 1.180 09-Dec-2007  jmcneill Merge jmcneill-pm branch.
 1.179 05-Dec-2007  xtraeme branches: 1.179.2;
arc(4) -> arcmsr(4)
 1.178 04-Dec-2007  xtraeme Enable arc(4).
 1.177 02-Dec-2007  kiyohara branches: 1.177.2;
Add bcsp(4).
 1.176 22-Nov-2007  jnemeth comment out com*/lpt* at acpi? as they cause these ports to move from
their traditional location and imminent changes in -current will cause
them to move back
 1.175 15-Nov-2007  xtraeme Update for it(4) -> itesio(4) rename.
 1.174 13-Nov-2007  ghen Add description for EST_FREQ_USERWRITE (from i386).
 1.173 11-Nov-2007  jmcneill Enable pad(4)
 1.172 04-Nov-2007  xtraeme branches: 1.172.2;
Remove System V semaphores and share memory options to set the limits:
SEMMNI, SEMMNS, SEMUME and SHMMAXPGS.

They can be tweaked via sysctl now. Ports that were setting values on
them weren't touched, I only removed the ones that were commented out.
 1.171 30-Oct-2007  xtraeme options<space><tab>FOO
 1.170 29-Oct-2007  xtraeme Enable "options INTEL_CORETEMP".
 1.169 28-Oct-2007  dsl Add (commented out) SYSCALL_COUNTS and SYSCALL_TIMES.
 1.168 24-Oct-2007  joerg Reduce difference to i386 GENERIC:
- add some comments from that
- options SPACE TAB
- enable EST
- enable DDB and build w/ frame pointer by default
- enable ACPI devices
- include AGP
- include Cardbus and PCMCIA
- include Synaptics driver
- include atw, ipw, iwi, hme, rtw, txp
- include uep, stuirda, utoppy, ugensa

This makes GENERIC actually usable for laptops.
 1.167 19-Oct-2007  njoly Add compat_linux and exec_linux_elf lkm support for amd64:
- Add needed COMPAT_OSSAUDIO to GENERIC.
- Add missing includes needed by linux_syscallargs.h.
- Add lkm building.
 1.166 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.165 04-Oct-2007  christos branches: 1.165.2;
add an smbus controller.
 1.164 06-Sep-2007  martti branches: 1.164.2;
Fixed indentation (it should be <keyword><space><tab><name><tab><comment>).
 1.163 06-Sep-2007  joerg Enable CGD in GENERIC for amd64 and i386.
 1.162 03-Sep-2007  xtraeme Add uchcom(4) and uslsa(4).
 1.161 29-Aug-2007  xtraeme Add cdce(4).
 1.160 26-Aug-2007  xtraeme branches: 1.160.2;
Add ichlpcib commented out.
 1.159 21-Aug-2007  kiyohara Oops.
I mistook commit. sdmmc(4) is not commit yet. And I don't have this.
 1.158 21-Aug-2007  kiyohara Comment-out 'slhci at pcmcia' because comment-outed for the pcmcia.
 1.157 21-Aug-2007  kiyohara Add slhci at pcmcia.
And reorder.
 1.156 20-Aug-2007  kiyohara Add btbc(4).
 1.155 18-Aug-2007  tnn Enable spdmem(4) in ALL configuration. Add commented out entries to GENERIC
 1.154 06-Aug-2007  adrianp Remove iso(4) from GENERIC kernels, as discussed on tech-net@
Ok'ed by core@
 1.153 11-Jul-2007  kiyohara branches: 1.153.2; 1.153.4; 1.153.8;
Add nfsmb(4).
 1.152 10-Jul-2007  xtraeme Add wpi(4).
 1.151 03-Jul-2007  briggs Add (commented-out) support for IPMI on amd64--pretty much copied straight
from i386.
 1.150 16-Jun-2007  ad -options I2OVERBOSE.
 1.149 09-Jun-2007  kiyohara Add zyd(4).
 1.148 04-Jun-2007  martin Add pseudo-device agr to all GENERIC kernels where it might make sense
(commented out in some).
 1.147 03-Jun-2007  xtraeme Add the options for Enhanced Speedstep commented out.
 1.146 01-Jun-2007  blymn Added smsc device.
 1.145 29-May-2007  christos Add compat 4.0
 1.144 26-May-2007  briggs Enable aac(4) and ld at aac.
 1.143 15-May-2007  bouyer add jmide(4), a driver for the JMicron Technology JMB36x PCIe to SATA II/PATA
controllers. These controllers can be found on add-on PCIe cards, or
on some motherboards to provide the PATA connectivity (e.g. some intel
ICH8-based motherboards).

Thanks to JMicron Technology for providing me documentation and
different sample boards for this work.
 1.142 08-May-2007  xtraeme Add "ug* at acpi?" following the current scheme in the files.
 1.141 07-May-2007  jnemeth PR/36234 - Joerg Niendorf -- xi -> xirc
 1.140 07-May-2007  xtraeme Enable rum(4).
 1.139 01-May-2007  bouyer Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.
 1.138 23-Apr-2007  dyoung branches: 1.138.2;
Add ATADEBUG so that a person can patch atadebug without having to
recompile the kernel.
 1.137 20-Mar-2007  xtraeme ALL: Enable INTEL_ONDEMAND_CLOCKMOD.
GENERIC: Add INTEL_ONDEMAND_CLOCKMOD disabled by default.
 1.136 14-Mar-2007  drochner branches: 1.136.2;
It doesn't make sense to specify "configuration" and "interface"
locators for uhub because a hub can't have sub-devices.
This might be sanity-checked eventually.
Same for ubt now after the change to device attachment.
 1.135 13-Mar-2007  xtraeme Add aiboost* at acpi, enabled by default on i386/GENERIC and disable
in the other ones (to follow current scheme).
 1.134 09-Mar-2007  xtraeme branches: 1.134.2; 1.134.4;
Erm, remove local changes added in previous.
 1.133 09-Mar-2007  xtraeme Enable SMBFS, as we do on i386.
 1.132 08-Mar-2007  njoly Add hpet support to i386/amd64 kernels.
- `hpet* at acpi?' to kernels that already support ACPI.
- `hpet* at amdpcib?' (commented out) to amd64 GENERIC.
 1.131 07-Mar-2007  bouyer Revert local changes that went in accidentally with the "add ACPI" commit.
 1.130 06-Mar-2007  bouyer For the benefit of modern hardware, enable ACPI by default in INSTALL and
GENERIC kernels. If ACPI is an issue on your hardware, 'boot -c' and
'disable acpi' should be a workaround. ACPI-enabled kernels works fine
on pre-acpi hardware.
for amd64:
- add ACPI to INSTALL and GENERIC, remove the *_ACPI config files.
- get rid of the bootfloppy-big.fs boot image, and got to a 3-floppy boot
image
for i386:
- introduce INSTALL_LARGE which has ACPI and some devices with big firmware
- move some devices from INSTALL to INSTALL_LARGE
- Boot floppies still use INSTALL, and bootfloppy-big.fs is still there
(for thoses who want to build el-torito floppy emulation boot CD) and use
INSTALL.
For both, drop the 'iso-image' code in etc/ to make the iso bootable, we'll
use something else to build bootable CDs.
 1.129 06-Mar-2007  dillo Complete rename of hfsp to hfs, requested by thorpej.
 1.128 05-Mar-2007  dillo Add file-system HFSP (commented out) to GENERIC kernels of ports
on which Mac OS runs.
 1.127 01-Mar-2007  kiyohara Add btuart(4).
 1.126 09-Feb-2007  ad branches: 1.126.2;
Merge newlock2 to head.
 1.125 24-Jan-2007  tls Remove option COMPAT_386BSD_MBRPART from default kernels. NetBSD has
not used partition ID 0x165 for many, many years, and the presence of
this option in INSTALL kernels can cause overwriting of existing FreeBSD
installations when sysinst writes back the disklabel. Those with very,
very old NetBSD installations may find that they must update their fdisk
partition tables to use partition ID 0x169 for their NetBSD partitions.

This seems like the best of a number of lousy choices for dealing with
this problem. Sysinst should perhaps grow code that asks whether an
existing 0x165 partition should be converted.

~
 1.124 06-Jan-2007  xtraeme Add ug0 at isa? commented out (driver for the Abit uGuru
Hardware system monitor).
 1.123 17-Dec-2006  bouyer Add bnx(4), a driver for Broadcom NetXtreme II 10/100/1000 Ethernet device.
Ported from OpenBSD by cube@, with some bus_dma fixes by me.
Tested on i386 and amd64.
 1.122 17-Dec-2006  bouyer Add mfi(4), a driver for LSI Logic & Dell MegaRAID SAS RAID controller.
Ported from OpenBSD, tested on i386 and amd64.
 1.121 11-Dec-2006  yamt - remove a static configuration, FILEASSOC_NHOOKS. do it dynamically instead.
- make fileassoc_t a pointer and remove FILEASSOC_INVAL.
- clean up kern_fileassoc.c. unify duplicated code.
- unexport fileassoc_init using RUN_ONCE(9).
- plug memory leaks in fileassoc_file_delete and fileassoc_table_delete.
- always call callbacks, regardless of the value of the associated data.

ok'ed by elad.
 1.120 30-Nov-2006  bouyer branches: 1.120.2;
Add ahcisata(4), a driver for AHCI 1.0 and 1.1 controllers. Tested on the sata
ports of a Intel 63xxESB chipset. Does not support NCQ yet.
 1.119 11-Nov-2006  jmmv Enable TMPFS by default. OK'ed by core@.

I'm leaving those platforms with few users and those whose machines are
not very powerful untouched per uwe@'s suggestion. The port masters or
the real users of those ports are better suited to make the decision of
enabling it.
 1.118 11-Nov-2006  jmmv Remove tmpfs's experimental status. OK'ed by core@.
 1.117 31-Oct-2006  perry one more time. sigh.
 1.116 31-Oct-2006  perry reddo the last space/tab fix *correctly*
 1.115 31-Oct-2006  perry another space tab fix
 1.114 30-Oct-2006  perry note about UFS_DIRHASH from i386, and a couple of space tab fixes
 1.113 26-Oct-2006  elad Compile in Veriexec by default on some popular archs (amd64, i386, sparc64)
so it's more accessible and less of a hassle to put to use. Also enable
fileassoc(9) by default as a result, which for itself may open the door for
a lot of cool stuff. (stay tuned. :)

I recommend port masters of other archs to consider doing the same.
Personally I don't know which ports are considered more of a legacy than
in-production, so I'm leaving it for someone else for now...

No objections on tech-kern.
 1.112 21-Oct-2006  bouyer Add support for the Intel 80003 Gigabit Ethernet controller (found e.g. in
newer server chipsets) to wm(4), from the FreeBSD em(4) driver.
While there, add a few other Intel Ethernet controller that should work as
is.
Properly update the RX error and TX collision counters.
Add ikphy(4), a driver for the Intel i82563 Kumeran 10/100/1000 Ethernet PHYs
 1.111 26-Sep-2006  elad Oops! forgot "options" in previous commit. Pointed out by freza@, thanks!
 1.110 26-Sep-2006  elad Make PaX mprotect(2) restrictions more accessible.

On amd64, sparc64, i386, and alpha, they will be compiled in and disabled
by default. That means that to use them you either enable the "global"
knob with sysctl, or use paxctl(1) to enable it on a per-program basis.

On sparc and macppc just include a commentd out line in the GENERIC kernel.
 1.109 23-Sep-2006  jmcneill Add iteide(4) driver to GENERIC and INSTALL kernels; PR# 33426.
 1.108 10-Sep-2006  plunky branches: 1.108.2;
add bluetooth support to amd64 port, built by default in GENERIC kernels
 1.107 10-Sep-2006  riz Add msk and mskc.
 1.106 26-Aug-2006  christos branches: 1.106.2;
PR/34283: Gene ENonymous: Add IPFILTER_LOOKUP to the default kernel options
Also remove CCITT,NS,NIP
 1.105 26-Aug-2006  tsutsui Remove obsolete #options VERIFIED_EXEC, found by grep(1).
 1.104 14-Aug-2006  skrll s/adpater/adapter/

Prompted by PR/34195
 1.103 12-Aug-2006  christos Disable SYSTRACE by default on all kernels (discussed with core)
 1.102 06-Aug-2006  xtraeme branches: 1.102.2;
AMD PowerNow!/Cool`n'Quiet driver for NetBSD/amd64,
adapted from OpenBSD.

Tested on a few machines:

http://bigbird.dohd.org:3021/NetBSD/dmesg
http://www.bsd.org.il/netbsd/acpi/dmesg

Thanks to cube, elad and others for testing and fixes.

Enabled by default on GENERIC.
 1.101 31-Jul-2006  hubertf spc(4) can also attach to pcmcia(4), as was already in hpcmips/GENERIC
for quite some time. Add it to all systems that have pcmcia SCSI.

Pointed out by Bj�rn Johannesson <rherdware@yahoo.com> in private mail,
OK'd by matt@
 1.100 30-Jul-2006  bouyer Add twa(4) and ld at twa
 1.99 24-Jul-2006  gdt Add UGEN_BULK_RA_WB, requested by cube@.
 1.98 15-Jul-2006  elad add (commented out) fileassoc(9) kernel options on some popular archs.
 1.97 04-Jul-2006  christos Apply fvdl's acpi pci interrupt configuration code.
- MPACPI is no more.
- MPACPI_SCANPCI -> ACPI_SCANPCI
 1.96 01-Jul-2006  xtraeme Add commented out it(4) entry, per suggestion in PR kern/33886.
 1.95 28-Jun-2006  liamjfoy Add CARP to GENERIC kernel configs. CARP is not enabled by default.

ok: christos
 1.94 27-Apr-2006  jonathan branches: 1.94.4;
Add entries for svwsata(4) to amd64 GENERIC and INSTALL kernels,
to support SATA ports on Serverworks HT-1000 (aka bcm5785) chips.
 1.93 19-Apr-2006  drochner adjust comments for the new location of wskbdmap_mfii.c,
addresses PR kern/33290 by henry nelson
 1.92 15-Apr-2006  jmmv Remove the getwschar and putwschar accessops from wsdisplay drivers as
requested by uwe@. These were wrong because they were receiving an
emulcookie yet they were accessops (thus having to receive an accesscookie).
Instead, just handle the WSDISPLAYIO_{GET,PUT}WSCHAR ioctls from the
driver's ioctl accessop.

As this reduces the amount of code needed to handle these operations to
two small functions in each driver, remove the WSDISPLAY_CHARFUNCS kernel
option.

Reviewed by, at least, uwe@ and macallan@. No objections in tech-kern@.
 1.91 12-Apr-2006  martti Added ciss(4). Tested by Joseph Dacuma on HP DL-380 G3 with Smart Array 5i.
 1.90 28-Mar-2006  pavel Add stf to all kernel configs which have INET6 and gif, except the INSTALL
ones and those for specific machines of developers. PR 32304.

OK'ed by rpaulo.

N.B. stf is a cloning device, so it still must be enabled by
"ifconfig stf0 create".
 1.89 25-Mar-2006  xtraeme Enable rgephy(4), closes PR port-amd64/33117.
 1.88 12-Mar-2006  chs branches: 1.88.2;
add nfe.
 1.87 19-Feb-2006  tls branches: 1.87.2; 1.87.4;
Add amdpm -- without this, we're throwing away a good hardware random
number source on a huge set of machines. Also, now that amdpm has
support for the SMBus controller, add (commented-out, since we don't
always know what address the sensors are at) iic at amdpm and adt7463c
at iic, which is the configuration used on the Tyan S2881 and S2882-D
server boards. This should work in either 64-bit or 32-bit mode; it's
been tested in 64-bit mode. Addresses PR kern/32463 submitted by
Anil Gopinath.
 1.86 09-Feb-2006  kleink options<space><tab>name previous.
 1.85 09-Feb-2006  manu Add initial (but unfinished) COMPAT_LINUX32 for amd64. This is good enough so
that the i386 license manager part of amd64 version of Fluent works.

While I'm here, add SysV IPC to COMPAT_LINUX/amd64
 1.84 05-Feb-2006  cube Remove 'count' argument for pseudo-devices that ignore it
(vnd, bpfilter, ppp, gif, gre, tun, sl, strip, faith, stf).
 1.83 04-Feb-2006  rpaulo bpfilter doesn't accept count anymore.
 1.82 02-Feb-2006  reinoud branches: 1.82.2;
Add commented out UDF file-system entry in all GENERIC configurations.
 1.81 31-Jan-2006  xtraeme branches: 1.81.2;
Add ral(4) at pci/uhub and atu(4) at uhub.
 1.80 31-Jan-2006  kochi remove ACPI_DISABLE_ON_POWEROFF option, which was there just for
compatibility of our old driver behavior, which is not necessary.
 1.79 04-Jan-2006  xtraeme Enable rlphy(4).
 1.78 20-Dec-2005  thorpej branches: 1.78.2;
Remove the tablet line discipline.
 1.77 09-Dec-2005  elad Add (commented out) Veriexec options and pseudo-device to GENERIC kernels,
and remove the i386 GENERIC_VERIEXEC config.
 1.76 07-Dec-2005  tsutsui Adjust comments for options FFS_NO_SNAPSHOT.

XXX: This option should be mentioned in options(4).
 1.75 25-Nov-2005  thorpej swcr -> swcrypto
 1.74 25-Nov-2005  thorpej "pseudo-device crypto" really refers to the /dev/crypto API to the
opencrypto framework, not the framework itself. Update the comment
accordingly.
 1.73 25-Nov-2005  thorpej Add "pseudo-device swcr" (commented out if "pseudo-device crypto" is also
commented out).
 1.72 03-Nov-2005  rpaulo branches: 1.72.2;
PR 31996: fix the comments for MPBIOS and MPACPI. By Damon Brodie.
 1.71 14-Sep-2005  tron Add 10 Gigabit Ethernet drivers dge(4) and xge(4).
 1.70 10-Sep-2005  jmmv Initial addition of tmpfs, an efficient memory file-system. This project
was developed as part of Google's Summer of Code 2005 program. This
change adds the kernel code, the mount_tmpfs utility, a regression test
suite and does all other related changes to integrate these.

The file-system is still *experimental*. Therefore, it is disabled by
default in all kernels. However, as typically done, a commented-out
entry is added in them to ease its setup.

Note that I haven't commited the required mountd(8) changes to be able
to export tmpfs file-systems because NFS support is still very unstable
and because, before enabling it, I'd like to do some other changes.

OK'ed by my project mentor, William Studenmund (wrstuden@).
 1.69 09-Sep-2005  drochner remove "dev" locators from cardbus device definitions, it doesn't
make sense technically and might be removed
 1.68 09-Sep-2005  rpaulo Enable WSDISPLAY_SCROLLSUPPORT by default.
 1.67 06-Sep-2005  dogcow after discussion with dyoung, add rtw* at cardbus
 1.66 19-Aug-2005  christos Enable ptyfs by default on the non-install and non small/tiny/ramdisk kernels
 1.65 19-Aug-2005  christos 64 bit inode changes.
 1.64 05-Aug-2005  skrll Add (commented out) ucycom to various kernel configs.
 1.63 31-Jul-2005  yamt revert "defflag VMSWAP" changes for now.
there seems to be far more people who don't want to edit
their kernel config files than i thought.
 1.62 30-Jul-2005  yamt add "options VMSWAP" to non INSTALL kernels.
 1.61 17-Jul-2005  augustss Remove obsolete comment about ehci.
 1.60 17-Jul-2005  hubertf Add support for reading cloop2 compressed filesystem image,
enable by putting VND_COMPRESSION into kernel config file.
Written by Cliff Wright, polished up slightly by me.
 1.59 14-Jul-2005  wiz Fix typo in comment, from Nicolas Joly in PR 30743.
 1.58 12-Jul-2005  sekiya Add config goo for ath. Tested with a PCI card, detected as:

ath0 at pci0 dev 10 function 0
ath0: interrupting at ioapic0 pin 17 (irq 5)
ath0: 11a rates: 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps
ath0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
ath0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36M bps 48Mbps 54Mbps
ath0: mac 5.9 phy 4.3 radio 3.6

Cardbus untested, so it is commented out.
 1.57 11-Jul-2005  kiyohara ieee1394 import from FreeBSD.
 1.56 07-Jul-2005  tron Add (commented out) IPSEC_NAT_T option.
 1.55 05-Jul-2005  augustss branches: 1.55.2;
Add auixp.
 1.54 04-Jul-2005  martti Added support for amr. Tested by Joseph A. Dacuma with Dell PowerEdge 2800.
 1.53 04-Jul-2005  augustss Uncomment ehci. It works fairly well now.
 1.52 01-Jul-2005  augustss Add ixpide so we handle ATI controllers specially.
 1.51 25-Jun-2005  rpaulo Add file-system PTYFS (commented out) so that people know its existence.

Ok'ed by Christos Zoulas and Hubert Feyrer.
 1.50 23-Jun-2005  sekiya ACPI_PCI_FIXUP -> PCI_INTR_FIXUP
 1.49 22-Jun-2005  wiz Remove duplicate apci at mainbus line, from Nicolas Joly in PR 30564.
 1.48 21-Jun-2005  kent add "azalia at pci"
 1.47 09-Jun-2005  tsutsui - Rename options NEW_BUFQ_STRATEGY -> options BUFQ_READPRIO.
(still commented out)
- Add (also commented out) options BUFQ_PRIOCSCAN.

Suggested by perry and soda on tech-kern.
Please refer options(4) for details for these options.
 1.46 15-Apr-2005  itohy Add ukyopon(4).
 1.45 25-Mar-2005  cube Add attimer(4) configurations everywhere pcppi(4) exists, with the
following rule:
If a pcppi device is enabled for an attachment, enable an attimer for the
same attachement, otherwise comment it.
 1.44 21-Mar-2005  xtraeme Add "pcppi* at acpi?" commented out.
 1.43 21-Mar-2005  cgd correctly alphabetize bce, skc/sk, inphy relative to their neighbors.
devices. correct typo in bce comment.
 1.42 25-Feb-2005  simonb branches: 1.42.2;
Add COMPAT_20 (and COMPAT_16 in some cases) to kernel config files
that didn't have those options but had other earlier compat options.
 1.41 20-Feb-2005  jdolecek add ciphy(4) and vge(4)
 1.40 18-Feb-2005  dsl Invert FFS_SNAPSHOT to FFS_NO_SNAPSHOT
 1.39 11-Feb-2005  dsl Add 'option FFS_SNAPSHOT' to most of the config files.
Commented out for kernels that appear to hace space constraints.
 1.38 31-Jan-2005  hannken Add file system snapshots to kernel configs.

- Ffs internal snapshots get compiled in unconditionally.

- File system snapshot device fss(4) added to all kernel configs that
have a disk. Device is commented out on all non-GENERIC kernels.

Reviewed by: Jason Thorpe <thorpej@netbsd.org>
 1.37 28-Jan-2005  rumble Sprinkle options UFS_DIRHASH on GENERIC kernels. It's presently
commented out and labeled experimental pending further review and
testing.
 1.36 18-Jan-2005  scw branches: 1.36.2;
Add "options PMS_SYNAPTICS_TOUCHPAD", commented out by default.
 1.35 17-Jan-2005  cube Add tap(4) support to a random^Wcarefully chosen set of kernel configs.
All those kernels have a line for both tun and bridge, and if either is
commented out, tap is commented out also. With the exception of i386's
GENERIC_TINY.

XXX: we _need_ some way of making this more simple.
 1.34 02-Dec-2004  xtraeme branches: 1.34.4;
Add ACPI joy(4) attachment, based on lpt_acpi.c by jmcneill@,
reviewed and ok'ed by cube@ and martin@.
 1.33 02-Dec-2004  xtraeme Add ACPI mpu(4) attachment, based on lpt_acpi.c by jmcneill@,
reviewed by christos@, cube@ and martin@.

While here, remove a printf() in mpu_attach() (ic/mpu.c) to remove
an empty line in some frontends (mpu_isa.c, etc).
 1.32 24-Nov-2004  bouyer pdcsata(4), a driver for the Promise SATA150 (aka PDC203xx) serie of
controllers. Tested with a PDC20375 (2 SATA, one PATA) controller on sparc64.
Added to all kernel config file which had pdcide(4).
 1.31 10-Nov-2004  christos Add COMPAT_BSDPTY to the rest of the config files.
 1.30 23-Oct-2004  augustss s/uax/axe/
 1.29 04-Sep-2004  manu IPv4 PIM support, based on a submission from Pavlin Radoslavov posted on
tech-net@
 1.28 15-Jul-2004  atatat Add "options SYSCTL_INCLUDE_DESCR" to a lot of configs, but commented
out in most of them.
 1.27 26-Jun-2004  abs Add (commented out) ALTQ options to all GENERIC-like files
 1.26 22-Jun-2004  toshii Add re; Realtek GbE.
 1.25 22-Jun-2004  itojun have pf and pflog pseudo-device (commented out).
reviewed by matt, perry, christos
 1.24 18-Jun-2004  christos ptm is now mandatory, depends on pty, and can be disabled with -DNO_DEV_PTM
 1.23 16-Jun-2004  christos Add pseudo-device ptm on all the generic flavored kernels.
 1.22 07-Jun-2004  kochi Add ACPICA_PEDANTIC/ACPI_DISABLE_ON_POWEROFF options; follow the i386
changes.
 1.21 14-Jan-2004  jonathan branches: 1.21.2;
Add support for opencrypto, PCI accelerators to sys/arch/*/conf/GENERIC
files for machines I know to have genuine PCI slots. As sent to tech-kern
for feedback in December 2003. Based on feedback, opencrypto is commented
out in the macppc GENERIC (due to absense of GENERIC_SOFTINT support),
and added to the sparc64 config (sys/arch/sparc64/conf/GENERIC32).
 1.20 14-Dec-2003  thorpej Split the Intel i31244 SATA controller ("Artisea") driver out of piixide
into its own driver (artsata).
 1.19 13-Dec-2003  thorpej Split out the Silicon Image SATALink support into its own driver,
"satalink".
 1.18 22-Nov-2003  fvdl Add and enable sk/skc drivers.
 1.17 08-Nov-2003  fvdl Add POSIX 1003.1b semaphores.
 1.16 05-Nov-2003  fvdl Add igphy.
 1.15 25-Oct-2003  fvdl Add ahd, bce, ataraid.
 1.14 23-Oct-2003  fvdl Add auvia.
 1.13 18-Oct-2003  lukem Use one 'atabus* at ata?' instead of multiple 'atabus* at FOOide? channel ?'
Use 'atapibus* at atapi?' instead of 'atapibus* at atabus?'
 1.12 08-Oct-2003  bouyer Add new per-chip pciide drivers.
 1.11 08-Oct-2003  bouyer Add atabus.
 1.10 06-Oct-2003  fvdl SIGINFO support.
Todo: 32bit compat support (COMPAT_NETBSD32 will not compile right now,
as it won't on other platforms).
 1.9 01-Sep-2003  fvdl Use MPBIOS_SCANPCI by default.
 1.8 22-Aug-2003  itojun add udav*
 1.7 06-Aug-2003  bouyer Add esiop at pci to GENERIC which already have siop at pci.
esiop has been tested enouth now.
esiop not added to INSTALL kernels because of possible space constraint.
siop should be able to drive all adapters supported by esiop.
 1.6 06-Jul-2003  kochi o cleanup usage of ACPI_ACTIVATE_DEV/ACPI_PCI_FIXUP
o delete usage of ENABLE_DEBUGGER

As ACPI_ACTIVATE_DEV/ACPI_PCI_FIXUP are defflag'ed in files.acpi,
these options don't have to have a value.
 1.5 29-May-2003  fvdl branches: 1.5.2;
Add the options MPBIOS_SCANPCI and MPACPI_SCANPCI to configure PCI roots
with the MPBIOS/ACPI bus information, by walking through the buses, and
descending down every bus that hasn't been marked configured yet.
 1.4 21-May-2003  christos Add ACPI gunk.
 1.3 11-May-2003  fvdl Add commented out acpi.
 1.2 07-May-2003  fvdl Enable LKM.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.5.2.14 11-Dec-2005  christos Sync with head.
 1.5.2.13 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.5.2.12 01-Apr-2005  skrll Sync with HEAD.
 1.5.2.11 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.5.2.10 15-Feb-2005  skrll Sync with HEAD.
 1.5.2.9 04-Feb-2005  skrll Sync with HEAD.
 1.5.2.8 24-Jan-2005  skrll Sync with HEAD.
 1.5.2.7 18-Dec-2004  skrll Sync with HEAD.
 1.5.2.6 29-Nov-2004  skrll Sync with HEAD.
 1.5.2.5 14-Nov-2004  skrll Sync with HEAD.
 1.5.2.4 02-Nov-2004  skrll Sync with HEAD.
 1.5.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.5.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.5.2.1 03-Aug-2004  skrll Sync with HEAD
 1.21.2.5 11-Aug-2007  bouyer Pull up following revision(s) (requested by adrianp in ticket #11356):
sys/arch/acorn32/conf/GENERIC 1.80 via patch
sys/arch/amd64/conf/GENERIC 1.154 via patch
sys/arch/amiga/conf/GENERIC.in 1.61 via patch
sys/arch/arc/conf/GENERIC 1.148 via patch
sys/arch/atari/conf/GENERIC.in 1.68 via patch
sys/arch/cats/conf/GENERIC 1.116 via patch
sys/arch/hp300/conf/GENERIC 1.141 via patch
sys/arch/hp700/conf/GENERIC patch
sys/arch/i386/conf/GENERIC 1.840 via patch
sys/arch/i386/conf/GENERIC_LAPTOP 1.239 via patch
sys/arch/i386/conf/GENERIC.MPACPI patch
sys/arch/mac68k/conf/GENERIC 1.182 via patch
sys/arch/sgimips/conf/GENERIC32_IP2x 1.68 via patch
sys/arch/sgimips/conf/GENERIC32_IP3x 1.66 via patch
sys/arch/sparc/conf/GENERIC 1.200 via patch
sys/arch/sparc64/conf/GENERIC32 patch
sys/arch/xen/conf/GENERIC patch
Remove iso(4) from GENERIC kernels, as discussed on tech-net@
Ok'ed by core@
 1.21.2.4 15-Jul-2004  he branches: 1.21.2.4.2;
Pull up revision 1.28 (requested by atatat in ticket #663):
Add "options SYSCTL_INCLUDE_DESCR" to a lot of configurations,
but commented out in most of them.
 1.21.2.3 13-Jul-2004  tron Pull up revision 1.26 (requested by he in ticket #641):
Add re; Realtek GbE.
 1.21.2.2 30-Jun-2004  jdc Pull up revision 1.27 (requested by abs in ticket #567).

Add (commented out) ALTQ options to all GENERIC-like files
 1.21.2.1 14-Jun-2004  jmc Pullup patch (requested by kochi in ticket #463)

Add ACPI_DISABLE_ON_POWEROFF option. PR#24869
 1.21.2.4.2.3 11-Aug-2007  bouyer Pull up following revision(s) (requested by adrianp in ticket #11356):
sys/arch/acorn32/conf/GENERIC 1.80 via patch
sys/arch/amd64/conf/GENERIC 1.154 via patch
sys/arch/amiga/conf/GENERIC.in 1.61 via patch
sys/arch/arc/conf/GENERIC 1.148 via patch
sys/arch/atari/conf/GENERIC.in 1.68 via patch
sys/arch/cats/conf/GENERIC 1.116 via patch
sys/arch/hp300/conf/GENERIC 1.141 via patch
sys/arch/hp700/conf/GENERIC patch
sys/arch/i386/conf/GENERIC 1.840 via patch
sys/arch/i386/conf/GENERIC_LAPTOP 1.239 via patch
sys/arch/i386/conf/GENERIC.MPACPI patch
sys/arch/mac68k/conf/GENERIC 1.182 via patch
sys/arch/sgimips/conf/GENERIC32_IP2x 1.68 via patch
sys/arch/sgimips/conf/GENERIC32_IP3x 1.66 via patch
sys/arch/sparc/conf/GENERIC 1.200 via patch
sys/arch/sparc64/conf/GENERIC32 patch
sys/arch/xen/conf/GENERIC patch
Remove iso(4) from GENERIC kernels, as discussed on tech-net@
Ok'ed by core@
 1.21.2.4.2.2 21-Jul-2005  riz branches: 1.21.2.4.2.2.2;
Pull up revision 1.46 (requested by itohy in ticket #1430):
Add ukyopon(4).
 1.21.2.4.2.1 02-Apr-2005  he Pull up revision 1.32 (requested by bouyer in ticket #1019):
Add pdcsata(4), a driver for the Promise SATA150 (aka PDC203xx) series of
controllers.
 1.21.2.4.2.2.2.1 11-Aug-2007  bouyer Pull up following revision(s) (requested by adrianp in ticket #11356):
sys/arch/acorn32/conf/GENERIC 1.80 via patch
sys/arch/amd64/conf/GENERIC 1.154 via patch
sys/arch/amiga/conf/GENERIC.in 1.61 via patch
sys/arch/arc/conf/GENERIC 1.148 via patch
sys/arch/atari/conf/GENERIC.in 1.68 via patch
sys/arch/cats/conf/GENERIC 1.116 via patch
sys/arch/hp300/conf/GENERIC 1.141 via patch
sys/arch/hp700/conf/GENERIC patch
sys/arch/i386/conf/GENERIC 1.840 via patch
sys/arch/i386/conf/GENERIC_LAPTOP 1.239 via patch
sys/arch/i386/conf/GENERIC.MPACPI patch
sys/arch/mac68k/conf/GENERIC 1.182 via patch
sys/arch/sgimips/conf/GENERIC32_IP2x 1.68 via patch
sys/arch/sgimips/conf/GENERIC32_IP3x 1.66 via patch
sys/arch/sparc/conf/GENERIC 1.200 via patch
sys/arch/sparc64/conf/GENERIC32 patch
sys/arch/xen/conf/GENERIC patch
Remove iso(4) from GENERIC kernels, as discussed on tech-net@
Ok'ed by core@
 1.34.4.1 29-Apr-2005  kent sync with -current
 1.36.2.3 26-Mar-2005  yamt sync with head.
 1.36.2.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.36.2.1 12-Feb-2005  yamt sync with head.
 1.42.2.18 15-Oct-2007  riz Pull up following revisions via patch (requested by bouyer in ticket #1838):
distrib/sets/lists/man/mi: revision 1.997
sbin/bioctl/strtonum.c: revision 1.1
sys/dev/Makefile: revision 1.25
sys/arch/amd64/conf/GENERIC: revision 1.139
sbin/bioctl/strtonum.h: revision 1.1
sys/dev/bio.c: revision 1.1
sbin/bioctl/bioctl.c: revision 1.1
share/man/man4/bio.4: revision 1.1
sbin/bioctl/bioctl.8: revision 1.1
sys/sys/envsys.h: revision 1.11
sbin/bioctl/bioctl.8: revision 1.3
sbin/bioctl/bioctl.8: revision 1.4
sys/arch/i386/conf/XEN2_DOM0: revision 1.25
distrib/sets/lists/base/mi: revision 1.704
sys/conf/majors: revision 1.34
share/man/man4/Makefile: revision 1.426
etc/MAKEDEV.tmpl: revision 1.86
sys/arch/i386/conf/GENERIC: revision 1.825
distrib/sets/lists/comp/mi: revision 1.1022
sys/conf/files: revision 1.839
usr.sbin/envstat/envstat.c: revision 1.24
sbin/Makefile: revision 1.105
sys/dev/ic/mfi.c: revision 1.4
sys/dev/biovar.h: revision 1.1
sys/dev/ic/mfivar.h: revision 1.4
sbin/bioctl/Makefile: revision 1.1
Fix typo.
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.
Fix Dd argument (use full month names).
Use more markup.
Comment out references to safte(4) and softraid(4), which don't exist in
NetBSD.
Remove trailing whitespace.
Use macros instead of characters for HTML output (replace ">", "<"
with \*[Gt], \*[Lt]).
Sort sections.
Create /dev/bio
 1.42.2.17 28-Aug-2007  ghen Pull up following revision(s) (requested by adrianp in ticket #1826):
sys/arch/hp300/conf/GENERIC: revision 1.141 via patch
sys/arch/amd64/conf/GENERIC: revision 1.154 via patch
sys/arch/cats/conf/GENERIC: revision 1.116 via patch
sys/arch/arc/conf/GENERIC: revision 1.148 via patch
sys/arch/acorn32/conf/GENERIC: revision 1.80 via patch
sys/arch/sparc/conf/GENERIC: revision 1.200 via patch
sys/arch/sparc64/conf/GENERIC: revision 1.88 via patch
sys/arch/atari/conf/GENERIC.in: revision 1.68 via patch
sys/arch/amiga/conf/GENERIC: revision 1.248 via patch
sys/arch/i386/conf/GENERIC.MPACPI: patch
sys/arch/i386/conf/GENERIC_LAPTOP: revision 1.239 via patch
sys/arch/sgimips/conf/GENERIC32_IP3x: revision 1.66 via patch
sys/arch/i386/conf/GENERIC: revision 1.840 via patch
sys/arch/amiga/conf/GENERIC.in: revision 1.61 via patch
sys/arch/sgimips/conf/GENERIC32_IP2x: revision 1.68 via patch
sys/arch/mac68k/conf/GENERIC: revision 1.182 via patch
Remove iso(4) from GENERIC kernels, as discussed on tech-net&#64;
Ok'ed by core&#64;
 1.42.2.16 27-May-2007  bouyer Pull up following revision(s) (requested by jnemeth in ticket #1778):
sys/arch/hpcarm/conf/IPAQ: revision 1.50
sys/arch/amd64/conf/GENERIC: revision 1.141
sys/arch/amd64/conf/INSTALL: revision 1.68
sys/arch/i386/conf/SWINGER: revision 1.90
PR/36234 - Joerg Niendorf -- xi -> xirc
 1.42.2.15 03-Mar-2007  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1673):
distrib/sets/lists/man/mi 1.844, 1.871
share/man/man4/Makefile 1.372, 1.379 via patch
share/man/man4/re.4 1.8, 1.9, 1.11, 1.12
share/man/man4/rgephy.4 1.1
share/man/man4/rlphy.4 1.1, 1.2
sys/arch/amd64/conf/GENERIC 1.79, 1.89
sys/arch/amd64/conf/INSTALL 1.45, 1.49
sys/arch/i386/conf/GENERIC 1.717, 1.747
sys/arch/i386/conf/GENERIC_LAPTOP 1.164
sys/arch/i386/conf/INSTALL 1.277, 1.283
sys/arch/i386/conf/INSTALL_LAPTOP 1.96, 1.98
sys/arch/i386/conf/XEN2_DOM0 1.22 via patch
sys/arch/macppc/conf/GENERIC 1.220, 1.246
sys/arch/macppc/conf/INSTALL 1.96, 1.100
sys/dev/cardbus/if_re_cardbus.c 1.10
sys/dev/cardbus/if_rtk_cardbus.c 1.29-1.31
sys/dev/ic/rtl8169.c 1.14, 1.20, 1.24, 1.25, 1.28-1.61, 1.63, 1.64-1.81 via patch
sys/dev/ic/rtl81x9.c 1.52, 1.54-1.63, 1.65, 1.67-1.70
sys/dev/ic/rtl81x9reg.h 1.15-1.26
sys/dev/ic/rtl81x9var.h 1.19, 1.21-1.37
sys/dev/mii/files.mii 1.38
sys/dev/mii/miidevs 1.62, 1.64
sys/dev/mii/rgephy.c 1.10, 1.13-1.16
sys/dev/mii/rlphy.c 1.1, 1.6, 1.7, 1.11 via patch
sys/dev/pci/if_re_pci.c 1.13, 1.15-1.17, 1.19-1.23
sys/dev/pci/if_rtk_pci.c 1.25, 1.28, 1.29, 1.31
sys/dev/pci/pcidevs 1.851, 1.852

on re(4):
- improve stability (I believe ;-)
- add a workaround for hardware ip4csum-tx bug
- support newer chips (8169SB/SC, PCIe based 8168 etc.)
- fix 8139C+ support
- enable hardware VLAN
- misc bus_dma(9) fix (which makes re(4) work on mips ports)

on rtk(4):
- fix kern/31348
- fix possible panic on dreamcast
 1.42.2.14 23-Dec-2006  ghen Pull up following revision(s) (requested by bouyer in ticket #1609):
sys/arch/i386/conf/INSTALL: revision 1.298
sys/arch/i386/conf/GENERIC: revision 1.802
sys/dev/pci/files.pci: revision 1.274
sys/arch/amd64/conf/GENERIC: revision 1.122
sys/dev/pci/mfi_pci.c: revision 1.1 via patch
distrib/sets/lists/man/mi: revision 1.958
sys/arch/amd64/conf/INSTALL: revision 1.61
sys/dev/ic/mfireg.h: revision 1.1
share/man/man4/Makefile: revision 1.416 via patch
sys/dev/ic/mfi.c: revision 1.1
sys/arch/i386/conf/XEN2_DOM0: revision 1.19
sys/dev/ic/mfivar.h: revision 1.1
sys/conf/files: revision 1.821
share/man/man4/mfi.4: revision 1.1
share/man/man4/mfi.4: revision 1.2
sys/dev/pci/pcidevs via patch
Add mfi(4), a driver for LSI Logic & Dell MegaRAID SAS RAID controller.
Ported from OpenBSD, tested on i386 and amd64.
Punctuation issues.
 1.42.2.13 23-Dec-2006  ghen Pull up following revision(s) (requested by bouyer in ticket #1608):
sys/arch/i386/conf/INSTALL: revision 1.299 via patch
sys/arch/i386/conf/XEN2_DOM0: revision 1.20 via patch
sys/arch/i386/conf/GENERIC: revision 1.803 via patch
sys/dev/pci/files.pci: revision 1.275 via patch
sys/arch/i386/conf/GENERIC_LAPTOP: revision 1.218 via patch
sys/arch/amd64/conf/GENERIC: revision 1.123 via patch
sys/dev/pci/if_bnx.c: revision 1.1 via patch
share/man/man4/bnx.4: revision 1.1-1.2 via patch
distrib/sets/lists/man/mi: revision 1.959 via patch
sys/arch/amd64/conf/INSTALL: revision 1.62 via patch
sys/dev/microcode/bnx/bnxfw.h: revision 1.1-1.2 via patch
sys/dev/pci/if_bnxreg.h: revision 1.1 via patch
share/man/man4/Makefile: revision 1.417 via patch
sys/arch/i386/conf/INSTALL_LAPTOP: revision 1.112 via patch
Add bnx(4), a driver for Broadcom NetXtreme II 10/100/1000 Ethernet device.
Ported from OpenBSD by cube@, with some bus_dma fixes by me.
Tested on i386 and amd64.
Add a NetBSD RCS tag.
Nx -> Ox; remove trailing whitespace.
 1.42.2.12 31-Jul-2006  tron branches: 1.42.2.12.2;
Apply patch (requested by bouyer in ticket #1441):
Pullup the twa(4) driver for the 3ware Apache RAID controllers.
Matching revisions in current:
share/man/man4/twa.4 1.1
sys/dev/pci/ld_twa.c 1.2
sys/dev/pci/twa.c 1.9
sys/dev/pci/twaio.h 1.3
sys/dev/pci/twareg.h 1.5
sys/dev/pci/twavar.h 1.5
 1.42.2.11 04-May-2006  tron Pull up following revision(s) (requested by jonathan in ticket #1298):
sys/arch/amd64/conf/INSTALL: revision 1.53
sys/arch/amd64/conf/GENERIC: revision 1.94
Add entries for svwsata(4) to amd64 GENERIC and INSTALL kernels,
to support SATA ports on Serverworks HT-1000 (aka bcm5785) chips.
 1.42.2.10 20-Apr-2006  tron Pull up following revision(s) (requested by martti in ticket #1258):
sys/arch/i386/conf/INSTALL: revision 1.284
sys/arch/i386/conf/GENERIC: revision 1.741
sys/arch/amd64/conf/GENERIC: revision 1.91
sys/arch/i386/conf/INSTALL_SMALL: revision 1.125
sys/arch/amd64/conf/INSTALL: revision 1.50
sys/arch/i386/conf/INSTALL_TINY: revision 1.102
Added ciss(4). Tested by Joseph Dacuma on HP DL-380 G3 with Smart Array 5i.
 1.42.2.9 20-Apr-2006  snj Pull up following revision(s) (requested by tron in ticket #1266):
sys/arch/amd64/conf/GENERIC: revision 1.88
sys/arch/i386/conf/INSTALL: revision 1.282
sys/arch/amd64/conf/INSTALL: revision 1.48
sys/arch/i386/conf/XEN0: revision 1.35
sys/arch/i386/conf/GENERIC: revision 1.733
add nfe.
 1.42.2.8 20-Feb-2006  tron Pull up following revision(s) (requested by tls in ticket #1180):
sys/arch/amd64/conf/GENERIC: revision 1.87
sys/arch/i386/conf/GENERIC: revision 1.727
Add amdpm -- without this, we're throwing away a good hardware random
number source on a huge set of machines. Also, now that amdpm has
support for the SMBus controller, add (commented-out, since we don't
always know what address the sensors are at) iic at amdpm and adt7463c
at iic, which is the configuration used on the Tyan S2881 and S2882-D
server boards. This should work in either 64-bit or 32-bit mode; it's
been tested in 64-bit mode. Addresses PR kern/32463 submitted by
Anil Gopinath.
 1.42.2.7 15-Sep-2005  snj branches: 1.42.2.7.2;
Pull up following revision(s) (requested by tron in ticket #786):
sys/arch/amd64/conf/GENERIC: revision 1.71
sys/arch/i386/conf/GENERIC.MPACPI: revision 1.46
sys/arch/i386/conf/GENERIC: revision 1.700
Add 10 Gigabit Ethernet drivers dge(4) and xge(4).
 1.42.2.6 15-Sep-2005  snj Pull up following revision(s) (requested by tron in ticket #786):
sys/arch/amd64/conf/GENERIC: revision 1.43
correctly alphabetize bce, skc/sk, inphy relative to their neighbors.
devices. correct typo in bce comment.
 1.42.2.5 14-Aug-2005  riz Pull up revision 1.60 (requested by hubertf in ticket #625):
Add support for reading cloop2 compressed filesystem images,
enable by putting VND_COMPRESSION into kernel config file.
Written by Cliff Wright, polished up slightly by me.
 1.42.2.4 18-Jul-2005  riz Pull up revision 1.56 (requested by tron in ticket #566):
Add (commented out) IPSEC_NAT_T option.
 1.42.2.3 05-Jul-2005  tron Pull up revision 1.54 (requested by martti in ticket #546):
Added support for amr. Tested by Joseph A. Dacuma with Dell PowerEdge 2800.
 1.42.2.2 02-Jul-2005  tron Pull up revision 1.48 (requested by kent in ticket #494):
add "azalia at pci"
 1.42.2.1 17-Apr-2005  tron Pull up revision 1.46 (requested by itohy in ticket #160):
Add ukyopon(4).
 1.42.2.12.2.2 28-Aug-2007  ghen Pull up following revision(s) (requested by adrianp in ticket #1826):
sys/arch/hp300/conf/GENERIC: revision 1.141 via patch
sys/arch/amd64/conf/GENERIC: revision 1.154 via patch
sys/arch/cats/conf/GENERIC: revision 1.116 via patch
sys/arch/arc/conf/GENERIC: revision 1.148 via patch
sys/arch/acorn32/conf/GENERIC: revision 1.80 via patch
sys/arch/sparc/conf/GENERIC: revision 1.200 via patch
sys/arch/sparc64/conf/GENERIC: revision 1.88 via patch
sys/arch/atari/conf/GENERIC.in: revision 1.68 via patch
sys/arch/amiga/conf/GENERIC: revision 1.248 via patch
sys/arch/i386/conf/GENERIC.MPACPI: patch
sys/arch/i386/conf/GENERIC_LAPTOP: revision 1.239 via patch
sys/arch/sgimips/conf/GENERIC32_IP3x: revision 1.66 via patch
sys/arch/i386/conf/GENERIC: revision 1.840 via patch
sys/arch/amiga/conf/GENERIC.in: revision 1.61 via patch
sys/arch/sgimips/conf/GENERIC32_IP2x: revision 1.68 via patch
sys/arch/mac68k/conf/GENERIC: revision 1.182 via patch
Remove iso(4) from GENERIC kernels, as discussed on tech-net@
Ok'ed by core@
 1.42.2.12.2.1 27-May-2007  bouyer Pull up following revision(s) (requested by jnemeth in ticket #1778):
sys/arch/hpcarm/conf/IPAQ: revision 1.50
sys/arch/amd64/conf/GENERIC: revision 1.141
sys/arch/amd64/conf/INSTALL: revision 1.68
sys/arch/i386/conf/SWINGER: revision 1.90
PR/36234 - Joerg Niendorf -- xi -> xirc
 1.42.2.7.2.2 28-Aug-2007  ghen Pull up following revision(s) (requested by adrianp in ticket #1826):
sys/arch/hp300/conf/GENERIC: revision 1.141 via patch
sys/arch/amd64/conf/GENERIC: revision 1.154 via patch
sys/arch/cats/conf/GENERIC: revision 1.116 via patch
sys/arch/arc/conf/GENERIC: revision 1.148 via patch
sys/arch/acorn32/conf/GENERIC: revision 1.80 via patch
sys/arch/sparc/conf/GENERIC: revision 1.200 via patch
sys/arch/sparc64/conf/GENERIC: revision 1.88 via patch
sys/arch/atari/conf/GENERIC.in: revision 1.68 via patch
sys/arch/amiga/conf/GENERIC: revision 1.248 via patch
sys/arch/i386/conf/GENERIC.MPACPI: patch
sys/arch/i386/conf/GENERIC_LAPTOP: revision 1.239 via patch
sys/arch/sgimips/conf/GENERIC32_IP3x: revision 1.66 via patch
sys/arch/i386/conf/GENERIC: revision 1.840 via patch
sys/arch/amiga/conf/GENERIC.in: revision 1.61 via patch
sys/arch/sgimips/conf/GENERIC32_IP2x: revision 1.68 via patch
sys/arch/mac68k/conf/GENERIC: revision 1.182 via patch
Remove iso(4) from GENERIC kernels, as discussed on tech-net@
Ok'ed by core@
 1.42.2.7.2.1 27-May-2007  bouyer Pull up following revision(s) (requested by jnemeth in ticket #1778):
sys/arch/hpcarm/conf/IPAQ: revision 1.50
sys/arch/amd64/conf/GENERIC: revision 1.141
sys/arch/amd64/conf/INSTALL: revision 1.68
sys/arch/i386/conf/SWINGER: revision 1.90
PR/36234 - Joerg Niendorf -- xi -> xirc
 1.55.2.10 17-Mar-2008  yamt sync with head.
 1.55.2.9 04-Feb-2008  yamt sync with head.
 1.55.2.8 21-Jan-2008  yamt sync with head
 1.55.2.7 07-Dec-2007  yamt sync with head
 1.55.2.6 15-Nov-2007  yamt sync with head.
 1.55.2.5 27-Oct-2007  yamt sync with head.
 1.55.2.4 03-Sep-2007  yamt sync with head.
 1.55.2.3 26-Feb-2007  yamt sync with head.
 1.55.2.2 30-Dec-2006  yamt sync with head.
 1.55.2.1 21-Jun-2006  yamt sync with head.
 1.72.2.1 29-Nov-2005  yamt sync with head.
 1.78.2.4 01-Mar-2006  yamt sync with head.
 1.78.2.3 18-Feb-2006  yamt sync with head.
 1.78.2.2 01-Feb-2006  yamt sync with head.
 1.78.2.1 15-Jan-2006  yamt sync with head.
 1.81.2.1 09-Sep-2006  rpaulo sync with head
 1.82.2.2 01-Jun-2006  kardel Sync with head.
 1.82.2.1 22-Apr-2006  simonb Sync with head.
 1.87.4.2 11-May-2006  elad sync with head
 1.87.4.1 19-Apr-2006  elad sync with head - hopefully this will work
 1.87.2.6 14-Sep-2006  yamt sync with head.
 1.87.2.5 03-Sep-2006  yamt sync with head.
 1.87.2.4 11-Aug-2006  yamt sync with head
 1.87.2.3 24-May-2006  yamt sync with head.
 1.87.2.2 01-Apr-2006  yamt sync with head.
 1.87.2.1 13-Mar-2006  yamt sync with head.
 1.88.2.3 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.88.2.2 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.88.2.1 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.94.4.1 13-Jul-2006  gdamore Merge from HEAD.
 1.102.2.3 22-Sep-2006  riz Pull up following revision(s) (requested by tsutsui in ticket #170):
sys/arch/sparc64/conf/GENERIC: revision 1.63
sys/arch/sgimips/conf/GENERIC32_IP3x: revision 1.55
sys/arch/sgimips/conf/GENERIC32_IP2x: revision 1.54
sys/arch/next68k/conf/GENERIC: revision 1.105
sys/arch/ews4800mips/conf/GENERIC: revision 1.12
sys/arch/arc/conf/GENERIC: revision 1.142
sys/arch/sun3/conf/GENERIC3X: revision 1.91
sys/arch/amd64/conf/GENERIC: revision 1.105
sys/arch/sun2/conf/GENERIC: revision 1.58
sys/arch/amiga/conf/GENERIC.in: revision 1.55
sys/arch/mac68k/conf/GENERIC: revision 1.175
sys/arch/acorn26/conf/GENERIC: revision 1.46
sys/arch/shark/conf/GENERIC: revision 1.65
sys/arch/cesfic/conf/GENERIC: revision 1.45
sys/arch/sandpoint/conf/GENERIC: revision 1.36
sys/arch/iyonix/conf/GENERIC: revision 1.32
sys/arch/mvme68k/conf/GENERIC: revision 1.69
sys/arch/evbarm/conf/ARMADILLO210: revision 1.3
sys/arch/vax/conf/GENERIC: revision 1.154
sys/arch/mipsco/conf/GENERIC: revision 1.61
sys/arch/evbarm/conf/ARMADILLO9: revision 1.14
sys/arch/cobalt/conf/GENERIC: revision 1.103
sys/arch/ofppc/conf/GENERIC: revision 1.94
sys/arch/hp700/conf/GENERIC: revision 1.69
sys/arch/playstation2/conf/GENERIC: revision 1.8
sys/arch/dreamcast/conf/GENERIC: revision 1.73
sys/arch/news68k/conf/GENERIC: revision 1.81
sys/arch/macppc/conf/GENERIC: revision 1.234
sys/arch/hp300/conf/GENERIC: revision 1.134
sys/arch/mmeye/conf/GENERIC: revision 1.83
sys/arch/ibmnws/conf/GENERIC: revision 1.26
sys/arch/cats/conf/GENERIC: revision 1.109
sys/arch/sparc/conf/GENERIC: revision 1.191
sys/arch/pdp10/conf/GENERIC: revision 1.27
sys/arch/acorn32/conf/GENERIC: revision 1.75
sys/arch/luna68k/conf/GENERIC: revision 1.74
sys/arch/bebox/conf/GENERIC: revision 1.101
sys/arch/pmax/conf/GENERIC: revision 1.148
sys/arch/x68k/conf/GENERIC: revision 1.130
sys/arch/sun3/conf/GENERIC: revision 1.134
sys/arch/prep/conf/GENERIC: revision 1.126
sys/arch/alpha/conf/GENERIC: revision 1.293
sys/arch/newsmips/conf/GENERIC: revision 1.94
sys/arch/netwinder/conf/GENERIC: revision 1.83
sys/arch/hpcsh/conf/GENERIC: revision 1.69
sys/arch/sbmips/conf/GENERIC: revision 1.55
sys/arch/pc532/conf/GENERIC: revision 1.65
sys/arch/hpcmips/conf/GENERIC: revision 1.192
Remove obsolete #options VERIFIED_EXEC, found by grep(1).
 1.102.2.2 15-Sep-2006  tron Pull up following revision(s) (requested by riz in ticket #153):
sys/arch/amd64/conf/INSTALL: revision 1.56
sys/arch/amd64/conf/GENERIC: revision 1.107
sys/arch/i386/conf/XEN2_DOM0: revision 1.7
sys/arch/i386/conf/INSTALL: revision 1.289
sys/arch/i386/conf/GENERIC: revision 1.780
Add msk and mskc.
 1.102.2.1 14-Aug-2006  tron Pull up following revision(s) (requested by elad in ticket #17):
sys/arch/sparc/conf/KRUPS: revision 1.38
sys/arch/i386/conf/XEN2_DOMU: revision 1.2
sys/arch/i386/conf/GENERIC_LAPTOP: revision 1.197
sys/arch/sgimips/conf/GENERIC32_IP2x: revision 1.53
sys/arch/evbsh5/conf/SIMULATOR: revision 1.12
sys/arch/sparc/conf/MRCOFFEE: revision 1.17
sys/arch/next68k/conf/GENERIC: revision 1.104
sys/arch/i386/conf/VIRTUALPC: revision 1.44
sys/arch/ews4800mips/conf/GENERIC: revision 1.11
sys/arch/evbsh5/conf/CAYMAN: revision 1.23
sys/arch/arc/conf/GENERIC: revision 1.141
sys/arch/amd64/conf/GENERIC: revision 1.103
sys/arch/sun3/conf/GENERIC3X: revision 1.90
sys/arch/evbarm/conf/HDL_G: revision 1.3
sys/arch/sun2/conf/GENERIC: revision 1.57
sys/arch/news68k/conf/GENERIC_TINY: revision 1.51
sys/arch/evbppc/conf/EXPLORA451: revision 1.27
sys/arch/amiga/conf/GENERIC.in: revision 1.54
sys/arch/mac68k/conf/GENERIC: revision 1.174
sys/arch/acorn26/conf/GENERIC: revision 1.45
sys/arch/shark/conf/GENERIC: revision 1.64
sys/arch/cesfic/conf/GENERIC: revision 1.44
sys/arch/mvme68k/conf/GENERIC: revision 1.68
sys/arch/i386/conf/XEN2_DOM0: revision 1.4
sys/arch/atari/conf/GENERIC.in: revision 1.63
sys/arch/amiga/conf/GENERIC: revision 1.240
sys/arch/i386/conf/LAMB: revision 1.65
sys/arch/i386/conf/GENERIC: revision 1.773
sys/arch/acorn32/conf/EB7500ATX: revision 1.26
sys/arch/x68k/conf/GENERIC: revision 1.128
sys/arch/vax/conf/GENERIC: revision 1.153
sys/arch/atari/conf/ATARITT: revision 1.81
sys/arch/mipsco/conf/GENERIC: revision 1.60
sys/arch/cobalt/conf/GENERIC: revision 1.101
sys/arch/evbarm/conf/ARMADILLO9: revision 1.13
sys/arch/ofppc/conf/GENERIC: revision 1.93
sys/arch/atari/conf/MILAN-PCIIDE: revision 1.51
sys/arch/arc/conf/RPC44: revision 1.26
sys/arch/sparc64/conf/GENERIC: revision 1.59
sys/arch/i386/conf/XEN3_DOMU: revision 1.2
sys/arch/hp700/conf/GENERIC: revision 1.68
sys/arch/atari/conf/MILAN-ISAIDE: revision 1.47
sys/arch/macppc/conf/GENERIC: revision 1.231
sys/arch/dreamcast/conf/GENERIC: revision 1.72
sys/arch/news68k/conf/GENERIC: revision 1.80
sys/arch/hp300/conf/GENERIC: revision 1.133
sys/arch/mmeye/conf/GENERIC: revision 1.82
sys/arch/macppc/conf/MAMBO: revision 1.2
sys/arch/cats/conf/GENERIC: revision 1.107
sys/arch/atari/conf/FALCON: revision 1.79
sys/arch/acorn32/conf/GENERIC: revision 1.71
sys/arch/sparc/conf/GENERIC: revision 1.190
sys/arch/news68k/conf/LIBERO: revision 1.40
sys/arch/amiga/conf/DRACO: revision 1.114
sys/arch/cobalt/conf/INSTALL: revision 1.23
sys/arch/luna68k/conf/GENERIC: revision 1.73
sys/arch/bebox/conf/GENERIC: revision 1.100
sys/arch/pmax/conf/GENERIC: revision 1.147
sys/arch/amiga/conf/WSCONS: revision 1.52
sys/arch/macppc/conf/POWERMAC_G5: revision 1.2
sys/arch/alpha/conf/ALPHA: revision 1.218
sys/arch/sun3/conf/GENERIC: revision 1.133
sys/arch/prep/conf/GENERIC: revision 1.124
sys/arch/alpha/conf/GENERIC: revision 1.291
sys/arch/atari/conf/HADES: revision 1.71
sys/arch/newsmips/conf/GENERIC: revision 1.93
sys/arch/netwinder/conf/GENERIC: revision 1.82
sys/arch/hpcmips/conf/GENERIC: revision 1.190
sys/arch/amiga/conf/AMIGA: revision 1.98
sys/arch/sbmips/conf/GENERIC: revision 1.54
sys/arch/pc532/conf/GENERIC: revision 1.64
sys/arch/sgimips/conf/GENERIC32_IP3x: revision 1.53
Disable SYSTRACE by default on all kernels (discussed with core)
 1.106.2.4 06-Feb-2007  ad Add pseudo-device lockstat.
 1.106.2.3 01-Feb-2007  ad Sync with head.
 1.106.2.2 12-Jan-2007  ad Sync with head.
 1.106.2.1 18-Nov-2006  ad Sync with head.
 1.108.2.3 18-Dec-2006  yamt sync with head.
 1.108.2.2 10-Dec-2006  yamt sync with head.
 1.108.2.1 22-Oct-2006  yamt sync with head
 1.120.2.19 24-Mar-2009  bouyer Pullup the following revisions (requested by msaitoh in ticket #1284):
distrib/sets/lists/base/mi 1.706-707,1.797
distrib/sets/lists/man/mi 1.1006
etc/mtree/NetBSD.dist 1.340
share/man/man4/Makefile 1.432
sys/arch/amd64/conf/GENERIC 1.149 via patch
sys/arch/i386/conf/ALL 1.103
sys/arch/i386/conf/GENERIC 1.832
sys/arch/i386/conf/GENERIC_LAPTOP 1.237
sys/arch/macppc/conf/GENERIC 1.257
sys/arch/sparc64/conf/GENERIC 1.86
sys/dev/usb/usbdevs 1.468,1.479-480 via patch
sys/dev/usb/usbdevs.h regen
sys/dev/usb/usbdevs_data.h regen
sys/dev/microcode/Makefile 1.7
sys/dev/usb/files.usb patch
share/man/man4/zyd.4 1.1 via patch
sys/dev/microcode/zyd/Makefile 1.1-1.2
sys/dev/microcode/zyd/build.c 1.1
sys/dev/microcode/zyd/microcode.h 1.1
sys/dev/microcode/zyd/zd1211-license 1.1
sys/dev/microcode/zyd/zyd-zd1211 1.1
sys/dev/microcode/zyd/zyd-zd1211b 1.1
sys/dev/usb/if_zyd.c patch
sys/dev/usb/if_zydreg.h 1.1-1.2

Add ZyDAS ZD1211/ZD1211B USB IEEE 802.11b/g wireless network device support
 1.120.2.18 11-Jan-2008  xtraeme Pull up following revision(s) (requested by christos in ticket #1037):
sys/dev/pci/arcmsr.c: patch
sys/dev/pci/arcmsrvar.h: patch
sys/dev/pci/pcidevs: patch
sys/dev/pci/files.pci: patch
sys/arch/i386/conf/GENERIC: patch
sys/arch/i386/conf/XEN2_DOM0: patch
sys/arch/i386/conf/INSTALL_LARGE: patch
sys/arch/amd64/conf/GENERIC: patch
sys/arch/amd64/conf/INSTALL: patch
share/man/man4/Makefile: patch
share/man/man4/arcmsr.4: patch
distrib/sets/lists/man/mi: patch

Add the Areca Technology Corporation SATA RAID controller driver, ported
from OpenBSD.
 1.120.2.17 19-Dec-2007  ghen Pull up following revision(s) (requested by briggs in ticket #989):
sys/arch/amd64/conf/GENERIC: revision 1.151
sys/arch/x86/x86/ipmi.c: revision 1.12
sys/dev/DEVNAMES: revision 1.228
sys/arch/amd64/amd64/bios32.c: revision 1.6
sys/arch/x86/x86/ipmi.c: revision 1.8
sys/arch/amd64/conf/files.amd64: revision 1.39 via patch
sys/arch/amd64/amd64/mainbus.c: revision 1.17
Use PRIx64 for a 64-bit quantity instead of llx in a debug print.
Add (commented-out) support for IPMI on amd64--pretty much copied straight
from i386.
Check for duplicate sensor names in the IPMI table. If a duplicate name
is found, try to make it unique by appending a count (1-99) to the sensor
description (truncating, if necessary).
 1.120.2.16 26-Nov-2007  xtraeme Pull up following revision(s) (requested by jnemeth in ticket #998):
sys/arch/amd64/conf/GENERIC: revision 1.176 (patch)
sys/arch/i386/conf/GENERIC: revision 1.863
comment out com*/lpt* at acpi? as they cause these ports to move from
their traditional location and imminent changes in -current will cause
them to move back
 1.120.2.15 25-Nov-2007  xtraeme Pull up following revision(s) (requested by briggs in ticket #990):
sys/dev/ic/aac_tables.h: revision 1.5 (patch)
sys/dev/ic/aac.c: revision 1.31 (patch)
sys/dev/ic/aac.c: revision 1.32 (patch)
sys/dev/ic/aac.c: revision 1.33 (patch)
sys/dev/ic/aac.c: revision 1.34 (patch)
sys/arch/amd64/conf/INSTALL: revision 1.70 (patch)
sys/dev/ic/aac.c: revision 1.37 (patch)
sys/dev/ic/aacreg.h: revision 1.6 (patch)
sys/dev/ic/aacreg.h: revision 1.7 (patch)
sys/dev/ic/aacreg.h: revision 1.8 (patch)
sys/dev/ic/aacreg.h: revision 1.9 (patch)
sys/dev/pci/aac_pci.c: revision 1.21 (patch)
sys/dev/ic/aacvar.h: revision 1.10 (patch)
sys/dev/ic/aacvar.h: revision 1.9 (patch)
sys/arch/amd64/conf/GENERIC: revision 1.144 (patch)
sys/dev/ic/ld_aac.c: revision 1.14 (patch)
sys/dev/ic/ld_aac.c: revision 1.15 (patch)
Compile and run on amd64 and on >2GB RAM.
 1.120.2.14 05-Nov-2007  pavel Apply patch (requested by joerg in ticket #963):
sys/arch/amd64/conf/GENERIC: patch
Reduce difference to i386 GENERIC:
- add some comments from that
- options SPACE TAB
- enable EST
- enable DDB and build w/ frame pointer by default
- enable ACPI devices
- include Cardbus and PCMCIA
- include Synaptics driver
- include atw, ipw, iwi, hme, rtw, txp
- include uep, utoppy, ugensa
This makes GENERIC actually usable for laptops.
 1.120.2.13 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.120.2.12 31-Aug-2007  pavel Pull up following revision(s) (requested by bouyer in ticket #678):
distrib/sets/lists/man/mi: revision 1.1001
doc/CHANGES: revision 1.853 via patch
share/man/man4/Makefile: revision 1.428
share/man/man4/jmide.4: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.143
sys/arch/amd64/conf/INSTALL: revision 1.69
sys/arch/i386/conf/GENERIC: revision 1.827
sys/arch/i386/conf/INSTALL_LARGE: revision 1.2 via patch
sys/arch/i386/conf/XEN2_DOM0: revision 1.26
sys/conf/files: revision 1.844 via patch
sys/dev/ic/ahcisata_core.c: revision 1.1 via patch
sys/dev/ic/ahcisata_core.c: revision 1.3
sys/dev/ic/ahcisatareg.h: revision 1.1
sys/dev/ic/ahcisatavar.h: revision 1.1
sys/dev/pci/ahcisata.c: delete
sys/dev/pci/ahcisatareg.h: delete
sys/dev/pci/ahcisata_pci.c: revision 1.1
sys/dev/pci/files.pci: revision 1.287-1.288
sys/dev/pci/jmide.c: revision 1.1-1.2
sys/dev/pci/jmide_reg.h: revision 1.1
sys/dev/pci/pcidevs: revision 1.878
Add JMicron Technology vendor ID, and their current PCIe SATA/PATA
controllers.

Split the ahcisata driver in pci front-end and bus-independant back-end.
add jmide(4), a driver for the JMicron Technology JMB36x PCIe to SATA II/PATA
controllers. These controllers can be found on add-on PCIe cards, or
on some motherboards to provide the PATA connectivity (e.g. some intel
ICH8-based motherboards).
Thanks to JMicron Technology for providing me documentation and
different sample boards for this work.

Move mapping of AHCI register so that jmide knows if it fails, and avoids
calling ahci_intr() (which would cause a panic).
Try to use the pciide function for SATA drives if attaching ahci fails (this
doesn't seems to work though, it may be BIOS dependant).
Thanks to Gary Duzan for testing multiple pacthes.

We're not ready to handle ATAPI yet so just claim there's no drive to the
upper layer. This should work around a NULL pointer dereference when
an ATAPI device is detected on a AHCI device.
 1.120.2.11 25-Aug-2007  liamjfoy Pull up following revision(s) (requested by adrianp in ticket #820):
sys/arch/hp300/conf/GENERIC: revision 1.141
sys/arch/alpha/conf/GENERIC: revision 1.315
sys/arch/amd64/conf/GENERIC: revision 1.154
sys/arch/cats/conf/GENERIC: revision 1.116
sys/arch/arc/conf/GENERIC: revision 1.148
sys/arch/acorn32/conf/GENERIC: revision 1.80
sys/arch/sparc/conf/GENERIC: revision 1.200
sys/arch/sparc64/conf/GENERIC: revision 1.88
sys/arch/atari/conf/GENERIC.in: revision 1.68
sys/arch/amiga/conf/GENERIC: revision 1.248
sys/arch/i386/conf/GENERIC_LAPTOP: revision 1.239
sys/arch/sgimips/conf/GENERIC32_IP3x: revision 1.66
sys/arch/i386/conf/GENERIC: revision 1.840
sys/arch/amiga/conf/GENERIC.in: revision 1.61
sys/arch/sgimips/conf/GENERIC32_IP2x: revision 1.68
sys/arch/mac68k/conf/GENERIC: revision 1.182
Remove iso(4) from GENERIC kernels, as discussed on tech-net@
Ok'ed by core@
 1.120.2.10 27-Jul-2007  liamjfoy Pullup requested by degroote in ticket 795:

Add wpi(4).
 1.120.2.9 05-Jun-2007  bouyer Pull up following revision(s) (requested by martin in ticket #699):
sys/arch/hpcmips/conf/GENERIC: revision 1.196
sys/arch/hp700/conf/GENERIC: revision 1.74
sys/arch/i386/conf/GENERIC: revision 1.831
sys/arch/next68k/conf/GENERIC: revision 1.108
sys/arch/alpha/conf/GENERIC: revision 1.313
sys/arch/arc/conf/GENERIC: revision 1.146
sys/arch/cats/conf/GENERIC: revision 1.115
sys/arch/ews4800mips/conf/GENERIC: revision 1.18
sys/arch/landisk/conf/GENERIC: revision 1.8 via patch
sys/arch/sparc64/conf/GENERIC: revision 1.85
sys/arch/pmax/conf/GENERIC: revision 1.152
sys/arch/iyonix/conf/GENERIC: revision 1.38 via patch
sys/arch/amiga/conf/GENERIC: revision 1.245
sys/arch/vax/conf/GENERIC: revision 1.157
sys/arch/prep/conf/GENERIC: revision 1.135
sys/arch/pc532/conf/GENERIC: revision 1.70
sys/arch/sbmips/conf/GENERIC: revision 1.61
sys/arch/mipsco/conf/GENERIC: revision 1.65
sys/arch/cobalt/conf/GENERIC: revision 1.108
sys/arch/ofppc/conf/GENERIC: revision 1.98
sys/arch/amd64/conf/GENERIC: revision 1.148
sys/arch/acorn26/conf/GENERIC: revision 1.50
sys/arch/dreamcast/conf/GENERIC: revision 1.78
sys/arch/mac68k/conf/GENERIC: revision 1.181
sys/arch/hp300/conf/GENERIC: revision 1.139
sys/arch/mmeye/conf/GENERIC: revision 1.88
sys/arch/news68k/conf/GENERIC: revision 1.88
sys/arch/mvme68k/conf/GENERIC: revision 1.71
sys/arch/acorn32/conf/GENERIC: revision 1.79
sys/arch/sparc/conf/GENERIC: revision 1.199
sys/arch/luna68k/conf/GENERIC: revision 1.78
sys/arch/bebox/conf/GENERIC: revision 1.105
sys/arch/macppc/conf/GENERIC: revision 1.256 via patch
sys/arch/x68k/conf/GENERIC: revision 1.134
sys/arch/sun3/conf/GENERIC: revision 1.138
sys/arch/newsmips/conf/GENERIC: revision 1.98
Add pseudo-device agr to all GENERIC kernels where it might make sense
(commented out in some).
 1.120.2.8 13-May-2007  pavel branches: 1.120.2.8.2;
Pull up patch (requested by xtraeme in ticket #633):
sys/arch/amd64/conf/GENERIC: patch
sys/arch/i386/conf/ALL: patch
sys/arch/i386/conf/GENERIC: patch
sys/conf/files: patch
sys/dev/acpi/files.acpi: patch
sys/dev/acpi/ug_acpi.c: patch
sys/dev/ic/ug.c: patch
sys/dev/ic/ugreg.h: patch
sys/dev/ic/ugvar.h: patch
sys/dev/isa/files.isa: patch
sys/dev/isa/ug_isa.c: patch
share/man/man4/ug.4: patch
doc/CHANGES: patch
sys/dev/isa/ug.c: delete
sys/dev/isa/ugvar.h: delete

Add an acpi attachement for the ug hardware monitor driver.
 1.120.2.7 12-May-2007  pavel Pull up following revision(s) (requested by jnemeth in ticket #639):
sys/arch/hpcarm/conf/IPAQ: revision 1.50
sys/arch/amd64/conf/GENERIC: revision 1.141
sys/arch/amd64/conf/INSTALL: revision 1.68
sys/arch/i386/conf/SWINGER: revision 1.90
sys/arch/hpcarm/conf/JORNADA820: revision 1.8
PR/36234 - Joerg Niendorf -- xi -> xirc
 1.120.2.6 08-May-2007  pavel Pull up following revision(s) (requested by bouyer in ticket #603):
distrib/sets/lists/base/mi: revision 1.704
distrib/sets/lists/comp/mi: revision 1.1022
distrib/sets/lists/man/mi: revision 1.997
doc/CHANGES: revision 1.839
sbin/Makefile: patch
sbin/bioctl/Makefile: revision 1.1
sbin/bioctl/bioctl.8: revision 1.1
sbin/bioctl/bioctl.c: revision 1.1
sbin/bioctl/strtonum.c: revision 1.1
sbin/bioctl/strtonum.h: revision 1.1
share/man/man4/Makefile: revision 1.426
share/man/man4/bio.4: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.139
sys/arch/i386/conf/GENERIC: revision 1.825
sys/arch/i386/conf/XEN2_DOM0: revision 1.25
sys/conf/files: revision 1.839
sys/conf/majors: patch
sys/dev/Makefile: revision 1.25
sys/dev/bio.c: patch
sys/dev/biovar.h: patch
sys/dev/ic/mfi.c: revision 1.4-1.5
sys/dev/ic/mfivar.h: revision 1.4
sys/sys/envsys.h: revision 1.11
usr.sbin/envstat/envstat.c: revision 1.24
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.

note bio(4), envsys(4) DRIVE, and mfi(4) support for both.

tred->sensor is a u_int.
 1.120.2.5 20-Apr-2007  pavel Pull up following revision(s) (requested by bouyer in ticket #494):
sys/arch/amd64/conf/GENERIC: revision 1.130
sys/arch/amd64/conf/GENERIC: revision 1.131
two revisions forgotten in the initial commit for this ticket.
 1.120.2.4 28-Jan-2007  tron Pull up following revision(s) (requested by tls in ticket #386):
doc/CHANGES: revision 1.783 via patch
sys/arch/i386/conf/INSTALL_TINY: revision 1.109
sys/arch/i386/conf/INSTALL_XEN2_DOMU: revision 1.11
sys/arch/i386/conf/INSTALL_SMALL: revision 1.132
sys/arch/i386/conf/GENERIC: revision 1.806
sys/arch/amd64/conf/GENERIC: revision 1.125
sys/arch/i386/conf/INSTALL: revision 1.303
sys/arch/i386/conf/GENERIC_LAPTOP: revision 1.220
sys/arch/i386/conf/GENERIC_TINY: revision 1.103
sys/arch/i386/conf/INSTALL_LAPTOP: revision 1.114
Remove option COMPAT_386BSD_MBRPART from default kernels. NetBSD has
not used partition ID 0x165 for many, many years, and the presence of
this option in INSTALL kernels can cause overwriting of existing FreeBSD
installations when sysinst writes back the disklabel. Those with very,
very old NetBSD installations may find that they must update their fdisk
partition tables to use partition ID 0x169 for their NetBSD partitions.
This seems like the best of a number of lousy choices for dealing with
this problem. Sysinst should perhaps grow code that asks whether an
existing 0x165 partition should be converted.
~
 1.120.2.3 12-Jan-2007  bouyer Pull up following revision(s) (requested by xtraeme in ticket #341):
distrib/sets/lists/man/mi: revision 1.965
share/man/man4/ug.4: revision 1.1
sys/dev/isa/files.isa: revision 1.145
sys/arch/amd64/conf/GENERIC: revision 1.124
sys/dev/isa/ug.c: revision 1.1
sys/dev/isa/ugvar.h: revision 1.1
share/man/man4/envsys.4: revision 1.21
share/man/man4/Makefile: revision 1.418
Driver for the Abit uGuru Hardware system monitor, contributed by
Mihai Chelaru. Minor changes (simplification and KNF) by me.
Thanks.
Add ug0 at isa? commented out (driver for the Abit uGuru
Hardware system monitor).
ug(4): manual page for the Abit uGuru hardware system monitor
(wiz please review, thanks).
+ ug(4)
 1.120.2.2 21-Dec-2006  tron Pull up following revision(s) (requested by bouyer in ticket #287):
sys/arch/i386/conf/INSTALL: revision 1.299
sys/arch/i386/conf/XEN2_DOM0: revision 1.20
sys/arch/i386/conf/GENERIC: revision 1.803
sys/dev/pci/files.pci: revision 1.275
sys/arch/i386/conf/GENERIC_LAPTOP: revision 1.218
sys/arch/amd64/conf/GENERIC: revision 1.123
sys/dev/pci/if_bnx.c: revision 1.1
share/man/man4/bnx.4: revision 1.1
distrib/sets/lists/man/mi: revision 1.959
sys/arch/amd64/conf/INSTALL: revision 1.62
sys/dev/microcode/bnx/bnxfw.h: revision 1.1
sys/arch/i386/conf/ALL: revision 1.76
sys/dev/pci/if_bnxreg.h: revision 1.1
share/man/man4/Makefile: revision 1.417
sys/arch/i386/conf/INSTALL_LAPTOP: revision 1.112
Add bnx(4), a driver for Broadcom NetXtreme II 10/100/1000 Ethernet device.
Ported from OpenBSD by cube@, with some bus_dma fixes by me.
Tested on i386 and amd64.
 1.120.2.1 21-Dec-2006  tron Pull up following revision(s) (requested by bouyer in ticket #286):
sys/arch/i386/conf/INSTALL: revision 1.298
sys/arch/i386/conf/GENERIC: revision 1.802
sys/dev/pci/files.pci: revision 1.274
sys/arch/amd64/conf/GENERIC: revision 1.122
sys/dev/pci/mfi_pci.c: revision 1.1
distrib/sets/lists/man/mi: revision 1.958
sys/arch/amd64/conf/INSTALL: revision 1.61
sys/arch/i386/conf/ALL: revision 1.75
sys/dev/ic/mfireg.h: revision 1.1
share/man/man4/Makefile: revision 1.416
sys/dev/ic/mfi.c: revision 1.1
sys/arch/i386/conf/XEN2_DOM0: revision 1.19
sys/dev/ic/mfivar.h: revision 1.1
sys/conf/files: revision 1.821
share/man/man4/mfi.4: revision 1.1
Add mfi(4), a driver for LSI Logic & Dell MegaRAID SAS RAID controller.
Ported from OpenBSD, tested on i386 and amd64.
 1.120.2.8.2.4 03-Jun-2008  skrll Sync with netbsd-4.
 1.120.2.8.2.3 06-Jan-2008  wrstuden Catch up to netbsd-4.0 release.
 1.120.2.8.2.2 23-Sep-2007  wrstuden Sync with somewhat-recent netbsd-4.
 1.120.2.8.2.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.126.2.4 17-May-2007  yamt sync with head.
 1.126.2.3 07-May-2007  yamt sync with head.
 1.126.2.2 24-Mar-2007  yamt sync with head.
 1.126.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.134.4.1 11-Jul-2007  mjf Sync with head.
 1.134.2.9 03-Dec-2007  ad Sync with HEAD.
 1.134.2.8 03-Dec-2007  ad Sync with HEAD.
 1.134.2.7 09-Oct-2007  ad Sync with head.
 1.134.2.6 20-Aug-2007  ad Sync with HEAD.
 1.134.2.5 15-Jul-2007  ad Sync with head.
 1.134.2.4 09-Jun-2007  ad Sync with head.
 1.134.2.3 27-May-2007  ad Sync with head.
 1.134.2.2 10-Apr-2007  ad Sync with head.
 1.134.2.1 13-Mar-2007  ad Sync with head.
 1.136.2.1 29-Mar-2007  reinoud Pullup to -current
 1.138.2.4 16-Oct-2007  garbled Sync with HEAD
 1.138.2.3 03-Oct-2007  garbled Sync with HEAD
 1.138.2.2 26-Jun-2007  garbled Sync with HEAD.
 1.138.2.1 22-May-2007  matt Update to HEAD.
 1.153.8.17 09-Dec-2007  jmcneill Sync with HEAD.
 1.153.8.16 03-Dec-2007  joerg Sync with HEAD.
 1.153.8.15 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.153.8.14 21-Nov-2007  joerg Sync with HEAD.
 1.153.8.13 14-Nov-2007  joerg Sync with HEAD.
 1.153.8.12 04-Nov-2007  jmcneill Sync with HEAD.
 1.153.8.11 31-Oct-2007  joerg Sync with HEAD.
 1.153.8.10 29-Oct-2007  joerg Sync with HEAD.
 1.153.8.9 28-Oct-2007  joerg Include apm emulation by default.
 1.153.8.8 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.153.8.7 04-Oct-2007  joerg Sync with HEAD.
 1.153.8.6 02-Oct-2007  joerg Rewrite the ACPI Embedded Controller handler to use pure event driven
operation. On suspend a special flag is set to force explicit polling
as AcpiLeaveSleep accesses the interrupt before GPE handling is
restored. The driver uses a kernel thread to handle GPE queries and
mutex/condvar for synchronisation.

Split the ACPI EC into two drivers, one that is attached directly by
acpi.c for the ECDT driven attachment and the normal acpiec for late
attachment. Share almost all code between this two drivers. If acpiecdt
is attached, acpiec is returning. This was discussed with cube@ and is
the best solution so far.
 1.153.8.5 02-Oct-2007  joerg Sync with HEAD.
 1.153.8.4 06-Sep-2007  jmcneill Enable cardbus, pcmcia, and acpi devices by default.
 1.153.8.3 06-Sep-2007  joerg Enable cgd by default on amd64 and i386.
 1.153.8.2 03-Sep-2007  jmcneill Sync with HEAD.
 1.153.8.1 09-Aug-2007  jmcneill Sync with HEAD.
 1.153.4.3 10-Sep-2007  skrll Sync with HEAD.
 1.153.4.2 03-Sep-2007  skrll Sync with HEAD.
 1.153.4.1 15-Aug-2007  skrll Sync with HEAD.
 1.153.2.1 07-Aug-2007  matt Sync with HEAD.
 1.160.2.3 23-Mar-2008  matt sync with HEAD
 1.160.2.2 09-Jan-2008  matt sync with HEAD
 1.160.2.1 06-Nov-2007  matt sync with HEAD
 1.164.2.1 06-Oct-2007  yamt sync with head.
 1.165.2.4 22-Nov-2007  bouyer Sync with HEAD
 1.165.2.3 18-Nov-2007  bouyer Sync with HEAD
 1.165.2.2 13-Nov-2007  bouyer Sync with HEAD
 1.165.2.1 25-Oct-2007  bouyer Sync with HEAD.
 1.172.2.4 18-Feb-2008  mjf Sync with HEAD.
 1.172.2.3 27-Dec-2007  mjf Sync with HEAD.
 1.172.2.2 08-Dec-2007  mjf Sync with HEAD.
 1.172.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.177.2.2 26-Dec-2007  ad Sync with head.
 1.177.2.1 08-Dec-2007  ad Sync with head.
 1.179.2.1 11-Dec-2007  yamt sync with head.
 1.181.2.3 08-Jan-2008  bouyer Sync with HEAD
 1.181.2.2 02-Jan-2008  bouyer Sync with HEAD
 1.181.2.1 13-Dec-2007  bouyer Sync with HEAD
 1.199.6.6 17-Jan-2009  mjf Sync with HEAD.
 1.199.6.5 05-Oct-2008  mjf Sync with HEAD.
 1.199.6.4 28-Sep-2008  mjf Sync with HEAD.
 1.199.6.3 02-Jul-2008  mjf Sync with HEAD.
 1.199.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.199.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.199.2.1 24-Mar-2008  keiichi sync with head.
 1.204.2.2 04-Jun-2008  yamt sync with head
 1.204.2.1 18-May-2008  yamt sync with head.
 1.205.2.8 09-Oct-2010  yamt sync with head
 1.205.2.7 11-Aug-2010  yamt sync with head.
 1.205.2.6 11-Mar-2010  yamt sync with head
 1.205.2.5 16-Sep-2009  yamt sync with head
 1.205.2.4 19-Aug-2009  yamt sync with head.
 1.205.2.3 20-Jun-2009  yamt sync with head
 1.205.2.2 04-May-2009  yamt sync with head.
 1.205.2.1 16-May-2008  yamt sync with head.
 1.210.2.4 10-Oct-2008  skrll Sync with HEAD.
 1.210.2.3 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.210.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.210.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.216.4.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.216.4.1 19-Oct-2008  haad Sync with HEAD.
 1.216.2.1 10-Jun-2008  simonb Initial commit of Wasabi System's WAPBL (Write Ahead Physical Block
Logging) journaling code. Originally written by Darrin B. Jewell
while at Wasabi and updated to -current by Antti Kantee, Andy Doran,
Greg Oster and Simon Burge.

Still a number of issues - look in doc/BRANCHES for "simonb-wapbl"
for more info.
 1.231.4.11 19-Jun-2013  bouyer Pullup the following revisions via patch, requested by msaitoh in ticket #1850:
sys/dev/pci/if_wm.c 1.201, 1.203-1.204,
1.207-1.212, 1.215,
1.217-1.218, 1.220-1.223,
1.228, 1.232-245
sys/dev/pci/if_wmreg.h 1.40-1.45, 1.47-1.48
sys/dev/pci/if_wmvar.h 1.11-1.13
sys/dev/pci/pcidevs 1.1074, 1.1077, 1.1117
sys/dev/pci/pcidevs.h regen
sys/dev/pci/pcidevs_data.h regen
sys/dev/mii/igphyreg.h 1.6
sys/dev/mii/ihphy.c 1.1-1.2
sys/dev/mii/ihphyreg.h 1.1
sys/dev/mii/inbmphyreg.h 1.3
sys/dev/mii/files.mii 1.47 via patch
sys/dev/mii/miidevs 1.97 and 1.100
sys/dev/mii/miidevs.h regen
sys/dev/mii/miidevs_data.h regen
sys/arch/i386/conf/ALL 1.280
sys/arch/i386/conf/GENERIC 1.1001
sys/arch/i386/conf/INSTALL_FLOPPY 1.11
sys/arch/i386/conf/XEN2_DOM0 patch
sys/arch/amd64/conf/GENERIC 1.293
sys/arch/amd64/conf/XEN3_DOM0 1.61
share/man/man4/wm.4 1.21-1.24

Apply almost all fixes and improvements from netbsd-6 except for
the rev. 1.196's iqdrops' change.

- Add the detach code.
- Add code for WOL, ASF, IPMI and Intel AMT. WOL is disabled by default
- Add Yet another workaround for ICH8.
- 82576 is dual port, so check the FUNCID and increment the MAC address for
the 2nd port.
- Fix the names of 82577L[MC] LAN controllers (for mobile).
- Fix CTRL_EXT_SWDPIN() and CTRL_EXT_SWDPIO() macros. The bit order of the
SW definable pin is not 6543 but 3654!!!
- Rewrite the code to read MAC address from eeprom.
- Add 82580 support.
- 82571 quirk. Only 82571 shares port 0 of EEMNGCTL_CFGDONE.
- The document says that the TDH register must be set after
TCL.EN is set on 82575 and newer devices.
- Fix some register names. No functional change.
- Omit U+00AE "REGISTERED SIGN" in a product name due to its non-ASCII nature.
- Stop wm(4) from needlessly resetting when you add or delete a vlan(4).
- Fix MAC address check on 8257[156] and 80003 case. Some cards have non 0xffff
pointer but those don't use alternative MAC address in reality. So we check
whether the broadcast bit is set or not like Intel's e1000 driver.
Fixes PR kern/44072 reported by Jean-Yves Moulin.
- Add PCH2(and 82579) support. Fixes PR#46487
- Add yet another 82567V support.
- Add ICH10+HANKSVILL support.
- Add support Intel I350 Ethernet.
- Make vlan and all ip/ip6 checksum offload work for the I350.
- Fix compile error with WM_DEBUG.
- Fix a bug that PHY isn't set to low-power mode on PCH and PCH2.
- Add WM_DEBUG_NVM. If WM_DEBUG_NVM is enabled, dump the FLASH ROM data.
- Skip 64bit BAR correctly.
- Fix RAL_TABSIZE for ICH8, 82576, 82580 and I350.
- Use 82580(and I350) specific PHY read/write functions. Fixes PR#47542.
- Style fix. Fix typo in comment. Fix comments. Add comments.
 1.231.4.10 28-Sep-2012  sborrill Pull up the following revisions(s) (requested by liamjfoy in ticket #1797):
lib/libusbhid/usb_hid_usages: revision 1.5 via patch
share/man/man4/Makefile: revision 1.578 via patch
share/man/man4/uts.4: revision 1.1
share/man/man4/wsmouse.4: revision 1.19 via patch
sys/arch/amd64/conf/GENERIC: revision 1.346-1.347 via patch
sys/arch/i386/conf/GENERIC: revision 1.1078 via patch
sys/dev/usb/FILES: revision 1.12 via patch
sys/dev/usb/usbdevices.config: revision 1.12 via patch
sys/dev/usb/files.usb: revision 1.119-1.120 via patch
sys/dev/usb/usbhid.h: revision 1.14 via patch
sys/dev/usb/uts.c: revision 1.1
distrib/sets/lists/man/mi: revision 1.1370 via patch

Add uts(4) driver for USB touchscreens.
 1.231.4.9 25-Jan-2012  riz Pull up following revision(s) (requested by hannken in ticket #1715):
- Be robust against an invalid timer period value.
sys/dev/ic/hpetreg.h Rev. 1.4
sys/dev/ic/hpet.c Rev. 1.8

- Fix wrong definition of LAPIC_LEVEL_ASSERT / _MASK
sys/arch/x86/include/i82489reg.h Rev. 1.11

- Add virtio driver - speed up disk and network access in virtual environments
sys/arch/i386/conf/GENERIC Rev. 1.1055
sys/arch/i386/conf/ALL Rev. 1.325
sys/arch/amd64/conf/GENERIC Rev. 1.338
sys/dev/pci/files.pci Rev. 1.350
sys/dev/pci/if_vioif.c Rev. 0-1.2
sys/dev/pci/ld_virtio.c Rev. 0-1.4
sys/dev/pci/viomb.c Rev. 0-1.1
sys/dev/pci/virtio.c Rev. 0-1.3
sys/dev/pci/virtioreg.h Rev. 0-1.1
sys/dev/pci/virtiovar.h Rev. 0-1.1
distrib/sets/lists/man/mi Rev. 1.1352 and 1.1358
share/man/man4/Makefile Rev. 1.573 and 1.575
share/man/man4/ld.4 Rev. 1.19
share/man/man4/virtio.4 Rev. 0-1.4
share/man/man4/vioif.4 Rev. 0-1.2
share/man/man4/viomb.4 Rev. 0-1.2

Allow NetBSD to run unmodified under Linux/kvm.
 1.231.4.8 21-Nov-2010  riz Pull up following revision(s) (requested by plunky in ticket #1407):
sys/dev/bluetooth/btdev.h: revision 1.9
sys/arch/iyonix/conf/GENERIC: revision 1.60
sys/arch/sparc64/conf/GENERIC: revision 1.129
sys/dev/usb/hid.c: revision 1.30
sys/dev/usb/hid.h: revision 1.13
sys/arch/i386/conf/GENERIC: revision 1.983
usr.sbin/btdevctl/print.c: revision 1.10
sys/arch/evbarm/conf/MPCSA_GENERIC: revision 1.16
sys/arch/alpha/conf/GENERIC: revision 1.337
sys/dev/bluetooth/files.bluetooth: revision 1.14
sys/arch/evbarm/conf/GUMSTIX: revision 1.49
sys/dev/usb/usbdevs: revision 1.550
sys/arch/evbppc/conf/OPENBLOCKS266_OPT: revision 1.14
sys/arch/hpcsh/conf/GENERIC: revision 1.91
sys/dev/bluetooth/btmagic.c: revision 1.1
distrib/sets/lists/man/mi: revision 1.1210
sys/arch/amd64/conf/GENERIC: revision 1.279
sys/arch/i386/conf/ALL: revision 1.258
sys/arch/amd64/conf/XEN3_DOM0: revision 1.54
sys/arch/hpcarm/conf/JORNADA720: revision 1.78
sys/dev/usb/hid.c: revision 1.29
share/man/man4/btmagic.4: revision 1.1
hid_get_data() does not work if the size of data is less than
a byte and crosses a byte boundary, and it always returns a
sign-extended value.
fix this by using the algorithm from libusbhid to read bytes,
and provide a hid_get_udata() function to return unsigned data
values.
while here, const args
update DPRINTF to reflect actual function name
add Apple Magic Mouse product-id
regen for Magic Mouse id
allow for vendor-id and product-id properties, passing them
through to child devices
add Magic Mouse driver and manpage btmagic(4)
additionally query the "PnP Information" service record to discover
any USB Forum vendor-id and product-id values and store them in the
property list if found.
add btmagic(4) where other Bluetooth drivers are listed
 1.231.4.7 28-Oct-2009  bouyer Pull up the following revisions, requested by sborrill in ticket #1114:
share/man/man4/sdhc.4 1.1-1.2
sys/dev/pci/sdhc_pci.c 1.1-1.3
distrib/sets/lists/man/mi patch
share/man/man4/Makefile patch
sys/arch/amd64/conf/GENERIC patch
sys/arch/i386/conf/ALL patch
sys/arch/i386/conf/GENERIC patch
sys/dev/pci/files.pci patch
sys/dev/pci/pcidevs patch
sys/dev/pci/pcidevs.h regen
sys/dev/pci/pcidevs_data.h regen

Add sdhc(4), a driver for SD controllers following the SD Host
Controller Standard Simplified Specification.
 1.231.4.6 08-Oct-2009  sborrill Pull up the following revisions(s) (requested by jmcneill in ticket #1045):
distrib/sets/lists/man/mi: revision 1.1160
share/man/man4/Makefile: revision 1.499
share/man/man4/wb.4: revision 1.1-1.2
share/man/man4/ld.4: revision 1.17
sys/arch/i386/conf/ALL: revision 1.215-1.216 + patch
sys/arch/i386/conf/GENERIC: revision 1.946-1.947 + patch
sys/arch/amd64/conf/GENERIC: revision 1.254-1.256 + patch
sys/conf/files: revision 1.958
sys/dev/acpi/files.acpi: revision 1.59
sys/dev/acpi/wb_acpi.c: revision 1.1
sys/dev/ic/w83l518d.c: revision 1.1
sys/dev/ic/w83l518d_sdmmc.c: revision 1.1
sys/dev/ic/w83l518d_sdmmc.h: revision 1.1
sys/dev/ic/w83l518dreg.h: revision 1.1
sys/dev/ic/w83l518dvar.h.c: revision 1.1

wb(4): Add a driver for Winbond W83L518D SD/MMC readers.
 1.231.4.5 26-Sep-2009  snj Pull up following revision(s) (requested by jmcneill in ticket #946):
distrib/sets/lists/man/mi: revision 1.1155
doc/CHANGES: revision 1.1285
etc/MAKEDEV.tmpl: revision 1.128
share/man/man4/Makefile: revision 1.498 via patch
share/man/man4/hdaudio.4: revision 1.1-1.3
share/man/man8/MAKEDEV.8: revision 1.36
sys/arch/amd64/conf/GENERIC: revision 1.250-1.251
sys/arch/amd64/conf/XEN3_DOM0: revision 1.44-1.45
sys/arch/i386/conf/ALL: revision 1.206-1.207
sys/arch/i386/conf/GENERIC: revision 1.942-1.943
sys/arch/i386/conf/XEN3_DOM0: patch
sys/conf/majors: revision 1.47 via patch
sys/dev/pci/hdaudio/files.hdaudio: revision 1.1-1.2
sys/dev/pci/hdaudio/hdaudio.c: revision 1.1-1.4
sys/dev/pci/hdaudio/hdaudio_afg.c: revisions 1.1-1.14
sys/dev/pci/hdaudio/hdaudio_mixer.h: revisions 1.1-1.3
sys/dev/pci/hdaudio/hdaudio_pci.c: revisions 1.1-1.2
sys/dev/pci/hdaudio/hdaudioio.h: revisions 1.1-1.2
sys/dev/pci/hdaudio/hdaudioreg.h: revisions 1.1-1.3
sys/dev/pci/hdaudio/hdaudiovar.h: revisions 1.1-1.4
sys/dev/pci/files.pci: revisions 1.319 and 1.322 via patch
hdaudio(4) is a standards-compliant driver for High Definition Audio.
It will replace azalia(4) after testing.
To use, comment out azalia in your kernel configuration and uncomment the
hdaudio and hdafg lines so it reads:
hdaudio* at pci? dev ? function ?
hdafg* at hdaudiobus?
You should also:
cd /dev
sh MAKEDEV audio
 1.231.4.4 13-Sep-2009  snj Pull up following revision(s) (requested by jmcneill in ticket #943):
sys/arch/amd64/conf/GENERIC: revision 1.235
add options PMS_ELANTECH_TOUCHPAD
 1.231.4.3 03-May-2009  snj Pull up following revision(s) (requested by cegger in ticket #735):
sys/dev/pci/if_age.c: revisions 1.1-1.28
sys/dev/pci/if_agereg.h: revisions 1.1-1.2
sys/dev/pci/if_ale.c: revisions 1.1-1.3
sys/dev/pci/if_alereg.h: revisions 1.1-1.2
sys/dev/pci/files.pci: revisions 1.310-1.313
sys/dev/mii/atphy.c: revisions 1.1-1.5
sys/dev/mii/files.mii: revision 1.42
share/man/man4/age.4: revisions 1.1-1.3
share/man/man4/ale.4: revisions 1.1-1.2
share/man/man4/atphy.4: revisions 1.1-1.2
share/man/man4/Makefile: revisions 1.486, 1.489
distrib/sets/lists/man/mi: revisions 1.1118, 1.1132
sys/arch/i386/conf/GENERIC: revisions 1.928, 1.933
sys/arch/i386/conf/XEN2_DOM0: revisions 1.57, 1.60
sys/arch/amd64/conf/GENERIC: revisions 1.239, 1.241
sys/arch/amd64/conf/XEN3_DOM0: revisions 1.38, 1.42
Add the age(4) and ale(4) drivers for Attansic L1 and Atheros
AR8121/AR8113/AR8114 devices respectively.
 1.231.4.2 19-Feb-2009  snj branches: 1.231.4.2.4;
Apply patch (requested by pooka in ticket #453):
Add puffs and putter to amd64, i386, macppc, and sparc64 GENERIC kernels.
 1.231.4.1 02-Feb-2009  snj Pull up following revision(s) (requested by ad in ticket #402):
sys/arch/amd64/conf/GENERIC: revision 1.237
sys/arch/i386/conf/GENERIC: revision 1.924
Enable BUFQ_PRIOCSCAN by default.
 1.231.4.2.4.1 21-Apr-2010  matt sync to netbsd-5
 1.231.2.3 28-Apr-2009  skrll Sync with HEAD.
 1.231.2.2 03-Mar-2009  skrll Sync with HEAD.
 1.231.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.235.2.2 30-Dec-2008  christos add COMPAT_50
 1.235.2.1 14-Dec-2008  christos file GENERIC was added on branch christos-time_t on 2008-12-30 19:39:28 +0000
 1.237.2.8 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.237.2.7 02-May-2011  jym Sync with head.
 1.237.2.6 29-Mar-2011  jym More sync fixes. And add the mbr_gpt files.
 1.237.2.5 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.237.2.4 01-Nov-2009  jym Sync with HEAD.
 1.237.2.3 23-Jul-2009  jym Sync with HEAD.
 1.237.2.2 31-May-2009  jym Sync with HEAD.
 1.237.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.264.2.4 06-Nov-2010  uebayasi Sync with HEAD.
 1.264.2.3 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.264.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.264.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.271.2.5 31-May-2011  rmind sync with head
 1.271.2.4 21-Apr-2011  rmind sync with head
 1.271.2.3 05-Mar-2011  rmind sync with head
 1.271.2.2 03-Jul-2010  rmind sync with head
 1.271.2.1 30-May-2010  rmind sync with head
 1.298.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.299.2.4 05-Mar-2011  bouyer Sync with HEAD
 1.299.2.3 17-Feb-2011  bouyer Sync with HEAD
 1.299.2.2 08-Feb-2011  bouyer Add QUOTA2 where QUOTA is enabled (and QUOTA2 commented out where QUOTA
is commented out)
 1.299.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.319.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.338.2.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.338.2.4 23-Jan-2013  yamt sync with head
 1.338.2.3 30-Oct-2012  yamt sync with head
 1.338.2.2 23-May-2012  yamt sync with head.
 1.338.2.1 17-Apr-2012  yamt sync with head
 1.340.2.8 02-Jun-2012  mrg sync to latest -current.
 1.340.2.7 29-Apr-2012  mrg sync to latest -current.
 1.340.2.6 05-Apr-2012  mrg sync to latest -current.
 1.340.2.5 11-Mar-2012  mrg sync to latest -current
 1.340.2.4 06-Mar-2012  mrg sync to -current
 1.340.2.3 06-Mar-2012  mrg sync to -current
 1.340.2.2 04-Mar-2012  mrg sync to latest -current.
 1.340.2.1 18-Feb-2012  mrg merge to -current.
 1.348.2.7 29-Sep-2014  msaitoh Pull up following revision(s) (requested by riastradh in ticket #1129):
sys/arch/amd64/conf/GENERIC: revision 1.385
Enable options VND_COMPRESSION in amd64/GENERIC.
 1.348.2.6 15-Aug-2012  sborrill Pull up the following revisions(s) (requested by martin in ticket #502):
sys/arch/cobalt/conf/GENERIC: patch
sys/arch/i386/conf/GENERIC: patch
sys/arch/i386/conf/XEN3_DOM0: patch
sys/arch/i386/conf/XEN3_DOMU: patch
sys/arch/mvmeppc/conf/GENERIC: patch
sys/arch/shark/conf/GENERIC: patch
sys/arch/sparc64/conf/GENERIC: patch
sys/arch/sparc64/conf/GENERIC.DEBUG: patch
sys/arch/zaurus/conf/GENERIC: patch

Switch off DIAGNOSTIC and/or DEBUG on release kernels.
Enable DIAGNOSTIC in DEBUG kernels to allow for option
being switched off in GENERIC.
 1.348.2.5 15-Jun-2012  sborrill Pull up the following revisions(s) (requested by riz in ticket #343):
sys/dev/usb/files.usb: revision 1.122
sys/dev/usb/if_urtw.c: revision 1.1
sys/dev/usb/if_urtwreg.h: revision 1.1
share/man/man4/Makefile: revision 1.586
share/man/man4/urtw.4: revision 1.1
distrib/sets/lists/man/mi: revision 1.1393
sys/dev/usb/usbdevs: revision 1.617
sys/arch/i386/conf/GENERIC: revision 1.357
sys/arch/amd64/conf/GENERIC: revision 1.1075 via patch

Add urtw(4) driver for Realtek RTL8187/RTL8187B 802.11b/g USB wireless
adapter. From OpenBSD.
 1.348.2.4 14-Jun-2012  sborrill Pull up the following revisions(s) (requested by riz in ticket #326):
distrib/sets/lists/base/mi: 1.989
distrib/sets/lists/man/mi: 1.1385
etc/mtree/NetBSD.dist.base: 1.99
share/man/man4/Makefile: 1.583
share/man/man4/urtwn.4: 1.1
share/man/man4/usb.4: 1.97
sys/arch/amd64/conf/GENERIC: 1.351
sys/arch/i386/conf/GENERIC: 1.1068
sys/dev/usb/files.usb: 1.121
sys/dev/usb/if_urtwn.c: 1.1-1.4
sys/dev/usb/if_urtwn_data.h: 1.1
sys/dev/usb/if_urtwnreg.h: 1.1
sys/dev/usb/if_urtwnvar.h: 1.1
sys/dev/usb/usbdevices.config: 1.13
sys/dev/usb/usbdevs: 1.621 via patch
sys/dev/usb/usbdevs.h: regen
sys/dev/usb/usbdevs_data.h: regen
sys/modules/if_urtwn/Makefile: 1.1
sys/modules/if_urtwn/if_urtwn.ioconf: 1.1

Add support for urtwn(4) wireless. Ported from OpenBSD
 1.348.2.3 12-Jun-2012  riz Remove test changes which accidentally snuck in on the netbsd-6 branch.
Oops.
 1.348.2.2 12-Jun-2012  riz Pull up following revision(s) (requested by abs in ticket #311):
sys/arch/netwinder/conf/GENERIC: revision 1.112
sys/arch/i386/conf/GENERIC: revision 1.1074
sys/arch/atari/conf/MILAN.in: revision 1.26
sys/arch/zaurus/conf/GENERIC: revision 1.54
sys/arch/shark/conf/GENERIC: revision 1.101
sys/arch/hpcmips/conf/MPC303: revision 1.60
sys/arch/i386/conf/XEN3_DOM0: revision 1.67
sys/arch/evbarm/conf/MPCSA_GENERIC: revision 1.29
sys/arch/vax/conf/GENERIC: revision 1.181
sys/arch/sparc/conf/KRUPS: revision 1.59
sys/arch/evbarm/conf/BEAGLEBOARD: revision 1.27
sys/arch/i386/conf/INSTALL_FLOPPY: revision 1.16
sys/arch/prep/conf/GENERIC: revision 1.163
sys/arch/hpcmips/conf/GENERIC: revision 1.216
sys/arch/sparc/conf/TADPOLE3GX: revision 1.56
sys/arch/shark/conf/INSTALL: revision 1.50
sys/arch/next68k/conf/GENERIC: revision 1.127
sys/arch/evbppc/conf/VIRTEX_GSRD2: revision 1.16
sys/arch/evbppc/conf/VIRTEX_DFC: revision 1.17
sys/arch/evbppc/conf/EXPLORA451: revision 1.48
sys/arch/bebox/conf/INSTALL: revision 1.54
sys/arch/next68k/conf/SLAB: revision 1.46
sys/arch/i386/conf/GENERIC_TINY: revision 1.132
sys/arch/bebox/conf/GENERIC: revision 1.131
sys/arch/amd64/conf/XEN3_DOM0: revision 1.84
sys/arch/amd64/conf/GENERIC: revision 1.356
sys/arch/evbarm/conf/MMNET_GENERIC: revision 1.6
share/man/man4/wscons.4: revision 1.31
sys/arch/hpcmips/conf/TX3912: revision 1.79
sys/arch/evbarm/conf/ARMADILLO9: revision 1.35
sys/arch/hpcsh/conf/GENERIC: revision 1.97
sys/arch/i386/conf/ALL: revision 1.339
sys/arch/hpcmips/conf/TX3922: revision 1.93
sys/arch/cats/conf/INSTALL: revision 1.82
sys/arch/sparc64/conf/GENERIC: revision 1.151
sys/arch/i386/conf/INSTALL_TINY: revision 1.135
sys/arch/evbppc/conf/VIRTEX_GSRD1: revision 1.15
sys/arch/evbarm/conf/TS7200: revision 1.49
sys/arch/hpcmips/conf/VR41XX: revision 1.55
sys/arch/hp700/conf/GENERIC: revision 1.115
sys/arch/cats/conf/GENERIC: revision 1.140
Mention wsconscfg(8) needs WSDISPLAY_COMPAT_USL
If a port is going to have wscons for virtual terminals then it really make=
s
sense to enable WSDISPLAY_COMPAT_USL so the system can switch between the
virtual terminals...
Adjust the WSDISPLAY_COMPAT_USL comment to mention wsconscfg, to at least
give a hint that its not just for third party compat. No functional change.
 1.348.2.1 23-Apr-2012  riz Pull up following revision(s) (requested by bouyer in ticket #193):
sys/arch/i386/conf/GENERIC: revision 1.1072
sys/dev/pci/mpii.c: revision 1.1
sys/arch/i386/conf/XEN3_DOM0: revision 1.66
sys/dev/pci/files.pci: revision 1.357
share/man/man4/Makefile: revision 1.584
distrib/sets/lists/man/mi: revision 1.1387
share/man/man4/mpii.4: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.354
sys/arch/amd64/conf/XEN3_DOM0: revision 1.83
sys/arch/i386/conf/ALL: revision 1.337
Add mpii(4), a driver for LSI Logic Fusion-MPT Message Passing Interface II
SAS controllers. Ported from OpenBSD.
 1.363.2.5 03-Dec-2017  jdolecek update from HEAD
 1.363.2.4 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.363.2.3 23-Jun-2013  tls resync from head
 1.363.2.2 25-Feb-2013  tls resync with head
 1.363.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.378.2.2 18-May-2014  rmind sync with head
 1.378.2.1 28-Aug-2013  rmind sync with head
 1.383.2.1 10-Aug-2014  tls Rebase.
 1.392.2.11 25-Jul-2017  snj Apply patch (requested by nonaka in ticket #1413):
iwm(4): Add a driver for Intel Wireless 726x, 316x, 826x and 416x series.
Ported from OpenBSD.
 1.392.2.10 05-Apr-2017  snj Pull up following revision(s) (requested by skrll in ticket #1395):
share/man/man4/axe.4: netbsd-7-nhusb
share/man/man4/axen.4: netbsd-7-nhusb
share/man/man4/cdce.4: netbsd-7-nhusb
share/man/man4/uaudio.4: netbsd-7-nhusb
share/man/man4/ucom.4: netbsd-7-nhusb
share/man/man4/uep.4: netbsd-7-nhusb
share/man/man4/urtw.4: netbsd-7-nhusb
share/man/man4/usb.4: netbsd-7-nhusb
share/man/man4/uyap.4: netbsd-7-nhusb
share/man/man4/xhci.4: netbsd-7-nhusb
share/man/man9/usbdi.9: netbsd-7-nhusb
sys/arch/amd64/conf/ALL: netbsd-7-nhusb
sys/arch/amd64/conf/GENERIC: netbsd-7-nhusb
sys/arch/amiga/dev/slhci_zbus.c: netbsd-7-nhusb
sys/arch/arm/allwinner/awin_otg.c: netbsd-7-nhusb
sys/arch/arm/allwinner/awin_usb.c: netbsd-7-nhusb
sys/arch/arm/amlogic/amlogic_dwctwo.c: netbsd-7-nhusb
sys/arch/arm/at91/at91ohci.c: netbsd-7-nhusb
sys/arch/arm/broadcom/bcm2835_dwctwo.c: netbsd-7-nhusb
sys/arch/arm/broadcom/bcm53xx_usb.c: netbsd-7-nhusb
sys/arch/arm/ep93xx/epohci.c: netbsd-7-nhusb
sys/arch/arm/gemini/obio_ehci.c: netbsd-7-nhusb
sys/arch/arm/imx/files.imx23: netbsd-7-nhusb
sys/arch/arm/imx/imxusb.c: netbsd-7-nhusb
sys/arch/arm/imx/imxusbreg.h: netbsd-7-nhusb
sys/arch/arm/omap/obio_ohci.c: netbsd-7-nhusb
sys/arch/arm/omap/omap3_ehci.c: netbsd-7-nhusb
sys/arch/arm/omap/omapl1x_ohci.c: netbsd-7-nhusb
sys/arch/arm/omap/tiotg.c: netbsd-7-nhusb
sys/arch/arm/s3c2xx0/ohci_s3c24x0.c: netbsd-7-nhusb
sys/arch/arm/samsung/exynos_usb.c: netbsd-7-nhusb
sys/arch/arm/xscale/pxa2x0_ohci.c: netbsd-7-nhusb
sys/arch/arm/zynq/zynq_usb.c: netbsd-7-nhusb
sys/arch/hpcarm/dev/nbp_slhci.c: netbsd-7-nhusb
sys/arch/hpcmips/dev/plumohci.c: netbsd-7-nhusb
sys/arch/i386/conf/ALL: netbsd-7-nhusb
sys/arch/i386/conf/GENERIC: netbsd-7-nhusb
sys/arch/i386/pci/gcscehci.c: netbsd-7-nhusb
sys/arch/luna68k/conf/GENERIC: netbsd-7-nhusb
sys/arch/mips/adm5120/dev/ahci.c: netbsd-7-nhusb
sys/arch/mips/adm5120/dev/ahcivar.h: netbsd-7-nhusb
sys/arch/mips/alchemy/dev/ohci_aubus.c: netbsd-7-nhusb
sys/arch/mips/atheros/dev/ehci_arbus.c: netbsd-7-nhusb
sys/arch/mips/atheros/dev/ohci_arbus.c: netbsd-7-nhusb
sys/arch/mips/conf/files.adm5120: netbsd-7-nhusb
sys/arch/mips/ralink/ralink_ehci.c: netbsd-7-nhusb
sys/arch/mips/ralink/ralink_ohci.c: netbsd-7-nhusb
sys/arch/mips/rmi/rmixl_ehci.c: netbsd-7-nhusb
sys/arch/mips/rmi/rmixl_ohci.c: netbsd-7-nhusb
sys/arch/playstation2/dev/ohci_sbus.c: netbsd-7-nhusb
sys/arch/powerpc/booke/dev/pq3ehci.c: netbsd-7-nhusb
sys/arch/powerpc/ibm4xx/dev/dwctwo_plb.c: netbsd-7-nhusb
sys/arch/x68k/dev/slhci_intio.c: netbsd-7-nhusb
sys/conf/files: netbsd-7-nhusb
sys/dev/cardbus/ehci_cardbus.c: netbsd-7-nhusb
sys/dev/cardbus/ohci_cardbus.c: netbsd-7-nhusb
sys/dev/cardbus/uhci_cardbus.c: netbsd-7-nhusb
sys/dev/ic/sl811hs.c: netbsd-7-nhusb
sys/dev/ic/sl811hsvar.h: netbsd-7-nhusb
sys/dev/isa/slhci_isa.c: netbsd-7-nhusb
sys/dev/marvell/ehci_mv.c: netbsd-7-nhusb
sys/dev/pci/ehci_pci.c: netbsd-7-nhusb
sys/dev/pci/ohci_pci.c: netbsd-7-nhusb
sys/dev/pci/uhci_pci.c: netbsd-7-nhusb
sys/dev/pci/xhci_pci.c: netbsd-7-nhusb
sys/dev/pcmcia/slhci_pcmcia.c: netbsd-7-nhusb
sys/dev/usb/Makefile.usbdevs: netbsd-7-nhusb
sys/dev/usb/TODO: netbsd-7-nhusb
sys/dev/usb/TODO.usbmp: netbsd-7-nhusb
sys/dev/usb/aubtfwl.c: netbsd-7-nhusb
sys/dev/usb/auvitek.c: netbsd-7-nhusb
sys/dev/usb/auvitek_audio.c: netbsd-7-nhusb
sys/dev/usb/auvitek_dtv.c: netbsd-7-nhusb
sys/dev/usb/auvitek_i2c.c: netbsd-7-nhusb
sys/dev/usb/auvitek_video.c: netbsd-7-nhusb
sys/dev/usb/auvitekvar.h: netbsd-7-nhusb
sys/dev/usb/ehci.c: netbsd-7-nhusb
sys/dev/usb/ehcireg.h: netbsd-7-nhusb
sys/dev/usb/ehcivar.h: netbsd-7-nhusb
sys/dev/usb/emdtv.c: netbsd-7-nhusb
sys/dev/usb/emdtv_dtv.c: netbsd-7-nhusb
sys/dev/usb/emdtv_ir.c: netbsd-7-nhusb
sys/dev/usb/emdtvvar.h: netbsd-7-nhusb
sys/dev/usb/ezload.c: netbsd-7-nhusb
sys/dev/usb/ezload.h: netbsd-7-nhusb
sys/dev/usb/files.usb: netbsd-7-nhusb
sys/dev/usb/hid.c: netbsd-7-nhusb
sys/dev/usb/hid.h: netbsd-7-nhusb
sys/dev/usb/if_athn_usb.c: netbsd-7-nhusb
sys/dev/usb/if_athn_usb.h: netbsd-7-nhusb
sys/dev/usb/if_atu.c: netbsd-7-nhusb
sys/dev/usb/if_atureg.h: netbsd-7-nhusb
sys/dev/usb/if_aue.c: netbsd-7-nhusb
sys/dev/usb/if_auereg.h: netbsd-7-nhusb
sys/dev/usb/if_axe.c: netbsd-7-nhusb
sys/dev/usb/if_axen.c: netbsd-7-nhusb
sys/dev/usb/if_axenreg.h: netbsd-7-nhusb
sys/dev/usb/if_axereg.h: netbsd-7-nhusb
sys/dev/usb/if_cdce.c: netbsd-7-nhusb
sys/dev/usb/if_cdcereg.h: netbsd-7-nhusb
sys/dev/usb/if_cue.c: netbsd-7-nhusb
sys/dev/usb/if_cuereg.h: netbsd-7-nhusb
sys/dev/usb/if_kue.c: netbsd-7-nhusb
sys/dev/usb/if_kuereg.h: netbsd-7-nhusb
sys/dev/usb/if_otus.c: netbsd-7-nhusb
sys/dev/usb/if_otusvar.h: netbsd-7-nhusb
sys/dev/usb/if_rum.c: netbsd-7-nhusb
sys/dev/usb/if_rumreg.h: netbsd-7-nhusb
sys/dev/usb/if_rumvar.h: netbsd-7-nhusb
sys/dev/usb/if_run.c: netbsd-7-nhusb
sys/dev/usb/if_runvar.h: netbsd-7-nhusb
sys/dev/usb/if_smsc.c: netbsd-7-nhusb
sys/dev/usb/if_smscreg.h: netbsd-7-nhusb
sys/dev/usb/if_smscvar.h: netbsd-7-nhusb
sys/dev/usb/if_udav.c: netbsd-7-nhusb
sys/dev/usb/if_udavreg.h: netbsd-7-nhusb
sys/dev/usb/if_upgt.c: netbsd-7-nhusb
sys/dev/usb/if_upgtvar.h: netbsd-7-nhusb
sys/dev/usb/if_upl.c: netbsd-7-nhusb
sys/dev/usb/if_ural.c: netbsd-7-nhusb
sys/dev/usb/if_uralreg.h: netbsd-7-nhusb
sys/dev/usb/if_uralvar.h: netbsd-7-nhusb
sys/dev/usb/if_url.c: netbsd-7-nhusb
sys/dev/usb/if_urlreg.h: netbsd-7-nhusb
sys/dev/usb/if_urndis.c: netbsd-7-nhusb
sys/dev/usb/if_urndisreg.h: netbsd-7-nhusb
sys/dev/usb/if_urtw.c: netbsd-7-nhusb
sys/dev/usb/if_urtwn.c: netbsd-7-nhusb
sys/dev/usb/if_urtwn_data.h: netbsd-7-nhusb
sys/dev/usb/if_urtwnreg.h: netbsd-7-nhusb
sys/dev/usb/if_urtwnvar.h: netbsd-7-nhusb
sys/dev/usb/if_urtwreg.h: netbsd-7-nhusb
sys/dev/usb/if_zyd.c: netbsd-7-nhusb
sys/dev/usb/if_zydreg.h: netbsd-7-nhusb
sys/dev/usb/irmce.c: netbsd-7-nhusb
sys/dev/usb/moscom.c: netbsd-7-nhusb
sys/dev/usb/motg.c: netbsd-7-nhusb
sys/dev/usb/motgvar.h: netbsd-7-nhusb
sys/dev/usb/ohci.c: netbsd-7-nhusb
sys/dev/usb/ohcireg.h: netbsd-7-nhusb
sys/dev/usb/ohcivar.h: netbsd-7-nhusb
sys/dev/usb/pseye.c: netbsd-7-nhusb
sys/dev/usb/slurm.c: netbsd-7-nhusb
sys/dev/usb/stuirda.c: netbsd-7-nhusb
sys/dev/usb/u3g.c: netbsd-7-nhusb
sys/dev/usb/uark.c: netbsd-7-nhusb
sys/dev/usb/uatp.c: netbsd-7-nhusb
sys/dev/usb/uaudio.c: netbsd-7-nhusb
sys/dev/usb/uberry.c: netbsd-7-nhusb
sys/dev/usb/ubsa.c: netbsd-7-nhusb
sys/dev/usb/ubsa_common.c: netbsd-7-nhusb
sys/dev/usb/ubsavar.h: netbsd-7-nhusb
sys/dev/usb/ubt.c: netbsd-7-nhusb
sys/dev/usb/uchcom.c: netbsd-7-nhusb
sys/dev/usb/ucom.c: netbsd-7-nhusb
sys/dev/usb/ucomvar.h: netbsd-7-nhusb
sys/dev/usb/ucycom.c: netbsd-7-nhusb
sys/dev/usb/udl.c: netbsd-7-nhusb
sys/dev/usb/udl.h: netbsd-7-nhusb
sys/dev/usb/udsbr.c: netbsd-7-nhusb
sys/dev/usb/udsir.c: netbsd-7-nhusb
sys/dev/usb/uep.c: netbsd-7-nhusb
sys/dev/usb/uftdi.c: netbsd-7-nhusb
sys/dev/usb/uftdireg.h: netbsd-7-nhusb
sys/dev/usb/ugen.c: netbsd-7-nhusb
sys/dev/usb/ugensa.c: netbsd-7-nhusb
sys/dev/usb/uhci.c: netbsd-7-nhusb
sys/dev/usb/uhcireg.h: netbsd-7-nhusb
sys/dev/usb/uhcivar.h: netbsd-7-nhusb
sys/dev/usb/uhid.c: netbsd-7-nhusb
sys/dev/usb/uhidev.c: netbsd-7-nhusb
sys/dev/usb/uhidev.h: netbsd-7-nhusb
sys/dev/usb/uhmodem.c: netbsd-7-nhusb
sys/dev/usb/uhso.c: netbsd-7-nhusb
sys/dev/usb/uhub.c: netbsd-7-nhusb
sys/dev/usb/uipad.c: netbsd-7-nhusb
sys/dev/usb/uipaq.c: netbsd-7-nhusb
sys/dev/usb/uirda.c: netbsd-7-nhusb
sys/dev/usb/uirdavar.h: netbsd-7-nhusb
sys/dev/usb/ukbd.c: netbsd-7-nhusb
sys/dev/usb/ukbdmap.c: netbsd-7-nhusb
sys/dev/usb/ukyopon.c: netbsd-7-nhusb
sys/dev/usb/ukyopon.h: netbsd-7-nhusb
sys/dev/usb/ulpt.c: netbsd-7-nhusb
sys/dev/usb/umass.c: netbsd-7-nhusb
sys/dev/usb/umass_isdata.c: netbsd-7-nhusb
sys/dev/usb/umass_isdata.h: netbsd-7-nhusb
sys/dev/usb/umass_quirks.c: netbsd-7-nhusb
sys/dev/usb/umass_quirks.h: netbsd-7-nhusb
sys/dev/usb/umass_scsipi.c: netbsd-7-nhusb
sys/dev/usb/umass_scsipi.h: netbsd-7-nhusb
sys/dev/usb/umassvar.h: netbsd-7-nhusb
sys/dev/usb/umcs.c: netbsd-7-nhusb
sys/dev/usb/umct.c: netbsd-7-nhusb
sys/dev/usb/umidi.c: netbsd-7-nhusb
sys/dev/usb/umidi_quirks.c: netbsd-7-nhusb
sys/dev/usb/umidi_quirks.h: netbsd-7-nhusb
sys/dev/usb/umodem.c: netbsd-7-nhusb
sys/dev/usb/umodem_common.c: netbsd-7-nhusb
sys/dev/usb/umodemvar.h: netbsd-7-nhusb
sys/dev/usb/ums.c: netbsd-7-nhusb
sys/dev/usb/uplcom.c: netbsd-7-nhusb
sys/dev/usb/urio.c: netbsd-7-nhusb
sys/dev/usb/urio.h: netbsd-7-nhusb
sys/dev/usb/usb.c: netbsd-7-nhusb
sys/dev/usb/usb.h: netbsd-7-nhusb
sys/dev/usb/usb_mem.c: netbsd-7-nhusb
sys/dev/usb/usb_mem.h: netbsd-7-nhusb
sys/dev/usb/usb_quirks.c: netbsd-7-nhusb
sys/dev/usb/usb_quirks.h: netbsd-7-nhusb
sys/dev/usb/usb_subr.c: netbsd-7-nhusb
sys/dev/usb/usbdevices.config: netbsd-7-nhusb
sys/dev/usb/usbdevs: netbsd-7-nhusb
sys/dev/usb/usbdevs.h: netbsd-7-nhusb
sys/dev/usb/usbdevs_data.h: netbsd-7-nhusb
sys/dev/usb/usbdi.c: netbsd-7-nhusb
sys/dev/usb/usbdi.h: netbsd-7-nhusb
sys/dev/usb/usbdi_util.c: netbsd-7-nhusb
sys/dev/usb/usbdi_util.h: netbsd-7-nhusb
sys/dev/usb/usbdivar.h: netbsd-7-nhusb
sys/dev/usb/usbhid.h: netbsd-7-nhusb
sys/dev/usb/usbhist.h: netbsd-7-nhusb
sys/dev/usb/usbroothub.c: netbsd-7-nhusb
sys/dev/usb/usbroothub.h: netbsd-7-nhusb
sys/dev/usb/usbroothub_subr.c: delete
sys/dev/usb/usbroothub_subr.h: delete
sys/dev/usb/uscanner.c: netbsd-7-nhusb
sys/dev/usb/uslsa.c: netbsd-7-nhusb
sys/dev/usb/usscanner.c: netbsd-7-nhusb
sys/dev/usb/ustir.c: netbsd-7-nhusb
sys/dev/usb/uthum.c: netbsd-7-nhusb
sys/dev/usb/utoppy.c: netbsd-7-nhusb
sys/dev/usb/uts.c: netbsd-7-nhusb
sys/dev/usb/uvideo.c: netbsd-7-nhusb
sys/dev/usb/uvisor.c: netbsd-7-nhusb
sys/dev/usb/uvscom.c: netbsd-7-nhusb
sys/dev/usb/uyap.c: netbsd-7-nhusb
sys/dev/usb/uyap_firmware.h: netbsd-7-nhusb
sys/dev/usb/uyurex.c: netbsd-7-nhusb
sys/dev/usb/x1input_rdesc.h: netbsd-7-nhusb
sys/dev/usb/xhci.c: netbsd-7-nhusb
sys/dev/usb/xhcireg.h: netbsd-7-nhusb
sys/dev/usb/xhcivar.h: netbsd-7-nhusb
sys/dev/usb/xinput_rdesc.h: netbsd-7-nhusb
sys/external/bsd/common/conf/files.linux: netbsd-7-nhusb
sys/external/bsd/common/include/linux/err.h: netbsd-7-nhusb
sys/external/bsd/common/include/linux/kernel.h: netbsd-7-nhusb
sys/external/bsd/common/include/linux/workqueue.h: netbsd-7-nhusb
sys/external/bsd/common/linux/linux_work.c: netbsd-7-nhusb
sys/external/bsd/drm2/dist/drm/radeon/atombios_encoders.c: netbsd-7-nhusb
sys/external/bsd/drm2/dist/drm/radeon/radeon_legacy_encoders.c: netbsd-7-nhusb
sys/external/bsd/drm2/drm/files.drmkms: netbsd-7-nhusb
sys/external/bsd/drm2/i915drm/files.i915drmkms: netbsd-7-nhusb
sys/external/bsd/drm2/include/linux/err.h: delete
sys/external/bsd/drm2/include/linux/workqueue.h: delete
sys/external/bsd/drm2/linux/files.drmkms_linux: netbsd-7-nhusb
sys/external/bsd/drm2/linux/linux_work.c: delete
sys/external/bsd/dwc2/dwc2.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dwc2.h: netbsd-7-nhusb
sys/external/bsd/dwc2/dwc2var.h: netbsd-7-nhusb
sys/external/bsd/dwc2/dwctwo2netbsd: netbsd-7-nhusb
sys/external/bsd/dwc2/conf/files.dwc2: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_core.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_core.h: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_coreintr.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hcd.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hcd.h: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hcdddma.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hcdintr.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hcdqueue.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hw.h: netbsd-7-nhusb
sys/modules/drmkms_linux/Makefile: netbsd-7-nhusb
sys/modules/i915drmkms/Makefile: netbsd-7-nhusb
sys/rump/dev/lib/libugenhc/ugenhc.c: netbsd-7-nhusb
sys/rump/dev/lib/libusb/Makefile: netbsd-7-nhusb
sys/rump/dev/lib/libusb/USB.ioconf: netbsd-7-nhusb
sys/rump/dev/lib/libusb/usb_at_ugenhc.c: delete
sys/rump/dev/lib/libusb/opt/opt_usb.h: delete
sys/rump/dev/lib/libusb/opt/opt_usbverbose.h: delete
sys/sys/mbuf.h: netbsd-7-nhusb
usr.sbin/usbdevs/usbdevs.8: netbsd-7-nhusb
usr.sbin/usbdevs/usbdevs.c: netbsd-7-nhusb
Merge netbsd-7-nhusb:
- API / infrastructure changes to support memory management changes.
- Memory management improvements and bug fixes.
- HCDs should now be MP safe
- conversion to KERNHIST based debug
- FS/LS isoc support on ehci(4).
- conversion to kmem(9)
- Some USB 3 support - mostly from Takahiro HAYASHI (t-hash).
- interrupt transfers now get proper DMA operations
- general bug fixes
- kern/48308
- uhub status notification improvements
- umass(4) probe fix (applied to HEAD already)
- ohci(4) short transfer fix
- Change the SOFTINT level from NET to SERIAL for the USB softint handler.
This gives the callback a chance of running when another softint handler
at SOFTINT_NET has blocked holding a lock, e.g. softnet_lock and most of
the network stack.
- kern/49065 - ifconfig tun0 ... sequence locks up system / lockup:
softnet_lock held across usb xfr
- kern/50491 - unkillable wait in usbd_transfer while using usmsc0
on raspberry pi 2
- kern/51395 - USB Ethernet makes xhci hang
- Various improvements to slhci(4)
- Various improvements to dwc2(4)
 1.392.2.9 23-Dec-2016  snj Pull up following revision(s) (requested by bsiegert in ticket #1338):
sys/arch/amd64/conf/GENERIC: revision 1.418
sys/dev/pci/files.pci: revision 1.379
sys/dev/pci/vioscsi.c: revisions 1.1-1.8
sys/dev/pci/vioscsireg.h: revision 1.1
sys/dev/pci/virtioreg.h: revisions 1.5, 1.6
add the common flag bits
--
Add vioscsi, compile tested only (toxic)
--
this is working now, remove debugging.
--
add vioscsi
--
kill some more debugging.
--
Fake mode sense data for illegal targets. qemu reports 256 targets...
--
fix the status return.
--
Use SCSIPI_CHAN_NOSETTLE.
--
vioscsi_req_get()/virtio_enqueue_prep() failing is actually perfectly
normal - observed failures included 10, 27, 61 in-flight commands,
so probably depends on particular command mix; return with
XS_RESOURCE_SHORTAGE rather then panic
do vioscsi_req_put() when initial bus_dmamap_load() fails, as suggested
by the XXX; the vq_done hook is called by virtio, but in that case we
never get to commit the request to it
--
react on ADAPTER_REQ_SET_XFER_MODE so that we set tagged queuing
pass tag type and set id
 1.392.2.8 09-Dec-2016  snj Pull up following revision(s) (requested by msaitoh in ticket #1297):
sys/arch/amd64/conf/ALL: revision 1.37
sys/arch/amd64/conf/GENERIC: revision 1.436
sys/arch/amd64/conf/XEN3_DOM0: revision 1.120
sys/arch/i386/conf/ALL: revision 1.400
sys/arch/i386/conf/GENERIC: revision 1.1138
sys/arch/i386/conf/XEN3_DOM0: revision 1.99
Add sdtemp(4)
--
Add ichsmb(4), spdmem(4) and sdtemp(4).
 1.392.2.7 15-May-2015  snj branches: 1.392.2.7.4;
Pull up following revision(s) (requested by jnemeth in ticket #762):
share/man/man4/options.4: revision 1.442
sys/arch/amd64/conf/ALL: revision 1.18
sys/arch/amd64/conf/GENERIC: revision 1.396
sys/arch/dreamcast/conf/GENERIC: revision 1.119
sys/arch/epoc32/conf/GENERIC: revision 1.6
sys/arch/evbarm/conf/BCM5301X: revision 1.24
sys/arch/evbarm/conf/BCM56340: revision 1.9
sys/arch/evbarm/conf/IMX23_OLINUXINO: revision 1.9
sys/arch/evbarm/conf/std.beagle: revision 1.13
sys/arch/evbarm/conf/std.kobo: revision 1.2
sys/arch/evbarm/conf/std.netwalker: revision 1.10
sys/arch/evbppc/conf/P2020DS: revision 1.25
sys/arch/evbppc/conf/RB800: revision 1.30
sys/arch/evbppc/conf/TWRP1025: revision 1.18
sys/arch/hp300/conf/GENERIC: revision 1.187
sys/arch/hpcsh/conf/GENERIC: revision 1.104
sys/arch/i386/conf/GENERIC: revision 1.1111
sys/arch/i386/conf/MONOLITHIC: revision 1.17
sys/arch/landisk/conf/GENERIC: revision 1.43
sys/arch/luna68k/conf/GENERIC: revision 1.117
sys/arch/macppc/conf/GENERIC: revision 1.316
sys/arch/macppc/conf/GENERIC_601: revision 1.5
sys/arch/mmeye/conf/MMEYE_WLF: revision 1.16
sys/arch/news68k/conf/GENERIC: revision 1.123
sys/arch/sandpoint/conf/GENERIC: revision 1.85
sys/arch/shark/conf/GENERIC: revision 1.119
sys/arch/sparc/conf/GENERIC: revision 1.246
sys/arch/sparc64/conf/GENERIC: revision 1.174
sys/arch/sun3/conf/GENERIC3X: revision 1.125
sys/arch/sun3/conf/GENERIC: revision 1.169
sys/arch/x68k/conf/GENERIC: revision 1.177
sys/arch/zaurus/conf/GENERIC: revision 1.62
sys/conf/files: revision 1.1099
sys/kern/kern_module.c: revisions 1.98, 1.99
Create an "options MODULAR_DEFAULT_AUTOLOAD" config option and add
it to all kernel configs that contain "options MODULAR". This
option turns on module autoloading by default (which is the current
default). This allows people who don't want module autoloading on
by default to disable it by simply removing/commentting this line.
--
fix typo. (s/MODULE_DEFAULT_AUTOLOAD/MODULAR_DEFAULT_AUTOLOAD/)
 1.392.2.6 18-Mar-2015  snj Apply patch (requested by christos in ticket #542):
- Enable intel and radeon DRM/KMS drivers in GENERIC
- Disable all of the old DRM drivers in GENERIC
- Remove the separate DRMKMS kernel
 1.392.2.5 20-Jan-2015  martin Change the following, requested by snj in ticket #438:

sys/arch/i386/conf/GENERIC patch
sys/arch/amd64/conf/GENERIC patch

Remove the i915drm driver since the version we use doesn't support UMS
anymore, so X will fail to start. Without it, at least the vesa driver
will work.
 1.392.2.4 18-Nov-2014  snj Pull up following revision(s) (requested by manu in ticket #251):
sys/arch/acorn26/conf/GENERIC: revision 1.81
sys/arch/acorn32/conf/GENERIC: revision 1.116
sys/arch/alpha/conf/GENERIC: revision 1.362
sys/arch/amd64/conf/ALL: revision 1.23
sys/arch/amd64/conf/GENERIC: revision 1.404
sys/arch/amd64/conf/XEN3_DOM0: revision 1.112
sys/arch/amd64/conf/XEN3_DOMU: revision 1.60
sys/arch/amiga/conf/GENERIC.in: revision 1.129
sys/arch/amiga/conf/GENERIC: revision 1.311
sys/arch/amigappc/conf/GENERIC: revision 1.24
sys/arch/arc/conf/GENERIC: revision 1.184
sys/arch/bebox/conf/GENERIC: revision 1.145
sys/arch/cats/conf/GENERIC: revision 1.155
sys/arch/cesfic/conf/GENERIC: revision 1.65
sys/arch/cobalt/conf/GENERIC: revision 1.147
sys/arch/dreamcast/conf/GENERIC: revision 1.121
sys/arch/emips/conf/GENERIC: revision 1.15
sys/arch/epoc32/conf/GENERIC: revision 1.8
sys/arch/ews4800mips/conf/GENERIC: revision 1.51
sys/arch/hp300/conf/GENERIC: revision 1.190
sys/arch/hpcmips/conf/GENERIC: revision 1.229
sys/arch/hpcsh/conf/GENERIC: revision 1.106
sys/arch/hppa/conf/GENERIC: revision 1.6
sys/arch/i386/conf/ALL: revision 1.389
sys/arch/i386/conf/GENERIC: revision 1.1118
sys/arch/i386/conf/XEN3_DOM0: revision 1.93
sys/arch/i386/conf/XEN3_DOMU: revision 1.65
sys/arch/ibmnws/conf/GENERIC: revision 1.46
sys/arch/iyonix/conf/GENERIC: revision 1.88
sys/arch/landisk/conf/GENERIC: revision 1.45
sys/arch/luna68k/conf/GENERIC: revision 1.119
sys/arch/mac68k/conf/GENERIC: revision 1.220
sys/arch/macppc/conf/GENERIC: revision 1.320
sys/arch/macppc/conf/MAMBO: revision 1.24
sys/arch/macppc/conf/POWERMAC_G5: revision 1.25
sys/arch/mipsco/conf/GENERIC: revision 1.88
sys/arch/mmeye/conf/GENERIC: revision 1.120
sys/arch/mvme68k/conf/GENERIC: revision 1.94
sys/arch/mvmeppc/conf/GENERIC: revision 1.24
sys/arch/netwinder/conf/GENERIC: revision 1.126
sys/arch/news68k/conf/GENERIC: revision 1.125
sys/arch/newsmips/conf/GENERIC: revision 1.129
sys/arch/next68k/conf/GENERIC: revision 1.139
sys/arch/ofppc/conf/GENERIC: revision 1.157
sys/arch/pmax/conf/GENERIC64: revision 1.21
sys/arch/pmax/conf/GENERIC: revision 1.185
sys/arch/prep/conf/GENERIC: revision 1.174
sys/arch/rs6000/conf/GENERIC: revision 1.33
sys/arch/sandpoint/conf/GENERIC: revision 1.88
sys/arch/sbmips/conf/GENERIC: revision 1.101
sys/arch/sgimips/conf/GENERIC32_IP12: revision 1.28
sys/arch/sgimips/conf/GENERIC32_IP2x: revision 1.104
sys/arch/sgimips/conf/GENERIC32_IP3x: revision 1.106
sys/arch/shark/conf/GENERIC: revision 1.121
sys/arch/sparc/conf/GENERIC: revision 1.248
sys/arch/sparc/conf/TADPOLE3GX: revision 1.65
sys/arch/sparc64/conf/GENERIC: revision 1.177
sys/arch/sparc64/conf/NONPLUS64: revision 1.44
sys/arch/sun2/conf/GENERIC: revision 1.94
sys/arch/sun3/conf/GENERIC: revision 1.171
sys/arch/vax/conf/GENERIC: revision 1.193
sys/arch/vax/conf/VAX780: revision 1.19
sys/arch/x68k/conf/GENERIC: revision 1.179
sys/arch/zaurus/conf/GENERIC: revision 1.65
sys/ufs/files.ufs: revision 1.38
Remove unused extended attributes kernel options

As Masao Uebayashi pointed to me, UFS_EXTATTR_AUTOSTART, LFS_EXTATTR_AUTOSTART
and UFS_EXTATTR_AUTOCREATE are not used anywhere in the code. Remove them
as they have been obsolete for a long time:
UFS_EXTATTR_AUTOSTART was replaced by mount -o extattr
LFS_EXTATTR_AUTOSTART was created to match obsolete UFS_EXTATTR_AUTOSTART
UFS_EXTATTR_AUTOCREATE was replaced by sysctl vfs.ffs.extattr_autocreate
 1.392.2.3 14-Nov-2014  martin Pull up following revision(s) (requested by manu in ticket #232):
sys/arch/next68k/conf/GENERIC: revision 1.138
sys/arch/cobalt/conf/GENERIC: revision 1.146
sys/arch/mvme68k/conf/GENERIC: revision 1.93
sys/arch/vax/conf/VAX780: revision 1.18
sys/arch/newsmips/conf/GENERIC: revision 1.128
sys/arch/luna68k/conf/GENERIC: revision 1.118
sys/arch/sbmips/conf/GENERIC: revision 1.100
sys/arch/pmax/conf/GENERIC: revision 1.184
sys/arch/alpha/conf/GENERIC: revision 1.361
sys/arch/sparc64/conf/GENERIC: revision 1.176
sys/arch/sun3/conf/GENERIC: revision 1.170
sys/arch/shark/conf/GENERIC: revision 1.120
sys/arch/landisk/conf/GENERIC: revision 1.44
sys/arch/bebox/conf/GENERIC: revision 1.144
sys/arch/sparc64/conf/NONPLUS64: revision 1.43
sys/arch/sandpoint/conf/GENERIC: revision 1.87
sys/arch/emips/conf/GENERIC: revision 1.14
sys/arch/amd64/conf/XEN3_DOM0: revision 1.111
sys/arch/dreamcast/conf/GENERIC: revision 1.120
sys/arch/cesfic/conf/GENERIC: revision 1.64
sys/arch/mmeye/conf/GENERIC: revision 1.119
sys/arch/epoc32/conf/GENERIC: revision 1.7
sys/arch/x68k/conf/GENERIC: revision 1.178
sys/arch/iyonix/conf/GENERIC: revision 1.87
sys/arch/sun2/conf/GENERIC: revision 1.93
sys/arch/ews4800mips/conf/GENERIC: revision 1.50
sys/arch/amd64/conf/XEN3_DOMU: revision 1.59
sys/arch/acorn26/conf/GENERIC: revision 1.80
sys/arch/acorn32/conf/GENERIC: revision 1.115
sys/arch/macppc/conf/POWERMAC_G5: revision 1.24
sys/arch/i386/conf/GENERIC: revision 1.1117
sys/arch/arc/conf/GENERIC: revision 1.183
sys/arch/cats/conf/GENERIC: revision 1.154
sys/arch/amiga/conf/GENERIC.in: revision 1.128
sys/arch/zaurus/conf/GENERIC: revision 1.64
sys/arch/netwinder/conf/GENERIC: revision 1.125
sys/arch/hppa/conf/GENERIC: revision 1.5
sys/arch/mvmeppc/conf/GENERIC: revision 1.23
sys/arch/macppc/conf/GENERIC: revision 1.319
sys/arch/amiga/conf/GENERIC: revision 1.310
sys/arch/pmax/conf/GENERIC64: revision 1.20
sys/arch/macppc/conf/MAMBO: revision 1.23
sys/arch/sgimips/conf/GENERIC32_IP12: revision 1.27
sys/arch/amigappc/conf/GENERIC: revision 1.23
sys/arch/amd64/conf/GENERIC: revision 1.403
sys/arch/ofppc/conf/GENERIC: revision 1.156
sys/arch/mac68k/conf/GENERIC: revision 1.219
sys/arch/i386/conf/XEN3_DOMU: revision 1.64
sys/arch/mipsco/conf/GENERIC: revision 1.87
sys/arch/hp300/conf/GENERIC: revision 1.189
sys/arch/vax/conf/GENERIC: revision 1.192
sys/arch/news68k/conf/GENERIC: revision 1.124
sys/arch/ibmnws/conf/GENERIC: revision 1.45
sys/arch/hpcsh/conf/GENERIC: revision 1.105
sys/arch/sparc/conf/TADPOLE3GX: revision 1.64
sys/arch/i386/conf/XEN3_DOM0: revision 1.92
sys/arch/sparc/conf/GENERIC: revision 1.247
sys/arch/sgimips/conf/GENERIC32_IP3x: revision 1.105
sys/arch/prep/conf/GENERIC: revision 1.173
sys/arch/sgimips/conf/GENERIC32_IP2x: revision 1.103
sys/arch/rs6000/conf/GENERIC: revision 1.32
sys/arch/hpcmips/conf/GENERIC: revision 1.228
Support for UFS1 extended attributes in GENERIC and GENERIC-like kernels
This change just brings UFS1 extended attribute *support* in the kernel,
extended attributes are not enabled unless three conditions are met:
1) filesystem is UFS1 (newfs -O1)
2) .attribute/system and .attribute/user directories are created at fs root
3) filesystem is mounted with -o extattr
Some GENERIC kernels are obviously memory constrained, the extended
attributes options were not enabled for them, but just added commented out.
(kernel were considered memory constrained if QUOTA option was disabled)
 1.392.2.2 02-Nov-2014  martin Pull up following revision(s) (requested by tls in ticket #174):
doc/CHANGES: revision 1.2005
sys/dev/pci/viornd.c: revision 1.1
sys/dev/pci/files.pci: revision 1.372
sys/arch/amd64/conf/GENERIC: revision 1.401
share/man/man4/viornd.4: revision 1.1
Add viornd(4), a driver for the VirtIO entropy source available on
QEMU, KVM, and Google Compute Engine. From OpenBSD.
 1.392.2.1 10-Oct-2014  snj Apply patch (requested by bouyer/martin in ticket #116):
Disable DIAGNOSTIC and/or DEBUG.
 1.392.2.7.4.2 18-Jan-2017  skrll Sync with netbsd-5
 1.392.2.7.4.1 06-Sep-2016  skrll First pass at netbsd-7 updated with USB code from HEAD
 1.404.2.13 28-Aug-2017  skrll Sync with HEAD
 1.404.2.12 05-Feb-2017  skrll Sync with HEAD
 1.404.2.11 05-Dec-2016  skrll Sync with HEAD
 1.404.2.10 05-Oct-2016  skrll Sync with HEAD
 1.404.2.9 09-Jul-2016  skrll Sync with HEAD
 1.404.2.8 29-May-2016  skrll Sync with HEAD
 1.404.2.7 22-Apr-2016  skrll Sync with HEAD
 1.404.2.6 19-Mar-2016  skrll Sync with HEAD
 1.404.2.5 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.404.2.4 22-Sep-2015  skrll Sync with HEAD
 1.404.2.3 21-Sep-2015  skrll Enable xhci(4)
 1.404.2.2 06-Jun-2015  skrll Sync with HEAD
 1.404.2.1 06-Apr-2015  skrll Sync with HEAD
 1.435.2.4 26-Apr-2017  pgoyette Sync with HEAD
 1.435.2.3 20-Mar-2017  pgoyette Sync with HEAD
 1.435.2.2 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.435.2.1 06-Aug-2016  pgoyette Sync with HEAD
 1.450.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.459.2.15 12-Jun-2019  martin Pull up following revision(s) (requested by nonaka in ticket #1280):

sys/arch/x86/x86/consinit.c: revision 1.29
sys/dev/hyperv/vmbusvar.h: revision 1.2
sys/dev/hyperv/genfb_vmbusvar.h: revision 1.1
sys/arch/x86/x86/x86_autoconf.c: revision 1.78
sys/arch/x86/x86/identcpu.c: revision 1.91
sys/arch/x86/x86/hyperv.c: revision 1.2
sys/arch/x86/x86/hyperv.c: revision 1.3
sys/arch/x86/x86/hyperv.c: revision 1.4
sys/arch/i386/conf/GENERIC: revision 1.1207
sys/dev/wscons/wsconsio.h: revision 1.123
sys/arch/x86/x86/hypervvar.h: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.528
sys/dev/hyperv/files.hyperv: revision 1.2
sys/arch/x86/include/autoconf.h: revision 1.6
sys/dev/hyperv/hyperv_common.c: revision 1.2
sys/arch/xen/x86/autoconf.c: revision 1.23
sys/arch/x86/pci/pci_machdep.c: revision 1.86
sys/dev/hyperv/hvkbd.c: revision 1.1
sys/dev/hyperv/hypervvar.h: revision 1.2
sys/dev/acpi/vmbus_acpi.c: revision 1.2
sys/dev/hyperv/vmbus.c: revision 1.3
sys/dev/hyperv/hvkbdvar.h: revision 1.1
sys/dev/hyperv/genfb_vmbus.c: revision 1.1

Added drivers for Hyper-V Synthetic Keyboard and Video device.

Avoid undefined reference to `hyperv_guid_video' without vmbus(4).

Avoid undefined reference to `hyperv_is_gen1' without hyperv(4).

Use efi_probe().
 1.459.2.14 09-Mar-2019  martin Pull up following revision(s) via patch (requested by nonaka in ticket #1210):

sys/dev/hyperv/vmbusvar.h: revision 1.1
sys/dev/hyperv/hvs.c: revision 1.1
sys/dev/hyperv/if_hvn.c: revision 1.1
sys/dev/hyperv/vmbusic.c: revision 1.1
sys/arch/x86/x86/lapic.c: revision 1.69
sys/arch/x86/isa/clock.c: revision 1.34
sys/arch/x86/include/intrdefs.h: revision 1.22
sys/arch/i386/conf/GENERIC: revision 1.1201
sys/arch/x86/x86/hyperv.c: revision 1.1
sys/arch/x86/include/cpu.h: revision 1.105
sys/arch/x86/x86/x86_machdep.c: revision 1.124
sys/arch/i386/conf/GENERIC: revision 1.1203
sys/arch/amd64/amd64/genassym.cf: revision 1.74
sys/arch/i386/conf/GENERIC: revision 1.1204
sys/arch/amd64/conf/GENERIC: revision 1.520
sys/arch/x86/x86/hypervreg.h: revision 1.1
sys/arch/amd64/amd64/vector.S: revision 1.69
sys/dev/hyperv/hvshutdown.c: revision 1.1
sys/dev/hyperv/hvshutdown.c: revision 1.2
sys/dev/usb/if_urndisreg.h: file removal
sys/arch/x86/x86/cpu.c: revision 1.167
sys/arch/x86/conf/files.x86: revision 1.107
sys/dev/usb/if_urndis.c: revision 1.20
sys/dev/hyperv/vmbusicreg.h: revision 1.1
sys/dev/hyperv/hvheartbeat.c: revision 1.1
sys/dev/hyperv/vmbusicreg.h: revision 1.2
sys/dev/hyperv/hvheartbeat.c: revision 1.2
sys/dev/hyperv/files.hyperv: revision 1.1
sys/dev/ic/rndisreg.h: revision 1.1
sys/arch/i386/i386/genassym.cf: revision 1.111
sys/dev/ic/rndisreg.h: revision 1.2
sys/dev/hyperv/hyperv_common.c: revision 1.1
sys/dev/hyperv/hvtimesync.c: revision 1.1
sys/dev/hyperv/hypervreg.h: revision 1.1
sys/dev/hyperv/hvtimesync.c: revision 1.2
sys/dev/hyperv/vmbusicvar.h: revision 1.1
sys/dev/hyperv/if_hvnreg.h: revision 1.1
sys/arch/x86/x86/lapic.c: revision 1.70
sys/arch/amd64/amd64/vector.S: revision 1.70
sys/dev/ic/ndisreg.h: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.516
sys/dev/hyperv/hypervvar.h: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.518
sys/arch/amd64/conf/GENERIC: revision 1.519
sys/arch/i386/conf/files.i386: revision 1.400
sys/dev/acpi/vmbus_acpi.c: revision 1.1
sys/dev/hyperv/vmbus.c: revision 1.1
sys/dev/hyperv/vmbus.c: revision 1.2
sys/arch/x86/x86/intr.c: revision 1.144
sys/arch/i386/i386/vector.S: revision 1.83
sys/arch/amd64/conf/files.amd64: revision 1.112

separate RNDIS definitions from urndis(4) for use with Hyper-V NetVSC.

-

Added Microsoft Hyper-V support. It ported from OpenBSD and FreeBSD.
graphical console is not work on Gen.2 VM yet. To use the serial console,
enter "consdev com,0x3f8,115200" on efiboot.

-

Add __diagused.

-

PR/53984: Partial revert of modify lapic_calibrate_timer() in lapic.c r1.69.

-

Update Hyper-V related drivers description.

-

Remove unused definition.

-

Rename the MODULE_*_HOOK() macros to MODULE_HOOK_*() as briefly
discussed on irc.
NFCI intended.

-

commented out hvkvp entry.

-

fix typo. pointed out by pgoyette@n.o.

-

Use IDTVEC instead of NENTRY for handle_hyperv_hypercall.

-

Rename the MODULE_*_HOOK() macros to MODULE_HOOK_*() as briefly
discussed on irc.
 1.459.2.13 07-Dec-2018  martin Pull up following revision(s) (requested by bouyer in ticket #1129):

sys/arch/amd64/conf/XEN3_DOM0: revision 1.159
sys/arch/amd64/conf/GENERIC: revision 1.508
sys/arch/i386/conf/ALL: revision 1.458
sys/dev/ic/mfi.c: revision 1.60
sys/dev/pci/mpiireg.h: revision 1.1
distrib/sets/lists/man/mi: revision 1.1628
sys/dev/pci/mfii.c: revision 1.1,1.2 (adapted)
sys/arch/i386/conf/GENERIC: revision 1.1194
sys/dev/pci/mpii.c: revision 1.13
sys/dev/ic/mfireg.h: revision 1.9
share/man/man4/mfii.4: revision 1.1
share/man/man4/Makefile: revision 1.673 (patch)
sys/dev/pci/files.pci: revision 1.410
share/man/man4/mfii.4: revision 1.2
sys/arch/amd64/conf/ALL: revision 1.108
sys/arch/i386/conf/XEN3PAE_DOM0: revision 1.8 (patch, in XEN3_DOM0)

Add some definitions from OpenBSD, needed by the upcoming mfii driver.
No functionnal change.

-

Move registers definitions to a separate file, needed for the upcomning mpii
driver. No functionnal change.

-

Add mpii(4), a driver for LSI Megaraid Fusion controllers.
Ported from OpenBSD. This driver is MP-safe.

Note that the earlier fusion controllers (Megaraid 2208, codenamed Thunderbold)
are also supported by mfi(4). mpii will take precedence if both drivers
are enabled.

Tested on a
mfii0 at pci6 dev 0 function 0: "PERC H740P Adapter ", firmware 50.3.0-1512, 819
2MB cache
mfii0: interrupting at ioapic2 pin 2
scsibus0 at mfii0: 64 targets, 8 luns per target
scsibus0: waiting 2 seconds for devices to settle...
sd0 at scsibus0 target 0 lun 0: <DELL, PERC H740P Adp, 5.03> disk fixed
sd0: fabricating a geometry
sd0: 99 GB, 102399 cyl, 64 head, 32 sec, 512 bytes/sect x 209714688 sectors
sd0: tagged queueing
sd1 at scsibus0 target 1 lun 0: <DELL, PERC H740P Adp, 5.03> disk fixed
sd1: fabricating a geometry
sd1: 22254 GB, 22788608 cyl, 64 head, 32 sec, 512 bytes/sect x 46671069696 sectors
sd1: fabricating a geometry

It supports bioctl(8) ioctls, as well as sensors for the BBU and logical
drives.

Sponsored by LIP6.

-

Add my name in copyright list

-

add a man page for the new mpii, mostly from OpenBSD.

-

Sort SEE ALSO. Fix date. Whitespace fixes.
 1.459.2.12 31-Oct-2018  martin Add bwfm config glue, requested by maya in ticket #1072.
 1.459.2.11 07-Sep-2018  martin Pull up following revision(s) (requested by mrg in ticket #1011):

sys/dev/usb/usbdevices.config: revision 1.32 (patch)
sys/arch/amd64/conf/GENERIC: revision 1.502 (patch)
sys/arch/i386/conf/GENERIC: revision 1.1188 (patch)

- add commented entries that exist in amd64 GENERIC: oboe, mos, umb.
(XXX: mos might be deleteable now?).
- comment uscanner(4) -- usb scanners use ugen(4) interface.
- minor sort.

-

use dev/usb/usbdevices.config, gaining these missing drivers:
slurm(4), uthum(4), umcs(4), uark(4), upgt(4), and usmsc(4).

-

use dev/usb/usbdevices.config instead of a local list.
adds slurm(4), umcs(4), uark(4), and usmsc(4).
 1.459.2.10 09-Jun-2018  martin Pullup the following revisions, requested by maxv in ticket #865:

sys/arch/amd64/amd64/machdep.c 1.303 (patch)
sys/arch/amd64/conf/GENERIC 1.492 (patch)
sys/arch/amd64/conf/files.amd64 1.103 (patch)
sys/arch/i386/i386/machdep.c 1.806 (patch)
sys/arch/i386/conf/GENERIC 1.1179 (patch)
sys/arch/i386/conf/files.i386 1.393 (patch)
sys/arch/x86/include/cpu.h 1.91 (patch)
sys/arch/x86/include/specialreg.h upto 1.126 (patch)
sys/arch/x86/x86/x86_machdep.c upto 1.115 (patch, adapted)
sys/arch/x86/x86/spectre.c upto 1.19 (patch, adapted,
no IBRS,
SpectreV2 mitigations not
enabled by default)

Backport the hardware SpectreV2 and SpectreV4 mitigations.
 1.459.2.9 18-Apr-2018  martin Requested by skrll in ticket #60:
sys/arch/amd64/conf/GENERIC
sys/arch/amd64/conf/XEN3_DOM0
sys/arch/amd64/conf/XEN3_DOMU
sys/arch/cobalt/conf/GENERIC
sys/arch/evbarm/conf/BEAGLEBONE
sys/arch/evbarm/conf/BEAGLEBOARD
sys/arch/evbarm/conf/BEAGLEBOARDXM
sys/arch/evbarm/conf/GENERIC.common
sys/arch/i386/conf/GENERIC
sys/arch/i386/conf/XEN3_DOM0
sys/arch/i386/conf/XEN3_DOMU
sys/arch/mvmeppc/conf/GENERIC
sys/arch/shark/conf/GENERIC
sys/arch/sparc64/conf/GENERIC
sys/arch/zaurus/conf/GENERIC

Remove option DIAGNOSTIC.
 1.459.2.8 11-Apr-2018  martin Pull up following revision(s) (requested by mrg in ticket #731):
sys/arch/i386/conf/files.i386: revision 1.392
sys/arch/i386/conf/GENERIC: revision 1.1175
sys/arch/i386/conf/GENERIC: revision 1.1176
sys/arch/amd64/conf/files.amd64: revision 1.102
sys/arch/i386/conf/GENERIC: revision 1.1177
share/man/man4/options.4: revision 1.485 (patch)
sys/arch/i386/conf/Makefile.i386: revision 1.190
sys/arch/amd64/conf/GENERIC: revision 1.487
sys/arch/amd64/conf/ALL: revision 1.85
sys/arch/amd64/conf/GENERIC: revision 1.488
sys/arch/amd64/conf/GENERIC: revision 1.489
sys/arch/amd64/conf/Makefile.amd64: revision 1.67
sys/arch/i386/conf/ALL: revision 1.437

add an SPECTRE_V2_GCC_MITIGATION option to x86 kernels, that turns
on the GCC spectre v2 mitigation options.
XXX: pullup-8.
XXX: turn on in all kernels.

actually do what the previous change said:
don't turn on the new 'SPECTRE_V2_GCC_MITIGATION' option yet.

turn on GCC spectre v2 mitigation options.
XXX: amd64 ALL doesn't build for me right now
 1.459.2.7 04-Apr-2018  martin Pull up the following revision, requested by maxv in tickt #691:

sys/arch/amd64/conf/GENERIC 1.485 (via patch)

Enable SVS by default.
 1.459.2.6 22-Mar-2018  martin Pull up the following revisions, requested by maxv in ticket #652:

sys/arch/amd64/amd64/amd64_trap.S upto 1.39 (partial, patch)
sys/arch/amd64/amd64/db_machdep.c 1.6 (patch)
sys/arch/amd64/amd64/genassym.cf 1.65,1.66,1.67 (patch)
sys/arch/amd64/amd64/locore.S upto 1.159 (partial, patch)
sys/arch/amd64/amd64/machdep.c 1.299-1.302 (patch)
sys/arch/amd64/amd64/trap.c upto 1.113 (partial, patch)
sys/arch/amd64/amd64/amd64/vector.S upto 1.61 (partial, patch)
sys/arch/amd64/conf/GENERIC 1.477,1.478 (patch)
sys/arch/amd64/conf/kern.ldscript 1.26 (patch)
sys/arch/amd64/include/frameasm.h upto 1.37 (partial, patch)
sys/arch/amd64/include/param.h 1.25 (patch)
sys/arch/amd64/include/pmap.h 1.41,1.43,1.44 (patch)
sys/arch/x86/conf/files.x86 1.91,1.93 (patch)
sys/arch/x86/include/cpu.h 1.88,1.89 (patch)
sys/arch/x86/include/pmap.h 1.75 (patch)
sys/arch/x86/x86/cpu.c 1.144,1.146,1.148,1.149 (patch)
sys/arch/x86/x86/pmap.c upto 1.289 (partial, patch)
sys/arch/x86/x86/vm_machdep.c 1.31,1.32 (patch)
sys/arch/x86/x86/x86_machdep.c 1.104,1.106,1.108 (patch)
sys/arch/x86/x86/svs.c 1.1-1.14
sys/arch/xen/conf/files.compat 1.30 (patch)

Backport SVS. Not enabled yet.
 1.459.2.5 11-Feb-2018  snj Pull up following revision(s) (requested by ozaki-r in ticket #536):
distrib/sets/lists/base/shl.mi: 1.825
distrib/sets/lists/comp/mi: 1.2168-1.2169
distrib/sets/lists/comp/shl.mi: 1.310
distrib/sets/lists/debug/mi: 1.234
distrib/sets/lists/debug/shl.mi: 1.188
distrib/sets/lists/man/mi: 1.1570
distrib/sets/lists/tests/mi: 1.772
etc/mtree/NetBSD.dist.tests: 1.150
share/man/man4/Makefile: 1.650
share/man/man4/ipsec.4: 1.42-1.43
share/man/man4/ipsecif.4: 1.1-1.5
sys/arch/amd64/conf/ALL: 1.77
sys/arch/amd64/conf/GENERIC: 1.480
sys/conf/files: 1.1191
sys/net/Makefile: 1.34
sys/net/files.net: 1.14
sys/net/if.c: 1.404
sys/net/if.h: 1.248
sys/net/if_gif.c: 1.135
sys/net/if_ipsec.c: 1.1-1.3
sys/net/if_ipsec.h: 1.1
sys/net/if_l2tp.c: 1.16
sys/net/if_types.h: 1.28
sys/netinet/in.c: 1.214
sys/netinet/in.h: 1.103
sys/netinet/in_gif.c: 1.92
sys/netinet/ip_var.h: 1.122
sys/netinet6/in6.c: 1.257
sys/netinet6/in6.h: 1.88
sys/netinet6/in6_gif.c: 1.90
sys/netinet6/ip6_var.h: 1.75
sys/netipsec/Makefile: 1.6
sys/netipsec/files.netipsec: 1.13
sys/netipsec/ipsec.h: 1.62
sys/netipsec/ipsecif.c: 1.1
sys/netipsec/ipsecif.h: 1.1
sys/netipsec/key.c: 1.246-1.247
sys/netipsec/key.h: 1.34
sys/rump/net/Makefile.rumpnetcomp: 1.20
sys/rump/net/lib/libipsec/IPSEC.ioconf: 1.1
sys/rump/net/lib/libipsec/Makefile: 1.1
sys/rump/net/lib/libipsec/ipsec_component.c: 1.1
tests/net/Makefile: 1.34
tests/net/if_ipsec/Makefile: 1.1
tests/net/if_ipsec/t_ipsec.sh: 1.1-1.2
Don't touch an SP without a reference to it
unify processing to check nesting count for some tunnel protocols.
add ipsec(4) interface, which is used for route-based VPN.
man and ATF are added later, please see man for details.
reviewed by christos@n.o, joerg@n.o and ozaki-r@n.o, thanks.
https://mail-index.netbsd.org/tech-net/2017/12/18/msg006557.html
ipsec(4) interface supports rump now.
add ipsec(4) interface ATF.
add ipsec(4) interface man as ipsecif.4.
add ipsec(4) interface to amd64/GENERIC and amd64/ALL configs.
apply in{,6}_tunnel_validate() to gif(4).
Spell IPsec that way. Simplify macro usage. Sort SEE ALSO. Bump
date for previous.
Improve wording and macro use.
Some parts are not clear to me, so someone with knowledge of ipsecif(4)
should improve this some more.
Improve ipsecif.4. Default port ipsec(4) NAT-T is tested now.
pointed out by wiz@n.o and suggested by ozaki-r@n.o, thanks.
Change the prefix of test names to ipsecif_ to distinguish from tests for ipsec(4)
New sentence, new line. Remove empty macro.
Fix PR kern/52920. Pointed out by David Binderman, thanks.
Improve wording, and put a new drawing, from me and Kengo Nakahara.
apply a little more #ifdef INET/INET6. fixes !INET6 builds.
 1.459.2.4 05-Feb-2018  martin Pull up following revision(s) (requested by pgoyette in ticket #524):

distrib/sets/lists/man/mi 1.1574
distrib/sets/lists/modules/md.amd64 1.73
distrib/sets/lists/modules/md.i386 1.76
share/man/man4/amdtemp.4 1.11
share/man/man4/man4.x86/Makefile 1.17
share/man/man4/man4.x86/amdsmn.4 1.1-1.3
share/man/man4/man4.x86/amdzentemp.4 1.1-1.6
sys/arch/amd64/conf/ALL 1.79,1.80
sys/arch/amd64/conf/GENERIC 1.482,1.484
sys/arch/amd64/conf/XEN3_DOM0 1.146,1.147
sys/arch/x86/pci/amdsmn.c 1.1-1.2
sys/arch/x86/pci/amdsmn.h 1.1
sys/arch/x86/pci/amdzentemp.c 1.1-1.7
sys/arch/x86/pci/files.pci 1.22,1.23
sys/modules/amdzentemp/amdzentemp.ioconf 1.2


Add amdzentemp from FreeBSD via Ian Clark.

man pages for amdsmn and amdzentemp.

Some clean-up on the HISTORY and AUTHORS sections, and addition of a BUGS
section to document the fact that we don't yet handle the required temp
offset, nor do we expose the available thermal-trip value.

Add missing article 'a'

KNF: Put back the blank line following the empty variable declarations
Put back the variable declaration, too, and mark it __diagused
Otherwise a DIAGNOSTIC kernel will complain about the variable being
undeclared.

Correct placement of __diagused attribute.

Modularize the amdsmn(4) driver, and update dependency for amdzentemp(4),
Create amdsmn(4) amd amdzentemp(4) modules for X86.
 1.459.2.3 29-Aug-2017  martin Requested by skrll in ticket #60:
sys/arch/amd64/conf/GENERIC
sys/arch/amd64/conf/XEN3_DOM0
sys/arch/amd64/conf/XEN3_DOMU
sys/arch/cobalt/conf/GENERIC
sys/arch/evbarm/conf/BEAGLEBONE
sys/arch/evbarm/conf/BEAGLEBOARD
sys/arch/evbarm/conf/BEAGLEBOARDXM
sys/arch/evbarm/conf/GENERIC.common
sys/arch/i386/conf/GENERIC
sys/arch/i386/conf/XEN3_DOM0
sys/arch/i386/conf/XEN3_DOMU
sys/arch/mvmeppc/conf/GENERIC
sys/arch/shark/conf/GENERIC
sys/arch/sparc64/conf/GENERIC
sys/arch/zaurus/conf/GENERIC


Re-enable option DIAGNOSTIC for now, will remove it again later.
 1.459.2.2 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.459.2.1 05-Jul-2017  martin Remove options DIAGNOSTIC/DEBUG and PAX debug options.
Requested by snj in #60.
 1.485.2.14 22-Jan-2019  pgoyette Synch GENERIC and NOCOMPAT with GENERIC from HEAD
 1.485.2.13 18-Jan-2019  pgoyette Synch with HEAD
 1.485.2.12 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.485.2.11 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.485.2.10 20-Oct-2018  pgoyette Sync with head
 1.485.2.9 30-Sep-2018  pgoyette Ssync with HEAD
 1.485.2.8 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.485.2.7 28-Jul-2018  pgoyette Sync with HEAD
 1.485.2.6 25-Jun-2018  pgoyette Sync with HEAD
 1.485.2.5 21-May-2018  pgoyette Sync with HEAD
 1.485.2.4 16-Apr-2018  pgoyette Sync with HEAD, resolve some conflicts
 1.485.2.3 30-Mar-2018  pgoyette Extract compat_14 stuff into its own module
 1.485.2.2 30-Mar-2018  pgoyette Resolve conflicts between branch and HEAD
 1.485.2.1 06-Mar-2018  pgoyette Add a NOCOMPAT kernel definition to serve as a baseline for getting
the incremental COMPAT_xx options working.

While here, add some additional "requires COMPAT_xxx" to some of the
options in GENERIC
 1.493.2.4 21-Apr-2020  martin Sync with HEAD
 1.493.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.493.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.493.2.1 10-Jun-2019  christos Sync with HEAD
 1.531.2.11 21-Jun-2021  martin Pull up following revision(s) (requested by riastradh in ticket #1308):

sys/arch/amd64/conf/GENERIC: revision 1.581

Enable tpm @ acpi (now that it can match TPM 1.2 devices, which are not,
as the comment implies, experimental).
 1.531.2.10 07-Jul-2020  martin Pull up following revision(s) (requested by jmcneill in ticket #980):

sys/dev/pci/if_aq.c: revision 1.4
sys/dev/pci/if_aq.c: revision 1.5
sys/arch/amd64/conf/GENERIC: revision 1.553
sys/dev/pci/files.pci: revision 1.419
sys/arch/amd64/conf/XEN3_DOM0: revision 1.170
sys/dev/pci/if_aq.c: revision 1.9
share/man/man4/Makefile: revision 1.693
sys/dev/pci/pcidevs: revision 1.1411
share/man/man4/aq.4: revision 1.1
share/man/man4/aq.4: revision 1.3
sys/arch/i386/conf/ALL: revision 1.479
share/man/man4/aq.4: revision 1.4
sys/dev/pci/if_aq.c: revision 1.10
sys/dev/pci/files.pci: revision 1.421
sys/dev/pci/if_aq.c: revision 1.11
sys/dev/pci/if_aq.c: revision 1.12
sys/dev/pci/if_aq.c: revision 1.13
sys/dev/pci/if_aq.c: revision 1.14
sys/dev/pci/if_aq.c: revision 1.15
sys/dev/pci/if_aq.c: revision 1.16
sys/dev/pci/pcidevs: revision 1.1408
sys/arch/amd64/conf/ALL: revision 1.135
sys/net/ethertypes.h: revision 1.19
sys/arch/i386/conf/GENERIC: revision 1.1218
distrib/sets/lists/man/mi: revision 1.1668
sys/dev/pci/if_aq.c: revision 1.1
sys/dev/pci/if_aq.c: revision 1.2
sys/dev/pci/pcidevs: revision 1.1395
sys/dev/pci/if_aq.c: revision 1.3
sys/arch/evbarm/conf/GENERIC64: revision 1.125

Add the ETHERTYPE_QINQ for 802.1ad VLAN stacking

add Aquantia AQC 10G network adapters
add support Aquantia AQC seriese 10G network adapters.

this driver is based on the FreeBSD version https://github.com/Aquantia/aqtion-freebsd ,
but drastically rewritten for NetBSD.

add aq(4)

Add Aquantia AQC100, AQC100S and D100.

add support VLAN HW filter

set/clear IFF_OACTIVE flag only on txring 0

make counters per queue

support internal PHY temperature sensor

Found by kUBSan:
- Use unsigned to avoid undefined behavior in aq_hw_init().
- Cast to unsigned to avoid undefined behavior in aq_set_mac_addr().

fix descriptions of register map in comment

return the ifmedia active status correctly even while the link is not up after attach.
pointed out by msaitoh@. thanks.

On FIBRE devices, there are times when linkstat interrupt doesn't occur?
reported from Andrius V. thanks.
- use polling instead of linkstat interrupt when FIBRE
- add AQ_FORCE_POLL_LINKSTAT options (not by default)

sort product table, and tabify

add support AQC100S and D100.
not tested, but they are probably the same as the AQC100.
 1.531.2.9 18-May-2020  martin Pull up following revision(s) (requested by isaki in ticket #911):

sys/dev/audio/audiodef.h: revision 1.13
sys/dev/audio/audiodef.h: revision 1.14
sys/arch/sparc/include/param.h: revision 1.74
sys/arch/evbarm/conf/GENERIC64: revision 1.148
sys/arch/sh3/include/param.h: revision 1.25
sys/arch/evbarm/conf/GENERIC: revision 1.75
sys/arch/m68k/include/param.h: revision 1.23
sys/arch/amd64/conf/GENERIC: revision 1.564
sys/arch/hppa/include/param.h: revision 1.27
sys/dev/audio/audio.c: revision 1.68
sys/arch/vax/include/param.h: revision 1.63
sys/dev/audio/audio.c: revision 1.69

Reduce default AUDIO_BLK_MS from 40msec to 10msec on all platform except m68k
(m68k uses 40msec default as before). And remove the option from GENERIC.

- It's not good idea to set such parameter in individual GENERICs.
- 4msec is (probably no problem for most modern real hardware but)
too aggressive to be default.
- 10msec is too severe for antique machines but it's hard to draw a line.

Set AUDIO_BLK_MS 40 msec on other old(slow) architectures not only m68k.

Thanks tsutsui@ for comment about architecture choice.
And move it from audiodef.h to audio.c as suggested by joerg@.


Move machine dependent AUDIO_BLK_MS default value to <machine/param.h>.
If the port has __AUDIO_BLK_MS in <machine/param.h>, it will be used.

Otherwise the default value (currently 10 msec) defined in audio.c will
be used. This mechanism is for very old ports which cannot satisfactorily
handle 10 msec block. Currently hppa, m68k, sh3, sparc(!64) and vax are.

For port maintainers, if general models in your port cannot satisfactorily
handle 10 msec block, please consider to define your suitable longer period
(40 msec would be a good first choice).

But please don't be eager to make the default value shorter.
<machine/param.h> was discussed in source-changes-d. It's better than
ifdef storm, or adding 60+ new header files in every arch/*/include/
directories for this. Thanks mrg@, ad@, and everyone.
http://mail-index.netbsd.org/source-changes-d/2020/05/01/msg012572.html
 1.531.2.8 27-Jan-2020  martin Pull up following revision(s) (requested by nia in ticket #657):

sys/dev/files.audio: revision 1.13
sys/dev/files.audio: revision 1.14
sys/arch/amd64/conf/GENERIC: revision 1.559
sys/arch/evbarm/conf/GENERIC: revision 1.71
sys/arch/evbarm/conf/GENERIC64: revision 1.134
sys/dev/audio/audiodef.h: revision 1.8

Set AUDIO_BLK_MS=4 - unlikely to cause significant overhead on non-m68k.

Several of us have been setting this in /etc/sysctl.conf for months, to
get better performance from applications that require synced audio, etc.
It's also mentioned as a good value with low overhead on most archs here:
href="https://mail-index.netbsd.org/tech-kern/2019/12/07/msg025830.html

We could probably go lower, but this is low enough to make most/all
software run well, removing frame drops. It's also low enough to get
emulators/mednafen to stop complaining in the console.

defopt AUDIO_BLK_MS

Follow amd64 and set AUDIO_BLK_MS=4 by default

defopt -> defparam (oops)
 1.531.2.7 21-Jan-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #626):

sys/arch/amd64/conf/GENERIC: revision 1.552
sys/dev/pci/if_casreg.h: revision 1.2
sys/dev/pci/if_cas.c: revision 1.37
share/man/man4/cas.4: revision 1.4
sys/dev/pci/if_casvar.h: revision 1.7

Update supported device list with part number. From FreeBSD.

Fix a bug that the driver sometimes incorrectly attach gentbi(4) instead of
gphyter(4) on non-fiber device.

Tested with Sun Quad GigaSwift Ethernet UTP (QGE) (part no. 501-6522) on
amd64. On this environment, the problem frequently had occurred. I also
tested with other 4 cas(4) variants.

Add cas(4).
 1.531.2.6 25-Nov-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #478):

sys/dev/mii/smscphy.c: revision 1.1
sys/arch/amd64/conf/ALL: revision 1.127
sys/arch/amd64/conf/ALL: revision 1.128
sys/dev/mii/files.mii: revision 1.52
sys/dev/mii/files.mii: revision 1.53
sys/arch/i386/conf/ALL: revision 1.473
share/man/man4/mii.4: revision 1.29
sys/arch/i386/conf/ALL: revision 1.474
sys/arch/amd64/conf/GENERIC: revision 1.543
sys/arch/amd64/conf/GENERIC: revision 1.544
sys/dev/mii/jmphyreg.h: revision 1.1
share/man/man4/Makefile: revision 1.687
share/man/man4/smscphy.4: revision 1.1
share/man/man4/Makefile: revision 1.688
sys/dev/mii/jmphy.c: revision 1.1
sys/dev/DEVNAMES: revision 1.324
sys/dev/DEVNAMES: revision 1.325
distrib/sets/lists/man/mi: revision 1.1661
sys/arch/i386/conf/GENERIC: revision 1.1214
distrib/sets/lists/man/mi: revision 1.1662
sys/arch/i386/conf/GENERIC: revision 1.1215
share/man/man4/jmphy.4: revision 1.1
share/man/man4/jme.4: revision 1.8

Add jmphy(4) from OpenBSD.

Add jmphy.4.

Port SMSC LAN87xx 10/100 Ethernet PHY driver from FreeBSD with some cleanup
and IFM_NONE support.
 1.531.2.5 25-Nov-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #476):

sys/dev/pci/if_stgereg.h: revision 1.6
sys/arch/amd64/conf/ALL: revision 1.124
sys/dev/mii/files.mii: revision 1.51
share/man/man4/vge.4: revision 1.8
share/man/man4/vge.4: revision 1.9
distrib/sets/lists/man/mi: revision 1.1656
sys/arch/i386/conf/ALL: revision 1.471
share/man/man4/mii.4: revision 1.28
sys/dev/pci/if_stge.c: revision 1.71
sys/dev/mii/ipgphy.c: revision 1.1
sys/dev/mii/ipgphy.c: revision 1.2
share/man/man4/Makefile: revision 1.684
sys/dev/mii/ipgphy.c: revision 1.3
sys/dev/mii/ipgphyreg.h: revision 1.1
sys/dev/mii/ipgphy.c: revision 1.4
sys/dev/mii/ipgphyreg.h: revision 1.2
sys/dev/mii/ipgphy.c: revision 1.5
sys/dev/mii/ipgphyreg.h: revision 1.3
sys/dev/DEVNAMES: revision 1.322
sys/arch/i386/conf/GENERIC: revision 1.1211
sys/arch/amd64/conf/GENERIC: revision 1.537
share/man/man4/ipgphy.4: revision 1.1
share/man/man4/ipgphy.4: revision 1.2

Add support IC Plus IP1000* PHYs. PR/kern 42314 first reported by

Tomokazu HARADA and patch provided by Andrius V.

New sentence, new line.
Fix date. Add RCS Id.

KNF. No functional change.

STGE_PhyCtrl is not PHY register but MAC register, so use ukphy_status()
for IP1000A device.

- Use auto-negotiation when forcing 1000BASE-T.
- Add XXX comment for strange pause setting code. I suspect this is wrong.
- On my environments, 1000BASE-T half duplex doesn't work, so we might remove
IFM_1000T_HDX from this device in future.
- Define IPGPHY_SCR's address.
- Whitespace fix.

Add missing NetBSD RCS Id. Reported by Andrius V.
 1.531.2.4 21-Nov-2019  martin In preparation for the upcoming release, turn off DIAGNOSTIC in most
kernel configs, modules and libc.
 1.531.2.3 15-Oct-2019  martin Pull up following revision(s) (requested by tnn in ticket #306):

sys/arch/amd64/conf/GENERIC: revision 1.536

add mcx(4) to GENERIC

Tested on dual-port ConnectX-4 with 25 Gbit/s AOC
 1.531.2.2 09-Aug-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #37):

doc/3RDPARTY: revision 1.1641
sys/dev/pci/if_ena.c: revision 1.16
sys/arch/amd64/conf/GENERIC: revision 1.532

If the memory space's BAR and the MSI-X table is on the same BAR,
reserve the space. Almost the same as nvme_pci.c and xhci_pci.c.
Tested by ryoon@.

Add ena(4).
 1.531.2.1 09-Aug-2019  martin Pull up following revision(s) (requested by rin in ticket #35):

sys/arch/amd64/conf/ALL: revision 1.121
sys/arch/i386/conf/XEN3PAE_DOM0: revision 1.14
sys/arch/amd64/conf/XEN3_DOM0: revision 1.168
sys/arch/i386/conf/GENERIC: revision 1.1210
sys/arch/amd64/conf/GENERIC: revision 1.534

xhci(4) is considered stable enough. So, remove misleading comments.

XXX
pullup to netbsd-9
 1.553.2.3 29-Feb-2020  ad Sync with head.
 1.553.2.2 25-Jan-2020  ad Sync with head.
 1.553.2.1 17-Jan-2020  ad Sync with head.
 1.564.2.2 25-Apr-2020  bouyer Merge GENERIC_XENHVM in GENERIC.
Remove XEN3_PVHVM/XEN3PAE_PVHVM files which have been obsolete for some time
on the branch
 1.564.2.1 20-Apr-2020  bouyer Sync with HEAD
 1.580.2.1 03-Apr-2021  thorpej Sync with HEAD.
 1.588.6.1 31-May-2021  cjep sync with head
 1.588.4.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.599.4.8 08-Aug-2025  martin Pull up following revision(s) (requested by skrll in ticket #1148):

sys/arch/evbarm/conf/GENERIC64: revision 1.227
sys/dev/pci/files.pci: revision 1.451
sys/dev/pci/pvscsi.c: revision 1.1
sys/dev/pci/pvscsi.c: revision 1.2
sys/dev/pci/pvscsi.h: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.617

Add a port of the FreeBSD driver for the VMware PV SCSI controller found
in VMware's ESXi product.

Tested on ESXi/Arm such that an installation from ISO succeeds and boots.

Add the barrier that a comment describes.
 1.599.4.7 09-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #939):

distrib/sets/lists/debug/module.md.amd64: revision 1.18
sys/modules/Makefile: revision 1.292
lib/libc/gen/arc4random.c: revision 1.34
lib/libc/gen/arc4random.c: revision 1.35
lib/libc/gen/arc4random.c: revision 1.36
lib/libc/gen/arc4random.c: revision 1.37
sys/kern/kern_entropy.c: revision 1.70
lib/libc/gen/arc4random.c: revision 1.38
sys/kern/kern_entropy.c: revision 1.71
lib/libc/gen/getentropy.3: revision 1.8
distrib/sets/lists/modules/md.amd64: revision 1.103
share/man/man4/rnd.4: revision 1.42
share/man/man4/rnd.4: revision 1.44
lib/libc/include/arc4random.h: revision 1.1
distrib/sets/lists/man/mi: revision 1.1786
sys/arch/i386/conf/GENERIC: revision 1.1258
sys/modules/acpivmgenid/acpivmgenid.ioconf: revision 1.1
sys/arch/amd64/conf/ALL: revision 1.190
distrib/sets/lists/debug/mi: revision 1.446
sys/arch/i386/conf/ALL: revision 1.521
lib/libc/gen/Makefile.inc: revision 1.219
distrib/sets/lists/debug/module.md.i386: revision 1.12
sys/dev/acpi/acpi_vmgenid.c: revision 1.1
sys/dev/acpi/acpi_vmgenid.c: revision 1.2
lib/libc/include/reentrant.h: revision 1.22
sys/arch/evbarm/conf/GENERIC64: revision 1.219
share/man/man4/Makefile: revision 1.735
distrib/sets/lists/modules/md.i386: revision 1.100
distrib/sets/lists/tests/mi: revision 1.1334
lib/libc/gen/arc4random.3: revision 1.22
sys/dev/acpi/files.acpi: revision 1.133
lib/libc/gen/arc4random.3: revision 1.23
tests/lib/libc/gen/t_arc4random.c: revision 1.1
sys/sys/entropy.h: revision 1.6
sys/arch/amd64/conf/GENERIC: revision 1.614
sys/modules/acpivmgenid/Makefile: revision 1.1
share/man/man4/acpivmgenid.4: revision 1.1
lib/libc/gen/Makefile.inc: revision 1.220
tests/lib/libc/gen/Makefile: revision 1.56
share/man/man4/acpivmgenid.4: revision 1.2
share/man/man4/acpivmgenid.4: revision 1.3

(all via patch)

Catch up with all the lint warnings since exit on warning was disabled.

Disable 'missing header declaration' and 'nested extern' warnings for now.
acpivmgenid(4): New driver for virtual machine generation ID.

Added to amd64/ALL and i386/ALL kernel configurations, and made
available as a loadable module acpivmgenid.kmod on x86, for now.
TBD: Add to all ACPI-supporting GENERIC kernels.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

entropy(9): Factor out subroutines to reset and gather entropy.
`Reset' means we keep the data in the pool, but assume it had zero
entropy. `Gather' means we request samples from all on-demand
sources and wait for the synchronous ones to complete.

No functional change intended, other than to expose new symbols --
just preparation to expose these to acpivmgenid(4), so it can use
these when the VM host notifies us that we, the guest, have been
cloned.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

acpivmgenid(4): Reset and gather entropy on VM clone notification.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

arc4random(3): Reseed if system entropy epoch changes.
This can happen, for example, if the system is a VM instance, and the
VM is cloned.

This incurs the cost of a system call on every arc4random call, which
is unfortunate, but
1. we don't currently have a (machine-independent) mechanism for
exposing a read-only page to userland shared by the kernel to
enable a cheaper access path to the entropy epoch; and
2. the algorithm here -- a simple application of ChaCha -- is likely
also a bottleneck and could be much cheaper by
(a) using sys/crypto/chacha for machine-dependent vectorized
ChaCha code, and
(b) filling a buffer (somewhere between a cipher block and a page)
in a batch at a time, instead of running ChaCha to generate
only 32 bytes at a time.
So although this might be a performance hit, the security benefit is
worthwhile and we have a clear path to do better than reversing the
performance hit later.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

acpivmgenid(4): Nix BUGS that have been squashed.
Reference kern.entropy.epoch for the remaining bug (which is a
performance issue, not a security issue).
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

entropy(9): Allow unprivileged reads of sysctl kern.entropy.epoch.

Applications need this in order to know when to reseed. (We should
also expose it through a page shared read-only with userland for
cheaper access, but until we do, let's let applications get at it
through sysctl.)
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

arc4random.c: Fix test program.

This isn't wired up anywhere, but let's reduce the bitrot. It was
helpful in reminding me that kern.entropy.epoch was, for reasons I
can't remember, restricted to privileged access.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

amd64, evbarm, i386: Add acpivmgenid(4) to GENERIC.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

rnd(4): Document kern.entropy.epoch is unprivileged and elaborate.
Cross-reference acpivmgenid(4).
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

arc4random(3): Note that arc4random respects kern.entropy.epoch.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork
Add debug info for new acpivmgenid module

arc4random(3): Add automatic tests.

This verifies that:
- arc4random zeroes its state and reseeds itself on fork
- arc4random reseeds itself on entropy consolidation (e.g., VM clone)
- arc4random falls back to global state if it can't allocate local
state because address space limits cause mmap to fail

NOTE: This adds a new libc symbol __arc4random_global, but it's in
the reserved namespace and only used by t_arc4random, so no libc
minor bump.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

getentropy(3): Note intent to reseed on VM clone, and caveats.

Tidy markup and pacify some mandoc -Tlint complaints while here.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

Bump dates on man pages recently updated to mention VM clones.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

arc4random(3): Pacify some of lint's complaints.
PR kern/58632: getentropy(2) and arc4random(3) do not reseed on VM
fork

arc4random: suppress another lint warning
 1.599.4.6 20-Jun-2024  martin Pull up following revision(s) (requested by andvar in ticket #700):

sys/arch/i386/conf/GENERIC: revision 1.1256
share/man/man4/man4.x86/viac7temp.4: revision 1.1
sys/arch/x86/x86/viac7temp.c: revision 1.11
share/man/man4/man4.x86/Makefile: revision 1.24
share/man/man4/man4.i386/viac7temp.4: file removal
share/man/man4/man4.i386/Makefile: revision 1.81
distrib/sets/lists/man/mi: revision 1.1773
sys/arch/amd64/conf/GENERIC: revision 1.612
sys/arch/amd64/conf/ALL: revision 1.188
sys/arch/i386/conf/ALL: revision 1.519

viac7temp(4): rewrite temperature sensor to read value from MSR instead of using
documented cpuid instruction and eax register.

This approach is adapted from linux via-cputemp.c, no official documentation is
currently available. However, msr value seems to work on all tested CPUs while
documented cpuid instruction typically reports 0, even for my C7-D CPU.
msr value seems to have temperature in Celsius in lower 24-bits without fraction
(thus "msr & 0xffffff;" is used).

Tested on my personal systems based on CPUs below (i386 and amd64):
C7-D 1.6GHz (i386 only), Nano X2 L4350E, Nano X2 U4300, U2300 Nano, KX-U6580.
Also got one response via email which was based on Nano X2 L4050 (VE-900).

Nano reports independent values for each core.

KX-U6580 seems to show the same value for all cores but more testing is needed.

Since it works on amd64 capable CPUs, adding driver to GENERIC kernel config.

Also moving viac7temp man page to x86 instead of i386 (with updates).

In theory the change should add support for all VIA Nano CPUs and Zhaoxin CPUs
at least up to KX-6000(G) series.

In the future I may need to introduce amd64 kernel module as well.

Patch mainly reviewed by riastradh.
 1.599.4.5 03-Nov-2023  martin Pull up following revision(s) (requested by msaitoh in ticket #446):

sys/dev/pci/if_eqos_pci.c: revision 1.3
sys/arch/i386/conf/GENERIC: revision 1.1251
sys/arch/i386/conf/GENERIC: revision 1.1252
sys/arch/amd64/conf/GENERIC: revision 1.607
sys/arch/amd64/conf/GENERIC: revision 1.608
sys/dev/ic/dwc_eqos.c: revision 1.20
sys/dev/ic/dwc_eqos.c: revision 1.21
share/man/man4/eqos.4: revision 1.2
sys/dev/ic/dwc_eqos.c: revision 1.22
sys/dev/ic/dwc_eqos_reg.h: revision 1.7
sys/dev/ic/dwc_eqos.c: revision 1.23
sys/dev/ic/dwc_eqos_reg.h: revision 1.8
sys/dev/ic/dwc_eqos.c: revision 1.24
sys/dev/ic/dwc_eqos.c: revision 1.25
sys/dev/ic/dwc_eqos.c: revision 1.26
sys/dev/ic/dwc_eqos.c: revision 1.27
sys/dev/ic/dwc_eqos_var.h: revision 1.5
sys/dev/ic/dwc_eqos.c: revision 1.28
sys/dev/ic/dwc_eqos_var.h: revision 1.6
sys/dev/ic/dwc_eqos.c: revision 1.29
sys/dev/ic/dwc_eqos.c: revision 1.18
sys/dev/ic/dwc_eqos.c: revision 1.19
sys/dev/pci/files.pci: revision 1.448
sys/dev/pci/if_eqos_pci.c: revision 1.1
sys/dev/pci/if_eqos_pci.c: revision 1.2

eqos(4): Fix definition of GMAC_MAC_HW_FEATURE1_RXFIFOSIZE.

eqos(4): Fix a bug that the MAC address is swapped.
Don't swap the MAC address in eqos_get_eaddr(). Other OSes except FreeBSD
(which was based on NetBSD's) don't swap it. With this change, my own
OnLogic Helix 330's MAC address becomes correct. The OUI is 84:8b:cd:4d.
It's owned by Logic Supply and they were acquired by OnLogic.

On Quartz64 with UEFI, the MAC address is wrongly set and the multicast
bit might be set. To do workaround, clear the bit if it's set.

eqos(4): Add missing clock range.

eqos(4): Accept if snpsver == 0x52. Tested with Intel Elkhart Lake.

TODO:
Multiqueue support.
Add watchdog timer.
Add detach function.

eqos(4): Add initial support for Intel Elkhart Lake internal Ethernet devices.
- Only tested on PSE SGMII 1G Ethernet MAC with MaxLinear GPY115.
- I don't know why dmat64 doesn't work. eqos_attach() have a special
code if EQOS_HW_FEATURE_ADDR64_32BIT(sc) is true, but it seems it doesn't
work.
- TODO:
Multiqueue support.
Detach support.

eqos(4): Fix compile error for arch that sizeof(bus_size_t) == 4 (i386).
Trailing whitespace

eqos(4): Disable eqos(4) by default because it's not stable on x86.

eqos(4): KNF. No functional change.

eqos(4): Add and modify some DPRINTF()s.

eqos(4): Add sysctls for debugging.

eqos(4): Use EQOS_TXLOCK() more to be stable.
Fix a bug that sc_tx.{cur,next,queued} become inconsitent.
Use txlock when accessing TX data.

eqos(4): Set TX/RX DMA burst length to improve performance.

eqos(4): Set flow control correctly.

eqos_pci: Limit to 32bit DMA only for PSE devices.

eqos(4): Fix typo in comment.
 1.599.4.4 09-Oct-2023  snj Apply patch (requested by martin in ticket #401):
Disable DIAGNOSTIC/DEBUG.
 1.599.4.3 08-Oct-2023  martin Pull up following revision(s) (requested by rin in ticket #393):

sys/dev/pci/igc/if_igc.c up to 1.3
sys/dev/pci/igc/if_igc.h up to 1.2
sys/dev/pci/igc/igc_api.c up to 1.2
sys/dev/pci/igc/igc_api.h up to 1.2
sys/dev/pci/igc/igc_base.c up to 1.2
sys/dev/pci/igc/igc_base.h up to 1.2
sys/dev/pci/igc/igc_defines.h up to 1.2
sys/dev/pci/igc/igc_evcnt.h up to 1.1
sys/dev/pci/igc/igc_hw.h up to 1.2
sys/dev/pci/igc/igc_i225.c up to 1.2
sys/dev/pci/igc/igc_i225.h up to 1.2
sys/dev/pci/igc/igc_mac.c up to 1.2
sys/dev/pci/igc/igc_mac.h up to 1.2
sys/dev/pci/igc/igc_nvm.c up to 1.2
sys/dev/pci/igc/igc_nvm.h up to 1.2
sys/dev/pci/igc/igc_phy.c up to 1.2
sys/dev/pci/igc/igc_phy.h up to 1.2
sys/dev/pci/igc/igc_regs.h up to 1.2
distrib/sets/lists/man/mi: revision 1.1766
sys/arch/amd64/conf/GENERIC: revision 1.606
sys/arch/evbppc/conf/DHT: revision 1.5
sys/arch/evbarm/conf/GENERIC64: revision 1.213
share/man/man4/Makefile: revision 1.733
sys/arch/amd64/conf/ALL: revision 1.181
share/man/man4/igc.4: revision 1.1
sys/dev/pci/files.pci: revision 1.447
sys/arch/amd64/conf/XEN3_DOM0: revision 1.200
doc/CHANGES (apply patch)

Add igc(4) for Intel I225/I226 series ethernet devices
 1.599.4.2 17-Aug-2023  martin Pull up following revision(s) (requested by andvar in ticket #329):

distrib/sets/lists/modules/md.amd64: revision 1.100
sys/external/bsd/drm2/dist/include/drm/drm_pciids.h: revision 1.5
sys/arch/amd64/conf/GENERIC: revision 1.605
sys/modules/Makefile: revision 1.279
distrib/sets/lists/debug/module.md.amd64: revision 1.14

viadrmums(4): build legacy VIA DRM UMS driver module for amd64.

This driver is not built-in by default, thus loadable module can help (un)lucky
owners of 64-bit capable VIA (Nano/Eden) systems or early AMD/Intel systems
with some VIA chipsets, which include VIA integrated graphics.

I also boldly added product IDs for few later models from VX8xx/VX9xx chipsets
without 3D support (DX9_0) to "expand" the driver support to more systems.

Tested successfully basic functionality on VX800, and partially successfully
on VX900 (on VX900 Xorg failed to initialize due to openchrome related issues,
viadrmums attaches and it is by used the driver).

Didn't test on VX855, I don't have one.
 1.599.4.1 01-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #282):

sys/dev/pci/ichsmb.c: revision 1.82
sys/arch/amd64/conf/GENERIC: revision 1.602
sys/arch/x86/pci/tco.c: revision 1.10
sys/arch/x86/pci/tco.h: revision 1.5
sys/arch/x86/pci/ichlpcib.c: revision 1.59
sys/dev/ic/i82801lpcreg.h: revision 1.17
sys/arch/x86/pci/files.pci: revision 1.27
sys/dev/pci/files.pci: revision 1.446

ichsmb(4), tco(4): Add support for TCO on newer Intel chipsets.

TCO (`Total Cost of Ownership', Intel's bizarre name for a watchdog
timer) used to hang off the Intel I/O platform controller hub's (ICH)
low-pin-count interface bridge (LPC IB), or ichlpcib(4). On newer
devices, it hangs off the ICH SMBus instead.
Tested on INTEL 100SERIES_SMB (works) and INTEL 100SERIES_LP_SMB
(doesn't work, still not sure why).

XXX kernel revbump: This breaks the module ABI -- tco(4) modules
older than the change to make ta_has_rcba into ta_version will
incorrectly attach at buses they do not understand. (However, the
tco(4) driver is statically built into GENERIC, so maybe it's safe
for pullup since the module wouldn't have worked anyway.)
 1.612.2.1 02-Aug-2025  perseant Sync with HEAD
 1.616.2.2 20-Oct-2025  martin Pull up following revision(s) (requested by riastradh in ticket #66):

sys/arch/x86/include/mpacpi.h: revision 1.12
sys/arch/x86/x86/mpacpi.c: revision 1.112
sys/arch/amd64/conf/ALL: revision 1.194
sys/arch/i386/conf/ALL: revision 1.524
sys/arch/x86/acpi/acpi_machdep.c: revision 1.40
sys/arch/i386/conf/GENERIC: revision 1.1261
sys/dev/acpi/acpi_mcfg.h: revision 1.6
sys/arch/amd64/conf/GENERIC: revision 1.618

x86: Wire up PCI resource manager if enabled.

Enable in your kernel config with `options PCI_RESOURCE'.

Adapted from a patch by mlelstv@.
PR port-amd64/59118: Thinkpad T495s - iwm PCI BAR is zero
 1.616.2.1 08-Aug-2025  martin Pull up following revision(s) (requested by skrll in ticket #6):

sys/arch/evbarm/conf/GENERIC64: revision 1.227
sys/dev/pci/files.pci: revision 1.451
sys/dev/pci/pvscsi.c: revision 1.1
sys/dev/pci/pvscsi.c: revision 1.2
sys/dev/pci/pvscsi.h: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.617

Add a port of the FreeBSD driver for the VMware PV SCSI controller found
in VMware's ESXi product.

Tested on ESXi/Arm such that an installation from ISO succeeds and boots.

Add the barrier that a comment describes.
 1.3 20-Dec-2007  ad Remove GENERIC.MP config and enable SMP by default on amd64.
 1.2 27-Dec-2005  chs branches: 1.2.50; 1.2.56; 1.2.60; 1.2.64;
remove the COM_MPLOCK option. always include the spinlock in the softc
and always call the simple_* locking functions. the locking functions
are compiled out if they are not needed anyway, so a separate option
for this doesn't gain anything.

this also fixes the serial console on my alpha ES40 (which doesn't make much
sense since the com driver should still be under the big lock on alpha,
but whatever).
 1.1 26-Apr-2003  fvdl branches: 1.1.18;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.18.2 21-Jan-2008  yamt sync with head
 1.1.18.1 21-Jun-2006  yamt sync with head.
 1.2.64.1 02-Jan-2008  bouyer Sync with HEAD
 1.2.60.1 26-Dec-2007  ad Sync with head.
 1.2.56.1 27-Dec-2007  mjf Sync with HEAD.
 1.2.50.1 23-Mar-2008  matt sync with HEAD
 1.2 29-Feb-2008  jmmv Remove GENERIC.local from the repository

Make all the kernels that currently include their corresponding GENERIC.local
file use the cinclude directive instead of include. This way config(1) will
not complain if the file cannot be found.

After doing this, remove the GENERIC.local files from the repository so that
the user will not see modified files during updates, and local changes to
them cannot end up in the repository by mistake.

Discussed in tech-kern@ earlier this month. No strong objections.
 1.1 26-Apr-2003  fvdl branches: 1.1.18; 1.1.80; 1.1.100; 1.1.104;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.104.1 03-Apr-2008  mjf Sync with HEAD.
 1.1.100.1 24-Mar-2008  keiichi sync with head.
 1.1.80.1 23-Mar-2008  matt sync with HEAD
 1.1.18.1 17-Mar-2008  yamt sync with head.
 1.3 06-Mar-2007  bouyer For the benefit of modern hardware, enable ACPI by default in INSTALL and
GENERIC kernels. If ACPI is an issue on your hardware, 'boot -c' and
'disable acpi' should be a workaround. ACPI-enabled kernels works fine
on pre-acpi hardware.
for amd64:
- add ACPI to INSTALL and GENERIC, remove the *_ACPI config files.
- get rid of the bootfloppy-big.fs boot image, and got to a 3-floppy boot
image
for i386:
- introduce INSTALL_LARGE which has ACPI and some devices with big firmware
- move some devices from INSTALL to INSTALL_LARGE
- Boot floppies still use INSTALL, and bootfloppy-big.fs is still there
(for thoses who want to build el-torito floppy emulation boot CD) and use
INSTALL.
For both, drop the 'iso-image' code in etc/ to make the iso bootable, we'll
use something else to build bootable CDs.
 1.2 04-Jul-2006  christos branches: 1.2.10;
Apply fvdl's acpi pci interrupt configuration code.
- MPACPI is no more.
- MPACPI_SCANPCI -> ACPI_SCANPCI
 1.1 30-Dec-2005  rjs branches: 1.1.4; 1.1.8; 1.1.16; 1.1.18;
Add config for ACPI kernel.
 1.1.18.4 03-Sep-2007  yamt sync with head.
 1.1.18.3 30-Dec-2006  yamt sync with head.
 1.1.18.2 21-Jun-2006  yamt sync with head.
 1.1.18.1 30-Dec-2005  yamt file GENERIC_ACPI was added on branch yamt-lazymbuf on 2006-06-21 14:48:25 +0000
 1.1.16.1 13-Jul-2006  gdamore Merge from HEAD.
 1.1.8.1 11-Aug-2006  yamt sync with head
 1.1.4.1 09-Sep-2006  rpaulo sync with head
 1.2.10.2 17-May-2007  yamt fix merge botches.
 1.2.10.1 12-Mar-2007  rmind Sync with HEAD.
 1.5 21-Jul-2018  maxv Remove "no options GPROF", we don't have GPROF in the x86 kernels anymore.
By the way this caused a warning because GPROF is not defflag'ed
correctly...
 1.4 04-Feb-2018  maxv branches: 1.4.2; 1.4.4;
Explicitly disable the kernel-mode GPROF (even though it is never enabled),
and explain a bit.
 1.3 29-Oct-2017  maxv branches: 1.3.2;
Mmh, we don't map the CTF section on kaslr kernels, so disable
KDTRACE_HOOKS for now.
 1.2 08-Oct-2017  maxv KASLR: add workarounds to compute the bootinfo VAs (use the direct map),
and don't use large pages yet. Both will be fixed later.
 1.1 07-Oct-2017  maxv Add GENERIC_KASLR, only toolchain parts for now.
 1.3.2.2 03-Dec-2017  jdolecek update from HEAD
 1.3.2.1 29-Oct-2017  jdolecek file GENERIC_KASLR was added on branch tls-maxphys on 2017-12-03 11:35:47 +0000
 1.4.4.1 10-Jun-2019  christos Sync with HEAD
 1.4.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.2 18-Dec-2016  dholland Whitespace.
 1.1 30-Jun-2012  reinoud branches: 1.1.2; 1.1.4; 1.1.18; 1.1.22;
Move i386 and amd64 usermode configurations to their respective directories
and make the usermode kernels buildalbe under build.sh.

The resulting kernels are build and packaged correctly as are the associated
modules.
 1.1.22.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.1.18.1 05-Feb-2017  skrll Sync with HEAD
 1.1.4.2 30-Oct-2012  yamt sync with head
 1.1.4.1 30-Jun-2012  yamt file GENERIC_USERMODE was added on branch yamt-pagecache on 2012-10-30 17:18:45 +0000
 1.1.2.1 03-Dec-2017  jdolecek update from HEAD
 1.1 16-Apr-2020  bouyer branches: 1.1.2;
file GENERIC_XENHVM was initially added on branch bouyer-xenpvh.
 1.1.2.6 25-Apr-2020  bouyer Merge GENERIC_XENHVM in GENERIC.
Remove XEN3_PVHVM/XEN3PAE_PVHVM files which have been obsolete for some time
on the branch
 1.1.2.5 20-Apr-2020  bouyer Thanks do jdolecek@, MAXPHYS is not restricted to 32k now.
Nothing prevents merging GENERIC_XENHVM in GENERIC now
 1.1.2.4 16-Apr-2020  bouyer amd64: Xhypervisor_pvhvm_callback has to be in text.user for SVS.
Thanks to maxv@ for helping me with this.
Enable SVS again.
While there, increase ci_idepth before calling do_hypervisor_callback,
and don't touch ci_idepth while looping over pending events.
 1.1.2.3 16-Apr-2020  bouyer Well, no, SVS does't quite work yet.
 1.1.2.2 16-Apr-2020  bouyer SVS is working with PVHVM now
 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.
 1.96 29-Jul-2022  riastradh x86: Disable new DRM_LEGACY option in INSTALL kernel.

The INSTALL kernel appears to be intended to have no drm in it at
all, but DRM_LEGACY brings it in just for modules.
 1.95 18-Apr-2019  maya Follow arm64 and provide two sizes of fonts, so a larger one is chosen
for larger displays.
 1.94 11-Dec-2018  maya revert previous, nouveau apparently works for some people.
 1.93 11-Dec-2018  maya comment out nouveau related lines in INSTALL kernels too
 1.92 25-Dec-2017  rin branches: 1.92.4;
Disable nouveau for INSTALL as in a similar manner to other DRMKMS drivers.
XXX pullup to netbsd-8
 1.91 18-Dec-2016  dholland branches: 1.91.8;
Whitespace.
 1.90 02-Nov-2014  christos branches: 1.90.2; 1.90.4;
propagate drm changes
 1.89 06-Jun-2013  msaitoh branches: 1.89.8;
Fix compile error. PR#38480 was correctly fixed in 2009, it's ok to remove
"no options MTRR"
 1.88 19-Nov-2011  tls branches: 1.88.8;
First step of random number subsystem rework described in
<20111022023242.BA26F14A158@mail.netbsd.org>. This change includes
the following:

An initial cleanup and minor reorganization of the entropy pool
code in sys/dev/rnd.c and sys/dev/rndpool.c. Several bugs are
fixed. Some effort is made to accumulate entropy more quickly at
boot time.

A generic interface, "rndsink", is added, for stream generators to
request that they be re-keyed with good quality entropy from the pool
as soon as it is available.

The arc4random()/arc4randbytes() implementation in libkern is
adjusted to use the rndsink interface for rekeying, which helps
address the problem of low-quality keys at boot time.

An implementation of the FIPS 140-2 statistical tests for random
number generator quality is provided (libkern/rngtest.c). This
is based on Greg Rose's implementation from Qualcomm.

A new random stream generator, nist_ctr_drbg, is provided. It is
based on an implementation of the NIST SP800-90 CTR_DRBG by
Henric Jungheim. This generator users AES in a modified counter
mode to generate a backtracking-resistant random stream.

An abstraction layer, "cprng", is provided for in-kernel consumers
of randomness. The arc4random/arc4randbytes API is deprecated for
in-kernel use. It is replaced by "cprng_strong". The current
cprng_fast implementation wraps the existing arc4random
implementation. The current cprng_strong implementation wraps the
new CTR_DRBG implementation. Both interfaces are rekeyed from
the entropy pool automatically at intervals justifiable from best
current cryptographic practice.

In some quick tests, cprng_fast() is about the same speed as
the old arc4randbytes(), and cprng_strong() is about 20% faster
than rnd_extract_data(). Performance is expected to improve.

The AES code in src/crypto/rijndael is no longer an optional
kernel component, as it is required by cprng_strong, which is
not an optional kernel component.

The entropy pool output is subjected to the rngtest tests at
startup time; if it fails, the system will reboot. There is
approximately a 3/10000 chance of a false positive from these
tests. Entropy pool _input_ from hardware random numbers is
subjected to the rngtest tests at attach time, as well as the
FIPS continuous-output test, to detect bad or stuck hardware
RNGs; if any are detected, they are detached, but the system
continues to run.

A problem with rndctl(8) is fixed -- datastructures with
pointers in arrays are no longer passed to userspace (this
was not a security problem, but rather a major issue for
compat32). A new kernel will require a new rndctl.

The sysctl kern.arandom() and kern.urandom() nodes are hooked
up to the new generators, but the /dev/*random pseudodevices
are not, yet.

Manual pages for the new kernel interfaces are forthcoming.
 1.87 08-Aug-2011  jakllsch branches: 1.87.2;
Finish reverting premature modularization of amd64 kernels.
 1.86 28-May-2011  ryo many whitespace cleanup.
 1.85 16-Feb-2011  jym Per mrg@ request, add MFS as default builtin, for things like init(8).

XXX should be replaced by TMPFS eventually.
 1.84 16-Feb-2011  jym Build certain file-systems and options(7) as module(7). 32 and 64 bits
support are still builtin, as well as FFS, NFS, TMPFS, and most COMPAT
code. Saves approx. 750kiB.

Reflect this in INSTALL kernel, where we have to support more file systems
statically.

See http://mail-index.netbsd.org/port-amd64/2011/02/13/msg001318.html
 1.83 11-Feb-2011  jmcneill attach drm hw drivers to 'drm' not 'vga'
 1.82 09-Aug-2009  christos branches: 1.82.4; 1.82.6; 1.82.8;
put back drm.
 1.81 06-Feb-2009  jym branches: 1.81.2;
Changes to MEMORY_RBFLAGS option:
- renamed to MEMORY_DISK_RBFLAGS to better fit the rest of the
MEMORY_DISK options(4)
- change default value to RB_AUTOBOOT instead of RB_SINGLE, and adapt
the config(5) files accordingly
- document this option inside options(4)

See also http://mail-index.netbsd.org/tech-kern/2008/12/25/msg003924.html

Reviewed by abs@ in private mail.
 1.80 02-May-2008  ad branches: 1.80.8;
- Give x86 BIOS boot the ability to load new style modules and pass them
into the kernel. Based on a patch by jmcneill@, with many fixes and
improvements by me.

- Put MEMORY_DISK_DYNAMIC and MODULAR into the GENERIC kernels, so that
you can load miniroot.kmod from the boot blocks and boot into the
installer!
 1.79 21-Apr-2008  tls branches: 1.79.2;
Work around PR38480 by making it possible to omit options MTRR from
amd64 INSTALL kernels -- and doing so. At least you can now get an
INSTALL kernel onto a box with this odd MTRR configuration to debug it.
 1.78 02-Jan-2008  joerg branches: 1.78.6; 1.78.8;
Better description, this is not GENERIC after all.
 1.77 17-Dec-2007  joerg Use GENERIC for installation as well, just add the ramdisk hooks.
 1.76 05-Dec-2007  xtraeme branches: 1.76.4;
arc(4) -> arcmsr(4)
 1.75 04-Dec-2007  xtraeme Enable arc(4).
 1.74 19-Nov-2007  jnemeth branches: 1.74.2;
PR/37404 - Rui-Xiang Guo -- sync phy list with GENERIC
 1.73 17-Oct-2007  garbled branches: 1.73.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.72 06-Sep-2007  martti branches: 1.72.4;
Fixed indentation (it should be <keyword><space><tab><name><tab><comment>).
 1.71 16-Jun-2007  ad branches: 1.71.4; 1.71.8; 1.71.10;
-options I2OVERBOSE.
 1.70 26-May-2007  briggs Enable aac(4) and ld at aac.
 1.69 15-May-2007  bouyer add jmide(4), a driver for the JMicron Technology JMB36x PCIe to SATA II/PATA
controllers. These controllers can be found on add-on PCIe cards, or
on some motherboards to provide the PATA connectivity (e.g. some intel
ICH8-based motherboards).

Thanks to JMicron Technology for providing me documentation and
different sample boards for this work.
 1.68 07-May-2007  jnemeth PR/36234 - Joerg Niendorf -- xi -> xirc
 1.67 14-Mar-2007  drochner branches: 1.67.6;
It doesn't make sense to specify "configuration" and "interface"
locators for uhub because a hub can't have sub-devices.
This might be sanity-checked eventually.
Same for ubt now after the change to device attachment.
 1.66 06-Mar-2007  bouyer branches: 1.66.2; 1.66.4;
For the benefit of modern hardware, enable ACPI by default in INSTALL and
GENERIC kernels. If ACPI is an issue on your hardware, 'boot -c' and
'disable acpi' should be a workaround. ACPI-enabled kernels works fine
on pre-acpi hardware.
for amd64:
- add ACPI to INSTALL and GENERIC, remove the *_ACPI config files.
- get rid of the bootfloppy-big.fs boot image, and got to a 3-floppy boot
image
for i386:
- introduce INSTALL_LARGE which has ACPI and some devices with big firmware
- move some devices from INSTALL to INSTALL_LARGE
- Boot floppies still use INSTALL, and bootfloppy-big.fs is still there
(for thoses who want to build el-torito floppy emulation boot CD) and use
INSTALL.
For both, drop the 'iso-image' code in etc/ to make the iso bootable, we'll
use something else to build bootable CDs.
 1.65 01-Feb-2007  tron branches: 1.65.2;
Disable wsmouse(4) and all the related low-level drivers The installer
ramdisk doesn't support using the mouse anyway.

Idea provided by Blair Sadewitz in private e-mail.
 1.64 14-Jan-2007  bouyer Uncomment pseudo-device raid and options RAID_AUTOCONFIG, to match
i386's INSTALL. Suggested by Florence HENRY on port-amd64@
 1.63 03-Jan-2007  tron Disable ppp(4) because pppd(8) isn't on the installation image anyway.
 1.62 17-Dec-2006  bouyer Add bnx(4), a driver for Broadcom NetXtreme II 10/100/1000 Ethernet device.
Ported from OpenBSD by cube@, with some bus_dma fixes by me.
Tested on i386 and amd64.
 1.61 17-Dec-2006  bouyer Add mfi(4), a driver for LSI Logic & Dell MegaRAID SAS RAID controller.
Ported from OpenBSD, tested on i386 and amd64.
 1.60 30-Nov-2006  bouyer branches: 1.60.2;
Add ahcisata(4), a driver for AHCI 1.0 and 1.1 controllers. Tested on the sata
ports of a Intel 63xxESB chipset. Does not support NCQ yet.
 1.59 21-Oct-2006  bouyer Add support for the Intel 80003 Gigabit Ethernet controller (found e.g. in
newer server chipsets) to wm(4), from the FreeBSD em(4) driver.
While there, add a few other Intel Ethernet controller that should work as
is.
Properly update the RX error and TX collision counters.
Add ikphy(4), a driver for the Intel i82563 Kumeran 10/100/1000 Ethernet PHYs
 1.58 15-Oct-2006  xtraeme Sync IDE/SATA drivers with i386/GENERIC. Fixes PR port-amd64/34829.
 1.57 23-Sep-2006  jmcneill Add iteide(4) driver to GENERIC and INSTALL kernels; PR# 33426.
 1.56 10-Sep-2006  riz branches: 1.56.2;
Add msk and mskc.
 1.55 14-Aug-2006  skrll branches: 1.55.2;
s/adpater/adapter/

Prompted by PR/34195
 1.54 30-Jul-2006  bouyer branches: 1.54.2;
Add twa(4) and ld at twa
 1.53 27-Apr-2006  jonathan Add entries for svwsata(4) to amd64 GENERIC and INSTALL kernels,
to support SATA ports on Serverworks HT-1000 (aka bcm5785) chips.
 1.52 19-Apr-2006  drochner adjust comments for the new location of wskbdmap_mfii.c,
addresses PR kern/33290 by henry nelson
 1.51 15-Apr-2006  jmmv Remove the getwschar and putwschar accessops from wsdisplay drivers as
requested by uwe@. These were wrong because they were receiving an
emulcookie yet they were accessops (thus having to receive an accesscookie).
Instead, just handle the WSDISPLAYIO_{GET,PUT}WSCHAR ioctls from the
driver's ioctl accessop.

As this reduces the amount of code needed to handle these operations to
two small functions in each driver, remove the WSDISPLAY_CHARFUNCS kernel
option.

Reviewed by, at least, uwe@ and macallan@. No objections in tech-kern@.
 1.50 12-Apr-2006  martti Added ciss(4). Tested by Joseph Dacuma on HP DL-380 G3 with Smart Array 5i.
 1.49 25-Mar-2006  xtraeme Enable rgephy(4), closes PR port-amd64/33117.
 1.48 12-Mar-2006  chs branches: 1.48.2;
add nfe.
 1.47 05-Feb-2006  cube branches: 1.47.2; 1.47.4;
Remove 'count' argument for pseudo-devices that ignore it
(vnd, bpfilter, ppp, gif, gre, tun, sl, strip, faith, stf).
 1.46 04-Feb-2006  rpaulo bpfilter doesn't accept count anymore.
 1.45 04-Jan-2006  xtraeme branches: 1.45.2; 1.45.4;
Enable rlphy(4).
 1.44 20-Dec-2005  thorpej branches: 1.44.2;
Remove the tablet line discipline.
 1.43 07-Dec-2005  tsutsui Adjust comments for options FFS_NO_SNAPSHOT.

XXX: This option should be mentioned in options(4).
 1.42 27-Nov-2005  dsl Compile with -fno-asynchronous-unwind-tables so that gcc doesn't generate
the .eh_frame data area that can be used to aid thr generation of stack
traceback - at a cost of a load of bloat!
Reinstate the isp driver.
Remove the unlikely-to-be-needed esh, lmc and ntwoc.
 1.41 24-Nov-2005  dsl We don't need 'le' here, I'm not sure amd64 GENERIC deserves it either.
 1.40 10-Oct-2005  dsl branches: 1.40.6;
Add sk ethernet as found on ASUS A8V.
Increase ramdisk to 5MB, costs virtually nothing.
 1.39 09-Sep-2005  drochner remove "dev" locators from cardbus device definitions, it doesn't
make sense technically and might be removed
 1.38 19-Aug-2005  christos Enable ptyfs by default on the non-install and non small/tiny/ramdisk kernels
 1.37 05-Aug-2005  skrll Add (commented out) ucycom to various kernel configs.
 1.36 12-Jul-2005  sekiya Add config goo for ath. Tested with a PCI card, detected as:

ath0 at pci0 dev 10 function 0
ath0: interrupting at ioapic0 pin 17 (irq 5)
ath0: 11a rates: 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps
ath0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
ath0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36M bps 48Mbps 54Mbps
ath0: mac 5.9 phy 4.3 radio 3.6

Cardbus untested, so it is commented out.
 1.35 07-Jul-2005  tron Add (commented out) IPSEC_NAT_T option.
 1.34 04-Jul-2005  martti branches: 1.34.2;
Added support for amr. Tested by Joseph A. Dacuma with Dell PowerEdge 2800.
 1.33 26-Jun-2005  dsl Remove 'isp' driver (support for Qlogic ISP [12]0x0 SCSI/FibreChannel).
Compensates for the recent bloat of the ath driver and 802.11 support.
 1.32 09-Jun-2005  tsutsui - Rename options NEW_BUFQ_STRATEGY -> options BUFQ_READPRIO.
(still commented out)
- Add (also commented out) options BUFQ_PRIOCSCAN.

Suggested by perry and soda on tech-kern.
Please refer options(4) for details for these options.
 1.31 15-Apr-2005  itohy Add ukyopon(4).
 1.30 10-Apr-2005  tron Comment out options for PPP compression and active filtering. They are not
necessary in an installation kernel but increase the size considerably.
This fixes PR port-amd64/29928.
 1.29 09-Apr-2005  tron Comment out some wscons(4) options which are only required to run a
X11 server.
 1.28 25-Mar-2005  cube Add attimer(4) configurations everywhere pcppi(4) exists, with the
following rule:
If a pcppi device is enabled for an attachment, enable an attimer for the
same attachement, otherwise comment it.
 1.27 27-Feb-2005  dsl branches: 1.27.2;
Enable FFS_NO_SNAPSHOT in the INSTALL kernel so that it fits into 2 floppies
 1.26 18-Feb-2005  dsl Invert FFS_SNAPSHOT to FFS_NO_SNAPSHOT
 1.25 11-Feb-2005  dsl Add 'option FFS_SNAPSHOT' to most of the config files.
Commented out for kernels that appear to hace space constraints.
 1.24 31-Jan-2005  hannken Add file system snapshots to kernel configs.

- Ffs internal snapshots get compiled in unconditionally.

- File system snapshot device fss(4) added to all kernel configs that
have a disk. Device is commented out on all non-GENERIC kernels.

Reviewed by: Jason Thorpe <thorpej@netbsd.org>
 1.23 18-Jan-2005  scw branches: 1.23.2;
Add "options PMS_SYNAPTICS_TOUCHPAD", commented out by default.
 1.22 17-Jan-2005  cube Add tap(4) support to a random^Wcarefully chosen set of kernel configs.
All those kernels have a line for both tun and bridge, and if either is
commented out, tap is commented out also. With the exception of i386's
GENERIC_TINY.

XXX: we _need_ some way of making this more simple.
 1.21 24-Nov-2004  bouyer branches: 1.21.4;
pdcsata(4), a driver for the Promise SATA150 (aka PDC203xx) serie of
controllers. Tested with a PDC20375 (2 SATA, one PATA) controller on sparc64.
Added to all kernel config file which had pdcide(4).
 1.20 10-Nov-2004  christos Add COMPAT_BSDPTY to the rest of the config files.
 1.19 23-Oct-2004  augustss s/uax/axe/
 1.18 13-Sep-2004  fvdl Remove some devices (sync with i386).
 1.17 04-Sep-2004  manu IPv4 PIM support, based on a submission from Pavlin Radoslavov posted on
tech-net@
 1.16 22-Jun-2004  toshii Add re; Realtek GbE.
 1.15 11-May-2004  thorpej Don't need cz or cy devices in INSTALL kernel, and they put space
pressure on install media.
 1.14 16-Feb-2004  thorpej branches: 1.14.2;
Comment out some SYSV* and *VERBOSE options to shrink these down so
they fit in the current boot floppies.
 1.13 14-Dec-2003  thorpej Split the Intel i31244 SATA controller ("Artisea") driver out of piixide
into its own driver (artsata).
 1.12 13-Dec-2003  thorpej Split out the Silicon Image SATALink support into its own driver,
"satalink".
 1.11 10-Nov-2003  fvdl Trim ramdisk and remove some unneeded options.
 1.10 05-Nov-2003  fvdl Add igphy.
 1.9 25-Oct-2003  fvdl Add ahd, bce, ataraid
 1.8 18-Oct-2003  lukem Use one 'atabus* at ata?' instead of multiple 'atabus* at FOOide? channel ?'
Use 'atapibus* at atapi?' instead of 'atapibus* at atabus?'
 1.7 08-Oct-2003  bouyer Add new per-chip pciide drivers.
 1.6 08-Oct-2003  bouyer Add atabus.
 1.5 01-Sep-2003  fvdl Use MPBIOS_SCANPCI by default.
 1.4 30-Aug-2003  fvdl Remove a lot of stuff, making it closer to the i386 INSTALL.
 1.3 15-May-2003  fvdl branches: 1.3.2;
Decrease the ramdisk size a bit to allow for more options to be added
to the kernel, and still have it fit in 2.88M.
 1.2 10-May-2003  fvdl Enable ioapics.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.3.2.13 11-Dec-2005  christos Sync with head.
 1.3.2.12 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.3.2.11 01-Apr-2005  skrll Sync with HEAD.
 1.3.2.10 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.3.2.9 15-Feb-2005  skrll Sync with HEAD.
 1.3.2.8 04-Feb-2005  skrll Sync with HEAD.
 1.3.2.7 24-Jan-2005  skrll Sync with HEAD.
 1.3.2.6 29-Nov-2004  skrll Sync with HEAD.
 1.3.2.5 14-Nov-2004  skrll Sync with HEAD.
 1.3.2.4 02-Nov-2004  skrll Sync with HEAD.
 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.14.2.2 14-Sep-2004  jmc branches: 1.14.2.2.2;
Pullup rev 1.18 (requested by fvdl in ticket #845)

Remove some devices (sync with i386).
 1.14.2.1 14-Jul-2004  tron Pull up revision 1.16 (requested by fvdl in ticket #655):
Add re; Realtek GbE.
 1.14.2.2.2.2 21-Jul-2005  riz Pull up revision 1.31 (requested by itohy in ticket #1430):
Add ukyopon(4).
 1.14.2.2.2.1 02-Apr-2005  he Pull up revision 1.21 (requested by bouyer in ticket #1019):
Add pdcsata(4), a driver for the Promise SATA150 (aka PDC203xx) series of
controllers.
 1.21.4.1 29-Apr-2005  kent sync with -current
 1.23.2.3 26-Mar-2005  yamt sync with head.
 1.23.2.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.23.2.1 12-Feb-2005  yamt sync with head.
 1.27.2.18 27-May-2007  bouyer Pull up following revision(s) (requested by jnemeth in ticket #1778):
sys/arch/hpcarm/conf/IPAQ: revision 1.50
sys/arch/amd64/conf/GENERIC: revision 1.141
sys/arch/amd64/conf/INSTALL: revision 1.68
sys/arch/i386/conf/SWINGER: revision 1.90
PR/36234 - Joerg Niendorf -- xi -> xirc
 1.27.2.17 03-Mar-2007  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1673):
distrib/sets/lists/man/mi 1.844, 1.871
share/man/man4/Makefile 1.372, 1.379 via patch
share/man/man4/re.4 1.8, 1.9, 1.11, 1.12
share/man/man4/rgephy.4 1.1
share/man/man4/rlphy.4 1.1, 1.2
sys/arch/amd64/conf/GENERIC 1.79, 1.89
sys/arch/amd64/conf/INSTALL 1.45, 1.49
sys/arch/i386/conf/GENERIC 1.717, 1.747
sys/arch/i386/conf/GENERIC_LAPTOP 1.164
sys/arch/i386/conf/INSTALL 1.277, 1.283
sys/arch/i386/conf/INSTALL_LAPTOP 1.96, 1.98
sys/arch/i386/conf/XEN2_DOM0 1.22 via patch
sys/arch/macppc/conf/GENERIC 1.220, 1.246
sys/arch/macppc/conf/INSTALL 1.96, 1.100
sys/dev/cardbus/if_re_cardbus.c 1.10
sys/dev/cardbus/if_rtk_cardbus.c 1.29-1.31
sys/dev/ic/rtl8169.c 1.14, 1.20, 1.24, 1.25, 1.28-1.61, 1.63, 1.64-1.81 via patch
sys/dev/ic/rtl81x9.c 1.52, 1.54-1.63, 1.65, 1.67-1.70
sys/dev/ic/rtl81x9reg.h 1.15-1.26
sys/dev/ic/rtl81x9var.h 1.19, 1.21-1.37
sys/dev/mii/files.mii 1.38
sys/dev/mii/miidevs 1.62, 1.64
sys/dev/mii/rgephy.c 1.10, 1.13-1.16
sys/dev/mii/rlphy.c 1.1, 1.6, 1.7, 1.11 via patch
sys/dev/pci/if_re_pci.c 1.13, 1.15-1.17, 1.19-1.23
sys/dev/pci/if_rtk_pci.c 1.25, 1.28, 1.29, 1.31
sys/dev/pci/pcidevs 1.851, 1.852

on re(4):
- improve stability (I believe ;-)
- add a workaround for hardware ip4csum-tx bug
- support newer chips (8169SB/SC, PCIe based 8168 etc.)
- fix 8139C+ support
- enable hardware VLAN
- misc bus_dma(9) fix (which makes re(4) work on mips ports)

on rtk(4):
- fix kern/31348
- fix possible panic on dreamcast
 1.27.2.16 04-Jan-2007  ghen Pull up following revision(s) (requested by tron in ticket #1615):
sys/arch/amd64/conf/INSTALL: revision 1.63 via patch
sys/arch/i386/conf/INSTALL_LAPTOP: revision 1.113 via patch
Disable ppp(4) because pppd(8) isn't on the installation image anyway.
 1.27.2.15 23-Dec-2006  ghen Pull up following revision(s) (requested by bouyer in ticket #1609):
sys/arch/i386/conf/INSTALL: revision 1.298
sys/arch/i386/conf/GENERIC: revision 1.802
sys/dev/pci/files.pci: revision 1.274
sys/arch/amd64/conf/GENERIC: revision 1.122
sys/dev/pci/mfi_pci.c: revision 1.1 via patch
distrib/sets/lists/man/mi: revision 1.958
sys/arch/amd64/conf/INSTALL: revision 1.61
sys/dev/ic/mfireg.h: revision 1.1
share/man/man4/Makefile: revision 1.416 via patch
sys/dev/ic/mfi.c: revision 1.1
sys/arch/i386/conf/XEN2_DOM0: revision 1.19
sys/dev/ic/mfivar.h: revision 1.1
sys/conf/files: revision 1.821
share/man/man4/mfi.4: revision 1.1
share/man/man4/mfi.4: revision 1.2
sys/dev/pci/pcidevs via patch
Add mfi(4), a driver for LSI Logic & Dell MegaRAID SAS RAID controller.
Ported from OpenBSD, tested on i386 and amd64.
Punctuation issues.
 1.27.2.14 23-Dec-2006  ghen Pull up following revision(s) (requested by bouyer in ticket #1608):
sys/arch/i386/conf/INSTALL: revision 1.299 via patch
sys/arch/i386/conf/XEN2_DOM0: revision 1.20 via patch
sys/arch/i386/conf/GENERIC: revision 1.803 via patch
sys/dev/pci/files.pci: revision 1.275 via patch
sys/arch/i386/conf/GENERIC_LAPTOP: revision 1.218 via patch
sys/arch/amd64/conf/GENERIC: revision 1.123 via patch
sys/dev/pci/if_bnx.c: revision 1.1 via patch
share/man/man4/bnx.4: revision 1.1-1.2 via patch
distrib/sets/lists/man/mi: revision 1.959 via patch
sys/arch/amd64/conf/INSTALL: revision 1.62 via patch
sys/dev/microcode/bnx/bnxfw.h: revision 1.1-1.2 via patch
sys/dev/pci/if_bnxreg.h: revision 1.1 via patch
share/man/man4/Makefile: revision 1.417 via patch
sys/arch/i386/conf/INSTALL_LAPTOP: revision 1.112 via patch
Add bnx(4), a driver for Broadcom NetXtreme II 10/100/1000 Ethernet device.
Ported from OpenBSD by cube@, with some bus_dma fixes by me.
Tested on i386 and amd64.
Add a NetBSD RCS tag.
Nx -> Ox; remove trailing whitespace.
 1.27.2.13 31-Jul-2006  tron branches: 1.27.2.13.2;
Apply patch (requested by bouyer in ticket #1441):
Pullup the twa(4) driver for the 3ware Apache RAID controllers.
Matching revisions in current:
share/man/man4/twa.4 1.1
sys/dev/pci/ld_twa.c 1.2
sys/dev/pci/twa.c 1.9
sys/dev/pci/twaio.h 1.3
sys/dev/pci/twareg.h 1.5
sys/dev/pci/twavar.h 1.5
 1.27.2.12 04-May-2006  tron Pull up following revision(s) (requested by jonathan in ticket #1298):
sys/arch/amd64/conf/INSTALL: revision 1.53
sys/arch/amd64/conf/GENERIC: revision 1.94
Add entries for svwsata(4) to amd64 GENERIC and INSTALL kernels,
to support SATA ports on Serverworks HT-1000 (aka bcm5785) chips.
 1.27.2.11 20-Apr-2006  tron Pull up following revision(s) (requested by martti in ticket #1258):
sys/arch/i386/conf/INSTALL: revision 1.284
sys/arch/i386/conf/GENERIC: revision 1.741
sys/arch/amd64/conf/GENERIC: revision 1.91
sys/arch/i386/conf/INSTALL_SMALL: revision 1.125
sys/arch/amd64/conf/INSTALL: revision 1.50
sys/arch/i386/conf/INSTALL_TINY: revision 1.102
Added ciss(4). Tested by Joseph Dacuma on HP DL-380 G3 with Smart Array 5i.
 1.27.2.10 20-Apr-2006  snj Pull up following revision(s) (requested by tron in ticket #1266):
sys/arch/amd64/conf/GENERIC: revision 1.88
sys/arch/i386/conf/INSTALL: revision 1.282
sys/arch/amd64/conf/INSTALL: revision 1.48
sys/arch/i386/conf/XEN0: revision 1.35
sys/arch/i386/conf/GENERIC: revision 1.733
add nfe.
 1.27.2.9 28-Nov-2005  riz branches: 1.27.2.9.2;
Pull up following revision(s) (requested by tron in ticket #1013):
sys/arch/amd64/conf/INSTALL: revision 1.42
Compile with -fno-asynchronous-unwind-tables so that gcc doesn't generate
the .eh_frame data area that can be used to aid thr generation of stack
traceback - at a cost of a load of bloat!
Reinstate the isp driver.
Remove the unlikely-to-be-needed esh, lmc and ntwoc.
 1.27.2.8 28-Nov-2005  riz Pull up following revision(s) (requested by tron in ticket #1013):
sys/arch/amd64/conf/INSTALL: revision 1.41
We don't need 'le' here, I'm not sure amd64 GENERIC deserves it either.
 1.27.2.7 22-Nov-2005  riz Pull up following revision(s) (requested by tron in ticket #987):
sys/arch/amd64/conf/INSTALL: revision 1.33
Remove 'isp' driver (support for Qlogic ISP [12]0x0 SCSI/FibreChannel).
Compensates for the recent bloat of the ath driver and 802.11 support.
 1.27.2.6 21-Nov-2005  tron Pull up following revision(s) (requested by dsl in ticket #978):
sys/arch/amd64/conf/INSTALL: revision 1.40
Add sk ethernet as found on ASUS A8V.
Increase ramdisk to 5MB, costs virtually nothing.
 1.27.2.5 18-Jul-2005  riz Pull up revision 1.35 (requested by tron in ticket #566):
Add (commented out) IPSEC_NAT_T option.
 1.27.2.4 05-Jul-2005  tron Pull up revision 1.34 (requested by martti in ticket #546):
Added support for amr. Tested by Joseph A. Dacuma with Dell PowerEdge 2800.
 1.27.2.3 07-May-2005  riz Pull up revision 1.30 (requested by tron in ticket #131):
Comment out options for PPP compression and active filtering. They are not
necessary in an installation kernel but increase the size considerably.
This fixes PR port-amd64/29928.
 1.27.2.2 17-Apr-2005  tron Pull up revision 1.31 (requested by itohy in ticket #160):
Add ukyopon(4).
 1.27.2.1 09-Apr-2005  tron Pull up revision 1.29 (requested by dsl in ticket #129):
Comment out some wscons(4) options which are only required to run a
X11 server.
 1.27.2.13.2.1 27-May-2007  bouyer Pull up following revision(s) (requested by jnemeth in ticket #1778):
sys/arch/hpcarm/conf/IPAQ: revision 1.50
sys/arch/amd64/conf/GENERIC: revision 1.141
sys/arch/amd64/conf/INSTALL: revision 1.68
sys/arch/i386/conf/SWINGER: revision 1.90
PR/36234 - Joerg Niendorf -- xi -> xirc
 1.27.2.9.2.1 27-May-2007  bouyer Pull up following revision(s) (requested by jnemeth in ticket #1778):
sys/arch/hpcarm/conf/IPAQ: revision 1.50
sys/arch/amd64/conf/GENERIC: revision 1.141
sys/arch/amd64/conf/INSTALL: revision 1.68
sys/arch/i386/conf/SWINGER: revision 1.90
PR/36234 - Joerg Niendorf -- xi -> xirc
 1.34.2.7 21-Jan-2008  yamt sync with head
 1.34.2.6 07-Dec-2007  yamt sync with head
 1.34.2.5 27-Oct-2007  yamt sync with head.
 1.34.2.4 03-Sep-2007  yamt sync with head.
 1.34.2.3 26-Feb-2007  yamt sync with head.
 1.34.2.2 30-Dec-2006  yamt sync with head.
 1.34.2.1 21-Jun-2006  yamt sync with head.
 1.40.6.1 29-Nov-2005  yamt sync with head.
 1.44.2.2 18-Feb-2006  yamt sync with head.
 1.44.2.1 15-Jan-2006  yamt sync with head.
 1.45.4.2 01-Jun-2006  kardel Sync with head.
 1.45.4.1 22-Apr-2006  simonb Sync with head.
 1.45.2.1 09-Sep-2006  rpaulo sync with head
 1.47.4.2 11-May-2006  elad sync with head
 1.47.4.1 19-Apr-2006  elad sync with head - hopefully this will work
 1.47.2.6 14-Sep-2006  yamt sync with head.
 1.47.2.5 03-Sep-2006  yamt sync with head.
 1.47.2.4 11-Aug-2006  yamt sync with head
 1.47.2.3 24-May-2006  yamt sync with head.
 1.47.2.2 01-Apr-2006  yamt sync with head.
 1.47.2.1 13-Mar-2006  yamt sync with head.
 1.48.2.2 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.48.2.1 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.54.2.1 15-Sep-2006  tron Pull up following revision(s) (requested by riz in ticket #153):
sys/arch/amd64/conf/INSTALL: revision 1.56
sys/arch/amd64/conf/GENERIC: revision 1.107
sys/arch/i386/conf/XEN2_DOM0: revision 1.7
sys/arch/i386/conf/INSTALL: revision 1.289
sys/arch/i386/conf/GENERIC: revision 1.780
Add msk and mskc.
 1.55.2.4 09-Feb-2007  ad Sync with HEAD.
 1.55.2.3 01-Feb-2007  ad Sync with head.
 1.55.2.2 12-Jan-2007  ad Sync with head.
 1.55.2.1 18-Nov-2006  ad Sync with head.
 1.56.2.3 18-Dec-2006  yamt sync with head.
 1.56.2.2 10-Dec-2006  yamt sync with head.
 1.56.2.1 22-Oct-2006  yamt sync with head
 1.60.2.10 11-Jan-2008  xtraeme Pull up following revision(s) (requested by christos in ticket #1037):
sys/dev/pci/arcmsr.c: patch
sys/dev/pci/arcmsrvar.h: patch
sys/dev/pci/pcidevs: patch
sys/dev/pci/files.pci: patch
sys/arch/i386/conf/GENERIC: patch
sys/arch/i386/conf/XEN2_DOM0: patch
sys/arch/i386/conf/INSTALL_LARGE: patch
sys/arch/amd64/conf/GENERIC: patch
sys/arch/amd64/conf/INSTALL: patch
share/man/man4/Makefile: patch
share/man/man4/arcmsr.4: patch
distrib/sets/lists/man/mi: patch

Add the Areca Technology Corporation SATA RAID controller driver, ported
from OpenBSD.
 1.60.2.9 26-Nov-2007  xtraeme Pull up following revision(s) (requested by jnemeth in ticket #996):
sys/arch/amd64/conf/INSTALL: revision 1.74
PR/37404 - Rui-Xiang Guo -- sync phy list with GENERIC
 1.60.2.8 25-Nov-2007  xtraeme Pull up following revision(s) (requested by briggs in ticket #990):
sys/dev/ic/aac_tables.h: revision 1.5 (patch)
sys/dev/ic/aac.c: revision 1.31 (patch)
sys/dev/ic/aac.c: revision 1.32 (patch)
sys/dev/ic/aac.c: revision 1.33 (patch)
sys/dev/ic/aac.c: revision 1.34 (patch)
sys/arch/amd64/conf/INSTALL: revision 1.70 (patch)
sys/dev/ic/aac.c: revision 1.37 (patch)
sys/dev/ic/aacreg.h: revision 1.6 (patch)
sys/dev/ic/aacreg.h: revision 1.7 (patch)
sys/dev/ic/aacreg.h: revision 1.8 (patch)
sys/dev/ic/aacreg.h: revision 1.9 (patch)
sys/dev/pci/aac_pci.c: revision 1.21 (patch)
sys/dev/ic/aacvar.h: revision 1.10 (patch)
sys/dev/ic/aacvar.h: revision 1.9 (patch)
sys/arch/amd64/conf/GENERIC: revision 1.144 (patch)
sys/dev/ic/ld_aac.c: revision 1.14 (patch)
sys/dev/ic/ld_aac.c: revision 1.15 (patch)
Compile and run on amd64 and on >2GB RAM.
 1.60.2.7 31-Aug-2007  pavel Pull up following revision(s) (requested by bouyer in ticket #678):
distrib/sets/lists/man/mi: revision 1.1001
doc/CHANGES: revision 1.853 via patch
share/man/man4/Makefile: revision 1.428
share/man/man4/jmide.4: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.143
sys/arch/amd64/conf/INSTALL: revision 1.69
sys/arch/i386/conf/GENERIC: revision 1.827
sys/arch/i386/conf/INSTALL_LARGE: revision 1.2 via patch
sys/arch/i386/conf/XEN2_DOM0: revision 1.26
sys/conf/files: revision 1.844 via patch
sys/dev/ic/ahcisata_core.c: revision 1.1 via patch
sys/dev/ic/ahcisata_core.c: revision 1.3
sys/dev/ic/ahcisatareg.h: revision 1.1
sys/dev/ic/ahcisatavar.h: revision 1.1
sys/dev/pci/ahcisata.c: delete
sys/dev/pci/ahcisatareg.h: delete
sys/dev/pci/ahcisata_pci.c: revision 1.1
sys/dev/pci/files.pci: revision 1.287-1.288
sys/dev/pci/jmide.c: revision 1.1-1.2
sys/dev/pci/jmide_reg.h: revision 1.1
sys/dev/pci/pcidevs: revision 1.878
Add JMicron Technology vendor ID, and their current PCIe SATA/PATA
controllers.

Split the ahcisata driver in pci front-end and bus-independant back-end.
add jmide(4), a driver for the JMicron Technology JMB36x PCIe to SATA II/PATA
controllers. These controllers can be found on add-on PCIe cards, or
on some motherboards to provide the PATA connectivity (e.g. some intel
ICH8-based motherboards).
Thanks to JMicron Technology for providing me documentation and
different sample boards for this work.

Move mapping of AHCI register so that jmide knows if it fails, and avoids
calling ahci_intr() (which would cause a panic).
Try to use the pciide function for SATA drives if attaching ahci fails (this
doesn't seems to work though, it may be BIOS dependant).
Thanks to Gary Duzan for testing multiple pacthes.

We're not ready to handle ATAPI yet so just claim there's no drive to the
upper layer. This should work around a NULL pointer dereference when
an ATAPI device is detected on a AHCI device.
 1.60.2.6 12-May-2007  pavel branches: 1.60.2.6.2;
Pull up following revision(s) (requested by jnemeth in ticket #639):
sys/arch/hpcarm/conf/IPAQ: revision 1.50
sys/arch/amd64/conf/GENERIC: revision 1.141
sys/arch/amd64/conf/INSTALL: revision 1.68
sys/arch/i386/conf/SWINGER: revision 1.90
sys/arch/hpcarm/conf/JORNADA820: revision 1.8
PR/36234 - Joerg Niendorf -- xi -> xirc
 1.60.2.5 09-Mar-2007  riz Pull up following revision(s) (requested by bouyer in ticket #494):
sys/arch/i386/conf/GENERIC.MP: revision 1.9
distrib/pc532/cdroms/installcd/Makefile: revision 1.1
distrib/macppc/Makefile: revision 1.15
distrib/ofppc/Makefile: revision 1.2
distrib/ibmnws/Makefile: revision 1.2
distrib/acorn32/Makefile: revision 1.18
distrib/x68k/cdroms/installcd/Makefile: revision 1.1
distrib/sparc/Makefile: revision 1.7
distrib/sparc64/cdroms/Makefile: revision 1.1
distrib/hp300/cdroms/Makefile: revision 1.1
distrib/hpcsh/Makefile: revision 1.6
distrib/ofppc/cdroms/installcd/Makefile: revision 1.1
distrib/playstation2/Makefile: revision 1.13
distrib/news68k/cdroms/installcd/Makefile: revision 1.1
distrib/amiga/cdroms/installcd/Makefile: revision 1.1
distrib/hp700/cdroms/installcd/Makefile: revision 1.1
distrib/playstation2/cdroms/Makefile: revision 1.1
distrib/amiga/cdroms/Makefile: revision 1.1
etc/etc.mac68k/Makefile.inc: revision 1.18
distrib/shark/cdroms/installcd/Makefile: revision 1.1
distrib/hpcmips/Makefile: revision 1.28
distrib/hpcmips/cdroms/Makefile: revision 1.1
distrib/amd64/floppies/Makefile: revision 1.3
sys/arch/amd64/conf/INSTALL_ACPI: file removal
distrib/i386/cdroms/Makefile: revision 1.4
distrib/acorn26/cdroms/installcd/Makefile: revision 1.1
distrib/hpcsh/cdroms/Makefile: revision 1.1
distrib/prep/cdroms/Makefile: revision 1.1
distrib/pc532/Makefile: revision 1.4
distrib/acorn32/cdroms/installcd/Makefile: revision 1.1
distrib/sun2/Makefile: revision 1.8
distrib/vax/Makefile: revision 1.17
distrib/sparc64/cdroms/installcd/Makefile: revision 1.1
distrib/pmax/cdroms/Makefile: revision 1.1
distrib/mipsco/cdroms/installcd/Makefile: revision 1.1
distrib/sun3/cdroms/installcd/Makefile: revision 1.1
distrib/vax/cdroms/installcd/Makefile: revision 1.1
distrib/hpcarm/cdroms/installcd/Makefile: revision 1.1
distrib/mvme68k/Makefile: revision 1.4
distrib/mvmeppc/cdroms/Makefile: revision 1.1
distrib/newsmips/Makefile: revision 1.4
sys/arch/i386/conf/GENERIC.MPACPI: file removal
distrib/hpcarm/cdroms/Makefile: revision 1.1
distrib/evbppc/cdroms/Makefile: revision 1.1
sys/arch/i386/conf/INSTALL_LARGE: revision 1.1
distrib/i386/cdroms/installcd/Makefile: revision 1.2
distrib/i386/cdroms/installcd/Makefile: revision 1.3
doc/CHANGES: revision 1.804
distrib/hpcsh/cdroms/installcd/Makefile: revision 1.1
distrib/i386/cdroms/bootcd/Makefile: revision 1.2
distrib/mvmeppc/cdroms/installcd/Makefile: revision 1.1
distrib/i386/cdroms/bootcd/Makefile: revision 1.3
distrib/evbarm/Makefile: revision 1.8
distrib/mvmeppc/Makefile: revision 1.3
distrib/i386/cdroms/bootcd-com/Makefile: revision 1.2
distrib/i386/cdroms/bootcd-com/Makefile: revision 1.3
distrib/macppc/cdroms/installcd/Makefile: revision 1.1
distrib/acorn26/cdroms/Makefile: revision 1.1
distrib/alpha/cdroms/Makefile: revision 1.1
distrib/hp300/cdroms/installcd/Makefile: revision 1.1
distrib/amd64/floppies/bootfloppy/Makefile: revision 1.4
distrib/pmppc/cdroms/installcd/Makefile: revision 1.1
distrib/hp700/Makefile: revision 1.2
distrib/pmppc/Makefile: revision 1.2
distrib/arc/cdroms/Makefile: revision 1.1
sys/arch/amd64/conf/INSTALL: revision 1.66
distrib/sun3/cdroms/Makefile: revision 1.1
distrib/mipsco/Makefile: revision 1.4
distrib/sun3/Makefile: revision 1.9
distrib/vax/cdroms/Makefile: revision 1.1
distrib/pmppc/cdroms/Makefile: revision 1.1
distrib/amd64/cdroms/Makefile.cdrom: revision 1.1
distrib/atari/cdroms/installcd/Makefile: revision 1.1
distrib/evbppc/cdroms/installcd/Makefile: revision 1.1
distrib/newsmips/cdroms/installcd/Makefile: revision 1.1
distrib/pmax/Makefile: revision 1.4
Makefile: revision 1.247
distrib/cats/cdroms/installcd/Makefile: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.130
sys/arch/amd64/conf/GENERIC: revision 1.131
distrib/sgimips/cdroms/installcd/Makefile: revision 1.1
distrib/hp700/cdroms/Makefile: revision 1.1
distrib/cats/cdroms/Makefile: revision 1.1
distrib/evbmips/Makefile: revision 1.3
distrib/evbmips/Makefile: revision 1.4
sys/arch/amd64/conf/GENERIC_ACPI: file removal
distrib/ews4800mips/Makefile: revision 1.2
distrib/amd64/cdroms/bootcd-com/Makefile: revision 1.2
distrib/i386/Makefile: revision 1.5
distrib/amd64/cdroms/installcd/Makefile: revision 1.2
distrib/mvme68k/cdroms/installcd/Makefile: revision 1.1
distrib/alpha/cdroms/installcd/Makefile: revision 1.1
etc/etc.amd64/Makefile.inc: revision 1.7
distrib/i386/instkernel/Makefile: revision 1.6
distrib/x68k/cdroms/Makefile: revision 1.1
distrib/i386/cdroms/Makefile.cdrom: revision 1.1
distrib/sandpoint/Makefile: revision 1.4
distrib/i386/cdroms/Makefile.cdrom: revision 1.2
distrib/amiga/Makefile: revision 1.3
distrib/amd64/cdroms/bootcd/Makefile: revision 1.2
distrib/news68k/Makefile: revision 1.4
distrib/amd64/floppies/bootfloppy-com/Makefile: revision 1.5
distrib/news68k/cdroms/Makefile: revision 1.1
distrib/sparc/cdroms/Makefile: revision 1.1
distrib/shark/cdroms/Makefile: revision 1.1
etc/Makefile: revision 1.341
distrib/amd64/instkernel/Makefile: revision 1.2
distrib/sparc64/Makefile: revision 1.7
distrib/dreamcast/cdroms/Makefile: revision 1.1
distrib/shark/Makefile: revision 1.3
distrib/ews4800mips/cdroms/Makefile: revision 1.1
distrib/sun2/cdroms/installcd/Makefile: revision 1.1
distrib/shark/Makefile: revision 1.4
distrib/macppc/cdroms/Makefile: revision 1.1
distrib/mvme68k/cdroms/Makefile: revision 1.1
distrib/sun2/cdroms/Makefile: revision 1.1
distrib/hpcarm/Makefile: revision 1.3
distrib/arc/cdroms/installcd/Makefile: revision 1.1
distrib/hpcmips/cdroms/installcd/Makefile: revision 1.1
distrib/mipsco/cdroms/Makefile: revision 1.1
distrib/Makefile.inc: revision 1.9
distrib/playstation2/cdroms/installcd/Makefile: revision 1.1
distrib/ibmnws/cdroms/installcd/Makefile: revision 1.1
distrib/newsmips/cdroms/Makefile: revision 1.1
distrib/arc/Makefile: revision 1.3
distrib/sparc/cdroms/installcd/Makefile: revision 1.1
distrib/evbmips/cdroms/installcd/Makefile: revision 1.1
distrib/ews4800mips/cdroms/installcd/Makefile: revision 1.1
distrib/prep/Makefile: revision 1.3
distrib/ibmnws/cdroms/Makefile: revision 1.1
distrib/sandpoint/cdroms/Makefile: revision 1.1
distrib/atari/Makefile: revision 1.6
distrib/sgimips/cdroms/Makefile: revision 1.1
distrib/amd64/Makefile: revision 1.4
distrib/atari/cdroms/Makefile: revision 1.1
distrib/x68k/Makefile: revision 1.5
distrib/x68k/Makefile: revision 1.6
distrib/sandpoint/cdroms/installcd/Makefile: revision 1.1
distrib/evbarm/cdroms/Makefile: revision 1.1
distrib/acorn32/cdroms/Makefile: revision 1.1
distrib/cats/Makefile: revision 1.3
distrib/evbmips/cdroms/Makefile: revision 1.1
distrib/pc532/cdroms/Makefile: revision 1.1
distrib/Makefile: revision 1.14
distrib/evbarm/cdroms/installcd/Makefile: revision 1.1
distrib/ofppc/cdroms/Makefile: revision 1.1
distrib/amd64/cdroms/Makefile: revision 1.3
distrib/common/Makefile.bootcd: revision 1.8
distrib/i386/cdroms/bootcd-laptop/Makefile: file removal
sys/arch/i386/conf/GENERIC: revision 1.813
distrib/hp300/Makefile: revision 1.17
sys/arch/i386/conf/GENERIC: revision 1.814
distrib/evbppc/Makefile: revision 1.2
distrib/pmax/cdroms/installcd/Makefile: revision 1.1
etc/etc.i386/Makefile.inc: revision 1.49
distrib/sgimips/Makefile: revision 1.2
distrib/prep/cdroms/installcd/Makefile: revision 1.1
distrib/acorn26/Makefile: revision 1.4
distrib/dreamcast/cdroms/installcd/Makefile: revision 1.1
distrib/alpha/Makefile: revision 1.22
distrib/dreamcast/Makefile: revision 1.2
Improve the use of makefs to build boot CDs, and make it truely MI:
- allow to specify the "instkernel" directory, and allow to put multiple
kernels on the image
- allow to specify the directory where the image will be created
- only use bootxx_cd9660 if it exists
- search for second-stage boot as usr/mdec/boot.${MACHINE} in addition to
usr/mdec/boot
- make 'installboot -e' optional
- use target 'release' or 'iso_image' depending on ${CDRELEASE}
- call some MD targets, which will eventually complete the file list or
make the image bootable
For the benefit of modern hardware, enable ACPI by default in INSTALL and
GENERIC kernels. If ACPI is an issue on your hardware, 'boot -c' and
'disable acpi' should be a workaround. ACPI-enabled kernels works fine
on pre-acpi hardware.
for amd64:
- add ACPI to INSTALL and GENERIC, remove the *_ACPI config files.
- get rid of the bootfloppy-big.fs boot image, and got to a 3-floppy boot
image
for i386:
- introduce INSTALL_LARGE which has ACPI and some devices with big firmware
- move some devices from INSTALL to INSTALL_LARGE
- Boot floppies still use INSTALL, and bootfloppy-big.fs is still there
(for thoses who want to build el-torito floppy emulation boot CD) and use
INSTALL.
For both, drop the 'iso-image' code in etc/ to make the iso bootable, we'll
use something else to build bootable CDs.
Add an iso_image target (iso-image as a target name doesn't play well with
bsd.subdirs.mk) in distrib/makefile, which builds an iso image for $MACHINE
with binary sets, stored in ${RELEASEDIR}/iso. The image is bootable for:
alpha, amd64, cats, i386, pmax, sgimips, sparc, sparc64, sun3, vax.
mac68k/macppc no there yet because of missing feature in makefs.
call iso_image in distrib/ for iso-image in the top Makefile.
Use the new common/Makefile.bootcd to make i386 and amd64 bootable ISO
images. amd64 gets a single kernel; i386 images gets 3 kernels:
- netbsd, copy from netbsd-INSTALL_LARGE.gz, loaded by default
- nbsd-l, copy from netbsd-INSTALL_LAPTOP.gz
- nbsd-i, copy from netbsd-INSTALL.gz for those who want the traditionnal
non-ACPI kernel
- drop the bootcd-laptop image
both gets an installcd image, which is the same as bootcd but with the
binary sets in addition to kernels.
Make iso-image do nothing for all but mac68k, which still
relies on mkisofs to create bootable ISO image. macppc should also be there,
but it seems the code to make an iso bootable never got added in etc.macppc/
Fix typo in subdir name.
Revert local changes that went in accidentally with the "add ACPI" commit.
Note ACPI by default in i386/amd64, and the iso-image changes.
Fix SUBDIR in previous
Remove duplicate ACPIVERBOSE and ACPI_SCANPCI; pointed out by Nicolas Joly.
Correct typo: the directory is named cdroms, not cdrom.
Use nblaptop and nbnoacpi for the alternative kernel names; as suggected by
Alan Barrett. While there factor out the kernels in Makefile.cdrom.
 1.60.2.4 08-Feb-2007  bouyer Pull up following revision(s) (requested by tron in ticket #405):
distrib/amd64/ramdisks/ramdisk/list: revision 1.2
sys/arch/amd64/conf/INSTALL: revision 1.64 - 1.65
Uncomment pseudo-device raid and options RAID_AUTOCONFIG, to match
i386's INSTALL. Suggested by Florence HENRY on port-amd64@
Sync with i386: add sbin/raidctl to amd64's install ramdisk.
Disable wsmouse(4) and all the related low-level drivers The installer
ramdisk doesn't support using the mouse anyway.
Idea provided by Blair Sadewitz in private e-mail.
 1.60.2.3 04-Jan-2007  bouyer Pull up following revision(s) (requested by tron in ticket #331):
sys/arch/amd64/conf/INSTALL: revision 1.63
sys/arch/i386/conf/INSTALL_LAPTOP: revision 1.113
Disable ppp(4) because pppd(8) isn't on the installation image anyway.
 1.60.2.2 21-Dec-2006  tron Pull up following revision(s) (requested by bouyer in ticket #287):
sys/arch/i386/conf/INSTALL: revision 1.299
sys/arch/i386/conf/XEN2_DOM0: revision 1.20
sys/arch/i386/conf/GENERIC: revision 1.803
sys/dev/pci/files.pci: revision 1.275
sys/arch/i386/conf/GENERIC_LAPTOP: revision 1.218
sys/arch/amd64/conf/GENERIC: revision 1.123
sys/dev/pci/if_bnx.c: revision 1.1
share/man/man4/bnx.4: revision 1.1
distrib/sets/lists/man/mi: revision 1.959
sys/arch/amd64/conf/INSTALL: revision 1.62
sys/dev/microcode/bnx/bnxfw.h: revision 1.1
sys/arch/i386/conf/ALL: revision 1.76
sys/dev/pci/if_bnxreg.h: revision 1.1
share/man/man4/Makefile: revision 1.417
sys/arch/i386/conf/INSTALL_LAPTOP: revision 1.112
Add bnx(4), a driver for Broadcom NetXtreme II 10/100/1000 Ethernet device.
Ported from OpenBSD by cube@, with some bus_dma fixes by me.
Tested on i386 and amd64.
 1.60.2.1 21-Dec-2006  tron Pull up following revision(s) (requested by bouyer in ticket #286):
sys/arch/i386/conf/INSTALL: revision 1.298
sys/arch/i386/conf/GENERIC: revision 1.802
sys/dev/pci/files.pci: revision 1.274
sys/arch/amd64/conf/GENERIC: revision 1.122
sys/dev/pci/mfi_pci.c: revision 1.1
distrib/sets/lists/man/mi: revision 1.958
sys/arch/amd64/conf/INSTALL: revision 1.61
sys/arch/i386/conf/ALL: revision 1.75
sys/dev/ic/mfireg.h: revision 1.1
share/man/man4/Makefile: revision 1.416
sys/dev/ic/mfi.c: revision 1.1
sys/arch/i386/conf/XEN2_DOM0: revision 1.19
sys/dev/ic/mfivar.h: revision 1.1
sys/conf/files: revision 1.821
share/man/man4/mfi.4: revision 1.1
Add mfi(4), a driver for LSI Logic & Dell MegaRAID SAS RAID controller.
Ported from OpenBSD, tested on i386 and amd64.
 1.60.2.6.2.3 03-Jun-2008  skrll Sync with netbsd-4.
 1.60.2.6.2.2 06-Jan-2008  wrstuden Catch up to netbsd-4.0 release.
 1.60.2.6.2.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.65.2.3 17-May-2007  yamt sync with head.
 1.65.2.2 24-Mar-2007  yamt sync with head.
 1.65.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.66.4.1 11-Jul-2007  mjf Sync with head.
 1.66.2.5 03-Dec-2007  ad Sync with HEAD.
 1.66.2.4 09-Oct-2007  ad Sync with head.
 1.66.2.3 15-Jul-2007  ad Sync with head.
 1.66.2.2 27-May-2007  ad Sync with head.
 1.66.2.1 10-Apr-2007  ad Sync with head.
 1.67.6.3 03-Oct-2007  garbled Sync with HEAD
 1.67.6.2 26-Jun-2007  garbled Sync with HEAD.
 1.67.6.1 22-May-2007  matt Update to HEAD.
 1.71.10.2 09-Jan-2008  matt sync with HEAD
 1.71.10.1 06-Nov-2007  matt sync with HEAD
 1.71.8.3 09-Dec-2007  jmcneill Sync with HEAD.
 1.71.8.2 21-Nov-2007  joerg Sync with HEAD.
 1.71.8.1 02-Oct-2007  joerg Sync with HEAD.
 1.71.4.1 10-Sep-2007  skrll Sync with HEAD.
 1.72.4.1 21-Nov-2007  bouyer Sync with HEAD
 1.73.2.3 18-Feb-2008  mjf Sync with HEAD.
 1.73.2.2 27-Dec-2007  mjf Sync with HEAD.
 1.73.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.74.2.1 08-Dec-2007  ad Sync with head.
 1.76.4.1 02-Jan-2008  bouyer Sync with HEAD
 1.78.8.1 18-May-2008  yamt sync with head.
 1.78.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.79.2.3 19-Aug-2009  yamt sync with head.
 1.79.2.2 04-May-2009  yamt sync with head.
 1.79.2.1 16-May-2008  yamt sync with head.
 1.80.8.1 03-Mar-2009  skrll Sync with HEAD.
 1.81.2.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.81.2.3 29-Mar-2011  jym More sync fixes. And add the mbr_gpt files.
 1.81.2.2 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.81.2.1 01-Nov-2009  jym Sync with HEAD.
 1.82.8.1 17-Feb-2011  bouyer Sync with HEAD
 1.82.6.1 06-Jun-2011  jruoho Sync with HEAD.
 1.82.4.2 31-May-2011  rmind sync with head
 1.82.4.1 05-Mar-2011  rmind sync with head
 1.87.2.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.87.2.1 17-Apr-2012  yamt sync with head
 1.88.8.2 03-Dec-2017  jdolecek update from HEAD
 1.88.8.1 23-Jun-2013  tls resync from head
 1.89.8.2 18-Mar-2015  snj Apply patch (requested by christos in ticket #542):
- Enable intel and radeon DRM/KMS drivers in GENERIC
- Disable all of the old DRM drivers in GENERIC
- Remove the separate DRMKMS kernel
 1.89.8.1 23-Jan-2015  martin Remove "no i915drm*" now that the declaration is gone from GENERIC.
Requested by snj in ticket #438.
 1.90.4.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.90.2.1 05-Feb-2017  skrll Sync with HEAD
 1.91.8.1 07-Jan-2018  snj Pull up following revision(s) (requested by rin in ticket #467):
sys/arch/amd64/conf/INSTALL: 1.92
sys/arch/i386/conf/INSTALL: 1.332-1.333
install/52845: Enable vga@isa and pcdisplay for INSTALL. Otherwise, install
media do not boot on pre-PCI machines.
--
Disable nouveau for INSTALL as in a similar manner to other DRMKMS drivers.
--
 1.92.4.1 10-Jun-2019  christos Sync with HEAD
 1.32 06-Mar-2007  bouyer For the benefit of modern hardware, enable ACPI by default in INSTALL and
GENERIC kernels. If ACPI is an issue on your hardware, 'boot -c' and
'disable acpi' should be a workaround. ACPI-enabled kernels works fine
on pre-acpi hardware.
for amd64:
- add ACPI to INSTALL and GENERIC, remove the *_ACPI config files.
- get rid of the bootfloppy-big.fs boot image, and got to a 3-floppy boot
image
for i386:
- introduce INSTALL_LARGE which has ACPI and some devices with big firmware
- move some devices from INSTALL to INSTALL_LARGE
- Boot floppies still use INSTALL, and bootfloppy-big.fs is still there
(for thoses who want to build el-torito floppy emulation boot CD) and use
INSTALL.
For both, drop the 'iso-image' code in etc/ to make the iso bootable, we'll
use something else to build bootable CDs.
 1.31 04-Jul-2006  christos branches: 1.31.8; 1.31.10;
Apply fvdl's acpi pci interrupt configuration code.
- MPACPI is no more.
- MPACPI_SCANPCI -> ACPI_SCANPCI
 1.30 11-Dec-2005  christos branches: 1.30.4; 1.30.8; 1.30.16;
merge ktrace-lwp.
 1.29 10-Oct-2005  dsl include "INSTALL" then modify it - so we get the same device
 1.28 09-Sep-2005  drochner remove "dev" locators from cardbus device definitions, it doesn't
make sense technically and might be removed
 1.27 19-Aug-2005  christos Enable ptyfs by default on the non-install and non small/tiny/ramdisk kernels
 1.26 05-Aug-2005  skrll Add (commented out) ucycom to various kernel configs.
 1.25 12-Jul-2005  sekiya Add config goo for ath. Tested with a PCI card, detected as:

ath0 at pci0 dev 10 function 0
ath0: interrupting at ioapic0 pin 17 (irq 5)
ath0: 11a rates: 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps
ath0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
ath0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36M bps 48Mbps 54Mbps
ath0: mac 5.9 phy 4.3 radio 3.6

Cardbus untested, so it is commented out.
 1.24 07-Jul-2005  tron Add (commented out) IPSEC_NAT_T option.
 1.23 09-Jun-2005  tsutsui branches: 1.23.2;
- Rename options NEW_BUFQ_STRATEGY -> options BUFQ_READPRIO.
(still commented out)
- Add (also commented out) options BUFQ_PRIOCSCAN.

Suggested by perry and soda on tech-kern.
Please refer options(4) for details for these options.
 1.22 15-Apr-2005  itohy Add ukyopon(4).
 1.21 10-Apr-2005  tron Comment out options for PPP compression and active filtering. They are not
necessary in an installation kernel but increase the size considerably.
This fixes PR port-amd64/29928.
 1.20 09-Apr-2005  tron Comment out some wscons(4) options which are only required to run a
X11 server.
 1.19 25-Mar-2005  cube Add attimer(4) configurations everywhere pcppi(4) exists, with the
following rule:
If a pcppi device is enabled for an attachment, enable an attimer for the
same attachement, otherwise comment it.
 1.18 18-Feb-2005  dsl branches: 1.18.4;
Invert FFS_SNAPSHOT to FFS_NO_SNAPSHOT
 1.17 11-Feb-2005  dsl Add 'option FFS_SNAPSHOT' to most of the config files.
Commented out for kernels that appear to hace space constraints.
 1.16 31-Jan-2005  hannken Add file system snapshots to kernel configs.

- Ffs internal snapshots get compiled in unconditionally.

- File system snapshot device fss(4) added to all kernel configs that
have a disk. Device is commented out on all non-GENERIC kernels.

Reviewed by: Jason Thorpe <thorpej@netbsd.org>
 1.15 18-Jan-2005  scw branches: 1.15.2;
Add "options PMS_SYNAPTICS_TOUCHPAD", commented out by default.
 1.14 17-Jan-2005  cube Add tap(4) support to a random^Wcarefully chosen set of kernel configs.
All those kernels have a line for both tun and bridge, and if either is
commented out, tap is commented out also. With the exception of i386's
GENERIC_TINY.

XXX: we _need_ some way of making this more simple.
 1.13 24-Nov-2004  bouyer branches: 1.13.4;
pdcsata(4), a driver for the Promise SATA150 (aka PDC203xx) serie of
controllers. Tested with a PDC20375 (2 SATA, one PATA) controller on sparc64.
Added to all kernel config file which had pdcide(4).
 1.12 10-Nov-2004  christos Add COMPAT_BSDPTY to the rest of the config files.
 1.11 23-Oct-2004  augustss s/uax/axe/
 1.10 13-Sep-2004  fvdl Remove some devices (sync with i386).
 1.9 04-Sep-2004  manu IPv4 PIM support, based on a submission from Pavlin Radoslavov posted on
tech-net@
 1.8 16-Feb-2004  thorpej branches: 1.8.2;
Comment out some SYSV* and *VERBOSE options to shrink these down so
they fit in the current boot floppies.
 1.7 14-Dec-2003  thorpej Split the Intel i31244 SATA controller ("Artisea") driver out of piixide
into its own driver (artsata).
 1.6 13-Dec-2003  thorpej Split out the Silicon Image SATALink support into its own driver,
"satalink".
 1.5 18-Oct-2003  lukem Use one 'atabus* at ata?' instead of multiple 'atabus* at FOOide? channel ?'
Use 'atapibus* at atapi?' instead of 'atapibus* at atabus?'
 1.4 08-Oct-2003  bouyer Add new per-chip pciide drivers.
 1.3 08-Oct-2003  bouyer Add atabus.
 1.2 06-Sep-2003  itojun add rnd(4) device to installation media.
necessary for many purposes, including password seeding, tcp sequence number,
and more. see tech-security
 1.1 15-May-2003  fvdl branches: 1.1.2;
Decrease the ramdisk size a bit to allow for more options to be added
to the kernel, and still have it fit in 2.88M.
 1.1.2.12 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.2.11 01-Apr-2005  skrll Sync with HEAD.
 1.1.2.10 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.2.9 15-Feb-2005  skrll Sync with HEAD.
 1.1.2.8 04-Feb-2005  skrll Sync with HEAD.
 1.1.2.7 24-Jan-2005  skrll Sync with HEAD.
 1.1.2.6 29-Nov-2004  skrll Sync with HEAD.
 1.1.2.5 14-Nov-2004  skrll Sync with HEAD.
 1.1.2.4 02-Nov-2004  skrll Sync with HEAD.
 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.8.2.1 14-Sep-2004  jmc branches: 1.8.2.1.2;
Pullup rev 1.10 (requested by fvdl in ticket #845)

Remove some devices (sync with i386).
 1.8.2.1.2.2 21-Jul-2005  riz Pull up revision 1.22 (requested by itohy in ticket #1430):
Add ukyopon(4).
 1.8.2.1.2.1 02-Apr-2005  he Pull up revision 1.13 (requested by bouyer in ticket #1019):
Add pdcsata(4), a driver for the Promise SATA150 (aka PDC203xx) series of
controllers.
 1.13.4.1 29-Apr-2005  kent sync with -current
 1.15.2.3 26-Mar-2005  yamt sync with head.
 1.15.2.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.15.2.1 12-Feb-2005  yamt sync with head.
 1.18.4.5 21-Nov-2005  tron Pull up following revision(s) (requested by dsl in ticket #977):
sys/arch/amd64/conf/INSTALL_ACPI: revision 1.29 via patch
include "INSTALL" then modify it - so we get the same device
 1.18.4.4 18-Jul-2005  riz Pull up revision 1.24 (requested by tron in ticket #566):
Add (commented out) IPSEC_NAT_T option.
 1.18.4.3 07-May-2005  riz Pull up revision 1.21 (requested by tron in ticket #131):
Comment out options for PPP compression and active filtering. They are not
necessary in an installation kernel but increase the size considerably.
This fixes PR port-amd64/29928.
 1.18.4.2 17-Apr-2005  tron Pull up revision 1.22 (requested by itohy in ticket #160):
Add ukyopon(4).
 1.18.4.1 09-Apr-2005  tron Pull up revision 1.20 (requested by dsl in ticket #129):
Comment out some wscons(4) options which are only required to run a
X11 server.
 1.23.2.3 03-Sep-2007  yamt sync with head.
 1.23.2.2 30-Dec-2006  yamt sync with head.
 1.23.2.1 21-Jun-2006  yamt sync with head.
 1.30.16.1 13-Jul-2006  gdamore Merge from HEAD.
 1.30.8.1 11-Aug-2006  yamt sync with head
 1.30.4.1 09-Sep-2006  rpaulo sync with head
 1.31.10.2 17-May-2007  yamt fix merge botches.
 1.31.10.1 12-Mar-2007  rmind Sync with HEAD.
 1.31.8.1 09-Mar-2007  riz Pull up following revision(s) (requested by bouyer in ticket #494):
sys/arch/i386/conf/GENERIC.MP: revision 1.9
distrib/pc532/cdroms/installcd/Makefile: revision 1.1
distrib/macppc/Makefile: revision 1.15
distrib/ofppc/Makefile: revision 1.2
distrib/ibmnws/Makefile: revision 1.2
distrib/acorn32/Makefile: revision 1.18
distrib/x68k/cdroms/installcd/Makefile: revision 1.1
distrib/sparc/Makefile: revision 1.7
distrib/sparc64/cdroms/Makefile: revision 1.1
distrib/hp300/cdroms/Makefile: revision 1.1
distrib/hpcsh/Makefile: revision 1.6
distrib/ofppc/cdroms/installcd/Makefile: revision 1.1
distrib/playstation2/Makefile: revision 1.13
distrib/news68k/cdroms/installcd/Makefile: revision 1.1
distrib/amiga/cdroms/installcd/Makefile: revision 1.1
distrib/hp700/cdroms/installcd/Makefile: revision 1.1
distrib/playstation2/cdroms/Makefile: revision 1.1
distrib/amiga/cdroms/Makefile: revision 1.1
etc/etc.mac68k/Makefile.inc: revision 1.18
distrib/shark/cdroms/installcd/Makefile: revision 1.1
distrib/hpcmips/Makefile: revision 1.28
distrib/hpcmips/cdroms/Makefile: revision 1.1
distrib/amd64/floppies/Makefile: revision 1.3
sys/arch/amd64/conf/INSTALL_ACPI: file removal
distrib/i386/cdroms/Makefile: revision 1.4
distrib/acorn26/cdroms/installcd/Makefile: revision 1.1
distrib/hpcsh/cdroms/Makefile: revision 1.1
distrib/prep/cdroms/Makefile: revision 1.1
distrib/pc532/Makefile: revision 1.4
distrib/acorn32/cdroms/installcd/Makefile: revision 1.1
distrib/sun2/Makefile: revision 1.8
distrib/vax/Makefile: revision 1.17
distrib/sparc64/cdroms/installcd/Makefile: revision 1.1
distrib/pmax/cdroms/Makefile: revision 1.1
distrib/mipsco/cdroms/installcd/Makefile: revision 1.1
distrib/sun3/cdroms/installcd/Makefile: revision 1.1
distrib/vax/cdroms/installcd/Makefile: revision 1.1
distrib/hpcarm/cdroms/installcd/Makefile: revision 1.1
distrib/mvme68k/Makefile: revision 1.4
distrib/mvmeppc/cdroms/Makefile: revision 1.1
distrib/newsmips/Makefile: revision 1.4
sys/arch/i386/conf/GENERIC.MPACPI: file removal
distrib/hpcarm/cdroms/Makefile: revision 1.1
distrib/evbppc/cdroms/Makefile: revision 1.1
sys/arch/i386/conf/INSTALL_LARGE: revision 1.1
distrib/i386/cdroms/installcd/Makefile: revision 1.2
distrib/i386/cdroms/installcd/Makefile: revision 1.3
doc/CHANGES: revision 1.804
distrib/hpcsh/cdroms/installcd/Makefile: revision 1.1
distrib/i386/cdroms/bootcd/Makefile: revision 1.2
distrib/mvmeppc/cdroms/installcd/Makefile: revision 1.1
distrib/i386/cdroms/bootcd/Makefile: revision 1.3
distrib/evbarm/Makefile: revision 1.8
distrib/mvmeppc/Makefile: revision 1.3
distrib/i386/cdroms/bootcd-com/Makefile: revision 1.2
distrib/i386/cdroms/bootcd-com/Makefile: revision 1.3
distrib/macppc/cdroms/installcd/Makefile: revision 1.1
distrib/acorn26/cdroms/Makefile: revision 1.1
distrib/alpha/cdroms/Makefile: revision 1.1
distrib/hp300/cdroms/installcd/Makefile: revision 1.1
distrib/amd64/floppies/bootfloppy/Makefile: revision 1.4
distrib/pmppc/cdroms/installcd/Makefile: revision 1.1
distrib/hp700/Makefile: revision 1.2
distrib/pmppc/Makefile: revision 1.2
distrib/arc/cdroms/Makefile: revision 1.1
sys/arch/amd64/conf/INSTALL: revision 1.66
distrib/sun3/cdroms/Makefile: revision 1.1
distrib/mipsco/Makefile: revision 1.4
distrib/sun3/Makefile: revision 1.9
distrib/vax/cdroms/Makefile: revision 1.1
distrib/pmppc/cdroms/Makefile: revision 1.1
distrib/amd64/cdroms/Makefile.cdrom: revision 1.1
distrib/atari/cdroms/installcd/Makefile: revision 1.1
distrib/evbppc/cdroms/installcd/Makefile: revision 1.1
distrib/newsmips/cdroms/installcd/Makefile: revision 1.1
distrib/pmax/Makefile: revision 1.4
Makefile: revision 1.247
distrib/cats/cdroms/installcd/Makefile: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.130
sys/arch/amd64/conf/GENERIC: revision 1.131
distrib/sgimips/cdroms/installcd/Makefile: revision 1.1
distrib/hp700/cdroms/Makefile: revision 1.1
distrib/cats/cdroms/Makefile: revision 1.1
distrib/evbmips/Makefile: revision 1.3
distrib/evbmips/Makefile: revision 1.4
sys/arch/amd64/conf/GENERIC_ACPI: file removal
distrib/ews4800mips/Makefile: revision 1.2
distrib/amd64/cdroms/bootcd-com/Makefile: revision 1.2
distrib/i386/Makefile: revision 1.5
distrib/amd64/cdroms/installcd/Makefile: revision 1.2
distrib/mvme68k/cdroms/installcd/Makefile: revision 1.1
distrib/alpha/cdroms/installcd/Makefile: revision 1.1
etc/etc.amd64/Makefile.inc: revision 1.7
distrib/i386/instkernel/Makefile: revision 1.6
distrib/x68k/cdroms/Makefile: revision 1.1
distrib/i386/cdroms/Makefile.cdrom: revision 1.1
distrib/sandpoint/Makefile: revision 1.4
distrib/i386/cdroms/Makefile.cdrom: revision 1.2
distrib/amiga/Makefile: revision 1.3
distrib/amd64/cdroms/bootcd/Makefile: revision 1.2
distrib/news68k/Makefile: revision 1.4
distrib/amd64/floppies/bootfloppy-com/Makefile: revision 1.5
distrib/news68k/cdroms/Makefile: revision 1.1
distrib/sparc/cdroms/Makefile: revision 1.1
distrib/shark/cdroms/Makefile: revision 1.1
etc/Makefile: revision 1.341
distrib/amd64/instkernel/Makefile: revision 1.2
distrib/sparc64/Makefile: revision 1.7
distrib/dreamcast/cdroms/Makefile: revision 1.1
distrib/shark/Makefile: revision 1.3
distrib/ews4800mips/cdroms/Makefile: revision 1.1
distrib/sun2/cdroms/installcd/Makefile: revision 1.1
distrib/shark/Makefile: revision 1.4
distrib/macppc/cdroms/Makefile: revision 1.1
distrib/mvme68k/cdroms/Makefile: revision 1.1
distrib/sun2/cdroms/Makefile: revision 1.1
distrib/hpcarm/Makefile: revision 1.3
distrib/arc/cdroms/installcd/Makefile: revision 1.1
distrib/hpcmips/cdroms/installcd/Makefile: revision 1.1
distrib/mipsco/cdroms/Makefile: revision 1.1
distrib/Makefile.inc: revision 1.9
distrib/playstation2/cdroms/installcd/Makefile: revision 1.1
distrib/ibmnws/cdroms/installcd/Makefile: revision 1.1
distrib/newsmips/cdroms/Makefile: revision 1.1
distrib/arc/Makefile: revision 1.3
distrib/sparc/cdroms/installcd/Makefile: revision 1.1
distrib/evbmips/cdroms/installcd/Makefile: revision 1.1
distrib/ews4800mips/cdroms/installcd/Makefile: revision 1.1
distrib/prep/Makefile: revision 1.3
distrib/ibmnws/cdroms/Makefile: revision 1.1
distrib/sandpoint/cdroms/Makefile: revision 1.1
distrib/atari/Makefile: revision 1.6
distrib/sgimips/cdroms/Makefile: revision 1.1
distrib/amd64/Makefile: revision 1.4
distrib/atari/cdroms/Makefile: revision 1.1
distrib/x68k/Makefile: revision 1.5
distrib/x68k/Makefile: revision 1.6
distrib/sandpoint/cdroms/installcd/Makefile: revision 1.1
distrib/evbarm/cdroms/Makefile: revision 1.1
distrib/acorn32/cdroms/Makefile: revision 1.1
distrib/cats/Makefile: revision 1.3
distrib/evbmips/cdroms/Makefile: revision 1.1
distrib/pc532/cdroms/Makefile: revision 1.1
distrib/Makefile: revision 1.14
distrib/evbarm/cdroms/installcd/Makefile: revision 1.1
distrib/ofppc/cdroms/Makefile: revision 1.1
distrib/amd64/cdroms/Makefile: revision 1.3
distrib/common/Makefile.bootcd: revision 1.8
distrib/i386/cdroms/bootcd-laptop/Makefile: file removal
sys/arch/i386/conf/GENERIC: revision 1.813
distrib/hp300/Makefile: revision 1.17
sys/arch/i386/conf/GENERIC: revision 1.814
distrib/evbppc/Makefile: revision 1.2
distrib/pmax/cdroms/installcd/Makefile: revision 1.1
etc/etc.i386/Makefile.inc: revision 1.49
distrib/sgimips/Makefile: revision 1.2
distrib/prep/cdroms/installcd/Makefile: revision 1.1
distrib/acorn26/Makefile: revision 1.4
distrib/dreamcast/cdroms/installcd/Makefile: revision 1.1
distrib/alpha/Makefile: revision 1.22
distrib/dreamcast/Makefile: revision 1.2
Improve the use of makefs to build boot CDs, and make it truely MI:
- allow to specify the "instkernel" directory, and allow to put multiple
kernels on the image
- allow to specify the directory where the image will be created
- only use bootxx_cd9660 if it exists
- search for second-stage boot as usr/mdec/boot.${MACHINE} in addition to
usr/mdec/boot
- make 'installboot -e' optional
- use target 'release' or 'iso_image' depending on ${CDRELEASE}
- call some MD targets, which will eventually complete the file list or
make the image bootable
For the benefit of modern hardware, enable ACPI by default in INSTALL and
GENERIC kernels. If ACPI is an issue on your hardware, 'boot -c' and
'disable acpi' should be a workaround. ACPI-enabled kernels works fine
on pre-acpi hardware.
for amd64:
- add ACPI to INSTALL and GENERIC, remove the *_ACPI config files.
- get rid of the bootfloppy-big.fs boot image, and got to a 3-floppy boot
image
for i386:
- introduce INSTALL_LARGE which has ACPI and some devices with big firmware
- move some devices from INSTALL to INSTALL_LARGE
- Boot floppies still use INSTALL, and bootfloppy-big.fs is still there
(for thoses who want to build el-torito floppy emulation boot CD) and use
INSTALL.
For both, drop the 'iso-image' code in etc/ to make the iso bootable, we'll
use something else to build bootable CDs.
Add an iso_image target (iso-image as a target name doesn't play well with
bsd.subdirs.mk) in distrib/makefile, which builds an iso image for $MACHINE
with binary sets, stored in ${RELEASEDIR}/iso. The image is bootable for:
alpha, amd64, cats, i386, pmax, sgimips, sparc, sparc64, sun3, vax.
mac68k/macppc no there yet because of missing feature in makefs.
call iso_image in distrib/ for iso-image in the top Makefile.
Use the new common/Makefile.bootcd to make i386 and amd64 bootable ISO
images. amd64 gets a single kernel; i386 images gets 3 kernels:
- netbsd, copy from netbsd-INSTALL_LARGE.gz, loaded by default
- nbsd-l, copy from netbsd-INSTALL_LAPTOP.gz
- nbsd-i, copy from netbsd-INSTALL.gz for those who want the traditionnal
non-ACPI kernel
- drop the bootcd-laptop image
both gets an installcd image, which is the same as bootcd but with the
binary sets in addition to kernels.
Make iso-image do nothing for all but mac68k, which still
relies on mkisofs to create bootable ISO image. macppc should also be there,
but it seems the code to make an iso bootable never got added in etc.macppc/
Fix typo in subdir name.
Revert local changes that went in accidentally with the "add ACPI" commit.
Note ACPI by default in i386/amd64, and the iso-image changes.
Fix SUBDIR in previous
Remove duplicate ACPIVERBOSE and ACPI_SCANPCI; pointed out by Nicolas Joly.
Correct typo: the directory is named cdroms, not cdrom.
Use nblaptop and nbnoacpi for the alternative kernel names; as suggected by
Alan Barrett. While there factor out the kernels in Makefile.cdrom.
 1.7 28-May-2011  ryo many whitespace cleanup.
 1.6 06-Feb-2009  jym branches: 1.6.2; 1.6.6; 1.6.8;
Changes to MEMORY_RBFLAGS option:
- renamed to MEMORY_DISK_RBFLAGS to better fit the rest of the
MEMORY_DISK options(4)
- change default value to RB_AUTOBOOT instead of RB_SINGLE, and adapt
the config(5) files accordingly
- document this option inside options(4)

See also http://mail-index.netbsd.org/tech-kern/2008/12/25/msg003924.html

Reviewed by abs@ in private mail.
 1.5 01-Mar-2008  joerg branches: 1.5.4; 1.5.12;
Derive Xen3 domu install kernel from XEN3_DOMU.
 1.4 16-Jan-2008  ad branches: 1.4.2; 1.4.6;
Remove options MATH_EMULATE.
 1.3 07-Jan-2008  martti branches: 1.3.2;
Fixed option indentation, it should be

option<space><tab>
makeoption<space><tab>
 1.2 22-Nov-2007  bouyer branches: 1.2.2; 1.2.4; 1.2.8; 1.2.12;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.1 17-Oct-2007  bouyer branches: 1.1.2; 1.1.4;
file INSTALL_XEN3_DOMU was initially added on branch bouyer-xenamd64.
 1.1.4.2 18-Feb-2008  mjf Sync with HEAD.
 1.1.4.1 08-Dec-2007  mjf Sync with HEAD.
 1.1.2.2 19-Nov-2007  bouyer Get rid of arch/xenamd64, step 1: empty xenamd64/conf
- move xenamd64/conf/std.xen to amd64/conf/
- define arch to amd64 amd64/conf/std.xen, and i386 in xen/conf/std.xen
(machine is xen)
- enclose content of amd64/conf/files.amd64 and i386/conf/files.i386 in
ifndef xen/endif, so it can be transparently inclued for xen kernels
- support MACHINE_ARCH=x86_64 in xen/conf/Makefile*
 1.1.2.1 17-Oct-2007  bouyer amd64 (aka x86-64) support for Xen. Based on the OpenBSD port done by
Mathieu Ropert in 2006.
DomU-only for now. An INSTALL_XEN3_DOMU kernel with a ramdisk will boot to
sysinst if you're lucky. Often it panics because a runable LWP has
a NULL stack (really, it's all of l->l_addr which is has been zeroed out
while the process was on the queue !)
TODO:
- bug fixes :)
- Most of the xpq_* functions should be shared with xen/i386
- The xen/i386 assembly bootstrap code should be remplaced with the C
version in xenamd64/amd64/xpmap.c
- see if a config(5) trick could allow to merge xenamd64 back to xen or amd64.
 1.2.12.2 19-Jan-2008  bouyer Sync with HEAD
 1.2.12.1 08-Jan-2008  bouyer Sync with HEAD
 1.2.8.4 17-Mar-2008  yamt sync with head.
 1.2.8.3 21-Jan-2008  yamt sync with head
 1.2.8.2 07-Dec-2007  yamt sync with head
 1.2.8.1 22-Nov-2007  yamt file INSTALL_XEN3_DOMU was added on branch yamt-lazymbuf on 2007-12-07 17:24:00 +0000
 1.2.4.2 03-Dec-2007  ad Sync with HEAD.
 1.2.4.1 22-Nov-2007  ad file INSTALL_XEN3_DOMU was added on branch vmlocking on 2007-12-03 19:02:42 +0000
 1.2.2.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.2.2.1 22-Nov-2007  joerg file INSTALL_XEN3_DOMU was added on branch jmcneill-pm on 2007-11-27 19:35:29 +0000
 1.3.2.3 23-Mar-2008  matt sync with HEAD
 1.3.2.2 09-Jan-2008  matt sync with HEAD
 1.3.2.1 07-Jan-2008  matt file INSTALL_XEN3_DOMU was added on branch matt-armv6 on 2008-01-09 01:44:49 +0000
 1.4.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.4.2.1 24-Mar-2008  keiichi sync with head.
 1.5.12.1 03-Mar-2009  skrll Sync with HEAD.
 1.5.4.1 04-May-2009  yamt sync with head.
 1.6.8.1 06-Jun-2011  jruoho Sync with HEAD.
 1.6.6.1 31-May-2011  rmind sync with head
 1.6.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.4 23-Aug-2025  imil Add `+invtsc` to the QEMU command line example, this enables the
invariant TSC feature, allowing the kernel to use CPUID 0x40000010 to
read TSC and LAPIC frequencies from the host, thus avoiding the need
for frequency calculation and gaining over 200ms in boot speed.
 1.3 28-Mar-2025  imil branches: 1.3.2; 1.3.4;
x86: consolidate MICROVM kernel configurations

Move common configuration options from amd64/conf/MICROVM and
i386/conf/MICROVM into a shared x86/conf/MICROVM.common file.
 1.2 27-Mar-2025  riastradh virtio(4): Consolidate kernel configs.

No functional change intended.

Leave `# XXX ?' comments where I don't know why the driver in
question is excluded. (Typical reason is that PAGE_SIZE is not 4096
but I didn't investigate -- if you do investigate, please either
update the comment if you determine a reason, or enable the driver if
you don't.)

PR kern/59211: vio9p(4): missing from various GENERICs and MAKEDEVs
 1.1 15-Jan-2025  imil Add support for command line MMIO devices, at least qemu and
Firecracker pass MMIO virtual devices mapping through the kernel
command line.
This driver is based on Colin Percival's FreeBSD virtio_mmio_cmdline.c
https://github.com/freebsd/freebsd-src/blob/main/sys/dev/virtio/mmio/virtio_mmio_cmdline.c

The following kernel options are needed

options MPBIOS
options MPTABLE_LINUX_BUG_COMPAT

As are these drivers

pv* at pvbus?
virtio* at pv?

Exemple qemu usage on a Linux host to boot a NetBSD guest:

qemu-system-x86_64 \
-M microvm,x-option-roms=off,rtc=on,acpi=off,pic=off,accel=kvm \
-m 256 -cpu host -kernel ${KERNEL} \
-append "root=ld0a console=com rw -v" \
-device virtio-blk-device,drive=hd0 \
-drive file=${IMG},format=raw,id=hd0 \
-device virtio-net-device,netdev=net0 \
-netdev user,id=net0,ipv6=off,hostfwd=::2200-:22 \
-global virtio-mmio.force-legacy=false -display none -serial stdio

A lightweight kernel configuration named MICROVM if available for this
use case.
 1.3.4.2 02-Aug-2025  perseant Sync with HEAD
 1.3.4.1 28-Mar-2025  perseant file MICROVM was added on branch perseant-exfatfs on 2025-08-02 05:55:24 +0000
 1.3.2.1 25-Aug-2025  martin Pull up following revision(s) (requested by imil in ticket #14):

sys/arch/amd64/conf/MICROVM: revision 1.4
sys/arch/i386/conf/MICROVM: revision 1.4

Add `+invtsc` to the QEMU command line example, this enables the
invariant TSC feature, allowing the kernel to use CPUID 0x40000010 to
read TSC and LAPIC frequencies from the host, thus avoiding the need
for frequency calculation and gaining over 200ms in boot speed.
 1.20 20-Mar-2025  pgoyette We now have COMPAT_100, so use the modular version vs built-in
 1.19 20-Jan-2021  nia branches: 1.19.24;
remove compat_ossaudio from kernel modules

this is only useful with compat_linux and gets autoloaded when
compat_linux is loaded, so there's no reason to bake it into kernels
any more.
 1.18 19-Oct-2020  christos branches: 1.18.2;
Arrange so that no options COREDUMP and no options PTRACE work together.
Thanks to Paul Goyette for testing.
 1.17 27-Sep-2020  roy vether: Add to kernel configurations

It's only enabled if the kernel enabled bridge AND tap.
Otherwise it's commented out.
 1.16 16-Aug-2020  jdolecek make COMPAT_LINUX option disabled by default

leave the option enabled only in amd64/i386 ALL kernels to make
sure it continues to be compilable also when included in kernel
 1.15 25-Mar-2020  jdolecek remove 'file-system SMBFS' and 'pseudo-device nsmb' from all kernel configs
to prepare for their eventual removal
 1.14 19-Jan-2020  thorpej Remove the strip(4) - Starmode Radio IP - pseudo-device driver. It is
long since obsolete.
 1.13 31-Dec-2019  pgoyette branches: 1.13.2;
Update to not include COMPAT_90
 1.12 17-Jun-2019  christos complete the list of filesystems and enable ffs as a module.
 1.11 13-Jan-2018  christos branches: 1.11.4;
added commented out AUTOFS pseudo-device entries
 1.10 09-Jan-2018  christos Merge autofs support from: Tomohiro Kusumi
XXX: Does not work yet
 1.9 14-Sep-2017  mrg branches: 1.9.2;
clean up COMPAT_* options for native netbsd code:
- new series of files that are useful for saying "i want everything
since netbsd 1.4", etc.
- use the fact COMPAT_* options have future dependancies to remove
many redundant options.

removes about 3000 lines total across kernel configuration files.
tested about 30 random kernels in the changed list.
 1.8 05-Mar-2017  christos use the modular versions of spkr
 1.7 18-Feb-2017  christos l2tp is a module
 1.6 18-Dec-2016  dholland branches: 1.6.2;
Whitespace.
 1.5 09-Sep-2016  christos branches: 1.5.2;
let sppp be loaded dynamically.
 1.4 07-Aug-2016  christos Add some more drivers
 1.3 07-Aug-2016  christos don't load loopback as a module as other parts of the code use it directly.
 1.2 07-Aug-2016  christos Use "-no" and add more cloners.
 1.1 04-Aug-2016  christos branches: 1.1.2;
An attempt to create a fully modular kernel by including GENERIC and
undefining all the drivers we have modules for. This is done to reduce
the kernel footprint for DTRACE and also to test that the modularized
drivers work. Current issues:

1. builtin drivers can't depend on modularized drivers (the modularized
drivers are attempted to load as builtins).
2. there is no way to "no define" drivers
3. it is not always obvious by their names which drivers/options correspond
to which modules.
4. right now critical drivers that would need to be pre-loaded (ffs,
exec_elf64) are still built-in so that we don't need to alter the boot
blocks to boot.

Ideally modstat should show none of the drivers as built-in but we are far
from that.
 1.1.2.4 20-Mar-2017  pgoyette Sync with HEAD
 1.1.2.3 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.1.2.2 06-Aug-2016  pgoyette Sync with HEAD
 1.1.2.1 04-Aug-2016  pgoyette file MODULAR was added on branch pgoyette-localcount on 2016-08-06 00:19:04 +0000
 1.5.2.4 28-Aug-2017  skrll Sync with HEAD
 1.5.2.3 05-Feb-2017  skrll Sync with HEAD
 1.5.2.2 05-Oct-2016  skrll Sync with HEAD
 1.5.2.1 09-Sep-2016  skrll file MODULAR was added on branch nick-nhusb on 2016-10-05 20:55:23 +0000
 1.6.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.9.2.2 03-Dec-2017  jdolecek update from HEAD
 1.9.2.1 14-Sep-2017  jdolecek file MODULAR was added on branch tls-maxphys on 2017-12-03 11:35:47 +0000
 1.11.4.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.13.2.1 25-Jan-2020  ad Sync with head.
 1.18.2.1 03-Apr-2021  thorpej Sync with HEAD.
 1.19.24.1 02-Aug-2025  perseant Sync with HEAD
 1.86 06-Jan-2023  christos Explicitly set -z noseparate-code because the default is about to change
and the boot blocks might not be able to load binaries with more than two
PT_LOAD sections.
 1.85 11-May-2020  joerg Fix GCC flags for Spectre mitigation to really only apply to GCC.
 1.84 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.83 13-Apr-2020  maxv Make KASAN compatible with LLVM. Same as GCC, except that LLVM aggressively
inlines the shadow checks, and this causes problems at boot time; so we
pass -asan-instrumentation-with-call-threshold=0 to force callbacks instead
of inlines.
 1.82 04-Apr-2020  maxv branches: 1.82.2;
KCOV doesn't depend on specificdata and cpu_intr_p() anymore, so drop
references.
 1.81 03-Apr-2020  maxv Add KASAN instrumentation on on-stack VLAs.
 1.80 14-Nov-2019  maxv Add support for Kernel Memory Sanitizer (kMSan). It detects uninitialized
memory used by the kernel at run time, and just like kASan and kCSan, it
is an excellent feature. It has already detected 38 uninitialized variables
in the kernel during my testing, which I have since discreetly fixed.

We use two shadows:
- "shad", to track uninitialized memory with a bit granularity (1:1).
Each bit set to 1 in the shad corresponds to one uninitialized bit of
real kernel memory.
- "orig", to track the origin of the memory with a 4-byte granularity
(1:1). Each uint32_t cell in the orig indicates the origin of the
associated uint32_t of real kernel memory.

The memory consumption of these shadows is consequent, so at least 4GB of
RAM is recommended to run kMSan.

The compiler inserts calls to specific __msan_* functions on each memory
access, to manage both the shad and the orig and detect uninitialized
memory accesses that change the execution flow (like an "if" on an
uninitialized variable).

We mark as uninit several types of memory buffers (stack, pools, kmem,
malloc, uvm_km), and check each buffer passed to copyout, copyoutstr,
bwrite, if_transmit_lock and DMA operations, to detect uninitialized memory
that leaves the system. This allows us to detect kernel info leaks in a way
that is more efficient and also more user-friendly than KLEAK.

Contrary to kASan, kMSan requires comprehensive coverage, ie we cannot
tolerate having one non-instrumented function, because this could cause
false positives. kMSan cannot instrument ASM functions, so I converted
most of them to __asm__ inlines, which kMSan is able to instrument. Those
that remain receive special treatment.

Contrary to kASan again, kMSan uses a TLS, so we must context-switch this
TLS during interrupts. We use different contexts depending on the interrupt
level.

The orig tracks precisely the origin of a buffer. We use a special encoding
for the orig values, and pack together in each uint32_t cell of the orig:
- a code designating the type of memory (Stack, Pool, etc), and
- a compressed pointer, which points either (1) to a string containing
the name of the variable associated with the cell, or (2) to an area
in the kernel .text section which we resolve to a symbol name + offset.

This encoding allows us not to consume extra memory for associating
information with each cell, and produces a precise output, that can tell
for example the name of an uninitialized variable on the stack, the
function in which it was pushed on the stack, and the function where we
accessed this uninitialized variable.

kMSan is available with LLVM, but not with GCC.

The code is organized in a way that is similar to kASan and kCSan, so it
means that other architectures than amd64 can be supported.
 1.79 05-Nov-2019  maxv Add Kernel Concurrency Sanitizer (kCSan) support. This sanitizer allows us
to detect race conditions at runtime. It is a variation of TSan that is
easy to implement and more suited to kernel internals, albeit theoretically
less precise than TSan's happens-before.

We do basically two things:

- On every KCSAN_NACCESSES (=2000) memory accesses, we create a cell
describing the access, and delay the calling CPU (10ms).

- On all memory accesses, we verify if the memory we're reading/writing
is referenced in a cell already.

The combination of the two means that, if for example cpu0 does a read that
is selected and cpu1 does a write at the same address, kCSan will fire,
because cpu1's write collides with cpu0's read cell.

The coverage of the instrumentation is the same as that of kASan. Also, the
code is organized in a way similar to kASan, so it is easy to add support
for more architectures than amd64. kCSan is compatible with KCOV.

Reviewed by Kamil.
 1.78 07-Sep-2019  maxv Merge amd64func.S into cpufunc.S, and clean up.
 1.77 22-May-2019  kamil Allow to use KCOV + kASan together

Stop instrumenting KCOV files with kASan and the other way around.
This fixes booting of the setup of using them together.

In theory the checks could be more fine grained, however there is no good
reason (except extra DIAGNISTIC) for running a kernel sanitizer without
kernel coverage.

Patch by <R3x>
 1.76 24-Feb-2019  maxv Add support for use-after-scope detection in KASAN. It is available since
GCC7, and we have GCC7 by default now.

Slightly reorder the code, and remove a duplicated KASSERT too.

Tested on amd64-KASAN. Not yet enabled on aarch64-KASAN, but it should
work as-is.
 1.75 31-Oct-2018  maxv Move the MI parts of KASAN into kern/subr_asan.c. This file includes
machine/asan.h, which contains the MD functions. We use an include rather
than a plain C file, because we want GCC to optimize/inline some functions
into one single block.

The amd64 MD parts of KASAN are moved accordingly.

The naming convention we use is:

kasan_*
a generic kasan object, declared in subr_asan.c
kasan_md_*
an MD kasan object, declared in machine/asan.h, and used
in subr_asan.c
__md_*
an MD object, declared in machine/asan.h, and not used
outside

Overall this makes it easier to add KASAN support on more architectures.

Discussed with several people.
 1.74 22-Sep-2018  rin - Determine KERN_AS automatically depending on whether OPT_MODULAR is
set or not, in the same way as libcompat.

- Specify OPT_MODULAR in the port Makefile instead of KERN_AS.

Now, KERN_AS=library is used for kernels without module(7) for all ports.

OK christos
 1.73 22-Aug-2018  maxv Add support for monitoring the stack with kASan. This allows us to detect
illegal memory accesses occuring there.

The compiler inlines a piece of code in each function that adds redzones
around the local variables and poisons them. The illegal accesses are then
detected using the usual kASan machinery.

The stack size is doubled, from 4 pages to 8 pages.

Several boot functions are marked with the __noasan flag, to prevent the
compiler from adding redzones in them (because we haven't yet initialized
kASan). The kasan_early_init function is called early at boot time to
quickly create the shadow for the current stack; after this is done, we
don't need __noasan anymore in the boot path.

We pass -fasan-shadow-offset=0xDFFF900000000000, because the compiler
wants to do
shad = shadow-offset + (addr >> 3)
and we do, in kasan_addr_to_shad
shad = KASAN_SHADOW_START + ((addr - CANONICAL_BASE) >> 3)
hence
shad = KASAN_SHADOW_START + (addr >> 3) - (CANONICAL_BASE >> 3)
= [KASAN_SHADOW_START - (CANONICAL_BASE >> 3)] + (addr >> 3)
implies
shadow-offset = KASAN_SHADOW_START - (CANONICAL_BASE >> 3)
= 0xFFFF800000000000 - (0xFFFF800000000000 >> 3)
= 0xDFFF900000000000

In UVM, we add a kasan_free (that is not preceded by a kasan_alloc). We
don't add poisoned redzones ourselves, but all the functions we execute
do, so we need to manually clear the poison before freeing the stack.

With the help of Kamil for the makefile stuff.
 1.72 20-Aug-2018  maxv Add support for kASan on amd64. Written by me, with some parts inspired
from Siddharth Muralee's initial work. This feature can detect several
kinds of memory bugs, and it's an excellent feature.

It can be enabled by uncommenting these three lines in GENERIC:

#makeoptions KASAN=1 # Kernel Address Sanitizer
#options KASAN
#no options SVS

The kernel is compiled without SVS, without DMAP and without PCPU area.
A shadow area is created at boot time, and it can cover the upper 128TB
of the address space. This area is populated gradually as we allocate
memory. With this design the memory consumption is kept at its lowest
level.

The compiler calls the __asan_* functions each time a memory access is
done. We verify whether this access is legal by looking at the shadow
area.

We declare our own special memcpy/memset/etc functions, because the
compiler's builtins don't add the __asan_* instrumentation.

Initially all the mappings are marked as valid. During dynamic
allocations, we add a redzone, which we mark as invalid. Any access on
it will trigger a kASan error message. Additionally, the compiler adds
a redzone on global variables, and we mark these redzones as invalid too.
The illegal-access detection works with a 1-byte granularity.

For now, we cover three areas:

- global variables
- kmem_alloc-ated areas
- malloc-ated areas

More will come, but that's a good start.
 1.71 02-Jun-2018  christos branches: 1.71.2;
Disable sanitizers for the kernel.
 1.70 18-Apr-2018  martin Simplify previous, pointed out by mrg.
 1.69 18-Apr-2018  martin Fix previous: HAVE_GCC needs to be checked in additon to
SPECTRE_V2_GCC_MITIGATION, but SPECTRE_V2_GCC_MITIGATION being empty is
not a good enough check as it can't be overwritte on the make
command line. Now I can do: "make SPECTRE_V2_GCC_MITIGATION=0" (e.g. when
my gcc is too old for having the indirect-branch options).
 1.68 18-Apr-2018  martin Fix copy & pasto
 1.67 07-Apr-2018  mrg add an SPECTRE_V2_GCC_MITIGATION option to x86 kernels, that turns
on the GCC spectre v2 mitigation options.

XXX: pullup-8.
XXX: turn on in all kernels.
 1.66 23-Feb-2018  maxv branches: 1.66.2;
Revert previous, we'll need something better (and compatible with Clang).
 1.65 23-Feb-2018  maxv Add -fno-shrink-wrap, to force GCC to push the frames at the very beginning
of the functions. Otherwise DDB is unable to display a correct stack trace
if a fault occurred in a function before the frame was pushed.

Discussed on tech-kern@, flag suggested by Krister Walfridsson. Should fix
PR/52560.
 1.64 15-Nov-2017  maxv Support large pages on KASLR kernels, in a way that does not reduce
randomness, but on the contrary that increases it.

The size of the kernel sub-blocks is changed to be 1MB. This produces a
kernel with sections that are always < 2MB in size, that can fit a large
page.

Each section is put in a 2MB physical chunk. In this chunk, there is a
padding of approximately 1MB. The prekern uses a random offset aligned to
sh_addralign, to shift the section in physical memory.

For example, physical memory layout created by the bootloader for .text.4
and .rodata.0:
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
|+---------------+ |+---------------+ |
|| .text.4 | PAD || .rodata.0 | PAD |
|+---------------+ |+---------------+ |
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
PA PA+2MB PA+4MB

Then, physical memory layout, after having been shifted by the prekern:
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
| P +---------------+ | +---------------+ |
| A | .text.4 | PAD | PAD | .rodata.0 | PAD |
| D +---------------+ | +---------------+ |
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
PA PA+2MB PA+4MB

The kernel maps these 2MB physical chunks with 2MB large pages. Therefore,
randomness is enforced at both the virtual and physical levels, and the
resulting entropy is higher than that of our current implementaion until
now.

The padding around the section is filled by the prekern. Not to consume
too much memory, the sections that are smaller than PAGE_SIZE are mapped
with normal pages - because there is no point in optimizing them. In these
normal pages, the same shift is applied.

This change has two additional advantages: (a) the cache attacks based on
the TLB are mostly mitigated, because even if you are able to determine
that a given page-aligned range is mapped as executable you don't know
where exactly within that range the section actually begins, and (b) given
that we are slightly randomizing the physical layout we are making some
rare physical attacks more difficult to conduct.

NOTE: after this change you need to update GENERIC_KASLR / prekern /
bootloader.
 1.63 14-Nov-2017  maxv Split each kernel section into sub-blocks of approximately 2MB. The newly
created sections are named .origname.i, for example:

.text -> { .text .text.0 .text.1 .text.2 .text.3 .text.4 }

Each section is randomized independently by the prekern - and in a random
order obviously. As a result we can get intertwined mappings, of the type:

+-------+-----------+------+---------+-----------+-------+-------+------+-
| text1 | NOTMAPPED | bss0 | rodata1 | NOTMAPPED | data2 | text3 | bss1 |
+-------+-----------+------+---------+-----------+-------+-------+------+-

---------+-
rodata0 | ...
---------+-

The CTF section is dropped completely, because (a) when split it becomes
enormous for some reason (that I don't quite understand, verily), and (b)
the kernel expects only one CTF and can't handle several of them.
 1.62 14-Nov-2017  maxv Remove max-page-size on KASLR, it doesn't play any role.
 1.61 09-Nov-2017  maxv Use another ld script for kaslr kernels, in which there are no alignment
directives. They don't matter since the bootloader overwrites them.

But, normally we still need to make sure .data.read_mostly is aligned.
Unfortunately I couldn't find any way to force sh_addralign to be 64, so
I'm leaving the alignment there as a useless reminder.
 1.60 01-Nov-2017  maxv Add linux_sigcode.o, otherwise it doesn't get rebuilt.
 1.59 07-Oct-2017  maxv Add GENERIC_KASLR, only toolchain parts for now.
 1.58 09-Aug-2017  maxv Remove several dead entries from the x86 makefiles. Looks like people (me
included) regularly forget to take care of this.
 1.57 11-Feb-2017  maxv branches: 1.57.6;
Put 2MB alignments between the kernel segments. This way the kernel image
is entirely mapped with large pages, which uniformizes performance and
reduces fluctuation. Sent on port-amd64.
 1.56 02-Feb-2017  maxv Increase KERNTEXTOFF from 1MB to 2MB on amd64. [1MB; 2MB[ is now handled
by UVM, so there is no physical loss.

On amd64 we always remap the kernel text with 2MB pages, and because of the
1MB start address we were forced to map [0MB; 2MB[ inside the first large
page. The problem is, the lower half is used by UVM to allocate physical
pages, and it is possible that some of these could be used by userland. We
could end up with userland-controllable data mapped into the kernel text on
a privileged page, which is far from being a good idea from a security pov.

I am not fixing i386 yet, because the large page size depends on PAE, and
we probably don't want to have a text located at 4MB on low-memory systems.

(note: I didn't introduce this issue, it was already there when I came in)
 1.55 29-Apr-2016  christos branches: 1.55.2; 1.55.4;
Moved hack to ufs_lookup.c
 1.54 28-Apr-2016  mrg XXX: build ufs_lookup.c with -fno-tree-vrp when using GCC 5, for now.
 1.53 06-Sep-2015  uebayasi Define MD start code at the top of files.${MACHINE} relying on config(1)'s
deterministic file output order. No need to define ${MD_OBJS} and its useless,
explicit compile rules.
 1.52 03-Sep-2015  uebayasi Define ${MD_OBJS} as relative path. This change makes amd64 kernel buildable
for `-S' mode.
 1.51 24-Aug-2015  uebayasi Define ${LINKSCRIPT} in one place.
 1.50 18-Aug-2015  uebayasi ${KERN_LDSCRIPT} -> ${KERNLDSCRIPT}
 1.49 01-May-2015  nat Include splash with genfb.
splash.o is only included with options SPLASHSCREEN.
splash_image.o target moved to Makefile.kern.inc.

This commit was approved by matt@
 1.48 30-Apr-2015  nat Remove unintended whitespace.
 1.47 30-Apr-2015  nat Added a new option for embedding a splash screen into kernel.
Add: options SPLASHSCREEN
makeoptions SPLASHSCREEN_IMAGE="path/to/image"
to your config file. So far it will work on amd64 and RPI/RPI2.

This commit was with ideas, help, and OK from jmcneill@.
 1.46 15-Nov-2014  uebayasi branches: 1.46.2;
Use LINKSCRIPT.
 1.45 24-May-2014  jakllsch Add -fno-omit-frame-pointer to DEFCOPTS.
 1.44 05-Feb-2014  dsl branches: 1.44.2;
Apparantly clang doesn't like -mno-80387 or -mno-fp-ret-in-387
-msoft-float is equivalent to the former, the latter is probably unlikely
to stop anything not picked up elsewhere.
 1.43 05-Feb-2014  dsl Change the compiler options to explicitly specify:
-mno-mmx -mno-sse -mno-avx -mno-80387 -mno-fp-ret-in-387
Since no-sse implies no-sse2 that should ensure that the compiler really
doesn't emit any instructions that might trap trying to use the FPU.
On amd64 at least some of those are needed to stop the compiler
saving the registers to stack on every varargs function.
It might be that -mno-sse did that before.
 1.42 15-Jan-2014  joerg Reduce amount of -no-integrated-as on x86 as .code16 is now supported by
LLVM.
 1.41 14-Dec-2012  christos branches: 1.41.2;
do like the i386 for modular.
 1.40 19-Dec-2011  joerg branches: 1.40.6;
Move Clang-warning flags for ah_regdomain.c into sys/conf, they are
platform independent. Use the selective -Wno-* flags instead of
-Wno-error.
 1.39 14-Sep-2011  christos branches: 1.39.2; 1.39.6;
include wakecode after kernel rules so that the .depend rules are defined
 1.38 02-Aug-2011  joerg Remove a number of now unnecessary -no-integrated-as cases.
 1.37 10-Jun-2011  joerg Disable LLVM MC for spl.S for now. The different spllower sizes break
patchfunc.
 1.36 10-Jun-2011  joerg Explicitly disable use of SSE. LLVM generates SSE by default on AMD64
and we certainly don't want that in the kernel.
 1.35 30-May-2011  joerg branches: 1.35.2;
Disable -Werror for ah_regdomain.c if building with clang as workaround
for http://llvm.org/bugs/show_bug.cgi?id=10030.
 1.34 20-May-2011  joerg Drop redundant -I.
 1.33 20-May-2011  joerg Really apply the -no-integrated-as only for clang.
 1.32 20-May-2011  joerg Reuse -x assembler-with-cpp from sys.mk.
 1.31 20-May-2011  joerg LLVM's assembler parser doesn't support .code32 yet, so disable it as
needed.
 1.30 12-Jan-2011  joerg branches: 1.30.2;
Allow use of traditional CPP to be set on a per platform base in sys.mk.
Honour this for dependency processing in bsd.dep.mk. Switch i386 and
amd64 assembly to use ISO C90 preprocessor concat and drop the
-traditional-cpp on this platform.
 1.29 25-Nov-2009  tron branches: 1.29.4;
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.28 02-Oct-2009  skrll It's -z max-page-size, not -z maxpagesize.
 1.27 01-Oct-2009  skrll MAXPAGESIZE got bumped to 0x200000. Use -z maxpagesize=0x100000 until
someone(tm) decides that kernels should have that alignment, etc.
 1.26 11-Dec-2008  alc branches: 1.26.2;
Clean-up makefile stub used to include in the build the binary HAL object
 1.25 30-Oct-2008  joerg branches: 1.25.2; 1.25.8;
New assym.h dependency.
 1.24 10-Mar-2008  ad branches: 1.24.4; 1.24.10; 1.24.12;
Implement an optimized, preemption-safe asm version of tsc_get_timecount().
The C version needs work to be preemption safe. Cuts the clock cycles
for microtime() from 950 down to 300 on a Pentium D.
 1.23 25-Jan-2008  joerg branches: 1.23.2; 1.23.6;
Refactor in_cksum/in4_cksum/in6_cksum implementations:
- All three functions are included in the kernel by default.
They call a backend function cpu_in_cksum after possibly
computing the checksum of the pseudo header.
- cpu_in_cksum is the core to implement the one-complement sum.
The default implementation is moderate fast on most platforms
and provides a 32bit accumulator with 16bit addends for L32 platforms
and a 64bit accumulator with 32bit addends for L64 platforms.
It handles edge cases like very large mbuf chains (could happen with
native IPv6 in the future) and provides a good base for new native
implementations.
- Modify i386 and amd64 assembly to use the new interface.

This disables the MD implementations on !x86 until the conversion is
done. For Alpha, the portable version is faster.
 1.22 21-Jan-2008  joerg in_cksum.S needs assym.h.
 1.21 17-Jan-2008  lukem Remove unnecessary references to config_time.h.
 1.20 30-Dec-2007  joerg Missing assym.h dependency.
 1.19 21-Dec-2007  joerg lock_stubs.S needs assym.h.
 1.18 09-Dec-2007  jmcneill branches: 1.18.2;
Merge jmcneill-pm branch.
 1.17 24-Oct-2007  joerg branches: 1.17.2; 1.17.4; 1.17.6;
cpufunc.S depends on assym.h.
 1.16 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.15 04-Oct-2007  christos branches: 1.15.2;
busfunc depends on assym.h
 1.14 07-Jun-2006  kardel branches: 1.14.16; 1.14.24; 1.14.34; 1.14.36; 1.14.38;
convert to timecounters (from branch simonb-timecounters)
 1.13 04-Apr-2006  gdamore branches: 1.13.2;
Convert existing ath users to new Makefile, except for amd64, which needs
the rules due to needing to conditionally postprocess the HAL object file.

Macppc needs a a non-ELF HAL (EABI) object, so take care of that by default
in the atheros include file.
 1.12 02-Apr-2006  gdamore Reorganize ath layout as requested by sam@ and suggested by dyoung@ in
http://mail-index.netbsd.org/tech-net/2006/03/15/0000.html.

The new layout almost precisely matches FreeBSD, and should make
future imports much easier.

At the same time, import the current 0.9.16.16 HAL from FreeBSD. According
to sam@, this is the proper version we should be using.
 1.11 08-Mar-2006  dyoung branches: 1.11.2;
No need to create opt_ah.h here, config(8) takes care of it.
 1.10 03-Mar-2006  he branches: 1.10.2; 1.10.4;
Before symlinking opt_ah.h, make sure the target doesn't already exist.
This fixes a build problem with UPDATE set.
 1.9 30-Nov-2005  dsl branches: 1.9.4; 1.9.6;
It seems that make doesn't like testing empty() on undefined variables.
Also objdump DTRT when asked to update a file, so no need to do a mv ourselves.
 1.8 27-Nov-2005  dsl If we are compiling with -fno-asynchronous-unwind-tables then also
remove the .eh_frame section from athhal-x86_64-elf.hal.o.
 1.7 12-Jul-2005  sekiya branches: 1.7.6;
Add config goo for ath. Tested with a PCI card, detected as:

ath0 at pci0 dev 10 function 0
ath0: interrupting at ioapic0 pin 17 (irq 5)
ath0: 11a rates: 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps
ath0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
ath0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36M bps 48Mbps 54Mbps
ath0: mac 5.9 phy 4.3 radio 3.6

Cardbus untested, so it is commented out.
 1.6 31-May-2005  christos branches: 1.6.2;
s/GENASSYM/GENASSYM_CONF/ so we can use "GENASSYM" as the program name.
 1.5 04-Jun-2004  thorpej Add the %MAKEOPTIONSAPPEND token at the end of the file, after the
common Makefile.kern.inc has been included.
 1.4 27-May-2003  christos branches: 1.4.2; 1.4.6;
another dependency on assym.h
 1.3 17-May-2003  christos clock.o depends on config_time.h
 1.2 04-May-2003  fvdl Default to -O2.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.4.6.1 06-Feb-2005  jmc Pull up patch (requested by martti in ticket #1086)
Move ipf to sys/dist/ipf and sync w. trunk
 1.4.2.5 11-Dec-2005  christos Sync with head.
 1.4.2.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 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.2.5 17-Mar-2008  yamt sync with head.
 1.6.2.4 04-Feb-2008  yamt sync with head.
 1.6.2.3 21-Jan-2008  yamt sync with head
 1.6.2.2 27-Oct-2007  yamt sync with head.
 1.6.2.1 21-Jun-2006  yamt sync with head.
 1.7.6.1 29-Nov-2005  yamt sync with head.
 1.9.6.2 30-Apr-2006  kardel retire microtime.S
 1.9.6.1 22-Apr-2006  simonb Sync with head.
 1.9.4.1 09-Sep-2006  rpaulo sync with head
 1.10.4.1 19-Apr-2006  elad sync with head - hopefully this will work
 1.10.2.3 26-Jun-2006  yamt sync with head.
 1.10.2.2 11-Apr-2006  yamt sync with head
 1.10.2.1 13-Mar-2006  yamt sync with head.
 1.11.2.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.13.2.1 19-Jun-2006  chap Sync with head.
 1.14.38.1 06-Oct-2007  yamt sync with head.
 1.14.36.3 23-Mar-2008  matt sync with HEAD
 1.14.36.2 09-Jan-2008  matt sync with HEAD
 1.14.36.1 06-Nov-2007  matt sync with HEAD
 1.14.34.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.14.34.3 04-Oct-2007  joerg Sync with HEAD.
 1.14.34.2 24-Sep-2007  joerg Generate the ACPI wakecode image dynamically at build time.
 1.14.34.1 10-Sep-2007  joerg Add work-in-progress remerge of i386 changes for the ACPI wakecode
and changes to adopt it to AMD64.
 1.14.24.1 16-Oct-2007  garbled Sync with HEAD
 1.14.16.2 03-Dec-2007  ad Sync with HEAD.
 1.14.16.1 09-Oct-2007  ad Sync with head.
 1.15.2.1 13-Nov-2007  bouyer Sync with HEAD
 1.17.6.1 11-Dec-2007  yamt sync with head.
 1.17.4.1 26-Dec-2007  ad Sync with head.
 1.17.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.18.2.3 23-Jan-2008  bouyer Sync with HEAD.
 1.18.2.2 19-Jan-2008  bouyer Sync with HEAD
 1.18.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.23.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.23.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.23.2.1 24-Mar-2008  keiichi sync with head.
 1.24.12.1 19-Jan-2009  skrll Sync with HEAD.
 1.24.10.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.24.4.2 11-Mar-2010  yamt sync with head
 1.24.4.1 04-May-2009  yamt sync with head.
 1.25.8.1 21-Apr-2010  matt sync to netbsd-5
 1.25.2.1 07-Aug-2009  snj Pull up following revision(s) (requested by sborrill in ticket #905):
sys/arch/alpha/conf/Makefile.alpha: revision 1.81
sys/arch/amd64/conf/Makefile.amd64: revision 1.26
sys/arch/i386/conf/Makefile.i386: revision 1.162
sys/arch/macppc/conf/Makefile.macppc: revision 1.31
sys/arch/mips/conf/Makefile.mips: revision 1.52
sys/arch/sparc64/conf/Makefile.sparc64: revision 1.68
sys/arch/xen/conf/Makefile.xen: revision 1.28
Clean-up makefile stub used to include in the build the binary HAL object
 1.26.2.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.2.3 29-Mar-2011  jym More sync fixes. And add the mbr_gpt files.
 1.26.2.2 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.26.2.1 01-Nov-2009  jym Sync with HEAD.
 1.29.4.3 12-Jun-2011  rmind sync with head
 1.29.4.2 31-May-2011  rmind sync with head
 1.29.4.1 05-Mar-2011  rmind sync with head
 1.30.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.35.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.39.6.1 18-Feb-2012  mrg merge to -current.
 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 23-Jan-2013  yamt sync with head
 1.39.2.1 17-Apr-2012  yamt sync with head
 1.40.6.3 03-Dec-2017  jdolecek update from HEAD
 1.40.6.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.40.6.1 25-Feb-2013  tls resync with head
 1.41.2.1 18-May-2014  rmind sync with head
 1.44.2.1 10-Aug-2014  tls Rebase.
 1.46.2.4 28-Aug-2017  skrll Sync with HEAD
 1.46.2.3 05-Feb-2017  skrll Sync with HEAD
 1.46.2.2 22-Sep-2015  skrll Sync with HEAD
 1.46.2.1 06-Jun-2015  skrll Sync with HEAD
 1.55.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.55.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.57.6.1 11-Apr-2018  martin Pull up following revision(s) (requested by mrg in ticket #731):
sys/arch/i386/conf/files.i386: revision 1.392
sys/arch/i386/conf/GENERIC: revision 1.1175
sys/arch/i386/conf/GENERIC: revision 1.1176
sys/arch/amd64/conf/files.amd64: revision 1.102
sys/arch/i386/conf/GENERIC: revision 1.1177
share/man/man4/options.4: revision 1.485 (patch)
sys/arch/i386/conf/Makefile.i386: revision 1.190
sys/arch/amd64/conf/GENERIC: revision 1.487
sys/arch/amd64/conf/ALL: revision 1.85
sys/arch/amd64/conf/GENERIC: revision 1.488
sys/arch/amd64/conf/GENERIC: revision 1.489
sys/arch/amd64/conf/Makefile.amd64: revision 1.67
sys/arch/i386/conf/ALL: revision 1.437

add an SPECTRE_V2_GCC_MITIGATION option to x86 kernels, that turns
on the GCC spectre v2 mitigation options.
XXX: pullup-8.
XXX: turn on in all kernels.

actually do what the previous change said:
don't turn on the new 'SPECTRE_V2_GCC_MITIGATION' option yet.

turn on GCC spectre v2 mitigation options.
XXX: amd64 ALL doesn't build for me right now
 1.66.2.6 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.66.2.5 30-Sep-2018  pgoyette Ssync with HEAD
 1.66.2.4 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.66.2.3 25-Jun-2018  pgoyette Sync with HEAD
 1.66.2.2 22-Apr-2018  pgoyette Sync with HEAD
 1.66.2.1 16-Apr-2018  pgoyette Sync with HEAD, resolve some conflicts
 1.71.2.3 21-Apr-2020  martin Sync with HEAD
 1.71.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.71.2.1 10-Jun-2019  christos Sync with HEAD
 1.82.2.2 20-Apr-2020  bouyer Sync with HEAD
 1.82.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.
 1.7 05-Jun-2023  pgoyette Un-comment the ident line
 1.6 20-Jan-2021  pgoyette COMPAT_OSSAUDIO no longer exists; remove dangling reference
 1.5 16-Aug-2020  jdolecek branches: 1.5.2;
make COMPAT_LINUX option disabled by default

leave the option enabled only in amd64/i386 ALL kernels to make
sure it continues to be compilable also when included in kernel
 1.4 05-Oct-2019  pgoyette Add a commented-out entry for COMPAT_90 for completeness

NFCI
 1.3 12-Jun-2019  pgoyette Fix typo in comment (missing 'need')
 1.2 27-Jan-2019  pgoyette branches: 1.2.4;
Merge the [pgoyette-compat] branch
 1.1 06-Mar-2018  pgoyette branches: 1.1.2;
file NOCOMPAT was initially added on branch pgoyette-compat.
 1.1.2.9 24-Jan-2019  pgoyette Disable more COMPAT_xx stuff for the NOCOMPAT config
cvs: ----------------------------------------------------------------------
 1.1.2.8 22-Jan-2019  pgoyette Only explicitly disable COMPAT_15, it is the only compat option that
is actually set. The others are "pulled in" by statements in
sys/conf/files


This avoids numerous noisy but unnecessary warnings from nbconfig.
 1.1.2.7 22-Jan-2019  pgoyette Rather than having to track changes in GENERIC and incorporate them
into NOCOMPAT, just include GENERIC and then turn off the various
COMPAT options.
 1.1.2.6 22-Jan-2019  pgoyette Synch GENERIC and NOCOMPAT with GENERIC from HEAD
 1.1.2.5 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.1.2.4 01-Oct-2018  pgoyette Sync with changes from HEAD: no more ATM
 1.1.2.3 11-Mar-2018  pgoyette Remove another COMPAT option
 1.1.2.2 09-Mar-2018  pgoyette Split the sysv_ipc module into two pieces: one for contemporary
SYSV* functionality, and one for compatability with previous NetBSD
versions. No need to pull in all of compat just to have a sysv_ipc
module.
 1.1.2.1 06-Mar-2018  pgoyette Add a NOCOMPAT kernel definition to serve as a baseline for getting
the incremental COMPAT_xx options working.

While here, add some additional "requires COMPAT_xxx" to some of the
options in GENERIC
 1.2.4.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.2.4.2 10-Jun-2019  christos Sync with HEAD
 1.2.4.1 27-Jan-2019  christos file NOCOMPAT was added on branch phil-wifi on 2019-06-10 22:05:47 +0000
 1.5.2.1 03-Apr-2021  thorpej Sync with HEAD.
 1.3 02-Nov-2014  christos make DRMKMS the default on GENERIC and comment out the legacy drivers.
 1.2 18-Mar-2014  riastradh branches: 1.2.4; 1.2.6; 1.2.8; 1.2.10;
Merge riastradh-drm2 to HEAD.
 1.1 24-Jul-2013  riastradh branches: 1.1.2;
file NO_DRM was initially added on branch riastradh-drm2.
 1.1.2.3 30-Jan-2014  riastradh Redo amd64/NO_DRM config and add amd64/DRMKMS.
 1.1.2.2 29-Jan-2014  riastradh Include genfb in NO_DRM kernel rather than modularizing.

Modularizing required a bunch of hacks (wscons/genfb/&c. is not ready
for modules) and failed to pull in rasops dependencies, so rasops
never worked correctly.
 1.1.2.1 24-Jul-2013  riastradh Provisional NO_DRM config for testing with a module.

Too much trouble to keep this as an uncommitted change...
 1.2.10.3 03-Dec-2017  jdolecek update from HEAD
 1.2.10.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.10.1 18-Mar-2014  tls file NO_DRM was added on branch tls-maxphys on 2014-08-20 00:02:42 +0000
 1.2.8.2 18-Mar-2015  snj Apply patch (requested by christos in ticket #542):
- Enable intel and radeon DRM/KMS drivers in GENERIC
- Disable all of the old DRM drivers in GENERIC
- Remove the separate DRMKMS kernel
 1.2.8.1 21-Jan-2015  martin After removing i915drm from GENERIC, also remove the corresponding
"no i915drm*" statements to make (old) config(1) happy.
Requested by snj in ticket #438
 1.2.6.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.2.6.1 18-Mar-2014  yamt file NO_DRM was added on branch yamt-pagecache on 2014-05-22 11:39:28 +0000
 1.2.4.2 18-May-2014  rmind sync with head
 1.2.4.1 18-Mar-2014  rmind file NO_DRM was added on branch rmind-smpnet on 2014-05-18 17:44:54 +0000
 1.3 30-Apr-2020  riastradh Rewrite entropy subsystem.

Primary goals:

1. Use cryptography primitives designed and vetted by cryptographers.
2. Be honest about entropy estimation.
3. Propagate full entropy as soon as possible.
4. Simplify the APIs.
5. Reduce overhead of rnd_add_data and cprng_strong.
6. Reduce side channels of HWRNG data and human input sources.
7. Improve visibility of operation with sysctl and event counters.

Caveat: rngtest is no longer used generically for RND_TYPE_RNG
rndsources. Hardware RNG devices should have hardware-specific
health tests. For example, checking for two repeated 256-bit outputs
works to detect AMD's 2019 RDRAND bug. Not all hardware RNGs are
necessarily designed to produce exactly uniform output.

ENTROPY POOL

- A Keccak sponge, with test vectors, replaces the old LFSR/SHA-1
kludge as the cryptographic primitive.

- `Entropy depletion' is available for testing purposes with a sysctl
knob kern.entropy.depletion; otherwise it is disabled, and once the
system reaches full entropy it is assumed to stay there as far as
modern cryptography is concerned.

- No `entropy estimation' based on sample values. Such `entropy
estimation' is a contradiction in terms, dishonest to users, and a
potential source of side channels. It is the responsibility of the
driver author to study the entropy of the process that generates
the samples.

- Per-CPU gathering pools avoid contention on a global queue.

- Entropy is occasionally consolidated into global pool -- as soon as
it's ready, if we've never reached full entropy, and with a rate
limit afterward. Operators can force consolidation now by running
sysctl -w kern.entropy.consolidate=1.

- rndsink(9) API has been replaced by an epoch counter which changes
whenever entropy is consolidated into the global pool.
. Usage: Cache entropy_epoch() when you seed. If entropy_epoch()
has changed when you're about to use whatever you seeded, reseed.
. Epoch is never zero, so initialize cache to 0 if you want to reseed
on first use.
. Epoch is -1 iff we have never reached full entropy -- in other
words, the old rnd_initial_entropy is (entropy_epoch() != -1) --
but it is better if you check for changes rather than for -1, so
that if the system estimated its own entropy incorrectly, entropy
consolidation has the opportunity to prevent future compromise.

- Sysctls and event counters provide operator visibility into what's
happening:
. kern.entropy.needed - bits of entropy short of full entropy
. kern.entropy.pending - bits known to be pending in per-CPU pools,
can be consolidated with sysctl -w kern.entropy.consolidate=1
. kern.entropy.epoch - number of times consolidation has happened,
never 0, and -1 iff we have never reached full entropy

CPRNG_STRONG

- A cprng_strong instance is now a collection of per-CPU NIST
Hash_DRBGs. There are only two in the system: user_cprng for
/dev/urandom and sysctl kern.?random, and kern_cprng for kernel
users which may need to operate in interrupt context up to IPL_VM.

(Calling cprng_strong in interrupt context does not strike me as a
particularly good idea, so I added an event counter to see whether
anything actually does.)

- Event counters provide operator visibility into when reseeding
happens.

INTEL RDRAND/RDSEED, VIA C3 RNG (CPU_RNG)

- Unwired for now; will be rewired in a subsequent commit.
 1.2 10-Aug-2014  tls branches: 1.2.4;
Merge tls-earlyentropy branch into HEAD.
 1.1 06-Apr-2014  tls branches: 1.1.2;
file RNDVERBOSE was initially added on branch tls-earlyentropy.
 1.1.2.1 06-Apr-2014  tls RNDVERBOSE kernel for testing.
 1.2.4.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.4.1 10-Aug-2014  tls file RNDVERBOSE was added on branch tls-maxphys on 2014-08-20 00:02:42 +0000
 1.35 10-Dec-2007  ad Real hardware has been available for a long time now!
 1.34 17-Oct-2007  garbled branches: 1.34.2; 1.34.4; 1.34.6; 1.34.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.33 06-Sep-2007  martti Fixed indentation (it should be <keyword><space><tab><name>tab><comment>).
 1.32 16-Jun-2007  ad branches: 1.32.4; 1.32.8; 1.32.10;
-options I2OVERBOSE.
 1.31 29-May-2007  christos Add compat 4.0
 1.30 29-Dec-2006  yamt branches: 1.30.6; 1.30.8; 1.30.14;
update comments on NFS_V2_ONLY after nqnfs removal. no functional changes.
from Arnaud Lacombe.
 1.29 27-Sep-2006  manu - Document COMPAT_15 as doing nothing
- Add COMPAT_15 to all the kernel that had COMPAT_14, for the sake of coherency
- Remove the only occurences of #ifdef COMPAT_15 in the tree: for the ARM
ports, COMPAT_15 was always used in conjunction with EXEC_AOUT. Only EXEC_AOUT
matters here.

This address kern/18407
 1.28 26-Aug-2006  christos branches: 1.28.2; 1.28.4;
PR/34283: Gene ENonymous: Add IPFILTER_LOOKUP to the default kernel options
Also remove CCITT,NS,NIP
 1.27 05-Feb-2006  cube branches: 1.27.2;
Remove 'count' argument for pseudo-devices that ignore it
(vnd, bpfilter, ppp, gif, gre, tun, sl, strip, faith, stf).
 1.26 04-Feb-2006  rpaulo bpfilter doesn't accept count anymore.
 1.25 20-Dec-2005  thorpej branches: 1.25.2; 1.25.4; 1.25.6;
Remove the tablet line discipline.
 1.24 07-Dec-2005  tsutsui Remove obsolete options VNODE_OP_NOINLINE.
 1.23 07-Dec-2005  tsutsui Adjust comments for options FFS_NO_SNAPSHOT.

XXX: This option should be mentioned in options(4).
 1.22 19-Aug-2005  christos Enable ptyfs by default on the non-install and non small/tiny/ramdisk kernels
 1.21 19-Aug-2005  christos 64 bit inode changes.
 1.20 31-Jul-2005  yamt revert "defflag VMSWAP" changes for now.
there seems to be far more people who don't want to edit
their kernel config files than i thought.
 1.19 30-Jul-2005  yamt add "options VMSWAP" to non INSTALL kernels.
 1.18 28-Jun-2005  wiz branches: 1.18.2;
pss(4) was removed, remove it from kernel configs too.
 1.17 25-Mar-2005  cube Add attimer(4) configurations everywhere pcppi(4) exists, with the
following rule:
If a pcppi device is enabled for an attachment, enable an attimer for the
same attachement, otherwise comment it.
 1.16 11-Mar-2005  matt Add cpu* at mainbus0
 1.15 25-Feb-2005  simonb Add COMPAT_20 (and COMPAT_16 in some cases) to kernel config files
that didn't have those options but had other earlier compat options.
 1.14 18-Feb-2005  dsl Invert FFS_SNAPSHOT to FFS_NO_SNAPSHOT
 1.13 11-Feb-2005  dsl Add 'option FFS_SNAPSHOT' to most of the config files.
Commented out for kernels that appear to hace space constraints.
 1.12 31-Jan-2005  hannken Add file system snapshots to kernel configs.

- Ffs internal snapshots get compiled in unconditionally.

- File system snapshot device fss(4) added to all kernel configs that
have a disk. Device is commented out on all non-GENERIC kernels.

Reviewed by: Jason Thorpe <thorpej@netbsd.org>
 1.11 24-Nov-2004  bouyer branches: 1.11.4; 1.11.6;
pdcsata(4), a driver for the Promise SATA150 (aka PDC203xx) serie of
controllers. Tested with a PDC20375 (2 SATA, one PATA) controller on sparc64.
Added to all kernel config file which had pdcide(4).
 1.10 10-Nov-2004  christos Add COMPAT_BSDPTY on all the kernels that have COMPAT options.
 1.9 04-Sep-2004  manu IPv4 PIM support, based on a submission from Pavlin Radoslavov posted on
tech-net@
 1.8 15-Jul-2004  atatat Add "options SYSCTL_INCLUDE_DESCR" to a lot of configs, but commented
out in most of them.
 1.7 14-Dec-2003  thorpej branches: 1.7.2;
Split the Intel i31244 SATA controller ("Artisea") driver out of piixide
into its own driver (artsata).
 1.6 13-Dec-2003  thorpej Split out the Silicon Image SATALink support into its own driver,
"satalink".
 1.5 18-Oct-2003  lukem Use one 'atabus* at ata?' instead of multiple 'atabus* at FOOide? channel ?'
Use 'atapibus* at atapi?' instead of 'atapibus* at atabus?'
 1.4 08-Oct-2003  bouyer Add new per-chip pciide drivers.
 1.3 08-Oct-2003  bouyer Add atabus.
 1.2 15-May-2003  wiz branches: 1.2.2;
There are no olms or omms drivers for amd64.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.2.2.11 11-Dec-2005  christos Sync with head.
 1.2.2.10 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.2.2.9 01-Apr-2005  skrll Sync with HEAD.
 1.2.2.8 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.2.2.7 15-Feb-2005  skrll Sync with HEAD.
 1.2.2.6 04-Feb-2005  skrll Sync with HEAD.
 1.2.2.5 29-Nov-2004  skrll Sync with HEAD.
 1.2.2.4 14-Nov-2004  skrll Sync with HEAD.
 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.7.2.1 15-Jul-2004  he branches: 1.7.2.1.2;
Pull up revision 1.8 (requested by atatat in ticket #663):
Add "options SYSCTL_INCLUDE_DESCR" to a lot of configurations,
but commented out in most of them.
 1.7.2.1.2.1 02-Apr-2005  he Pull up revision 1.11 (requested by bouyer in ticket #1019):
Add pdcsata(4), a driver for the Promise SATA150 (aka PDC203xx) series of
controllers.
 1.11.6.3 26-Mar-2005  yamt sync with head.
 1.11.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.11.6.1 12-Feb-2005  yamt sync with head.
 1.11.4.1 29-Apr-2005  kent sync with -current
 1.18.2.5 21-Jan-2008  yamt sync with head
 1.18.2.4 27-Oct-2007  yamt sync with head.
 1.18.2.3 03-Sep-2007  yamt sync with head.
 1.18.2.2 30-Dec-2006  yamt sync with head.
 1.18.2.1 21-Jun-2006  yamt sync with head.
 1.25.6.1 22-Apr-2006  simonb Sync with head.
 1.25.4.1 09-Sep-2006  rpaulo sync with head
 1.25.2.1 18-Feb-2006  yamt sync with head.
 1.27.2.1 03-Sep-2006  yamt sync with head.
 1.28.4.1 22-Oct-2006  yamt sync with head
 1.28.2.2 12-Jan-2007  ad Sync with head.
 1.28.2.1 18-Nov-2006  ad Sync with head.
 1.30.14.2 03-Oct-2007  garbled Sync with HEAD
 1.30.14.1 26-Jun-2007  garbled Sync with HEAD.
 1.30.8.1 11-Jul-2007  mjf Sync with head.
 1.30.6.3 09-Oct-2007  ad Sync with head.
 1.30.6.2 15-Jul-2007  ad Sync with head.
 1.30.6.1 09-Jun-2007  ad Sync with head.
 1.32.10.2 23-Mar-2008  matt sync with HEAD
 1.32.10.1 06-Nov-2007  matt sync with HEAD
 1.32.8.1 02-Oct-2007  joerg Sync with HEAD.
 1.32.4.1 10-Sep-2007  skrll Sync with HEAD.
 1.34.8.1 13-Dec-2007  bouyer Sync with HEAD
 1.34.6.1 11-Dec-2007  yamt sync with head.
 1.34.4.1 26-Dec-2007  ad Sync with head.
 1.34.2.1 27-Dec-2007  mjf Sync with HEAD.
 1.1 12-Jul-2018  phil branches: 1.1.2;
file TESTWIFI was initially added on branch phil-wifi.
 1.1.2.4 10-Jun-2019  christos Sync with HEAD
 1.1.2.3 15-Aug-2018  phil Final changes for 200 hour contract. Still a lot of work to do.
With these changes, Station mode works with an open AP.
 1.1.2.2 03-Aug-2018  phil State Save:
Scanning works, can see the broadcasts and stations.
Association appears to work. (open networks only, no encryption yet.)
IP traffic doesn't flow yet, not sure where the error is.
Added back more NetBSD ioctls not in the FreeBSD code. Still have
more to go.
Updated my TESTWIFI kernel config.
 1.1.2.1 12-Jul-2018  phil State save. New kernel config for this brach only. TESTWIFI does
produce a kernel. It is not working. athn files not compiling yet
and commented out of the TESTWIFI kernel, which only has urtwn 802.11
driver enabled. ieee80211_alq.c and ieee80211_ddb.c not compiling yet.
 1.206 21-Oct-2025  pgoyette Add Realtek 8126 to comment for rge*
 1.205 22-May-2025  bad actually include "amd64/conf/XEN3_DOM0.local as intended

Typoed in previous commit.

PR port-xen/59438: GENERIC content can't be in GENERIC.local because of XEN3_DOM* kernels
 1.204 22-May-2025  bad make XEN3 configs include XEN3.local instead of GENERIC.local

The XEN device tree is not compatible with the non-XEN device tree.

This means that one can't enable in GENERIC.local many devices that are
commented out in GENERIC. E.g,

vio9p* at virtio?
i915drm* at drm?
qat* at pci? dev ? function ?
audio* at audiobus?

Switch to including XEN3.local instead of GENERIC.local to have a common
file for local XEN3 specific configuration.

See https://mail-index.netbsd.org/tech-kern/2024/08/11/msg029672.html for
the discussion.

Note that GENERIC.local was added to most arches only in February 2023:
https://mail-index.netbsd.org/source-changes/2023/02/12/msg143277.html

Addresses: PR port-xen/59438: GENERIC content can't be in GENERIC.local because
of XEN3_DOM* kernels

Should probably be pulled up to -10 and -9.
 1.203 02-Apr-2024  charlotte branches: 1.203.2;
Mention DKWEDGE_METHOD_TOS in several kernel config files
 1.202 29-Jan-2024  christos PR/57889: Ricardo Branco: ext2fs does not have user immutable and append
file flags, only system ones. Restrict those to the superuser. Before
the behavior was controlled by EXT2FS_SYSTEM_FLAGS. Make that behavior the
default.
 1.201 17-Oct-2023  bouyer Enable genfb in DOM0 kernels
 1.200 04-Oct-2023  rin igc(4): Added to kernel config files for tested platforms

I.e., aarch64, amd64, and evbppc/DHT, at the moment.

Please feel free to add to other config files, and report us back
if you find problems :)
 1.199 05-Aug-2023  riastradh xen/x86: Enable heartbeat checks.
 1.198 09-Feb-2023  abs Adjust _all_ cinclude of *.local files

- Ensure always at end
- Use tab rather than spaces
- Add consistent comment
"Pull in optional local configuration - always at end"

The only functional change is that a local file which tried to
override an existing setting (eg with "no foo") would have failed
in some cases before, but now will work
 1.197 07-Aug-2022  simonb branches: 1.197.4;
UFS/LFS dirhash:
- Enable UFS_DIRHASH if the architecture or kernel model specific config
file can use 128MB of RAM or more.
- Remove experimental tag from UFS_DIRHASH; it's been with RUMP kernel
and by a number of NetBSD developers for years.
- Add LFS_DIRHASH if LFS was enabled.
- Be somewhat consistent with FS options order.
 1.196 24-May-2022  bouyer PR kern/56853: add a dummy acpi_md_vbios_reset variable so that we
can again enable vga at pci for Xen.
Note that this only works in BIOS mode, not UEFI mode.
 1.195 24-May-2022  bouyer Looks like we finally can enable MSI/MSI-X on Xen
Should fix PR kern/56793 and PR kern/55667
 1.194 24-Sep-2021  manu Move XEN3_DOM0 as close as possible to GENERIC.
Document why some options are disabled
Set NO_PCI_MSI_MSIX to work around crashes reported in multiple PR
 1.193 29-Jun-2021  nia Remove uscanner(4) driver

This exists for compatibility with a Linux interface which was apparently
deprecated in Linux 2.6. There are various mailing list threads going
back to 2004 where the usefulness of this driver is discussed, but
the conclusion is that scanner software has all moved to using ugen(4)
instead, and enabling this driver will not help you scan things.
 1.192 05-Mar-2021  gdt branches: 1.192.4;
XEN3_DOM0: Approach GENERIC

When processed to remove comments, blank lines, normalize whitespace,
and sort/uniq (one line was previously duplicated), this file is
identical to the previous version. It has been reorganized to reduce
diffs to GENERIC, and many missing lines from GENERIC have been added
but commented out.
 1.191 04-Mar-2021  gdt XEN3_DOM0: Move closer to GENERIC (NFC)

This is another step in making XEN3_DOM0 closer to GENERIC. It is
just reordering lines, adding commented out lines, and adding a few
comments. (Test-booted with no dmesg change.)

This pass is showing cases where there are substantive and likely
undesired changes (e.g., UFS_ACL is not defined in XEN3_DOM0). Often
I added them but commented them out to preserve the NFC property of
this commit. My plan is to finish the easy NFC stuff first before
addressing functional changes.
 1.190 03-Mar-2021  gdt XEN3_DOM0: Move closer to GENERIC (NFC)

This commit reorders some lines, and brings in commented lines from
GENERIC to reduce the diff. It also brings in two agp lines,
commented out, and with a warning that they are intentionally omitted.
 1.189 02-Mar-2021  gdt XEN3_DOM0: Fix pckbc console attachment logic

Copy PCKBD_CNATTACH_MAY_FAIL lines from GENERIC to XEN3_DOM0.

GENERIC defines PCKBD_CNATTACH_MAY_FAIL, which means that an attempt
to activate console input on pckbc will fail if there is no keyboard
present. This is a problem on semi-modern machines that have pckbc
silicon but not ports, and thus almost always have a USB keyboard
also. What I suspect are bugs in console attachment logic lead to
attempting to attach a ukbd while there already is a console keyboard,
and with DIAGNOSTIC this is (properly) fatal, so XEN3_DOM0 blows up
with a USB keyboard in current, and probably not in 9.

Live tested on a machine that previously paniced on boot.
 1.188 02-Mar-2021  gdt XEN3_DOM0: Sync VERBOSE with GENERIC

Copy the *VERBOSE option block from GENERIC, and prune the scattered
verbose options in XEN3_DOM0, surely dating from a time they were
copied from an earlier GENERIC. This amounts to adding PCIVERBOSE and
SCSIVERBOSE, and the diff from GENERIC to DOM0 boots is markedly
reduced.
 1.187 01-Mar-2021  gdt amd64/conf/XEN3_DOM0: Add comment

This commit merely adds a comment explaining how XEN3_DOM0 ought to
relate to GENERIC.
 1.186 20-Jan-2021  nia remove compat_ossaudio from kernel modules

this is only useful with compat_linux and gets autoloaded when
compat_linux is loaded, so there's no reason to bake it into kernels
any more.
 1.185 27-Sep-2020  roy branches: 1.185.2;
vether: Add to kernel configurations

It's only enabled if the kernel enabled bridge AND tap.
Otherwise it's commented out.
 1.184 16-Aug-2020  jdolecek make COMPAT_LINUX option disabled by default

leave the option enabled only in amd64/i386 ALL kernels to make
sure it continues to be compilable also when included in kernel
 1.183 01-Aug-2020  maxv Remove references to BRIDGE_IPF, it is now compiled in by default.
 1.182 28-Jul-2020  jdolecek remove NO_PCI_MSI_MSIX again, enabling MSI for Xen Dom0 by default
 1.181 26-May-2020  jdolecek put back NO_PCI_MSI_MSIX, need to fix MSI issues reported in PR port-xen/55285
first
 1.180 22-May-2020  jdolecek remove NO_PCI_MSI_MSIX option, MSI is supported for XenPV Dom0
 1.179 16-May-2020  maya Remove uyap, USB YAP phone firmware loader.

And the associated ezload EZ-USB code, which is only used by uyap.
It could theoretically be used by other drivers, but none of them are
in tree.

I suspect that this device isn't in use, as phone technology has improved
a lot since 2001 when uyap(4) was added to the tree.

Proposed with no objections on netbsd-users on 13 April 2020
 1.178 13-May-2020  bouyer MULTIPROCESSOR for dom0 should be safe now. Enable it.
 1.177 25-Apr-2020  bouyer Disable -g, which got enabled by mistake in the bouyer-xenpvh merge
 1.176 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.175 09-Feb-2020  jmcneill branches: 1.175.4;
Retire azalia(4).
 1.174 29-Jan-2020  maya remove urio(4), a driver for the Rio500 MP3 player.

At this point it is highly unlikely this 1999 device still has users,
but it still comes up in the context of maxv's USB-fuzzing (and any device
could pretend to be a urio(4)), so it's best to get rid of it.

Renamed all major entries to obsolete, as was done in previous removals.

This still requires an update to sanitizers, but they're located in
"external", perhaps it should be first committed upstream?

Proposed on tech-kern a month ago.
 1.173 25-Jan-2020  thorpej Retire "le* at pci?" from the shipped kernel configs:
- If the config had both an le@pci and a pcn, simply remove le@pci
(pcn would match at a higher priority anyway).
- If the config had le@pci enabled, but no pcn, change le@pci to pcn.
- If the config had le@pci commented out, but no pcn, change le@pci
to pcn and leave it commented out.

The pcn driver supports more chips than le@pci and does DMA directly
to/from mbufs rather than memory copies.
 1.172 20-Jan-2020  thorpej Remove FDDI support.
 1.171 19-Jan-2020  thorpej Remove HIPPI support and the esh(4) driver that uses it. There have not
been any users of HIPPI for some time, and it is unlikely to be resurrected.
 1.170 01-Jan-2020  ryo branches: 1.170.2;
add aq(4)
 1.169 21-Aug-2019  maxv No USER_LDT on Xen.
 1.168 09-Aug-2019  rin xhci(4) is considered stable enough. So, remove misleading comments.

XXX
pullup to netbsd-9
 1.167 06-May-2019  sevan branches: 1.167.2;
Use filesystems.config to reduce duplication
 1.166 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.165 06-Feb-2019  rin Add ure(4) to kernel config files. Also add PHY drivers where necessary.
 1.164 02-Feb-2019  cherry Re-enable ixg(4) on NetBSD/xen dom0

Namespace conflicts have been resolved.

Note that driver still has an incorrect us of __asm() gnu primitives
via

#if __FreeBSD_version < 800000
...
#endif

Since __FreeBSD_version is undefined and thus equates to 0 and thus
satisfies the inequality.

Needs fixing by driver maintainer.
 1.163 02-Feb-2019  cherry Summary: Disable ixg(4) until the linuxist mb() API re-definition
within the XEN amd64 dom0 build is resolved.

Detail:
The xen public headers >= 0x00030201 depend on a linuxism - a memory
barrier "API" namely mb(), rmb() and wmb(). These are made accessible
to NetBSD code via the interface
sys/external/bsd/common/include/asm/barrier.h

Currently the ixg(4) driver uses an identical API by defining them
(incorrectly) to inline assembler macro definitions in
sys/dev/pci/ixgbe/ixgbe_osdep.h

This will result in the dom0 builds failing to build due to this
redefinition of the macros. We therefore disable the driver in
NetBSD/amd64 dom0 in order to facilitate smoothly moving the XEN
kernel builds to the new XEN source level API (RELEASE-4.11.1).

The fix for this is trivial, but needs the attention of the driver
maintainer.
 1.162 25-Dec-2018  mlelstv Make ipmi driver available to other platforms.
Add ACPI attachment.
 1.161 22-Dec-2018  cherry This change modifies the mainbus(4) entry point for all x86 sub-archs
in the following way:

i) It provides a unified entry point in
x86/x86/mainbus.c:mainbus_attach()
ii) It carves out the preliminary bus attachment sequence that is
common to all sub-archs into
x86/x86/mainbus.c: x86_cpubus_attach()
iii) It consolidates the remaining pathways as internal callee
functions so that these may be called piecemeal if required. A
special usecase of this is XEN PVHVM which may need to call the
native configure path, the xen configure path, or both.
iv) It moves the driver private data structures from
i386/i386_mainbus.c to an x86/ level one. This allows for other
sub-arch's to do similar, if needed. (They do not at the moment).
v) For dom0 kernels, it enables 'acpi0 at mainbus?' and
'acpi0 at hypervisorbus'. This serves two purposes:
a) To demonstrate the possibility of dynamic configuration tree
traversal ordering changes.
b) To allow for the common acpi_check(self, "acpibus") call in
x86/mainbus.c to not barf when it is called from the dom0 attach
path. We allow for the acpi0 device to be a child of mainbus with
the changes to amd64/conf/XEN3_DOM0 and i386/conf/XEN3PAE_DOM0
without actually probing further in the code. This path will later
be pursued in a PVHVM boot codepath.

There should be no operative changes with this change. If there are,
please complain loudly.
 1.160 12-Dec-2018  maxv Remove references to "lmc" in the kernel configurations.
 1.159 24-Nov-2018  bouyer Add mpii(4), a driver for LSI Megaraid Fusion controllers.
Ported from OpenBSD. This driver is MP-safe.
Note that the earlier fusion controllers (Megaraid 2208, codenamed Thunderbold)
are also supported by mfi(4). mpii will take precedence if both drivers
are enabled.
Tested on a
mfii0 at pci6 dev 0 function 0: "PERC H740P Adapter ", firmware 50.3.0-1512, 819
2MB cache
mfii0: interrupting at ioapic2 pin 2
scsibus0 at mfii0: 64 targets, 8 luns per target
scsibus0: waiting 2 seconds for devices to settle...
sd0 at scsibus0 target 0 lun 0: <DELL, PERC H740P Adp, 5.03> disk fixed
sd0: fabricating a geometry
sd0: 99 GB, 102399 cyl, 64 head, 32 sec, 512 bytes/sect x 209714688 sectors
sd0: tagged queueing
sd1 at scsibus0 target 1 lun 0: <DELL, PERC H740P Adp, 5.03> disk fixed
sd1: fabricating a geometry
sd1: 22254 GB, 22788608 cyl, 64 head, 32 sec, 512 bytes/sect x 46671069696 sectors
sd1: fabricating a geometry

It supports bioctl(8) ioctls, as well as sensors for the BBU and logical
drives.

Sponsored by LIP6.
 1.158 23-Oct-2018  jdolecek remove the 'wd* at umass?' for the non-standardized and rare (extinct?)
In-System Design ATA protocol over Bulk-Only devices from most kernels,
leave only in i386/amd64 ALL; it's unmaintained and likely currently broken,
lack of test hardware makes it impossible to support
 1.157 06-Sep-2018  maxv Retire the 'midway' driver. Discussed on tech-net@ recently and also three
years ago, part of removing the network ATM code.
 1.156 25-Aug-2018  rin Add (commented out) mue(4) to where appropriate.
Also add MII/PHY drivers for USB NICs if missing.
 1.155 14-Aug-2018  maxv Enable L2TP on all x86 configurations, not just native amd64.
 1.154 01-Aug-2018  maxv Unreference IPF/PF from the x86 config files (amd64, i386, xen), and enable
NPF instead when wanted.
 1.153 23-Jun-2018  jakllsch branches: 1.153.2;
Add acpiecdt* at acpi?.
 1.152 22-Jun-2018  darcy PR port-xen/50446
With approval from bouyer@ and acceptance, sometimes grudgingly, from
others I have removed the AGP lines from the XEN3_DOM0 config. I have
left a note in the PR suggesting that if it ever gets a proper fix that
those lines can be considered for re-inclusion.
 1.151 07-Jun-2018  thorpej Revert changes that pinned-down i2c parent specs. The i2c subsystem
has been enhanced to make this unnecessary.
 1.150 15-May-2018  thorpej Fully specifiy the location of indirectly-configured I2C devices. In
particular, the parent spec must not be wild-carded, as doing so doesn't
work well on systems where more than one I2C bus is present.

N.B. The x86 platforms are sort of a mess, here... legacy indirect
config and ACPI direct config sort of smashed together with the
same config file directives.
 1.149 17-Feb-2018  sevan branches: 1.149.2;
With the introduction of ddb.dumpstack which is enabled by default, we no longer
need to explicitly set DDB_COMMANDONENTER to run a trace.
 1.148 05-Feb-2018  bouyer Follow GENERIC and enable xhci(4) by default. PR port-xen/52978
 1.147 27-Jan-2018  pgoyette Update amdzentemp(4) attachment info. Also for ALL, remove duplicate
entry for amdtemp(4).
 1.146 25-Jan-2018  christos add amdzentemp
 1.145 23-Jan-2018  sevan Alternate buffer queue strategies no longer considered experimental, update
description.

Discussed on tech-kern
http://mail-index.netbsd.org/tech-kern/2018/01/21/msg023002.html
 1.144 13-Jan-2018  christos added commented out AUTOFS pseudo-device entries
 1.143 09-Jan-2018  christos Merge autofs support from: Tomohiro Kusumi
XXX: Does not work yet
 1.142 10-Dec-2017  bouyer Add dwiic, ihidev and ims
 1.141 06-Nov-2017  rin Revive commented out DISKLABEL_EI option to kernel configuration files
that contain FFS_EI option.
 1.140 30-Sep-2017  pgoyette Add commented-out ident lines to the XEN3_DOM{0,U} kernel config files
for consistency with other config files.

OK bouyer@
 1.139 14-Sep-2017  mrg clean up COMPAT_* options for native netbsd code:
- new series of files that are useful for saying "i want everything
since netbsd 1.4", etc.
- use the fact COMPAT_* options have future dependancies to remove
many redundant options.

removes about 3000 lines total across kernel configuration files.
tested about 30 random kernels in the changed list.
 1.138 10-Aug-2017  maxv Pff, I forgot to revert my change in these files. I committed only the
GENERIC files, and the message was:

Revert my changes, and re-enable COMPAT_NOMID, COMPAT_09 and COMPAT_43.
Several compat options happen to be dependent on the compat_43_* functions,
the availability of which is (wrongfully) controlled with COMPAT_43. Same
for COMPAT_09.
 1.137 28-Jul-2017  maxv After a careful review, and all things considered, disable compat43 by
default on amd64. The use case is limited, the potential for damage too
high, and it is safer to run a BSD4.3 binary on i386 since the kernel does
not have to go through netbsd32 - which may not correctly reproduce i386.
 1.136 22-Jun-2017  khorben Register support for SD card readers with Xen DOM0 kernels

Tested on a Lenovo ThinkPad T440s (amd64)
 1.135 20-Apr-2017  msaitoh branches: 1.135.4;
Add ixg(4). Fixes PR#52180 from Harry Waddell.

XXX pullup to netbsd-7
 1.134 17-Apr-2017  bouyer Disable MULTIPROCESSOR for dom0. The dom0 support code is not MP-safe
(see xen_shm_machdep.c for example, but there are probably others).
 1.133 17-Apr-2017  maya Uncomment MULTIPROCESSOR in dom0 kernels
 1.132 26-Feb-2017  rin Comment out DISKLABEL_RDB as it is too specific for general usage.
(Also add commented out that entry for GENERIC on amd64; I forgot it)
 1.131 26-Feb-2017  maya Remove commented DISKLABEL_EI for strictly little endian architectures

It will never be useful.
 1.130 26-Feb-2017  rin Add DKWEDGE_METHOD_RDB option, which is enabled for x86, commented out for
other platforms by default.
 1.129 19-Feb-2017  rin PR kern/51208
Add DISKLABEL_EI option (and also FFS_EI if missing), commented out except for
ALL on amd64 and i386.
 1.128 23-Jan-2017  christos PR/51908: Kyle Amon: Allow customization of XEN kernels via .local files.
 1.127 12-Jan-2017  ryo branches: 1.127.2;
white space police
 1.126 26-Dec-2016  cherry xen dom0 SMP is now bootable again.

add the 'options MULTIPROCESSOR' in respective configs, but mark them
experimental - and thus disabled by default.
 1.125 18-Dec-2016  dholland Whitespace.
 1.124 17-Dec-2016  maxv Add MODULAR in Xen kernels.
 1.123 13-Dec-2016  christos wildcard speaker attachments, now that we can handle many of them.
 1.122 10-Dec-2016  christos remove VAUDIOSPEAKER for now, will be done differently.
 1.121 08-Dec-2016  nat Add a synthesized pc beeper and keyboard bell for platforms with an audio
device.
 1.120 27-Jul-2016  msaitoh Add ichsmb(4), spdmem(4) and sdtemp(4).
 1.119 14-May-2016  christos branches: 1.119.2;
Turn on MPROTECT on GENERIC and both MPROTECT and ASLR on XEN*
 1.118 01-May-2016  nonaka Added nvme(4) for Non-Volatile Memory Host Controller Interface devices.
Ported from OpenBSD.
 1.117 19-Mar-2016  gdt Disable uscanner in all kernel configs

As discussed on current-users@, SANE uses ugen via libusb and not
uscanner, so users are not well served by having uscanner. Consensus
is that addressing how to adjust permissions for scanners should not
block restoring basic functionionality.

(Compile-tested only, but there are multiple reports of this being the
right approach.)
 1.116 10-Nov-2015  tnn Add "pseudo-device iscsi" to ALL and as a commented out hint in XEN3_*
 1.115 08-Aug-2015  maxv Remove KMEMSTATS.
 1.114 16-Jul-2015  bouyer Uncoment options IPSEC, as requested by Gary Duzan in PR port-amd64/50052
 1.113 17-Feb-2015  nonaka Add iwm(4).
 1.112 16-Nov-2014  manu branches: 1.112.2;
Remove unused extended attributes kernel options

As Masao Uebayashi pointed to me, UFS_EXTATTR_AUTOSTART, LFS_EXTATTR_AUTOSTART
and UFS_EXTATTR_AUTOCREATE are not used anywhere in the code. Remove them
as they have been obsolete for a long time:
UFS_EXTATTR_AUTOSTART was replaced by mount -o extattr
LFS_EXTATTR_AUTOSTART was created to match obsolete UFS_EXTATTR_AUTOSTART
UFS_EXTATTR_AUTOCREATE was replaced by sysctl vfs.ffs.extattr_autocreate
 1.111 12-Nov-2014  manu Support for UFS1 extended attributes in GENERIC and GENERIC-like kernels

This change just brings UFS1 extended attribute *support* in the kernel,
extended attributes are not enabled unless three conditions are met:
1) filesystem is UFS1 (newfs -O1)
2) .attribute/system and .attribute/user directories are created at fs root
3) filesystem is mounted with -o extattr

Some GENERIC kernels are obviously memory constrained, the extended
attributes options were not enabled for them, but just added commented out.
(kernel were considered memory constrained if QUOTA option was disabled)
 1.110 18-Oct-2014  uebayasi Install agp_* drivers where pchb(4) is installed except INSTALL_FLOPPY.

XXX
Config around agp(4) is done in quite wrong direction.
"pchb <- (agpbus) <- agp <- agp_*"
should be:
"pchb <- (pcibus) <- agp_* <- (agpbus) <- agp"
 1.109 11-Oct-2014  uebayasi Don't include std.ath_hal for XEN3_DOMU.
 1.108 19-Sep-2014  christos Add HDAUDIOVERBOSE
 1.107 19-Sep-2014  christos Disable BSDLABEL and MBR DKWEDGE methods again since sysinst does not work
with wedges.
 1.106 23-Aug-2014  dholland Systematize (and in many cases, fix) the comments on options COMPAT_NN.

There are quite a few configs that are missing some COMPAT_NN options
in ways that don't make sense; this should probably get cleaned up
too, but for the time being I've not added or removed anything.
 1.105 18-Aug-2014  christos - Enable Wedge support for MBR/BSDLABEL where it was commented out.
- Add apple partition support where it was missing
- Add comments where missing
 1.104 16-Aug-2014  apb Add "options COMPAT_70" to all kernel configuration files that
already had "options COMPAT_60".
 1.103 25-Jul-2014  dholland branches: 1.103.2;
Fix description of DIAGNOSTIC in x86 kernels.
 1.102 16-Jun-2014  dsl Comment out the xhci entries.
The driver really doesn't work well enough to be generally useful.
 1.101 24-Mar-2014  szptvlfn branches: 1.101.2;
fix manual section numbering of sysctl.
thanks wiz@
 1.100 17-Feb-2014  schmonz Add urtw (ok'd by christos).
 1.99 23-Oct-2013  matt Add xhci device
 1.98 30-Jun-2013  rmind G/C PFIL_HOOKS from the kernel configs.
 1.97 05-Jun-2013  christos branches: 1.97.2;
remove obsolete networking options
 1.96 27-Apr-2013  christos the bogus number police
 1.95 27-Apr-2013  christos remove confusing numeric locators where they are unused.
 1.94 02-Mar-2013  christos Under FAST_IPSEC, IPSEC_ESP is mandatory; GC it.
 1.93 01-Mar-2013  joerg Retire OSI network stack. OK core@
 1.92 09-Feb-2013  khorben Added wpi(4) to the XEN3_DOM0 kernel for both amd64 and i386
Tested on a Lenovo ThinkPad T60 2007 (amd64)
 1.91 30-Nov-2012  riz Add alc* at pci, re-sort slightly to reduce diffs from GENERIC.
 1.90 17-Oct-2012  apb Add "options COMPAT_60" to all kernel configuration files
that already had "options COMPAT_50".
 1.89 04-Oct-2012  dsl Remove references to VM86 from the amd64 kernel configs.
VM86 mode isn't supported while in long mode.
 1.88 24-Sep-2012  khorben Enable support for synaptics touchpads when running Xen as domain 0; helps
usability on laptops. Fixes PR port-xen/44055.

ok bouyer@ riz@
 1.87 23-Sep-2012  chs add vmt entry to GENERIC.
standardize commented pfsync and npf entries.
 1.86 01-Sep-2012  jakllsch branches: 1.86.2;
Rename RT2500USB driver to ural(4) as it was originally in OpenBSD,
as ural(4) and ral(4) do not actually share any code.

Enable ural(4) in hpcarm WZERO3 kernel too, as it will now build.

Fixes PR#43520.
 1.85 22-Jun-2012  khorben Disable azalia(4) now that hdaudio(4) was switched on

ok bouyer@
 1.84 05-Jun-2012  abs Adjust the WSDISPLAY_COMPAT_USL comment to mention wsconscfg, to at least
give a hint that its not just for third party compat. No functional change.
 1.83 19-Apr-2012  bouyer Add mpii(4), a driver for LSI Logic Fusion-MPT Message Passing Interface II
SAS controllers. Ported from OpenBSD.
 1.82 13-Apr-2012  cegger Replace amdtempbus with amdnb_miscbus.
This allows us to have independent drivers on the same device (northbridge f3)
each coming with a certain functionality/feature.
This way we do not need to mess with amdtemp(4) to utilize other features.
 1.81 10-Mar-2012  joerg P1003_1B_SEMAPHORE is no longer optional.
 1.80 25-Feb-2012  bouyer Also comment out ACPIVERBOSE and MPVERBOSE
 1.79 25-Feb-2012  bouyer Also comment out MPDEBUG
 1.78 25-Feb-2012  bouyer Comment out options DEBUG from Xen kernel; also comment out
makeoptions DEBUG="-g" where it was still enabled.
 1.77 13-Jan-2012  cegger branches: 1.77.2;
Support CPU microcode loading via cpuctl(8).
Implemented and enabled via CPU_UCODE kernel config option
for x86 and Xen Dom0.
Tested on different AMD machines with different
CPU families.

ok wiz@ for the manpages
ok releng@
ok core@ via releng@
 1.76 18-Dec-2011  dholland WABPL is no longer considered experimental (has not been for some time)
so update its comment in config files.
 1.75 22-Nov-2011  tls branches: 1.75.2;

The rnd pseudo-device is not really optional, because it is in the same
source file as the entropy-pool code itself. Move it to std. This
will be cleaned up more when I split the sources up as they should be.

This fixes build breaks on several ports. Thanks to Havard Eidnes for
pointing them out.
 1.74 25-Oct-2011  jakllsch branches: 1.74.2;
Per existing x86 GENERIC kernels, add:
#options BUFQ_READPRIO
options BUFQ_PRIOCSCAN
to Xen kernels.
 1.73 03-Oct-2011  jmcneill remove iic, I fixed the i2c code
 1.72 03-Oct-2011  mbalmer Enable an iic(4) device to prevent a linker warning.
 1.71 18-Aug-2011  jakllsch Attach amdtemp(4) at pchb(4) instead of in place of pchb(4).

Should fix PR#45268.
 1.70 23-Jul-2011  jakllsch Enable or note aubtfwl(4) wherever ubt(4) is enabled or noted.
 1.69 20-Jul-2011  jakllsch Add urndis(4).
 1.68 28-May-2011  ryo many whitespace cleanup.
 1.67 29-Apr-2011  jym Enable balloon(4) for Xen kernels.

ok bouyer@; shortly discussed on port-xen@.
 1.66 18-Apr-2011  jym Large rewrite of the balloon driver. This one:

- turns balloon into a driver that attaches to xenbus(4). This allows to
disable the functionality either at compile time or boot time via
userconf(4). Driver can implement detach or pmf(9) hooks if deemed
necessary.

- keeps Cherry's locking model, but simplify it a bit. There is now
only one target value serialized inside balloon, we do not feedback
alternative value to Xenstore (clients are not expected to see its value
evolve behind their back, and can't do much about that either)

- implements min threshold; this is an admin-settable value that tells
driver to "not balloon below this threshold." This can be used by domain
to keep memory reservations, useful if activity is expected in the near
future.

- in addition to min threshold, the driver implements internally a
safeguard value (uvmexp.freemin + 1MiB), so that admin cannot
inadvertently set min to a very low value forcing domain into heavy
memory pressure and swapping.

- create the sysctl(8) kern.xen.balloon tree. 4 nodes are actually present
(values are in KiB):
- min: (rw) an admin-settable value that prevents ballooning below this
mark
- max: (ro) the maximum size for reservation, as set by xm(1) mem-max.
- current: (ro) the current reservation for domain.
- target: (rw) the targetted reservation for domain.

- fix a few limitations here and there, most notably the max_reservation
hypercall, and KiB vs pages representations at interfaces.

The driver is still turned off by default. Enabling it would need more
approval, especially from bouyer@, cherry@ and cegger@.

FWIW: tested it two days long, from amd64 dom0 (with dom0 ballooning
enabled for xend), and bunch of domUs. Did not notice anything suspicious.

XXX it still has one big limitation: it cannot hotplug memory pages in
uvm(9) if they were not present beforehand. Example: ballooning above
physmem will give more pages to domain but it won't use it to serve
allocations, unless we teach uvm(9) how to handle the extra pages.
 1.65 06-Mar-2011  bouyer merge the bouyer-quota2 branch. This adds a new on-disk format
to store disk quota usage and limits, integrated with ffs
metadata. Usage is checked by fsck_ffs (no more quotacheck)
and is covered by the WAPBL journal. Enabled with kernel
option QUOTA2 (added where QUOTA was enabled in kernel config files),
turned on with tunefs(8) on a per-filesystem
basis. mount_mfs(8) can also turn quotas on.

See http://mail-index.netbsd.org/tech-kern/2011/02/19/msg010025.html
for details.
 1.64 24-Feb-2011  jruoho Move PowerNow! to the cpufeaturebus.
 1.63 24-Feb-2011  jruoho Add cpufeaturebus and est(4) for Xen.
 1.62 23-Feb-2011  jruoho Move ENHANCED_SPEEDSTEP, or henceforth est(4), to the cpufeaturebus.
 1.61 27-Nov-2010  christos branches: 1.61.2; 1.61.4;
add ihphy
 1.60 23-Nov-2010  hannken Remove unused count from pseudo-device md.
 1.59 13-Nov-2010  jnemeth Add new et(4)/etphy(4) devices.
 1.58 06-Nov-2010  jakllsch Enable siisata(4) in Xen dom0 kernels.
 1.57 12-Aug-2010  haad dd dm driver to XEN configs because they do not have modules working yet.
This will enable using LVM by default on XEN DOM0 hostings running NetBSD.

Change suggested by Sam Fourman.
 1.56 06-Jul-2010  cherry The Xen balloon driver enables growing and shrinking
PV domains on the fly, by collaborating with UVM and the hypervisor
 1.55 26-Jun-2010  bouyer Sync DKWEDGE options with GENERIC
 1.54 22-May-2010  plunky add btmagic(4) where other Bluetooth drivers are listed
 1.53 16-Apr-2010  pooka Remove unused count (invariably "4") from pseudo-device fss.
 1.52 07-Mar-2010  plunky branches: 1.52.2;
add uhso(4) device where appropriate
- follow the lead of other USB driver declarations wrt commented out
- (cross-)build tested all these kernels
 1.51 06-Mar-2010  cnst remove aiboost(4) from GENERICs, since it cannot win in autoconf(9) over aibs(4); ok pgoyette
 1.50 21-Feb-2010  cnst New wbsio(4) driver for Winbond Super I/O attachment of lm(4) on any port.

http://mail-index.netbsd.org/tech-kern/2010/02/17/msg007338.html

Reviewed by <pgoyette>, <tech-kern>.
 1.49 09-Feb-2010  cnst New aibs(4) driver for ASUSTeK AI Booster (ACPI ATK0110) hardware monitor
with limit support.

http://thread.gmane.org/gmane.os.netbsd.devel.kernel/35654

Reviewed by <pgoyette>, <jruoho> and <tech-kern>.
 1.48 17-Dec-2009  jym branches: 1.48.2;
Compile in PaX support for Xen x86 kernels (dom0 and domU).

ok bouyer@. Compiled and tested by me under i386. Only compile tested for
amd64.
 1.47 05-Dec-2009  pooka Remove the portalfs kernel file system driver. Replace mount_portal(8)
with a version based on puffs. User functionality remains the same.
 1.46 07-Sep-2009  jmcneill Switch on hdaudio(4)
 1.45 07-Sep-2009  jmcneill Refer to hdaudio as 'High Definition Audio', not
'Intel High Definition Audio' as many vendors implement the HD audio spec.
 1.44 06-Sep-2009  sborrill hdaudio(4) is a standards-compliant driver for Intel High Definition Audio.
It will replace azalia(4) after testing.

To use, comment out azalia in your kernel configuration and uncomment the
hdaudio and hdafg lines so it reads:

# Intel High Definition Audio
hdaudio* at pci? dev ? function ?
hdafg* at hdaudiobus?

You should also:
cd /dev
sh MAKEDEV audio
 1.43 05-Aug-2009  jym Add Intel SpeedStep and AMD PowerNow! support in Xen dom0. MSR operations
are now compiled in by default.

Note that MSR support in Xen depends on its version. rdmsr() should always
succeed, but wrmsr() to certain registers can end in a NOOP. In that case,
the error will be logged (see xm dmesg).

Setting CPU frequency (SpeedStep) requires Xen 3.3 with the option
cpufreq="dom0-kernel" passed down to hypervisor during boot.

Compiled and tested for SpeedStep under i386 for XEN3_DOM0 and XEN3PAE_DOM0
by jym@. amd64 was tested by Joel Carnat.

See also http://mail-index.netbsd.org/port-xen/2009/08/02/msg005213.html .

Commit requested by bouyer@.
 1.42 20-Apr-2009  cegger add age(4)
 1.41 20-Apr-2009  cegger add ale(4)
 1.40 25-Mar-2009  cegger catch up with i386 xen kernels:
enable cgd by default
 1.39 06-Mar-2009  cegger add options COMPAT_50
 1.38 06-Mar-2009  cegger add age(4) and atphy(4)
 1.37 05-Mar-2009  bouyer Add pciback device to XEN3 dom0 kernels
 1.36 04-Mar-2009  nisimura comment out NFS_BOOT_BOOTSTATIC. It will be useful when a valid set of
NFS_BOOTSTATICs are specfied.
 1.35 24-Nov-2008  ad branches: 1.35.4;
Remove softdep, pass 1. We are focused on improving journalling.

Proposed on tech-kern@.
 1.34 12-Nov-2008  ad Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.
 1.33 21-Oct-2008  cegger branches: 1.33.2; 1.33.4; 1.33.8;
catch up with GENERIC
- add verbose options (commented out)
- add descriptive comments
- sort them alphabetically
 1.32 19-Oct-2008  joerg Add u3g entries in kernels that have ugensa as well.
 1.31 11-Oct-2008  bouyer jme(4), a driver for JMicron Technologies JME250 Gigabit Ethernet and
JME260 Fast Ethernet PCI Express controllers.
Written with a lot of cut-n-paste from the FreeBSD jme(4) driver.
No support for jumbo ethernet frames yet (but should come soon).
Thanks to JMicron Technologies for providing me sample boards and
documentation for this work.
 1.30 07-Oct-2008  pgoyette Move all platforms to new dbCool driver in preparation for removal of
chip-specific drivers
 1.29 30-Sep-2008  jmcneill Remove esl(4)
 1.28 17-Sep-2008  cegger Add amdtemp(4) to Xen Dom0 kernels.
 1.27 09-Sep-2008  ober Adding iwn(4) to GENERIC
 1.26 25-Aug-2008  cegger GENERIC: add auacer(4) which is already in XEN3_DOM0
XEN3_DOM0: add azalia(4) which is already in GENERIC
 1.25 21-Aug-2008  bouyer Enable ipmi(4) by default in GENERIC and related kernels.
 1.24 10-Aug-2008  cegger Add accept filters per request from port-xen:
http://mail-index.netbsd.org/port-xen/2008/08/10/msg004087.html

pseudo-device entries were copied from sys/arch/i386/conf/GENERIC, rev. 1.904
 1.23 03-Aug-2008  joerg Reduce diff to GENERIC for compat options.
 1.22 03-Aug-2008  joerg Remove SYSV IPC options as they have been replaced with sysctls.
 1.21 31-Jul-2008  cegger Add "options WAPBL" to Xen configs
 1.20 05-Jun-2008  cegger branches: 1.20.4;
add pckbc at acpi
add pcppi at acpi
 1.19 05-Jun-2008  cegger add aiboost at acpi
 1.18 26-May-2008  ad Disable OSI networking.
 1.17 18-May-2008  cegger acpidalb(4): Driver for PNP0C32 Hotkeys aka "Direct Application Launch Buttons".
"awesome" jmcneill
 1.16 01-May-2008  cegger branches: 1.16.2;
hpqlb(4): driver for HP Quick Launch buttons - found on HP Pavilion Notebooks
 1.15 21-Apr-2008  cegger branches: 1.15.2;
add acpitz at acpi
 1.14 29-Mar-2008  cube branches: 1.14.2;
Add and enable lii(4) in amd64 configurations, too, as it is very likely
the hw is used on amd64-capable otherboards, although it is not confirmed
yet.
 1.13 27-Mar-2008  tnn Revert for DOM0 as well at request of Christoph Egger.
I guess this bootstatic stuff is supposed to play nicely with dhcp,
but it still doesn't for me. I suspect it's due to misdetecting the bootdev.
 1.12 27-Mar-2008  tnn Comment out NFS_BOOT_BOOTSTATIC. There no use having it in the default
kernel as it needs manual configuration anyway. Also, if it's enabled
but no static options given, then the kernel will happily configure the
interface as INADDY_ANY and not even try to use DHCP.
 1.11 01-Mar-2008  bouyer Add wscons options, pointed out by Jonathan A. Kollasch on port-xen@
 1.10 29-Feb-2008  jmmv Remove GENERIC.local from the repository

Make all the kernels that currently include their corresponding GENERIC.local
file use the cinclude directive instead of include. This way config(1) will
not complain if the file cannot be found.

After doing this, remove the GENERIC.local files from the repository so that
the user will not see modified files during updates, and local changes to
them cannot end up in the repository by mistake.

Discussed in tech-kern@ earlier this month. No strong objections.
 1.9 16-Feb-2008  bouyer branches: 1.9.2; 1.9.6;
Sync with GENERIC, add options ACPI_SCANPCI and MPBIOS_SCANPCI,
as well as commented out ACPI_ACTIVATE_DEV and ACPICA_PEDANTIC.
Should fix PR kern/37996.
 1.8 02-Feb-2008  joerg amd64 kernels should use amd64 GENERIC.local.
 1.7 07-Jan-2008  martti branches: 1.7.2;
Fixed option indentation, it should be

option<space><tab>
makeoption<space><tab>
 1.6 31-Dec-2007  ad Remove systrace. Ok core@.
 1.5 17-Dec-2007  riz Add drvctl(4)
 1.4 07-Dec-2007  xtraeme branches: 1.4.2; 1.4.4; 1.4.8;
Enable arcmsr(4).
 1.3 06-Dec-2007  bouyer Remove MAXPHYS=32768 (coming from a too large cut-n-paste), it's not needed
for dom0 kernels.
 1.2 22-Nov-2007  bouyer branches: 1.2.2; 1.2.4; 1.2.6;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.1 16-Nov-2007  bouyer branches: 1.1.2;
file XEN3_DOM0 was initially added on branch bouyer-xenamd64.
 1.1.2.2 19-Nov-2007  bouyer Get rid of arch/xenamd64, step 1: empty xenamd64/conf
- move xenamd64/conf/std.xen to amd64/conf/
- define arch to amd64 amd64/conf/std.xen, and i386 in xen/conf/std.xen
(machine is xen)
- enclose content of amd64/conf/files.amd64 and i386/conf/files.i386 in
ifndef xen/endif, so it can be transparently inclued for xen kernels
- support MACHINE_ARCH=x86_64 in xen/conf/Makefile*
 1.1.2.1 16-Nov-2007  bouyer Initial domain0 support for xenamd64. The kernel boots multiuser, but
xen tools have not been tried yet.
In this process, cleanup some more the page table bootstrap, and properly
handle event counters for soft interrupts.
 1.2.6.2 26-Dec-2007  ad Sync with head.
 1.2.6.1 08-Dec-2007  ad Sync with head.
 1.2.4.2 03-Dec-2007  ad Sync with HEAD.
 1.2.4.1 22-Nov-2007  ad file XEN3_DOM0 was added on branch vmlocking on 2007-12-03 19:02:44 +0000
 1.2.2.3 09-Dec-2007  jmcneill Sync with HEAD.
 1.2.2.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.2.2.1 22-Nov-2007  joerg file XEN3_DOM0 was added on branch jmcneill-pm on 2007-11-27 19:35:29 +0000
 1.4.8.2 08-Jan-2008  bouyer Sync with HEAD
 1.4.8.1 02-Jan-2008  bouyer Sync with HEAD
 1.4.4.4 18-Feb-2008  mjf Sync with HEAD.
 1.4.4.3 27-Dec-2007  mjf Sync with HEAD.
 1.4.4.2 08-Dec-2007  mjf Sync with HEAD.
 1.4.4.1 07-Dec-2007  mjf file XEN3_DOM0 was added on branch mjf-devfs on 2007-12-08 18:16:27 +0000
 1.4.2.6 17-Mar-2008  yamt sync with head.
 1.4.2.5 27-Feb-2008  yamt sync with head.
 1.4.2.4 04-Feb-2008  yamt sync with head.
 1.4.2.3 21-Jan-2008  yamt sync with head
 1.4.2.2 07-Dec-2007  yamt sync with head
 1.4.2.1 07-Dec-2007  yamt file XEN3_DOM0 was added on branch yamt-lazymbuf on 2007-12-07 17:24:01 +0000
 1.7.2.3 23-Mar-2008  matt sync with HEAD
 1.7.2.2 09-Jan-2008  matt sync with HEAD
 1.7.2.1 07-Jan-2008  matt file XEN3_DOM0 was added on branch matt-armv6 on 2008-01-09 01:44:50 +0000
 1.9.6.6 17-Jan-2009  mjf Sync with HEAD.
 1.9.6.5 05-Oct-2008  mjf Sync with HEAD.
 1.9.6.4 28-Sep-2008  mjf Sync with HEAD.
 1.9.6.3 05-Jun-2008  mjf Sync with HEAD.

Also fix build.
 1.9.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.9.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.9.2.1 24-Mar-2008  keiichi sync with head.
 1.14.2.3 17-Jun-2008  yamt sync with head.
 1.14.2.2 04-Jun-2008  yamt sync with head
 1.14.2.1 18-May-2008  yamt sync with head.
 1.15.2.7 09-Oct-2010  yamt sync with head
 1.15.2.6 11-Aug-2010  yamt sync with head.
 1.15.2.5 11-Mar-2010  yamt sync with head
 1.15.2.4 16-Sep-2009  yamt sync with head
 1.15.2.3 19-Aug-2009  yamt sync with head.
 1.15.2.2 04-May-2009  yamt sync with head.
 1.15.2.1 16-May-2008  yamt sync with head.
 1.16.2.4 10-Oct-2008  skrll Sync with HEAD.
 1.16.2.3 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.16.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.16.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.20.4.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.20.4.1 19-Oct-2008  haad Sync with HEAD.
 1.33.8.1 21-Apr-2010  matt sync to netbsd-5
 1.33.4.7 19-Jun-2013  bouyer Pullup the following revisions via patch, requested by msaitoh in ticket #1850:
sys/dev/pci/if_wm.c 1.201, 1.203-1.204,
1.207-1.212, 1.215,
1.217-1.218, 1.220-1.223,
1.228, 1.232-245
sys/dev/pci/if_wmreg.h 1.40-1.45, 1.47-1.48
sys/dev/pci/if_wmvar.h 1.11-1.13
sys/dev/pci/pcidevs 1.1074, 1.1077, 1.1117
sys/dev/pci/pcidevs.h regen
sys/dev/pci/pcidevs_data.h regen
sys/dev/mii/igphyreg.h 1.6
sys/dev/mii/ihphy.c 1.1-1.2
sys/dev/mii/ihphyreg.h 1.1
sys/dev/mii/inbmphyreg.h 1.3
sys/dev/mii/files.mii 1.47 via patch
sys/dev/mii/miidevs 1.97 and 1.100
sys/dev/mii/miidevs.h regen
sys/dev/mii/miidevs_data.h regen
sys/arch/i386/conf/ALL 1.280
sys/arch/i386/conf/GENERIC 1.1001
sys/arch/i386/conf/INSTALL_FLOPPY 1.11
sys/arch/i386/conf/XEN2_DOM0 patch
sys/arch/amd64/conf/GENERIC 1.293
sys/arch/amd64/conf/XEN3_DOM0 1.61
share/man/man4/wm.4 1.21-1.24

Apply almost all fixes and improvements from netbsd-6 except for
the rev. 1.196's iqdrops' change.

- Add the detach code.
- Add code for WOL, ASF, IPMI and Intel AMT. WOL is disabled by default
- Add Yet another workaround for ICH8.
- 82576 is dual port, so check the FUNCID and increment the MAC address for
the 2nd port.
- Fix the names of 82577L[MC] LAN controllers (for mobile).
- Fix CTRL_EXT_SWDPIN() and CTRL_EXT_SWDPIO() macros. The bit order of the
SW definable pin is not 6543 but 3654!!!
- Rewrite the code to read MAC address from eeprom.
- Add 82580 support.
- 82571 quirk. Only 82571 shares port 0 of EEMNGCTL_CFGDONE.
- The document says that the TDH register must be set after
TCL.EN is set on 82575 and newer devices.
- Fix some register names. No functional change.
- Omit U+00AE "REGISTERED SIGN" in a product name due to its non-ASCII nature.
- Stop wm(4) from needlessly resetting when you add or delete a vlan(4).
- Fix MAC address check on 8257[156] and 80003 case. Some cards have non 0xffff
pointer but those don't use alternative MAC address in reality. So we check
whether the broadcast bit is set or not like Intel's e1000 driver.
Fixes PR kern/44072 reported by Jean-Yves Moulin.
- Add PCH2(and 82579) support. Fixes PR#46487
- Add yet another 82567V support.
- Add ICH10+HANKSVILL support.
- Add support Intel I350 Ethernet.
- Make vlan and all ip/ip6 checksum offload work for the I350.
- Fix compile error with WM_DEBUG.
- Fix a bug that PHY isn't set to low-power mode on PCH and PCH2.
- Add WM_DEBUG_NVM. If WM_DEBUG_NVM is enabled, dump the FLASH ROM data.
- Skip 64bit BAR correctly.
- Fix RAL_TABSIZE for ICH8, 82576, 82580 and I350.
- Use 82580(and I350) specific PHY read/write functions. Fixes PR#47542.
- Style fix. Fix typo in comment. Fix comments. Add comments.
 1.33.4.6 21-Nov-2010  riz Pull up following revision(s) (requested by bouyer in ticket #1419):
sys/arch/i386/conf/XEN2_DOM0: patch
sys/arch/amd64/conf/XEN3_DOM0: revision 1.55
Sync DKWEDGE options with GENERIC
 1.33.4.5 21-Nov-2010  riz Pull up following revision(s) (requested by plunky in ticket #1407):
sys/dev/bluetooth/btdev.h: revision 1.9
sys/arch/iyonix/conf/GENERIC: revision 1.60
sys/arch/sparc64/conf/GENERIC: revision 1.129
sys/dev/usb/hid.c: revision 1.30
sys/dev/usb/hid.h: revision 1.13
sys/arch/i386/conf/GENERIC: revision 1.983
usr.sbin/btdevctl/print.c: revision 1.10
sys/arch/evbarm/conf/MPCSA_GENERIC: revision 1.16
sys/arch/alpha/conf/GENERIC: revision 1.337
sys/dev/bluetooth/files.bluetooth: revision 1.14
sys/arch/evbarm/conf/GUMSTIX: revision 1.49
sys/dev/usb/usbdevs: revision 1.550
sys/arch/evbppc/conf/OPENBLOCKS266_OPT: revision 1.14
sys/arch/hpcsh/conf/GENERIC: revision 1.91
sys/dev/bluetooth/btmagic.c: revision 1.1
distrib/sets/lists/man/mi: revision 1.1210
sys/arch/amd64/conf/GENERIC: revision 1.279
sys/arch/i386/conf/ALL: revision 1.258
sys/arch/amd64/conf/XEN3_DOM0: revision 1.54
sys/arch/hpcarm/conf/JORNADA720: revision 1.78
sys/dev/usb/hid.c: revision 1.29
share/man/man4/btmagic.4: revision 1.1
hid_get_data() does not work if the size of data is less than
a byte and crosses a byte boundary, and it always returns a
sign-extended value.
fix this by using the algorithm from libusbhid to read bytes,
and provide a hid_get_udata() function to return unsigned data
values.
while here, const args
update DPRINTF to reflect actual function name
add Apple Magic Mouse product-id
regen for Magic Mouse id
allow for vendor-id and product-id properties, passing them
through to child devices
add Magic Mouse driver and manpage btmagic(4)
additionally query the "PnP Information" service record to discover
any USB Forum vendor-id and product-id values and store them in the
property list if found.
add btmagic(4) where other Bluetooth drivers are listed
 1.33.4.4 15-Feb-2010  sborrill Pull up the following revisions(s) (requested by tron in ticket #1306):
sys/arch/i386/conf/XEN2_DOM0 patch
sys/arch/i386/conf/XEN2_DOMU patch
sys/arch/amd64/conf/XEN3_DOM0 patch
sys/arch/amd64/conf/XEN3_DOM0 patch

Enable cgd(4) support on all amd64 and i386 XEN kernels.
 1.33.4.3 03-Oct-2009  snj Pull up following revision(s) (requested by bouyer in ticket #1054):
sys/arch/amd64/conf/XEN3_DOM0: revision 1.37
sys/arch/i386/conf/XEN3_DOM0: revision 1.12
Add pciback device to XEN3 dom0 kernels
 1.33.4.2 26-Sep-2009  snj Pull up following revision(s) (requested by jmcneill in ticket #946):
distrib/sets/lists/man/mi: revision 1.1155
doc/CHANGES: revision 1.1285
etc/MAKEDEV.tmpl: revision 1.128
share/man/man4/Makefile: revision 1.498 via patch
share/man/man4/hdaudio.4: revision 1.1-1.3
share/man/man8/MAKEDEV.8: revision 1.36
sys/arch/amd64/conf/GENERIC: revision 1.250-1.251
sys/arch/amd64/conf/XEN3_DOM0: revision 1.44-1.45
sys/arch/i386/conf/ALL: revision 1.206-1.207
sys/arch/i386/conf/GENERIC: revision 1.942-1.943
sys/arch/i386/conf/XEN3_DOM0: patch
sys/conf/majors: revision 1.47 via patch
sys/dev/pci/hdaudio/files.hdaudio: revision 1.1-1.2
sys/dev/pci/hdaudio/hdaudio.c: revision 1.1-1.4
sys/dev/pci/hdaudio/hdaudio_afg.c: revisions 1.1-1.14
sys/dev/pci/hdaudio/hdaudio_mixer.h: revisions 1.1-1.3
sys/dev/pci/hdaudio/hdaudio_pci.c: revisions 1.1-1.2
sys/dev/pci/hdaudio/hdaudioio.h: revisions 1.1-1.2
sys/dev/pci/hdaudio/hdaudioreg.h: revisions 1.1-1.3
sys/dev/pci/hdaudio/hdaudiovar.h: revisions 1.1-1.4
sys/dev/pci/files.pci: revisions 1.319 and 1.322 via patch
hdaudio(4) is a standards-compliant driver for High Definition Audio.
It will replace azalia(4) after testing.
To use, comment out azalia in your kernel configuration and uncomment the
hdaudio and hdafg lines so it reads:
hdaudio* at pci? dev ? function ?
hdafg* at hdaudiobus?
You should also:
cd /dev
sh MAKEDEV audio
 1.33.4.1 03-May-2009  snj Pull up following revision(s) (requested by cegger in ticket #735):
sys/dev/pci/if_age.c: revisions 1.1-1.28
sys/dev/pci/if_agereg.h: revisions 1.1-1.2
sys/dev/pci/if_ale.c: revisions 1.1-1.3
sys/dev/pci/if_alereg.h: revisions 1.1-1.2
sys/dev/pci/files.pci: revisions 1.310-1.313
sys/dev/mii/atphy.c: revisions 1.1-1.5
sys/dev/mii/files.mii: revision 1.42
share/man/man4/age.4: revisions 1.1-1.3
share/man/man4/ale.4: revisions 1.1-1.2
share/man/man4/atphy.4: revisions 1.1-1.2
share/man/man4/Makefile: revisions 1.486, 1.489
distrib/sets/lists/man/mi: revisions 1.1118, 1.1132
sys/arch/i386/conf/GENERIC: revisions 1.928, 1.933
sys/arch/i386/conf/XEN2_DOM0: revisions 1.57, 1.60
sys/arch/amd64/conf/GENERIC: revisions 1.239, 1.241
sys/arch/amd64/conf/XEN3_DOM0: revisions 1.38, 1.42
Add the age(4) and ale(4) drivers for Attansic L1 and Atheros
AR8121/AR8113/AR8114 devices respectively.
 1.33.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.33.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.35.4.7 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.35.4.6 02-May-2011  jym Sync with head.
 1.35.4.5 29-Mar-2011  jym More sync fixes. And add the mbr_gpt files.
 1.35.4.4 28-Mar-2011  jym Cure sync hiccups. Code with compile errors is not really useful, heh.
 1.35.4.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.35.4.2 01-Nov-2009  jym Sync with HEAD.
 1.35.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.48.2.3 09-Nov-2010  uebayasi Sync with HEAD.
 1.48.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.48.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.52.2.5 31-May-2011  rmind sync with head
 1.52.2.4 21-Apr-2011  rmind sync with head
 1.52.2.3 05-Mar-2011  rmind sync with head
 1.52.2.2 03-Jul-2010  rmind sync with head
 1.52.2.1 30-May-2010  rmind sync with head
 1.61.4.2 05-Mar-2011  bouyer Sync with HEAD
 1.61.4.1 08-Feb-2011  bouyer Add QUOTA2 where QUOTA is enabled (and QUOTA2 commented out where QUOTA
is commented out)
 1.61.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.74.2.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.74.2.4 16-Jan-2013  yamt sync with (a bit old) head
 1.74.2.3 30-Oct-2012  yamt sync with head
 1.74.2.2 23-May-2012  yamt sync with head.
 1.74.2.1 17-Apr-2012  yamt sync with head
 1.75.2.4 29-Apr-2012  mrg sync to latest -current.
 1.75.2.3 11-Mar-2012  mrg sync to latest -current
 1.75.2.2 04-Mar-2012  mrg sync to latest -current.
 1.75.2.1 18-Feb-2012  mrg merge to -current.
 1.77.2.9 11-Feb-2013  riz Pull up following revision(s) (requested by khorben in ticket #815):
sys/arch/amd64/conf/XEN3_DOM0: revision 1.92
sys/arch/i386/conf/XEN3_DOM0: revision 1.72
Added wpi(4) to the XEN3_DOM0 kernel for both amd64 and i386
Tested on a Lenovo ThinkPad T60 2007 (amd64)
 1.77.2.8 01-Dec-2012  msaitoh Pull up following revision(s) (requested by riz in ticket #730):
sys/arch/amd64/conf/XEN3_DOM0: revision 1.91
Add alc* at pci, re-sort slightly to reduce diffs from GENERIC.
 1.77.2.7 17-Oct-2012  riz Pull up following revision(s) (requested by khorben in ticket #572):
sys/arch/i386/conf/XEN3_DOM0: revision 1.70
sys/arch/amd64/conf/XEN3_DOM0: revision 1.88
Enable support for synaptics touchpads when running Xen as domain 0; helps
usability on laptops. Fixes PR port-xen/44055.
ok bouyer@ riz@
 1.77.2.6 15-Aug-2012  sborrill Pull up the following revisions(s) (requested by martin in ticket #502):
sys/arch/cobalt/conf/GENERIC: patch
sys/arch/i386/conf/GENERIC: patch
sys/arch/i386/conf/XEN3_DOM0: patch
sys/arch/i386/conf/XEN3_DOMU: patch
sys/arch/mvmeppc/conf/GENERIC: patch
sys/arch/shark/conf/GENERIC: patch
sys/arch/sparc64/conf/GENERIC: patch
sys/arch/sparc64/conf/GENERIC.DEBUG: patch
sys/arch/zaurus/conf/GENERIC: patch

Switch off DIAGNOSTIC and/or DEBUG on release kernels.
Enable DIAGNOSTIC in DEBUG kernels to allow for option
being switched off in GENERIC.
 1.77.2.5 03-Jul-2012  jdc Pull up revision 1.85 via patch (requested by khorben in ticket #383).

Disable azalia(4) now that hdaudio(4) was switched on

ok bouyer@
 1.77.2.4 12-Jun-2012  riz Pull up following revision(s) (requested by abs in ticket #311):
sys/arch/netwinder/conf/GENERIC: revision 1.112
sys/arch/i386/conf/GENERIC: revision 1.1074
sys/arch/atari/conf/MILAN.in: revision 1.26
sys/arch/zaurus/conf/GENERIC: revision 1.54
sys/arch/shark/conf/GENERIC: revision 1.101
sys/arch/hpcmips/conf/MPC303: revision 1.60
sys/arch/i386/conf/XEN3_DOM0: revision 1.67
sys/arch/evbarm/conf/MPCSA_GENERIC: revision 1.29
sys/arch/vax/conf/GENERIC: revision 1.181
sys/arch/sparc/conf/KRUPS: revision 1.59
sys/arch/evbarm/conf/BEAGLEBOARD: revision 1.27
sys/arch/i386/conf/INSTALL_FLOPPY: revision 1.16
sys/arch/prep/conf/GENERIC: revision 1.163
sys/arch/hpcmips/conf/GENERIC: revision 1.216
sys/arch/sparc/conf/TADPOLE3GX: revision 1.56
sys/arch/shark/conf/INSTALL: revision 1.50
sys/arch/next68k/conf/GENERIC: revision 1.127
sys/arch/evbppc/conf/VIRTEX_GSRD2: revision 1.16
sys/arch/evbppc/conf/VIRTEX_DFC: revision 1.17
sys/arch/evbppc/conf/EXPLORA451: revision 1.48
sys/arch/bebox/conf/INSTALL: revision 1.54
sys/arch/next68k/conf/SLAB: revision 1.46
sys/arch/i386/conf/GENERIC_TINY: revision 1.132
sys/arch/bebox/conf/GENERIC: revision 1.131
sys/arch/amd64/conf/XEN3_DOM0: revision 1.84
sys/arch/amd64/conf/GENERIC: revision 1.356
sys/arch/evbarm/conf/MMNET_GENERIC: revision 1.6
share/man/man4/wscons.4: revision 1.31
sys/arch/hpcmips/conf/TX3912: revision 1.79
sys/arch/evbarm/conf/ARMADILLO9: revision 1.35
sys/arch/hpcsh/conf/GENERIC: revision 1.97
sys/arch/i386/conf/ALL: revision 1.339
sys/arch/hpcmips/conf/TX3922: revision 1.93
sys/arch/cats/conf/INSTALL: revision 1.82
sys/arch/sparc64/conf/GENERIC: revision 1.151
sys/arch/i386/conf/INSTALL_TINY: revision 1.135
sys/arch/evbppc/conf/VIRTEX_GSRD1: revision 1.15
sys/arch/evbarm/conf/TS7200: revision 1.49
sys/arch/hpcmips/conf/VR41XX: revision 1.55
sys/arch/hp700/conf/GENERIC: revision 1.115
sys/arch/cats/conf/GENERIC: revision 1.140
Mention wsconscfg(8) needs WSDISPLAY_COMPAT_USL
If a port is going to have wscons for virtual terminals then it really make=
s
sense to enable WSDISPLAY_COMPAT_USL so the system can switch between the
virtual terminals...
Adjust the WSDISPLAY_COMPAT_USL comment to mention wsconscfg, to at least
give a hint that its not just for third party compat. No functional change.
 1.77.2.3 23-Apr-2012  riz Pull up following revision(s) (requested by bouyer in ticket #193):
sys/arch/i386/conf/GENERIC: revision 1.1072
sys/dev/pci/mpii.c: revision 1.1
sys/arch/i386/conf/XEN3_DOM0: revision 1.66
sys/dev/pci/files.pci: revision 1.357
share/man/man4/Makefile: revision 1.584
distrib/sets/lists/man/mi: revision 1.1387
share/man/man4/mpii.4: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.354
sys/arch/amd64/conf/XEN3_DOM0: revision 1.83
sys/arch/i386/conf/ALL: revision 1.337
Add mpii(4), a driver for LSI Logic Fusion-MPT Message Passing Interface II
SAS controllers. Ported from OpenBSD.
 1.77.2.2 25-Feb-2012  sborrill Remainder of pullup request:

Pull up the following revisions(s) (requested by bouyer in ticket #52):
sys/arch/amd64/conf/XEN3_DOM0: revision 1.79-1.80
sys/arch/i386/conf/XEN3_DOM0: revision 1.62-1.63

Comment out MPDEBUG, ACPIVERBOSE and MPVERBOSE.
 1.77.2.1 25-Feb-2012  sborrill Pull up the following revisions(s) (requested by bouyer in ticket #52):
sys/arch/amd64/conf/XEN3_DOM0: revision 1.78
sys/arch/amd64/conf/XEN3_DOMU: revision 1.37
sys/arch/i386/conf/XEN3_DOM0: revision 1.61
sys/arch/i386/conf/XEN3_DOMU: revision 1.42

Xen is stable enough now to remove debug messages in default kernel.
Comment out options DEBUG from Xen kernel; also comment out makeoptions
DEBUG="-g" where it was still enabled.
 1.86.2.5 03-Dec-2017  jdolecek update from HEAD
 1.86.2.4 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.86.2.3 23-Jun-2013  tls resync from head
 1.86.2.2 25-Feb-2013  tls resync with head
 1.86.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.97.2.2 18-May-2014  rmind sync with head
 1.97.2.1 28-Aug-2013  rmind sync with head
 1.101.2.1 10-Aug-2014  tls Rebase.
 1.103.2.9 08-Jul-2017  snj Pull up following revision(s) (requested by khorben in ticket #1445):
sys/arch/amd64/conf/XEN3_DOM0: revision 1.136
sys/arch/i386/conf/XEN3_DOM0: revision 1.113
sys/arch/xen/conf/files.xen: revision 1.148
Register support for SD card readers with Xen DOM0 kernels
Tested on a Lenovo ThinkPad T440s (amd64)
 1.103.2.8 13-May-2017  snj Pull up following revision(s) (requested by msaitoh in ticket #1408):
sys/arch/amd64/conf/XEN3_DOM0: revision 1.135 via patch
Add ixg(4). Fixes PR#52180 from Harry Waddell.
 1.103.2.7 18-Apr-2017  snj Pull up following revision(s) (requested by bouyer in ticket #1367):
sys/arch/amd64/conf/XEN3_DOM0: revision 1.134
sys/arch/i386/conf/XEN3_DOM0: revision 1.112
Be more explicit about the status of dom0 SMP support.
 1.103.2.6 17-Apr-2017  snj Pull up following revision(s) (requested by khorben in ticket #1367):
sys/arch/amd64/conf/XEN3_DOM0: revision 1.126
sys/arch/i386/conf/XEN3_DOM0: revision 1.104
sys/arch/xen/x86/xen_pmap.c: revision 1.25
In the MP case,
do not attempt to pmap_tlb_shootdown() after a pmap_kenter_ma() during
boot. pmap_tlb_shootdown() assumes post boot. Instead invalidate the
entry on the local CPU only.
XXX: to DTRT, probably this assumption needs re-examination.
XXX: The tradeoff is a (predicted) single word size comparison
penalty, so perhaps a decision needs performance stats.
xen dom0 SMP is now bootable again.
--
add the 'options MULTIPROCESSOR' in respective configs, but mark them
experimental - and thus disabled by default.
 1.103.2.5 09-Dec-2016  snj Pull up following revision(s) (requested by msaitoh in ticket #1297):
sys/arch/amd64/conf/ALL: revision 1.37
sys/arch/amd64/conf/GENERIC: revision 1.436
sys/arch/amd64/conf/XEN3_DOM0: revision 1.120
sys/arch/i386/conf/ALL: revision 1.400
sys/arch/i386/conf/GENERIC: revision 1.1138
sys/arch/i386/conf/XEN3_DOM0: revision 1.99
Add sdtemp(4)
--
Add ichsmb(4), spdmem(4) and sdtemp(4).
 1.103.2.4 22-Jul-2015  snj branches: 1.103.2.4.4;
Pull up following revision(s) (requested by bouyer in ticket #884):
sys/arch/amd64/conf/XEN3_DOM0: revision 1.114
sys/arch/amd64/conf/XEN3_DOMU: revision 1.62
sys/arch/i386/conf/XEN3_DOM0: revision 1.96
sys/arch/i386/conf/XEN3_DOMU: revision 1.68
Uncoment options IPSEC, as requested by Gary Duzan in PR port-amd64/50052
 1.103.2.3 18-Nov-2014  snj Pull up following revision(s) (requested by manu in ticket #251):
sys/arch/acorn26/conf/GENERIC: revision 1.81
sys/arch/acorn32/conf/GENERIC: revision 1.116
sys/arch/alpha/conf/GENERIC: revision 1.362
sys/arch/amd64/conf/ALL: revision 1.23
sys/arch/amd64/conf/GENERIC: revision 1.404
sys/arch/amd64/conf/XEN3_DOM0: revision 1.112
sys/arch/amd64/conf/XEN3_DOMU: revision 1.60
sys/arch/amiga/conf/GENERIC.in: revision 1.129
sys/arch/amiga/conf/GENERIC: revision 1.311
sys/arch/amigappc/conf/GENERIC: revision 1.24
sys/arch/arc/conf/GENERIC: revision 1.184
sys/arch/bebox/conf/GENERIC: revision 1.145
sys/arch/cats/conf/GENERIC: revision 1.155
sys/arch/cesfic/conf/GENERIC: revision 1.65
sys/arch/cobalt/conf/GENERIC: revision 1.147
sys/arch/dreamcast/conf/GENERIC: revision 1.121
sys/arch/emips/conf/GENERIC: revision 1.15
sys/arch/epoc32/conf/GENERIC: revision 1.8
sys/arch/ews4800mips/conf/GENERIC: revision 1.51
sys/arch/hp300/conf/GENERIC: revision 1.190
sys/arch/hpcmips/conf/GENERIC: revision 1.229
sys/arch/hpcsh/conf/GENERIC: revision 1.106
sys/arch/hppa/conf/GENERIC: revision 1.6
sys/arch/i386/conf/ALL: revision 1.389
sys/arch/i386/conf/GENERIC: revision 1.1118
sys/arch/i386/conf/XEN3_DOM0: revision 1.93
sys/arch/i386/conf/XEN3_DOMU: revision 1.65
sys/arch/ibmnws/conf/GENERIC: revision 1.46
sys/arch/iyonix/conf/GENERIC: revision 1.88
sys/arch/landisk/conf/GENERIC: revision 1.45
sys/arch/luna68k/conf/GENERIC: revision 1.119
sys/arch/mac68k/conf/GENERIC: revision 1.220
sys/arch/macppc/conf/GENERIC: revision 1.320
sys/arch/macppc/conf/MAMBO: revision 1.24
sys/arch/macppc/conf/POWERMAC_G5: revision 1.25
sys/arch/mipsco/conf/GENERIC: revision 1.88
sys/arch/mmeye/conf/GENERIC: revision 1.120
sys/arch/mvme68k/conf/GENERIC: revision 1.94
sys/arch/mvmeppc/conf/GENERIC: revision 1.24
sys/arch/netwinder/conf/GENERIC: revision 1.126
sys/arch/news68k/conf/GENERIC: revision 1.125
sys/arch/newsmips/conf/GENERIC: revision 1.129
sys/arch/next68k/conf/GENERIC: revision 1.139
sys/arch/ofppc/conf/GENERIC: revision 1.157
sys/arch/pmax/conf/GENERIC64: revision 1.21
sys/arch/pmax/conf/GENERIC: revision 1.185
sys/arch/prep/conf/GENERIC: revision 1.174
sys/arch/rs6000/conf/GENERIC: revision 1.33
sys/arch/sandpoint/conf/GENERIC: revision 1.88
sys/arch/sbmips/conf/GENERIC: revision 1.101
sys/arch/sgimips/conf/GENERIC32_IP12: revision 1.28
sys/arch/sgimips/conf/GENERIC32_IP2x: revision 1.104
sys/arch/sgimips/conf/GENERIC32_IP3x: revision 1.106
sys/arch/shark/conf/GENERIC: revision 1.121
sys/arch/sparc/conf/GENERIC: revision 1.248
sys/arch/sparc/conf/TADPOLE3GX: revision 1.65
sys/arch/sparc64/conf/GENERIC: revision 1.177
sys/arch/sparc64/conf/NONPLUS64: revision 1.44
sys/arch/sun2/conf/GENERIC: revision 1.94
sys/arch/sun3/conf/GENERIC: revision 1.171
sys/arch/vax/conf/GENERIC: revision 1.193
sys/arch/vax/conf/VAX780: revision 1.19
sys/arch/x68k/conf/GENERIC: revision 1.179
sys/arch/zaurus/conf/GENERIC: revision 1.65
sys/ufs/files.ufs: revision 1.38
Remove unused extended attributes kernel options

As Masao Uebayashi pointed to me, UFS_EXTATTR_AUTOSTART, LFS_EXTATTR_AUTOSTART
and UFS_EXTATTR_AUTOCREATE are not used anywhere in the code. Remove them
as they have been obsolete for a long time:
UFS_EXTATTR_AUTOSTART was replaced by mount -o extattr
LFS_EXTATTR_AUTOSTART was created to match obsolete UFS_EXTATTR_AUTOSTART
UFS_EXTATTR_AUTOCREATE was replaced by sysctl vfs.ffs.extattr_autocreate
 1.103.2.2 14-Nov-2014  martin Pull up following revision(s) (requested by manu in ticket #232):
sys/arch/next68k/conf/GENERIC: revision 1.138
sys/arch/cobalt/conf/GENERIC: revision 1.146
sys/arch/mvme68k/conf/GENERIC: revision 1.93
sys/arch/vax/conf/VAX780: revision 1.18
sys/arch/newsmips/conf/GENERIC: revision 1.128
sys/arch/luna68k/conf/GENERIC: revision 1.118
sys/arch/sbmips/conf/GENERIC: revision 1.100
sys/arch/pmax/conf/GENERIC: revision 1.184
sys/arch/alpha/conf/GENERIC: revision 1.361
sys/arch/sparc64/conf/GENERIC: revision 1.176
sys/arch/sun3/conf/GENERIC: revision 1.170
sys/arch/shark/conf/GENERIC: revision 1.120
sys/arch/landisk/conf/GENERIC: revision 1.44
sys/arch/bebox/conf/GENERIC: revision 1.144
sys/arch/sparc64/conf/NONPLUS64: revision 1.43
sys/arch/sandpoint/conf/GENERIC: revision 1.87
sys/arch/emips/conf/GENERIC: revision 1.14
sys/arch/amd64/conf/XEN3_DOM0: revision 1.111
sys/arch/dreamcast/conf/GENERIC: revision 1.120
sys/arch/cesfic/conf/GENERIC: revision 1.64
sys/arch/mmeye/conf/GENERIC: revision 1.119
sys/arch/epoc32/conf/GENERIC: revision 1.7
sys/arch/x68k/conf/GENERIC: revision 1.178
sys/arch/iyonix/conf/GENERIC: revision 1.87
sys/arch/sun2/conf/GENERIC: revision 1.93
sys/arch/ews4800mips/conf/GENERIC: revision 1.50
sys/arch/amd64/conf/XEN3_DOMU: revision 1.59
sys/arch/acorn26/conf/GENERIC: revision 1.80
sys/arch/acorn32/conf/GENERIC: revision 1.115
sys/arch/macppc/conf/POWERMAC_G5: revision 1.24
sys/arch/i386/conf/GENERIC: revision 1.1117
sys/arch/arc/conf/GENERIC: revision 1.183
sys/arch/cats/conf/GENERIC: revision 1.154
sys/arch/amiga/conf/GENERIC.in: revision 1.128
sys/arch/zaurus/conf/GENERIC: revision 1.64
sys/arch/netwinder/conf/GENERIC: revision 1.125
sys/arch/hppa/conf/GENERIC: revision 1.5
sys/arch/mvmeppc/conf/GENERIC: revision 1.23
sys/arch/macppc/conf/GENERIC: revision 1.319
sys/arch/amiga/conf/GENERIC: revision 1.310
sys/arch/pmax/conf/GENERIC64: revision 1.20
sys/arch/macppc/conf/MAMBO: revision 1.23
sys/arch/sgimips/conf/GENERIC32_IP12: revision 1.27
sys/arch/amigappc/conf/GENERIC: revision 1.23
sys/arch/amd64/conf/GENERIC: revision 1.403
sys/arch/ofppc/conf/GENERIC: revision 1.156
sys/arch/mac68k/conf/GENERIC: revision 1.219
sys/arch/i386/conf/XEN3_DOMU: revision 1.64
sys/arch/mipsco/conf/GENERIC: revision 1.87
sys/arch/hp300/conf/GENERIC: revision 1.189
sys/arch/vax/conf/GENERIC: revision 1.192
sys/arch/news68k/conf/GENERIC: revision 1.124
sys/arch/ibmnws/conf/GENERIC: revision 1.45
sys/arch/hpcsh/conf/GENERIC: revision 1.105
sys/arch/sparc/conf/TADPOLE3GX: revision 1.64
sys/arch/i386/conf/XEN3_DOM0: revision 1.92
sys/arch/sparc/conf/GENERIC: revision 1.247
sys/arch/sgimips/conf/GENERIC32_IP3x: revision 1.105
sys/arch/prep/conf/GENERIC: revision 1.173
sys/arch/sgimips/conf/GENERIC32_IP2x: revision 1.103
sys/arch/rs6000/conf/GENERIC: revision 1.32
sys/arch/hpcmips/conf/GENERIC: revision 1.228
Support for UFS1 extended attributes in GENERIC and GENERIC-like kernels
This change just brings UFS1 extended attribute *support* in the kernel,
extended attributes are not enabled unless three conditions are met:
1) filesystem is UFS1 (newfs -O1)
2) .attribute/system and .attribute/user directories are created at fs root
3) filesystem is mounted with -o extattr
Some GENERIC kernels are obviously memory constrained, the extended
attributes options were not enabled for them, but just added commented out.
(kernel were considered memory constrained if QUOTA option was disabled)
 1.103.2.1 10-Oct-2014  snj Apply patch (requested by bouyer/martin in ticket #116):
Disable DIAGNOSTIC and/or DEBUG.
 1.103.2.4.4.1 18-Jan-2017  skrll Sync with netbsd-5
 1.112.2.9 28-Aug-2017  skrll Sync with HEAD
 1.112.2.8 05-Feb-2017  skrll Sync with HEAD
 1.112.2.7 05-Oct-2016  skrll Sync with HEAD
 1.112.2.6 29-May-2016  skrll Sync with HEAD
 1.112.2.5 22-Apr-2016  skrll Sync with HEAD
 1.112.2.4 19-Mar-2016  skrll Sync with HEAD
 1.112.2.3 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.112.2.2 22-Sep-2015  skrll Sync with HEAD
 1.112.2.1 06-Apr-2015  skrll Sync with HEAD
 1.119.2.4 26-Apr-2017  pgoyette Sync with HEAD
 1.119.2.3 20-Mar-2017  pgoyette Sync with HEAD
 1.119.2.2 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.119.2.1 06-Aug-2016  pgoyette Sync with HEAD
 1.127.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.135.4.8 07-Dec-2018  martin Fixup pullups from ticket #1129:

sys/arch/amd64/conf/XEN3_DOM0 rev 1.159
src/sys/arch/i386/conf/XEN3PAE_DOM0 rev 1.8 (via patch)

Add mffii(4)
 1.135.4.7 18-Apr-2018  martin Requested by skrll in ticket #60:
sys/arch/amd64/conf/GENERIC
sys/arch/amd64/conf/XEN3_DOM0
sys/arch/amd64/conf/XEN3_DOMU
sys/arch/cobalt/conf/GENERIC
sys/arch/evbarm/conf/BEAGLEBONE
sys/arch/evbarm/conf/BEAGLEBOARD
sys/arch/evbarm/conf/BEAGLEBOARDXM
sys/arch/evbarm/conf/GENERIC.common
sys/arch/i386/conf/GENERIC
sys/arch/i386/conf/XEN3_DOM0
sys/arch/i386/conf/XEN3_DOMU
sys/arch/mvmeppc/conf/GENERIC
sys/arch/shark/conf/GENERIC
sys/arch/sparc64/conf/GENERIC
sys/arch/zaurus/conf/GENERIC

Remove option DIAGNOSTIC.
 1.135.4.6 05-Feb-2018  martin Pull up following revision(s) (requested by bouyer in ticket #533):
sys/arch/i386/conf/XEN3_DOM0: revision 1.126
sys/arch/amd64/conf/XEN3_DOM0: revision 1.148
Follow GENERIC and enable xhci(4) by default. PR port-xen/52978
 1.135.4.5 05-Feb-2018  martin Pull up following revision(s) (requested by pgoyette in ticket #524):

distrib/sets/lists/man/mi 1.1574
distrib/sets/lists/modules/md.amd64 1.73
distrib/sets/lists/modules/md.i386 1.76
share/man/man4/amdtemp.4 1.11
share/man/man4/man4.x86/Makefile 1.17
share/man/man4/man4.x86/amdsmn.4 1.1-1.3
share/man/man4/man4.x86/amdzentemp.4 1.1-1.6
sys/arch/amd64/conf/ALL 1.79,1.80
sys/arch/amd64/conf/GENERIC 1.482,1.484
sys/arch/amd64/conf/XEN3_DOM0 1.146,1.147
sys/arch/x86/pci/amdsmn.c 1.1-1.2
sys/arch/x86/pci/amdsmn.h 1.1
sys/arch/x86/pci/amdzentemp.c 1.1-1.7
sys/arch/x86/pci/files.pci 1.22,1.23
sys/modules/amdzentemp/amdzentemp.ioconf 1.2


Add amdzentemp from FreeBSD via Ian Clark.

man pages for amdsmn and amdzentemp.

Some clean-up on the HISTORY and AUTHORS sections, and addition of a BUGS
section to document the fact that we don't yet handle the required temp
offset, nor do we expose the available thermal-trip value.

Add missing article 'a'

KNF: Put back the blank line following the empty variable declarations
Put back the variable declaration, too, and mark it __diagused
Otherwise a DIAGNOSTIC kernel will complain about the variable being
undeclared.

Correct placement of __diagused attribute.

Modularize the amdsmn(4) driver, and update dependency for amdzentemp(4),
Create amdsmn(4) amd amdzentemp(4) modules for X86.
 1.135.4.4 26-Jan-2018  martin Pull up following revision(s) (requested by sevan in ticket #510):
sys/arch/sun3/conf/GENERIC3X: revision 1.130
sys/arch/sparc64/conf/GENERIC: revision 1.203
sys/arch/news68k/conf/LIBERO: revision 1.66
sys/arch/amiga/conf/DRACO: revision 1.185
sys/arch/evbarm/conf/MV2120: revision 1.35
sys/arch/x68k/conf/GENERIC: revision 1.187
sys/arch/rs6000/conf/GENERIC: revision 1.39
sys/arch/news68k/conf/GENERIC_TINY: revision 1.86
sys/arch/i386/conf/XEN3_DOMU: revision 1.88
sys/arch/iyonix/conf/GENERIC: revision 1.97
sys/arch/evbarm64/conf/A64EMUL: revision 1.11
sys/arch/mvme68k/conf/GENERIC: revision 1.98
sys/arch/acorn32/conf/GENERIC: revision 1.124
sys/arch/i386/conf/XEN3_DOM0: revision 1.125
sys/arch/cobalt/conf/INSTALL: revision 1.65
sys/arch/macppc/conf/GENERIC_601: revision 1.16
sys/arch/hppa/conf/GENERIC: revision 1.17
sys/arch/amiga/conf/GENERIC.in: revision 1.137
sys/arch/sgimips/conf/GENERIC32_IP12: revision 1.33
sys/arch/netwinder/conf/GENERIC: revision 1.134
sys/arch/amd64/conf/XEN3_DOMU: revision 1.83
sys/arch/mac68k/conf/GENERIC: revision 1.225
sys/arch/arc/conf/RPC44: revision 1.54
sys/arch/mipsco/conf/GENERIC: revision 1.92
sys/arch/cats/conf/GENERIC: revision 1.166
sys/arch/amd64/conf/XEN3_DOM0: revision 1.145
sys/arch/amigappc/conf/GENERIC: revision 1.33
sys/arch/sun3/conf/GENERIC: revision 1.176
sys/arch/news68k/conf/GENERIC: revision 1.130
sys/arch/hpcsh/conf/GENERIC: revision 1.110
sys/arch/hp300/conf/GENERIC: revision 1.198
sys/arch/atari/conf/GENERIC.in: revision 1.115
sys/arch/sparc/conf/MRCOFFEE: revision 1.54
sys/arch/evbppc/conf/EXPLORA451: revision 1.62
sys/arch/cesfic/conf/GENERIC: revision 1.69
sys/arch/vax/conf/GENERIC: revision 1.204
sys/arch/sgimips/conf/GENERIC32_IP3x: revision 1.115
sys/arch/sgimips/conf/GENERIC32_IP2x: revision 1.112
sys/arch/sparc/conf/GENERIC: revision 1.258
sys/arch/next68k/conf/GENERIC: revision 1.145
sys/arch/evbarm/conf/MMNET_GENERIC: revision 1.34
sys/arch/prep/conf/GENERIC: revision 1.185
sys/arch/amiga/conf/INSTALL: revision 1.129
sys/arch/newsmips/conf/GENERIC: revision 1.133
sys/arch/cobalt/conf/GENERIC: revision 1.156
sys/arch/sun2/conf/GENERIC: revision 1.99
sys/arch/luna68k/conf/INSTALL: revision 1.25
sys/arch/amigappc/conf/NULL: revision 1.53
sys/arch/acorn26/conf/GENERIC: revision 1.85
sys/arch/vax/conf/VAX780: revision 1.25
sys/arch/luna68k/conf/GENERIC: revision 1.125
sys/arch/ews4800mips/conf/GENERIC: revision 1.56
sys/arch/macppc/conf/POWERMAC_G5: revision 1.29
sys/arch/arc/conf/GENERIC: revision 1.189
sys/arch/macppc/conf/MAMBO: revision 1.27
sys/arch/acorn32/conf/EB7500ATX: revision 1.64
sys/arch/pmax/conf/GENERIC: revision 1.196
sys/arch/pmax/conf/GENERIC64: revision 1.28
sys/arch/amiga/conf/GENERIC: revision 1.319
sys/arch/evbarm/conf/MPCSA_GENERIC: revision 1.55
sys/arch/macppc/conf/GENERIC: revision 1.339
sys/arch/emips/conf/GENERIC: revision 1.21
sys/arch/sandpoint/conf/GENERIC: revision 1.97
sys/arch/landisk/conf/GENERIC: revision 1.58
sys/arch/bebox/conf/GENERIC: revision 1.157
sys/arch/alpha/conf/GENERIC: revision 1.379
Alternate buffer queue strategies no longer considered experimental, update
description.
Discussed on tech-kern
http://mail-index.netbsd.org/tech-kern/2018/01/21/msg023002.html
 1.135.4.3 29-Aug-2017  martin Requested by skrll in ticket #60:
sys/arch/amd64/conf/GENERIC
sys/arch/amd64/conf/XEN3_DOM0
sys/arch/amd64/conf/XEN3_DOMU
sys/arch/cobalt/conf/GENERIC
sys/arch/evbarm/conf/BEAGLEBONE
sys/arch/evbarm/conf/BEAGLEBOARD
sys/arch/evbarm/conf/BEAGLEBOARDXM
sys/arch/evbarm/conf/GENERIC.common
sys/arch/i386/conf/GENERIC
sys/arch/i386/conf/XEN3_DOM0
sys/arch/i386/conf/XEN3_DOMU
sys/arch/mvmeppc/conf/GENERIC
sys/arch/shark/conf/GENERIC
sys/arch/sparc64/conf/GENERIC
sys/arch/zaurus/conf/GENERIC


Re-enable option DIAGNOSTIC for now, will remove it again later.
 1.135.4.2 05-Jul-2017  martin Remove options DIAGNOSTIC/DEBUG and PAX debug options.
Requested by snj in #60.
 1.135.4.1 30-Jun-2017  snj Pull up following revision(s) (requested by khorben in ticket #62):
sys/arch/amd64/conf/XEN3_DOM0: revision 1.136
sys/arch/i386/conf/XEN3_DOM0: revision 1.113
sys/arch/xen/conf/files.xen: revision 1.148
Register support for SD card readers with Xen DOM0 kernels
Tested on a Lenovo ThinkPad T440s (amd64)
 1.149.2.6 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.149.2.5 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.149.2.4 30-Sep-2018  pgoyette Ssync with HEAD
 1.149.2.3 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.149.2.2 25-Jun-2018  pgoyette Sync with HEAD
 1.149.2.1 21-May-2018  pgoyette Sync with HEAD
 1.153.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.153.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.153.2.1 10-Jun-2019  christos Sync with HEAD
 1.167.2.3 07-Jul-2020  martin Pull up following revision(s) (requested by jmcneill in ticket #980):

sys/dev/pci/if_aq.c: revision 1.4
sys/dev/pci/if_aq.c: revision 1.5
sys/arch/amd64/conf/GENERIC: revision 1.553
sys/dev/pci/files.pci: revision 1.419
sys/arch/amd64/conf/XEN3_DOM0: revision 1.170
sys/dev/pci/if_aq.c: revision 1.9
share/man/man4/Makefile: revision 1.693
sys/dev/pci/pcidevs: revision 1.1411
share/man/man4/aq.4: revision 1.1
share/man/man4/aq.4: revision 1.3
sys/arch/i386/conf/ALL: revision 1.479
share/man/man4/aq.4: revision 1.4
sys/dev/pci/if_aq.c: revision 1.10
sys/dev/pci/files.pci: revision 1.421
sys/dev/pci/if_aq.c: revision 1.11
sys/dev/pci/if_aq.c: revision 1.12
sys/dev/pci/if_aq.c: revision 1.13
sys/dev/pci/if_aq.c: revision 1.14
sys/dev/pci/if_aq.c: revision 1.15
sys/dev/pci/if_aq.c: revision 1.16
sys/dev/pci/pcidevs: revision 1.1408
sys/arch/amd64/conf/ALL: revision 1.135
sys/net/ethertypes.h: revision 1.19
sys/arch/i386/conf/GENERIC: revision 1.1218
distrib/sets/lists/man/mi: revision 1.1668
sys/dev/pci/if_aq.c: revision 1.1
sys/dev/pci/if_aq.c: revision 1.2
sys/dev/pci/pcidevs: revision 1.1395
sys/dev/pci/if_aq.c: revision 1.3
sys/arch/evbarm/conf/GENERIC64: revision 1.125

Add the ETHERTYPE_QINQ for 802.1ad VLAN stacking

add Aquantia AQC 10G network adapters
add support Aquantia AQC seriese 10G network adapters.

this driver is based on the FreeBSD version https://github.com/Aquantia/aqtion-freebsd ,
but drastically rewritten for NetBSD.

add aq(4)

Add Aquantia AQC100, AQC100S and D100.

add support VLAN HW filter

set/clear IFF_OACTIVE flag only on txring 0

make counters per queue

support internal PHY temperature sensor

Found by kUBSan:
- Use unsigned to avoid undefined behavior in aq_hw_init().
- Cast to unsigned to avoid undefined behavior in aq_set_mac_addr().

fix descriptions of register map in comment

return the ifmedia active status correctly even while the link is not up after attach.
pointed out by msaitoh@. thanks.

On FIBRE devices, there are times when linkstat interrupt doesn't occur?
reported from Andrius V. thanks.
- use polling instead of linkstat interrupt when FIBRE
- add AQ_FORCE_POLL_LINKSTAT options (not by default)

sort product table, and tabify

add support AQC100S and D100.
not tested, but they are probably the same as the AQC100.
 1.167.2.2 21-Nov-2019  martin In preparation for the upcoming release, turn off DIAGNOSTIC in most
kernel configs, modules and libc.
 1.167.2.1 09-Aug-2019  martin Pull up following revision(s) (requested by rin in ticket #35):

sys/arch/amd64/conf/ALL: revision 1.121
sys/arch/i386/conf/XEN3PAE_DOM0: revision 1.14
sys/arch/amd64/conf/XEN3_DOM0: revision 1.168
sys/arch/i386/conf/GENERIC: revision 1.1210
sys/arch/amd64/conf/GENERIC: revision 1.534

xhci(4) is considered stable enough. So, remove misleading comments.

XXX
pullup to netbsd-9
 1.170.2.2 29-Feb-2020  ad Sync with head.
 1.170.2.1 25-Jan-2020  ad Sync with head.
 1.175.4.2 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.
 1.175.4.1 12-Apr-2020  bouyer no MULTIPROCESSOR so NO_PREEMTION
 1.185.2.1 03-Apr-2021  thorpej Sync with HEAD.
 1.192.4.1 01-Aug-2021  thorpej Sync with HEAD.
 1.197.4.3 18-Oct-2023  martin Pull up following revision(s) (requested by bouyer in ticket #428):

sys/arch/xen/xen/xen_machdep.c: revision 1.28
sys/arch/x86/pci/pci_machdep.c: revision 1.97
sys/arch/xen/xen/genfb_xen.c: revision 1.1
sys/arch/xen/xen/genfb_xen.c: revision 1.2
sys/arch/xen/include/hypervisor.h: revision 1.59
sys/arch/i386/conf/XEN3PAE_DOM0: revision 1.41 (patch)
sys/arch/x86/x86/genfb_machdep.c: revision 1.22
sys/arch/xen/x86/consinit.c: revision 1.18
sys/arch/xen/x86/autoconf.c: revision 1.26
sys/external/mit/xen-include-public/dist/xen/include/public/platform.h: revision 1.2
sys/arch/xen/conf/files.xen: revision 1.188
sys/arch/x86/x86/consinit.c: revision 1.37
sys/arch/xen/conf/files.xen: revision 1.189
sys/arch/x86/x86/consinit.c: revision 1.38
sys/external/mit/xen-include-public/dist/xen/include/public/xen.h: revision 1.2
sys/arch/x86/include/genfb_machdep.h: revision 1.7
sys/arch/xen/x86/pvh_consinit.c: revision 1.5
sys/arch/xen/x86/pvh_consinit.c: revision 1.6
sys/arch/amd64/conf/XEN3_DOM0: revision 1.201

Move the pvh_xencons so xen_machdep.c as early_xencons, so it can be
used in the future as early ouput for plain PV guests too.

Support non-VGA framebuffers for Xen dom0. This is mandatory for graphic
console on EFI-only hardware.

Add a xen_genfb_getbtinfo() function which will return a btinfo_framebuffer
structure, filled in with parameters provided by Xen

when runing as a Xen dom0, call xen_genfb_getbtinfo() instead of
lookup_bootinfo(BTINFO_FRAMEBUFFER) when adding properties to the
PCI graphic device (when genfb is attached) and in x86_genfb_init()
when genfb is used as console.

x86/x86/consinit.c: If running as a Xen dom0, use xen_genfb_getbtinfo()
to check if we have a genfb console

xen/x86/consinit.c: support genfb as possible console

xen/x86/consinit.c: use the hypervior IO as console until a better one
is found. If the hypervisor is using a serial port for boot messages,
we'll get NetBSD's boot message on the serial port too until
the real console takes over.

xen/x86/autoconf.c: rework device_register() to be closer to the x86 version.
Especially make sure that device_pci_register() is called.

Make sure to always fall back to xen_early_console, even for dom0

Enable genfb in DOM0 kernels

Add ext_lfb_base to dom0_vga_console_info, from recent Xen. We know if it's
present or not by checking dom0.info_size

Add XENPF_get_dom0_console, which gets a dom0_vga_console_info stucture
from the hypervisor. To be used by PVH dom0 kernels.

XENPVH option is not used. Fix consinit.c to use XENPVHVM as intended
and XENPVH from defflag
for a dom0 PVH, the dom0_vga_console_info structure has to be retrieved
using a platform hypercall; do so in the XENPVHVM case.

Now genfb works in a PVH dom0 running on Xen 4.18 (Xen 4.15 doesn't support
this platoform op, so no way to make it work here).
 1.197.4.2 09-Oct-2023  snj Apply patch (requested by martin in ticket #401):
Disable DIAGNOSTIC/DEBUG.
 1.197.4.1 08-Oct-2023  martin Pull up following revision(s) (requested by rin in ticket #393):

sys/dev/pci/igc/if_igc.c up to 1.3
sys/dev/pci/igc/if_igc.h up to 1.2
sys/dev/pci/igc/igc_api.c up to 1.2
sys/dev/pci/igc/igc_api.h up to 1.2
sys/dev/pci/igc/igc_base.c up to 1.2
sys/dev/pci/igc/igc_base.h up to 1.2
sys/dev/pci/igc/igc_defines.h up to 1.2
sys/dev/pci/igc/igc_evcnt.h up to 1.1
sys/dev/pci/igc/igc_hw.h up to 1.2
sys/dev/pci/igc/igc_i225.c up to 1.2
sys/dev/pci/igc/igc_i225.h up to 1.2
sys/dev/pci/igc/igc_mac.c up to 1.2
sys/dev/pci/igc/igc_mac.h up to 1.2
sys/dev/pci/igc/igc_nvm.c up to 1.2
sys/dev/pci/igc/igc_nvm.h up to 1.2
sys/dev/pci/igc/igc_phy.c up to 1.2
sys/dev/pci/igc/igc_phy.h up to 1.2
sys/dev/pci/igc/igc_regs.h up to 1.2
distrib/sets/lists/man/mi: revision 1.1766
sys/arch/amd64/conf/GENERIC: revision 1.606
sys/arch/evbppc/conf/DHT: revision 1.5
sys/arch/evbarm/conf/GENERIC64: revision 1.213
share/man/man4/Makefile: revision 1.733
sys/arch/amd64/conf/ALL: revision 1.181
share/man/man4/igc.4: revision 1.1
sys/dev/pci/files.pci: revision 1.447
sys/arch/amd64/conf/XEN3_DOM0: revision 1.200
doc/CHANGES (apply patch)

Add igc(4) for Intel I225/I226 series ethernet devices
 1.203.2.1 02-Aug-2025  perseant Sync with HEAD
 1.106 22-May-2025  bad make XEN3 configs include XEN3.local instead of GENERIC.local

The XEN device tree is not compatible with the non-XEN device tree.

This means that one can't enable in GENERIC.local many devices that are
commented out in GENERIC. E.g,

vio9p* at virtio?
i915drm* at drm?
qat* at pci? dev ? function ?
audio* at audiobus?

Switch to including XEN3.local instead of GENERIC.local to have a common
file for local XEN3 specific configuration.

See https://mail-index.netbsd.org/tech-kern/2024/08/11/msg029672.html for
the discussion.

Note that GENERIC.local was added to most arches only in February 2023:
https://mail-index.netbsd.org/source-changes/2023/02/12/msg143277.html

Addresses: PR port-xen/59438: GENERIC content can't be in GENERIC.local because
of XEN3_DOM* kernels

Should probably be pulled up to -10 and -9.
 1.105 02-Apr-2024  charlotte branches: 1.105.2;
Mention DKWEDGE_METHOD_TOS in several kernel config files
 1.104 29-Jan-2024  christos PR/57889: Ricardo Branco: ext2fs does not have user immutable and append
file flags, only system ones. Restrict those to the superuser. Before
the behavior was controlled by EXT2FS_SYSTEM_FLAGS. Make that behavior the
default.
 1.103 05-Aug-2023  riastradh xen/x86: Enable heartbeat checks.
 1.102 22-Jul-2023  riastradh amd64/XEN3_DOMU: Pass -g to build debug data like GENERIC.

Needed for CTF data by dtrace when MKDEBUG=no MKDEBUGKERNEL=no.

XXX pullup-10
 1.101 21-Jul-2023  riastradh amd64/XEN3_DOMU: Enable KDTRACE_HOOKS.

XXX pullup-10
 1.100 09-Feb-2023  abs Adjust _all_ cinclude of *.local files

- Ensure always at end
- Use tab rather than spaces
- Add consistent comment
"Pull in optional local configuration - always at end"

The only functional change is that a local file which tried to
override an existing setting (eg with "no foo") would have failed
in some cases before, but now will work
 1.99 07-Aug-2022  simonb branches: 1.99.4;
UFS/LFS dirhash:
- Enable UFS_DIRHASH if the architecture or kernel model specific config
file can use 128MB of RAM or more.
- Remove experimental tag from UFS_DIRHASH; it's been with RUMP kernel
and by a number of NetBSD developers for years.
- Add LFS_DIRHASH if LFS was enabled.
- Be somewhat consistent with FS options order.
 1.98 29-Nov-2021  jdolecek enable UFS_ACL option for XEN3_DOMU, it's useful for e.g. running Samba in DomU

idea from Matthias Petermann via current-users@
 1.97 20-Jan-2021  nia remove compat_ossaudio from kernel modules

this is only useful with compat_linux and gets autoloaded when
compat_linux is loaded, so there's no reason to bake it into kernels
any more.
 1.96 27-Sep-2020  roy branches: 1.96.2;
vether: Add to kernel configurations

It's only enabled if the kernel enabled bridge AND tap.
Otherwise it's commented out.
 1.95 16-Aug-2020  jdolecek make COMPAT_LINUX option disabled by default

leave the option enabled only in amd64/i386 ALL kernels to make
sure it continues to be compilable also when included in kernel
 1.94 01-Aug-2020  maxv Remove references to BRIDGE_IPF, it is now compiled in by default.
 1.93 25-Apr-2020  bouyer Disable -g, which got enabled by mistake in the bouyer-xenpvh merge
 1.92 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.91 15-Apr-2020  jdolecek remove MAXPHYS override, xbd(4) was changed to work with 64k transfers
 1.90 21-Aug-2019  maxv branches: 1.90.6;
No USER_LDT on Xen.
 1.89 06-May-2019  sevan branches: 1.89.2;
Use filesystems.config to reduce duplication
 1.88 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.87 14-Aug-2018  maxv Enable L2TP on all x86 configurations, not just native amd64.
 1.86 01-Aug-2018  maxv Unreference IPF/PF from the x86 config files (amd64, i386, xen), and enable
NPF instead when wanted.
 1.85 17-Jul-2018  bouyer Put back trace in DDB_COMMANDONENTER; in seems that the sysctl is not
functionnal early in boot.
 1.84 17-Feb-2018  sevan branches: 1.84.2; 1.84.4;
With the introduction of ddb.dumpstack which is enabled by default, we no longer
need to explicitly set DDB_COMMANDONENTER to run a trace.
 1.83 23-Jan-2018  sevan Alternate buffer queue strategies no longer considered experimental, update
description.

Discussed on tech-kern
http://mail-index.netbsd.org/tech-kern/2018/01/21/msg023002.html
 1.82 13-Jan-2018  christos added commented out AUTOFS pseudo-device entries
 1.81 09-Jan-2018  christos Merge autofs support from: Tomohiro Kusumi
XXX: Does not work yet
 1.80 06-Nov-2017  rin Revive commented out DISKLABEL_EI option to kernel configuration files
that contain FFS_EI option.
 1.79 30-Sep-2017  pgoyette Add commented-out ident lines to the XEN3_DOM{0,U} kernel config files
for consistency with other config files.

OK bouyer@
 1.78 14-Sep-2017  mrg clean up COMPAT_* options for native netbsd code:
- new series of files that are useful for saying "i want everything
since netbsd 1.4", etc.
- use the fact COMPAT_* options have future dependancies to remove
many redundant options.

removes about 3000 lines total across kernel configuration files.
tested about 30 random kernels in the changed list.
 1.77 10-Aug-2017  maxv Pff, I forgot to revert my change in these files. I committed only the
GENERIC files, and the message was:

Revert my changes, and re-enable COMPAT_NOMID, COMPAT_09 and COMPAT_43.
Several compat options happen to be dependent on the compat_43_* functions,
the availability of which is (wrongfully) controlled with COMPAT_43. Same
for COMPAT_09.
 1.76 28-Jul-2017  maxv After a careful review, and all things considered, disable compat43 by
default on amd64. The use case is limited, the potential for damage too
high, and it is safer to run a BSD4.3 binary on i386 since the kernel does
not have to go through netbsd32 - which may not correctly reproduce i386.
 1.75 21-May-2017  pgoyette branches: 1.75.2;
Remove unnecessary SYSMON_* options.
 1.74 11-May-2017  sborrill Add commented out carp and mpls pseudo-devices to be consistent with
GENERIC
 1.73 26-Feb-2017  rin branches: 1.73.4;
Comment out DISKLABEL_RDB as it is too specific for general usage.
(Also add commented out that entry for GENERIC on amd64; I forgot it)
 1.72 26-Feb-2017  maya Remove commented DISKLABEL_EI for strictly little endian architectures

It will never be useful.
 1.71 26-Feb-2017  rin Add DKWEDGE_METHOD_RDB option, which is enabled for x86, commented out for
other platforms by default.
 1.70 19-Feb-2017  rin PR kern/51208
Add DISKLABEL_EI option (and also FFS_EI if missing), commented out except for
ALL on amd64 and i386.
 1.69 23-Jan-2017  christos PR/51908: Kyle Amon: Allow customization of XEN kernels via .local files.
 1.68 12-Jan-2017  ryo branches: 1.68.2;
white space police
 1.67 18-Dec-2016  dholland Whitespace.
 1.66 17-Dec-2016  maxv Add MODULAR in Xen kernels.
 1.65 14-May-2016  christos branches: 1.65.2;
Turn on MPROTECT on GENERIC and both MPROTECT and ASLR on XEN*
 1.64 10-Nov-2015  tnn Add "pseudo-device iscsi" to ALL and as a commented out hint in XEN3_*
 1.63 12-Aug-2015  maxv Remove KMEMSTATS.
 1.62 16-Jul-2015  bouyer Uncoment options IPSEC, as requested by Gary Duzan in PR port-amd64/50052
 1.61 05-May-2015  pgoyette For non-modular XEN3_DOMU kernels, include sysmon and all of its
subcomponents. While the wdog and envsys subcomponents aren't
terribly useful in DOMU environment, this restores functionality
to previous (pre-modularized sysmon) state.
 1.60 16-Nov-2014  manu branches: 1.60.2;
Remove unused extended attributes kernel options

As Masao Uebayashi pointed to me, UFS_EXTATTR_AUTOSTART, LFS_EXTATTR_AUTOSTART
and UFS_EXTATTR_AUTOCREATE are not used anywhere in the code. Remove them
as they have been obsolete for a long time:
UFS_EXTATTR_AUTOSTART was replaced by mount -o extattr
LFS_EXTATTR_AUTOSTART was created to match obsolete UFS_EXTATTR_AUTOSTART
UFS_EXTATTR_AUTOCREATE was replaced by sysctl vfs.ffs.extattr_autocreate
 1.59 12-Nov-2014  manu Support for UFS1 extended attributes in GENERIC and GENERIC-like kernels

This change just brings UFS1 extended attribute *support* in the kernel,
extended attributes are not enabled unless three conditions are met:
1) filesystem is UFS1 (newfs -O1)
2) .attribute/system and .attribute/user directories are created at fs root
3) filesystem is mounted with -o extattr

Some GENERIC kernels are obviously memory constrained, the extended
attributes options were not enabled for them, but just added commented out.
(kernel were considered memory constrained if QUOTA option was disabled)
 1.58 19-Sep-2014  christos Disable BSDLABEL and MBR DKWEDGE methods again since sysinst does not work
with wedges.
 1.57 23-Aug-2014  dholland Systematize (and in many cases, fix) the comments on options COMPAT_NN.

There are quite a few configs that are missing some COMPAT_NN options
in ways that don't make sense; this should probably get cleaned up
too, but for the time being I've not added or removed anything.
 1.56 18-Aug-2014  christos - Enable Wedge support for MBR/BSDLABEL where it was commented out.
- Add apple partition support where it was missing
- Add comments where missing
 1.55 16-Aug-2014  apb Add "options COMPAT_70" to all kernel configuration files that
already had "options COMPAT_60".
 1.54 25-Jul-2014  dholland branches: 1.54.2;
Fix description of DIAGNOSTIC in x86 kernels.
 1.53 24-Mar-2014  szptvlfn branches: 1.53.2;
fix manual section numbering of sysctl.
thanks wiz@
 1.52 16-Mar-2014  jakllsch Disable xpci(4) PCI passthrough in XEN3_DOMU kernels by popular demand.
 1.51 15-Mar-2014  jakllsch Enable PCI support in amd64 XEN3_DOMU config to match i386 XEN3_DOMU config.
 1.50 30-Jun-2013  rmind G/C PFIL_HOOKS from the kernel configs.
 1.49 05-Jun-2013  christos branches: 1.49.2;
remove obsolete networking options
 1.48 27-Apr-2013  christos the bogus number police
 1.47 27-Apr-2013  christos remove confusing numeric locators where they are unused.
 1.46 17-Apr-2013  riz Sync DKWEDGE options with XEN3_DOM0.
 1.45 02-Mar-2013  christos Under FAST_IPSEC, IPSEC_ESP is mandatory; GC it.
 1.44 01-Mar-2013  joerg Retire OSI network stack. OK core@
 1.43 24-Jan-2013  bouyer Put back 32k MAXPHYS, reverting
http://mail-index.netbsd.org/source-changes/2013/01/19/msg040666.html

64k MAXPHYS breaks at last iso9660, as shown by periodic anita runs at
http://www-soc.lip6.fr/~bouyer/NetBSD-tests/xen/
 1.42 19-Jan-2013  jakllsch xbd has been able to cope with any value of MAXPHYS since
src/sys/arch/xen/xen/xbd_xenbus.c 1.56
 1.41 17-Oct-2012  apb Add "options COMPAT_60" to all kernel configuration files
that already had "options COMPAT_50".
 1.40 04-Oct-2012  dsl Remove references to VM86 from the amd64 kernel configs.
VM86 mode isn't supported while in long mode.
 1.39 23-Sep-2012  chs add vmt entry to GENERIC.
standardize commented pfsync and npf entries.
 1.38 10-Mar-2012  joerg branches: 1.38.2;
P1003_1B_SEMAPHORE is no longer optional.
 1.37 25-Feb-2012  bouyer Comment out options DEBUG from Xen kernel; also comment out
makeoptions DEBUG="-g" where it was still enabled.
 1.36 30-Jan-2012  cherry branches: 1.36.2;
switch on NetBSD/Xen MULTIPROCESSOR support for domUs as default, for wider testing
 1.35 19-Dec-2011  cherry Add knob to turn MULTIPROCESSOR build on for XEN
 1.34 18-Dec-2011  dholland WABPL is no longer considered experimental (has not been for some time)
so update its comment in config files.
 1.33 22-Nov-2011  tls branches: 1.33.2;

The rnd pseudo-device is not really optional, because it is in the same
source file as the entropy-pool code itself. Move it to std. This
will be cleaned up more when I split the sources up as they should be.

This fixes build breaks on several ports. Thanks to Havard Eidnes for
pointing them out.
 1.32 10-Nov-2011  riz Add pseudo-device drvctl. (Already exists in i386 domU config)
 1.31 25-Oct-2011  jakllsch branches: 1.31.2;
Per existing x86 GENERIC kernels, add:
#options BUFQ_READPRIO
options BUFQ_PRIOCSCAN
to Xen kernels.
 1.30 28-May-2011  ryo branches: 1.30.2;
many whitespace cleanup.
 1.29 29-Apr-2011  jym Enable balloon(4) for Xen kernels.

ok bouyer@; shortly discussed on port-xen@.
 1.28 18-Apr-2011  jym Large rewrite of the balloon driver. This one:

- turns balloon into a driver that attaches to xenbus(4). This allows to
disable the functionality either at compile time or boot time via
userconf(4). Driver can implement detach or pmf(9) hooks if deemed
necessary.

- keeps Cherry's locking model, but simplify it a bit. There is now
only one target value serialized inside balloon, we do not feedback
alternative value to Xenstore (clients are not expected to see its value
evolve behind their back, and can't do much about that either)

- implements min threshold; this is an admin-settable value that tells
driver to "not balloon below this threshold." This can be used by domain
to keep memory reservations, useful if activity is expected in the near
future.

- in addition to min threshold, the driver implements internally a
safeguard value (uvmexp.freemin + 1MiB), so that admin cannot
inadvertently set min to a very low value forcing domain into heavy
memory pressure and swapping.

- create the sysctl(8) kern.xen.balloon tree. 4 nodes are actually present
(values are in KiB):
- min: (rw) an admin-settable value that prevents ballooning below this
mark
- max: (ro) the maximum size for reservation, as set by xm(1) mem-max.
- current: (ro) the current reservation for domain.
- target: (rw) the targetted reservation for domain.

- fix a few limitations here and there, most notably the max_reservation
hypercall, and KiB vs pages representations at interfaces.

The driver is still turned off by default. Enabling it would need more
approval, especially from bouyer@, cherry@ and cegger@.

FWIW: tested it two days long, from amd64 dom0 (with dom0 ballooning
enabled for xend), and bunch of domUs. Did not notice anything suspicious.

XXX it still has one big limitation: it cannot hotplug memory pages in
uvm(9) if they were not present beforehand. Example: ballooning above
physmem will give more pages to domain but it won't use it to serve
allocations, unless we teach uvm(9) how to handle the extra pages.
 1.27 06-Mar-2011  bouyer merge the bouyer-quota2 branch. This adds a new on-disk format
to store disk quota usage and limits, integrated with ffs
metadata. Usage is checked by fsck_ffs (no more quotacheck)
and is covered by the WAPBL journal. Enabled with kernel
option QUOTA2 (added where QUOTA was enabled in kernel config files),
turned on with tunefs(8) on a per-filesystem
basis. mount_mfs(8) can also turn quotas on.

See http://mail-index.netbsd.org/tech-kern/2011/02/19/msg010025.html
for details.
 1.26 23-Nov-2010  hannken branches: 1.26.2; 1.26.4;
Remove unused count from pseudo-device md.
 1.25 12-Aug-2010  haad dd dm driver to XEN configs because they do not have modules working yet.
This will enable using LVM by default on XEN DOM0 hostings running NetBSD.

Change suggested by Sam Fourman.
 1.24 06-Jul-2010  cherry The Xen balloon driver enables growing and shrinking
PV domains on the fly, by collaborating with UVM and the hypervisor
 1.23 08-May-2010  mrg enable IPFILTER_COMPAT in all kernels that have ipfilter already.
canonicalise several of the ipf option segments in various files
(this mostly means adding commented out IPFILTER_DEFAULT_BLOCK,
or adding commented or uncommented IPFILTER_LOG or IPFILTER_LOOKUP
option statements.)

i built about 20 of these kernels to check, but not all of them.
 1.22 16-Apr-2010  pooka Remove unused count (invariably "4") from pseudo-device fss.
 1.21 17-Dec-2009  jym branches: 1.21.2; 1.21.4;
Compile in PaX support for Xen x86 kernels (dom0 and domU).

ok bouyer@. Compiled and tested by me under i386. Only compile tested for
amd64.
 1.20 05-Dec-2009  pooka Remove the portalfs kernel file system driver. Replace mount_portal(8)
with a version based on puffs. User functionality remains the same.
 1.19 25-Mar-2009  cegger catch up with i386 xen kernels:
enable cgd by default
 1.18 06-Mar-2009  cegger add options COMPAT_50
 1.17 04-Mar-2009  nisimura comment out NFS_BOOT_BOOTSTATIC. It will be useful when a valid set of
NFS_BOOTSTATICs are specfied.
 1.16 13-Feb-2009  bouyer Add commented out PCI pass-through support:
#xpci* at xenbus ? #Xen3 PCI front end driver
#pci* at xpci ?
 1.15 24-Nov-2008  ad branches: 1.15.4;
Remove softdep, pass 1. We are focused on improving journalling.

Proposed on tech-kern@.
 1.14 12-Nov-2008  ad Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.
 1.13 10-Aug-2008  cegger branches: 1.13.2; 1.13.4; 1.13.8;
Add accept filters per request from port-xen:
http://mail-index.netbsd.org/port-xen/2008/08/10/msg004087.html

pseudo-device entries were copied from sys/arch/i386/conf/GENERIC, rev. 1.904
 1.12 03-Aug-2008  joerg Reduce diff to GENERIC for compat options.
 1.11 03-Aug-2008  joerg Remove SYSV IPC options as they have been replaced with sysctls.
 1.10 31-Jul-2008  cegger Add "options WAPBL" to Xen configs
 1.9 26-May-2008  ad branches: 1.9.4;
Disable OSI networking.
 1.8 27-Mar-2008  tnn branches: 1.8.2; 1.8.4; 1.8.6;
Revert previous for DOMU kernels. They use a custom xennet bootstatic
callback for cmdline configuration. Keep for DOM0 kernels.
 1.7 27-Mar-2008  tnn Comment out NFS_BOOT_BOOTSTATIC. There no use having it in the default
kernel as it needs manual configuration anyway. Also, if it's enabled
but no static options given, then the kernel will happily configure the
interface as INADDY_ANY and not even try to use DHCP.
 1.6 29-Feb-2008  jmmv Remove GENERIC.local from the repository

Make all the kernels that currently include their corresponding GENERIC.local
file use the cinclude directive instead of include. This way config(1) will
not complain if the file cannot be found.

After doing this, remove the GENERIC.local files from the repository so that
the user will not see modified files during updates, and local changes to
them cannot end up in the repository by mistake.

Discussed in tech-kern@ earlier this month. No strong objections.
 1.5 02-Feb-2008  joerg branches: 1.5.2; 1.5.6;
amd64 kernels should use amd64 GENERIC.local.
 1.4 07-Jan-2008  martti branches: 1.4.2;
Fixed option indentation, it should be

option<space><tab>
makeoption<space><tab>
 1.3 31-Dec-2007  ad Remove systrace. Ok core@.
 1.2 22-Nov-2007  bouyer branches: 1.2.2; 1.2.4; 1.2.8; 1.2.12;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.1 17-Oct-2007  bouyer branches: 1.1.2; 1.1.4;
file XEN3_DOMU was initially added on branch bouyer-xenamd64.
 1.1.4.2 18-Feb-2008  mjf Sync with HEAD.
 1.1.4.1 08-Dec-2007  mjf Sync with HEAD.
 1.1.2.2 19-Nov-2007  bouyer Get rid of arch/xenamd64, step 1: empty xenamd64/conf
- move xenamd64/conf/std.xen to amd64/conf/
- define arch to amd64 amd64/conf/std.xen, and i386 in xen/conf/std.xen
(machine is xen)
- enclose content of amd64/conf/files.amd64 and i386/conf/files.i386 in
ifndef xen/endif, so it can be transparently inclued for xen kernels
- support MACHINE_ARCH=x86_64 in xen/conf/Makefile*
 1.1.2.1 17-Oct-2007  bouyer amd64 (aka x86-64) support for Xen. Based on the OpenBSD port done by
Mathieu Ropert in 2006.
DomU-only for now. An INSTALL_XEN3_DOMU kernel with a ramdisk will boot to
sysinst if you're lucky. Often it panics because a runable LWP has
a NULL stack (really, it's all of l->l_addr which is has been zeroed out
while the process was on the queue !)
TODO:
- bug fixes :)
- Most of the xpq_* functions should be shared with xen/i386
- The xen/i386 assembly bootstrap code should be remplaced with the C
version in xenamd64/amd64/xpmap.c
- see if a config(5) trick could allow to merge xenamd64 back to xen or amd64.
 1.2.12.2 08-Jan-2008  bouyer Sync with HEAD
 1.2.12.1 02-Jan-2008  bouyer Sync with HEAD
 1.2.8.5 17-Mar-2008  yamt sync with head.
 1.2.8.4 04-Feb-2008  yamt sync with head.
 1.2.8.3 21-Jan-2008  yamt sync with head
 1.2.8.2 07-Dec-2007  yamt sync with head
 1.2.8.1 22-Nov-2007  yamt file XEN3_DOMU was added on branch yamt-lazymbuf on 2007-12-07 17:24:02 +0000
 1.2.4.2 03-Dec-2007  ad Sync with HEAD.
 1.2.4.1 22-Nov-2007  ad file XEN3_DOMU was added on branch vmlocking on 2007-12-03 19:02:45 +0000
 1.2.2.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.2.2.1 22-Nov-2007  joerg file XEN3_DOMU was added on branch jmcneill-pm on 2007-11-27 19:35:30 +0000
 1.4.2.3 23-Mar-2008  matt sync with HEAD
 1.4.2.2 09-Jan-2008  matt sync with HEAD
 1.4.2.1 07-Jan-2008  matt file XEN3_DOMU was added on branch matt-armv6 on 2008-01-09 01:44:51 +0000
 1.5.6.4 17-Jan-2009  mjf Sync with HEAD.
 1.5.6.3 28-Sep-2008  mjf Sync with HEAD.
 1.5.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.5.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.5.2.1 24-Mar-2008  keiichi sync with head.
 1.8.6.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.8.6.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.8.4.4 09-Oct-2010  yamt sync with head
 1.8.4.3 11-Aug-2010  yamt sync with head.
 1.8.4.2 11-Mar-2010  yamt sync with head
 1.8.4.1 04-May-2009  yamt sync with head.
 1.8.2.1 04-Jun-2008  yamt sync with head
 1.9.4.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.9.4.1 19-Oct-2008  haad Sync with HEAD.
 1.13.8.1 21-Apr-2010  matt sync to netbsd-5
 1.13.4.4 09-Jun-2013  msaitoh Apply patch (requested by sborrill in ticket #1858):
sys/arch/amd64/conf/XEN3_DOMU
sys/arch/i386/conf/Attic/XEN2_DOMU
Add wedge support in DOMU kernels.
 1.13.4.3 13-Jan-2013  bouyer apply patch(s) (requested by sborrill in ticket #1834):
sys/arch/i386/conf/XEN2_DOMU: patch
sys/arch/amd64/conf/XEN3_DOMU: patch
Add drvctl to Xen DOMU kernels
 1.13.4.2 15-Feb-2010  sborrill Pull up the following revisions(s) (requested by tron in ticket #1306):
sys/arch/i386/conf/XEN2_DOM0 patch
sys/arch/i386/conf/XEN2_DOMU patch
sys/arch/amd64/conf/XEN3_DOM0 patch
sys/arch/amd64/conf/XEN3_DOM0 patch

Enable cgd(4) support on all amd64 and i386 XEN kernels.
 1.13.4.1 03-Oct-2009  snj Pull up following revision(s) (requested by bouyer in ticket #1054):
sys/arch/amd64/conf/XEN3_DOMU: revision 1.16
sys/arch/i386/conf/XEN3_DOMU: revision 1.12
Add commented out PCI pass-through support:
 1.13.2.3 28-Apr-2009  skrll Sync with HEAD.
 1.13.2.2 03-Mar-2009  skrll Sync with HEAD.
 1.13.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.15.4.7 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.15.4.6 02-May-2011  jym Sync with head.
 1.15.4.5 29-Mar-2011  jym More sync fixes. And add the mbr_gpt files.
 1.15.4.4 28-Mar-2011  jym Cure sync hiccups. Code with compile errors is not really useful, heh.
 1.15.4.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.15.4.2 01-Nov-2009  jym Sync with HEAD.
 1.15.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.21.4.4 31-May-2011  rmind sync with head
 1.21.4.3 21-Apr-2011  rmind sync with head
 1.21.4.2 05-Mar-2011  rmind sync with head
 1.21.4.1 30-May-2010  rmind sync with head
 1.21.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.21.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.26.4.1 08-Feb-2011  bouyer Add QUOTA2 where QUOTA is enabled (and QUOTA2 commented out where QUOTA
is commented out)
 1.26.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.30.2.1 03-Jun-2011  cherry Initial import of xen MP sources, with kernel and userspace tests.
- this is a source priview.
- boots to single user.
- spurious interrupt and pmap related panics are normal
 1.31.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.31.2.3 23-Jan-2013  yamt sync with head
 1.31.2.2 30-Oct-2012  yamt sync with head
 1.31.2.1 17-Apr-2012  yamt sync with head
 1.33.2.3 11-Mar-2012  mrg sync to latest -current
 1.33.2.2 04-Mar-2012  mrg sync to latest -current.
 1.33.2.1 18-Feb-2012  mrg merge to -current.
 1.36.2.2 15-Aug-2012  sborrill Pull up the following revisions(s) (requested by martin in ticket #502):
sys/arch/cobalt/conf/GENERIC: patch
sys/arch/i386/conf/GENERIC: patch
sys/arch/i386/conf/XEN3_DOM0: patch
sys/arch/i386/conf/XEN3_DOMU: patch
sys/arch/mvmeppc/conf/GENERIC: patch
sys/arch/shark/conf/GENERIC: patch
sys/arch/sparc64/conf/GENERIC: patch
sys/arch/sparc64/conf/GENERIC.DEBUG: patch
sys/arch/zaurus/conf/GENERIC: patch

Switch off DIAGNOSTIC and/or DEBUG on release kernels.
Enable DIAGNOSTIC in DEBUG kernels to allow for option
being switched off in GENERIC.
 1.36.2.1 25-Feb-2012  sborrill Pull up the following revisions(s) (requested by bouyer in ticket #52):
sys/arch/amd64/conf/XEN3_DOM0: revision 1.78
sys/arch/amd64/conf/XEN3_DOMU: revision 1.37
sys/arch/i386/conf/XEN3_DOM0: revision 1.61
sys/arch/i386/conf/XEN3_DOMU: revision 1.42

Xen is stable enough now to remove debug messages in default kernel.
Comment out options DEBUG from Xen kernel; also comment out makeoptions
DEBUG="-g" where it was still enabled.
 1.38.2.4 03-Dec-2017  jdolecek update from HEAD
 1.38.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.38.2.2 23-Jun-2013  tls resync from head
 1.38.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.49.2.2 18-May-2014  rmind sync with head
 1.49.2.1 28-Aug-2013  rmind sync with head
 1.53.2.1 10-Aug-2014  tls Rebase.
 1.54.2.4 22-Jul-2015  snj Pull up following revision(s) (requested by bouyer in ticket #884):
sys/arch/amd64/conf/XEN3_DOM0: revision 1.114
sys/arch/amd64/conf/XEN3_DOMU: revision 1.62
sys/arch/i386/conf/XEN3_DOM0: revision 1.96
sys/arch/i386/conf/XEN3_DOMU: revision 1.68
Uncoment options IPSEC, as requested by Gary Duzan in PR port-amd64/50052
 1.54.2.3 18-Nov-2014  snj Pull up following revision(s) (requested by manu in ticket #251):
sys/arch/acorn26/conf/GENERIC: revision 1.81
sys/arch/acorn32/conf/GENERIC: revision 1.116
sys/arch/alpha/conf/GENERIC: revision 1.362
sys/arch/amd64/conf/ALL: revision 1.23
sys/arch/amd64/conf/GENERIC: revision 1.404
sys/arch/amd64/conf/XEN3_DOM0: revision 1.112
sys/arch/amd64/conf/XEN3_DOMU: revision 1.60
sys/arch/amiga/conf/GENERIC.in: revision 1.129
sys/arch/amiga/conf/GENERIC: revision 1.311
sys/arch/amigappc/conf/GENERIC: revision 1.24
sys/arch/arc/conf/GENERIC: revision 1.184
sys/arch/bebox/conf/GENERIC: revision 1.145
sys/arch/cats/conf/GENERIC: revision 1.155
sys/arch/cesfic/conf/GENERIC: revision 1.65
sys/arch/cobalt/conf/GENERIC: revision 1.147
sys/arch/dreamcast/conf/GENERIC: revision 1.121
sys/arch/emips/conf/GENERIC: revision 1.15
sys/arch/epoc32/conf/GENERIC: revision 1.8
sys/arch/ews4800mips/conf/GENERIC: revision 1.51
sys/arch/hp300/conf/GENERIC: revision 1.190
sys/arch/hpcmips/conf/GENERIC: revision 1.229
sys/arch/hpcsh/conf/GENERIC: revision 1.106
sys/arch/hppa/conf/GENERIC: revision 1.6
sys/arch/i386/conf/ALL: revision 1.389
sys/arch/i386/conf/GENERIC: revision 1.1118
sys/arch/i386/conf/XEN3_DOM0: revision 1.93
sys/arch/i386/conf/XEN3_DOMU: revision 1.65
sys/arch/ibmnws/conf/GENERIC: revision 1.46
sys/arch/iyonix/conf/GENERIC: revision 1.88
sys/arch/landisk/conf/GENERIC: revision 1.45
sys/arch/luna68k/conf/GENERIC: revision 1.119
sys/arch/mac68k/conf/GENERIC: revision 1.220
sys/arch/macppc/conf/GENERIC: revision 1.320
sys/arch/macppc/conf/MAMBO: revision 1.24
sys/arch/macppc/conf/POWERMAC_G5: revision 1.25
sys/arch/mipsco/conf/GENERIC: revision 1.88
sys/arch/mmeye/conf/GENERIC: revision 1.120
sys/arch/mvme68k/conf/GENERIC: revision 1.94
sys/arch/mvmeppc/conf/GENERIC: revision 1.24
sys/arch/netwinder/conf/GENERIC: revision 1.126
sys/arch/news68k/conf/GENERIC: revision 1.125
sys/arch/newsmips/conf/GENERIC: revision 1.129
sys/arch/next68k/conf/GENERIC: revision 1.139
sys/arch/ofppc/conf/GENERIC: revision 1.157
sys/arch/pmax/conf/GENERIC64: revision 1.21
sys/arch/pmax/conf/GENERIC: revision 1.185
sys/arch/prep/conf/GENERIC: revision 1.174
sys/arch/rs6000/conf/GENERIC: revision 1.33
sys/arch/sandpoint/conf/GENERIC: revision 1.88
sys/arch/sbmips/conf/GENERIC: revision 1.101
sys/arch/sgimips/conf/GENERIC32_IP12: revision 1.28
sys/arch/sgimips/conf/GENERIC32_IP2x: revision 1.104
sys/arch/sgimips/conf/GENERIC32_IP3x: revision 1.106
sys/arch/shark/conf/GENERIC: revision 1.121
sys/arch/sparc/conf/GENERIC: revision 1.248
sys/arch/sparc/conf/TADPOLE3GX: revision 1.65
sys/arch/sparc64/conf/GENERIC: revision 1.177
sys/arch/sparc64/conf/NONPLUS64: revision 1.44
sys/arch/sun2/conf/GENERIC: revision 1.94
sys/arch/sun3/conf/GENERIC: revision 1.171
sys/arch/vax/conf/GENERIC: revision 1.193
sys/arch/vax/conf/VAX780: revision 1.19
sys/arch/x68k/conf/GENERIC: revision 1.179
sys/arch/zaurus/conf/GENERIC: revision 1.65
sys/ufs/files.ufs: revision 1.38
Remove unused extended attributes kernel options

As Masao Uebayashi pointed to me, UFS_EXTATTR_AUTOSTART, LFS_EXTATTR_AUTOSTART
and UFS_EXTATTR_AUTOCREATE are not used anywhere in the code. Remove them
as they have been obsolete for a long time:
UFS_EXTATTR_AUTOSTART was replaced by mount -o extattr
LFS_EXTATTR_AUTOSTART was created to match obsolete UFS_EXTATTR_AUTOSTART
UFS_EXTATTR_AUTOCREATE was replaced by sysctl vfs.ffs.extattr_autocreate
 1.54.2.2 14-Nov-2014  martin Pull up following revision(s) (requested by manu in ticket #232):
sys/arch/next68k/conf/GENERIC: revision 1.138
sys/arch/cobalt/conf/GENERIC: revision 1.146
sys/arch/mvme68k/conf/GENERIC: revision 1.93
sys/arch/vax/conf/VAX780: revision 1.18
sys/arch/newsmips/conf/GENERIC: revision 1.128
sys/arch/luna68k/conf/GENERIC: revision 1.118
sys/arch/sbmips/conf/GENERIC: revision 1.100
sys/arch/pmax/conf/GENERIC: revision 1.184
sys/arch/alpha/conf/GENERIC: revision 1.361
sys/arch/sparc64/conf/GENERIC: revision 1.176
sys/arch/sun3/conf/GENERIC: revision 1.170
sys/arch/shark/conf/GENERIC: revision 1.120
sys/arch/landisk/conf/GENERIC: revision 1.44
sys/arch/bebox/conf/GENERIC: revision 1.144
sys/arch/sparc64/conf/NONPLUS64: revision 1.43
sys/arch/sandpoint/conf/GENERIC: revision 1.87
sys/arch/emips/conf/GENERIC: revision 1.14
sys/arch/amd64/conf/XEN3_DOM0: revision 1.111
sys/arch/dreamcast/conf/GENERIC: revision 1.120
sys/arch/cesfic/conf/GENERIC: revision 1.64
sys/arch/mmeye/conf/GENERIC: revision 1.119
sys/arch/epoc32/conf/GENERIC: revision 1.7
sys/arch/x68k/conf/GENERIC: revision 1.178
sys/arch/iyonix/conf/GENERIC: revision 1.87
sys/arch/sun2/conf/GENERIC: revision 1.93
sys/arch/ews4800mips/conf/GENERIC: revision 1.50
sys/arch/amd64/conf/XEN3_DOMU: revision 1.59
sys/arch/acorn26/conf/GENERIC: revision 1.80
sys/arch/acorn32/conf/GENERIC: revision 1.115
sys/arch/macppc/conf/POWERMAC_G5: revision 1.24
sys/arch/i386/conf/GENERIC: revision 1.1117
sys/arch/arc/conf/GENERIC: revision 1.183
sys/arch/cats/conf/GENERIC: revision 1.154
sys/arch/amiga/conf/GENERIC.in: revision 1.128
sys/arch/zaurus/conf/GENERIC: revision 1.64
sys/arch/netwinder/conf/GENERIC: revision 1.125
sys/arch/hppa/conf/GENERIC: revision 1.5
sys/arch/mvmeppc/conf/GENERIC: revision 1.23
sys/arch/macppc/conf/GENERIC: revision 1.319
sys/arch/amiga/conf/GENERIC: revision 1.310
sys/arch/pmax/conf/GENERIC64: revision 1.20
sys/arch/macppc/conf/MAMBO: revision 1.23
sys/arch/sgimips/conf/GENERIC32_IP12: revision 1.27
sys/arch/amigappc/conf/GENERIC: revision 1.23
sys/arch/amd64/conf/GENERIC: revision 1.403
sys/arch/ofppc/conf/GENERIC: revision 1.156
sys/arch/mac68k/conf/GENERIC: revision 1.219
sys/arch/i386/conf/XEN3_DOMU: revision 1.64
sys/arch/mipsco/conf/GENERIC: revision 1.87
sys/arch/hp300/conf/GENERIC: revision 1.189
sys/arch/vax/conf/GENERIC: revision 1.192
sys/arch/news68k/conf/GENERIC: revision 1.124
sys/arch/ibmnws/conf/GENERIC: revision 1.45
sys/arch/hpcsh/conf/GENERIC: revision 1.105
sys/arch/sparc/conf/TADPOLE3GX: revision 1.64
sys/arch/i386/conf/XEN3_DOM0: revision 1.92
sys/arch/sparc/conf/GENERIC: revision 1.247
sys/arch/sgimips/conf/GENERIC32_IP3x: revision 1.105
sys/arch/prep/conf/GENERIC: revision 1.173
sys/arch/sgimips/conf/GENERIC32_IP2x: revision 1.103
sys/arch/rs6000/conf/GENERIC: revision 1.32
sys/arch/hpcmips/conf/GENERIC: revision 1.228
Support for UFS1 extended attributes in GENERIC and GENERIC-like kernels
This change just brings UFS1 extended attribute *support* in the kernel,
extended attributes are not enabled unless three conditions are met:
1) filesystem is UFS1 (newfs -O1)
2) .attribute/system and .attribute/user directories are created at fs root
3) filesystem is mounted with -o extattr
Some GENERIC kernels are obviously memory constrained, the extended
attributes options were not enabled for them, but just added commented out.
(kernel were considered memory constrained if QUOTA option was disabled)
 1.54.2.1 10-Oct-2014  snj Apply patch (requested by bouyer/martin in ticket #116):
Disable DIAGNOSTIC and/or DEBUG.
 1.60.2.6 28-Aug-2017  skrll Sync with HEAD
 1.60.2.5 05-Feb-2017  skrll Sync with HEAD
 1.60.2.4 29-May-2016  skrll Sync with HEAD
 1.60.2.3 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.60.2.2 22-Sep-2015  skrll Sync with HEAD
 1.60.2.1 06-Jun-2015  skrll Sync with HEAD
 1.65.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.65.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.68.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.73.4.1 19-May-2017  pgoyette Resolve conflicts from previous merge (all resulting from $NetBSD
keywork expansion)
 1.75.2.4 18-Apr-2018  martin Requested by skrll in ticket #60:
sys/arch/amd64/conf/GENERIC
sys/arch/amd64/conf/XEN3_DOM0
sys/arch/amd64/conf/XEN3_DOMU
sys/arch/cobalt/conf/GENERIC
sys/arch/evbarm/conf/BEAGLEBONE
sys/arch/evbarm/conf/BEAGLEBOARD
sys/arch/evbarm/conf/BEAGLEBOARDXM
sys/arch/evbarm/conf/GENERIC.common
sys/arch/i386/conf/GENERIC
sys/arch/i386/conf/XEN3_DOM0
sys/arch/i386/conf/XEN3_DOMU
sys/arch/mvmeppc/conf/GENERIC
sys/arch/shark/conf/GENERIC
sys/arch/sparc64/conf/GENERIC
sys/arch/zaurus/conf/GENERIC

Remove option DIAGNOSTIC.
 1.75.2.3 26-Jan-2018  martin Pull up following revision(s) (requested by sevan in ticket #510):
sys/arch/sun3/conf/GENERIC3X: revision 1.130
sys/arch/sparc64/conf/GENERIC: revision 1.203
sys/arch/news68k/conf/LIBERO: revision 1.66
sys/arch/amiga/conf/DRACO: revision 1.185
sys/arch/evbarm/conf/MV2120: revision 1.35
sys/arch/x68k/conf/GENERIC: revision 1.187
sys/arch/rs6000/conf/GENERIC: revision 1.39
sys/arch/news68k/conf/GENERIC_TINY: revision 1.86
sys/arch/i386/conf/XEN3_DOMU: revision 1.88
sys/arch/iyonix/conf/GENERIC: revision 1.97
sys/arch/evbarm64/conf/A64EMUL: revision 1.11
sys/arch/mvme68k/conf/GENERIC: revision 1.98
sys/arch/acorn32/conf/GENERIC: revision 1.124
sys/arch/i386/conf/XEN3_DOM0: revision 1.125
sys/arch/cobalt/conf/INSTALL: revision 1.65
sys/arch/macppc/conf/GENERIC_601: revision 1.16
sys/arch/hppa/conf/GENERIC: revision 1.17
sys/arch/amiga/conf/GENERIC.in: revision 1.137
sys/arch/sgimips/conf/GENERIC32_IP12: revision 1.33
sys/arch/netwinder/conf/GENERIC: revision 1.134
sys/arch/amd64/conf/XEN3_DOMU: revision 1.83
sys/arch/mac68k/conf/GENERIC: revision 1.225
sys/arch/arc/conf/RPC44: revision 1.54
sys/arch/mipsco/conf/GENERIC: revision 1.92
sys/arch/cats/conf/GENERIC: revision 1.166
sys/arch/amd64/conf/XEN3_DOM0: revision 1.145
sys/arch/amigappc/conf/GENERIC: revision 1.33
sys/arch/sun3/conf/GENERIC: revision 1.176
sys/arch/news68k/conf/GENERIC: revision 1.130
sys/arch/hpcsh/conf/GENERIC: revision 1.110
sys/arch/hp300/conf/GENERIC: revision 1.198
sys/arch/atari/conf/GENERIC.in: revision 1.115
sys/arch/sparc/conf/MRCOFFEE: revision 1.54
sys/arch/evbppc/conf/EXPLORA451: revision 1.62
sys/arch/cesfic/conf/GENERIC: revision 1.69
sys/arch/vax/conf/GENERIC: revision 1.204
sys/arch/sgimips/conf/GENERIC32_IP3x: revision 1.115
sys/arch/sgimips/conf/GENERIC32_IP2x: revision 1.112
sys/arch/sparc/conf/GENERIC: revision 1.258
sys/arch/next68k/conf/GENERIC: revision 1.145
sys/arch/evbarm/conf/MMNET_GENERIC: revision 1.34
sys/arch/prep/conf/GENERIC: revision 1.185
sys/arch/amiga/conf/INSTALL: revision 1.129
sys/arch/newsmips/conf/GENERIC: revision 1.133
sys/arch/cobalt/conf/GENERIC: revision 1.156
sys/arch/sun2/conf/GENERIC: revision 1.99
sys/arch/luna68k/conf/INSTALL: revision 1.25
sys/arch/amigappc/conf/NULL: revision 1.53
sys/arch/acorn26/conf/GENERIC: revision 1.85
sys/arch/vax/conf/VAX780: revision 1.25
sys/arch/luna68k/conf/GENERIC: revision 1.125
sys/arch/ews4800mips/conf/GENERIC: revision 1.56
sys/arch/macppc/conf/POWERMAC_G5: revision 1.29
sys/arch/arc/conf/GENERIC: revision 1.189
sys/arch/macppc/conf/MAMBO: revision 1.27
sys/arch/acorn32/conf/EB7500ATX: revision 1.64
sys/arch/pmax/conf/GENERIC: revision 1.196
sys/arch/pmax/conf/GENERIC64: revision 1.28
sys/arch/amiga/conf/GENERIC: revision 1.319
sys/arch/evbarm/conf/MPCSA_GENERIC: revision 1.55
sys/arch/macppc/conf/GENERIC: revision 1.339
sys/arch/emips/conf/GENERIC: revision 1.21
sys/arch/sandpoint/conf/GENERIC: revision 1.97
sys/arch/landisk/conf/GENERIC: revision 1.58
sys/arch/bebox/conf/GENERIC: revision 1.157
sys/arch/alpha/conf/GENERIC: revision 1.379
Alternate buffer queue strategies no longer considered experimental, update
description.
Discussed on tech-kern
http://mail-index.netbsd.org/tech-kern/2018/01/21/msg023002.html
 1.75.2.2 29-Aug-2017  martin Requested by skrll in ticket #60:
sys/arch/amd64/conf/GENERIC
sys/arch/amd64/conf/XEN3_DOM0
sys/arch/amd64/conf/XEN3_DOMU
sys/arch/cobalt/conf/GENERIC
sys/arch/evbarm/conf/BEAGLEBONE
sys/arch/evbarm/conf/BEAGLEBOARD
sys/arch/evbarm/conf/BEAGLEBOARDXM
sys/arch/evbarm/conf/GENERIC.common
sys/arch/i386/conf/GENERIC
sys/arch/i386/conf/XEN3_DOM0
sys/arch/i386/conf/XEN3_DOMU
sys/arch/mvmeppc/conf/GENERIC
sys/arch/shark/conf/GENERIC
sys/arch/sparc64/conf/GENERIC
sys/arch/zaurus/conf/GENERIC


Re-enable option DIAGNOSTIC for now, will remove it again later.
 1.75.2.1 05-Jul-2017  martin Remove options DIAGNOSTIC/DEBUG and PAX debug options.
Requested by snj in #60.
 1.84.4.3 21-Apr-2020  martin Sync with HEAD
 1.84.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.84.4.1 10-Jun-2019  christos Sync with HEAD
 1.84.2.2 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.84.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.89.2.1 21-Nov-2019  martin In preparation for the upcoming release, turn off DIAGNOSTIC in most
kernel configs, modules and libc.
 1.90.6.4 22-Apr-2020  bouyer Remove HZ=20, it was to testing only.
 1.90.6.3 20-Apr-2020  bouyer Sync with HEAD
 1.90.6.2 15-Apr-2020  bouyer On amd64, always use the cmpxchg8b version of spllower. All x86_64 host should
have it and we already rely on it in lock stubs.
On i386, always use i686_mutex_spin_exit and cx8_spllower for Xen;
Xen doesn't run on CPUs on CPUs lacking the required instructions anyway.
Skip x86_patch only for XENPV, and adjust for changes in assembly functions.
Tested on Xen PV and PVHVM, and on bare metal core i5.
 1.90.6.1 08-Apr-2020  bouyer Turn on -g by default on the branch
 1.96.2.1 03-Apr-2021  thorpej Sync with HEAD.
 1.99.4.2 29-Mar-2025  martin Pull up following revision(s) (requested by sborrill in ticket #1076):

sys/arch/amd64/conf/XEN3_DOMU: revision 1.101
sys/arch/amd64/conf/XEN3_DOMU: revision 1.102

amd64/XEN3_DOMU: Pass -g to build debug data like GENERIC.
Needed for CTF data by dtrace when MKDEBUG=no MKDEBUGKERNEL=no.

amd64/XEN3_DOMU: Enable KDTRACE_HOOKS.
 1.99.4.1 09-Oct-2023  snj Apply patch (requested by martin in ticket #401):
Disable DIAGNOSTIC/DEBUG.
 1.105.2.1 02-Aug-2025  perseant Sync with HEAD
 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 15-Apr-2020  jdolecek remove MAXPHYS override, xbd(4) was changed to work with 64k transfers
 1.3 06-Apr-2020  bouyer branches: 1.3.2;
use conf/filesystems.config, fix missing PTYFS
 1.2 21-Aug-2019  maxv No USER_LDT on Xen.
 1.1 14-Feb-2019  cherry branches: 1.1.4;
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.1.4.4 21-Apr-2020  martin Sync with HEAD
 1.1.4.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1.4.2 10-Jun-2019  christos Sync with HEAD
 1.1.4.1 14-Feb-2019  christos file XEN3_PVHVM was added on branch phil-wifi on 2019-06-10 22:05:47 +0000
 1.3.2.4 25-Apr-2020  bouyer Merge GENERIC_XENHVM in GENERIC.
Remove XEN3_PVHVM/XEN3PAE_PVHVM files which have been obsolete for some time
on the branch
 1.3.2.3 20-Apr-2020  bouyer Sync with HEAD
 1.3.2.2 10-Apr-2020  bouyer spllower(): Also check Xen pending events
hypervisor_pvhvm_callback(): exit via Xdoreti, so that pending interrupts
are checked.
disable __HAVE_FAST_SOFTINTS only for XENPV, it now works for PVHVM.
We still have to disable PREEMPTION, until we support MULTIPROCESSOR
 1.3.2.1 08-Apr-2020  bouyer Turn on -g by default on the branch
 1.1 27-Aug-2010  uebayasi branches: 1.1.2;
file XIP was initially added on branch uebayasi-xip.
 1.1.2.2 30-Oct-2010  uebayasi xmd(4) uses a conflicting symbol "md_root_image" with md(4).
Exclude md(4) where xmd(4) is used.

XXX In the long run mdsetimage(8) must die.
 1.1.2.1 27-Aug-2010  uebayasi xmd(4) / XIP config for amd64.
 1.124 02-Jan-2025  imil Trivial bus implementation inspired by OpenBSD's pv(4) to attach devices
that don't need nor rely on a PCI or ISA bus.
 1.123 23-Feb-2024  andvar branches: 1.123.2;
s/optionms/options/ in copy-pasted comment.
 1.122 05-Dec-2023  thorpej Add btvmei + btvmeii and vme to ALL.
 1.121 05-May-2023  manu Add a SELFRELOC kernel option for the sake of documentation clarity.

Instead of telling that x86/boot(8) reloc command needs a kernel able
to self relocate, we can tell it needs a kernel built with the
SELFRELOC option. This keeps the reader from wondering what could
make a kernel able to self relocate.
 1.120 21-Oct-2020  christos branches: 1.120.20;
make process_machdep.c included always since it provides register i/o used by
sys_process_getlwpstatus.c which is always included.
 1.119 20-Oct-2020  christos harmonize process_machdep.c inclusion.
 1.118 19-Oct-2020  christos Arrange so that no options COREDUMP and no options PTRACE work together.
Thanks to Paul Goyette for testing.
 1.117 15-Oct-2020  mgorny Revert "Merge convert_xmm_s87.c into fpu.c"

I am going to add ATF tests for these two functions, and having them
in a separate file will make it more convenient to build and run them
in userspace.
 1.116 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.115 09-Jan-2020  manu branches: 1.115.4;
Rollback multiboot2 for amd64, as requested by core
 1.114 10-Dec-2019  manu branches: 1.114.2;
Add multiboot 2 support to amd64 kernel
 1.113 07-Sep-2019  maxv Merge amd64func.S into cpufunc.S, and clean up.
 1.112 15-Feb-2019  nonaka branches: 1.112.4;
Added Microsoft Hyper-V support. It ported from OpenBSD and FreeBSD.

graphical console is not work on Gen.2 VM yet. To use the serial console,
enter "consdev com,0x3f8,115200" on efiboot.
 1.111 27-Jan-2019  pgoyette Merge the [pgoyette-compat] branch
 1.110 22-Dec-2018  cherry This change modifies the mainbus(4) entry point for all x86 sub-archs
in the following way:

i) It provides a unified entry point in
x86/x86/mainbus.c:mainbus_attach()
ii) It carves out the preliminary bus attachment sequence that is
common to all sub-archs into
x86/x86/mainbus.c: x86_cpubus_attach()
iii) It consolidates the remaining pathways as internal callee
functions so that these may be called piecemeal if required. A
special usecase of this is XEN PVHVM which may need to call the
native configure path, the xen configure path, or both.
iv) It moves the driver private data structures from
i386/i386_mainbus.c to an x86/ level one. This allows for other
sub-arch's to do similar, if needed. (They do not at the moment).
v) For dom0 kernels, it enables 'acpi0 at mainbus?' and
'acpi0 at hypervisorbus'. This serves two purposes:
a) To demonstrate the possibility of dynamic configuration tree
traversal ordering changes.
b) To allow for the common acpi_check(self, "acpibus") call in
x86/mainbus.c to not barf when it is called from the dom0 attach
path. We allow for the acpi0 device to be a child of mainbus with
the changes to amd64/conf/XEN3_DOM0 and i386/conf/XEN3PAE_DOM0
without actually probing further in the code. This path will later
be pursued in a PVHVM boot codepath.

There should be no operative changes with this change. If there are,
please complain loudly.
 1.109 22-Dec-2018  cherry Move mainbus(4) driver files in various x86 sub-archs to name prefixed
versions. This allows us to further modularise them by unifying common
bus probe code in x86/x86/mainbus.c to be introduced next.

This commit has no functional changes. It is done for ease of
visibility of newer diffs in the queue.
 1.108 03-Dec-2018  christos KASLR is in files.kern now.
 1.107 31-Oct-2018  maxv Move the MI parts of KASAN into kern/subr_asan.c. This file includes
machine/asan.h, which contains the MD functions. We use an include rather
than a plain C file, because we want GCC to optimize/inline some functions
into one single block.

The amd64 MD parts of KASAN are moved accordingly.

The naming convention we use is:

kasan_*
a generic kasan object, declared in subr_asan.c
kasan_md_*
an MD kasan object, declared in machine/asan.h, and used
in subr_asan.c
__md_*
an MD object, declared in machine/asan.h, and not used
outside

Overall this makes it easier to add KASAN support on more architectures.

Discussed with several people.
 1.106 20-Aug-2018  maxv Add support for kASan on amd64. Written by me, with some parts inspired
from Siddharth Muralee's initial work. This feature can detect several
kinds of memory bugs, and it's an excellent feature.

It can be enabled by uncommenting these three lines in GENERIC:

#makeoptions KASAN=1 # Kernel Address Sanitizer
#options KASAN
#no options SVS

The kernel is compiled without SVS, without DMAP and without PCPU area.
A shadow area is created at boot time, and it can cover the upper 128TB
of the address space. This area is populated gradually as we allocate
memory. With this design the memory consumption is kept at its lowest
level.

The compiler calls the __asan_* functions each time a memory access is
done. We verify whether this access is legal by looking at the shadow
area.

We declare our own special memcpy/memset/etc functions, because the
compiler's builtins don't add the __asan_* instrumentation.

Initially all the mappings are marked as valid. During dynamic
allocations, we add a redzone, which we mark as invalid. Any access on
it will trigger a kASan error message. Additionally, the compiler adds
a redzone on global variables, and we mark these redzones as invalid too.
The illegal-access detection works with a 1-byte granularity.

For now, we cover three areas:

- global variables
- kmem_alloc-ated areas
- malloc-ated areas

More will come, but that's a good start.
 1.105 13-Jul-2018  maxv Remove the X86PMC code I had written, replaced by tprof. Many defines
become unused in specialreg.h, so remove them. We don't want to add
defines all the time, there are countless PMCs on many generations, and
it's better to just inline the event/unit values.
 1.104 23-May-2018  maxv branches: 1.104.2;
Merge convert_xmm_s87.c into fpu.c. It contains only two functions, that
are used only in fpu.c.
 1.103 22-May-2018  maxv Mmh, don't compile spectre.c on Xen.
 1.102 07-Apr-2018  mrg add an SPECTRE_V2_GCC_MITIGATION option to x86 kernels, that turns
on the GCC spectre v2 mitigation options.

XXX: pullup-8.
XXX: turn on in all kernels.
 1.101 20-Jan-2018  maxv branches: 1.101.2;
Compile amd64_trap.S as a file instead of including it.
 1.100 08-Jan-2018  maxv Since SVS is now defined in files.x86, remove it from files.amd64
and files.i386.
 1.99 08-Jan-2018  martin Now that SVS is defined in file.x86, do not repeat it here
 1.98 07-Jan-2018  maxv Add a new option, SVS (for Separate Virtual Space), that unmaps kernel
pages when running in userland. For now, only the PTE area is unmapped.

Sent on tech-kern@.
 1.97 01-Jan-2018  maxv Compile the prekern entry point only under KASLR.
 1.96 07-Dec-2017  christos Save maxv@ some work and put back the compat_13_sigreturn changes that allow
amd64 to run ancient i386 binaries.
 1.95 02-Dec-2017  maxv Drop COMPAT_13 on amd64, already not enabled. Reduces the number of
critical places.
 1.94 08-Oct-2017  maxv KASLR: add workarounds to compute the bootinfo VAs (use the direct map),
and don't use large pages yet. Both will be fixed later.
 1.93 08-Oct-2017  maxv Add the prekern entry point in the kernel.
 1.92 15-Aug-2017  maxv Merge into x86/.
 1.91 15-Aug-2017  maxv Merge into x86/.
 1.90 01-Aug-2017  maxv Don't include files.svr4 and files.svr4_32.
 1.89 12-Jul-2017  maxv include opt_pmc.h
 1.88 15-Dec-2016  kamil branches: 1.88.8;
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.87 06-Sep-2015  uebayasi branches: 1.87.2;
Define MD start code at the top of files.${MACHINE} relying on config(1)'s
deterministic file output order. No need to define ${MD_OBJS} and its useless,
explicit compile rules.
 1.86 15-Dec-2014  christos fix compat paths.
 1.85 14-Dec-2014  christos add the two new compat files.
 1.84 10-Oct-2014  uebayasi branches: 1.84.2;
Define "machdep" attribute and mark files (in amd64 and x86).
 1.83 20-Feb-2014  pgoyette Since fpu.c is contained in every kernel, and it calls routines in
convert_xmm_s87.c we need to include convert_xmm_s87.c in all kernels.

Fixes building of kernels that do not have COMPAT_NETBSD32 defined.
 1.82 11-Feb-2014  dsl Move sys/arch/amd64/amd64/fpu.c and sys/arch/amd64/include/fpu.h
into sys/arch/x86 in preparation for using the same code for i386.
 1.81 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.80 17-Jul-2013  soren A few "isa" files are so tightly integrated into the x86 platform code
as to not really be part of the optional isa bus autoconf machinery.

Allows configuring a kernel like so:

include "arch/amd64/conf/GENERIC"
no isa
 1.79 13-Oct-2012  alnsn branches: 1.79.2; 1.79.8;
Enable sljit in amd64 kernel and modules.
 1.78 04-Oct-2012  dsl Remove references to VM86 from the amd64 kernel configs.
VM86 mode isn't supported while in long mode.
 1.77 27-Sep-2012  alnsn Remove bpf_jit which was ported from FreeBSD recently.

It will soon be replaced with the new bpfjit kernel module.
 1.76 01-Aug-2012  rmind branches: 1.76.2;
Add BPF JIT compiler, currently supporting amd64 and i386. Code obtained
from FreeBSD. Also, make few BPF fixes and simplifications while here.
Note that bpf_jit_enable is false for now.

OK dyoung@, some feedback from matt@
 1.75 07-May-2012  jym Merge i386 and amd64 version of db_memrw.c.

Use this opportunity to skip calculating the VA of the page. Let the CPU
deal with the invalidation itself through invlpg + destination address to
avoid converting between canonical/non canonical forms.
 1.74 06-Nov-2011  christos branches: 1.74.4;
Add compat_svr4 hooks, this does not work yet.
 1.73 12-Jun-2011  rmind branches: 1.73.2;
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 10-Apr-2011  christos branches: 1.72.2;
Merge db_trace for x86. From: Vladimir Kirillov proger at wilab dot org dot ua
 1.71 04-Apr-2011  dyoung Don't need x86_stub.c here, we'll pick it up from files.x86.
 1.70 03-Apr-2011  dyoung Clean up excessive #ifdef'age of NMI trap handling for amd64/i386/xen.
Handle NMI in all Xen kernels.
 1.69 08-Jul-2010  rmind branches: 1.69.2;
Unify i386 and amd64 procfs MD code into x86.
 1.68 16-Jun-2009  bouyer branches: 1.68.2; 1.68.4;
Split mc146818-related functions from clock.c into rtc.c.
Call rtc_set_ymdhms() from xen/xen/clock.c:xen_rtc_set() for xen3 dom0
kernels as the Xen3 hypervisor doesn't write the new date/time to the CMOS
by itself.
Now a XEN3_DOM0 kernel properly updates the CMOS time.
 1.67 21-Apr-2009  nonaka Added SD/MMC support from OpenBSD.
tested on i386, amd64 at current-users ML by pgoyette@.
tested on zaurus by myself.
 1.66 16-Apr-2009  rmind - Add macros to handle (some) trapframe registers for common x86 code.
- Merge i386 and amd64 syscall.c into x86. No functional changes intended.

Proposed on (port-i386 & port-amd64). Unfortunately, I cannot merge these
lists into the single port-x86. :(
 1.65 30-Mar-2009  rmind Merge i386 and amd64 ipifuncs.c into x86. No functional changes intended.
XXX: fpu #ifdefs are ugly (should be revisited at some point).
 1.64 30-Mar-2009  rmind Merge i386 and amd64 vm_machdep.c into x86. No functional changes intended.
Note: some #ifdefs will be removed with macros.
 1.63 30-Mar-2009  rmind Merge/move core_machdep.c into x86, no difference between i386 and amd64.
 1.62 14-Feb-2009  cube Don't set version deep in the source tree if it's older than the one in
conf/files.
 1.61 19-Nov-2008  ad branches: 1.61.4;
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.60 11-May-2008  ad branches: 1.60.4; 1.60.6; 1.60.8; 1.60.12;
Simplify x86 identcpu code, and share between i386/amd64.
 1.59 10-Mar-2008  ad branches: 1.59.2; 1.59.4; 1.59.6;
Implement an optimized, preemption-safe asm version of tsc_get_timecount().
The C version needs work to be preemption safe. Cuts the clock cycles
for microtime() from 950 down to 300 on a Pentium D.
 1.58 20-Feb-2008  drochner branches: 1.58.2; 1.58.6;
Since files.wscons et al. are included by ~all ports anyway, include
them in the mi "files" file, and remove include statements from md files.
These shouldn't pull in additional kernel code when not in use, so it
shouldn't do any harm except a risk of namespace collisions which
should be easy to fix.
 1.57 02-Feb-2008  joerg Fix flags: cpu_in_cksum should modify cpu_in_cksum.S, not cpufuncs.S.
 1.56 25-Jan-2008  joerg Refactor in_cksum/in4_cksum/in6_cksum implementations:
- All three functions are included in the kernel by default.
They call a backend function cpu_in_cksum after possibly
computing the checksum of the pseudo header.
- cpu_in_cksum is the core to implement the one-complement sum.
The default implementation is moderate fast on most platforms
and provides a 32bit accumulator with 16bit addends for L32 platforms
and a 64bit accumulator with 32bit addends for L64 platforms.
It handles edge cases like very large mbuf chains (could happen with
native IPv6 in the future) and provides a good base for new native
implementations.
- Modify i386 and amd64 assembly to use the new interface.

This disables the MD implementations on !x86 until the conversion is
done. For Alpha, the portable version is faster.
 1.55 16-Jan-2008  ad Remove options MATH_EMULATE.
 1.54 09-Jan-2008  joerg Add assembler version of in_cksum. Thanks to ad@ for his time as
peep hole optimiser. This is 30% faster than the portable C version
for checksumming 64byte and larger mbufs and as fast as or slightly
faster for shorter mbufs (with a high variance).
 1.53 06-Jan-2008  ad Add MODULAR option. Include kernel linker stuff if MODULAR.
 1.52 26-Dec-2007  joerg Add PHYSMEM_MAX_ADDR and PHYSMEM_MAX_SIZE options. This limit physical
memory based on overall size (useful for debugging to keep core dumps
small) or maximum address (when using devices with bus dma limits).
Contrary to REALBASEMEM and REALEXTMEM, they still use the BIOS memory
map and can therefore deal with fragmented memory.
 1.51 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.50 09-Dec-2007  jmcneill branches: 1.50.2;
Merge jmcneill-pm branch.
 1.49 22-Nov-2007  bouyer branches: 1.49.2; 1.49.4;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.48 26-Oct-2007  xtraeme branches: 1.48.2;
Share pcib(4) and amdpcib(4) between i386 and amd64; one copy is enough.
 1.47 26-Oct-2007  xtraeme - Share pchb(4) between i386 and amd64; one copy is enough for both.
- Move some of the x86 PCI devices into x86/pci/files.pci.
- Add more x86 stuff into x86/conf/files.x86.

ok joerg.
 1.46 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.45 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.44 26-Sep-2007  ad branches: 1.44.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.43 29-Aug-2007  ad branches: 1.43.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.42 26-Aug-2007  xtraeme branches: 1.42.2;
Some changes for the ichlpcib driver:

- Moved to x86/pci, so that EM64T systems running NetBSD/amd64 can use it.
- Added support for the TCO on ICH6 or newer chipsets, adapted from
FreeBSD.
- Added timecounter support for the power management timer, adapted from
OpenBSD.
- Plus some misc/cosmetic changes.

Thanks to yukonbob on irc@freenode for testing the TCO part on ICH4-M.
Tested by me with ICH7 too.
 1.41 06-Aug-2007  kiyohara Add support agp_amd64. Imported from FreeBSD.
 1.40 07-Jul-2007  tsutsui branches: 1.40.2; 1.40.4; 1.40.8;
Remove leftover netns stuff.
 1.39 03-Jul-2007  briggs Add (commented-out) support for IPMI on amd64--pretty much copied straight
from i386.
 1.38 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.37 16-Apr-2007  ad branches: 1.37.2;
Share the sysarch stuff between the x86 ports. PR kern/36046.
 1.36 10-Apr-2007  macallan include files.wsfb
 1.35 20-Mar-2007  xtraeme Erm, remove a local change committed accidentally in previous.
 1.34 20-Mar-2007  xtraeme ALL: Enable INTEL_ONDEMAND_CLOCKMOD.
GENERIC: Add INTEL_ONDEMAND_CLOCKMOD disabled by default.
 1.33 08-Mar-2007  njoly branches: 1.33.2; 1.33.4;
High Precision Event Timer driver, following Intel specifications.

Allow attachement at both ACPI (hpet@acpi) and AMD8111 LPC Controller
(hpet@amdpcib).

Requested by xtraeme, and tested by a few users.
 1.32 05-Mar-2007  drochner 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.31 09-Feb-2007  ad branches: 1.31.2;
Merge newlock2 to head.
 1.30 18-Dec-2006  christos Attach agp too.
 1.29 10-Sep-2006  plunky branches: 1.29.2; 1.29.4; 1.29.6;
add bluetooth support to amd64 port, built by default in GENERIC kernels
 1.28 04-Sep-2006  perry branches: 1.28.2;
switch to a common clock.c
 1.27 07-Aug-2006  xtraeme * Do not change struct powernow_pst_s (I added another member in my
previous patch) and this MUST be of that size, otherwise the tables
won't be found.

* powernow_k8.c moved into x86/x86, it should work both i386 and amd64.

* Added more DPRINTFs needed to found the first problem.

* Create "machdep.powernow.frequency" again, I can't remember why I
removed frequency... it should work with estd now.

* Do not try to call k[78]_powernow_init() if cpu is not AMD (thanks
to christos).

And more things I can't remember, but this time it will work in
Athlon 64 cpus and it won't crash in EM64T cpus.
 1.26 06-Aug-2006  xtraeme AMD PowerNow!/Cool`n'Quiet driver for NetBSD/amd64,
adapted from OpenBSD.

Tested on a few machines:

http://bigbird.dohd.org:3021/NetBSD/dmesg
http://www.bsd.org.il/netbsd/acpi/dmesg

Thanks to cube, elad and others for testing and fixes.

Enabled by default on GENERIC.
 1.25 10-Jul-2006  fvdl kern/33961: add kgdb support and remove some redundant (and incorrect) register
offset definitions from reg.h
 1.24 09-Jul-2006  christos include files.apm
 1.23 07-Jun-2006  kardel branches: 1.23.2;
convert to timecounters (from branch simonb-timecounters)
 1.22 04-Apr-2006  gdamore branches: 1.22.2;
Convert existing ath users to new Makefile, except for amd64, which needs
the rules due to needing to conditionally postprocess the HAL object file.

Macppc needs a a non-ELF HAL (EABI) object, so take care of that by default
in the atheros include file.
 1.21 12-Feb-2006  tron branches: 1.21.2; 1.21.4; 1.21.6;
Share Intel hardware random number generator support between amd64 and
i386 port. This will benefit EM64T systems using Intel i9xx chipsets.
 1.20 09-Feb-2006  manu Add initial (but unfinished) COMPAT_LINUX32 for amd64. This is good enough so
that the i386 license manager part of amd64 version of Fluent works.

While I'm here, add SysV IPC to COMPAT_LINUX/amd64
 1.19 21-Dec-2005  rjs branches: 1.19.2; 1.19.4; 1.19.6;
Add boilerplate for cardbus support.
 1.18 11-Dec-2005  christos merge ktrace-lwp.
 1.17 12-Jul-2005  sekiya Add config goo for ath. Tested with a PCI card, detected as:

ath0 at pci0 dev 10 function 0
ath0: interrupting at ioapic0 pin 17 (irq 5)
ath0: 11a rates: 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps
ath0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
ath0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36M bps 48Mbps 54Mbps
ath0: mac 5.9 phy 4.3 radio 3.6

Cardbus untested, so it is commented out.
 1.16 15-May-2005  fvdl branches: 1.16.2;
Move linux_trap.c from sys/arch/i386/i386 to sys/arch/x86/x86, and share
it. Remove the amd64 linux_trap.c (which was just a stub with a printf
anyway).
 1.15 15-May-2005  fvdl Fix up COMPAT_LINUX support for amd64. Still a work in progress, not
usable yet ("Hello World" runs, but many other things do not work).
 1.14 30-Aug-2004  drochner remove the (superfluous) definition of "cpu" as an interface attribute
 1.13 30-Aug-2004  drochner Phase out the use of a string as first "attach args" member to control
which bustype should be attached with a specific call to config_found()
(from a "mainbus" or a bus bridge).
Do it for isa/eisa/mca and pci/agp for now. These buses all attach to
an mi interface attribute "isabus", "eisabus" etc., and the autoconf
framework now allows to specify an interface attribute on config_found()
and config_search(), which limits the search of matching config data
to these which attach to that specific attribute.
So we basically have to call config_found_ia(..., "foobus", ...) where
such a bus is attached.
As a consequence, where a "mainbus" or alike also attaches other
devices (eg CPUs) which do not attach to a specific attribute yet,
we need at least pass an attribute name (different from "foobus") so
that the foo bus is not found at these places. This made some minor
changes necessary which are not obviously related to the mentioned buses.
 1.12 18-Apr-2004  fvdl Adapt for new aapic.c location.
 1.11 26-Mar-2004  drochner the whole sigcode business is COMPAT_16 only
 1.10 25-Mar-2004  drochner remove sigcontext-style signal delivery code
 1.9 13-Mar-2004  bjh21 Abstract the interface between pckbc(4), and the pckbd(4) and pms(4)
drivers that attach to it. This allows for other host interface chips
that use the same keyboards and mice, such as the ones in the ARM
IOMD20, ARM7500, and SA-1111. The PC-compatible driver is still
called pckbc(4), and the new abstraction layer is "pckbport", so the
child devices have moved from sys/dev/pckbc to sys/dev/pckbport, which
also contains some code shared between all host controllers. To avoid
incompatibility, pckbdreg.h is still installed in
/usr/include/dev/pckbc.

In theory, this shouldn't cause any behavioural changes in the drivers
concerned. Thy just use rather more function pointers than before. Tested
on i386 and (with a new host driver) acorn32. Compiled on several other
affected architectures.
 1.8 20-Jan-2004  jdolecek cleanup old lpt(4) attachment, and glue ppbus in so that they can coexist:
* lpt device is defined in MI place (dev/ppbus/files.ppbus), dev/ic/lpt.c
is included there too; dev/ic/lpt.c is not included if ppbus is
configured or if there is alternative platform lpt (like for pc532)
* g/c MD lpt definitions and custom puc/upc attachments,
glue moved to conf/files and dev/pci/files.pci respectively; remove
device lpt definition from dev/isa/files.isa
* add ppbus parport attribute, atppc device attachments, adjust plip and lpt
glue
 1.7 06-Oct-2003  fvdl SIGINFO support.
Todo: 32bit compat support (COMPAT_NETBSD32 will not compile right now,
as it won't on other platforms).
 1.6 06-Sep-2003  fvdl Move the bulk of pci_intr_string into a seperate intr_string function. Use
that new function to print the pciide compat interrupt in pciide_machdep.c.
Share pciide_machdep.c between amd64 and i386.
 1.5 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.4 27-Jul-2003  thorpej Since everyone uses clock_subr.c (or should, if they don't currently),
list it in conf/files instead of in every port's files.*.
 1.3 11-May-2003  fvdl branches: 1.3.2;
ACPI support. Wakeup code still to be done.
 1.2 03-May-2003  fvdl Add dummy eisa option to ease sharing with i386.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.3.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.3.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.3.2.2 03-Sep-2004  skrll Sync with HEAD
 1.3.2.1 03-Aug-2004  skrll Sync with HEAD
 1.16.2.10 17-Mar-2008  yamt sync with head.
 1.16.2.9 27-Feb-2008  yamt sync with head.
 1.16.2.8 04-Feb-2008  yamt sync with head.
 1.16.2.7 21-Jan-2008  yamt sync with head
 1.16.2.6 07-Dec-2007  yamt sync with head
 1.16.2.5 27-Oct-2007  yamt sync with head.
 1.16.2.4 03-Sep-2007  yamt sync with head.
 1.16.2.3 26-Feb-2007  yamt sync with head.
 1.16.2.2 30-Dec-2006  yamt sync with head.
 1.16.2.1 21-Jun-2006  yamt sync with head.
 1.19.6.2 30-Apr-2006  kardel include tsc.c into kernel build
 1.19.6.1 22-Apr-2006  simonb Sync with head.
 1.19.4.1 09-Sep-2006  rpaulo sync with head
 1.19.2.1 18-Feb-2006  yamt sync with head.
 1.21.6.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.21.4.1 19-Apr-2006  elad sync with head - hopefully this will work
 1.21.2.4 14-Sep-2006  yamt sync with head.
 1.21.2.3 11-Aug-2006  yamt sync with head
 1.21.2.2 26-Jun-2006  yamt sync with head.
 1.21.2.1 11-Apr-2006  yamt sync with head
 1.22.2.1 19-Jun-2006  chap Sync with head.
 1.23.2.1 13-Jul-2006  gdamore Merge from HEAD.
 1.28.2.3 12-Jan-2007  ad Sync with head.
 1.28.2.2 18-Nov-2006  ad Sync with head.
 1.28.2.1 10-Sep-2006  ad Add updated locking primatives.
 1.29.6.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.29.4.1 19-Dec-2007  ghen Pull up following revision(s) (requested by briggs in ticket #989):
sys/arch/amd64/conf/GENERIC: revision 1.151
sys/arch/x86/x86/ipmi.c: revision 1.12
sys/dev/DEVNAMES: revision 1.228
sys/arch/amd64/amd64/bios32.c: revision 1.6
sys/arch/x86/x86/ipmi.c: revision 1.8
sys/arch/amd64/conf/files.amd64: revision 1.39 via patch
sys/arch/amd64/amd64/mainbus.c: revision 1.17
Use PRIx64 for a 64-bit quantity instead of llx in a debug print.
Add (commented-out) support for IPMI on amd64--pretty much copied straight
from i386.
Check for duplicate sensor names in the IPMI table. If a duplicate name
is found, try to make it unique by appending a count (1-99) to the sensor
description (truncating, if necessary).
 1.29.2.1 21-Dec-2006  yamt sync with head.
 1.31.2.4 07-May-2007  yamt sync with head.
 1.31.2.3 15-Apr-2007  yamt sync with head.
 1.31.2.2 12-Mar-2007  rmind Sync with HEAD.
 1.31.2.1 03-Mar-2007  yamt adapt amd64.

XXX changes in identcpu.c is minmum for MONITOR.
XXX identcpu.c should be shared with i386.
 1.33.4.1 11-Jul-2007  mjf Sync with head.
 1.33.2.9 03-Dec-2007  ad Sync with HEAD.
 1.33.2.8 03-Dec-2007  ad Sync with HEAD.
 1.33.2.7 23-Oct-2007  ad Sync with head.
 1.33.2.6 09-Oct-2007  ad Sync with head.
 1.33.2.5 23-Aug-2007  ad Merged x86 cpu.c.
 1.33.2.4 20-Aug-2007  ad Sync with HEAD.
 1.33.2.3 15-Jul-2007  ad Sync with head.
 1.33.2.2 27-May-2007  ad Sync with head.
 1.33.2.1 10-Apr-2007  ad Sync with head.
 1.37.2.2 03-Oct-2007  garbled Sync with HEAD
 1.37.2.1 22-May-2007  matt Update to HEAD.
 1.40.8.8 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.40.8.7 28-Oct-2007  joerg Sync with HEAD.
 1.40.8.6 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.40.8.5 02-Oct-2007  joerg Sync with HEAD.
 1.40.8.4 10-Sep-2007  joerg Add work-in-progress remerge of i386 changes for the ACPI wakecode
and changes to adopt it to AMD64.
 1.40.8.3 04-Sep-2007  joerg Move common PCI devices on i386 and amd64 into a arch/x86/pci/fils.pci.
 1.40.8.2 03-Sep-2007  jmcneill Sync with HEAD.
 1.40.8.1 09-Aug-2007  jmcneill Sync with HEAD.
 1.40.4.2 03-Sep-2007  skrll Sync with HEAD.
 1.40.4.1 15-Aug-2007  skrll Sync with HEAD.
 1.40.2.1 07-Aug-2007  matt Sync with HEAD.
 1.42.2.3 23-Mar-2008  matt sync with HEAD
 1.42.2.2 09-Jan-2008  matt sync with HEAD
 1.42.2.1 06-Nov-2007  matt sync with HEAD
 1.43.2.3 06-Oct-2007  yamt sync with head.
 1.43.2.2 04-Oct-2007  yamt remove LARGEPAGES option. always use large pages if available.
 1.43.2.1 30-Sep-2007  yamt implement deferred pmap switching for amd64, and make amd64 use
x86 shared pmap code. it makes several i386 pmap improvements available
to amd64, including tlb shootdown reduction and bug fixes from Stephan Uphoff.
 1.44.2.3 19-Nov-2007  bouyer Get rid of arch/xenamd64, step 1: empty xenamd64/conf
- move xenamd64/conf/std.xen to amd64/conf/
- define arch to amd64 amd64/conf/std.xen, and i386 in xen/conf/std.xen
(machine is xen)
- enclose content of amd64/conf/files.amd64 and i386/conf/files.i386 in
ifndef xen/endif, so it can be transparently inclued for xen kernels
- support MACHINE_ARCH=x86_64 in xen/conf/Makefile*
 1.44.2.2 13-Nov-2007  bouyer Sync with HEAD
 1.44.2.1 25-Oct-2007  bouyer Sync with HEAD.
 1.48.2.3 18-Feb-2008  mjf Sync with HEAD.
 1.48.2.2 27-Dec-2007  mjf Sync with HEAD.
 1.48.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.49.4.1 11-Dec-2007  yamt sync with head.
 1.49.2.1 26-Dec-2007  ad Sync with head.
 1.50.2.4 19-Jan-2008  bouyer Sync with HEAD
 1.50.2.3 10-Jan-2008  bouyer Sync with HEAD
 1.50.2.2 08-Jan-2008  bouyer Sync with HEAD
 1.50.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.58.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.58.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.58.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.58.2.1 24-Mar-2008  keiichi sync with head.
 1.59.6.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.59.4.4 11-Aug-2010  yamt sync with head.
 1.59.4.3 20-Jun-2009  yamt sync with head
 1.59.4.2 04-May-2009  yamt sync with head.
 1.59.4.1 16-May-2008  yamt sync with head.
 1.59.2.1 18-May-2008  yamt sync with head.
 1.60.12.1 21-Apr-2010  matt sync to netbsd-5
 1.60.8.2 07-Oct-2009  sborrill Pull up the following revisions(s) (requested by jmcneill in ticket #1044):
distrib/sets/lists/man/mi: patch
share/man/man4/Makefile: patch
sys/arch/amd64/conf/files.amd64: 1.67
sys/arch/i386/conf/files.i386: 1.349
sys/conf/files 1.945
share/man/man4/sdmmc.4: 1.1-1.4
sys/dev/sdmmc/Makefile.sdmmcdevs 1.1
sys/dev/sdmmc/devlist2h.awk 1.1
sys/dev/sdmmc/files.sdmmc 1.1-1.2
sys/dev/sdmmc/ld_sdmmc.c 1.1-1.3
sys/dev/sdmmc/sbt.c 1.1-1.2
sys/dev/sdmmc/sdhc.c 1.1-1.3
sys/dev/sdmmc/sdhcreg.h 1.1
sys/dev/sdmmc/sdhcvar.h 1.1
sys/dev/sdmmc/sdmmc.c 1.1
sys/dev/sdmmc/sdmmc_cis.c 1.1
sys/dev/sdmmc/sdmmc_io.c 1.1
sys/dev/sdmmc/sdmmc_ioreg.h 1.1
sys/dev/sdmmc/sdmmc_mem.c 1.1-1.2
sys/dev/sdmmc/sdmmcchip.h 1.1
sys/dev/sdmmc/sdmmcdevs 1.1
sys/dev/sdmmc/sdmmcdevs.h 1.1-1.2
sys/dev/sdmmc/sdmmcreg.h 1.1-1.3
sys/dev/sdmmc/sdmmcvar.h 1.1

Add sdmmc framework
 1.60.8.1 19-Jun-2009  snj Pull up following revision(s) (requested by bouyer in ticket #816):
sys/arch/amd64/conf/files.amd64: revision 1.68
sys/arch/i386/conf/files.i386: revision 1.350
sys/arch/x86/include/rtc.h: revision 1.1
sys/arch/x86/isa/clock.c: revision 1.33
sys/arch/x86/isa/rtc.c: revision 1.1
sys/arch/xen/conf/files.xen: revision 1.100
sys/arch/xen/xen/clock.c: revision 1.50 via patch
Split mc146818-related functions from clock.c into rtc.c.
Call rtc_set_ymdhms() from xen/xen/clock.c:xen_rtc_set() for xen3 dom0
kernels as the Xen3 hypervisor doesn't write the new date/time to the CMOS
by itself.
Now a XEN3_DOM0 kernel properly updates the CMOS time.
 1.60.6.3 28-Apr-2009  skrll Sync with HEAD.
 1.60.6.2 03-Mar-2009  skrll Sync with HEAD.
 1.60.6.1 19-Jan-2009  skrll Sync with HEAD.
 1.60.4.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.61.4.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.61.4.5 02-May-2011  jym Sync with head.
 1.61.4.4 29-Mar-2011  jym More sync fixes. And add the mbr_gpt files.
 1.61.4.3 01-Nov-2009  jym Sync with HEAD.
 1.61.4.2 23-Jul-2009  jym Sync with HEAD.
 1.61.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.68.4.3 21-Apr-2011  rmind sync with head
 1.68.4.2 05-Mar-2011  rmind sync with head
 1.68.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.68.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.69.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.72.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.73.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.73.2.3 30-Oct-2012  yamt sync with head
 1.73.2.2 23-May-2012  yamt sync with head.
 1.73.2.1 10-Nov-2011  yamt sync with head
 1.74.4.1 02-Jun-2012  mrg sync to latest -current.
 1.76.2.3 03-Dec-2017  jdolecek update from HEAD
 1.76.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.76.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.79.8.1 23-Jul-2013  riastradh sync with HEAD
 1.79.2.2 18-May-2014  rmind sync with head
 1.79.2.1 28-Aug-2013  rmind sync with head
 1.84.2.4 28-Aug-2017  skrll Sync with HEAD
 1.84.2.3 05-Feb-2017  skrll Sync with HEAD
 1.84.2.2 22-Sep-2015  skrll Sync with HEAD
 1.84.2.1 06-Apr-2015  skrll Sync with HEAD
 1.87.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.88.8.5 09-Mar-2019  martin Pull up following revision(s) via patch (requested by nonaka in ticket #1210):

sys/dev/hyperv/vmbusvar.h: revision 1.1
sys/dev/hyperv/hvs.c: revision 1.1
sys/dev/hyperv/if_hvn.c: revision 1.1
sys/dev/hyperv/vmbusic.c: revision 1.1
sys/arch/x86/x86/lapic.c: revision 1.69
sys/arch/x86/isa/clock.c: revision 1.34
sys/arch/x86/include/intrdefs.h: revision 1.22
sys/arch/i386/conf/GENERIC: revision 1.1201
sys/arch/x86/x86/hyperv.c: revision 1.1
sys/arch/x86/include/cpu.h: revision 1.105
sys/arch/x86/x86/x86_machdep.c: revision 1.124
sys/arch/i386/conf/GENERIC: revision 1.1203
sys/arch/amd64/amd64/genassym.cf: revision 1.74
sys/arch/i386/conf/GENERIC: revision 1.1204
sys/arch/amd64/conf/GENERIC: revision 1.520
sys/arch/x86/x86/hypervreg.h: revision 1.1
sys/arch/amd64/amd64/vector.S: revision 1.69
sys/dev/hyperv/hvshutdown.c: revision 1.1
sys/dev/hyperv/hvshutdown.c: revision 1.2
sys/dev/usb/if_urndisreg.h: file removal
sys/arch/x86/x86/cpu.c: revision 1.167
sys/arch/x86/conf/files.x86: revision 1.107
sys/dev/usb/if_urndis.c: revision 1.20
sys/dev/hyperv/vmbusicreg.h: revision 1.1
sys/dev/hyperv/hvheartbeat.c: revision 1.1
sys/dev/hyperv/vmbusicreg.h: revision 1.2
sys/dev/hyperv/hvheartbeat.c: revision 1.2
sys/dev/hyperv/files.hyperv: revision 1.1
sys/dev/ic/rndisreg.h: revision 1.1
sys/arch/i386/i386/genassym.cf: revision 1.111
sys/dev/ic/rndisreg.h: revision 1.2
sys/dev/hyperv/hyperv_common.c: revision 1.1
sys/dev/hyperv/hvtimesync.c: revision 1.1
sys/dev/hyperv/hypervreg.h: revision 1.1
sys/dev/hyperv/hvtimesync.c: revision 1.2
sys/dev/hyperv/vmbusicvar.h: revision 1.1
sys/dev/hyperv/if_hvnreg.h: revision 1.1
sys/arch/x86/x86/lapic.c: revision 1.70
sys/arch/amd64/amd64/vector.S: revision 1.70
sys/dev/ic/ndisreg.h: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.516
sys/dev/hyperv/hypervvar.h: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.518
sys/arch/amd64/conf/GENERIC: revision 1.519
sys/arch/i386/conf/files.i386: revision 1.400
sys/dev/acpi/vmbus_acpi.c: revision 1.1
sys/dev/hyperv/vmbus.c: revision 1.1
sys/dev/hyperv/vmbus.c: revision 1.2
sys/arch/x86/x86/intr.c: revision 1.144
sys/arch/i386/i386/vector.S: revision 1.83
sys/arch/amd64/conf/files.amd64: revision 1.112

separate RNDIS definitions from urndis(4) for use with Hyper-V NetVSC.

-

Added Microsoft Hyper-V support. It ported from OpenBSD and FreeBSD.
graphical console is not work on Gen.2 VM yet. To use the serial console,
enter "consdev com,0x3f8,115200" on efiboot.

-

Add __diagused.

-

PR/53984: Partial revert of modify lapic_calibrate_timer() in lapic.c r1.69.

-

Update Hyper-V related drivers description.

-

Remove unused definition.

-

Rename the MODULE_*_HOOK() macros to MODULE_HOOK_*() as briefly
discussed on irc.
NFCI intended.

-

commented out hvkvp entry.

-

fix typo. pointed out by pgoyette@n.o.

-

Use IDTVEC instead of NENTRY for handle_hyperv_hypercall.

-

Rename the MODULE_*_HOOK() macros to MODULE_HOOK_*() as briefly
discussed on irc.
 1.88.8.4 09-Jun-2018  martin Pullup the following revisions, requested by maxv in ticket #865:

sys/arch/amd64/amd64/machdep.c 1.303 (patch)
sys/arch/amd64/conf/GENERIC 1.492 (patch)
sys/arch/amd64/conf/files.amd64 1.103 (patch)
sys/arch/i386/i386/machdep.c 1.806 (patch)
sys/arch/i386/conf/GENERIC 1.1179 (patch)
sys/arch/i386/conf/files.i386 1.393 (patch)
sys/arch/x86/include/cpu.h 1.91 (patch)
sys/arch/x86/include/specialreg.h upto 1.126 (patch)
sys/arch/x86/x86/x86_machdep.c upto 1.115 (patch, adapted)
sys/arch/x86/x86/spectre.c upto 1.19 (patch, adapted,
no IBRS,
SpectreV2 mitigations not
enabled by default)

Backport the hardware SpectreV2 and SpectreV4 mitigations.
 1.88.8.3 11-Apr-2018  martin Pull up following revision(s) (requested by mrg in ticket #731):
sys/arch/i386/conf/files.i386: revision 1.392
sys/arch/i386/conf/GENERIC: revision 1.1175
sys/arch/i386/conf/GENERIC: revision 1.1176
sys/arch/amd64/conf/files.amd64: revision 1.102
sys/arch/i386/conf/GENERIC: revision 1.1177
share/man/man4/options.4: revision 1.485 (patch)
sys/arch/i386/conf/Makefile.i386: revision 1.190
sys/arch/amd64/conf/GENERIC: revision 1.487
sys/arch/amd64/conf/ALL: revision 1.85
sys/arch/amd64/conf/GENERIC: revision 1.488
sys/arch/amd64/conf/GENERIC: revision 1.489
sys/arch/amd64/conf/Makefile.amd64: revision 1.67
sys/arch/i386/conf/ALL: revision 1.437

add an SPECTRE_V2_GCC_MITIGATION option to x86 kernels, that turns
on the GCC spectre v2 mitigation options.
XXX: pullup-8.
XXX: turn on in all kernels.

actually do what the previous change said:
don't turn on the new 'SPECTRE_V2_GCC_MITIGATION' option yet.

turn on GCC spectre v2 mitigation options.
XXX: amd64 ALL doesn't build for me right now
 1.88.8.2 07-Mar-2018  martin Pull up the following revisions (via patch), requested by maxv in ticket #610:

sys/arch/amd64/amd64/amd64_trap.S 1.8,1.10,1.12 (partial),1.13-1.15,
1.19 (partial),1.20,1.21,1.22,1.24
(via patch)
sys/arch/amd64/amd64/locore.S 1.129 (partial),1.132 (via patch)
sys/arch/amd64/amd64/trap.c 1.97 (partial),1.111 (via patch)
sys/arch/amd64/amd64/vector.S 1.54,1.55 (via patch)
sys/arch/amd64/include/frameasm.h 1.21,1.23 (via patch)
sys/arch/x86/x86/cpu.c 1.138 (via patch)
sys/arch/xen/conf/Makefile.xen 1.45 (via patch)

Rename and reorder several things in amd64_trap.S.
Compile amd64_trap.S as a file.
Introduce nmitrap and doubletrap.
Have the CPU clear PSL_D automatically in the syscall entry point.
 1.88.8.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.101.2.7 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.101.2.6 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.101.2.5 14-Sep-2018  pgoyette OMG it builds!

Finish rearranging the amd64 MD compat_netbsd32 code.

XXX Other architectures will be dealt with later.
 1.101.2.4 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.101.2.3 28-Jul-2018  pgoyette Sync with HEAD
 1.101.2.2 25-Jun-2018  pgoyette Sync with HEAD
 1.101.2.1 16-Apr-2018  pgoyette Sync with HEAD, resolve some conflicts
 1.104.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.104.2.1 10-Jun-2019  christos Sync with HEAD
 1.112.4.1 13-May-2023  martin Pull up following revision(s) (requested by manu in ticket #1632):

share/man/man8/man8.x86/boot.8: revision 1.27
sys/arch/i386/stand/efiboot/version: revision 1.3
share/man/man8/man8.x86/boot.8: revision 1.28 (via patch)
share/man/man8/man8.x86/boot.8: revision 1.29 (via patch)
sys/arch/i386/stand/lib/exec.c: revision 1.79
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.13
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.6
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.6
sys/arch/i386/stand/efiboot/boot.c: revision 1.22
sys/arch/amd64/amd64/locore.S: revision 1.219
sys/arch/i386/stand/efiboot/bootia32/startprog32.S: revision 1.3
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.12
sys/arch/amd64/conf/files.amd64: revision 1.121
sys/arch/amd64/conf/std.amd64: revision 1.13
share/man/man8/man8.x86/pxeboot.8: revision 1.6
sys/arch/i386/stand/efiboot/bootx64/startprog64.S: revision 1.4
sys/arch/amd64/amd64/locore.S: revision 1.220
share/man/man8/man8.x86/dosboot.8: revision 1.4
share/man/man4/options.4: revision 1.524

Add reloc keyworkd to let EFI bootstrap load amd64 kernel at any address

EFI bootstrap assumes it can copy the amd64 kernel to its ELF load
address (that is KERNTEXTOFF - KERNBASE = 0x200000), but it can
clash with previous UEFI memory allocation, as described here:
http://mail-index.netbsd.org/tech-kern/2023/04/07/msg028833.html

This change adds a reloc keyword for controling where the EFI
boostrap will copy the kernel image. Possible values are:
default - the default and prior behavior, copy at 0x200000.
none - do not copy and use the kernel image where it was loaded.
address - specify an explicit address where to copy the kernel.

This comes with an amd64 kernel patch that makes it self-relocatable.
It first discover where it was loaded in memory, and if this is
different than the expected 0x200000, hhe the kernel relocates
itself and start over at the right address.

Merge x86 boot options in x86/boot(8) and add undocumented UEFI options

We were supposed to keep the option list in x86/boot(8), x86/dosoot(8)
and x86/pxeboot(8) in sync, but it did not happen, hence it may work
better with all the options in x86/boot(8). Also add the undocumented
UEFI boot options.

Add a SELFRELOC kernel option for the sake of documentation clarity.
Instead of telling that x86/boot(8) reloc command needs a kernel able
to self relocate, we can tell it needs a kernel built with the
SELFRELOC option. This keeps the reader from wondering what could
make a kernel able to self relocate.

Remove XXX todo marker left by mistake

Raise the version for new feature (here reloc command)
Suggested by Masanobu SAITOH
 1.114.2.1 17-Jan-2020  ad Sync with head.
 1.115.4.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.
 1.120.20.1 13-May-2023  martin Pull up following revision(s) (requested by manu in ticket #159):

share/man/man8/man8.x86/boot.8: revision 1.27
sys/arch/i386/stand/efiboot/version: revision 1.3
share/man/man8/man8.x86/boot.8: revision 1.28
share/man/man8/man8.x86/boot.8: revision 1.29
sys/arch/i386/stand/lib/exec.c: revision 1.79
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.13
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.6
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.6
sys/arch/i386/stand/efiboot/boot.c: revision 1.22
sys/arch/amd64/amd64/locore.S: revision 1.219
sys/arch/i386/stand/efiboot/bootia32/startprog32.S: revision 1.3
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.12
sys/arch/amd64/conf/files.amd64: revision 1.121
sys/arch/amd64/conf/std.amd64: revision 1.13
share/man/man8/man8.x86/pxeboot.8: revision 1.6
sys/arch/i386/stand/efiboot/bootx64/startprog64.S: revision 1.4
sys/arch/amd64/amd64/locore.S: revision 1.220
share/man/man8/man8.x86/dosboot.8: revision 1.4
share/man/man4/options.4: revision 1.524

Add reloc keyworkd to let EFI bootstrap load amd64 kernel at any address

EFI bootstrap assumes it can copy the amd64 kernel to its ELF load
address (that is KERNTEXTOFF - KERNBASE = 0x200000), but it can
clash with previous UEFI memory allocation, as described here:
http://mail-index.netbsd.org/tech-kern/2023/04/07/msg028833.html

This change adds a reloc keyword for controling where the EFI
boostrap will copy the kernel image. Possible values are:
default - the default and prior behavior, copy at 0x200000.
none - do not copy and use the kernel image where it was loaded.
address - specify an explicit address where to copy the kernel.

This comes with an amd64 kernel patch that makes it self-relocatable.
It first discover where it was loaded in memory, and if this is
different than the expected 0x200000, hhe the kernel relocates
itself and start over at the right address.


Merge x86 boot options in x86/boot(8) and add undocumented UEFI options

We were supposed to keep the option list in x86/boot(8), x86/dosoot(8)
and x86/pxeboot(8) in sync, but it did not happen, hence it may work
better with all the options in x86/boot(8). Also add the undocumented
UEFI boot options.


Add a SELFRELOC kernel option for the sake of documentation clarity.
Instead of telling that x86/boot(8) reloc command needs a kernel able
to self relocate, we can tell it needs a kernel built with the
SELFRELOC option. This keeps the reader from wondering what could
make a kernel able to self relocate.

Remove XXX todo marker left by mistake

Raise the version for new feature (here reloc command)
Suggested by Masanobu SAITOH
 1.123.2.1 02-Aug-2025  perseant Sync with HEAD
 1.31 09-Jan-2020  manu Rollback multiboot2 for amd64, as requested by core
 1.30 15-Dec-2019  manu branches: 1.30.2;
Restore multiboot 2 header in amd64 kernel

The header must appear below 32k offset in the kernel file, but we
have to make sure it does not load at low addresses, otherwise we
break BIOS boot.

.text section used to load at 0x200000, we just load multiboot section
there, and have .text loaded just after.
 1.29 11-Dec-2019  manu Rollback kernel link scrpt change for multiboot

The multiboot section breaks BIOS boot. Rolling back the link script
removes the section, which breaks multiboot but should restore BIOS boot.
 1.28 10-Dec-2019  manu Add multiboot 2 support to amd64 kernel
 1.27 20-Aug-2018  maxv Add support for kASan on amd64. Written by me, with some parts inspired
from Siddharth Muralee's initial work. This feature can detect several
kinds of memory bugs, and it's an excellent feature.

It can be enabled by uncommenting these three lines in GENERIC:

#makeoptions KASAN=1 # Kernel Address Sanitizer
#options KASAN
#no options SVS

The kernel is compiled without SVS, without DMAP and without PCPU area.
A shadow area is created at boot time, and it can cover the upper 128TB
of the address space. This area is populated gradually as we allocate
memory. With this design the memory consumption is kept at its lowest
level.

The compiler calls the __asan_* functions each time a memory access is
done. We verify whether this access is legal by looking at the shadow
area.

We declare our own special memcpy/memset/etc functions, because the
compiler's builtins don't add the __asan_* instrumentation.

Initially all the mappings are marked as valid. During dynamic
allocations, we add a redzone, which we mark as invalid. Any access on
it will trigger a kASan error message. Additionally, the compiler adds
a redzone on global variables, and we mark these redzones as invalid too.
The illegal-access detection works with a 1-byte granularity.

For now, we cover three areas:

- global variables
- kmem_alloc-ated areas
- malloc-ated areas

More will come, but that's a good start.
 1.26 21-Jan-2018  maxv branches: 1.26.2; 1.26.4;
Unmap the kernel from userland in SVS, and leave only the needed
trampolines. As explained below, SVS should now completely mitigate
Meltdown on GENERIC kernels, even though it needs some more tweaking
for GENERIC_KASLR.

Until now the kernel entry points looked like:

FUNC(intr)
pushq $ERR
pushq $TRAPNO
INTRENTRY
... handle interrupt ...
INTRFASTEXIT
END(intr)

With this change they are split and become:

FUNC(handle)
... handle interrupt ...
INTRFASTEXIT
END(handle)

TEXT_USER_BEGIN
FUNC(intr)
pushq $ERR
pushq $TRAPNO
INTRENTRY
jmp handle
END(intr)
TEXT_USER_END

A new section is introduced, .text.user, that contains minimal kernel
entry/exit points. In order to choose what to put in this section, two
macros are introduced, TEXT_USER_BEGIN and TEXT_USER_END.

The section is mapped in userland with normal 4K pages.

In GENERIC, the section is 4K-page-aligned and embedded in .text, which
is mapped with large pages. That is to say, when an interrupt comes in,
the CPU has the user page tables loaded and executes the 'intr' functions
on 4K pages; after calling SVS_ENTER (in INTRENTRY) these 4K pages become
2MB large pages, and remain so when executing in kernel mode.

In GENERIC_KASLR, the section is 4K-page-aligned and independent from the
other kernel texts. The prekern just picks it up and maps it at a random
address.

In GENERIC, SVS should now completely mitigate Meltdown: what we put in
.text.user is not secret.

In GENERIC_KASLR, SVS would have to be improved a bit more: the
'jmp handle' instruction is actually secret, since it leaks the address
of the section we are jumping into. By exploiting Meltdown on Intel, this
theoretically allows a local user to reconstruct the address of the first
text section. But given that our KASLR produces several texts, and that
each section is not correlated with the others, the level of protection
KASLR provides is still good.
 1.25 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.24 18-Aug-2017  maxv Fill the .text padding with 0xcc (int3), in such a way that any jump into
this area will automatically fault. The alignment within the section is
necessary, in order to fill strictly all of the padding (took me a while
to figure this out); but it does not change the kernel size.

Greatly inspired from FreeBSD, but for some reason they decided not to
apply the alignment.
 1.23 14-Jun-2017  maxv Fix a pretty dumb mistake I made in r1.22: the alignment needs to be in the
bss, otherwise the bootloader will use memory before __kernel_end and give
a wrong start pa to the kernel.

This issue was investigated by Anthony Mallet. Should fix PR/52000.
 1.22 11-Feb-2017  maxv branches: 1.22.6;
Put 2MB alignments between the kernel segments. This way the kernel image
is entirely mapped with large pages, which uniformizes performance and
reduces fluctuation. Sent on port-amd64.
 1.21 12-May-2016  maxv branches: 1.21.2; 1.21.4;
Map the data+bss chunk independently on amd64, and remove the X
permission on it.
 1.20 12-May-2016  maxv Map the rodata segment independently on amd64, and remove the W permission
on it.
 1.19 12-May-2016  maxv Split the {text+rodata} chunk in two separate chunks on x86. The
rodata segment now loses the large page optimization, gets mapped inside
the data segment, and therefore becomes RWX. It may break the build on
Xen.
 1.18 08-May-2016  maxv Define __rodata_start. Will be used soon.
 1.17 07-May-2016  maxv Large pages are supported by default for the text+rodata segments. Apply
the proper alignment for the data segment, so that more pages can benefit
from it. Reduces TLB contention.

kern.ldscript.2MB and largepages.inc are useless.
 1.16 14-Nov-2015  maxv KNF, and fix some comments
 1.15 25-Aug-2015  uebayasi Fix previous; do include assym.h.
 1.14 25-Aug-2015  uebayasi Replace COHERENCY_UNIT in ldscript.
 1.13 22-Aug-2015  uebayasi Don't need to specify OUTPUT_FORMAT/OUTPUT_ARCH in linker scripts.
 1.12 20-Aug-2015  uebayasi Do =0 (zero-fill) only once.
 1.11 20-Aug-2015  uebayasi Simplify this by splitting absolute relocation directives from other
relative, position-independent directives. Since all sections are
relocated in parallel, specifying the address of .text is sufficient.
 1.10 20-Aug-2015  uebayasi Indent.
 1.9 20-Aug-2015  uebayasi Kill trailing whitespaces.
 1.8 02-Nov-2014  uebayasi branches: 1.8.2;
Revert previous per joerg@'s request.

According to him, exposing .data.{read_mostly,cacheline_aligned} is
intentional so that people can easily see which variables are optimized.
 1.7 01-Nov-2014  uebayasi amd64, i386: Don't expose .data.{read_mostly,cacheline_aligned} sections
 1.6 07-May-2014  jakllsch Set the kernel load (physical) address as is already done for i386 kernels.
 1.5 01-Jun-2010  mjf branches: 1.5.8; 1.5.18; 1.5.22; 1.5.32;
Add __cacheline_aligned and __read_mostly annotations.

These annotations help to mitigate false sharing on multiprocessor
systems.

Variables annotated with __cacheline_aligned are placed into the
.data.cacheline_aligned section in the kernel. Each item in this
section is aligned on a cachline boundary - this avoids false
sharing. Highly contended global locks are a good candidate for
__cacheline_aligned annotation.

Variables annotated with __read_mostly are packed together tightly
into a .data.read_mostly section in the kernel. The idea here is that
we can pack infrequently modified data items into a cacheline and
avoid having to purge the cache, which would happen if read mostly
data and write mostly data shared a cachline. Initialisation variables
are a prime candiate for __read_mostly annotations.
 1.4 18-Oct-2007  yamt branches: 1.4.20; 1.4.34; 1.4.40; 1.4.42;
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.3 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.2 12-May-2007  christos branches: 1.2.8; 1.2.10; 1.2.12; 1.2.14;
convert to a very simple kern.ldscript
 1.1 26-Apr-2003  fvdl branches: 1.1.18; 1.1.54; 1.1.56; 1.1.60; 1.1.62; 1.1.68; 1.1.70;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.70.1 17-Nov-2007  skrll Keep .note sections.
 1.1.68.1 22-May-2007  matt Update to HEAD.
 1.1.62.1 11-Jul-2007  mjf Sync with head.
 1.1.60.2 23-Oct-2007  ad Sync with head.
 1.1.60.1 27-May-2007  ad Sync with head.
 1.1.56.1 17-May-2007  yamt sync with head.
 1.1.54.1 16-Sep-2008  bouyer Sync with the following revisions (requested by skrll in ticket #1196):
gnu/dist/gdb removed
gnu/usr.bin/gdb53 removed
distrib/cats/instkernel/Makefile 1.14.6.1
gnu/dist/gdb6/bfd/config.bfd 1.3.6.1
gnu/dist/gdb6/bfd/elfxx-sparc.c 1.1.1.2.6.1
gnu/dist/gdb6/bfd/elfxx-sparc.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/Makefile.in 1.2.2.1.2.2
gnu/dist/gdb6/gdb/alpha-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/alpha-tdep.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/alphabsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/alphabsd-nat.h 1.1.2.1
gnu/dist/gdb6/gdb/alphabsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/alphabsd-tdep.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/alphanbsd-nat.c 1.1.2.1
gnu/dist/gdb6/gdb/alphanbsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/amd64-nat.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/amd64bsd-nat.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/amd64nbsd-nat.c 1.1.1.2.6.3
gnu/dist/gdb6/gdb/amd64nbsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/arm-tdep.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/armbsd-tdep.c 1.1.2.1
gnu/dist/gdb6/gdb/armnbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/armnbsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/configure 1.1.1.2.6.1
gnu/dist/gdb6/gdb/configure.ac 1.1.1.2.6.1
gnu/dist/gdb6/gdb/i386bsd-nat.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/i386nbsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/m68kbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/mipsnbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/nbsd-thread.c 1.1.2.3
gnu/dist/gdb6/gdb/ppcnbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/ppcnbsd-tdep.c 1.3.6.1
gnu/dist/gdb6/gdb/sh-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/shnbsd-nat.c 1.1.1.2.6.3
gnu/dist/gdb6/gdb/shnbsd-tdep.c 1.1.1.2.6.4
gnu/dist/gdb6/gdb/shnbsd-tdep.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/sparc-nat.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/sparc64nbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/sparcnbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/tramp-frame.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/vaxbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/config/alpha/nbsd.mh 1.1.1.2.6.1
gnu/dist/gdb6/gdb/config/arm/nbsd.mt 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/arm/nbsdelf.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/i386/nbsd64.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/m68k/nbsdelf.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/mips/nbsd.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/powerpc/nbsd.mh 1.1.1.2.6.1
gnu/dist/gdb6/gdb/config/sh/nbsd.mh 1.1.1.1.6.2
gnu/dist/gdb6/gdb/config/sh/tm-nbsd.h 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/sparc/nbsd64.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/sparc/nbsdelf.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/vax/nbsdelf.mh 1.1.1.1.6.1
gnu/dist/gdb6/opcodes/configure 1.1.1.2.6.1
gnu/dist/gdb6/opcodes/configure.in 1.1.1.2.6.1
gnu/usr.bin/Makefile 1.126.4.1
gnu/usr.bin/gdb6/arch/alpha/config.h 1.3.4.1
gnu/usr.bin/gdb6/arch/alpha/defs.mk 1.2.6.1
gnu/usr.bin/gdb6/arch/alpha/init.c 1.2.6.1
gnu/usr.bin/gdb6/arch/alpha/nm.h 1.2.6.1
gnu/usr.bin/gdb6/arch/arm/defs.mk 1.2.6.2
gnu/usr.bin/gdb6/arch/arm/init.c 1.1.6.1
gnu/usr.bin/gdb6/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/arch/armeb/defs.mk 1.1.6.3
gnu/usr.bin/gdb6/arch/armeb/init.c 1.1.6.2
gnu/usr.bin/gdb6/arch/armeb/tm.h 1.1.6.2
gnu/usr.bin/gdb6/arch/armeb/version.c 1.1.6.2
gnu/usr.bin/gdb6/arch/i386/defs.mk 1.4.4.1
gnu/usr.bin/gdb6/arch/i386/init.c 1.3.6.1
gnu/usr.bin/gdb6/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/arch/m68000/init.c 1.1.6.2
gnu/usr.bin/gdb6/arch/m68000/tm.h 1.1.6.2
gnu/usr.bin/gdb6/arch/m68000/version.c 1.1.6.2
gnu/usr.bin/gdb6/arch/m68k/defs.mk 1.1.4.1
gnu/usr.bin/gdb6/arch/m68k/init.c 1.1.4.1
gnu/usr.bin/gdb6/arch/mipseb/config.h 1.3.4.1
gnu/usr.bin/gdb6/arch/mipseb/defs.mk 1.2.6.2
gnu/usr.bin/gdb6/arch/mipseb/init.c 1.2.6.2
gnu/usr.bin/gdb6/arch/mipsel/config.h 1.2.6.3
gnu/usr.bin/gdb6/arch/mipsel/defs.mk 1.2.6.3
gnu/usr.bin/gdb6/arch/mipsel/init.c 1.2.6.3
gnu/usr.bin/gdb6/arch/mipsel/tm.h 1.2.6.2
gnu/usr.bin/gdb6/arch/mipsel/version.c 1.2.6.2
gnu/usr.bin/gdb6/arch/powerpc/defs.mk 1.3.6.1
gnu/usr.bin/gdb6/arch/powerpc/init.c 1.3.6.1
gnu/usr.bin/gdb6/arch/sh3eb/config.h 1.2.2.2
gnu/usr.bin/gdb6/arch/sh3eb/defs.mk 1.2.8.3
gnu/usr.bin/gdb6/arch/sh3eb/init.c 1.1.8.3
gnu/usr.bin/gdb6/arch/sh3eb/nm.h 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3eb/tm.h 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3eb/version.c 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3el/config.h 1.2.2.2
gnu/usr.bin/gdb6/arch/sh3el/defs.mk 1.2.8.3
gnu/usr.bin/gdb6/arch/sh3el/init.c 1.1.8.3
gnu/usr.bin/gdb6/arch/sh3el/nm.h 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3el/tm.h 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3el/version.c 1.1.8.2
gnu/usr.bin/gdb6/arch/sparc/defs.mk 1.2.6.1
gnu/usr.bin/gdb6/arch/sparc/init.c 1.1.6.1
gnu/usr.bin/gdb6/arch/sparc64/defs.mk 1.2.6.1
gnu/usr.bin/gdb6/arch/sparc64/init.c 1.1.6.1
gnu/usr.bin/gdb6/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/arch/vax/init.c 1.1.6.2
gnu/usr.bin/gdb6/arch/vax/tm.h 1.1.6.2
gnu/usr.bin/gdb6/arch/vax/version.c 1.1.6.2
gnu/usr.bin/gdb6/arch/x86_64/defs.mk 1.2.6.1
gnu/usr.bin/gdb6/arch/x86_64/init.c 1.1.6.1
gnu/usr.bin/gdb6/bfd/arch/armeb/bfd.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/armeb/bfdver.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/armeb/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/m68000/bfd.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/m68000/bfdver.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/mipsel/bfd.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/mipsel/bfdver.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/mipsel/config.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/mipsel/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/sh3eb/bfd.h 1.1.8.3
gnu/usr.bin/gdb6/bfd/arch/sh3eb/bfdver.h 1.1.8.2
gnu/usr.bin/gdb6/bfd/arch/sh3eb/config.h 1.1.8.2
gnu/usr.bin/gdb6/bfd/arch/sh3eb/defs.mk 1.1.8.3
gnu/usr.bin/gdb6/bfd/arch/sh3el/bfd.h 1.1.8.3
gnu/usr.bin/gdb6/bfd/arch/sh3el/bfdver.h 1.1.8.2
gnu/usr.bin/gdb6/bfd/arch/sh3el/config.h 1.1.8.2
gnu/usr.bin/gdb6/bfd/arch/sh3el/defs.mk 1.1.8.3
gnu/usr.bin/gdb6/bfd/arch/vax/bfd.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/vax/bfdver.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/gdb/Makefile 1.5.2.1.2.2
gnu/usr.bin/gdb6/gdbtui/Makefile 1.2.6.1
gnu/usr.bin/gdb6/libiberty/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/armeb/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/mipsel/config.h 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/mipsel/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/sh3eb/config.h 1.1.8.2
gnu/usr.bin/gdb6/libiberty/arch/sh3eb/defs.mk 1.1.8.2
gnu/usr.bin/gdb6/libiberty/arch/sh3el/config.h 1.1.8.2
gnu/usr.bin/gdb6/libiberty/arch/sh3el/defs.mk 1.1.8.2
gnu/usr.bin/gdb6/libiberty/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/armeb/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/mipsel/config.h 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/mipsel/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/sh3eb/config.h 1.1.8.2
gnu/usr.bin/gdb6/opcodes/arch/sh3eb/defs.mk 1.1.8.3
gnu/usr.bin/gdb6/opcodes/arch/sh3el/config.h 1.1.8.2
gnu/usr.bin/gdb6/opcodes/arch/sh3el/defs.mk 1.1.8.3
gnu/usr.bin/gdb6/opcodes/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/armeb/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/mipsel/config.h 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/mipsel/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/sh3eb/config.h 1.1.8.2
gnu/usr.bin/gdb6/readline/arch/sh3eb/defs.mk 1.1.8.2
gnu/usr.bin/gdb6/readline/arch/sh3el/config.h 1.1.8.2
gnu/usr.bin/gdb6/readline/arch/sh3el/defs.mk 1.1.8.2
gnu/usr.bin/gdb6/readline/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/sim/arch/mipseb/cconfig.h 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipseb/config.h 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipseb/defs.mk 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipsel/cconfig.h 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipsel/config.h 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipsel/defs.mk 1.1.2.1
lib/libkvm/kvm_sparc64.c 1.10.18.2
lib/libpthread/pthread.c 1.48.6.4
lib/libpthread/pthread_barrier.c 1.6.18.1
lib/libpthread/pthread_cond.c 1.18.12.2
lib/libpthread/pthread_debug.h 1.8.18.1
lib/libpthread/pthread_int.h 1.34.4.5
lib/libpthread/pthread_lock.c 1.14.6.1
lib/libpthread/pthread_mutex.c 1.22.4.2
lib/libpthread/pthread_run.c 1.18.12.4
lib/libpthread/pthread_rwlock.c 1.13.6.2
lib/libpthread/pthread_sa.c 1.37.6.5
lib/libpthread/pthread_sig.c 1.47.4.8
lib/libpthread/pthread_sleep.c 1.7.6.2
lib/libpthread/sem.c 1.9.6.2
lib/libpthread/arch/sh3/pthread_md.h 1.3.6.1
regress/lib/libpthread/resolv/Makefile 1.1.12.1
regress/lib/libpthread/sigrunning/Makefile 1.1.2.1
regress/lib/libpthread/sigrunning/sigrunning.c 1.1.2.1
share/mk/bsd.own.mk 1.489.4.3
sys/arch/amd64/amd64/locore.S 1.18.14.1
sys/arch/amd64/amd64/machdep.c 1.44.2.3.2.1
sys/arch/amd64/conf/kern.ldscript 1.1.70.1
sys/arch/cats/conf/Makefile.cats.inc 1.17.30.1
sys/arch/shark/conf/Makefile.shark.inc 1.6.30.1
sys/arch/sparc64/conf/kern.ldscript 1.7.26.2
sys/arch/sparc64/conf/kern32.ldscript 1.6.26.2
sys/arch/sparc64/include/kcore.h 1.4.92.2
sys/arch/sparc64/sparc64/locore.s 1.232.4.4
sys/arch/sparc64/sparc64/machdep.c 1.193.4.3
sys/arch/sparc64/sparc64/pmap.c 1.184.2.1.2.4
sys/conf/newvers.sh 1.42.26.2
sys/kern/kern_sa.c 1.87.4.11
sys/kern/kern_synch.c 1.173.4.2
sys/sys/savar.h 1.20.10.2
tools/gdb/Makefile 1.9.4.1
tools/gdb/mknative-gdb 1.1.6.1

pullup the wrstuden-fixsa CVS branch to netbsd-4:
toolchain/35540 - GDB 6 support for pthreads.
port-sparc64/37534 - ktrace firefox gives
kernel trap 30: data access expection
GDB changes:
- delete gdb53
- enable gdb6 on all architectures
- add support for amd64 crash dumps
- add support for sparc64 crash dumps
- add support for /proc pid to executable filename for all archs
- enable thread support for all architectures
- add a note section to kernels to all platforms
- support detection/unwinding of signals for most architectures.
- Fix PTHREAD_UCONTEXT_TO_REG / PTHREAD_REG_TO_UCONTEXT on sh3.
- Apply fix from binutils-current so that sparc gdb can be cross built
on a 64bit host.
SA/pthread changes:
Pre-allocate memory needed for event delivery. Eliminates dropped
interrupts under load.
Deliver intra-process signals to running threads
Eliminate some deadlock scenarios
Fix intra-process signal delivery when delivering to a thread waiting
for signals. Makes afs work again!
 1.1.18.2 27-Oct-2007  yamt sync with head.
 1.1.18.1 03-Sep-2007  yamt sync with head.
 1.2.14.1 25-Oct-2007  bouyer Sync with HEAD.
 1.2.12.1 04-Oct-2007  yamt - move etext before rodata. define __data_start at the start of
.data section and use it instead of etext where appropriate.
- put .rodata.* into .rodata section as well.
- pmap_bootstrap: don't assume NBPD_L2 alignment.
- pmap_bootstrap: if DEBUG, print how many large pages and normal pages are
used to map kernel text.
 1.2.10.1 06-Nov-2007  matt sync with HEAD
 1.2.8.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.4.42.1 03-Jul-2010  rmind sync with head
 1.4.40.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.4.34.2 29-Mar-2011  jym More sync fixes. And add the mbr_gpt files.
 1.4.34.1 24-Oct-2010  jym Sync with HEAD
 1.4.20.1 11-Aug-2010  yamt sync with head.
 1.5.32.1 10-Aug-2014  tls Rebase.
 1.5.22.1 18-May-2014  rmind sync with head
 1.5.18.2 03-Dec-2017  jdolecek update from HEAD
 1.5.18.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.5.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.8.2.4 28-Aug-2017  skrll Sync with HEAD
 1.8.2.3 29-May-2016  skrll Sync with HEAD
 1.8.2.2 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.8.2.1 22-Sep-2015  skrll Sync with HEAD
 1.21.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.21.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.22.6.3 22-Mar-2018  martin Pull up the following revisions, requested by maxv in ticket #652:

sys/arch/amd64/amd64/amd64_trap.S upto 1.39 (partial, patch)
sys/arch/amd64/amd64/db_machdep.c 1.6 (patch)
sys/arch/amd64/amd64/genassym.cf 1.65,1.66,1.67 (patch)
sys/arch/amd64/amd64/locore.S upto 1.159 (partial, patch)
sys/arch/amd64/amd64/machdep.c 1.299-1.302 (patch)
sys/arch/amd64/amd64/trap.c upto 1.113 (partial, patch)
sys/arch/amd64/amd64/amd64/vector.S upto 1.61 (partial, patch)
sys/arch/amd64/conf/GENERIC 1.477,1.478 (patch)
sys/arch/amd64/conf/kern.ldscript 1.26 (patch)
sys/arch/amd64/include/frameasm.h upto 1.37 (partial, patch)
sys/arch/amd64/include/param.h 1.25 (patch)
sys/arch/amd64/include/pmap.h 1.41,1.43,1.44 (patch)
sys/arch/x86/conf/files.x86 1.91,1.93 (patch)
sys/arch/x86/include/cpu.h 1.88,1.89 (patch)
sys/arch/x86/include/pmap.h 1.75 (patch)
sys/arch/x86/x86/cpu.c 1.144,1.146,1.148,1.149 (patch)
sys/arch/x86/x86/pmap.c upto 1.289 (partial, patch)
sys/arch/x86/x86/vm_machdep.c 1.31,1.32 (patch)
sys/arch/x86/x86/x86_machdep.c 1.104,1.106,1.108 (patch)
sys/arch/x86/x86/svs.c 1.1-1.14
sys/arch/xen/conf/files.compat 1.30 (patch)

Backport SVS. Not enabled yet.
 1.22.6.2 06-Mar-2018  martin Pull up the following revisions, requested by maxv in ticket #603:

amd64/conf/kern.ldscript 1.25 (patch)
amd64/conf/kern.ldscript.Xen 1.14 (patch)
i386/conf/kern.ldscript 1.21 (patch)
i386/conf/kern.ldscript.Xen 1.15 (patch)
x86/include/cpufunc.h 1.24 (patch)
x86/x86/patch.c 1.25 (partial) 1.26 (partial)

Backport x86_hotpatch.
 1.22.6.1 21-Jun-2017  snj Pull up following revision(s) (requested by maxv in ticket #42):
sys/arch/amd64/conf/kern.ldscript: revision 1.23
sys/arch/x86/x86/x86_machdep.c: revision 1.92
Fix a pretty dumb mistake I made in r1.22: the alignment needs to be in the
bss, otherwise the bootloader will use memory before __kernel_end and give
a wrong start pa to the kernel.
This issue was investigated by Anthony Mallet. Should fix PR/52000.
--
Fix a bug introduced in bus_space.c::r1.39. This check too is hard-coded.
Might have had a cumulative effect on PR/52000.
 1.26.4.1 10-Jun-2019  christos Sync with HEAD
 1.26.2.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.30.2.1 17-Jan-2020  ad Sync with head.
 1.12 07-May-2016  maxv Large pages are supported by default for the text+rodata segments. Apply
the proper alignment for the data segment, so that more pages can benefit
from it. Reduces TLB contention.

kern.ldscript.2MB and largepages.inc are useless.
 1.11 25-Aug-2015  uebayasi Fix previous; do include assym.h.
 1.10 25-Aug-2015  uebayasi Replace COHERENCY_UNIT in ldscript.
 1.9 22-Aug-2015  uebayasi Don't need to specify OUTPUT_FORMAT/OUTPUT_ARCH in linker scripts.
 1.8 20-Aug-2015  uebayasi Simplify these by relocating only .text.
 1.7 20-Aug-2015  uebayasi Indent with 2 spaces.
 1.6 20-Aug-2015  uebayasi Kill trailing whitespaces.
 1.5 02-Nov-2014  uebayasi branches: 1.5.2;
Revert previous per joerg@'s request.

According to him, exposing .data.{read_mostly,cacheline_aligned} is
intentional so that people can easily see which variables are optimized.
 1.4 01-Nov-2014  uebayasi amd64, i386: Don't expose .data.{read_mostly,cacheline_aligned} sections
 1.3 01-Jun-2010  mjf branches: 1.3.18;
Add __cacheline_aligned and __read_mostly annotations.

These annotations help to mitigate false sharing on multiprocessor
systems.

Variables annotated with __cacheline_aligned are placed into the
.data.cacheline_aligned section in the kernel. Each item in this
section is aligned on a cachline boundary - this avoids false
sharing. Highly contended global locks are a good candidate for
__cacheline_aligned annotation.

Variables annotated with __read_mostly are packed together tightly
into a .data.read_mostly section in the kernel. The idea here is that
we can pack infrequently modified data items into a cacheline and
avoid having to purge the cache, which would happen if read mostly
data and write mostly data shared a cachline. Initialisation variables
are a prime candiate for __read_mostly annotations.
 1.2 18-Oct-2007  yamt branches: 1.2.2; 1.2.4; 1.2.6; 1.2.10; 1.2.28; 1.2.42; 1.2.48; 1.2.50;
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.1 01-Oct-2007  yamt branches: 1.1.2; 1.1.4;
file kern.ldscript.2MB was initially added on branch yamt-x86pmap.
 1.1.4.1 25-Oct-2007  bouyer Sync with HEAD.
 1.1.2.2 04-Oct-2007  yamt - move etext before rodata. define __data_start at the start of
.data section and use it instead of etext where appropriate.
- put .rodata.* into .rodata section as well.
- pmap_bootstrap: don't assume NBPD_L2 alignment.
- pmap_bootstrap: if DEBUG, print how many large pages and normal pages are
used to map kernel text.
 1.1.2.1 01-Oct-2007  yamt - fix LARGEPAGES.
- add amd64 linker script for it.
 1.2.50.1 03-Jul-2010  rmind sync with head
 1.2.48.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.2.42.2 29-Mar-2011  jym More sync fixes. And add the mbr_gpt files.
 1.2.42.1 24-Oct-2010  jym Sync with HEAD
 1.2.28.1 11-Aug-2010  yamt sync with head.
 1.2.10.2 06-Nov-2007  matt sync with HEAD
 1.2.10.1 18-Oct-2007  matt file kern.ldscript.2MB was added on branch matt-armv6 on 2007-11-06 23:14:14 +0000
 1.2.6.2 27-Oct-2007  yamt sync with head.
 1.2.6.1 18-Oct-2007  yamt file kern.ldscript.2MB was added on branch yamt-lazymbuf on 2007-10-27 11:25:09 +0000
 1.2.4.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.2.4.1 18-Oct-2007  joerg file kern.ldscript.2MB was added on branch jmcneill-pm on 2007-10-26 15:42:10 +0000
 1.2.2.2 23-Oct-2007  ad Sync with head.
 1.2.2.1 18-Oct-2007  ad file kern.ldscript.2MB was added on branch vmlocking on 2007-10-23 20:35:37 +0000
 1.3.18.1 03-Dec-2017  jdolecek update from HEAD
 1.5.2.2 29-May-2016  skrll Sync with HEAD
 1.5.2.1 22-Sep-2015  skrll Sync with HEAD
 1.18 24-Jan-2022  maya put .note.Xen into PT_NOTE

this is where grub 2.02 and possibly other things expect
to find it.
Fixes booting with grub2 on prgmr.com.
 1.17 21-May-2020  jdolecek update Xen ldscript to add kASan .ctors section, so that Xen kernel with
enabled KASAN option at least compiles; no promises on it actually working
though
 1.16 24-Jun-2018  maxv Sync the ld scripts:

* Force a PAGE_SIZE alignment of .bss on i386. Normally that's not
required since the bootloader ensures page alignment, but let's be
safe. Same on Xen-i386.

* Fill the .text section padding with int3 instructions on Xen kernels,
to prevent FALLTHROUGHs if a pointer goes crazy, same as native.
 1.15 24-Jun-2018  jdolecek follow change in rev. 1.22 of kern.ldscript and apply same fix for xen
ldscript too, but using just regular PAGE_ALIGN alignment:

"""
Fix a pretty dumb mistake I made in r1.22: the alignment needs to be in the
bss, otherwise the bootloader will use memory before __kernel_end and give
a wrong start pa to the kernel.
"""

this got broke by amd64/locore.S rev. 1.141 which removed an unused variable
which forced the alignment

this fixes ps/bt in ddb to be able to find symbols and hence PR port-xen/53056
 1.14 07-Jan-2018  maxv branches: 1.14.2;
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.13 02-Aug-2016  maxv branches: 1.13.8;
Align the segments properly, and split text+rodata in two separate segments
on Xen.
 1.12 13-May-2016  maxv branches: 1.12.2;
Xen therefore uses x86/db_memrw.c, as I suspected. Define __rodata_start
in the Xen ld scripts, so that it can compile. We put the __rodata_start
definition right before __data_start, for it to appear as dead code, since
the rodata segment is not yet mapped independently on Xen.
 1.11 12-May-2016  maxv KNF the Xen ld scripts on x86.
 1.10 25-Aug-2015  uebayasi Fix previous; do include assym.h.
 1.9 25-Aug-2015  uebayasi Replace COHERENCY_UNIT in ldscript.
 1.8 22-Aug-2015  uebayasi Don't need to specify OUTPUT_FORMAT/OUTPUT_ARCH in linker scripts.
 1.7 20-Aug-2015  uebayasi Simplify these by relocating only .text.
 1.6 20-Aug-2015  uebayasi Indent with 2 spaces.
 1.5 02-Nov-2014  uebayasi branches: 1.5.2;
Revert previous per joerg@'s request.

According to him, exposing .data.{read_mostly,cacheline_aligned} is
intentional so that people can easily see which variables are optimized.
 1.4 01-Nov-2014  uebayasi amd64, i386: Don't expose .data.{read_mostly,cacheline_aligned} sections
 1.3 01-Jun-2010  mjf branches: 1.3.18;
Add __cacheline_aligned and __read_mostly annotations.

These annotations help to mitigate false sharing on multiprocessor
systems.

Variables annotated with __cacheline_aligned are placed into the
.data.cacheline_aligned section in the kernel. Each item in this
section is aligned on a cachline boundary - this avoids false
sharing. Highly contended global locks are a good candidate for
__cacheline_aligned annotation.

Variables annotated with __read_mostly are packed together tightly
into a .data.read_mostly section in the kernel. The idea here is that
we can pack infrequently modified data items into a cacheline and
avoid having to purge the cache, which would happen if read mostly
data and write mostly data shared a cachline. Initialisation variables
are a prime candiate for __read_mostly annotations.
 1.2 22-Nov-2007  bouyer branches: 1.2.2; 1.2.4; 1.2.8; 1.2.16; 1.2.26; 1.2.40; 1.2.46; 1.2.48;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.1 17-Oct-2007  bouyer branches: 1.1.2; 1.1.4;
file kern.ldscript.Xen was initially added on branch bouyer-xenamd64.
 1.1.4.1 08-Dec-2007  mjf Sync with HEAD.
 1.1.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.1.2.1 17-Oct-2007  bouyer amd64 (aka x86-64) support for Xen. Based on the OpenBSD port done by
Mathieu Ropert in 2006.
DomU-only for now. An INSTALL_XEN3_DOMU kernel with a ramdisk will boot to
sysinst if you're lucky. Often it panics because a runable LWP has
a NULL stack (really, it's all of l->l_addr which is has been zeroed out
while the process was on the queue !)
TODO:
- bug fixes :)
- Most of the xpq_* functions should be shared with xen/i386
- The xen/i386 assembly bootstrap code should be remplaced with the C
version in xenamd64/amd64/xpmap.c
- see if a config(5) trick could allow to merge xenamd64 back to xen or amd64.
 1.2.48.1 03-Jul-2010  rmind sync with head
 1.2.46.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.2.40.2 29-Mar-2011  jym More sync fixes. And add the mbr_gpt files.
 1.2.40.1 24-Oct-2010  jym Sync with HEAD
 1.2.26.1 11-Aug-2010  yamt sync with head.
 1.2.16.2 09-Jan-2008  matt sync with HEAD
 1.2.16.1 22-Nov-2007  matt file kern.ldscript.Xen was added on branch matt-armv6 on 2008-01-09 01:44:51 +0000
 1.2.8.2 07-Dec-2007  yamt sync with head
 1.2.8.1 22-Nov-2007  yamt file kern.ldscript.Xen was added on branch yamt-lazymbuf on 2007-12-07 17:24:03 +0000
 1.2.4.2 03-Dec-2007  ad Sync with HEAD.
 1.2.4.1 22-Nov-2007  ad file kern.ldscript.Xen was added on branch vmlocking on 2007-12-03 19:02:47 +0000
 1.2.2.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.2.2.1 22-Nov-2007  joerg file kern.ldscript.Xen was added on branch jmcneill-pm on 2007-11-27 19:35:31 +0000
 1.3.18.1 03-Dec-2017  jdolecek update from HEAD
 1.5.2.3 05-Oct-2016  skrll Sync with HEAD
 1.5.2.2 29-May-2016  skrll Sync with HEAD
 1.5.2.1 22-Sep-2015  skrll Sync with HEAD
 1.12.2.1 06-Aug-2016  pgoyette Sync with HEAD
 1.13.8.1 06-Mar-2018  martin Pull up the following revisions, requested by maxv in ticket #603:

amd64/conf/kern.ldscript 1.25 (patch)
amd64/conf/kern.ldscript.Xen 1.14 (patch)
i386/conf/kern.ldscript 1.21 (patch)
i386/conf/kern.ldscript.Xen 1.15 (patch)
x86/include/cpufunc.h 1.24 (patch)
x86/x86/patch.c 1.25 (partial) 1.26 (partial)

Backport x86_hotpatch.
 1.14.2.1 25-Jun-2018  pgoyette Sync with HEAD
 1.5 21-Jan-2018  maxv Unmap the kernel from userland in SVS, and leave only the needed
trampolines. As explained below, SVS should now completely mitigate
Meltdown on GENERIC kernels, even though it needs some more tweaking
for GENERIC_KASLR.

Until now the kernel entry points looked like:

FUNC(intr)
pushq $ERR
pushq $TRAPNO
INTRENTRY
... handle interrupt ...
INTRFASTEXIT
END(intr)

With this change they are split and become:

FUNC(handle)
... handle interrupt ...
INTRFASTEXIT
END(handle)

TEXT_USER_BEGIN
FUNC(intr)
pushq $ERR
pushq $TRAPNO
INTRENTRY
jmp handle
END(intr)
TEXT_USER_END

A new section is introduced, .text.user, that contains minimal kernel
entry/exit points. In order to choose what to put in this section, two
macros are introduced, TEXT_USER_BEGIN and TEXT_USER_END.

The section is mapped in userland with normal 4K pages.

In GENERIC, the section is 4K-page-aligned and embedded in .text, which
is mapped with large pages. That is to say, when an interrupt comes in,
the CPU has the user page tables loaded and executes the 'intr' functions
on 4K pages; after calling SVS_ENTER (in INTRENTRY) these 4K pages become
2MB large pages, and remain so when executing in kernel mode.

In GENERIC_KASLR, the section is 4K-page-aligned and independent from the
other kernel texts. The prekern just picks it up and maps it at a random
address.

In GENERIC, SVS should now completely mitigate Meltdown: what we put in
.text.user is not secret.

In GENERIC_KASLR, SVS would have to be improved a bit more: the
'jmp handle' instruction is actually secret, since it leaks the address
of the section we are jumping into. By exploiting Meltdown on Intel, this
theoretically allows a local user to reconstruct the address of the first
text section. But given that our KASLR produces several texts, and that
each section is not correlated with the others, the level of protection
KASLR provides is still good.
 1.4 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.3 14-Nov-2017  maxv branches: 1.3.2;
Split each kernel section into sub-blocks of approximately 2MB. The newly
created sections are named .origname.i, for example:

.text -> { .text .text.0 .text.1 .text.2 .text.3 .text.4 }

Each section is randomized independently by the prekern - and in a random
order obviously. As a result we can get intertwined mappings, of the type:

+-------+-----------+------+---------+-----------+-------+-------+------+-
| text1 | NOTMAPPED | bss0 | rodata1 | NOTMAPPED | data2 | text3 | bss1 |
+-------+-----------+------+---------+-----------+-------+-------+------+-

---------+-
rodata0 | ...
---------+-

The CTF section is dropped completely, because (a) when split it becomes
enormous for some reason (that I don't quite understand, verily), and (b)
the kernel expects only one CTF and can't handle several of them.
 1.2 13-Nov-2017  maxv Use SUBALIGN, to force the alignment at the section level, and remove
the inter-section ALIGN which doesn't do anything since the physical
address of the section is chosen dynamically by the bootloader.
 1.1 09-Nov-2017  maxv Use another ld script for kaslr kernels, in which there are no alignment
directives. They don't matter since the bootloader overwrites them.

But, normally we still need to make sure .data.read_mostly is aligned.
Unfortunately I couldn't find any way to force sh_addralign to be 64, so
I'm leaving the alignment there as a useless reminder.
 1.3.2.2 03-Dec-2017  jdolecek update from HEAD
 1.3.2.1 14-Nov-2017  jdolecek file kern.ldscript.kaslr was added on branch tls-maxphys on 2017-12-03 11:35:47 +0000
 1.5 07-May-2016  maxv Large pages are supported by default for the text+rodata segments. Apply
the proper alignment for the data segment, so that more pages can benefit
from it. Reduces TLB contention.

kern.ldscript.2MB and largepages.inc are useless.
 1.4 21-Aug-2015  uebayasi ${KERN_LDSCRIPT} -> ${KERNLDSCRIPT}
 1.3 07-Jan-2008  martti branches: 1.3.54; 1.3.74;
Fixed option indentation, it should be

option<space><tab>
makeoption<space><tab>
 1.2 18-Oct-2007  yamt branches: 1.2.2; 1.2.4; 1.2.6; 1.2.8; 1.2.10; 1.2.16;
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.1 01-Oct-2007  yamt branches: 1.1.2; 1.1.4;
file largepages.inc was initially added on branch yamt-x86pmap.
 1.1.4.1 25-Oct-2007  bouyer Sync with HEAD.
 1.1.2.2 04-Oct-2007  yamt remove LARGEPAGES option. always use large pages if available.
 1.1.2.1 01-Oct-2007  yamt - fix LARGEPAGES.
- add amd64 linker script for it.
 1.2.16.1 08-Jan-2008  bouyer Sync with HEAD
 1.2.10.3 09-Jan-2008  matt sync with HEAD
 1.2.10.2 06-Nov-2007  matt sync with HEAD
 1.2.10.1 18-Oct-2007  matt file largepages.inc was added on branch matt-armv6 on 2007-11-06 23:14:15 +0000
 1.2.8.1 18-Feb-2008  mjf Sync with HEAD.
 1.2.6.3 21-Jan-2008  yamt sync with head
 1.2.6.2 27-Oct-2007  yamt sync with head.
 1.2.6.1 18-Oct-2007  yamt file largepages.inc was added on branch yamt-lazymbuf on 2007-10-27 11:25:09 +0000
 1.2.4.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.2.4.1 18-Oct-2007  joerg file largepages.inc was added on branch jmcneill-pm on 2007-10-26 15:42:10 +0000
 1.2.2.2 23-Oct-2007  ad Sync with head.
 1.2.2.1 18-Oct-2007  ad file largepages.inc was added on branch vmlocking on 2007-10-23 20:35:38 +0000
 1.3.74.2 29-May-2016  skrll Sync with HEAD
 1.3.74.1 22-Sep-2015  skrll Sync with HEAD
 1.3.54.1 03-Dec-2017  jdolecek update from HEAD
 1.36 25-May-2022  uwe x86: Reserve device major for VirtualBox Guest Additions
 1.35 29-Jun-2021  nia Remove uscanner(4) driver

This exists for compatibility with a Linux interface which was apparently
deprecated in Linux 2.6. There are various mailing list threads going
back to 2004 where the usefulness of this driver is discussed, but
the conclusion is that scanner software has all moved to using ugen(4)
instead, and enabling this driver will not help you scan things.
 1.34 04-Apr-2020  jdolecek branches: 1.34.8;
mark nsmb major obsolete
 1.33 29-Jan-2020  maya remove urio(4), a driver for the Rio500 MP3 player.

At this point it is highly unlikely this 1999 device still has users,
but it still comes up in the context of maxv's USB-fuzzing (and any device
could pretend to be a urio(4)), so it's best to get rid of it.

Renamed all major entries to obsolete, as was done in previous removals.

This still requires an update to sanitizers, but they're located in
"external", perhaps it should be first committed upstream?

Proposed on tech-kern a month ago.
 1.32 28-Jan-2019  dholland branches: 1.32.6;
Systematize handling of removed drivers.

- Every driver that was removed and whose number hasn't already been
reused is now listed with a commented-out "obsolete" line.
- The format of these has been systematized. Future format changes can
probably be safely done with a script.
- This does not include a few cases of assignments that only lasted a
couple days, or stuff from before major reorgs. Some of these may
be included nonetheless, because there was a lot of ground to cover
and therefore not a lot of time to dig into history in detail.

Note that the obsolete listings do not mean the major numbers can
never be reused; that's up to portmasters and/or core. It does mean
that they won't be reused by accident, however, which in some cases
(depending on the driver, how widely used it was, its family of device
nodes, their default permissions, etc.) can be quite dangerous.

Note that some of the things now explicitly listed as obsolete are
really ancient history. My scan went back as far as when the majors
files were added. (But not before that.)
 1.31 27-Jan-2019  dholland Restore satlink's majors entries commented out and marked obsolete.
Otherwise they might accidentally get reused later and cause a
security problem.
 1.30 27-Jan-2019  maxv Remove the satlink driver. It was disabled everywhere, had no man page and
no use either. Spotted by thorpej in PR/21345, ok christos.
 1.29 19-Dec-2018  maxv Remove compat_svr4 and compat_svr4_32, as discussed on tech-kern@ recently,
but also as discussed several times in the past.
 1.28 23-Sep-2018  maxv Remove ISDN from the kernel. It has remained unmaintained for a long time,
is of poor quality, and is now an obstacle to MP-ification. It was removed
ten years ago from FreeBSD for the same reason.

This retires a big user of the mbuf API, and will ease maintenance of the
kernel.
 1.27 12-Jan-2017  ryo branches: 1.27.14; 1.27.16;
white space police
 1.26 08-Dec-2016  nat Add a synthesized pc beeper and keyboard bell for platforms with an audio
device.
 1.25 23-Apr-2015  pgoyette branches: 1.25.2;
Update device dependency information - the sysmon major device now depends on the sysmon module itself, not on the individual components.
 1.24 30-Jun-2011  wiz branches: 1.24.12; 1.24.30;
dependant -> dependent
 1.23 06-Mar-2010  plunky use a MI major number for uhso(4) driver
(requested by mrg)
 1.22 06-Mar-2010  plunky add major device for usho(4) driver
 1.21 12-Nov-2008  ad branches: 1.21.4; 1.21.6;
Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.
 1.20 15-Jul-2008  cegger branches: 1.20.2;
Configure /dev/power for domu as in src/sys/arch/i386/conf/majors.i386.
See discussion on port-xen for the details at http://mail-index.netbsd.org/port-xen/2008/06/14/msg003904.html
 1.19 31-Dec-2007  ad branches: 1.19.6; 1.19.10; 1.19.12; 1.19.14; 1.19.16;
Remove systrace. Ok core@.
 1.18 22-Nov-2007  bouyer branches: 1.18.6;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.17 09-Jan-2007  cube branches: 1.17.6; 1.17.22; 1.17.24; 1.17.28; 1.17.30;
Remove traces of scd(4), which apparently never actually had a driver in
the tree.
 1.16 24-Nov-2006  wiz s/independant/independent/, from Zafer.
 1.15 11-Dec-2005  christos branches: 1.15.20; 1.15.22;
merge ktrace-lwp.
 1.14 17-Sep-2005  yamt make VMSWAP optional again.
 1.13 31-Jul-2005  yamt revert "defflag VMSWAP" changes for now.
there seems to be far more people who don't want to edit
their kernel config files than i thought.
 1.12 30-Jul-2005  yamt defflag VMSWAP.
 1.11 10-Dec-2003  jmc branches: 1.11.16;
Change reference at bottom from sys/dev/majors to sys/conf/majors to match
reality
 1.10 22-Oct-2003  jdolecek add kttcp major
 1.9 22-Oct-2003  jdolecek add majors for mly, dpti, dpt, twe, joy, radio, cir
 1.8 22-Oct-2003  jdolecek add wsfont major to archs which have the other wscons devices
 1.7 15-Oct-2003  jdolecek add major for nsmb, at #98 to be in sync with i386
 1.6 10-Oct-2003  jdolecek reassing majors for crypto and pf to use the newly defined MI major
range
 1.5 10-Oct-2003  jdolecek update the comment - the space for machine-dependant majors
is reduced to 0-143
follows discussion on tech-kern
 1.4 05-Oct-2003  jdolecek Add some framework for MI assignment of device majors - add sys/dev/majors
which is automatically included during kernel config, and add comments
to individual machine-dependant majors.* files to assign new MI majors
in MI file.

Range 0-191 is reserved for machine-specific assignments, range
192+ are MI assignments.

Follows recent discussion on tech-kern@
 1.3 22-Aug-2003  itojun create /dev/crypto
 1.2 27-Jul-2003  itojun reserve cdev major # for PF. ok'ed by technical-exec
 1.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.2.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 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.11.16.5 21-Jan-2008  yamt sync with head
 1.11.16.4 07-Dec-2007  yamt sync with head
 1.11.16.3 26-Feb-2007  yamt sync with head.
 1.11.16.2 30-Dec-2006  yamt sync with head.
 1.11.16.1 21-Jun-2006  yamt sync with head.
 1.15.22.1 10-Dec-2006  yamt sync with head.
 1.15.20.1 12-Jan-2007  ad Sync with head.
 1.17.30.2 18-Feb-2008  mjf Sync with HEAD.
 1.17.30.1 08-Dec-2007  mjf Sync with HEAD.
 1.17.28.1 17-Oct-2007  bouyer amd64 (aka x86-64) support for Xen. Based on the OpenBSD port done by
Mathieu Ropert in 2006.
DomU-only for now. An INSTALL_XEN3_DOMU kernel with a ramdisk will boot to
sysinst if you're lucky. Often it panics because a runable LWP has
a NULL stack (really, it's all of l->l_addr which is has been zeroed out
while the process was on the queue !)
TODO:
- bug fixes :)
- Most of the xpq_* functions should be shared with xen/i386
- The xen/i386 assembly bootstrap code should be remplaced with the C
version in xenamd64/amd64/xpmap.c
- see if a config(5) trick could allow to merge xenamd64 back to xen or amd64.
 1.17.24.1 09-Jan-2008  matt sync with HEAD
 1.17.22.1 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.17.6.2 03-Dec-2007  ad Sync with HEAD.
 1.17.6.1 03-Dec-2007  ad Sync with HEAD.
 1.18.6.1 02-Jan-2008  bouyer Sync with HEAD
 1.19.16.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.19.16.1 19-Oct-2008  haad Sync with HEAD.
 1.19.14.1 18-Jul-2008  simonb Sync with head.
 1.19.12.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.19.10.1 04-May-2009  yamt sync with head.
 1.19.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.19.6.1 28-Sep-2008  mjf Sync with HEAD.
 1.20.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.21.6.2 27-Oct-2010  uebayasi Move flash(4)/xmd(4) majors to MI, as suggested by Chuck Silvers.
 1.21.6.1 27-Aug-2010  uebayasi xmd(4) / XIP config for amd64.
 1.21.4.3 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.21.4.2 29-Mar-2011  jym More sync fixes. And add the mbr_gpt files.
 1.21.4.1 24-Oct-2010  jym Sync with HEAD
 1.24.30.2 05-Feb-2017  skrll Sync with HEAD
 1.24.30.1 06-Jun-2015  skrll Sync with HEAD
 1.24.12.1 03-Dec-2017  jdolecek update from HEAD
 1.25.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.25.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.27.16.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.27.16.1 10-Jun-2019  christos Sync with HEAD
 1.27.14.2 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.27.14.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.32.6.1 29-Feb-2020  ad Sync with head.
 1.34.8.1 01-Aug-2021  thorpej Sync with HEAD.
 1.13 05-May-2023  manu Add a SELFRELOC kernel option for the sake of documentation clarity.

Instead of telling that x86/boot(8) reloc command needs a kernel able
to self relocate, we can tell it needs a kernel built with the
SELFRELOC option. This keeps the reader from wondering what could
make a kernel able to self relocate.
 1.12 25-Apr-2020  bouyer branches: 1.12.20;
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.11 12-Jan-2017  ryo branches: 1.11.20; 1.11.26;
white space police
 1.10 07-May-2015  mrg branches: 1.10.2;
bump CHILD_MAX and OPEN_MAX defaults on several platforms, both to 1024.
 1.9 27-Sep-2012  alnsn branches: 1.9.12; 1.9.14;
Remove bpf_jit which was ported from FreeBSD recently.

It will soon be replaced with the new bpfjit kernel module.
 1.8 01-Aug-2012  rmind branches: 1.8.2;
Add BPF JIT compiler, currently supporting amd64 and i386. Code obtained
from FreeBSD. Also, make few BPF fixes and simplifications while here.
Note that bpf_jit_enable is false for now.

OK dyoung@, some feedback from matt@
 1.7 11-Dec-2008  alc Import config(9) file and register HAL's files in the build machinery.
 1.6 30-Apr-2008  ad branches: 1.6.6; 1.6.8; 1.6.10; 1.6.16;
Shuffle ioapic/mainbus/cpu into std.amd64 like i386.
 1.5 29-Apr-2008  ad Require MULTIPROCESSOR. PR kern/38537.
 1.4 25-Jan-2008  joerg branches: 1.4.6; 1.4.8; 1.4.10;
Refactor in_cksum/in4_cksum/in6_cksum implementations:
- All three functions are included in the kernel by default.
They call a backend function cpu_in_cksum after possibly
computing the checksum of the pseudo header.
- cpu_in_cksum is the core to implement the one-complement sum.
The default implementation is moderate fast on most platforms
and provides a 32bit accumulator with 16bit addends for L32 platforms
and a 64bit accumulator with 32bit addends for L64 platforms.
It handles edge cases like very large mbuf chains (could happen with
native IPv6 in the future) and provides a good base for new native
implementations.
- Modify i386 and amd64 assembly to use the new interface.

This disables the MD implementations on !x86 until the conversion is
done. For Alpha, the portable version is faster.
 1.3 11-Dec-2005  christos branches: 1.3.50; 1.3.56;
merge ktrace-lwp.
 1.2 17-Sep-2005  yamt include "conf/std".
 1.1 26-Apr-2003  fvdl branches: 1.1.2; 1.1.18;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.18.2 04-Feb-2008  yamt sync with head.
 1.1.18.1 21-Jun-2006  yamt sync with head.
 1.1.2.1 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.3.56.1 18-Feb-2008  mjf Sync with HEAD.
 1.3.50.1 23-Mar-2008  matt sync with HEAD
 1.4.10.2 04-May-2009  yamt sync with head.
 1.4.10.1 16-May-2008  yamt sync with head.
 1.4.8.1 18-May-2008  yamt sync with head.
 1.4.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.4.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.6.16.1 21-Apr-2010  matt sync to netbsd-5
 1.6.10.1 07-Aug-2009  snj Apply patch (requested by jmcneill in ticket 775):
Update to the open source atheros HAL.
 1.6.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.6.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.8.2.2 03-Dec-2017  jdolecek update from HEAD
 1.8.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.9.14.2 05-Feb-2017  skrll Sync with HEAD
 1.9.14.1 06-Jun-2015  skrll Sync with HEAD
 1.9.12.1 09-May-2015  snj Pull up following revision(s) (requested by mrg in ticket #741):
sys/arch/aarch64/conf/std.aarch64: revision 1.2
sys/arch/amd64/conf/std.amd64: revision 1.10
sys/arch/evbarm/conf/std.evbarm: revision 1.4
sys/arch/evbarm64/conf/std.evbarm64: revision 1.2
sys/arch/i386/conf/std.i386: revision 1.34
sys/arch/sparc64/conf/std.sparc64: revision 1.19
bump CHILD_MAX and OPEN_MAX defaults on several platforms, both to 1024.
 1.10.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.11.26.2 20-Apr-2020  bouyer Use std.xenversion
 1.11.26.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.
 1.11.20.1 13-May-2023  martin Pull up following revision(s) (requested by manu in ticket #1632):

share/man/man8/man8.x86/boot.8: revision 1.27
sys/arch/i386/stand/efiboot/version: revision 1.3
share/man/man8/man8.x86/boot.8: revision 1.28 (via patch)
share/man/man8/man8.x86/boot.8: revision 1.29 (via patch)
sys/arch/i386/stand/lib/exec.c: revision 1.79
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.13
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.6
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.6
sys/arch/i386/stand/efiboot/boot.c: revision 1.22
sys/arch/amd64/amd64/locore.S: revision 1.219
sys/arch/i386/stand/efiboot/bootia32/startprog32.S: revision 1.3
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.12
sys/arch/amd64/conf/files.amd64: revision 1.121
sys/arch/amd64/conf/std.amd64: revision 1.13
share/man/man8/man8.x86/pxeboot.8: revision 1.6
sys/arch/i386/stand/efiboot/bootx64/startprog64.S: revision 1.4
sys/arch/amd64/amd64/locore.S: revision 1.220
share/man/man8/man8.x86/dosboot.8: revision 1.4
share/man/man4/options.4: revision 1.524

Add reloc keyworkd to let EFI bootstrap load amd64 kernel at any address

EFI bootstrap assumes it can copy the amd64 kernel to its ELF load
address (that is KERNTEXTOFF - KERNBASE = 0x200000), but it can
clash with previous UEFI memory allocation, as described here:
http://mail-index.netbsd.org/tech-kern/2023/04/07/msg028833.html

This change adds a reloc keyword for controling where the EFI
boostrap will copy the kernel image. Possible values are:
default - the default and prior behavior, copy at 0x200000.
none - do not copy and use the kernel image where it was loaded.
address - specify an explicit address where to copy the kernel.

This comes with an amd64 kernel patch that makes it self-relocatable.
It first discover where it was loaded in memory, and if this is
different than the expected 0x200000, hhe the kernel relocates
itself and start over at the right address.

Merge x86 boot options in x86/boot(8) and add undocumented UEFI options

We were supposed to keep the option list in x86/boot(8), x86/dosoot(8)
and x86/pxeboot(8) in sync, but it did not happen, hence it may work
better with all the options in x86/boot(8). Also add the undocumented
UEFI boot options.

Add a SELFRELOC kernel option for the sake of documentation clarity.
Instead of telling that x86/boot(8) reloc command needs a kernel able
to self relocate, we can tell it needs a kernel built with the
SELFRELOC option. This keeps the reader from wondering what could
make a kernel able to self relocate.

Remove XXX todo marker left by mistake

Raise the version for new feature (here reloc command)
Suggested by Masanobu SAITOH
 1.12.20.1 13-May-2023  martin Pull up following revision(s) (requested by manu in ticket #159):

share/man/man8/man8.x86/boot.8: revision 1.27
sys/arch/i386/stand/efiboot/version: revision 1.3
share/man/man8/man8.x86/boot.8: revision 1.28
share/man/man8/man8.x86/boot.8: revision 1.29
sys/arch/i386/stand/lib/exec.c: revision 1.79
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.13
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.6
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.6
sys/arch/i386/stand/efiboot/boot.c: revision 1.22
sys/arch/amd64/amd64/locore.S: revision 1.219
sys/arch/i386/stand/efiboot/bootia32/startprog32.S: revision 1.3
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.12
sys/arch/amd64/conf/files.amd64: revision 1.121
sys/arch/amd64/conf/std.amd64: revision 1.13
share/man/man8/man8.x86/pxeboot.8: revision 1.6
sys/arch/i386/stand/efiboot/bootx64/startprog64.S: revision 1.4
sys/arch/amd64/amd64/locore.S: revision 1.220
share/man/man8/man8.x86/dosboot.8: revision 1.4
share/man/man4/options.4: revision 1.524

Add reloc keyworkd to let EFI bootstrap load amd64 kernel at any address

EFI bootstrap assumes it can copy the amd64 kernel to its ELF load
address (that is KERNTEXTOFF - KERNBASE = 0x200000), but it can
clash with previous UEFI memory allocation, as described here:
http://mail-index.netbsd.org/tech-kern/2023/04/07/msg028833.html

This change adds a reloc keyword for controling where the EFI
boostrap will copy the kernel image. Possible values are:
default - the default and prior behavior, copy at 0x200000.
none - do not copy and use the kernel image where it was loaded.
address - specify an explicit address where to copy the kernel.

This comes with an amd64 kernel patch that makes it self-relocatable.
It first discover where it was loaded in memory, and if this is
different than the expected 0x200000, hhe the kernel relocates
itself and start over at the right address.


Merge x86 boot options in x86/boot(8) and add undocumented UEFI options

We were supposed to keep the option list in x86/boot(8), x86/dosoot(8)
and x86/pxeboot(8) in sync, but it did not happen, hence it may work
better with all the options in x86/boot(8). Also add the undocumented
UEFI boot options.


Add a SELFRELOC kernel option for the sake of documentation clarity.
Instead of telling that x86/boot(8) reloc command needs a kernel able
to self relocate, we can tell it needs a kernel built with the
SELFRELOC option. This keeps the reader from wondering what could
make a kernel able to self relocate.

Remove XXX todo marker left by mistake

Raise the version for new feature (here reloc command)
Suggested by Masanobu SAITOH
 1.14 04-Mar-2021  gdt std.xen: Move towards std.amd64

(No functional change.)
 1.13 25-Apr-2020  bouyer branches: 1.13.2;
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.12 09-Apr-2020  jdolecek move xen/conf/std.xen to i386/conf/std.xen, it's i386-specific

split off __XEN_INTERFACE_VERSION__ to new xen/conf/std.xenversion
and use from both i386/conf/std.xen and amd64/conf/stf.xen, so that
there is single place for the definition
 1.11 04-Feb-2019  cherry branches: 1.11.10;
Bump up XEN source API compatibility to 0x00030208 from 0x00030201,

but maintain backwards source API compilation compatibility.

ie; sources with config(5)
options __XEN_INTERFACE_VERSION__=0x00030201 # Xen 3.1 interface

should compile and run without problems.

Not that API version 0x00030201 is the lowest version we support now.
 1.10 02-Feb-2019  cherry Switch NetBSD/xen to use XEN api tag RELEASE-4.11.1

The headers for this api are in sys/external/mit/xen-include-public/dist/
 1.9 12-Jan-2017  ryo branches: 1.9.16;
white space police
 1.8 23-Sep-2016  joerg Use the same process and file limits as normal AND64 for Xen kernels.
 1.7 11-Oct-2014  uebayasi branches: 1.7.2; 1.7.4;
Don't include std.ath_hal for XEN3_DOMU.
 1.6 29-Jul-2009  cegger branches: 1.6.10; 1.6.22; 1.6.38; 1.6.40; 1.6.42;
remove Xen2 support.
ok bouyer@
 1.5 11-Dec-2008  alc branches: 1.5.2;
Import config(9) file and register HAL's files in the build machinery.
 1.4 13-Nov-2008  cegger prepare move to new interface
 1.3 25-Jan-2008  joerg branches: 1.3.6; 1.3.10; 1.3.16; 1.3.18; 1.3.20; 1.3.24;
Refactor in_cksum/in4_cksum/in6_cksum implementations:
- All three functions are included in the kernel by default.
They call a backend function cpu_in_cksum after possibly
computing the checksum of the pseudo header.
- cpu_in_cksum is the core to implement the one-complement sum.
The default implementation is moderate fast on most platforms
and provides a 32bit accumulator with 16bit addends for L32 platforms
and a 64bit accumulator with 32bit addends for L64 platforms.
It handles edge cases like very large mbuf chains (could happen with
native IPv6 in the future) and provides a good base for new native
implementations.
- Modify i386 and amd64 assembly to use the new interface.

This disables the MD implementations on !x86 until the conversion is
done. For Alpha, the portable version is faster.
 1.2 22-Nov-2007  bouyer branches: 1.2.2; 1.2.4; 1.2.8; 1.2.10; 1.2.18;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.1 19-Nov-2007  bouyer branches: 1.1.2;
file std.xen was initially added on branch bouyer-xenamd64.
 1.1.2.1 19-Nov-2007  bouyer Get rid of arch/xenamd64, step 1: empty xenamd64/conf
- move xenamd64/conf/std.xen to amd64/conf/
- define arch to amd64 amd64/conf/std.xen, and i386 in xen/conf/std.xen
(machine is xen)
- enclose content of amd64/conf/files.amd64 and i386/conf/files.i386 in
ifndef xen/endif, so it can be transparently inclued for xen kernels
- support MACHINE_ARCH=x86_64 in xen/conf/Makefile*
 1.2.18.3 23-Mar-2008  matt sync with HEAD
 1.2.18.2 09-Jan-2008  matt sync with HEAD
 1.2.18.1 22-Nov-2007  matt file std.xen was added on branch matt-armv6 on 2008-01-09 01:44:52 +0000
 1.2.10.3 18-Feb-2008  mjf Sync with HEAD.
 1.2.10.2 08-Dec-2007  mjf Sync with HEAD.
 1.2.10.1 22-Nov-2007  mjf file std.xen was added on branch mjf-devfs on 2007-12-08 18:16:28 +0000
 1.2.8.3 04-Feb-2008  yamt sync with head.
 1.2.8.2 07-Dec-2007  yamt sync with head
 1.2.8.1 22-Nov-2007  yamt file std.xen was added on branch yamt-lazymbuf on 2007-12-07 17:24:03 +0000
 1.2.4.2 03-Dec-2007  ad Sync with HEAD.
 1.2.4.1 22-Nov-2007  ad file std.xen was added on branch vmlocking on 2007-12-03 19:02:48 +0000
 1.2.2.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.2.2.1 22-Nov-2007  joerg file std.xen was added on branch jmcneill-pm on 2007-11-27 19:35:32 +0000
 1.3.24.1 21-Apr-2010  matt sync to netbsd-5
 1.3.20.1 07-Aug-2009  snj Apply patch (requested by jmcneill in ticket 775):
Update to the open source atheros HAL.
 1.3.18.1 19-Jan-2009  skrll Sync with HEAD.
 1.3.16.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.3.10.2 19-Aug-2009  yamt sync with head.
 1.3.10.1 04-May-2009  yamt sync with head.
 1.3.6.1 17-Jan-2009  mjf Sync with HEAD.
 1.5.2.2 29-Mar-2011  jym More sync fixes. And add the mbr_gpt files.
 1.5.2.1 01-Nov-2009  jym Sync with HEAD.
 1.6.42.1 18-Jan-2017  skrll Sync with netbsd-5
 1.6.40.1 01-Nov-2016  snj Pull up following revision(s) (requested by joerg in ticket #1258):
sys/arch/amd64/conf/std.xen: revision 1.8
sys/arch/xen/conf/std.xen: revision 1.8
Use the same process and file limits as normal AND64 for Xen kernels.
Given Xen/i386 the same process and file limit as native i386.
 1.6.38.1 01-Nov-2016  snj Pull up following revision(s) (requested by joerg in ticket #1258):
sys/arch/amd64/conf/std.xen: revision 1.8
sys/arch/xen/conf/std.xen: revision 1.8
Use the same process and file limits as normal AND64 for Xen kernels.
Given Xen/i386 the same process and file limit as native i386.
 1.6.22.1 03-Dec-2017  jdolecek update from HEAD
 1.6.10.1 03-Jun-2011  cherry Initial import of xen MP sources, with kernel and userspace tests.
- this is a source priview.
- boots to single user.
- spurious interrupt and pmap related panics are normal
 1.7.4.2 20-Mar-2017  pgoyette Sync with HEAD
 1.7.4.1 04-Nov-2016  pgoyette Sync with HEAD
 1.7.2.2 05-Feb-2017  skrll Sync with HEAD
 1.7.2.1 05-Oct-2016  skrll Sync with HEAD
 1.9.16.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.9.16.1 10-Jun-2019  christos Sync with HEAD
 1.11.10.2 20-Apr-2020  bouyer Sync with HEAD
 1.11.10.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.
 1.13.2.1 03-Apr-2021  thorpej Sync with HEAD.
 1.25 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.24 04-Nov-2024  christos Undo previous lwp.h change.
 1.23 03-Nov-2024  christos Split __lwp_getprivate_fast and __lwp_*tcb from mcontext.h into a separate
lwp.h file.
 1.22 31-Oct-2018  maxv branches: 1.22.36;
Revert my kasan addition in this makefile, it looks like it causes
asan.h to be installed, while we don't want it to be.
 1.21 31-Oct-2018  maxv Move the MI parts of KASAN into kern/subr_asan.c. This file includes
machine/asan.h, which contains the MD functions. We use an include rather
than a plain C file, because we want GCC to optimize/inline some functions
into one single block.

The amd64 MD parts of KASAN are moved accordingly.

The naming convention we use is:

kasan_*
a generic kasan object, declared in subr_asan.c
kasan_md_*
an MD kasan object, declared in machine/asan.h, and used
in subr_asan.c
__md_*
an MD object, declared in machine/asan.h, and not used
outside

Overall this makes it easier to add KASAN support on more architectures.

Discussed with several people.
 1.20 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.19 27-Feb-2016  tls branches: 1.19.16; 1.19.18;
Add cpu_rng, a framework for simple on-CPU random number generators.
 1.18 23-Jul-2014  alnsn branches: 1.18.4;
Rename sljitarch.h to sljit_machdep.h.
 1.17 18-Feb-2014  dsl branches: 1.17.2;
Copy fpu.h to release
 1.16 11-Feb-2014  dsl Move sys/arch/amd64/amd64/fpu.c and sys/arch/amd64/include/fpu.h
into sys/arch/x86 in preparation for using the same code for i386.
 1.15 05-Nov-2012  alnsn Build sljit test when MKSLJIT != no and set MKSLJIT to yes on amd64 and i386.
 1.14 08-Aug-2012  drochner branches: 1.14.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.13 17-Jul-2011  joerg branches: 1.13.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.12 17-Jul-2011  dyoung On amd64, good-bye <machine/bus.h>.

Up next: update set lists.
 1.11 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.10 04-Jan-2008  dsl branches: 1.10.10; 1.10.24; 1.10.30; 1.10.32;
Change the way that the trap/intr/syscall frames and the __gregset_t[]
indexes are defined so that only a single list of the registers is used.
The code no longer relies on the two structures matching.
There should be no binary change.
 1.9 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.8 09-Feb-2007  ad branches: 1.8.12; 1.8.24; 1.8.30; 1.8.32; 1.8.36;
Merge newlock2 to head.
 1.7 09-Feb-2006  manu branches: 1.7.14;
Add initial (but unfinished) COMPAT_LINUX32 for amd64. This is good enough so
that the i386 license manager part of amd64 version of Fluent works.

While I'm here, add SysV IPC to COMPAT_LINUX/amd64
 1.6 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.5 03-Feb-2006  jmmv branches: 1.5.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.4 11-Dec-2005  christos branches: 1.4.2; 1.4.4;
merge ktrace-lwp.
 1.3 02-Jul-2004  drochner branches: 1.3.12;
add a <machine/joystick.h> which just includes the new common one
 1.2 08-May-2004  kleink Factor out W{CHAR,INT}_{MAX,MIN} into their own header file.
 1.1 26-Apr-2003  fvdl branches: 1.1.2; 1.1.4;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.4.1 05-Jul-2004  he Pull up revision 1.3 (requested by drochner in ticket #605):
Add a <machine/joystick.h> which here is just a copy
of the i386 one.
 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.3.12.3 21-Jan-2008  yamt sync with head
 1.3.12.2 26-Feb-2007  yamt sync with head.
 1.3.12.1 21-Jun-2006  yamt sync with head.
 1.4.4.1 09-Sep-2006  rpaulo sync with head
 1.4.2.1 18-Feb-2006  yamt sync with head.
 1.5.2.1 22-Apr-2006  simonb Sync with head.
 1.7.14.1 24-Oct-2006  ad Compile fixes
 1.8.36.2 08-Jan-2008  bouyer Sync with HEAD
 1.8.36.1 02-Jan-2008  bouyer Sync with HEAD
 1.8.32.1 26-Dec-2007  ad Sync with head.
 1.8.30.1 18-Feb-2008  mjf Sync with HEAD.
 1.8.24.1 09-Jan-2008  matt sync with HEAD
 1.8.12.1 18-Apr-2007  thorpej Convert i386 and amd64 to the new atomic ops API.
 1.10.32.1 05-Mar-2011  rmind sync with head
 1.10.30.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.10.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.10.24.1 24-Oct-2010  jym Sync with HEAD
 1.10.10.1 11-Aug-2010  yamt sync with head.
 1.13.2.2 16-Jan-2013  yamt sync with (a bit old) head
 1.13.2.1 30-Oct-2012  yamt sync with head
 1.14.2.3 03-Dec-2017  jdolecek update from HEAD
 1.14.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.14.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.17.2.1 10-Aug-2014  tls Rebase.
 1.18.4.1 19-Mar-2016  skrll Sync with HEAD
 1.19.18.1 10-Jun-2019  christos Sync with HEAD
 1.19.16.2 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.19.16.1 28-Jul-2018  pgoyette Sync with HEAD
 1.22.36.1 02-Aug-2025  perseant Sync with HEAD
 1.5 19-Oct-2014  joerg Disable SSE and AVX for kernel modules too.
 1.4 11-Jun-2012  chs branches: 1.4.2; 1.4.14;
make dtrace work on amd64.
 1.3 27-Nov-2009  pooka branches: 1.3.4; 1.3.8; 1.3.10; 1.3.18; 1.3.24;
Move -mcmodel=kernel CFLAGS from bsd.klinks.mk to amd64/include/Makefile.inc
to avoid having the kernel toolchain flags split over a billion different
files.
 1.2 25-Nov-2009  tron 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 11-Nov-2009  haad branches: 1.1.2; 1.1.4;
Build kernel modules with -mno-red-zone like kernel is build. This fixes
frequent panics in amd64 zfs module. This should also fix problem reported
by Nicolas Joly in:

http://mail-index.netbsd.org/port-amd64/2008/12/09/msg000646.html

Thanks to cube@ for his help with this.
 1.1.4.2 13-Nov-2009  sborrill Pull up the following revisions(s) (requested by cube in ticket #1140):
sys/arch/amd64/include/Makefile.inc: revision 1.1

Build kernel modules with -mno-red-zone like kernel is build. This fixes
frequent panics in amd64 zfs module, plus other reported problems.
 1.1.4.1 11-Nov-2009  sborrill file Makefile.inc was added on branch netbsd-5-0 on 2009-11-13 20:42:49 +0000
 1.1.2.2 13-Nov-2009  sborrill Pull up the following revisions(s) (requested by cube in ticket #1140):
sys/arch/amd64/include/Makefile.inc: revision 1.1

Build kernel modules with -mno-red-zone like kernel is build. This fixes
frequent panics in amd64 zfs module, plus other reported problems.
 1.1.2.1 11-Nov-2009  sborrill file Makefile.inc was added on branch netbsd-5 on 2009-11-13 20:38:48 +0000
 1.3.24.2 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.3.24.1 22-Nov-2012  riz Pull up following revision(s) (requested by chs in ticket #690):
external/cddl/osnet/dev/dtrace/amd64/dtrace_isa.c: revision 1.4
sys/arch/amd64/include/Makefile.inc: revision 1.4
sys/arch/amd64/include/pmap.h: revision 1.33
external/cddl/osnet/dev/dtrace/amd64/dtrace_subr.c: revision 1.6
sys/arch/amd64/include/asm.h: revision 1.15
sys/arch/amd64/amd64/genassym.cf: revision 1.51
external/cddl/osnet/dev/dtrace/amd64/dtrace_asm.S: revision 1.4
make dtrace work on amd64.
allow more space for modules.
 1.3.18.1 30-Oct-2012  yamt sync with head
 1.3.10.2 24-Oct-2010  jym Sync with HEAD
 1.3.10.1 27-Nov-2009  jym file Makefile.inc was added on branch jym-xensuspend on 2010-10-24 22:47:52 +0000
 1.3.8.2 21-Apr-2010  matt sync to netbsd-5
 1.3.8.1 27-Nov-2009  matt file Makefile.inc was added on branch matt-nb5-mips64 on 2010-04-21 00:33:53 +0000
 1.3.4.2 11-Mar-2010  yamt sync with head
 1.3.4.1 27-Nov-2009  yamt file Makefile.inc was added on branch yamt-nfs-mp on 2010-03-11 15:01:59 +0000
 1.4.14.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.4.2.1 03-Dec-2017  jdolecek update from HEAD
 1.6 24-May-2008  jmcneill MI implementation of AcpiAcquireGlobalLock and AcpiReleaseGlobalLock.
 1.5 11-Apr-2008  jmcneill branches: 1.5.2; 1.5.4; 1.5.6;
Revert previous.
 1.4 11-Apr-2008  jmcneill Remove code erroneously copied from i386 ACPI_ACQUIRE_GLOBAL_LOCK.
 1.3 18-Feb-2008  scw branches: 1.3.6;
Re-sync the (broken) amd64 ACPI Global Lock macros with their i386
counterparts.

As discussed on port-amd64, these will be replaced by portable C code
in the near future.
 1.2 24-Dec-2005  perry branches: 1.2.24; 1.2.40; 1.2.50; 1.2.56;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.1 11-May-2003  fvdl branches: 1.1.18;
ACPI support. Wakeup code still to be done.
 1.1.18.2 27-Feb-2008  yamt sync with head.
 1.1.18.1 21-Jun-2006  yamt sync with head.
 1.2.56.1 18-Feb-2008  mjf Sync with HEAD.
 1.2.50.1 23-Mar-2008  matt sync with HEAD
 1.2.40.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.2.24.1 22-Feb-2008  bouyer Pull up following revision(s) (requested by scw in ticket #1077):
sys/arch/amd64/include/acpi_func.h: revision 1.3
Re-sync the (broken) amd64 ACPI Global Lock macros with their i386
counterparts.
 1.3.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.5.6.2 23-Jun-2008  wrstuden Remove files removed on branch. Updating using patch has its
drawbacks. :-)
 1.5.6.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.5.4.1 04-May-2009  yamt sync with head.
 1.5.2.1 04-Jun-2008  yamt sync with head
 1.1 11-May-2003  fvdl ACPI support. Wakeup code still to be done.
 1.11 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.10 17-Jul-2011  joerg branches: 1.10.54;
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.9 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.8 11-Jan-2009  christos branches: 1.8.2; 1.8.4; 1.8.6;
merge christos-time_t
 1.7 26-Oct-2008  mrg branches: 1.7.2;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.6 17-Oct-2007  garbled branches: 1.6.16; 1.6.18; 1.6.22; 1.6.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.5 03-Sep-2007  drochner clean up some definitions around rune_t which are not needed anymore
 1.4 04-Oct-2006  tnozaki branches: 1.4.8; 1.4.16; 1.4.22; 1.4.26; 1.4.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.3 11-Dec-2005  christos branches: 1.3.20; 1.3.22;
merge ktrace-lwp.
 1.2 07-Aug-2003  agc branches: 1.2.16;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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.2.16.2 27-Oct-2007  yamt sync with head.
 1.2.16.1 30-Dec-2006  yamt sync with head.
 1.3.22.1 22-Oct-2006  yamt sync with head
 1.3.20.1 18-Nov-2006  ad Sync with head.
 1.4.28.1 06-Nov-2007  matt sync with HEAD
 1.4.26.1 02-Oct-2007  joerg Sync with HEAD.
 1.4.22.1 10-Sep-2007  skrll Sync with HEAD.
 1.4.16.1 03-Oct-2007  garbled Sync with HEAD
 1.4.8.1 09-Oct-2007  ad Sync with head.
 1.6.28.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.6.22.2 11-Aug-2010  yamt sync with head.
 1.6.22.1 04-May-2009  yamt sync with head.
 1.6.18.5 04-Jan-2009  christos oops, missed ptrdiff_t.
 1.6.18.4 04-Jan-2009  christos revert clock_t and size_t changes.
 1.6.18.3 01-Nov-2008  christos Sync with head.
 1.6.18.2 30-Mar-2008  christos time_t is now __int64_t
 1.6.18.1 29-Mar-2008  christos Welcome to the time_t=long long dev_t=uint64_t branch.
 1.6.16.1 17-Jan-2009  mjf Sync with HEAD.
 1.7.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.8.6.1 30-May-2010  rmind sync with head
 1.8.4.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.8.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.8.2.1 24-Oct-2010  jym Sync with HEAD
 1.10.54.1 10-Jun-2019  christos Sync with HEAD
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.12 13-Sep-2022  riastradh amd64/asan.h, amd64/msan.h: Add include guards.
 1.11 22-Aug-2022  hannken Sprinkle "#include <machine/pmap_private.h>", kernel ALL/amd64
compiles again.
 1.10 20-Aug-2022  riastradh x86: Split bootspace out of x86/pmap.h into new x86/bootspace.h.
 1.9 10-Sep-2020  maxv kasan: fix the copyright notices
 1.8 05-Sep-2020  riastradh Round of uvm.h cleanup.

The poorly named uvm.h is generally supposed to be for uvm-internal
users only.

- Narrow it to files that actually need it -- mostly files that need
to query whether curlwp is the pagedaemon, which should maybe be
exposed by an external header.

- Use uvm_extern.h where feasible and uvm_*.h for things not exposed
by it. We should split up uvm_extern.h but this will serve for now
to reduce the uvm.h dependencies.

- Use uvm_stat.h and #ifdef UVMHIST uvm.h for files that use
UVMHIST(ubchist), since ubchist is declared in uvm.h but the
reference evaporates if UVMHIST is not defined, so we reduce header
file dependencies.

- Make uvm_device.h and uvm_swap.h independently includable while
here.

ok chs@
 1.7 23-Jun-2020  maxv Rename __MD_CANONICAL_BASE -> __MD_KERNMEM_BASE for clarity.
 1.6 02-May-2020  maxv Call kasan_early_init earlier, to unbreak KASAN after the recent RNG
changes. Will also prevent further trouble.
 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 15-Apr-2020  maxv Use large pages for the kASan shadow, same as kMSan.
 1.3 09-Mar-2019  maxv branches: 1.3.4; 1.3.12;
Start replacing the x86 PTE bits.
 1.2 04-Feb-2019  maxv Add more symbols to the unwinder, in case we get a KASAN message inside
an exception handler.
 1.1 31-Oct-2018  maxv branches: 1.1.2;
Move the MI parts of KASAN into kern/subr_asan.c. This file includes
machine/asan.h, which contains the MD functions. We use an include rather
than a plain C file, because we want GCC to optimize/inline some functions
into one single block.

The amd64 MD parts of KASAN are moved accordingly.

The naming convention we use is:

kasan_*
a generic kasan object, declared in subr_asan.c
kasan_md_*
an MD kasan object, declared in machine/asan.h, and used
in subr_asan.c
__md_*
an MD object, declared in machine/asan.h, and not used
outside

Overall this makes it easier to add KASAN support on more architectures.

Discussed with several people.
 1.1.2.2 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.1.2.1 31-Oct-2018  pgoyette file asan.h was added on branch pgoyette-compat on 2018-11-26 01:52:17 +0000
 1.3.12.1 20-Apr-2020  bouyer Sync with HEAD
 1.3.4.3 21-Apr-2020  martin Sync with HEAD
 1.3.4.2 10-Jun-2019  christos Sync with HEAD
 1.3.4.1 09-Mar-2019  christos file asan.h was added on branch phil-wifi on 2019-06-10 22:05:47 +0000
 1.24 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.23 09-Jun-2024  riastradh branches: 1.23.2;
amd64/asm.h: Respect _NETBSD_REVISIONID.
 1.22 17-Apr-2021  rillig sys/arch/amd64: remove trailing whitespace
 1.21 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.20 17-Apr-2020  joerg Mark the .ident section as mergable string section to avoid redundant
entries.
 1.19 22-May-2014  uebayasi branches: 1.19.28; 1.19.38;
Indent.
 1.18 12-Sep-2013  joerg branches: 1.18.2;
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.17 22-Jun-2013  uebayasi branches: 1.17.2;
Define IDTVEC_END(), from i386/asm.h.
 1.16 21-Jun-2013  uebayasi Add END(y) as i386/asm.h does.
 1.15 11-Jun-2012  chs branches: 1.15.2;
make dtrace work on amd64.
 1.14 20-Dec-2010  joerg branches: 1.14.8; 1.14.14;
Consistently use .gnu.warning with .pushsectio and .popsection on all
architectures instead of obsolete STABS frames for linker warnings.
 1.13 26-Oct-2008  mrg branches: 1.13.8; 1.13.16;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.12 01-Oct-2008  joerg Make RCSID() use section .ident like the C version and i386's asm does.
OK ad@
 1.11 20-Dec-2007  ad branches: 1.11.6; 1.11.10; 1.11.12; 1.11.16;
- 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.10 29-Nov-2007  ad branches: 1.10.2; 1.10.6;
Drop text alignment back to 16 - the usual size of blocks the instruction
decoder works with.
 1.9 17-Oct-2007  garbled branches: 1.9.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.8 29-Aug-2007  ad 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.7 09-Feb-2007  ad branches: 1.7.6; 1.7.14; 1.7.18; 1.7.22; 1.7.24;
Merge newlock2 to head.
 1.6 05-Sep-2006  ad branches: 1.6.2;
Add an SPLLOWER() macro.
 1.5 20-Jan-2006  christos branches: 1.5.2; 1.5.6;
Add a STRONG_ALIAS macro
 1.4 11-Dec-2005  christos branches: 1.4.2;
merge ktrace-lwp.
 1.3 07-Aug-2003  agc branches: 1.3.16;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.2 02-May-2003  yamt branches: 1.2.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.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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.3.16.6 21-Jan-2008  yamt sync with head
 1.3.16.5 07-Dec-2007  yamt sync with head
 1.3.16.4 03-Sep-2007  yamt sync with head.
 1.3.16.3 26-Feb-2007  yamt sync with head.
 1.3.16.2 30-Dec-2006  yamt sync with head.
 1.3.16.1 21-Jun-2006  yamt sync with head.
 1.4.2.1 01-Feb-2006  yamt sync with head.
 1.5.6.1 14-Sep-2006  yamt sync with head.
 1.5.2.1 09-Sep-2006  rpaulo sync with head
 1.6.2.3 06-Feb-2007  ad Remove now unused SPLLOWER() macro.
 1.6.2.2 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.6.2.1 29-Dec-2006  ad Checkpoint work in progress.
 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.2 03-Dec-2007  joerg Sync with HEAD.
 1.7.22.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.7.18.1 03-Sep-2007  skrll Sync with HEAD.
 1.7.14.1 03-Oct-2007  garbled Sync with HEAD
 1.7.6.2 03-Dec-2007  ad Sync with HEAD.
 1.7.6.1 09-Oct-2007  ad Sync with head.
 1.9.2.2 27-Dec-2007  mjf Sync with HEAD.
 1.9.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.10.6.1 02-Jan-2008  bouyer Sync with HEAD
 1.10.2.1 26-Dec-2007  ad Sync with head.
 1.11.16.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.11.16.1 19-Oct-2008  haad Sync with HEAD.
 1.11.12.1 10-Oct-2008  skrll Sync with HEAD.
 1.11.10.1 04-May-2009  yamt sync with head.
 1.11.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.11.6.1 05-Oct-2008  mjf Sync with HEAD.
 1.13.16.1 05-Mar-2011  rmind sync with head
 1.13.8.1 10-Jan-2011  jym Sync with HEAD
 1.14.14.1 22-Nov-2012  riz Pull up following revision(s) (requested by chs in ticket #690):
external/cddl/osnet/dev/dtrace/amd64/dtrace_isa.c: revision 1.4
sys/arch/amd64/include/Makefile.inc: revision 1.4
sys/arch/amd64/include/pmap.h: revision 1.33
external/cddl/osnet/dev/dtrace/amd64/dtrace_subr.c: revision 1.6
sys/arch/amd64/include/asm.h: revision 1.15
sys/arch/amd64/amd64/genassym.cf: revision 1.51
external/cddl/osnet/dev/dtrace/amd64/dtrace_asm.S: revision 1.4
make dtrace work on amd64.
allow more space for modules.
 1.14.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.14.8.1 30-Oct-2012  yamt sync with head
 1.15.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.15.2.1 23-Jun-2013  tls resync from head
 1.17.2.1 18-May-2014  rmind sync with head
 1.18.2.1 10-Aug-2014  tls Rebase.
 1.19.38.1 20-Apr-2020  bouyer Sync with HEAD
 1.19.28.1 21-Apr-2020  martin Sync with HEAD
 1.23.2.1 02-Aug-2025  perseant Sync with HEAD
 1.10 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.9 17-Oct-2007  garbled branches: 1.9.2; 1.9.4; 1.9.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.8 03-Oct-2007  ad Fix the ifdefs to match i386.
 1.7 03-Oct-2007  ad Make the atomics inline unless !__GNUC__.
 1.6 29-Aug-2007  ad branches: 1.6.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.5 09-Feb-2007  ad branches: 1.5.6; 1.5.12; 1.5.14; 1.5.18; 1.5.22; 1.5.24;
Merge newlock2 to head.
 1.4 28-Dec-2005  perry branches: 1.4.20;
inline -> __inline
 1.3 24-Dec-2005  perry __asm__ -> __asm
__const__ -> const
__inline__ -> inline
__volatile__ -> volatile
 1.2 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.1 26-Apr-2003  fvdl branches: 1.1.18;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.18.5 21-Jan-2008  yamt sync with head
 1.1.18.4 27-Oct-2007  yamt sync with head.
 1.1.18.3 03-Sep-2007  yamt sync with head.
 1.1.18.2 26-Feb-2007  yamt sync with head.
 1.1.18.1 21-Jun-2006  yamt sync with head.
 1.4.20.1 29-Dec-2006  ad Checkpoint work in progress.
 1.5.24.2 23-Mar-2008  matt sync with HEAD
 1.5.24.1 06-Nov-2007  matt sync with HEAD
 1.5.22.2 04-Oct-2007  joerg Sync with HEAD.
 1.5.22.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.5.18.1 03-Sep-2007  skrll Sync with HEAD.
 1.5.14.2 16-Oct-2007  garbled Sync with HEAD
 1.5.14.1 03-Oct-2007  garbled Sync with HEAD
 1.5.12.1 18-Apr-2007  thorpej Convert i386 and amd64 to the new atomic ops API.
 1.5.6.2 09-Oct-2007  ad Sync with head.
 1.5.6.1 23-Aug-2007  ad Fix x86_atomic_setbits_u64, which was cheerfully setting every bit except
the one specified!
 1.6.2.1 06-Oct-2007  yamt sync with head.
 1.9.8.1 02-Jan-2008  bouyer Sync with HEAD
 1.9.4.1 26-Dec-2007  ad Sync with head.
 1.9.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.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.3 26-Oct-2008  mrg put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.2 31-Jan-2006  dsl branches: 1.2.72; 1.2.76; 1.2.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.1 26-Apr-2003  fvdl branches: 1.1.18; 1.1.30;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.30.1 01-Feb-2006  yamt sync with head.
 1.1.18.1 21-Jun-2006  yamt sync with head.
 1.2.82.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.2.76.1 04-May-2009  yamt sync with head.
 1.2.72.1 17-Jan-2009  mjf Sync with HEAD.
 1.2 17-Jul-2011  dyoung On amd64, good-bye <machine/bus.h>.

Up next: update set lists.
 1.1 26-Apr-2003  fvdl branches: 1.1.122;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.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:51:35 +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:00 +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.8 17-Apr-2021  rillig sys/arch/amd64: remove trailing whitespace
 1.7 14-Jan-2010  joerg Provide inline assembly version of bswap64.
 1.6 26-Oct-2008  mrg branches: 1.6.4; 1.6.8; 1.6.12;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.5 28-Apr-2008  martin branches: 1.5.6;
Remove clause 3 and 4 from TNF licenses
 1.4 30-Jan-2006  dsl branches: 1.4.72; 1.4.74; 1.4.76;
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.3 28-Dec-2005  perry branches: 1.3.2;
inline -> __inline
 1.2 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.1 26-Apr-2003  fvdl branches: 1.1.18;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.18.1 21-Jun-2006  yamt sync with head.
 1.3.2.1 01-Feb-2006  yamt sync with head.
 1.4.76.3 11-Mar-2010  yamt sync with head
 1.4.76.2 04-May-2009  yamt sync with head.
 1.4.76.1 16-May-2008  yamt sync with head.
 1.4.74.1 18-May-2008  yamt sync with head.
 1.4.72.2 17-Jan-2009  mjf Sync with HEAD.
 1.4.72.1 02-Jun-2008  mjf Sync with HEAD.
 1.5.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.6.12.1 21-Apr-2010  matt sync to netbsd-5
 1.6.8.1 24-Oct-2010  jym Sync with HEAD
 1.6.4.1 16-Jan-2010  bouyer Pull up following revision(s) (requested by joerg in ticket #1245):
sys/arch/amd64/include/byte_swap.h: revision 1.7
Provide inline assembly version of bswap64.
 1.3 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.2 26-Oct-2008  mrg branches: 1.2.28; 1.2.32;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.1 26-Apr-2003  fvdl branches: 1.1.104; 1.1.108; 1.1.114;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.114.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.1.108.1 04-May-2009  yamt sync with head.
 1.1.104.1 17-Jan-2009  mjf Sync with HEAD.
 1.2.32.1 18-Feb-2012  mrg merge to -current.
 1.2.28.1 17-Apr-2012  yamt sync with head
 1.72 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.71 09-Apr-2023  riastradh amd64: 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 %gs is set
correctly, which must be the case here -- there's no need for the
volatile qualifier, so nix it.
 1.70 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.69 17-Apr-2021  rillig sys/arch/amd64: remove trailing whitespace
 1.68 17-Mar-2020  maxv Add a redzone between the pcb and the stack. Sent to port-amd64@.
 1.67 08-Dec-2019  maxv Use the inlines; it is actually fine, since the compiler drops the inlines
if the caller is kmsan-instrumented, forcing a white-listing of the memory
access.
 1.66 21-Nov-2019  ad mi_userret(): take care of calling preempt(), set spc_curpriority directly,
and remove MD code that does the same.
 1.65 14-Nov-2019  maxv Add support for Kernel Memory Sanitizer (kMSan). It detects uninitialized
memory used by the kernel at run time, and just like kASan and kCSan, it
is an excellent feature. It has already detected 38 uninitialized variables
in the kernel during my testing, which I have since discreetly fixed.

We use two shadows:
- "shad", to track uninitialized memory with a bit granularity (1:1).
Each bit set to 1 in the shad corresponds to one uninitialized bit of
real kernel memory.
- "orig", to track the origin of the memory with a 4-byte granularity
(1:1). Each uint32_t cell in the orig indicates the origin of the
associated uint32_t of real kernel memory.

The memory consumption of these shadows is consequent, so at least 4GB of
RAM is recommended to run kMSan.

The compiler inserts calls to specific __msan_* functions on each memory
access, to manage both the shad and the orig and detect uninitialized
memory accesses that change the execution flow (like an "if" on an
uninitialized variable).

We mark as uninit several types of memory buffers (stack, pools, kmem,
malloc, uvm_km), and check each buffer passed to copyout, copyoutstr,
bwrite, if_transmit_lock and DMA operations, to detect uninitialized memory
that leaves the system. This allows us to detect kernel info leaks in a way
that is more efficient and also more user-friendly than KLEAK.

Contrary to kASan, kMSan requires comprehensive coverage, ie we cannot
tolerate having one non-instrumented function, because this could cause
false positives. kMSan cannot instrument ASM functions, so I converted
most of them to __asm__ inlines, which kMSan is able to instrument. Those
that remain receive special treatment.

Contrary to kASan again, kMSan uses a TLS, so we must context-switch this
TLS during interrupts. We use different contexts depending on the interrupt
level.

The orig tracks precisely the origin of a buffer. We use a special encoding
for the orig values, and pack together in each uint32_t cell of the orig:
- a code designating the type of memory (Stack, Pool, etc), and
- a compressed pointer, which points either (1) to a string containing
the name of the variable associated with the cell, or (2) to an area
in the kernel .text section which we resolve to a symbol name + offset.

This encoding allows us not to consume extra memory for associating
information with each cell, and produces a precise output, that can tell
for example the name of an uninitialized variable on the stack, the
function in which it was pushed on the stack, and the function where we
accessed this uninitialized variable.

kMSan is available with LLVM, but not with GCC.

The code is organized in a way that is similar to kASan and kCSan, so it
means that other architectures than amd64 can be supported.
 1.64 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.63 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.62 16-Mar-2018  maxv branches: 1.62.2;
Remove the prototypes for cpu_uarea_*, I removed these functions two
minutes ago.
 1.61 17-Sep-2017  maxv branches: 1.61.2;
Remove the second argument from USERMODE and KERNELMODE, it is unused
now that we don't have vm86 anymore.
 1.60 21-Jan-2012  chs branches: 1.60.6; 1.60.40;
allocate uareas contiguously and access them via the direct map.
 1.59 30-Dec-2008  pooka branches: 1.59.14; 1.59.18;
_LKM -> _MODULE
 1.58 26-Oct-2008  mrg branches: 1.58.2;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.57 22-May-2008  ad branches: 1.57.4;
Mark x86_curlwp() with __attribute__ ((const)), so gcc can CSE it and know
that it does not clobber global data.
 1.56 11-May-2008  ad Wrap stuff in #ifdef _KERNEL
 1.55 11-May-2008  ad Share cpu.h between the x86 ports.
 1.54 11-May-2008  ad Simplify x86 identcpu code, and share between i386/amd64.
 1.53 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.52 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.51 30-Apr-2008  ad branches: 1.51.2;
Avoid unneeded AST faults.
 1.50 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.49 24-Apr-2008  ad branches: 1.49.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.48 23-Apr-2008  he Ensure that offsetof() is in scope by including <sys/systm.h>.
Fixes build problem found while building swapnetbsd.o for XEN3_DOM0.
 1.47 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.46 16-Apr-2008  cegger branches: 1.46.2;
use POSIX integer types
 1.45 27-Feb-2008  xtraeme Remove CTL_MACHDEP_NAMES, it's not used anywhere.

Ok by martin@.
 1.44 22-Jan-2008  joerg branches: 1.44.2; 1.44.6;
GC i8254_microtime.
 1.43 05-Jan-2008  yamt remove no longer necessary cpu_maxproc.
 1.42 05-Jan-2008  yamt - make amd64 use per-cpu tss.
- fix iopl syscall for amd64+xen.
 1.41 05-Jan-2008  yamt g/c unused members
 1.40 05-Jan-2008  yamt g/c ci_idle_pcb_paddr
 1.39 01-Jan-2008  yamt try to detect processor resource sharing topologies. ie. package/core/smt IDs.
 1.38 25-Dec-2007  perry Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.37 22-Dec-2007  dsl Define 'struct intrframe' in terms of 'struct trapframe' since the two are
assumed to match by a lot of code (including that which saves the regs).
This only slightly reduces the number of places the trapframe register
layout is defined.
 1.36 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.35 09-Dec-2007  jmcneill branches: 1.35.2;
Merge jmcneill-pm branch.
 1.34 03-Dec-2007  joerg branches: 1.34.2;
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.33 22-Nov-2007  bouyer branches: 1.33.2;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.32 12-Nov-2007  ad - cpu_vendor was both an int and char[] on amd64 - fix it.
- Run the errata check/patch on all CPUs, not just the boot processor.
 1.31 29-Oct-2007  ad branches: 1.31.2;
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.30 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.29 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.28 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.27 26-Sep-2007  ad branches: 1.27.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.26 25-Sep-2007  ad ci_astpending is no more.
 1.25 29-Aug-2007  ad branches: 1.25.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.24 21-May-2007  fvdl branches: 1.24.4; 1.24.8; 1.24.10;
Revert fs/gs changes until I figure out issues with them.
 1.23 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.22 11-May-2007  fvdl Don't save/restore %fs and %gs in trapframe. The kernel won't touch them.
Instead, save/restore them on context switch. For 32bit processes, save/restore
the selector values only, for 64bit processes, save/restore the appropriate
MSRs. Iff the defaults have been changed.
 1.21 21-Mar-2007  xtraeme branches: 1.21.4;
- 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.20 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.19 16-Mar-2007  xtraeme struct cpu_info: add a ci_feature2_flags member.
identcpu: print extended cpuid features with ci_feature2_flags.

"Looks good" by christos and njoly.
 1.18 16-Mar-2007  xtraeme Remove __P(), remove k8_powernow_init proto... it was moved to
x86/include/powernow.h long time ago.
 1.17 12-Mar-2007  ad branches: 1.17.2; 1.17.4;
Include sys/simplelock.h, not sys/lock.h.
 1.16 05-Mar-2007  drochner branches: 1.16.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.15 04-Mar-2007  christos Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.14 16-Feb-2007  ad branches: 1.14.2;
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.13 09-Feb-2007  ad Merge newlock2 to head.
 1.12 06-Aug-2006  xtraeme branches: 1.12.4; 1.12.8; 1.12.10;
AMD PowerNow!/Cool`n'Quiet driver for NetBSD/amd64,
adapted from OpenBSD.

Tested on a few machines:

http://bigbird.dohd.org:3021/NetBSD/dmesg
http://www.bsd.org.il/netbsd/acpi/dmesg

Thanks to cube, elad and others for testing and fixes.

Enabled by default on GENERIC.
 1.11 07-Jun-2006  kardel convert to timecounters (from branch simonb-timecounters)
 1.10 06-Mar-2006  cube branches: 1.10.6;
delay() is gone, so don't declare it. That way other parts of code that
use a variable named delay (say, netinet6/in6.c) won't shadow something
that doesn't exist anyway.
 1.9 24-Dec-2005  perry branches: 1.9.4; 1.9.6; 1.9.8;
bare asm -> __asm
 1.8 11-Dec-2005  christos merge ktrace-lwp.
 1.7 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.6 25-Sep-2004  yamt branches: 1.6.12;
don't expose cpu_info and friends to userland.
 1.5 25-Sep-2004  yamt fix a typo in a comment.
 1.4 22-Sep-2004  yamt move some per-cpu data definitions to MI place so that they can be modified
without touching all ports. discussed on tech-kern@.
 1.3 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.2 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.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.2.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.2.5 19-Oct-2004  skrll Sync with HEAD
 1.1.2.4 24-Sep-2004  skrll Sync with HEAD.
 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.6.12.10 17-Mar-2008  yamt sync with head.
 1.6.12.9 04-Feb-2008  yamt sync with head.
 1.6.12.8 21-Jan-2008  yamt sync with head
 1.6.12.7 07-Dec-2007  yamt sync with head
 1.6.12.6 15-Nov-2007  yamt sync with head.
 1.6.12.5 27-Oct-2007  yamt sync with head.
 1.6.12.4 03-Sep-2007  yamt sync with head.
 1.6.12.3 26-Feb-2007  yamt sync with head.
 1.6.12.2 30-Dec-2006  yamt sync with head.
 1.6.12.1 21-Jun-2006  yamt sync with head.
 1.9.8.3 11-Aug-2006  yamt sync with head
 1.9.8.2 26-Jun-2006  yamt sync with head.
 1.9.8.1 13-Mar-2006  yamt sync with head.
 1.9.6.2 30-Apr-2006  kardel initrtclock now get the frequency as argument
 1.9.6.1 22-Apr-2006  simonb Sync with head.
 1.9.4.1 09-Sep-2006  rpaulo sync with head
 1.10.6.1 19-Jun-2006  chap Sync with head.
 1.12.10.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.12.8.1 05-Jun-2007  bouyer Pull up following revision(s) (requested by xtraeme in ticket 702):
sys/arch/amd64/amd64/identcpu.c patch
sys/arch/amd64/include/cpu.h patch
sys/arch/x86/include/cputypes.h 1.1
Print all extended features for Intel EM64T CPUs on amd64.
 1.12.4.4 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.12.4.3 11-Jan-2007  ad Checkpoint work in progress.
 1.12.4.2 17-Nov-2006  ad Checkpoint work in progress.
 1.12.4.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.14.2.8 17-May-2007  yamt sync with head.
 1.14.2.7 28-Mar-2007  skrll More merge botch fixes.
 1.14.2.6 28-Mar-2007  skrll Remove committed conflicts.
 1.14.2.5 24-Mar-2007  yamt sync with head.
 1.14.2.4 23-Mar-2007  skrll Remove switch_exit declaration.
 1.14.2.3 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.14.2.2 12-Mar-2007  rmind Sync with HEAD.
 1.14.2.1 03-Mar-2007  yamt adapt amd64.

XXX changes in identcpu.c is minmum for MONITOR.
XXX identcpu.c should be shared with i386.
 1.16.2.9 03-Dec-2007  ad Sync with HEAD.
 1.16.2.8 23-Oct-2007  ad Sync with head.
 1.16.2.7 09-Oct-2007  ad Sync with head.
 1.16.2.6 23-Aug-2007  ad Fix some more bugs.
 1.16.2.5 23-Aug-2007  ad Merged x86 cpu.c.
 1.16.2.4 21-Aug-2007  ad amd64 changes, as yet untested:

- Adapt to vmlocking branch.
- Apply TLB shootdown and pv allocation changes to the pmap.
- Make it build.
 1.16.2.3 27-May-2007  ad Sync with head.
 1.16.2.2 10-Apr-2007  ad Sync with head.
 1.16.2.1 13-Mar-2007  ad Sync with head.
 1.17.4.1 18-Mar-2007  reinoud First attempt to bring branch in sync with HEAD
 1.17.2.1 11-Jul-2007  mjf Sync with head.
 1.21.4.2 03-Oct-2007  garbled Sync with HEAD
 1.21.4.1 22-May-2007  matt Update to HEAD.
 1.24.10.3 23-Mar-2008  matt sync with HEAD
 1.24.10.2 09-Jan-2008  matt sync with HEAD
 1.24.10.1 06-Nov-2007  matt sync with HEAD
 1.24.8.9 09-Dec-2007  jmcneill Sync with HEAD.
 1.24.8.8 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.24.8.7 14-Nov-2007  joerg Sync with HEAD.
 1.24.8.6 29-Oct-2007  joerg Sync with HEAD.
 1.24.8.5 28-Oct-2007  joerg Sync with HEAD.
 1.24.8.4 28-Oct-2007  joerg Make the reset of FS/GS base in cpu_init_msrs optional. We don't want
that in the ACPI resume path.
 1.24.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.24.8.2 02-Oct-2007  joerg Sync with HEAD.
 1.24.8.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.24.4.1 03-Sep-2007  skrll Sync with HEAD.
 1.25.2.2 06-Oct-2007  yamt sync with head.
 1.25.2.1 30-Sep-2007  yamt implement deferred pmap switching for amd64, and make amd64 use
x86 shared pmap code. it makes several i386 pmap improvements available
to amd64, including tlb shootdown reduction and bug fixes from Stephan Uphoff.
 1.27.2.4 13-Nov-2007  bouyer catch up with changes in HEAD.
 1.27.2.3 13-Nov-2007  bouyer Sync with HEAD
 1.27.2.2 25-Oct-2007  bouyer Sync with HEAD.
 1.27.2.1 17-Oct-2007  bouyer amd64 (aka x86-64) support for Xen. Based on the OpenBSD port done by
Mathieu Ropert in 2006.
DomU-only for now. An INSTALL_XEN3_DOMU kernel with a ramdisk will boot to
sysinst if you're lucky. Often it panics because a runable LWP has
a NULL stack (really, it's all of l->l_addr which is has been zeroed out
while the process was on the queue !)
TODO:
- bug fixes :)
- Most of the xpq_* functions should be shared with xen/i386
- The xen/i386 assembly bootstrap code should be remplaced with the C
version in xenamd64/amd64/xpmap.c
- see if a config(5) trick could allow to merge xenamd64 back to xen or amd64.
 1.31.2.4 18-Feb-2008  mjf Sync with HEAD.
 1.31.2.3 27-Dec-2007  mjf Sync with HEAD.
 1.31.2.2 08-Dec-2007  mjf Sync with HEAD.
 1.31.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.33.2.2 26-Dec-2007  ad Sync with head.
 1.33.2.1 08-Dec-2007  ad Sync with head.
 1.34.2.1 11-Dec-2007  yamt sync with head.
 1.35.2.3 23-Jan-2008  bouyer Sync with HEAD.
 1.35.2.2 08-Jan-2008  bouyer Sync with HEAD
 1.35.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.44.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.44.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.44.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.44.2.1 24-Mar-2008  keiichi sync with head.
 1.46.2.2 04-Jun-2008  yamt sync with head
 1.46.2.1 18-May-2008  yamt sync with head.
 1.49.2.2 04-May-2009  yamt sync with head.
 1.49.2.1 16-May-2008  yamt sync with head.
 1.51.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.57.4.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.58.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.59.18.1 18-Feb-2012  mrg merge to -current.
 1.59.14.1 17-Apr-2012  yamt sync with head
 1.60.40.1 17-Mar-2018  martin Pull up the following revisions, requested by maxv in ticket #637:

sys/arch/amd64/amd64/process_machdep.c 1.33,1.34,1.35 (patch)
sys/arch/amd64/include/types.h 1.55 (patch)
sys/arch/x86/x86/vm_machdep.c 1.33 (patch)

- Reduce the number of places where segment register faults can
occur.
- Remove __HAVE_CPU_UAREA_ROUTINES.
 1.60.6.1 03-Dec-2017  jdolecek update from HEAD
 1.61.2.2 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.61.2.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.62.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.62.2.1 10-Jun-2019  christos Sync with HEAD
 1.7 10-May-2008  ad Merge cpu_counter.h.
 1.6 28-Apr-2008  martin branches: 1.6.2;
Remove clause 3 and 4 from TNF licenses
 1.5 17-Oct-2007  garbled branches: 1.5.16; 1.5.18; 1.5.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.4 07-Jul-2007  tsutsui branches: 1.4.10;
Move x86 common cpu_counter functions into <x86/cpu_counter.h>.
 1.3 16-Feb-2006  perry branches: 1.3.24; 1.3.26; 1.3.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.2 24-Dec-2005  perry branches: 1.2.2; 1.2.4; 1.2.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.1 26-Apr-2003  fvdl branches: 1.1.18;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.18.1 03-Sep-2007  yamt sync with head.
 1.2.6.1 22-Apr-2006  simonb Sync with head.
 1.2.4.1 09-Sep-2006  rpaulo sync with head
 1.2.2.1 18-Feb-2006  yamt sync with head.
 1.3.32.1 03-Oct-2007  garbled Sync with HEAD
 1.3.26.1 11-Jul-2007  mjf Sync with head.
 1.3.24.1 15-Jul-2007  ad Sync with head.
 1.4.10.1 06-Nov-2007  matt sync with HEAD
 1.5.20.1 16-May-2008  yamt sync with head.
 1.5.18.1 18-May-2008  yamt sync with head.
 1.5.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.6.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:35:47 +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:29:54 +0000
 1.20 30-Nov-2020  bouyer Introduce smap_enable()/smap_disable() functions, to be used from
C code.
 1.19 17-Oct-2007  garbled branches: 1.19.120;
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.18 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.17 21-May-2007  fvdl branches: 1.17.8; 1.17.10; 1.17.12;
Revert fs/gs changes until I figure out issues with them.
 1.16 11-May-2007  fvdl Don't save/restore %fs and %gs in trapframe. The kernel won't touch them.
Instead, save/restore them on context switch. For 32bit processes, save/restore
the selector values only, for 64bit processes, save/restore the appropriate
MSRs. Iff the defaults have been changed.
 1.15 04-Mar-2007  christos branches: 1.15.2; 1.15.4; 1.15.10;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.14 09-Feb-2007  ad branches: 1.14.2;
Merge newlock2 to head.
 1.13 14-Jan-2007  ad .. but only if _KERNEL is defined.
 1.12 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.11 12-Jan-2007  ad x86_pause(): do issue the 'pause' instruction, for EMT64 CPUs.
 1.10 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.9 26-Aug-2006  ad branches: 1.9.2;
Add x86_sfence(), x86_mfence().
 1.8 19-Aug-2006  dsl Fix the amd64 INSTALL kernel (builds of machdep.c with -Os and -O3).
Load the idt with non-randmon data.
 1.7 28-Dec-2005  perry branches: 1.7.4; 1.7.8; 1.7.18;
inline -> __inline
 1.6 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.5 11-Dec-2005  christos merge ktrace-lwp.
 1.4 14-Jan-2004  yamt branches: 1.4.14; 1.4.16;
issue memory read barrier for BUS_DMASYNC_POSTREAD operation.
PR/21665 from Stephan Uphoff.
 1.3 08-May-2003  fvdl branches: 1.3.2;
Move x86_pause() out of ifdef _KERNEL.
 1.2 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.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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.4.16.5 27-Oct-2007  yamt sync with head.
 1.4.16.4 03-Sep-2007  yamt sync with head.
 1.4.16.3 26-Feb-2007  yamt sync with head.
 1.4.16.2 30-Dec-2006  yamt sync with head.
 1.4.16.1 21-Jun-2006  yamt sync with head.
 1.4.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.7.18.1 27-Aug-2006  riz Pull up following revision(s) (requested by dsl in ticket #68):
sys/arch/amd64/include/cpufunc.h: revision 1.8
Fix the amd64 INSTALL kernel (builds of machdep.c with -Os and -O3).
Load the idt with non-randmon data.
 1.7.8.1 03-Sep-2006  yamt sync with head.
 1.7.4.1 09-Sep-2006  rpaulo sync with head
 1.9.2.4 01-Feb-2007  ad Sync with head.
 1.9.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.9.2.2 12-Jan-2007  ad Sync with head.
 1.9.2.1 29-Dec-2006  ad Checkpoint work in progress.
 1.14.2.2 17-May-2007  yamt sync with head.
 1.14.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.15.10.2 03-Oct-2007  garbled Sync with HEAD
 1.15.10.1 22-May-2007  matt Update to HEAD.
 1.15.4.1 11-Jul-2007  mjf Sync with head.
 1.15.2.1 09-Oct-2007  ad Sync with head.
 1.17.12.1 06-Oct-2007  yamt sync with head.
 1.17.10.1 06-Nov-2007  matt sync with HEAD
 1.17.8.1 02-Oct-2007  joerg Sync with HEAD.
 1.19.120.1 14-Dec-2020  thorpej Sync w/ HEAD.
 1.2 09-Feb-2007  ad branches: 1.2.4;
Merge newlock2 to head.
 1.1 12-Jan-2007  ad branches: 1.1.2;
file cputypes.h was initially added on branch newlock2.
 1.1.2.1 12-Jan-2007  ad Sync with head.
 1.2.4.2 26-Feb-2007  yamt sync with head.
 1.2.4.1 09-Feb-2007  yamt file cputypes.h was added on branch yamt-lazymbuf on 2007-02-26 09:05:43 +0000
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.5 04-Dec-2024  alnsn PTE_BASE is defined in <machine/pmap_private.h>.
 1.4 10-Sep-2020  maxv branches: 1.4.26;
kcsan: fix the copyright notices
 1.3 08-Nov-2019  maxv branches: 1.3.8;
Exclude the PTE space from KCSAN, since there the same VA can point to
different PAs.
 1.2 06-Nov-2019  maxv Change kcsan_md_is_avail() to always return true; I was testing with
interrupts disabled as debugging. Change the delay/sample parameters
to have better fluidity.
 1.1 05-Nov-2019  maxv Add Kernel Concurrency Sanitizer (kCSan) support. This sanitizer allows us
to detect race conditions at runtime. It is a variation of TSan that is
easy to implement and more suited to kernel internals, albeit theoretically
less precise than TSan's happens-before.

We do basically two things:

- On every KCSAN_NACCESSES (=2000) memory accesses, we create a cell
describing the access, and delay the calling CPU (10ms).

- On all memory accesses, we verify if the memory we're reading/writing
is referenced in a cell already.

The combination of the two means that, if for example cpu0 does a read that
is selected and cpu1 does a write at the same address, kCSan will fire,
because cpu1's write collides with cpu0's read cell.

The coverage of the instrumentation is the same as that of kASan. Also, the
code is organized in a way similar to kASan, so it is easy to add support
for more architectures than amd64. kCSan is compatible with KCOV.

Reviewed by Kamil.
 1.3.8.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.3.8.1 08-Nov-2019  martin file csan.h was added on branch phil-wifi on 2020-04-13 08:03:30 +0000
 1.4.26.1 02-Aug-2025  perseant Sync with HEAD
 1.17 17-Apr-2021  rillig sys/arch/amd64: remove trailing whitespace
 1.16 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.15 26-Jul-2015  mrg properly copy regs for kgdb, and define the number of registers properly.
from openbsd via Vicente Chaves and PR port-amd64/50091.
 1.14 17-Oct-2013  christos branches: 1.14.6;
add missing _
 1.13 17-Oct-2013  christos we need to return something here.
 1.12 17-Oct-2013  christos use the parameter for instruction macros
 1.11 26-May-2011  joerg branches: 1.11.4; 1.11.14; 1.11.18;
Introduce DDB_EXPR_FMT and replace the logic around DB_EXPR_T_IS_QUAD.
 1.10 10-Apr-2011  christos Merge db_trace for x86. From: Vladimir Kirillov proger at wilab dot org dot ua
 1.9 14-Mar-2009  dsl branches: 1.9.4; 1.9.6;
Remove all the __P() from sys (excluding sys/dist)
Diff checked with grep and MK1 eyeball.
i386 and amd64 GENERIC and sys still build.
 1.8 11-Mar-2009  yamt add a missing _KERNEL_OPT ifdef.
 1.7 26-Oct-2008  mrg branches: 1.7.2; 1.7.8;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.6 21-Feb-2007  thorpej branches: 1.6.42; 1.6.46; 1.6.52;
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.5 26-Jun-2006  christos branches: 1.5.10;
define PC_ADVANCE to avoid a LHS cast which makes gcc4 unhappy.
From Kurt Schreiner
 1.4 01-Apr-2006  cherry branches: 1.4.4;
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.3 23-Jun-2003  martin branches: 1.3.18; 1.3.32; 1.3.34; 1.3.36; 1.3.38; 1.3.40;
Make sure to include opt_foo.h if a defflag option FOO is used.
 1.2 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.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.3.40.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.3.38.1 19-Apr-2006  elad sync with head - hopefully this will work
 1.3.36.2 11-Aug-2006  yamt sync with head
 1.3.36.1 11-Apr-2006  yamt sync with head
 1.3.34.1 22-Apr-2006  simonb Sync with head.
 1.3.32.1 09-Sep-2006  rpaulo sync with head
 1.3.18.3 26-Feb-2007  yamt sync with head.
 1.3.18.2 30-Dec-2006  yamt sync with head.
 1.3.18.1 21-Jun-2006  yamt sync with head.
 1.4.4.1 13-Jul-2006  gdamore Merge from HEAD.
 1.5.10.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.6.52.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.6.46.1 04-May-2009  yamt sync with head.
 1.6.42.1 17-Jan-2009  mjf Sync with HEAD.
 1.7.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.7.8.3 02-May-2011  jym 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 28-Apr-2009  skrll Sync with HEAD.
 1.9.6.1 06-Jun-2011  jruoho Sync with HEAD.
 1.9.4.2 31-May-2011  rmind sync with head
 1.9.4.1 21-Apr-2011  rmind sync with head
 1.11.18.1 18-May-2014  rmind sync with head
 1.11.14.2 03-Dec-2017  jdolecek update from HEAD
 1.11.14.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.11.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.14.6.1 22-Sep-2015  skrll Sync with HEAD
 1.10 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.9 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.8 28-Oct-2008  mrg branches: 1.8.6;
if HAVE_NBTOOL_CONFIG_H is defined, also use the contents of this
file, not <i386/disklabel.h>.

XXX: the way tools/disklabel builds is gross.
 1.7 26-Oct-2008  mrg branches: 1.7.2;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.6 11-Dec-2005  christos branches: 1.6.74; 1.6.78; 1.6.84;
merge ktrace-lwp.
 1.5 12-Jun-2005  dyoung 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.4 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.3 04-Aug-2003  dsl mbr partition stuff isn't saved here (or anywhere else) anymore.
 1.2 10-May-2003  thorpej branches: 1.2.2;
Remove redundant bounds_check_with_label() prototype.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.2.2.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 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.84.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.6.78.2 11-Mar-2010  yamt sync with head
 1.6.78.1 04-May-2009  yamt sync with head.
 1.6.74.1 17-Jan-2009  mjf Sync with HEAD.
 1.7.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.8.6.1 24-Oct-2010  jym Sync with HEAD
 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.6 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.5 02-Feb-2016  christos Add more relocation constants
 1.4 18-Mar-2010  cegger branches: 1.4.18; 1.4.36;
buildfix: invert comparison to get the 64bit defines by default.
Fixes 'i386/elf_machdep.h: No such file or directory error' when compiling
amd64 toolchain on OSX.
 1.3 30-May-2009  skrll branches: 1.3.2; 1.3.4;
Add TLS relocation definitions.
 1.2 26-Oct-2008  mrg branches: 1.2.8;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.1 26-Apr-2003  fvdl branches: 1.1.104; 1.1.108; 1.1.114;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.114.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.1.108.3 11-Aug-2010  yamt sync with head.
 1.1.108.2 20-Jun-2009  yamt sync with head
 1.1.108.1 04-May-2009  yamt sync with head.
 1.1.104.1 17-Jan-2009  mjf Sync with HEAD.
 1.2.8.3 24-Oct-2010  jym Sync with HEAD
 1.2.8.2 01-Nov-2009  jym Sync with HEAD.
 1.2.8.1 31-May-2009  jym Sync with HEAD.
 1.3.4.1 30-May-2010  rmind sync with head
 1.3.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.4.36.1 19-Mar-2016  skrll Sync with HEAD
 1.4.18.1 03-Dec-2017  jdolecek update from HEAD
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.4 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.3 11-Dec-2005  christos branches: 1.3.2;
merge ktrace-lwp.
 1.2 10-Jun-2004  kleink branches: 1.2.12;
Reflect <sys/endian.h> rev. 1.4: make htonl() et al. arguments and
results uint{16,32}_t. Noted by Ian Zagorskih.
 1.1 26-Apr-2003  fvdl branches: 1.1.2; 1.1.4;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.4.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.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.2.12.1 21-Jun-2006  yamt sync with head.
 1.3.2.1 01-Feb-2006  yamt sync with head.
 1.3 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.2 11-Feb-2014  dsl Move sys/arch/amd64/amd64/fpu.c and sys/arch/amd64/include/fpu.h
into sys/arch/x86 in preparation for using the same code for i386.
 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:49:16 +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:47:52 +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:43:53 +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:51:34 +0000
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.14 18-Feb-2014  dsl It seems that firefox includes machine/fpu.h on amd64.
Add the file back so that the firwfox source doesn't have to depend
on the version of netbsd it is being compiled for.
(The i386 version doesn't play the same games in its SIGFPE handler.)
 1.13 11-Feb-2014  dsl Move sys/arch/amd64/amd64/fpu.c and sys/arch/amd64/include/fpu.h
into sys/arch/x86 in preparation for using the same code for i386.
 1.12 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.11 11-Dec-2013  dsl Remove the fields that were used to save the i387 fp state on interrupt.
They were written but never read.
Possibly they should be saved for 32 bit processes, but that might be a relic
from real i387 where the fpu was actully asynchronous.
 1.10 01-Dec-2013  christos revert fpu/pcu changes until we figure out what's wrong; they cause random
freezes
 1.9 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.8 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.7 31-Dec-2012  dsl branches: 1.7.2;
Move the two fields used to save some i387 state on the last fpu trap
into their own sub-structure of the pcb (from 'struct savefpu').
They only (seem) to be used in some code that generates core dumps
for 32bit processes (code that might be broken as well!).
'struct safefpu' is now identical to 'struct fxsave64'. One (or both)
needs extending to support AVX - might need to be dynamically sized.
Removed all the __aligned(16) except for the one in struct pcb itself.
Only the copy used for the fsave instruction need be aligned.
 1.6 15-Dec-2012  dsl Add the offsets and comments for the members of 'struct fxsave64.
Spilt the 'fx_unused2' field into its reserved and available halves.
The latter could be used by the kernel software (cpu won't read/write it).
Remove the __padded from 'struct fxsave64', everything is aligned.
Add a CTASSERT that the size is correct (512).
Remove the unused 'struct oldfsave'.
Everything still builds.
 1.5 16-Apr-2008  cegger branches: 1.5.38; 1.5.48;
use POSIX integer types
 1.4 15-Jan-2008  joerg branches: 1.4.6;
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.3 25-Dec-2007  perry Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.2 27-Nov-2007  christos branches: 1.2.2; 1.2.6;
Add aligned(16) in savefpu like the i386 port has. Suggested by Matthias
Drochner.
 1.1 26-Apr-2003  fvdl branches: 1.1.18; 1.1.60; 1.1.78; 1.1.80; 1.1.86;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.86.2 18-Feb-2008  mjf Sync with HEAD.
 1.1.86.1 08-Dec-2007  mjf Sync with HEAD.
 1.1.80.2 23-Mar-2008  matt sync with HEAD
 1.1.80.1 09-Jan-2008  matt sync with HEAD
 1.1.78.1 03-Dec-2007  joerg Sync with HEAD.
 1.1.60.1 03-Dec-2007  ad Sync with HEAD.
 1.1.18.2 21-Jan-2008  yamt sync with head
 1.1.18.1 07-Dec-2007  yamt sync with head
 1.2.6.2 19-Jan-2008  bouyer Sync with HEAD
 1.2.6.1 02-Jan-2008  bouyer Sync with HEAD
 1.2.2.1 26-Dec-2007  ad Sync with head.
 1.4.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.5.48.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.5.48.1 25-Feb-2013  tls resync with head
 1.5.38.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.5.38.1 23-Jan-2013  yamt sync with head
 1.7.2.1 18-May-2014  rmind sync with head
 1.23 27-Jun-2025  andvar Grammar and spelling fixes, mainly in comments. A few in documentation,
logging, test description, and SCSI ASC/ASCQ assignment descriptions.
 1.22 14-Feb-2019  cherry branches: 1.22.36;
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.21 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.20 19-Nov-2018  kre Fix editing screwup in previous... noted by Rin Okuyama (thanks!)
 1.19 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.18 14-Jun-2017  chs branches: 1.18.4; 1.18.6;
add an lwp_trapframe() interface to return an LWP's user trapframe.
needed by dtrace.
 1.17 20-Feb-2014  dsl branches: 1.17.6;
This doesn't need fpu.h, but should include ucontext.h
 1.16 11-Feb-2014  dsl Move sys/arch/amd64/amd64/fpu.c and sys/arch/amd64/include/fpu.h
into sys/arch/x86 in preparation for using the same code for i386.
 1.15 26-Oct-2008  mrg branches: 1.15.28; 1.15.38; 1.15.44;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.14 28-Apr-2008  martin branches: 1.14.6;
Remove clause 3 and 4 from TNF licenses
 1.13 04-Jan-2008  dsl branches: 1.13.6; 1.13.8; 1.13.10;
Change the way that the trap/intr/syscall frames and the __gregset_t[]
indexes are defined so that only a single list of the registers is used.
The code no longer relies on the two structures matching.
There should be no binary change.
 1.12 22-Dec-2007  dsl Define 'struct intrframe' in terms of 'struct trapframe' since the two are
assumed to match by a lot of code (including that which saves the regs).
This only slightly reduces the number of places the trapframe register
layout is defined.
 1.11 21-Dec-2007  dsl Create the trap/syscall frame space for all the registers in one go.
Use the tramp-frame offsets (TF_foo) for all references to the registers.
Sort the saving of the GP registers into the same order as the trap frame
because consequetive memory accesses are liekly to be faster.
 1.10 17-Oct-2007  garbled branches: 1.10.2; 1.10.4; 1.10.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.9 21-May-2007  skrll branches: 1.9.10;
Correct comment - it's cpu_switchto now.
 1.8 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.7 11-Dec-2005  christos branches: 1.7.26; 1.7.30; 1.7.32; 1.7.38;
merge ktrace-lwp.
 1.6 28-Mar-2004  drochner branches: 1.6.16;
We should ensure stack alignment _after_ subtracting sizeof(sigframe).
Should fix PR bin/24948 by Wolfgang S. Rupprecht.
(nuke getframe() completely because its interface doesn't support this,
and it it used at one place only anyway)
 1.5 25-Mar-2004  drochner only accept signal trampoline version 2, and remove "struct sigcontext"
 1.4 13-Oct-2003  fvdl Define all frame members as unsigned, to avoid any possibility of
sign extension on these values.
 1.3 06-Oct-2003  fvdl SIGINFO support.
Todo: 32bit compat support (COMPAT_NETBSD32 will not compile right now,
as it won't on other platforms).
 1.2 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.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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.6.16.2 21-Jan-2008  yamt sync with head
 1.6.16.1 03-Sep-2007  yamt sync with head.
 1.7.38.1 22-May-2007  matt Update to HEAD.
 1.7.32.1 11-Jul-2007  mjf Sync with head.
 1.7.30.1 27-May-2007  ad Sync with head.
 1.7.26.1 03-Mar-2007  yamt adapt amd64.

XXX changes in identcpu.c is minmum for MONITOR.
XXX identcpu.c should be shared with i386.
 1.9.10.2 09-Jan-2008  matt sync with HEAD
 1.9.10.1 06-Nov-2007  matt sync with HEAD
 1.10.8.2 08-Jan-2008  bouyer Sync with HEAD
 1.10.8.1 02-Jan-2008  bouyer Sync with HEAD
 1.10.4.1 26-Dec-2007  ad Sync with head.
 1.10.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.13.10.2 04-May-2009  yamt sync with head.
 1.13.10.1 16-May-2008  yamt sync with head.
 1.13.8.1 18-May-2008  yamt sync with head.
 1.13.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.13.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.14.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.15.44.1 18-May-2014  rmind sync with head
 1.15.38.2 03-Dec-2017  jdolecek update from HEAD
 1.15.38.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.15.28.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.17.6.1 28-Aug-2017  skrll Sync with HEAD
 1.18.6.1 10-Jun-2019  christos Sync with HEAD
 1.18.4.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.22.36.1 02-Aug-2025  perseant Sync with HEAD
 1.8 17-Apr-2021  rillig sys/arch/amd64: remove trailing whitespace
 1.7 26-Apr-2015  mrg remove any pathname for gdb's amd64nbsd-tdep.c, so it doesn't really
matter where it lives. PR#49859.
 1.6 26-Apr-2015  christos PR/49859: Kamil Rytarowski: Invalid path to amd64nbsd-tdep.c in a comment
 1.5 27-Nov-2014  uebayasi branches: 1.5.2;
Improve grep'ability..
 1.4 06-Feb-2008  dsl branches: 1.4.2; 1.4.56;
Update comment about 'struct reg' and __greg alignment, and clarify
the comment about the syscall/trap entry substituting %r10 for %rcx.
 1.3 05-Jan-2008  dsl branches: 1.3.2; 1.3.4; 1.3.6;
Reorder the amd64 trapframe (swap rcx/r10 and add 4 spare slots after r9).
This allows the syscall code to pass the syscall args directly from the
trapframe instead of copying them to a separate structure.
It is still possible that some lurking code still assumes that
'struct trapframe', 'struct mcontext' and 'struct reg' all have the
registers in the same order, but I've fixed enough of them to get gdb working.
 1.2 04-Jan-2008  dsl Repeat after me, don't edit files (even to update comments) between test
build and committing.
 1.1 04-Jan-2008  dsl Change the way that the trap/intr/syscall frames and the __gregset_t[]
indexes are defined so that only a single list of the registers is used.
The code no longer relies on the two structures matching.
There should be no binary change.
 1.3.6.3 11-Feb-2008  yamt sync with head.
 1.3.6.2 21-Jan-2008  yamt sync with head
 1.3.6.1 05-Jan-2008  yamt file frame_regs.h was added on branch yamt-lazymbuf on 2008-01-21 09:35:24 +0000
 1.3.4.3 23-Mar-2008  matt sync with HEAD
 1.3.4.2 09-Jan-2008  matt sync with HEAD
 1.3.4.1 05-Jan-2008  matt file frame_regs.h was added on branch matt-armv6 on 2008-01-09 01:44:53 +0000
 1.3.2.2 08-Jan-2008  bouyer Sync with HEAD
 1.3.2.1 05-Jan-2008  bouyer file frame_regs.h was added on branch bouyer-xeni386 on 2008-01-08 22:09:19 +0000
 1.4.56.1 03-Dec-2017  jdolecek update from HEAD
 1.4.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.4.2.1 06-Feb-2008  mjf file frame_regs.h was added on branch mjf-devfs on 2008-02-18 21:04:21 +0000
 1.5.2.1 06-Jun-2015  skrll Sync with HEAD
 1.55 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.54 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.53 17-Apr-2021  rillig sys/arch/amd64: remove trailing whitespace
 1.52 19-Jul-2020  maxv Revert most of ad's movs/stos change. Instead do a lot simpler: declare
svs_quad_copy() used by SVS only, with no need for instrumentation, because
SVS is disabled when sanitizers are on.
 1.51 21-Jun-2020  bouyer Fix comment
 1.50 01-Jun-2020  ad Reported-by: syzbot+6dd5a230d19f0cbc7814@syzkaller.appspotmail.com

Instrument STOS/MOVS for KMSAN to unbreak it.
 1.49 26-Apr-2020  maxv Use the hotpatch framework for LFENCE/MFENCE.
 1.48 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.47 17-Nov-2019  maxv branches: 1.47.6;
Disable KCOV - by raising the interrupt level - in the TLB IPI handler,
because this is only noise.
 1.46 14-Nov-2019  maxv Add support for Kernel Memory Sanitizer (kMSan). It detects uninitialized
memory used by the kernel at run time, and just like kASan and kCSan, it
is an excellent feature. It has already detected 38 uninitialized variables
in the kernel during my testing, which I have since discreetly fixed.

We use two shadows:
- "shad", to track uninitialized memory with a bit granularity (1:1).
Each bit set to 1 in the shad corresponds to one uninitialized bit of
real kernel memory.
- "orig", to track the origin of the memory with a 4-byte granularity
(1:1). Each uint32_t cell in the orig indicates the origin of the
associated uint32_t of real kernel memory.

The memory consumption of these shadows is consequent, so at least 4GB of
RAM is recommended to run kMSan.

The compiler inserts calls to specific __msan_* functions on each memory
access, to manage both the shad and the orig and detect uninitialized
memory accesses that change the execution flow (like an "if" on an
uninitialized variable).

We mark as uninit several types of memory buffers (stack, pools, kmem,
malloc, uvm_km), and check each buffer passed to copyout, copyoutstr,
bwrite, if_transmit_lock and DMA operations, to detect uninitialized memory
that leaves the system. This allows us to detect kernel info leaks in a way
that is more efficient and also more user-friendly than KLEAK.

Contrary to kASan, kMSan requires comprehensive coverage, ie we cannot
tolerate having one non-instrumented function, because this could cause
false positives. kMSan cannot instrument ASM functions, so I converted
most of them to __asm__ inlines, which kMSan is able to instrument. Those
that remain receive special treatment.

Contrary to kASan again, kMSan uses a TLS, so we must context-switch this
TLS during interrupts. We use different contexts depending on the interrupt
level.

The orig tracks precisely the origin of a buffer. We use a special encoding
for the orig values, and pack together in each uint32_t cell of the orig:
- a code designating the type of memory (Stack, Pool, etc), and
- a compressed pointer, which points either (1) to a string containing
the name of the variable associated with the cell, or (2) to an area
in the kernel .text section which we resolve to a symbol name + offset.

This encoding allows us not to consume extra memory for associating
information with each cell, and produces a precise output, that can tell
for example the name of an uninitialized variable on the stack, the
function in which it was pushed on the stack, and the function where we
accessed this uninitialized variable.

kMSan is available with LLVM, but not with GCC.

The code is organized in a way that is similar to kASan and kCSan, so it
means that other architectures than amd64 can be supported.
 1.45 12-Oct-2019  maxv 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.44 18-May-2019  maxv Two changes in the CPU mitigations:

* Micro-optimize: put every mitigation in the same branch. This removes
two branches in each exc/int return path, and removes all branches in
the syscall return path.

* Modify the SpectreV2 mitigation to be compatible with SpectreV4. I
recently realized that both couldn't be enabled at the same time on
Intel. This is because initially, when there was just SpectreV2, we
could reset the whole IA32_SPEC_CTRL MSR. But then Intel added another
bit in it for SpectreV4, so it isn't right to reset it entirely
anymore. SSBD needs to stay.
 1.43 14-May-2019  maxv Mitigation for INTEL-SA-00233: Microarchitectural Data Sampling (MDS).

It requires a microcode update, now available on the Intel website. The
microcode modifies the behavior of the VERW instruction, and makes it flush
internal CPU buffers. We hotpatch the return-to-userland path to add VERW.

Two sysctls are added:

machdep.mds.mitigated = {0/1} user-settable
machdep.mds.method = {string} constructed by the kernel

The kernel will automatically enable the mitigation if the updated
microcode is present. If the new microcode is not present, the user can
load it via cpuctl, and set machdep.mds.mitigated=1.
 1.42 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.41 12-Aug-2018  maxv Move the PCPU area from slot 384 to slot 510, to avoid creating too much
fragmentation in the slot space (384 is in the middle of the kernel half
of the VA).
 1.40 13-Jul-2018  martin Provide empty SVS_ENTER_NMI/SVS_LEAVE_NMI for kernels w/o options SVS
 1.39 12-Jul-2018  maxv Handle NMIs correctly when SVS is enabled. We store the kernel's CR3 at the
top of the NMI stack, and we unconditionally switch to it, because we don't
know with which page tables we received the NMI. Hotpatch the whole thing as
usual.

This restores the ability to use PMCs on Intel CPUs.
 1.38 28-Mar-2018  maxv branches: 1.38.2;
Add the IBRS mitigation for SpectreV2 on amd64.

Different operations are performed during context transitions:

user->kernel: IBRS <- 1
kernel->user: IBRS <- 0

And during context switches:

user->user: IBPB <- 0
kernel->user: IBPB <- 0
[user->kernel:IBPB <- 0 this one may not be needed]

We use two macros, IBRS_ENTER and IBRS_LEAVE, to set the IBRS bit. The
thing is hotpatched for better performance, like SVS.

The idea is that IBRS is a "privileged" bit, which is set to 1 in kernel
mode and 0 in user mode. To protect the branch predictor between user
processes (which are of the same privilege), we use the IBPB barrier.

The Intel manual also talks about (MWAIT/HLT)+HyperThreading, and says
that when using either of the two instructions IBRS must be disabled for
better performance on the core. I'm not totally sure about this part, so
I'm not adding it now.

IBRS is available only when the Intel microcode update is applied. The
mitigation must be enabled manually with machdep.spectreV2.mitigated.

Tested by msaitoh a week ago (but I adapted a few things since). Probably
more changes to come.
 1.37 25-Feb-2018  maxv branches: 1.37.2;
Remove INTRENTRY_L, it's not used anymore.
 1.36 22-Feb-2018  maxv Make the machdep.svs_enabled sysctl writable, and add the kernel code
needed to disable SVS at runtime.

We set 'svs_enabled' to false, and hotpatch the kernel entry/exit points
to eliminate the context switch code.

We need to make sure there is no remote CPU that is executing the code we
are hotpatching. So we use two barriers:

* After the first one each CPU is guaranteed to be executing in
svs_disable_cpu with interrupts disabled (this way it can't leave this
place).

* After the second one it is guaranteed that SVS is disabled, so we flush
the cache, enable interrupts and continue execution normally.

Between the two barriers, cpu0 will disable SVS (svs_enabled=false and
hotpatch), and each CPU will restore the generic syscall entry point.

Three notes:

* We should call svs_pgg_update(true) afterwards, to put back PG_G on
the kernel pages (for better performance). This will be done in another
commit.

* The fact that we disable interrupts does not prevent us from receiving
an NMI, and it would be problematic. So we need to add some code to
verify that PMCs are disabled before hotpatching. This will be done
in another commit.

* In svs_disable() we expect each CPU to be online. We need to add a
check to make sure they indeed are.

The sysctl allows only a 1->0 transition. There is no point in doing 0->1
transitions anyway, and it would be complicated to implement because we
need to re-synchronize the CPU user page tables with the current ones (we
lost track of them in the last 1->0 transition).
 1.35 22-Feb-2018  maxv Add a dynamic detection for SVS.

The SVS_* macros are now compiled as skip-noopt. When the system boots, if
the cpu is from Intel, they are hotpatched to their real content.
Typically:

jmp 1f
int3
int3
int3
... int3 ...
1:

gets hotpatched to:

movq SVS_UTLS+UTLS_KPDIRPA,%rax
movq %rax,%cr3
movq CPUVAR(KRSP0),%rsp

These two chunks of code being of the exact same size. We put int3 (0xCC)
to make sure we never execute there.

In the non-SVS (ie non-Intel) case, all it costs is one jump. Given that
the SVS_* macros are small, this jump will likely leave us in the same
icache line, so it's pretty fast.

The syscall entry point is special, because there we use a scratch uint64_t
not in curcpu but in the UTLS page, and it's difficult to hotpatch this
properly. So instead of hotpatching we declare the entry point as an ASM
macro, and define two functions: syscall and syscall_svs, the latter being
the one used in the SVS case.

While here 'syscall' is optimized not to contain an SVS_ENTER - this way
we don't even need to do a jump on the non-SVS case.

When adding pages in the user page tables, make sure we don't have PG_G,
now that it's dynamic.

A read-only sysctl is added, machdep.svs_enabled, that tells whether the
kernel uses SVS or not.

More changes to come, svs_init() is not very clean.
 1.34 27-Jan-2018  maxv Put the default %cs value in INTR_RECURSE_HWFRAME. Pushing an immediate
costs less than reading the %cs register and pushing its value. This
value is not allowed to be != GSEL(GCODE_SEL,SEL_KPL) in all cases.
 1.33 27-Jan-2018  maxv Declare and use INTR_RECURSE_ENTRY, an optimized version of INTRENTRY.
When processing deferred interrupts, we are always entering the new
handler in kernel mode, so there is no point performing the userland
checks.

Saves several instructions.
 1.32 27-Jan-2018  maxv Remove DO_DEFERRED_SWITCH and DO_DEFERRED_SWITCH_RETRY, unused.
 1.31 21-Jan-2018  maxv Unmap the kernel from userland in SVS, and leave only the needed
trampolines. As explained below, SVS should now completely mitigate
Meltdown on GENERIC kernels, even though it needs some more tweaking
for GENERIC_KASLR.

Until now the kernel entry points looked like:

FUNC(intr)
pushq $ERR
pushq $TRAPNO
INTRENTRY
... handle interrupt ...
INTRFASTEXIT
END(intr)

With this change they are split and become:

FUNC(handle)
... handle interrupt ...
INTRFASTEXIT
END(handle)

TEXT_USER_BEGIN
FUNC(intr)
pushq $ERR
pushq $TRAPNO
INTRENTRY
jmp handle
END(intr)
TEXT_USER_END

A new section is introduced, .text.user, that contains minimal kernel
entry/exit points. In order to choose what to put in this section, two
macros are introduced, TEXT_USER_BEGIN and TEXT_USER_END.

The section is mapped in userland with normal 4K pages.

In GENERIC, the section is 4K-page-aligned and embedded in .text, which
is mapped with large pages. That is to say, when an interrupt comes in,
the CPU has the user page tables loaded and executes the 'intr' functions
on 4K pages; after calling SVS_ENTER (in INTRENTRY) these 4K pages become
2MB large pages, and remain so when executing in kernel mode.

In GENERIC_KASLR, the section is 4K-page-aligned and independent from the
other kernel texts. The prekern just picks it up and maps it at a random
address.

In GENERIC, SVS should now completely mitigate Meltdown: what we put in
.text.user is not secret.

In GENERIC_KASLR, SVS would have to be improved a bit more: the
'jmp handle' instruction is actually secret, since it leaks the address
of the section we are jumping into. By exploiting Meltdown on Intel, this
theoretically allows a local user to reconstruct the address of the first
text section. But given that our KASLR produces several texts, and that
each section is not correlated with the others, the level of protection
KASLR provides is still good.
 1.30 20-Jan-2018  maxv Use .pushsection/.popsection, we will soon embed macros in several layers
of nested sections.
 1.29 18-Jan-2018  maxv Unmap the kernel heap from the user page tables (SVS).

This implementation is optimized and organized in such a way that we
don't need to copy the kernel stack to a safe place during user<->kernel
transitions. We create two VAs that point to the same physical page; one
will be mapped in userland and is offset in order to contain only the
trapframe, the other is mapped in the kernel and maps the entire stack.

Sent on tech-kern@ a week ago.
 1.28 11-Jan-2018  maxv Declare new SVS_* variants: SVS_ENTER_NOSTACK and SVS_LEAVE_NOSTACK. Use
SVS_ENTER_NOSTACK in the syscall entry point, and put it before the code
that touches curlwp. (curlwp is located in the direct map.)

Then, disable __HAVE_CPU_UAREA_ROUTINES (to be removed later). This moves
the kernel stack into pmap_kernel(), and not the direct map. That's a
change I've always wanted to make: because of the direct map we can't add
a redzone on the stack, and basically, a stack overflow can go very far
in memory without being detected (as far as erasing all of the system's
memory).

Finally, unmap the direct map from userland.
 1.27 07-Jan-2018  maxv Add a new option, SVS (for Separate Virtual Space), that unmaps kernel
pages when running in userland. For now, only the PTE area is unmapped.

Sent on tech-kern@.
 1.26 07-Jan-2018  maxv Switch x86_retpatch[] -> HOTPATCH().
 1.25 07-Jan-2018  maxv Switch x86_lockpatch[] -> HOTPATCH().
 1.24 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.23 17-Oct-2017  maxv Have the cpu clear PSL_D automatically when entering the kernel via a
syscall. Then, don't clear PSL_D and PSL_AC in the syscall entry point,
they are now both cleared by the cpu (faster). However they still need to
be manually cleared in the interrupt/trap entry points.
 1.22 17-Oct-2017  maxv Add support for SMAP on amd64.

PSL_AC is cleared from %rflags in each kernel entry point. In the copy
sections, a copy window is opened and the kernel can touch userland
pages. This window is closed when the kernel is done, either at the end
of the copy sections or in the fault-recover functions.

This implementation is not optimized yet, due to the fact that INTRENTRY
is a macro, and we can't hotpatch macros.

Sent on tech-kern@ a month or two ago, tested on a Kabylake.
 1.21 15-Sep-2017  maxv Declare INTRFASTEXIT as a function, so that there is only one iretq in the
kernel. Then, check %rip against the address of this iretq instead of
disassembling (%rip) - which could fault again, or point at some random
address which happens to contain the iretq opcode. The same is true for gs
below, but I'll fix that in another commit.
 1.20 15-Jul-2012  dsl branches: 1.20.2; 1.20.32;
Rename MDP_IRET to MDL_IRET since it is an lwp flag, not a proc one.
Add an MDL_COMPAT32 flag to the lwp's md_flags, set it for 32bit lwps
and use it to force 'return to user' with iret (as is done when
MDL_IRET is set).
Split the iret/sysret code paths much later.
Remove all the replicated code for 32bit system calls - which was only
needed so that iret was always used.
frameasm.h for XEN contains '#define swapgs', while XEN probable never
needs swapgs, this is likely to be confusing.
Add a SWAPGS which is a nop on XEN and swapgs otherwise.
(I've not yet checked all the swapgs in files that include frameasm.h)
Simple x86 programs still work.
Hijack 6.99.9 kernel bump (needed for compat32 modules)
 1.19 17-May-2012  dsl Let the user of INTRENTRY_L() place a label on the 'swapgs' used
when faulting from user space.
 1.18 07-May-2012  dsl Add a ';' that got deleted in a slight tidyup.
 1.17 07-May-2012  dsl Move all the XEN differences to a single conditional.
Merge the XEN/non-XEN versions of INTRFASTEXIT and
INTR_RECURSE_HWFRAME by using extra defines.
Split INTRENTRY so that code can insert extra instructions
inside user/kernel conditional.
 1.16 10-Aug-2011  cherry branches: 1.16.2; 1.16.6; 1.16.8;
Correct offset calculation for ci
 1.15 12-Jan-2011  joerg branches: 1.15.6;
Allow use of traditional CPP to be set on a per platform base in sys.mk.
Honour this for dependency processing in bsd.dep.mk. Switch i386 and
amd64 assembly to use ISO C90 preprocessor concat and drop the
-traditional-cpp on this platform.
 1.14 07-Jul-2010  chs add the guts of TLS support on amd64. based on joerg's patch,
reworked by me to support 32-bit processes as well.
we now keep %fs and %gs loaded with the user values
while in the kernel, which means we don't need to
reload them when returning to user mode.
 1.13 21-Nov-2008  ad branches: 1.13.4; 1.13.6; 1.13.8;
PR port-amd64/39991 modules/compat_linux: build fix
 1.12 21-Apr-2008  cegger branches: 1.12.2; 1.12.8; 1.12.10; 1.12.12; 1.12.14; 1.12.18;
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.11 29-Feb-2008  yamt branches: 1.11.2;
don't bother to check curlwp==NULL.
 1.10 21-Dec-2007  dsl branches: 1.10.2; 1.10.6;
Create the trap/syscall frame space for all the registers in one go.
Use the tramp-frame offsets (TF_foo) for all references to the registers.
Sort the saving of the GP registers into the same order as the trap frame
because consequetive memory accesses are liekly to be faster.
 1.9 21-Dec-2007  dsl Change the xen CLI() and STI() defines to only use one scratch register.
As well as saving an instruction, in one place it saves a push/pop pair.
 1.8 22-Nov-2007  bouyer branches: 1.8.2; 1.8.6;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.7 14-Nov-2007  ad Clear the direction flag on entry to the kernel.
 1.6 18-Oct-2007  yamt branches: 1.6.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.5 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.4 21-May-2007  fvdl branches: 1.4.8; 1.4.10; 1.4.12; 1.4.14;
Revert fs/gs changes until I figure out issues with them.
 1.3 11-May-2007  fvdl Don't save/restore %fs and %gs in trapframe. The kernel won't touch them.
Instead, save/restore them on context switch. For 32bit processes, save/restore
the selector values only, for 64bit processes, save/restore the appropriate
MSRs. Iff the defaults have been changed.
 1.2 09-Feb-2007  ad branches: 1.2.2; 1.2.6; 1.2.8; 1.2.14;
Merge newlock2 to head.
 1.1 26-Apr-2003  fvdl branches: 1.1.18; 1.1.48;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.48.1 20-Oct-2006  ad Make ASTs per-LWP.
 1.1.18.6 17-Mar-2008  yamt sync with head.
 1.1.18.5 21-Jan-2008  yamt sync with head
 1.1.18.4 07-Dec-2007  yamt sync with head
 1.1.18.3 15-Nov-2007  yamt sync with head.
 1.1.18.2 27-Oct-2007  yamt sync with head.
 1.1.18.1 26-Feb-2007  yamt sync with head.
 1.2.14.1 22-May-2007  matt Update to HEAD.
 1.2.8.1 11-Jul-2007  mjf Sync with head.
 1.2.6.3 03-Dec-2007  ad Sync with HEAD.
 1.2.6.2 03-Dec-2007  ad Sync with HEAD.
 1.2.6.1 23-Oct-2007  ad Sync with head.
 1.2.2.1 17-May-2007  yamt sync with head.
 1.4.14.4 18-Nov-2007  bouyer Sync with HEAD
 1.4.14.3 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.4.14.2 18-Oct-2007  bouyer Explicitely set the flag argument of HYPERVISOR_iret to 0.
 1.4.14.1 17-Oct-2007  bouyer amd64 (aka x86-64) support for Xen. Based on the OpenBSD port done by
Mathieu Ropert in 2006.
DomU-only for now. An INSTALL_XEN3_DOMU kernel with a ramdisk will boot to
sysinst if you're lucky. Often it panics because a runable LWP has
a NULL stack (really, it's all of l->l_addr which is has been zeroed out
while the process was on the queue !)
TODO:
- bug fixes :)
- Most of the xpq_* functions should be shared with xen/i386
- The xen/i386 assembly bootstrap code should be remplaced with the C
version in xenamd64/amd64/xpmap.c
- see if a config(5) trick could allow to merge xenamd64 back to xen or amd64.
 1.4.12.1 30-Sep-2007  yamt implement deferred pmap switching for amd64, and make amd64 use
x86 shared pmap code. it makes several i386 pmap improvements available
to amd64, including tlb shootdown reduction and bug fixes from Stephan Uphoff.
 1.4.10.3 23-Mar-2008  matt sync with HEAD
 1.4.10.2 09-Jan-2008  matt sync with HEAD
 1.4.10.1 06-Nov-2007  matt sync with HEAD
 1.4.8.3 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.4.8.2 14-Nov-2007  joerg Sync with HEAD.
 1.4.8.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.6.2.3 27-Dec-2007  mjf Sync with HEAD.
 1.6.2.2 08-Dec-2007  mjf Sync with HEAD.
 1.6.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.8.6.1 02-Jan-2008  bouyer Sync with HEAD
 1.8.2.1 26-Dec-2007  ad Sync with head.
 1.10.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.10.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.10.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.10.2.1 24-Mar-2008  keiichi sync with head.
 1.11.2.1 18-May-2008  yamt sync with head.
 1.12.18.1 12-Jun-2012  riz Pull up following revision(s) (requested by spz in ticket #1772):
sys/arch/amd64/amd64/trap.c: revision 1.71 via patch
sys/arch/amd64/amd64/vector.S: revision 1.41 via patch
sys/arch/amd64/include/frameasm.h: patch

Treat traps in kernel mode during the 'return to user' iret sequence
as user faults.
Based heavily in the i386 code with the correct opcode bytes inserted.
iret path tested, arranging for segment register errors is harder.
User %fs and %gs (32bit apps) are loaded much earlier and any errors
will generate kernel panics - there is probably code to try to stop
the invalid values being set.
If we get a fault setting the user %gs, or on a iret that is returning
to userspace, we must do a 'swapgs' to reload the kernel %gs_base.
Also save the %ds, %es, %fs, %gs selector values in the frame so
they can be restored if we finally return to user (probably after
an application SIGSEGV handler has fixed the error).
Without this any such fault leaves the kernel running with the wrong
%gs offset and it will most likely fault again early in trap().
Repeats until the stack tramples on something important.
iret change works, invalid %gs is a little harder to arrange.
 1.12.14.1 12-Jun-2012  riz Pull up following revision(s) (requested by spz in ticket #1772):
sys/arch/amd64/amd64/trap.c: revision 1.71 via patch
sys/arch/amd64/amd64/vector.S: revision 1.41 via patch
sys/arch/amd64/include/frameasm.h: patch

Treat traps in kernel mode during the 'return to user' iret sequence
as user faults.
Based heavily in the i386 code with the correct opcode bytes inserted.
iret path tested, arranging for segment register errors is harder.
User %fs and %gs (32bit apps) are loaded much earlier and any errors
will generate kernel panics - there is probably code to try to stop
the invalid values being set.
If we get a fault setting the user %gs, or on a iret that is returning
to userspace, we must do a 'swapgs' to reload the kernel %gs_base.
Also save the %ds, %es, %fs, %gs selector values in the frame so
they can be restored if we finally return to user (probably after
an application SIGSEGV handler has fixed the error).
Without this any such fault leaves the kernel running with the wrong
%gs offset and it will most likely fault again early in trap().
Repeats until the stack tramples on something important.
iret change works, invalid %gs is a little harder to arrange.
 1.12.12.1 12-Jun-2012  riz Pull up following revision(s) (requested by spz in ticket #1772):
sys/arch/amd64/amd64/trap.c: revision 1.71 via patch
sys/arch/amd64/amd64/vector.S: revision 1.41 via patch
sys/arch/amd64/include/frameasm.h: patch

Treat traps in kernel mode during the 'return to user' iret sequence
as user faults.
Based heavily in the i386 code with the correct opcode bytes inserted.
iret path tested, arranging for segment register errors is harder.
User %fs and %gs (32bit apps) are loaded much earlier and any errors
will generate kernel panics - there is probably code to try to stop
the invalid values being set.
If we get a fault setting the user %gs, or on a iret that is returning
to userspace, we must do a 'swapgs' to reload the kernel %gs_base.
Also save the %ds, %es, %fs, %gs selector values in the frame so
they can be restored if we finally return to user (probably after
an application SIGSEGV handler has fixed the error).
Without this any such fault leaves the kernel running with the wrong
%gs offset and it will most likely fault again early in trap().
Repeats until the stack tramples on something important.
iret change works, invalid %gs is a little harder to arrange.
 1.12.10.1 19-Jan-2009  skrll Sync with HEAD.
 1.12.8.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.12.2.2 11-Aug-2010  yamt sync with head.
 1.12.2.1 04-May-2009  yamt sync with head.
 1.13.8.1 05-Mar-2011  rmind sync with head
 1.13.6.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.13.4.3 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.13.4.2 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.13.4.1 24-Oct-2010  jym Sync with HEAD
 1.15.6.1 03-Jun-2011  cherry Initial import of xen MP sources, with kernel and userspace tests.
- this is a source priview.
- boots to single user.
- spurious interrupt and pmap related panics are normal
 1.16.8.1 03-Jun-2012  jdc Pull up revisions:
src/sys/arch/amd64/include/frameasm.h revision 1.17-1.19
src/sys/arch/amd64/amd64/vector.S revision 1.40-1.41
src/sys/arch/amd64/amd64/trap.c revision 1.71
(requested by dsl in ticket #280).

Move all the XEN differences to a single conditional.
Merge the XEN/non-XEN versions of INTRFASTEXIT and
INTR_RECURSE_HWFRAME by using extra defines.
Split INTRENTRY so that code can insert extra instructions
inside user/kernel conditional.

Add a ';' that got deleted in a slight tidyup.

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

Let the user of INTRENTRY_L() place a label on the 'swapgs' used
when faulting from user space.

If we get a fault setting the user %gs, or on a iret that is returning
to userspace, we must do a 'swapgs' to reload the kernel %gs_base.
Also save the %ds, %es, %fs, %gs selector values in the frame so
they can be restored if we finally return to user (probably after
an application SIGSEGV handler has fixed the error).
Without this any such fault leaves the kernel running with the wrong
%gs offset and it will most likely fault again early in trap().
Repeats until the stack tramples on something important.
iret change works, invalid %gs is a little harder to arrange.

Treat traps in kernel mode during the 'return to user' iret sequence
as user faults.
Based heavily in the i386 code with the correct opcode bytes inserted.
iret path tested, arranging for segment register errors is harder.
User %fs and %gs (32bit apps) are loaded much earlier and any errors
will generate kernel panics - there is probably code to try to stop
the invalid values being set.
 1.16.6.1 02-Jun-2012  mrg sync to latest -current.
 1.16.2.2 30-Oct-2012  yamt sync with head
 1.16.2.1 23-May-2012  yamt sync with head.
 1.20.32.4 14-May-2019  martin Pull up following revision(s) (requested by maxv in ticket #1269):

sys/arch/amd64/amd64/locore.S: revision 1.181 (adapted)
sys/arch/amd64/amd64/amd64_trap.S: revision 1.47 (adapted)
sys/arch/x86/include/specialreg.h: revision 1.144 (adapted)
sys/arch/amd64/include/frameasm.h: revision 1.43 (adapted)
sys/arch/x86/x86/spectre.c: revision 1.27 (adapted)

Mitigation for INTEL-SA-00233: Microarchitectural Data Sampling (MDS).
It requires a microcode update, now available on the Intel website. The
microcode modifies the behavior of the VERW instruction, and makes it flush
internal CPU buffers. We hotpatch the return-to-userland path to add VERW.

Two sysctls are added:

machdep.mds.mitigated = {0/1} user-settable
machdep.mds.method = {string} constructed by the kernel

The kernel will automatically enable the mitigation if the updated
microcode is present. If the new microcode is not present, the user can
load it via cpuctl, and set machdep.mds.mitigated=1.
 1.20.32.3 14-Apr-2018  martin Pullup the following revisions via patch, requested by maxv in ticket #748:

sys/arch/amd64/amd64/copy.S 1.29 (adapted, via patch)
sys/arch/amd64/amd64/amd64_trap.S 1.16,1.19 (partial) (via patch)
sys/arch/amd64/amd64/trap.c 1.102,1.106 (partial),1.110 (via patch)
sys/arch/amd64/include/frameasm.h 1.22,1.24 (via patch)
sys/arch/x86/x86/cpu.c 1.137 (via patch)
sys/arch/x86/x86/patch.c 1.23,1.26 (partial) (via patch)

Backport of SMAP support.
 1.20.32.2 22-Mar-2018  martin Pull up the following revisions, requested by maxv in ticket #652:

sys/arch/amd64/amd64/amd64_trap.S upto 1.39 (partial, patch)
sys/arch/amd64/amd64/db_machdep.c 1.6 (patch)
sys/arch/amd64/amd64/genassym.cf 1.65,1.66,1.67 (patch)
sys/arch/amd64/amd64/locore.S upto 1.159 (partial, patch)
sys/arch/amd64/amd64/machdep.c 1.299-1.302 (patch)
sys/arch/amd64/amd64/trap.c upto 1.113 (partial, patch)
sys/arch/amd64/amd64/amd64/vector.S upto 1.61 (partial, patch)
sys/arch/amd64/conf/GENERIC 1.477,1.478 (patch)
sys/arch/amd64/conf/kern.ldscript 1.26 (patch)
sys/arch/amd64/include/frameasm.h upto 1.37 (partial, patch)
sys/arch/amd64/include/param.h 1.25 (patch)
sys/arch/amd64/include/pmap.h 1.41,1.43,1.44 (patch)
sys/arch/x86/conf/files.x86 1.91,1.93 (patch)
sys/arch/x86/include/cpu.h 1.88,1.89 (patch)
sys/arch/x86/include/pmap.h 1.75 (patch)
sys/arch/x86/x86/cpu.c 1.144,1.146,1.148,1.149 (patch)
sys/arch/x86/x86/pmap.c upto 1.289 (partial, patch)
sys/arch/x86/x86/vm_machdep.c 1.31,1.32 (patch)
sys/arch/x86/x86/x86_machdep.c 1.104,1.106,1.108 (patch)
sys/arch/x86/x86/svs.c 1.1-1.14
sys/arch/xen/conf/files.compat 1.30 (patch)

Backport SVS. Not enabled yet.
 1.20.32.1 07-Mar-2018  martin Pull up the following revisions (via patch), requested by maxv in ticket #610:

sys/arch/amd64/amd64/amd64_trap.S 1.8,1.10,1.12 (partial),1.13-1.15,
1.19 (partial),1.20,1.21,1.22,1.24
(via patch)
sys/arch/amd64/amd64/locore.S 1.129 (partial),1.132 (via patch)
sys/arch/amd64/amd64/trap.c 1.97 (partial),1.111 (via patch)
sys/arch/amd64/amd64/vector.S 1.54,1.55 (via patch)
sys/arch/amd64/include/frameasm.h 1.21,1.23 (via patch)
sys/arch/x86/x86/cpu.c 1.138 (via patch)
sys/arch/xen/conf/Makefile.xen 1.45 (via patch)

Rename and reorder several things in amd64_trap.S.
Compile amd64_trap.S as a file.
Introduce nmitrap and doubletrap.
Have the CPU clear PSL_D automatically in the syscall entry point.
 1.20.2.1 03-Dec-2017  jdolecek update from HEAD
 1.37.2.3 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.37.2.2 28-Jul-2018  pgoyette Sync with HEAD
 1.37.2.1 30-Mar-2018  pgoyette Resolve conflicts between branch and HEAD
 1.38.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.38.2.1 10-Jun-2019  christos Sync with HEAD
 1.47.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.14 30-Apr-2021  christos Merge the x86 gdt function and constant definitions
 1.13 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.12 25-Apr-2020  bouyer branches: 1.12.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.11 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.10 08-Feb-2017  maxv branches: 1.10.24;
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.9 08-Feb-2017  maxv Localify, add a comment and merge some others.
 1.8 20-Aug-2016  maxv branches: 1.8.2;
Make this area compile, even if we don't support USER_LDT on amd64.
 1.7 07-Jul-2010  chs branches: 1.7.18; 1.7.36; 1.7.40;
add the guts of TLS support on amd64. based on joerg's patch,
reworked by me to support 32-bit processes as well.
we now keep %fs and %gs loaded with the user values
while in the kernel, which means we don't need to
reload them when returning to user mode.
 1.6 14-Mar-2009  dsl branches: 1.6.2; 1.6.4;
Remove all the __P() from sys (excluding sys/dist)
Diff checked with grep and MK1 eyeball.
i386 and amd64 GENERIC and sys still build.
 1.5 28-Apr-2008  martin branches: 1.5.8; 1.5.14;
Remove clause 3 and 4 from TNF licenses
 1.4 05-Jan-2008  yamt branches: 1.4.6; 1.4.8; 1.4.10;
- make amd64 use per-cpu tss.
- fix iopl syscall for amd64+xen.
 1.3 11-Dec-2005  christos branches: 1.3.50; 1.3.56; 1.3.64;
merge ktrace-lwp.
 1.2 16-Jun-2004  fvdl branches: 1.2.12;
When converting GDT length units from segment structures to bytes for the
amd64 port, I converted MINGDTSIZ wrongly; it was not page aligned, causing
gdt_grow to corrupt the GDT. Fix this, and remove the extraneous definitions
of the sizes from gdt.c.

From OpenBSD.
 1.1 26-Apr-2003  fvdl branches: 1.1.2; 1.1.4;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.4.1 17-Jun-2004  tron Pull up revision 1.2 (requested by fvdl in ticket #506):
When converting GDT length units from segment structures to bytes for the
amd64 port, I converted MINGDTSIZ wrongly; it was not page aligned, causing
gdt_grow to corrupt the GDT. Fix this, and remove the extraneous definitions
of the sizes from gdt.c.
From OpenBSD.
 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.2.12.1 21-Jan-2008  yamt sync with head
 1.3.64.1 08-Jan-2008  bouyer Sync with HEAD
 1.3.56.1 18-Feb-2008  mjf Sync with HEAD.
 1.3.50.1 09-Jan-2008  matt sync with HEAD
 1.4.10.3 11-Aug-2010  yamt sync with head.
 1.4.10.2 04-May-2009  yamt sync with head.
 1.4.10.1 16-May-2008  yamt sync with head.
 1.4.8.1 18-May-2008  yamt sync with head.
 1.4.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.5.14.3 24-Oct-2010  jym Sync with HEAD
 1.5.14.2 01-Nov-2009  jym Sync with HEAD.
 1.5.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.5.8.1 28-Apr-2009  skrll Sync with HEAD.
 1.6.4.1 05-Mar-2011  rmind sync with head
 1.6.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.7.40.1 20-Mar-2017  pgoyette Sync with HEAD
 1.7.36.2 28-Aug-2017  skrll Sync with HEAD
 1.7.36.1 05-Oct-2016  skrll Sync with HEAD
 1.7.18.1 03-Dec-2017  jdolecek update from HEAD
 1.8.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.10.24.1 25-Apr-2020  bouyer Sync with bouyer-xenpvh-base2 (HEAD)
 1.12.6.1 13-May-2021  thorpej Sync with HEAD.
 1.10 17-Apr-2021  rillig sys/arch/amd64: remove trailing whitespace
 1.9 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.8 23-May-2017  nonaka branches: 1.8.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.7 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.6 11-Aug-2016  maxv Use absolute addressing mode, just like the rest.
 1.5 03-Jul-2008  drochner branches: 1.5.40; 1.5.58; 1.5.60; 1.5.62; 1.5.64; 1.5.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.4 27-Apr-2008  skd branches: 1.4.2; 1.4.4;
Fix pic locking to mirror simple_lock primitives.
 1.3 11-May-2003  fvdl branches: 1.3.104; 1.3.106; 1.3.108;
Reselect the ioapic register for each read or write.
 1.2 04-May-2003  fvdl Follow i386, and mask deferred level-triggered interrupts at the ioapic.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.3.108.2 04-May-2009  yamt sync with head.
 1.3.108.1 16-May-2008  yamt sync with head.
 1.3.106.1 18-May-2008  yamt sync with head.
 1.3.104.2 28-Sep-2008  mjf Sync with HEAD.
 1.3.104.1 02-Jun-2008  mjf Sync with HEAD.
 1.4.4.1 03-Jul-2008  simonb Sync with head.
 1.4.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.5.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.5.64.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.5.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.5.60.3 28-Aug-2017  skrll Sync with HEAD
 1.5.60.2 05-Dec-2016  skrll Sync with HEAD
 1.5.60.1 05-Oct-2016  skrll Sync with HEAD
 1.5.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.5.40.1 03-Dec-2017  jdolecek update from HEAD
 1.8.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.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.5 25-Jul-2014  joerg Add generic versions of machine/int_*.h for compilers providing
appropiate macros for all necessary types.
 1.4 29-May-2010  tnozaki branches: 1.4.18; 1.4.32;
fix wrong integer promotion rule(removed U suffix from UINT{8,16}_C).
see ISO/IEC 9899:1999 7.18.4.3.
 1.3 26-Oct-2008  mrg branches: 1.3.8; 1.3.14; 1.3.16;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.2 28-Apr-2008  martin branches: 1.2.6;
Remove clause 3 and 4 from TNF licenses
 1.1 26-Apr-2003  fvdl branches: 1.1.104; 1.1.106; 1.1.108;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.108.3 11-Aug-2010  yamt sync with head.
 1.1.108.2 04-May-2009  yamt sync with head.
 1.1.108.1 16-May-2008  yamt sync with head.
 1.1.106.1 18-May-2008  yamt sync with head.
 1.1.104.2 17-Jan-2009  mjf Sync with HEAD.
 1.1.104.1 02-Jun-2008  mjf Sync with HEAD.
 1.2.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.3.16.1 30-May-2010  rmind sync with head
 1.3.14.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.3.8.1 24-Oct-2010  jym Sync with HEAD
 1.4.32.1 10-Aug-2014  tls Rebase.
 1.4.18.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.7 25-Jul-2014  joerg Add generic versions of machine/int_*.h for compilers providing
appropiate macros for all necessary types.
 1.6 26-Oct-2008  mrg branches: 1.6.38; 1.6.54;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.5 28-Apr-2008  martin branches: 1.5.6;
Remove clause 3 and 4 from TNF licenses
 1.4 11-Dec-2005  christos branches: 1.4.74; 1.4.76; 1.4.78;
merge ktrace-lwp.
 1.3 23-May-2004  kleink Change {u,}int_fast{8,16}_t to 32-bit types.

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, which will be the first release for amd64). 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 31-Aug-2003  fvdl branches: 1.2.2;
Update a few types and formats.
 1.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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.2.2.1 25-May-2004  jmc Pullup rev 1.3 (requested by kleink in ticket #380)

Change {u,}int_fast{8,16}_t to 32-bit types.
 1.4.78.2 04-May-2009  yamt sync with head.
 1.4.78.1 16-May-2008  yamt sync with head.
 1.4.76.1 18-May-2008  yamt sync with head.
 1.4.74.2 17-Jan-2009  mjf Sync with HEAD.
 1.4.74.1 02-Jun-2008  mjf Sync with HEAD.
 1.5.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.6.54.1 10-Aug-2014  tls Rebase.
 1.6.38.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.10 17-Apr-2021  rillig sys/arch/amd64: remove trailing whitespace
 1.9 25-Jul-2014  joerg Add generic versions of machine/int_*.h for compilers providing
appropiate macros for all necessary types.
 1.8 27-Jan-2012  christos branches: 1.8.6; 1.8.20;
PR/45878: Nick Hudson: SIG_ATOMIC_{MAX,MIN} wrong for sig_atomic_t on amd64
sig_atomic_t is an int on amd64, put the proper limits there
 1.7 26-Oct-2008  mrg branches: 1.7.28; 1.7.32;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.6 28-Apr-2008  martin branches: 1.6.6;
Remove clause 3 and 4 from TNF licenses
 1.5 17-Oct-2007  garbled branches: 1.5.16; 1.5.18; 1.5.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.4 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.3 11-Dec-2005  christos branches: 1.3.30; 1.3.38; 1.3.44; 1.3.48; 1.3.50;
merge ktrace-lwp.
 1.2 08-May-2004  kleink branches: 1.2.12;
Factor out W{CHAR,INT}_{MAX,MIN} into their own header file.
 1.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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.2.12.1 03-Sep-2007  yamt sync with head.
 1.3.50.1 06-Nov-2007  matt sync with HEAD
 1.3.48.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.3.44.1 03-Sep-2007  skrll Sync with HEAD.
 1.3.38.1 03-Oct-2007  garbled Sync with HEAD
 1.3.30.1 09-Oct-2007  ad Sync with head.
 1.5.20.2 04-May-2009  yamt sync with head.
 1.5.20.1 16-May-2008  yamt sync with head.
 1.5.18.1 18-May-2008  yamt sync with head.
 1.5.16.2 17-Jan-2009  mjf Sync with HEAD.
 1.5.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.6.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.7.32.1 18-Feb-2012  mrg merge to -current.
 1.7.28.1 17-Apr-2012  yamt sync with head
 1.8.20.1 10-Aug-2014  tls Rebase.
 1.8.6.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.8 25-Jul-2014  joerg Add generic versions of machine/int_*.h for compilers providing
appropiate macros for all necessary types.
 1.7 26-Oct-2008  mrg branches: 1.7.38; 1.7.54;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.6 28-Apr-2008  martin branches: 1.6.6;
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 11-Dec-2005  christos merge ktrace-lwp.
 1.3 23-May-2004  kleink branches: 1.3.12;
Change {u,}int_fast{8,16}_t to 32-bit types.

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, which will be the first release for amd64). 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 31-Aug-2003  fvdl branches: 1.2.2;
Update a few types and formats.
 1.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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.2.2.1 25-May-2004  jmc Pullup rev 1.3 (requested by kleink in ticket #380)

Change {u,}int_fast{8,16}_t to 32-bit types.
 1.3.12.1 21-Jun-2006  yamt sync with head.
 1.5.78.2 04-May-2009  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.2 17-Jan-2009  mjf Sync with HEAD.
 1.5.74.1 02-Jun-2008  mjf Sync with HEAD.
 1.6.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.7.54.1 10-Aug-2014  tls Rebase.
 1.7.38.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.7 25-Jul-2014  joerg Add generic versions of machine/int_*.h for compilers providing
appropiate macros for all necessary types.
 1.6 26-Oct-2008  mrg branches: 1.6.38; 1.6.54;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.5 24-Dec-2005  perry branches: 1.5.74; 1.5.78; 1.5.84;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.4 11-Dec-2005  christos merge ktrace-lwp.
 1.3 25-May-2005  kleink branches: 1.3.2;
Include <sys/cdefs.h> for __signed; related to lib/30072.
 1.2 07-Aug-2003  agc branches: 1.2.6; 1.2.14;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.2.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 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.2.14.1 28-May-2005  tron Pull up revision 1.3 (requested by klein in ticket #346):
Include <sys/cdefs.h> for __signed; related to lib/30072.
 1.2.6.1 29-May-2005  riz Pull up revision 1.3 (requested by kleink in ticket #1555):
Include <sys/cdefs.h> for __signed; related to lib/30072.
 1.3.2.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.54.1 10-Aug-2014  tls Rebase.
 1.6.38.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.4 30-Apr-2020  bouyer Don't #include xen/intrdefs.h is !XEN.
Should fix third-party module builds (e.g. virtualbox)
 1.3 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.2 10-Aug-2011  cherry branches: 1.2.64;
Include Xen specific definitions.
 1.1 26-Apr-2003  fvdl branches: 1.1.122; 1.1.140;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.140.1 03-Jun-2011  cherry Initial import of xen MP sources, with kernel and userspace tests.
- this is a source priview.
- boots to single user.
- spurious interrupt and pmap related panics are normal
 1.1.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.2.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.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.2 11-Dec-2005  christos merge ktrace-lwp.
 1.1 02-Jul-2004  drochner branches: 1.1.2; 1.1.4;
add a <machine/joystick.h> which just includes the new common one
 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 02-Jul-2004  skrll file joystick.h was added on branch ktrace-lwp on 2004-08-03 10:31:36 +0000
 1.1.2.2 05-Jul-2004  he Pull up revision 1.1 (new, via patch, requested by drochner in ticket #605):
Add a <machine/joystick.h> which here is just a copy
of the i386 one.
 1.1.2.1 02-Jul-2004  he file joystick.h was added on branch netbsd-2-0 on 2004-07-05 22:12:16 +0000
 1.3 25-Jun-2013  joerg Fix header guards.
 1.2 16-Apr-2008  cegger branches: 1.2.38; 1.2.48;
use POSIX integer types
 1.1 26-Apr-2003  fvdl branches: 1.1.104;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.104.1 02-Jun-2008  mjf Sync with HEAD.
 1.2.48.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.38.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.2 08-Feb-2020  maxv Retire KLEAK.

KLEAK was a nice feature and served its purpose; it allowed us to detect
dozens of info leaks on the kernel->userland boundary, and thanks to it we
tackled a good part of the infoleak problem 1.5 years ago.

Nowadays however, we have kMSan, which can detect uninitialized memory in
the kernel. kMSan supersedes KLEAK: it can detect what KLEAK was able to
detect, but in addition, (1) it operates in all of the kernel and not just
the kernel->userland boundary, (2) it requires no user interaction, and (3)
it is deterministic and not statistical.

That makes kMSan the feature of choice to detect info leaks nowadays;
people interested in detecting info leaks should boot a kMSan kernel and
just wait for the magic to happen.

KLEAK was a good ride, and a fun project, but now is time for it to go.

Discussed with several people, including Thomas Barabosch.
 1.1 02-Dec-2018  maxv branches: 1.1.2; 1.1.6; 1.1.10;
Introduce KLEAK, a new feature that can detect kernel information leaks.

It works by tainting memory sources with marker values, letting the data
travel through the kernel, and scanning the kernel<->user frontier for
these marker values. Combined with compiler instrumentation and rotation
of the markers, it is able to yield relevant results with little effort.

We taint the pools and the stack, and scan copyout/copyoutstr. KLEAK is
supported on amd64 only for now, but it is not complicated to add more
architectures (just a matter of having the address of .text, and a stack
unwinder).

A userland tool is provided, that allows to execute a command in rounds
and monitor the leaks generated all the while.

KLEAK already detected directly 12 kernel info leaks, and prompted changes
that in total fixed 25+ leaks.

Based on an idea developed jointly with Thomas Barabosch (of Fraunhofer
FKIE).
 1.1.10.1 29-Feb-2020  ad Sync with head.
 1.1.6.3 08-Apr-2020  martin Merge changes from current as of 20200406
 1.1.6.2 10-Jun-2019  christos Sync with HEAD
 1.1.6.1 02-Dec-2018  christos file kleak.h was added on branch phil-wifi on 2019-06-10 22:05:47 +0000
 1.1.2.2 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.1.2.1 02-Dec-2018  pgoyette file kleak.h was added on branch pgoyette-compat on 2018-12-26 14:01:31 +0000
 1.15 21-Jan-2019  dholland Fix wrong scoping of {U,}LLONG_MAX.
PR 53298 from Roberto E. Vargas Caballero.
 1.14 21-Apr-2014  matt branches: 1.14.26; 1.14.28;
Since all our compilers support __DBL_* and __FLT_*, use them to define
{DBL,FLT}_{DIG,MIN,MAX}
 1.13 11-Apr-2013  christos branches: 1.13.4; 1.13.8;
add missing SSIZE_MIN
 1.12 28-Mar-2012  christos branches: 1.12.2;
- Normalize inclusion protection (remove)
- Move CHAR_{MIN,MAX} to a common file.
- Fix broken comments
 1.11 07-Jun-2010  tnozaki branches: 1.11.8; 1.11.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.10 26-Oct-2008  mrg branches: 1.10.8; 1.10.14; 1.10.16;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.9 17-Oct-2007  garbled branches: 1.9.16; 1.9.20; 1.9.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.8 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.7 11-Dec-2005  christos branches: 1.7.30; 1.7.38; 1.7.44; 1.7.48; 1.7.50;
merge ktrace-lwp.
 1.6 19-Sep-2003  fvdl branches: 1.6.16;
LONG_BIT should be 64. From Nicolas Joly.
 1.5 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.4 25-May-2003  fvdl branches: 1.4.2;
Correct a few maximum values.
 1.3 28-Apr-2003  bjh21 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.2 27-Apr-2003  fvdl Fix *LONGMAX values.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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.16.1 03-Sep-2007  yamt sync with head.
 1.7.50.1 06-Nov-2007  matt sync with HEAD
 1.7.48.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.7.44.1 03-Sep-2007  skrll Sync with HEAD.
 1.7.38.1 03-Oct-2007  garbled Sync with HEAD
 1.7.30.1 09-Oct-2007  ad Sync with head.
 1.9.26.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.9.20.2 11-Aug-2010  yamt sync with head.
 1.9.20.1 04-May-2009  yamt sync with head.
 1.9.16.1 17-Jan-2009  mjf Sync with HEAD.
 1.10.16.1 03-Jul-2010  rmind sync with head
 1.10.14.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.10.8.1 24-Oct-2010  jym Sync with HEAD
 1.11.12.1 05-Apr-2012  mrg sync to latest -current.
 1.11.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.11.8.1 17-Apr-2012  yamt sync with head
 1.12.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.12.2.1 23-Jun-2013  tls resync from head
 1.13.8.1 10-Aug-2014  tls Rebase.
 1.13.4.1 18-May-2014  rmind sync with head
 1.14.28.1 10-Jun-2019  christos Sync with HEAD
 1.14.26.1 26-Jan-2019  pgoyette Sync with HEAD
 1.3 18-Nov-2013  chs implement the *at() syscalls.
bring the unimplemented syscall list up to date.
 1.2 18-Nov-2011  christos branches: 1.2.10; 1.2.14;
include the new siginfo.h file
 1.1 09-Feb-2006  manu branches: 1.1.2; 1.1.10; 1.1.16; 1.1.22; 1.1.114;
Add initial (but unfinished) COMPAT_LINUX32 for amd64. This is good enough so
that the i386 license manager part of amd64 version of Fluent works.

While I'm here, add SysV IPC to COMPAT_LINUX/amd64
 1.1.114.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.1.114.1 17-Apr-2012  yamt sync with head
 1.1.22.2 09-Sep-2006  rpaulo sync with head
 1.1.22.1 09-Feb-2006  rpaulo file linux32_machdep.h was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:37:18 +0000
 1.1.16.2 21-Jun-2006  yamt sync with head.
 1.1.16.1 09-Feb-2006  yamt file linux32_machdep.h was added on branch yamt-lazymbuf on 2006-06-21 14:48:25 +0000
 1.1.10.2 22-Apr-2006  simonb Sync with head.
 1.1.10.1 09-Feb-2006  simonb file linux32_machdep.h was added on branch simonb-timecounters on 2006-04-22 11:37:12 +0000
 1.1.2.2 18-Feb-2006  yamt sync with head.
 1.1.2.1 09-Feb-2006  yamt file linux32_machdep.h was added on branch yamt-uio_vmspace on 2006-02-18 15:38:31 +0000
 1.2.14.1 18-May-2014  rmind sync with head
 1.2.10.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.4 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.3 01-Oct-2007  ad Now that the bootblocks are the same, share loadfile_machdep.h between
amd64 and i386.
 1.2 25-Jan-2006  christos branches: 1.2.28; 1.2.36; 1.2.46; 1.2.48; 1.2.50;
free -> dealloc
unsigned -> size_t for alloc/dealloc
 1.1 26-Apr-2003  fvdl branches: 1.1.18; 1.1.30;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.30.1 01-Feb-2006  yamt sync with head.
 1.1.18.2 27-Oct-2007  yamt sync with head.
 1.1.18.1 21-Jun-2006  yamt sync with head.
 1.2.50.1 06-Oct-2007  yamt sync with head.
 1.2.48.1 06-Nov-2007  matt sync with HEAD
 1.2.46.1 02-Oct-2007  joerg Sync with HEAD.
 1.2.36.1 03-Oct-2007  garbled Sync with HEAD
 1.2.28.1 09-Oct-2007  ad Sync with head.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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:24 +0000
 1.3 11-Dec-2005  christos merge ktrace-lwp.
 1.2 22-Oct-2003  kleink Use a common <machine/math.h> for amd64 and i386.
 1.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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.24 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.23 04-Nov-2024  christos Undo previous lwp.h change.
 1.22 03-Nov-2024  christos Split __lwp_getprivate_fast and __lwp_*tcb from mcontext.h into a separate
lwp.h file.
 1.21 18-May-2024  thorpej branches: 1.21.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.20 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.19 15-Feb-2018  kamil branches: 1.19.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.18 12-May-2014  uebayasi branches: 1.18.20;
Comments.
 1.17 15-Feb-2014  dsl branches: 1.17.2;
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.16 15-Dec-2012  dsl branches: 1.16.2;
Remove the incorrect comment about a (now deleted) pad field added
to make __fpregs be 16-byte aligned within ucontext_t.
I doubt that has been true for years!
Since the __fpregs field isn't accessed by fxsave it doesn't matter.
There is a lot of type fubar here, at leat mark the char[] __aligned(8).
 1.15 21-May-2012  martin branches: 1.15.2;
Calling _lwp_create() with a bogus ucontext could trigger a kernel
assertion failure (and thus a crash in DIAGNOSTIC kernels). Independently
discovered by YAMAMOTO Takashi and Joel Sing.

To avoid this, introduce a cpu_mcontext_validate() function and move all
sanity checks from cpu_setmcontext() there. Also untangle the netbsd32
compat mess slightly and add a cpu_mcontext32_validate() cousin there.

Add an exhaustive atf test case, based partly on code from Joel Sing.

Should finally fix the remaining open part of PR kern/43903.
 1.14 25-Feb-2011  joerg branches: 1.14.4; 1.14.8; 1.14.10;
Be nicer to software that insists on -ansi and use __inline.
 1.13 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.12 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.11 26-Oct-2008  mrg branches: 1.11.8; 1.11.16; 1.11.22; 1.11.24;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.10 28-Apr-2008  martin branches: 1.10.6;
Remove clause 3 and 4 from TNF licenses
 1.9 04-Jan-2008  dsl branches: 1.9.6; 1.9.8; 1.9.10;
Change the way that the trap/intr/syscall frames and the __gregset_t[]
indexes are defined so that only a single list of the registers is used.
The code no longer relies on the two structures matching.
There should be no binary change.
 1.8 29-Mar-2006  cube branches: 1.8.38; 1.8.44; 1.8.52;
Add the netbsd32 MD bits for sparc64 and amd64 to support SA.

Many thanks to all who helped for that little project, notably Martin
Husemann for teaching me a bit about the very special sparc64 world.
 1.7 11-Dec-2005  christos branches: 1.7.4; 1.7.6; 1.7.8; 1.7.10; 1.7.12;
merge ktrace-lwp.
 1.6 15-May-2005  fvdl branches: 1.6.2;
Optionally include saving and restoring the 64bit %gs and %fs base register
values in the PCB. Do this in pmap_activate for now (XXX not a good place
for it, but a convenient one).
 1.5 21-Oct-2004  fvdl Fix thread context switching to take the stack ABI into account.
From Wolfgang Solfrank.
 1.4 13-Oct-2003  fvdl branches: 1.4.2;
Define mcontext32_t (if COMPAT_NETBSD32).
 1.3 08-Oct-2003  thorpej 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.2 06-Oct-2003  fvdl SIGINFO support.
Todo: 32bit compat support (COMPAT_NETBSD32 will not compile right now,
as it won't on other platforms).
 1.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.2.4 02-Nov-2004  skrll Sync with HEAD.
 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.2.1 12-Nov-2004  jmc Pullup rev 1.5 (requested by fvdl in ticket #956)

Fix thread context switching to take the stack ABI into account.
 1.6.2.2 21-Jan-2008  yamt sync with head
 1.6.2.1 21-Jun-2006  yamt sync with head.
 1.7.12.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.7.10.1 19-Apr-2006  elad sync with head - hopefully this will work
 1.7.8.1 01-Apr-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.8.52.1 08-Jan-2008  bouyer Sync with HEAD
 1.8.44.1 18-Feb-2008  mjf Sync with HEAD.
 1.8.38.1 09-Jan-2008  matt sync with HEAD
 1.9.10.2 04-May-2009  yamt sync with head.
 1.9.10.1 16-May-2008  yamt sync with head.
 1.9.8.1 18-May-2008  yamt sync with head.
 1.9.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.9.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.10.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.11.24.1 05-Mar-2011  bouyer Sync with HEAD
 1.11.22.1 06-Jun-2011  jruoho Sync with HEAD.
 1.11.16.1 05-Mar-2011  rmind sync with head
 1.11.8.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.14.10.1 21-May-2012  riz Pull up following revision(s) (requested by martin in ticket #274):
sys/arch/amd64/amd64/process_machdep.c: revision 1.20
sys/kern/sys_lwp.c: revision 1.54
sys/arch/sparc64/sparc64/machdep.c: revision 1.267
sys/arch/mips/mips/cpu_subr.c: revision 1.16
sys/arch/vax/vax/machdep.c: revision 1.188
sys/sys/lwp.h: revision 1.161
sys/arch/sparc64/sparc64/netbsd32_machdep.c: revision 1.98
sys/arch/alpha/alpha/machdep.c: revision 1.339
sys/compat/sys/ucontext.h: revision 1.6
sys/arch/hppa/hppa/hppa_machdep.c: revision 1.28
distrib/sets/lists/tests/mi: revision 1.469
sys/arch/powerpc/powerpc/sig_machdep.c: revision 1.42
tests/lib/libc/sys/t_lwp_create.c: revision 1.1
tests/lib/libc/sys/Makefile: revision 1.23
sys/arch/arm/arm/sig_machdep.c: revision 1.42
sys/arch/amd64/include/mcontext.h: revision 1.15
sys/arch/amd64/amd64/machdep.c: revision 1.183
sys/arch/sh3/sh3/sh3_machdep.c: revision 1.99
sys/arch/i386/i386/machdep.c: revision 1.727
sys/compat/netbsd32/netbsd32_lwp.c: revision 1.13
sys/arch/sparc/sparc/machdep.c: revision 1.319
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.76
sys/arch/m68k/m68k/sig_machdep.c: revision 1.49
sys/sys/ucontext.h: revision 1.16
sys/arch/mips/mips/netbsd32_machdep.c: revision 1.9
lib/libc/sys/_lwp_create.2: revision 1.5
Calling _lwp_create() with a bogus ucontext could trigger a kernel
assertion failure (and thus a crash in DIAGNOSTIC kernels). Independently
discovered by YAMAMOTO Takashi and Joel Sing.
To avoid this, introduce a cpu_mcontext_validate() function and move all
sanity checks from cpu_setmcontext() there. Also untangle the netbsd32
compat mess slightly and add a cpu_mcontext32_validate() cousin there.
Add an exhaustive atf test case, based partly on code from Joel Sing.
Should finally fix the remaining open part of PR kern/43903.
 1.14.8.1 02-Jun-2012  mrg sync to latest -current.
 1.14.4.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.14.4.2 23-Jan-2013  yamt sync with head
 1.14.4.1 23-May-2012  yamt sync with head.
 1.15.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.15.2.1 25-Feb-2013  tls resync with head
 1.16.2.1 18-May-2014  rmind sync with head
 1.17.2.1 10-Aug-2014  tls Rebase.
 1.18.20.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.18.20.2 26-Feb-2018  snj revert ticket 552, which broke the build
 1.18.20.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.19.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.21.2.1 02-Aug-2025  perseant Sync with HEAD
 1.1 11-May-2003  fvdl ACPI support. Wakeup code still to be done.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.8 13-Sep-2022  riastradh amd64/asan.h, amd64/msan.h: Add include guards.
 1.7 22-Aug-2022  riastradh amd64/msan.h: Fix includes for private pmap.
 1.6 18-Nov-2020  hannken Make this at least compile.
Looks like a missing part from "Round of uvm.h cleanup (2020-09-05 18:30)".
 1.5 09-Sep-2020  maxv branches: 1.5.2;
kmsan: update the copyright notices
 1.4 07-Jun-2020  christos make this compile.
 1.3 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.2 15-Apr-2020  maxv Use large pages for the kMSan shadows. This greatly improves performance,
and slightly reduces memory consumption.
 1.1 14-Nov-2019  maxv branches: 1.1.6; 1.1.8;
Add support for Kernel Memory Sanitizer (kMSan). It detects uninitialized
memory used by the kernel at run time, and just like kASan and kCSan, it
is an excellent feature. It has already detected 38 uninitialized variables
in the kernel during my testing, which I have since discreetly fixed.

We use two shadows:
- "shad", to track uninitialized memory with a bit granularity (1:1).
Each bit set to 1 in the shad corresponds to one uninitialized bit of
real kernel memory.
- "orig", to track the origin of the memory with a 4-byte granularity
(1:1). Each uint32_t cell in the orig indicates the origin of the
associated uint32_t of real kernel memory.

The memory consumption of these shadows is consequent, so at least 4GB of
RAM is recommended to run kMSan.

The compiler inserts calls to specific __msan_* functions on each memory
access, to manage both the shad and the orig and detect uninitialized
memory accesses that change the execution flow (like an "if" on an
uninitialized variable).

We mark as uninit several types of memory buffers (stack, pools, kmem,
malloc, uvm_km), and check each buffer passed to copyout, copyoutstr,
bwrite, if_transmit_lock and DMA operations, to detect uninitialized memory
that leaves the system. This allows us to detect kernel info leaks in a way
that is more efficient and also more user-friendly than KLEAK.

Contrary to kASan, kMSan requires comprehensive coverage, ie we cannot
tolerate having one non-instrumented function, because this could cause
false positives. kMSan cannot instrument ASM functions, so I converted
most of them to __asm__ inlines, which kMSan is able to instrument. Those
that remain receive special treatment.

Contrary to kASan again, kMSan uses a TLS, so we must context-switch this
TLS during interrupts. We use different contexts depending on the interrupt
level.

The orig tracks precisely the origin of a buffer. We use a special encoding
for the orig values, and pack together in each uint32_t cell of the orig:
- a code designating the type of memory (Stack, Pool, etc), and
- a compressed pointer, which points either (1) to a string containing
the name of the variable associated with the cell, or (2) to an area
in the kernel .text section which we resolve to a symbol name + offset.

This encoding allows us not to consume extra memory for associating
information with each cell, and produces a precise output, that can tell
for example the name of an uninitialized variable on the stack, the
function in which it was pushed on the stack, and the function where we
accessed this uninitialized variable.

kMSan is available with LLVM, but not with GCC.

The code is organized in a way that is similar to kASan and kCSan, so it
means that other architectures than amd64 can be supported.
 1.1.8.3 21-Apr-2020  martin Sync with HEAD
 1.1.8.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1.8.1 14-Nov-2019  martin file msan.h was added on branch phil-wifi on 2020-04-13 08:03:30 +0000
 1.1.6.1 20-Apr-2020  bouyer Sync with HEAD
 1.5.2.1 14-Dec-2020  thorpej Sync w/ HEAD.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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:05:43 +0000
 1.25 27-Nov-2019  rin Add support for PT_[GS]ETXMMREGS requests for COMPAT_NETBSD32 on amd64.

For this purpose, PT_[GS]ETXMMREGS are added to amd64/ptrace.h. These
are intended for internal usage for COMPAT_NETBSD32, and therefore not
exposed to userland.

Thanks to kamil, mgorny, and pgoyette for their kind review!

XXX
pullup to netbsd-9
 1.24 26-Jun-2019  mgorny 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.23 04-Jun-2019  mgorny compat32: Translate userland PT_* request values into kernel codes

Currently, the compat32 passes PT_* request values to kernel functions
without translation. This works fine for low PT_* requests that happen
to have the same values both on i386 and amd64. However, for requests
higher than PT_SETFPREGS, the value passed from userland (matching i386
const) does not match the correct kernel (amd64) request. As a result,
e.g. when compat32 process calls PT_GETDBREGS, kernel actually processes
it as PT_SETSTEP.

To resolve this, introduce support for compat32 PT_* request
translation. The interface is based on PTRACE_TRANSLATE_REQUEST32 macro
that is defined to a mapping function on architectures needing it.
In case of amd64, this function maps userland i386 PT_* values into
appropriate amd64 PT_* values.

For the time being, the two additional PT_GETXMMREGS and PT_SETXMMREGS
requests are unsupported due to lack of matching free amd64 constant.
 1.22 23-Feb-2017  kamil branches: 1.22.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.21 06-Feb-2017  maxv Add the USER_LDT sysarch options in netbsd32. We don't translate 'desc',
since if we ever implement USER_LDT we will only allow 8-byte-sized
entries, which have the same layout on amd64 and i386.
 1.20 19-Oct-2016  skrll branches: 1.20.2;
PR kern/51514: ptrace(2) fails for 32-bit process on 64-bit kernel

Updated from the original patch in the PR by me.
 1.19 07-Feb-2014  dsl branches: 1.19.6; 1.19.10;
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.18 04-Jan-2014  dsl Remove __HAVE_PROCESS_XFPREGS and add the extra parameter for the size
of the fp save area to all the process_read_fpregs() and
process_write_fpregs() functions.
None of the functions have been modified to use the new parameters.
The size is set for all the writes, but some of the arch-specific reads
just pass NULL.
The amd64 (and i386) need variable sized fp register save areas in order
to support AVX and other enhanced register areas.
These functions are rarely called - so the extra argument won't matter.
 1.17 19-Feb-2012  rmind branches: 1.17.2; 1.17.4;
Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.
 1.16 15-Oct-2008  wrstuden branches: 1.16.28; 1.16.32;
Merge wrstuden-revivesa into HEAD.
 1.15 25-Dec-2007  perry branches: 1.15.6; 1.15.10; 1.15.12; 1.15.16;
Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.14 17-Oct-2007  garbled branches: 1.14.2; 1.14.4; 1.14.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.13 16-Sep-2007  dsl Define netbsd32_uint64 for 64bit integers with the alignment requirement
of the corresponding 32bit architecture.
Use it for the 64bit items in netbsd32_statvfs so that the structure
doesn't collect 8byte alignment (and 4 bytes of trailing padding).
This replaces the 'packed' attribute which wasn't architecture specific
and would cause massive overheads accessing every member of sparc64.
Should allow the MIPS64 port do DTRT.
 1.12 16-Mar-2007  dsl branches: 1.12.4; 1.12.12; 1.12.14;
Use NETBSD32PTR64() and NETBSD32PTR32() throughout.
 1.11 09-Feb-2007  ad branches: 1.11.2; 1.11.6; 1.11.8; 1.11.10;
Merge newlock2 to head.
 1.10 29-Mar-2006  cube branches: 1.10.8;
Add the netbsd32 MD bits for sparc64 and amd64 to support SA.

Many thanks to all who helped for that little project, notably Martin
Husemann for teaching me a bit about the very special sparc64 world.
 1.9 12-Mar-2006  cube branches: 1.9.2;
Support the generation of coredumps for 32-bits binaries under
COMPAT_NETBSD32. They haven't worked for 5 years.

Silently agreed by the tech-kern readers.

XXX sparc64 MD glue still lacking.
XXX The FPU registers on i386 are not dumped correctly, according to my
XXX tests. It shouldn't be much work for someone who has the slightest
XXX idea of how that stuff is supposed to be laid out on i386.
 1.8 11-Dec-2005  christos branches: 1.8.4; 1.8.6; 1.8.8; 1.8.10;
merge ktrace-lwp.
 1.7 27-Sep-2005  chs make this compile again.
 1.6 14-Sep-2005  chs need to include <compat/sys/ucontext.h> here.
 1.5 20-Feb-2004  drochner branches: 1.5.16;
provide a definition NETBSD32_MID_MACHINE which tells for the a.out MID
to look for in 32-bit emulation
 1.4 13-Oct-2003  fvdl Define 32bit versions of signal frames and contexts.
 1.3 26-Sep-2003  christos move MI stuff to the MI include.
 1.2 26-Sep-2003  christos add catch up with const sigset_t *
 1.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.2.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 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.5.16.5 21-Jan-2008  yamt sync with head
 1.5.16.4 27-Oct-2007  yamt sync with head.
 1.5.16.3 03-Sep-2007  yamt sync with head.
 1.5.16.2 26-Feb-2007  yamt sync with head.
 1.5.16.1 21-Jun-2006  yamt sync with head.
 1.8.10.1 19-Apr-2006  elad sync with head - hopefully this will work
 1.8.8.2 01-Apr-2006  yamt sync with head.
 1.8.8.1 13-Mar-2006  yamt sync with head.
 1.8.6.1 22-Apr-2006  simonb Sync with head.
 1.8.4.1 09-Sep-2006  rpaulo sync with head
 1.9.2.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.10.8.1 01-Feb-2007  ad Remove definition of struct netbsd32_saframe.
 1.11.10.1 18-Mar-2007  reinoud First attempt to bring branch in sync with HEAD
 1.11.8.1 11-Jul-2007  mjf Sync with head.
 1.11.6.2 09-Oct-2007  ad Sync with head.
 1.11.6.1 10-Apr-2007  ad Sync with head.
 1.11.2.1 24-Mar-2007  yamt sync with head.
 1.12.14.2 09-Jan-2008  matt sync with HEAD
 1.12.14.1 06-Nov-2007  matt sync with HEAD
 1.12.12.1 02-Oct-2007  joerg Sync with HEAD.
 1.12.4.1 03-Oct-2007  garbled Sync with HEAD
 1.14.8.1 02-Jan-2008  bouyer Sync with HEAD
 1.14.4.1 26-Dec-2007  ad Sync with head.
 1.14.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.15.16.1 19-Oct-2008  haad Sync with HEAD.
 1.15.12.1 28-Sep-2008  skrll Adapt the SA COMPAT_NETBSD32 stuff to this branch.
 1.15.10.1 04-May-2009  yamt sync with head.
 1.15.6.1 17-Jan-2009  mjf Sync with HEAD.
 1.16.32.1 24-Feb-2012  mrg sync to -current.
 1.16.28.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.16.28.1 17-Apr-2012  yamt sync with head
 1.17.4.1 18-May-2014  rmind sync with head
 1.17.2.2 03-Dec-2017  jdolecek update from HEAD
 1.17.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.19.10.2 20-Mar-2017  pgoyette Sync with HEAD
 1.19.10.1 04-Nov-2016  pgoyette Sync with HEAD
 1.19.6.2 28-Aug-2017  skrll Sync with HEAD
 1.19.6.1 05-Dec-2016  skrll Sync with HEAD
 1.20.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.22.14.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.22.14.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.22.14.1 10-Jun-2019  christos Sync with HEAD
 1.42 27-Apr-2025  riastradh amd64/param.h: Fix KASAN/KMSAN build (and ALL build by extension).

Make UPAGES match what it was before my recent changes, as verified
by the __CTASSERT below, justifying the existence of the __CTASSERT.

As I recall, SVS is incompatible with KASAN/KMSAN, so it doesn't
contribute to the sum; presumably KASAN/KMSAN requires three pages,
though I'm not sure where this is documented. If it turns out this
accounting is wrong, we should fix it and cross-reference any relevant
constraints affecting the accounting. (But for now I'm just making
sure to restore the status quo of these definitions, which was my
intent all along with adding the __CTASSERT.)

Issue noted by hannken@.

PR port-amd64/57661: Crash when booting on Xeon Silver 4416+ in
KVM/Qemu
 1.41 24-Apr-2025  riastradh x86: Make sure esp is aligned when delivering signal.

While here, use STACK_ALIGNBYTES consistently for the alignment mask
(or STACK_ALIGNBYTES32 in amd64 for the compat32 alignment mask).

PR kern/59327: user stack pointer is not aligned properly
 1.40 24-Apr-2025  kre Skip __CTASSERT() when _STANDALONE

Unbreak the amd64 build (the assembler did not like those things!).

These __CTASSERT()'s aren't really useful in any case, and
should probably just be deleted - they simply check that the
arithmetic in the previous few lines produces the answers
expected.

If those answers were critical, then we shouldn't be computing
them in the first place, and should simply
#define UPAGES 8
(conditionally, replacing all the previous computation which
generates UPAGES, and the 3 __CTASSERT()'s.)

But I suspect that they're not critical, they just happen to be
the answers currently expected to be achieved. That's not something
that should be asserted to be true, it isn't a required fact, it
could easily be altered in one of the cases if needed, and everything
else should cope with that.
 1.39 24-Apr-2025  riastradh amd64/param.h: Make UPAGES definition clearer.

Break it down into subaccounts that are summed at the end to make it
clear how much each part is using, and how many pages are actually
reserved for the stack.

No functional change intended.

PR port-amd64/57661: Crash when booting on Xeon Silver 4416+ in
KVM/Qemu
 1.38 29-Jun-2020  jdolecek branches: 1.38.26;
increase UPAGES (used for lwp kernel stack) for SVS so the the
amount of actually usable kernel stack is the same for SVS and
non-SVS kernels (currently 12 KiB)

discussed with maxv@, part of investigation for PR kern/S55402
 1.37 17-Mar-2020  maxv Add a redzone between the pcb and the stack. Sent to port-amd64@.
 1.36 08-Feb-2020  maxv Retire KLEAK.

KLEAK was a nice feature and served its purpose; it allowed us to detect
dozens of info leaks on the kernel->userland boundary, and thanks to it we
tackled a good part of the infoleak problem 1.5 years ago.

Nowadays however, we have kMSan, which can detect uninitialized memory in
the kernel. kMSan supersedes KLEAK: it can detect what KLEAK was able to
detect, but in addition, (1) it operates in all of the kernel and not just
the kernel->userland boundary, (2) it requires no user interaction, and (3)
it is deterministic and not statistical.

That makes kMSan the feature of choice to detect info leaks nowadays;
people interested in detecting info leaks should boot a kMSan kernel and
just wait for the magic to happen.

KLEAK was a good ride, and a fun project, but now is time for it to go.

Discussed with several people, including Thomas Barabosch.
 1.35 22-Jan-2020  ad Move the UBC defaults into vmparam.h
 1.34 17-Jan-2020  ad Bump UBC_WINSHIFT & UBC_NWINS to more reasonable values for amd64.
 1.33 14-Nov-2019  maxv branches: 1.33.2;
Add support for Kernel Memory Sanitizer (kMSan). It detects uninitialized
memory used by the kernel at run time, and just like kASan and kCSan, it
is an excellent feature. It has already detected 38 uninitialized variables
in the kernel during my testing, which I have since discreetly fixed.

We use two shadows:
- "shad", to track uninitialized memory with a bit granularity (1:1).
Each bit set to 1 in the shad corresponds to one uninitialized bit of
real kernel memory.
- "orig", to track the origin of the memory with a 4-byte granularity
(1:1). Each uint32_t cell in the orig indicates the origin of the
associated uint32_t of real kernel memory.

The memory consumption of these shadows is consequent, so at least 4GB of
RAM is recommended to run kMSan.

The compiler inserts calls to specific __msan_* functions on each memory
access, to manage both the shad and the orig and detect uninitialized
memory accesses that change the execution flow (like an "if" on an
uninitialized variable).

We mark as uninit several types of memory buffers (stack, pools, kmem,
malloc, uvm_km), and check each buffer passed to copyout, copyoutstr,
bwrite, if_transmit_lock and DMA operations, to detect uninitialized memory
that leaves the system. This allows us to detect kernel info leaks in a way
that is more efficient and also more user-friendly than KLEAK.

Contrary to kASan, kMSan requires comprehensive coverage, ie we cannot
tolerate having one non-instrumented function, because this could cause
false positives. kMSan cannot instrument ASM functions, so I converted
most of them to __asm__ inlines, which kMSan is able to instrument. Those
that remain receive special treatment.

Contrary to kASan again, kMSan uses a TLS, so we must context-switch this
TLS during interrupts. We use different contexts depending on the interrupt
level.

The orig tracks precisely the origin of a buffer. We use a special encoding
for the orig values, and pack together in each uint32_t cell of the orig:
- a code designating the type of memory (Stack, Pool, etc), and
- a compressed pointer, which points either (1) to a string containing
the name of the variable associated with the cell, or (2) to an area
in the kernel .text section which we resolve to a symbol name + offset.

This encoding allows us not to consume extra memory for associating
information with each cell, and produces a precise output, that can tell
for example the name of an uninitialized variable on the stack, the
function in which it was pushed on the stack, and the function where we
accessed this uninitialized variable.

kMSan is available with LLVM, but not with GCC.

The code is organized in a way that is similar to kASan and kCSan, so it
means that other architectures than amd64 can be supported.
 1.32 28-Sep-2019  christos remove local version of mstohz() now that <sys/param.h> provides it.
 1.31 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.30 16-Mar-2019  rin branches: 1.30.4;
Bump STACK_ALIGNBYTES to (16 - 1) to satisfy requirement by AMD64
System V ABI in kernel level. This is because

(1) for LLDB, we want to bypass libc/csu (and therefore manual stack
alignment in _start), and

(2) rtld in glibc >= 2.23 for Linux/x86_64 requires it.

Fix SEGV for Linux/x86_64 binaries with glibc >= 2.23, reported as
PR port-amd64/54052.
 1.29 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.28 07-Jan-2019  jdolecek 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.27 02-Dec-2018  maxv Introduce KLEAK, a new feature that can detect kernel information leaks.

It works by tainting memory sources with marker values, letting the data
travel through the kernel, and scanning the kernel<->user frontier for
these marker values. Combined with compiler instrumentation and rotation
of the markers, it is able to yield relevant results with little effort.

We taint the pools and the stack, and scan copyout/copyoutstr. KLEAK is
supported on amd64 only for now, but it is not complicated to add more
architectures (just a matter of having the address of .text, and a stack
unwinder).

A userland tool is provided, that allows to execute a command in rounds
and monitor the leaks generated all the while.

KLEAK already detected directly 12 kernel info leaks, and prompted changes
that in total fixed 25+ leaks.

Based on an idea developed jointly with Thomas Barabosch (of Fraunhofer
FKIE).
 1.26 22-Aug-2018  maxv Add support for monitoring the stack with kASan. This allows us to detect
illegal memory accesses occuring there.

The compiler inlines a piece of code in each function that adds redzones
around the local variables and poisons them. The illegal accesses are then
detected using the usual kASan machinery.

The stack size is doubled, from 4 pages to 8 pages.

Several boot functions are marked with the __noasan flag, to prevent the
compiler from adding redzones in them (because we haven't yet initialized
kASan). The kasan_early_init function is called early at boot time to
quickly create the shadow for the current stack; after this is done, we
don't need __noasan anymore in the boot path.

We pass -fasan-shadow-offset=0xDFFF900000000000, because the compiler
wants to do
shad = shadow-offset + (addr >> 3)
and we do, in kasan_addr_to_shad
shad = KASAN_SHADOW_START + ((addr - CANONICAL_BASE) >> 3)
hence
shad = KASAN_SHADOW_START + (addr >> 3) - (CANONICAL_BASE >> 3)
= [KASAN_SHADOW_START - (CANONICAL_BASE >> 3)] + (addr >> 3)
implies
shadow-offset = KASAN_SHADOW_START - (CANONICAL_BASE >> 3)
= 0xFFFF800000000000 - (0xFFFF800000000000 >> 3)
= 0xDFFF900000000000

In UVM, we add a kasan_free (that is not preceded by a kasan_alloc). We
don't add poisoned redzones ourselves, but all the functions we execute
do, so we need to manually clear the poison before freeing the stack.

With the help of Kamil for the makefile stuff.
 1.25 16-Mar-2018  maxv branches: 1.25.2;
Add one more page for the stack, to compensate for the fact that SVS's
stack switching mechanism consumes approximately one page.
 1.24 19-Feb-2018  sborrill branches: 1.24.2;
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.23 11-Jan-2018  maxv Initialize ist0 in cpu_init_tss. On amd64 this is the DDB stack, and it has
nothing to do with ci_intrstack. While here, style, and don't forget to
pass UVM_KMF_ZERO in uvm_km_alloc.
 1.22 14-Jun-2017  maxv Define MAXPHYSMEM globally.
 1.21 02-Feb-2017  maxv branches: 1.21.6;
Increase KERNTEXTOFF from 1MB to 2MB on amd64. [1MB; 2MB[ is now handled
by UVM, so there is no physical loss.

On amd64 we always remap the kernel text with 2MB pages, and because of the
1MB start address we were forced to map [0MB; 2MB[ inside the first large
page. The problem is, the lower half is used by UVM to allocate physical
pages, and it is possible that some of these could be used by userland. We
could end up with userland-controllable data mapped into the kernel text on
a privileged page, which is far from being a good idea from a security pov.

I am not fixing i386 yet, because the large page size depends on PAE, and
we probably don't want to have a text located at 4MB on low-memory systems.

(note: I didn't introduce this issue, it was already there when I came in)
 1.20 20-Jan-2017  maya increase max io mem on amd64. some devices need it.
 1.19 27-Oct-2015  mrg branches: 1.19.2; 1.19.4;
make sure MSGBUFSIZE can't expand strangely by using parens.
 1.18 20-Apr-2012  rmind branches: 1.18.2; 1.18.14; 1.18.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.17 04-Feb-2012  para branches: 1.17.2;
improve sizing of kmem_arena now that more allocations are made from it
don't enforce limits if not required

ok: riz@
 1.16 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.15 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.14 26-Jul-2011  yamt branches: 1.14.2; 1.14.6;
g/c round_pdr
 1.13 08-Feb-2010  joerg 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.12 11-Nov-2009  haad branches: 1.12.2;
Reert change which was not meant to be comitted.
 1.11 11-Nov-2009  haad Build kernel modules with -mno-red-zone like kernel is build. This fixes
frequent panics in amd64 zfs module. This should also fix problem reported
by Nicolas Joly in:

http://mail-index.netbsd.org/port-amd64/2008/12/09/msg000646.html

Thanks to cube@ for his help with this.
 1.10 20-Dec-2008  ad branches: 1.10.2;
- Kill NOREDZONE.
- Make the redzone conditional on DIAGNOSTIC.
- Give amd64 an additional page for the uarea. 2 is not enough.
 1.9 26-Oct-2008  mrg branches: 1.9.2; 1.9.4;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.8 08-Jan-2008  yamt branches: 1.8.6; 1.8.10; 1.8.16;
change the layout in u-area and reduce UPAGES.
 1.7 05-Jan-2008  yamt - make amd64 use per-cpu tss.
- fix iopl syscall for amd64+xen.
 1.6 18-Oct-2007  yamt branches: 1.6.2; 1.6.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.5 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.4 13-Oct-2007  joerg branches: 1.4.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.3 28-Aug-2006  yamt branches: 1.3.12; 1.3.20; 1.3.30; 1.3.32; 1.3.34;
- remove unused bdbtofsb.
- move the following macros from MD headers to sys/param.h.
ctod
dtoc
ctob
btoc
dbtob
btodb
 1.2 12-Feb-2006  chs branches: 1.2.2;
increase NKMEMPAGES_MAX_DEFAULT to 1 GB.
this allows lots more memory to be used for amaps, etc.
 1.1 26-Apr-2003  fvdl branches: 1.1.16; 1.1.18; 1.1.30; 1.1.32; 1.1.34;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.34.1 22-Apr-2006  simonb Sync with head.
 1.1.32.1 09-Sep-2006  rpaulo sync with head
 1.1.30.1 18-Feb-2006  yamt sync with head.
 1.1.18.4 21-Jan-2008  yamt sync with head
 1.1.18.3 27-Oct-2007  yamt sync with head.
 1.1.18.2 30-Dec-2006  yamt sync with head.
 1.1.18.1 21-Jun-2006  yamt sync with head.
 1.1.16.1 14-Feb-2006  tron Pull up following revision(s) (requested by chs in ticket #1166):
sys/arch/amd64/include/param.h: revision 1.2
increase NKMEMPAGES_MAX_DEFAULT to 1 GB.
this allows lots more memory to be used for amaps, etc.
 1.2.2.1 03-Sep-2006  yamt sync with head.
 1.3.34.2 14-Oct-2007  yamt sync with head.
 1.3.34.1 07-Oct-2007  yamt remove some #ifdef _LOCORE and use genassym instead.
 1.3.32.2 09-Jan-2008  matt sync with HEAD
 1.3.32.1 06-Nov-2007  matt sync with HEAD
 1.3.30.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.3.20.1 16-Oct-2007  garbled Sync with HEAD
 1.3.12.1 23-Oct-2007  ad Sync with head.
 1.4.2.1 25-Oct-2007  bouyer Sync with HEAD.
 1.6.8.1 08-Jan-2008  bouyer Sync with HEAD
 1.6.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.8.16.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.8.10.2 11-Mar-2010  yamt sync with head
 1.8.10.1 04-May-2009  yamt sync with head.
 1.8.6.1 17-Jan-2009  mjf Sync with HEAD.
 1.9.4.1 16-Feb-2009  snj Pull up following revision(s) (requested by ad in ticket #355):
sys/arch/amd64/amd64/vm_machdep.c: revision 1.37
sys/arch/amd64/include/param.h: revision 1.10
- Kill NOREDZONE.
- Make the redzone conditional on DIAGNOSTIC.
- Give amd64 an additional page for the uarea. 2 is not enough.
 1.9.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.10.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.10.2.1 24-Oct-2010  jym Sync with HEAD
 1.12.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.14.6.2 29-Apr-2012  mrg sync to latest -current.
 1.14.6.1 18-Feb-2012  mrg merge to -current.
 1.14.2.2 23-May-2012  yamt sync with head.
 1.14.2.1 17-Apr-2012  yamt sync with head
 1.17.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.18.16.3 28-Aug-2017  skrll Sync with HEAD
 1.18.16.2 05-Feb-2017  skrll Sync with HEAD
 1.18.16.1 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.18.14.2 30-Mar-2019  bouyer Pull up following revision(s) (requested by rin in ticket #1687):
sys/arch/amd64/include/param.h: revision 1.30
Bump STACK_ALIGNBYTES to (16 - 1) to satisfy requirement by AMD64
System V ABI in kernel level. This is because
(1) for LLDB, we want to bypass libc/csu (and therefore manual stack
alignment in _start), and
(2) rtld in glibc >= 2.23 for Linux/x86_64 requires it.
Fix SEGV for Linux/x86_64 binaries with glibc >= 2.23, reported as
PR port-amd64/54052.
 1.18.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.18.2.2 03-Dec-2017  jdolecek update from HEAD
 1.18.2.1 12-Sep-2012  tls Initial snapshot of work to eliminate 64K MAXPHYS. Basically works for
physio (I/O to raw devices); needs more doing to get it going with the
filesystems, but it shouldn't damage data.

All work's been done on amd64 so far. Not hard to add support to other
ports. If others want to pitch in, one very helpful thing would be to
sort out when and how IDE disks can do 128K or larger transfers, and
adjust the various PCI IDE (or at least ahcisata) drivers and wd.c
accordingly -- it would make testing much easier. Another very helpful
thing would be to implement a smart minphys() for RAIDframe along the
lines detailed in the MAXPHYS-NOTES file.
 1.19.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.19.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.21.6.4 29-Mar-2019  martin Pull up following revision(s) (requested by rin in ticket #1220):

sys/arch/amd64/include/param.h: revision 1.30

Bump STACK_ALIGNBYTES to (16 - 1) to satisfy requirement by AMD64
System V ABI in kernel level. This is because

(1) for LLDB, we want to bypass libc/csu (and therefore manual stack
alignment in _start), and
(2) rtld in glibc >= 2.23 for Linux/x86_64 requires it.

Fix SEGV for Linux/x86_64 binaries with glibc >= 2.23, reported as

PR port-amd64/54052.
 1.21.6.3 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.21.6.2 22-Mar-2018  martin Pull up the following revisions, requested by maxv in ticket #652:

sys/arch/amd64/amd64/amd64_trap.S upto 1.39 (partial, patch)
sys/arch/amd64/amd64/db_machdep.c 1.6 (patch)
sys/arch/amd64/amd64/genassym.cf 1.65,1.66,1.67 (patch)
sys/arch/amd64/amd64/locore.S upto 1.159 (partial, patch)
sys/arch/amd64/amd64/machdep.c 1.299-1.302 (patch)
sys/arch/amd64/amd64/trap.c upto 1.113 (partial, patch)
sys/arch/amd64/amd64/amd64/vector.S upto 1.61 (partial, patch)
sys/arch/amd64/conf/GENERIC 1.477,1.478 (patch)
sys/arch/amd64/conf/kern.ldscript 1.26 (patch)
sys/arch/amd64/include/frameasm.h upto 1.37 (partial, patch)
sys/arch/amd64/include/param.h 1.25 (patch)
sys/arch/amd64/include/pmap.h 1.41,1.43,1.44 (patch)
sys/arch/x86/conf/files.x86 1.91,1.93 (patch)
sys/arch/x86/include/cpu.h 1.88,1.89 (patch)
sys/arch/x86/include/pmap.h 1.75 (patch)
sys/arch/x86/x86/cpu.c 1.144,1.146,1.148,1.149 (patch)
sys/arch/x86/x86/pmap.c upto 1.289 (partial, patch)
sys/arch/x86/x86/vm_machdep.c 1.31,1.32 (patch)
sys/arch/x86/x86/x86_machdep.c 1.104,1.106,1.108 (patch)
sys/arch/x86/x86/svs.c 1.1-1.14
sys/arch/xen/conf/files.compat 1.30 (patch)

Backport SVS. Not enabled yet.
 1.21.6.1 16-Mar-2018  martin Pull up the following revisions (via patch), requested by maxv in #635:

sys/arch/amd64/amd64/gdt.c 1.39-1.45 (patch)
sys/arch/amd64/amd64/amd64/machdep.c 1.284,1.287,1.288 (patch)
sys/arch/amd64/amd64/include/param.h 1.23 (patch)
sys/arch/amd64/include/types.h 1.53 (patch)
sys/arch/x86/include/cpu.h 1.87 (patch)
sys/arch/x86/include/pmap.h 1.73,1.74 (patch)
sys/arch/x86/x86/cpu.c 1.142 (patch)
sys/arch/x86/x86/intr.c 1.117 (partial),1.120 (patch)
sys/arch/x86/x86/pmap.c 1.276 (patch)

Initialize ist0 in cpu_init_tss.
Backport __HAVE_PCPU_AREA.
 1.24.2.4 18-Jan-2019  pgoyette Synch with HEAD
 1.24.2.3 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.24.2.2 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.24.2.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.25.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.25.2.1 10-Jun-2019  christos Sync with HEAD
 1.30.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.33.2.3 29-Feb-2020  ad Sync with head.
 1.33.2.2 25-Jan-2020  ad Sync with head.
 1.33.2.1 17-Jan-2020  ad Sync with head.
 1.38.26.1 02-Aug-2025  perseant Sync with HEAD
 1.35 28-Apr-2025  riastradh xen: Stop-gap FPU PCB fix; disable Intel AMX for now.

Since the custom cpu_uarea_alloc/free are disabled under XENPV,
nothing would initialize struct pcb::pcb_savefpu to point either to
struct pcb::pcb_savefpusmall, or to a separately allocated large area
on machines with Intel AMX TILECFG/TILEDATA requiring it. So the
memset in fpu_lwp_fork would crash on null pointer dereference:

[ 1.0000030] uvm_fault(0xffffffff8094a300, 0x0, 2) -> e
[ 1.0000030] fatal page fault in supervisor mode
[ 1.0000030] trap type 6 code 0x2 rip 0xffffffff8062795c cs 0xe030 rflags 0x10202 cr2 0 ilevel 0 rsp 0xffffffff80adad38
[ 1.0000030] curlwp 0xffffffff8078f880 pid 0.0 lowest kstack 0xffffffff80ad62c0
kernel: page fault trap, code=0
Stopped in pid 0.0 (system) at netbsd:memset+0x2c: repe stosq %es:(%rdi)
memset() at netbsd:memset+0x2c
lwp_create() at netbsd:lwp_create+0x2f1
fork1() at netbsd:fork1+0x42c
main() at netbsd:main+0x44f

In order to support Intel AMX TILECFG/TILEDATA, or any other CPU
extensions that increase the XSAVE area beyond what fits in a single
page after struct pcb, we would need to enable the the custom
cpu_uarea_alloc/free. Currently that would imply allocating stack
guard pages (`redzone') under XENPV; if there's some reason the stack
guard pages don't work, we could also push #ifdef XENPV conditionals
into cpu_uarea_alloc/free to cover the guard pages -- to be
considered.

PR kern/59371: Xen domU uvm_fault since FPU state allocation patch

PR port-amd64/57661: Crash when booting on Xeon Silver 4416+ in
KVM/Qemu
 1.34 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.33 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.32 17-Mar-2020  maxv branches: 1.32.28;
Add a redzone between the pcb and the stack. Sent to port-amd64@.
 1.31 12-Oct-2019  christos disable CTASSERT for lint
 1.30 12-Oct-2019  maxv 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.29 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.28 31-Dec-2017  maxv branches: 1.28.2; 1.28.4;
gc unused
 1.27 31-Oct-2017  maxv 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.26 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.25 20-Feb-2014  dsl branches: 1.25.6; 1.25.10; 1.25.14;
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.24 11-Feb-2014  dsl Move sys/arch/amd64/amd64/fpu.c and sys/arch/amd64/include/fpu.h
into sys/arch/x86 in preparation for using the same code for i386.
 1.23 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.22 19-Jan-2014  dsl Remove the unused 'struct md_coredump'.
 1.21 11-Dec-2013  dsl Remove the fields that were used to save the i387 fp state on interrupt.
They were written but never read.
Possibly they should be saved for 32 bit processes, but that might be a relic
from real i387 where the fpu was actully asynchronous.
 1.20 01-Dec-2013  christos revert fpu/pcu changes until we figure out what's wrong; they cause random
freezes
 1.19 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.18 31-Dec-2012  dsl branches: 1.18.2;
Move the two fields used to save some i387 state on the last fpu trap
into their own sub-structure of the pcb (from 'struct savefpu').
They only (seem) to be used in some code that generates core dumps
for 32bit processes (code that might be broken as well!).
'struct safefpu' is now identical to 'struct fxsave64'. One (or both)
needs extending to support AVX - might need to be dynamically sized.
Removed all the __aligned(16) except for the one in struct pcb itself.
Only the copy used for the fsave instruction need be aligned.
 1.17 07-Jul-2010  chs branches: 1.17.8; 1.17.18;
add the guts of TLS support on amd64. based on joerg's patch,
reworked by me to support 32-bit processes as well.
we now keep %fs and %gs loaded with the user values
while in the kernel, which means we don't need to
reload them when returning to user mode.
 1.16 27-Oct-2009  rmind branches: 1.16.2; 1.16.4;
Make pcb_ldt_sel, in amd64, an unused field. Unlike in i386, it was
missed during clean-up of LDT handling.
 1.15 26-Oct-2008  mrg branches: 1.15.8;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.14 30-Apr-2008  ad branches: 1.14.6;
lcr0() was changed to take a u_long. pcb_cr0 was a 32-bit signed quantity.
It was being sign extended in cpu_hatch() (CR0_PG is always set), causing
systems to crash and reboot before going multiuser.
 1.13 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.12 16-Apr-2008  cegger branches: 1.12.2; 1.12.4;
use POSIX integer types
 1.11 05-Jan-2008  yamt branches: 1.11.6;
- make amd64 use per-cpu tss.
- fix iopl syscall for amd64+xen.
 1.10 27-Nov-2007  christos branches: 1.10.6;
Shuffle things around so that pcb_savefpu goes back to be aligned in a 16
bit boundary. Noted by Arto Huusko.
 1.9 26-Nov-2007  christos make cr2 64 bits. Requested by fvdl.
 1.8 24-Nov-2007  christos preserve cr2 on pcb for the benefit of linux emulation.
 1.7 17-Oct-2007  garbled branches: 1.7.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.6 17-May-2007  yamt branches: 1.6.8; 1.6.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.5 04-Mar-2007  christos branches: 1.5.2; 1.5.4; 1.5.10;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.4 11-Dec-2005  christos branches: 1.4.26;
merge ktrace-lwp.
 1.3 15-May-2005  fvdl branches: 1.3.2;
Optionally include saving and restoring the 64bit %gs and %fs base register
values in the PCB. Do this in pmap_activate for now (XXX not a good place
for it, but a convenient one).
 1.2 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.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.2.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 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.3.2.3 21-Jan-2008  yamt sync with head
 1.3.2.2 07-Dec-2007  yamt sync with head
 1.3.2.1 03-Sep-2007  yamt sync with head.
 1.4.26.2 12-Mar-2007  rmind Sync with HEAD.
 1.4.26.1 03-Mar-2007  yamt adapt amd64.

XXX changes in identcpu.c is minmum for MONITOR.
XXX identcpu.c should be shared with i386.
 1.5.10.1 22-May-2007  matt Update to HEAD.
 1.5.4.1 11-Jul-2007  mjf Sync with head.
 1.5.2.2 03-Dec-2007  ad Sync with HEAD.
 1.5.2.1 27-May-2007  ad Sync with head.
 1.6.10.2 09-Jan-2008  matt sync with HEAD
 1.6.10.1 06-Nov-2007  matt sync with HEAD
 1.6.8.1 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.7.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.7.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.10.6.1 08-Jan-2008  bouyer Sync with HEAD
 1.11.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.11.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.12.4.4 11-Aug-2010  yamt sync with head.
 1.12.4.3 11-Mar-2010  yamt sync with head
 1.12.4.2 04-May-2009  yamt sync with head.
 1.12.4.1 16-May-2008  yamt sync with head.
 1.12.2.1 18-May-2008  yamt sync with head.
 1.14.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.15.8.2 24-Oct-2010  jym Sync with HEAD
 1.15.8.1 01-Nov-2009  jym Sync with HEAD.
 1.16.4.1 05-Mar-2011  rmind sync with head
 1.16.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.17.18.3 03-Dec-2017  jdolecek update from HEAD
 1.17.18.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.17.18.1 25-Feb-2013  tls resync with head
 1.17.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.17.8.1 23-Jan-2013  yamt sync with head
 1.18.2.1 18-May-2014  rmind sync with head
 1.25.14.1 21-Apr-2017  bouyer Sync with HEAD
 1.25.10.1 20-Mar-2017  pgoyette Sync with HEAD
 1.25.6.1 28-Aug-2017  skrll Sync with HEAD
 1.28.4.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.28.4.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.28.4.1 10-Jun-2019  christos Sync with HEAD
 1.28.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.32.28.1 02-Aug-2025  perseant Sync with HEAD
 1.2 15-Jun-2003  fvdl Handle 64bit DMA addresses on PCI for platforms that can (currently only
enabled on amd64). Add a dmat64 field to various PCI attach structures,
and pass it down where needed. Implement a simple new function called
pci_dma64_available(pa) to test if 64bit DMA addresses may be used.
This returns 1 iff _PCI_HAVE_DMA64 is defined in <machine/pci_machdep.h>,
and there is more than 4G of memory.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.69 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.68 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.67 20-Aug-2022  riastradh x86: Move struct vm_page_md to common x86/pmap.h.
 1.66 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.65 17-Mar-2020  ad Always set PTEs using atomics. There are too many assumptions to go wrong.
 1.64 14-Nov-2019  maxv Add support for Kernel Memory Sanitizer (kMSan). It detects uninitialized
memory used by the kernel at run time, and just like kASan and kCSan, it
is an excellent feature. It has already detected 38 uninitialized variables
in the kernel during my testing, which I have since discreetly fixed.

We use two shadows:
- "shad", to track uninitialized memory with a bit granularity (1:1).
Each bit set to 1 in the shad corresponds to one uninitialized bit of
real kernel memory.
- "orig", to track the origin of the memory with a 4-byte granularity
(1:1). Each uint32_t cell in the orig indicates the origin of the
associated uint32_t of real kernel memory.

The memory consumption of these shadows is consequent, so at least 4GB of
RAM is recommended to run kMSan.

The compiler inserts calls to specific __msan_* functions on each memory
access, to manage both the shad and the orig and detect uninitialized
memory accesses that change the execution flow (like an "if" on an
uninitialized variable).

We mark as uninit several types of memory buffers (stack, pools, kmem,
malloc, uvm_km), and check each buffer passed to copyout, copyoutstr,
bwrite, if_transmit_lock and DMA operations, to detect uninitialized memory
that leaves the system. This allows us to detect kernel info leaks in a way
that is more efficient and also more user-friendly than KLEAK.

Contrary to kASan, kMSan requires comprehensive coverage, ie we cannot
tolerate having one non-instrumented function, because this could cause
false positives. kMSan cannot instrument ASM functions, so I converted
most of them to __asm__ inlines, which kMSan is able to instrument. Those
that remain receive special treatment.

Contrary to kASan again, kMSan uses a TLS, so we must context-switch this
TLS during interrupts. We use different contexts depending on the interrupt
level.

The orig tracks precisely the origin of a buffer. We use a special encoding
for the orig values, and pack together in each uint32_t cell of the orig:
- a code designating the type of memory (Stack, Pool, etc), and
- a compressed pointer, which points either (1) to a string containing
the name of the variable associated with the cell, or (2) to an area
in the kernel .text section which we resolve to a symbol name + offset.

This encoding allows us not to consume extra memory for associating
information with each cell, and produces a precise output, that can tell
for example the name of an uninitialized variable on the stack, the
function in which it was pushed on the stack, and the function where we
accessed this uninitialized variable.

kMSan is available with LLVM, but not with GCC.

The code is organized in a way that is similar to kASan and kCSan, so it
means that other architectures than amd64 can be supported.
 1.63 01-Nov-2019  maxv Fix KUBSAN: the kernel size now exceeds the mapping limit, so bump the
limit.
 1.62 07-Aug-2019  maxv Add support for USER_LDT in SVS. This allows us to have both enabled at
the same time.

We allocate an LDT for each CPU in the GDT and map an area for it, in
addition to the default LDT already present. In context switches between
different processes, we choose between the default or the per-cpu LDT
selector: if the user set specific LDT entries, we memcpy them to the
per-cpu LDT and load the per-cpu selector.

Tested by Naveen Narayanan (with Wine on amd64).
 1.61 29-May-2019  maxv Add PCID support in SVS. This avoids TLB flushes during kernel<->user
transitions, which greatly reduces the performance penalty introduced by
SVS.

We use two ASIDs, 0 (kern) and 1 (user), and use invpcid to flush pages
in both ASIDs.

The read-only machdep.svs.pcid={0,1} sysctl is added, and indicates whether
SVS+PCID is in use.
 1.60 09-Mar-2019  maxv New software PTE bits.
 1.59 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.58 19-Nov-2018  maxv Introduce pl_pi, will be used soon.
 1.57 19-Nov-2018  maxv Rename 'mask' -> 'frame', we will use the real 'mask' soon.
 1.56 29-Aug-2018  maxv Remove the constants of the DMAP, they are unused, and move NL4_SLOT_DIRECT
into amd64/.
 1.55 20-Aug-2018  maxv Add support for kASan on amd64. Written by me, with some parts inspired
from Siddharth Muralee's initial work. This feature can detect several
kinds of memory bugs, and it's an excellent feature.

It can be enabled by uncommenting these three lines in GENERIC:

#makeoptions KASAN=1 # Kernel Address Sanitizer
#options KASAN
#no options SVS

The kernel is compiled without SVS, without DMAP and without PCPU area.
A shadow area is created at boot time, and it can cover the upper 128TB
of the address space. This area is populated gradually as we allocate
memory. With this design the memory consumption is kept at its lowest
level.

The compiler calls the __asan_* functions each time a memory access is
done. We verify whether this access is legal by looking at the shadow
area.

We declare our own special memcpy/memset/etc functions, because the
compiler's builtins don't add the __asan_* instrumentation.

Initially all the mappings are marked as valid. During dynamic
allocations, we add a redzone, which we mark as invalid. Any access on
it will trigger a kASan error message. Additionally, the compiler adds
a redzone on global variables, and we mark these redzones as invalid too.
The illegal-access detection works with a 1-byte granularity.

For now, we cover three areas:

- global variables
- kmem_alloc-ated areas
- malloc-ated areas

More will come, but that's a good start.
 1.54 17-Aug-2018  maxv Remove big outdated comment, remove unused macros, remove XXX that has
nothing to do here, style.
 1.53 12-Aug-2018  maxv More ASLR: randomize the location of the PTE area. The PTE slot is not
created in locore anymore, but a little later; by using the already
entered L4 page, rather than the recursive slot itself (which doesn't
exist yet).

In the prekern we still map the slot - the prekern behaves as an external
locore -, because we need it as part of the randomization/relocation
work. The kernel then removes this slot, and regenerates a randomized
one.

Tested on GENERIC and GENERIC_KASLR, Xen doesn't have it and dom0 still
boots fine.
 1.52 12-Aug-2018  maxv Move the PTE area from slot 255 to slot 509. I've never understood why we
put it on 255; the "kernel" half of the VM space begins on slot 256, so
if anything, the PTE area should have been above it, not below.

Virtually extend the user slots in slotspace, because we don't want
(randomized) kernel mappings to land on slot 255.

The prekern is updated accordingly.

Tested on GENERIC, GENERIC_KASLR and XEN3_DOM0.
 1.51 12-Aug-2018  maxv Introduce PDIR_SLOT_USERLIM, which indicates the limit of the user slots.
Use it instead of PDIR_SLOT_PTE when we just want to iterate over the
user slots. Also use it in SVS, I had hardcoded 255 because there was no
proper define (which there now is).
 1.50 12-Aug-2018  maxv Randomize the main memory on Xen, same as native. Tested on amd64-dom0.
 1.49 12-Aug-2018  maxv More ASLR: randomize the kernel main memory. VM_MIN_KERNEL_ADDRESS becomes
variable, and its location is chosen at boot time. There is room for
improvement, since for now we ask for an alignment of NBPD_L4.

This is enabled by default in GENERIC, but not in Xen. Tested extensively
on GENERIC and GENERIC_KASLR, XEN3_DOM0 still boots fine.
 1.48 27-Jul-2018  maxv Remove KERN_BASE, unused. It has always been wrong anyway, the value
should have been passed into VA_SIGN_NEG().
 1.47 25-Jul-2018  maxv Remove NPTECL, unused.
 1.46 19-May-2018  jdolecek branches: 1.46.2;
add experimental new function uvm_direct_process(), to allow of read/writes
of contents of uvm pages without mapping them into kernel, using
direct map or moral equivalent; pmaps supporting the interface need
to provide pmap_direct_process() and define PMAP_DIRECT

implement the new interface for amd64; I hear alpha and mips might be relatively
easy to add too, but I lack the knowledge

part of resolution for PR kern/53124
 1.45 22-Feb-2018  maxv branches: 1.45.2;
Remove svs_pgg_update(). Instead of manually changing PG_G on each page,
we can disable the global-paging mechanism in %cr4 with CR4_PGE. Do that.

In addition, install CR4_PGE when SVS is disabled manually (via the
sysctl).

Now, doing "sysctl -w machdep.svs_enabled=0" restores the performance
completely, exactly as if SVS hadn't been enabled in the first place.
 1.44 22-Feb-2018  maxv Improve the SVS initialization.

Declare x86_patch_window_open() and x86_patch_window_close(), and globalify
x86_hotpatch().

Introduce svs_enable() in x86/svs.c, that does the SVS hotpatching.

Change svs_init() to take a bool. This function gets called twice; early
when the system just booted (and nothing is initialized), lately when at
least pmap_kernel has been initialized.
 1.43 18-Feb-2018  maxv Add svs_enabled, which defaults to 'true' when SVS is compiled (no dynamic
detection yet).
 1.42 21-Jan-2018  maxv Increase the size of the initial mapping of the kernel. KASLR kernels are
bigger than their GENERIC counterparts, and the limit will soon be hit on
them.
 1.41 07-Jan-2018  maxv Add a new option, SVS (for Separate Virtual Space), that unmaps kernel
pages when running in userland. For now, only the PTE area is unmapped.

Sent on tech-kern@.
 1.40 17-Jun-2017  maxv Increase the kernel heap size from 512GB to 32TB, in such a way that it
is able to map the maximum amount of ram supported twice (16TB x 2).
 1.39 11-Nov-2016  maxv branches: 1.39.8;
Remove useless values, and explain where some others come from
 1.38 22-Jul-2016  maxv Remove pmap_prealloc_lowmem_ptps on amd64. This function creates levels in
the page tree so that the first 2MB of virtual memory can be kentered in
L1.

Strictly speaking, the kernel should never kenter a virtual page below
VM_MIN_KERNEL_ADDRESS, because then it wouldn't be available in userland.
It used to need the first 2MB in order to map the CPU trampoline and the
initial VAs used by the bootstrap code. Now, the CPU trampoline VA is
allocated with uvm_km_alloc and the VAs used by the bootstrap code are
allocated with pmap_bootstrap_valloc, and in either case the resulting VA
is above VM_MIN_KERNEL_ADDRESS.

The low levels in the page tree are therefore unused. By removing this
function, we are making sure no one will be tempted to map an area below
VM_MIN_KERNEL_ADDRESS in kernel mode, and particularly, we are making sure
NULL cannot be kentered.

In short, there is no way to map NULL in kernel mode anymore.
 1.37 21-May-2016  maxv branches: 1.37.2;
Explain where this value comes from.
 1.36 14-May-2016  maxv KNF so it appears aligned on NXR, and fix a comment.
 1.35 09-Jan-2015  riastradh Bump amd64 module map size to 32 MB.

For lack of anything better to do, after no progress in discussion on
the matter:

https://mail-index.netbsd.org/port-amd64/2014/08/22/msg002108.html

Needed in order to load the (solaris module needed by) dtrace module.
 1.34 30-Jun-2012  jym branches: 1.34.2; 1.34.14; 1.34.16;
Extend the xpmap API, as described in [1]. This change is mechanical and
avoids exposing the MD phys_to_machine/machine_to_phys tables directly.
Added:

- xpmap_ptom handles PFN (pseudo physical) to MFN (machine frame number)
translations, and is under control of the domain.
- xpmap_mtop is its counterpart (MFN to PFN), and is under control of
hypervisor.

xpmap_ptom_map() map a pseudo-phys address to a machine address
xpmap_ptom_unmap() unmap a pseudo-phys address (invalidation)
xpmap_ptom_isvalid() check for pseudo-phys address validity

The parameters are physical/machine addresses, like bus_dma/bus_space(9).
As x86 MFNs are tracked by u_long (Xen's choice) while machine addresses
can be 64 bits entities (PAE), use ptoa() to avoid truncation when bit
shifting by PAGE_SHIFT.

I kept the same namespace (xpmap_) to avoid code churn.

[1] http://mail-index.netbsd.org/port-xen/2009/05/09/msg004951.html

XXX will document ptoa/atop/trunc_page separately.
 1.33 11-Jun-2012  chs allow more space for modules.
 1.32 19-Feb-2012  cherry Removing remaining references to the alternate PTE space. Modify documentation appropriately
 1.31 19-Jan-2012  bouyer branches: 1.31.2;
pmap_pte_set() is not supposed to be atomic, so only raise IPL, no need to
take pte_lock
 1.30 15-Jan-2012  cherry for xen on amd64 PDP_BASE points to the per-cpu ci->ci_kpm_pdir copy of *pmap_kernel()*'s L4 pdir, which is an alias for ci->ci_kpm_pdir. This is unlike PAE, where PDP_BASE points to the per-pmap pm_pdir consisting of 4 pages, the last of which is the "shadow". This "shadow" is not used directly in an active pmap, since it duplicates the kernel space and, for PAE, xen dissallows multiple cpus pointing to the same L3[3] page. Therefore, we use a per-cpu copy of the pmap_kernel() pdir's L3[3] page, ci->ci_pae_l3_pdir[3], while L3[0-2] point to the original pmap's pm_pdir[0 - 2]. Thus the "shadow" pdir only exists on i386 PAE. Note that on PAE, the recursive PDIR_SLOT_PTE is not per-cpu, and therefore cannot be made to point to per-cpu pdirs via (L4_BASE + PDIR_SLOT_PTE), unlike xen x86_64 where this is exactly the case.
 1.29 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.28 06-Nov-2011  cherry branches: 1.28.4;
[merging from cherry-xenmp] make pmap_kernel() shadow PMD per-cpu and MP aware.
 1.27 06-Nov-2011  cherry [merging from cherry-xenmp] Make the xen MMU op queue locking api private. Implement per-cpu queues.
 1.26 27-Aug-2011  christos branches: 1.26.2;
Implement sparse dumps for amd64 (copied from i386). Disabled for now via
sysctl.
XXX: most of the code can be merged.
 1.25 13-Aug-2011  cherry Add locking around ops to the hypervisor MMU "queue".
 1.24 01-Feb-2011  chuck branches: 1.24.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.23 14-Nov-2010  uebayasi branches: 1.23.2; 1.23.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.22 26-Oct-2008  mrg branches: 1.22.8; 1.22.14; 1.22.16;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.21 23-Jan-2008  bouyer branches: 1.21.6; 1.21.10; 1.21.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.20 20-Jan-2008  bouyer Make first argument of Xen's pmap_pte_cas() volatile, fix a warning
building pmap.c.
 1.19 13-Jan-2008  yamt add pmap_pte_cas.
 1.18 03-Jan-2008  ad Bump NKL2_KIMG_ENTRIES to allow for 20MB of kernel.

Well past time for an in-kernel linker...
 1.17 28-Nov-2007  ad branches: 1.17.6;
Remove remaining CPUCLASS_386 tests.
 1.16 28-Nov-2007  ad Use the new atomic ops.
 1.15 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.14 18-Oct-2007  yamt branches: 1.14.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.13 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.12 27-Sep-2007  ad branches: 1.12.2;
Only include machine/cpufunc.h if _KERNEL.
 1.11 29-Aug-2007  ad branches: 1.11.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.10 21-Feb-2007  thorpej branches: 1.10.4; 1.10.10; 1.10.12; 1.10.16; 1.10.20; 1.10.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.9 16-Feb-2006  perry branches: 1.9.20;
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.8 24-Dec-2005  perry branches: 1.8.2; 1.8.4; 1.8.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.7 11-Dec-2005  christos merge ktrace-lwp.
 1.6 04-Jul-2005  blymn branches: 1.6.2;
Remove bogus external declaration for pdes, it appears not to be needed.
 1.5 08-Aug-2004  yamt kvtopte: use a correct base addr for LARGEPAGES.
 1.4 08-Aug-2004  yamt correct VAs in a comment.
 1.3 15-Jun-2004  fvdl Add a prototype for pmap_changeprot_local, a function that changes
protection for a page and doesn't care about TLB shootdowns.
 1.2 04-Jun-2004  sekiya Use the SPLAY_* macros. Copied from the i386 pmap, okay'ed by fvdl@
 1.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 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 12-Aug-2004  skrll Sync with HEAD.
 1.1.2.1 03-Aug-2004  skrll Sync with HEAD
 1.6.2.6 04-Feb-2008  yamt sync with head.
 1.6.2.5 21-Jan-2008  yamt sync with head
 1.6.2.4 07-Dec-2007  yamt sync with head
 1.6.2.3 27-Oct-2007  yamt sync with head.
 1.6.2.2 03-Sep-2007  yamt sync with head.
 1.6.2.1 26-Feb-2007  yamt sync with head.
 1.8.6.1 22-Apr-2006  simonb Sync with head.
 1.8.4.1 09-Sep-2006  rpaulo sync with head
 1.8.2.1 18-Feb-2006  yamt sync with head.
 1.9.20.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.10.22.3 23-Mar-2008  matt sync with HEAD
 1.10.22.2 09-Jan-2008  matt sync with HEAD
 1.10.22.1 06-Nov-2007  matt sync with HEAD
 1.10.20.6 03-Dec-2007  joerg Sync with HEAD.
 1.10.20.5 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.10.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.10.20.3 02-Oct-2007  joerg Sync with HEAD.
 1.10.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.10.20.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.10.16.1 03-Sep-2007  skrll Sync with HEAD.
 1.10.12.1 03-Oct-2007  garbled Sync with HEAD
 1.10.10.1 18-Apr-2007  thorpej Convert i386 and amd64 to the new atomic ops API.
 1.10.4.9 03-Dec-2007  ad Sync with HEAD.
 1.10.4.8 23-Oct-2007  ad Sync with head.
 1.10.4.7 12-Oct-2007  ad Remove unnecessary changes v head.
 1.10.4.6 09-Oct-2007  ad Sync with head.
 1.10.4.5 09-Oct-2007  ad Sync with head.
 1.10.4.4 09-Oct-2007  ad Sync with head.
 1.10.4.3 01-Sep-2007  ad Use pool_cache for allocating a few more types of objects.
 1.10.4.2 23-Aug-2007  ad Add pmap_pte_set, pmap_pte_setbits, pmap_pte_clearbits where missing.
 1.10.4.1 21-Aug-2007  ad amd64 changes, as yet untested:

- Adapt to vmlocking branch.
- Apply TLB shootdown and pv allocation changes to the pmap.
- Make it build.
 1.11.2.17 08-Oct-2007  yamt revive pmap_changeprot_local which has been removed mistakenly.
 1.11.2.16 08-Oct-2007  yamt fix the previous.
 1.11.2.15 08-Oct-2007  yamt merge some parts of x86 pmap.h.
 1.11.2.14 07-Oct-2007  yamt tweak assertions to reduce diffs between i386 and amd64.
 1.11.2.13 07-Oct-2007  yamt sync comments and whitespaces.
 1.11.2.12 07-Oct-2007  yamt rename PTDpaddr to PDPpaddr to match with i386.
(if you think it's a good idea to make gratuitous renames like this,
please do it for both of i386 and amd64 consistently.)
 1.11.2.11 07-Oct-2007  yamt sync with i386. remove some unused externs.
 1.11.2.10 07-Oct-2007  yamt remove some #ifdef _LOCORE and use genassym instead.
 1.11.2.9 07-Oct-2007  yamt sync with i386. no functional changes.
- kill __P
- ansify
 1.11.2.8 07-Oct-2007  yamt remove an unused definition.
 1.11.2.7 07-Oct-2007  yamt remove unused definitions.
 1.11.2.6 06-Oct-2007  yamt sync with head.
 1.11.2.5 04-Oct-2007  yamt remove LARGEPAGES option. always use large pages if available.
 1.11.2.4 30-Sep-2007  yamt implement deferred pmap switching for amd64, and make amd64 use
x86 shared pmap code. it makes several i386 pmap improvements available
to amd64, including tlb shootdown reduction and bug fixes from Stephan Uphoff.
 1.11.2.3 30-Sep-2007  yamt remove unused pmap_remove_record.
 1.11.2.2 30-Sep-2007  yamt - whitespace
- ptob -> x86_ptob
 1.11.2.1 29-Sep-2007  yamt u_int32_t -> uint32_t to reduce diffs from i386
 1.12.2.3 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.12.2.2 21-Oct-2007  bouyer Protect xpq_* usage with splvm()
Make sure xen_current_user_pgd really reflects what's in the hypervisor.
 1.12.2.1 17-Oct-2007  bouyer amd64 (aka x86-64) support for Xen. Based on the OpenBSD port done by
Mathieu Ropert in 2006.
DomU-only for now. An INSTALL_XEN3_DOMU kernel with a ramdisk will boot to
sysinst if you're lucky. Often it panics because a runable LWP has
a NULL stack (really, it's all of l->l_addr which is has been zeroed out
while the process was on the queue !)
TODO:
- bug fixes :)
- Most of the xpq_* functions should be shared with xen/i386
- The xen/i386 assembly bootstrap code should be remplaced with the C
version in xenamd64/amd64/xpmap.c
- see if a config(5) trick could allow to merge xenamd64 back to xen or amd64.
 1.14.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.14.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.17.6.5 20-Jan-2008  bouyer Sync with HEAD: make first argument of pmap_pte_cas() volatile.
 1.17.6.4 19-Jan-2008  bouyer Make things build again after sync with HEAD
 1.17.6.3 19-Jan-2008  bouyer Sync with HEAD
 1.17.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.17.6.1 08-Jan-2008  bouyer Sync with HEAD
 1.21.16.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.21.10.1 04-May-2009  yamt sync with head.
 1.21.6.1 17-Jan-2009  mjf Sync with HEAD.
 1.22.16.1 05-Mar-2011  rmind sync with head
 1.22.14.1 15-Nov-2010  uebayasi Sync with HEAD.
 1.22.8.3 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.22.8.2 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.22.8.1 10-Jan-2011  jym Sync with HEAD
 1.23.4.1 08-Feb-2011  bouyer Sync with HEAD
 1.23.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.24.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.24.2.2 20-Aug-2011  cherry PAE MP support (preliminary), amd64 per-cpu L4 model redesigned, i386 pmap_pa_start/end fixup
 1.24.2.1 03-Jun-2011  cherry Initial import of xen MP sources, with kernel and userspace tests.
- this is a source priview.
- boots to single user.
- spurious interrupt and pmap related panics are normal
 1.26.2.3 30-Oct-2012  yamt sync with head
 1.26.2.2 17-Apr-2012  yamt sync with head
 1.26.2.1 10-Nov-2011  yamt sync with head
 1.28.4.2 24-Feb-2012  mrg sync to -current.
 1.28.4.1 18-Feb-2012  mrg merge to -current.
 1.31.2.1 22-Nov-2012  riz Pull up following revision(s) (requested by chs in ticket #690):
external/cddl/osnet/dev/dtrace/amd64/dtrace_isa.c: revision 1.4
sys/arch/amd64/include/Makefile.inc: revision 1.4
sys/arch/amd64/include/pmap.h: revision 1.33
external/cddl/osnet/dev/dtrace/amd64/dtrace_subr.c: revision 1.6
sys/arch/amd64/include/asm.h: revision 1.15
sys/arch/amd64/amd64/genassym.cf: revision 1.51
external/cddl/osnet/dev/dtrace/amd64/dtrace_asm.S: revision 1.4
make dtrace work on amd64.
allow more space for modules.
 1.34.16.5 28-Aug-2017  skrll Sync with HEAD
 1.34.16.4 05-Dec-2016  skrll Sync with HEAD
 1.34.16.3 05-Oct-2016  skrll Sync with HEAD
 1.34.16.2 29-May-2016  skrll Sync with HEAD
 1.34.16.1 06-Apr-2015  skrll Sync with HEAD
 1.34.14.1 18-Mar-2015  snj Pull up following revision(s) (requested by riastradh in ticket #612):
sys/arch/amd64/include/pmap.h: revision 1.35
Bump amd64 module map size to 32 MB.
For lack of anything better to do, after no progress in discussion on
the matter:
https://mail-index.netbsd.org/port-amd64/2014/08/22/msg002108.html
Needed in order to load the (solaris module needed by) dtrace module.
 1.34.2.1 03-Dec-2017  jdolecek update from HEAD
 1.37.2.2 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.37.2.1 26-Jul-2016  pgoyette Sync with HEAD
 1.39.8.1 22-Mar-2018  martin Pull up the following revisions, requested by maxv in ticket #652:

sys/arch/amd64/amd64/amd64_trap.S upto 1.39 (partial, patch)
sys/arch/amd64/amd64/db_machdep.c 1.6 (patch)
sys/arch/amd64/amd64/genassym.cf 1.65,1.66,1.67 (patch)
sys/arch/amd64/amd64/locore.S upto 1.159 (partial, patch)
sys/arch/amd64/amd64/machdep.c 1.299-1.302 (patch)
sys/arch/amd64/amd64/trap.c upto 1.113 (partial, patch)
sys/arch/amd64/amd64/amd64/vector.S upto 1.61 (partial, patch)
sys/arch/amd64/conf/GENERIC 1.477,1.478 (patch)
sys/arch/amd64/conf/kern.ldscript 1.26 (patch)
sys/arch/amd64/include/frameasm.h upto 1.37 (partial, patch)
sys/arch/amd64/include/param.h 1.25 (patch)
sys/arch/amd64/include/pmap.h 1.41,1.43,1.44 (patch)
sys/arch/x86/conf/files.x86 1.91,1.93 (patch)
sys/arch/x86/include/cpu.h 1.88,1.89 (patch)
sys/arch/x86/include/pmap.h 1.75 (patch)
sys/arch/x86/x86/cpu.c 1.144,1.146,1.148,1.149 (patch)
sys/arch/x86/x86/pmap.c upto 1.289 (partial, patch)
sys/arch/x86/x86/vm_machdep.c 1.31,1.32 (patch)
sys/arch/x86/x86/x86_machdep.c 1.104,1.106,1.108 (patch)
sys/arch/x86/x86/svs.c 1.1-1.14
sys/arch/xen/conf/files.compat 1.30 (patch)

Backport SVS. Not enabled yet.
 1.45.2.4 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.45.2.3 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.45.2.2 28-Jul-2018  pgoyette Sync with HEAD
 1.45.2.1 21-May-2018  pgoyette Sync with HEAD
 1.46.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.46.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.46.2.1 10-Jun-2019  christos Sync with HEAD
 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.5 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.4 10-Mar-2017  maxv branches: 1.4.12; 1.4.14;
Move pmc.c into x86/, it can be shared with amd64.
 1.3 18-Feb-2017  maxv PERFCTRS -> PMC (not implemented anyway)
 1.2 20-Mar-2014  christos branches: 1.2.6; 1.2.10; 1.2.14;
make pmc compile with amd64
 1.1 26-Apr-2003  fvdl branches: 1.1.142; 1.1.152; 1.1.158;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.158.1 18-May-2014  rmind sync with head
 1.1.152.2 03-Dec-2017  jdolecek update from HEAD
 1.1.152.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.142.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.2.14.1 21-Apr-2017  bouyer Sync with HEAD
 1.2.10.1 20-Mar-2017  pgoyette Sync with HEAD
 1.2.6.1 28-Aug-2017  skrll Sync with HEAD
 1.4.14.1 10-Jun-2019  christos Sync with HEAD
 1.4.12.1 28-Jul-2018  pgoyette Sync with HEAD
 1.25 13-Jun-2020  ad Print a rate limited warning if the TSC timecounter goes backwards from the
viewpoint of any single LWP.
 1.24 13-Jan-2020  ad Remove now unused mdlwp fields md_gc_pmap and md_gc_ptp.
 1.23 12-Oct-2019  maxv branches: 1.23.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.22 25-Feb-2017  kamil branches: 1.22.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.21 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.20 15-Dec-2016  kamil branches: 1.20.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.19 20-Feb-2014  dsl branches: 1.19.6; 1.19.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.18 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.17 01-Dec-2013  christos revert fpu/pcu changes until we figure out what's wrong; they cause random
freezes
 1.16 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.15 15-Jul-2012  dsl branches: 1.15.2; 1.15.4;
Rename MDP_IRET to MDL_IRET since it is an lwp flag, not a proc one.
Add an MDL_COMPAT32 flag to the lwp's md_flags, set it for 32bit lwps
and use it to force 'return to user' with iret (as is done when
MDL_IRET is set).
Split the iret/sysret code paths much later.
Remove all the replicated code for 32bit system calls - which was only
needed so that iret was always used.
frameasm.h for XEN contains '#define swapgs', while XEN probable never
needs swapgs, this is likely to be confusing.
Add a SWAPGS which is a nop on XEN and swapgs otherwise.
(I've not yet checked all the swapgs in files that include frameasm.h)
Simple x86 programs still work.
Hijack 6.99.9 kernel bump (needed for compat32 modules)
 1.14 08-Jul-2012  dsl The MDP_USEDFPU (amd64 and sh3) and MDP_SSTEP (sh3) are lwp flags not
process ones, rename to MDL_xxx.
 1.13 14-Jan-2011  rmind branches: 1.13.8;
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.12 14-Mar-2009  dsl branches: 1.12.4;
Remove all the __P() from sys (excluding sys/dist)
Diff checked with grep and MK1 eyeball.
i386 and amd64 GENERIC and sys still build.
 1.11 26-Oct-2008  mrg branches: 1.11.2; 1.11.8;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.10 05-Jun-2008  ad branches: 1.10.4;
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.9 08-Jan-2008  yamt branches: 1.9.6; 1.9.8; 1.9.10; 1.9.12;
change the layout in u-area and reduce UPAGES.
 1.8 05-Jan-2008  yamt - make amd64 use per-cpu tss.
- fix iopl syscall for amd64+xen.
 1.7 16-Nov-2007  skrll branches: 1.7.6;
s/proc/lwp/ in comment
 1.6 09-Feb-2007  ad branches: 1.6.6; 1.6.22; 1.6.24; 1.6.28; 1.6.30;
Merge newlock2 to head.
 1.5 24-Dec-2005  perry branches: 1.5.20;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.4 11-Dec-2005  christos merge ktrace-lwp.
 1.3 20-Aug-2003  fvdl branches: 1.3.16;
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.2 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.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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.3.16.4 21-Jan-2008  yamt sync with head
 1.3.16.3 07-Dec-2007  yamt sync with head
 1.3.16.2 26-Feb-2007  yamt sync with head.
 1.3.16.1 21-Jun-2006  yamt sync with head.
 1.5.20.1 20-Oct-2006  ad Make ASTs per-LWP.
 1.6.30.2 18-Feb-2008  mjf Sync with HEAD.
 1.6.30.1 19-Nov-2007  mjf Sync with HEAD.
 1.6.28.1 18-Nov-2007  bouyer Sync with HEAD
 1.6.24.1 09-Jan-2008  matt sync with HEAD
 1.6.22.1 21-Nov-2007  joerg Sync with HEAD.
 1.6.6.1 03-Dec-2007  ad Sync with HEAD.
 1.7.6.1 08-Jan-2008  bouyer Sync with HEAD
 1.9.12.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.9.10.1 04-May-2009  yamt sync with head.
 1.9.8.1 17-Jun-2008  yamt sync with head.
 1.9.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.9.6.1 29-Jun-2008  mjf Sync with HEAD.
 1.10.4.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.11.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.11.8.2 01-Nov-2009  jym Sync with HEAD.
 1.11.8.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.11.2.1 28-Apr-2009  skrll Sync with HEAD.
 1.12.4.1 05-Mar-2011  rmind sync with head
 1.13.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.13.8.1 30-Oct-2012  yamt sync with head
 1.15.4.1 18-May-2014  rmind sync with head
 1.15.2.2 03-Dec-2017  jdolecek update from HEAD
 1.15.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.19.10.2 20-Mar-2017  pgoyette Sync with HEAD
 1.19.10.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.19.6.2 28-Aug-2017  skrll Sync with HEAD
 1.19.6.1 05-Feb-2017  skrll Sync with HEAD
 1.20.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.22.14.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.22.14.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.23.2.1 17-Jan-2020  ad Sync with head.
 1.21 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.20 17-Apr-2021  rillig sys/arch/amd64: remove trailing whitespace
 1.19 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.18 11-Apr-2016  bouyer branches: 1.18.18;
x86_lfence() calls mcount(), so inline lfence instructions in mcount
helper functions
 1.17 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.16 12-Sep-2013  joerg branches: 1.16.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.15 26-Oct-2008  mrg branches: 1.15.28; 1.15.38; 1.15.44;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.14 25-May-2008  chs branches: 1.14.4;
fix profiling compilation.
 1.13 21-Apr-2008  cegger branches: 1.13.2; 1.13.4;
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 20-Dec-2007  ad branches: 1.12.6; 1.12.8;
- 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.11 24-Nov-2007  bouyer branches: 1.11.2; 1.11.6;
Make Xen profiling kernels work.
XXX assembly still needs to be fixed for non-Xen kernels.
 1.10 17-Oct-2007  garbled branches: 1.10.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.9 27-Sep-2007  ad Sync with i386.
 1.8 26-Sep-2007  xtraeme Fix profiling kernels:

read_psl -> x86_read_psl
write_psl -> x86_write_psl
disable_intr -> x86_disable_intr
 1.7 09-Feb-2007  ad branches: 1.7.6; 1.7.12; 1.7.14; 1.7.22; 1.7.24; 1.7.26;
Merge newlock2 to head.
 1.6 03-Feb-2006  skrll branches: 1.6.16;
Make sure we generate the right call with -fPIC.
 1.5 11-Dec-2005  christos branches: 1.5.2; 1.5.4;
merge ktrace-lwp.
 1.4 22-Sep-2005  chs pull in changes from i386 profile.h:
- allow profiling of MP kernels, add a spinlock around the body of mcount().
fixes PR 31360.
- save and restore eflags instead of just doing cli/sti.
 1.3 28-Nov-2003  fvdl branches: 1.3.14; 1.3.16;
Define the mcount function in assembler, and have it save all registers
used for argument passing, plus %rax (used to pass the number of float
arguments to varargs functions), to avoid having it clobber caller-saved
registers. mcount is emitted "under the radar", so the compiler doesn't
know it should do this.

Change the kernel mcount entry/exit macros to use plain cli/sti, like on i386.
 1.2 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.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.2.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 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.3.16.5 21-Jan-2008  yamt sync with head
 1.3.16.4 07-Dec-2007  yamt sync with head
 1.3.16.3 27-Oct-2007  yamt sync with head.
 1.3.16.2 26-Feb-2007  yamt sync with head.
 1.3.16.1 21-Jun-2006  yamt sync with head.
 1.3.14.1 30-Sep-2005  tron Pull up following revision(s) (requested by chs in ticket #831):
sys/arch/amd64/include/profile.h: revision 1.4
pull in changes from i386 profile.h:
- allow profiling of MP kernels, add a spinlock around the body of mcount().
fixes PR 31360.
- save and restore eflags instead of just doing cli/sti.
 1.5.4.1 09-Sep-2006  rpaulo sync with head
 1.5.2.1 18-Feb-2006  yamt sync with head.
 1.6.16.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.7.26.1 06-Oct-2007  yamt 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.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.7.22.1 02-Oct-2007  joerg Sync with HEAD.
 1.7.14.1 03-Oct-2007  garbled Sync with HEAD
 1.7.12.1 18-Apr-2007  thorpej Convert i386 and amd64 to the new atomic ops API.
 1.7.6.3 03-Dec-2007  ad Sync with HEAD.
 1.7.6.2 03-Dec-2007  ad Sync with HEAD.
 1.7.6.1 09-Oct-2007  ad Sync with head.
 1.10.2.2 27-Dec-2007  mjf Sync with HEAD.
 1.10.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.11.6.1 02-Jan-2008  bouyer Sync with HEAD
 1.11.2.1 26-Dec-2007  ad Sync with head.
 1.12.8.2 04-Jun-2008  yamt sync with head
 1.12.8.1 18-May-2008  yamt sync with head.
 1.12.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.12.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.13.4.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.13.2.1 04-May-2009  yamt sync with head.
 1.14.4.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.15.44.1 18-May-2014  rmind sync with head
 1.15.38.2 03-Dec-2017  jdolecek update from HEAD
 1.15.38.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.15.28.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.16.6.2 22-Apr-2016  skrll Sync with HEAD
 1.16.6.1 19-Mar-2016  skrll Sync with HEAD
 1.18.18.1 10-Jun-2019  christos Sync with HEAD
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.17 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.16 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.15 20-Aug-2022  riastradh amd64/pte.h, i386/pte.h: Need sys/stdint.h for uintN_t.
 1.14 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.13 25-Apr-2020  maxv Switch to the new PTE naming. The old naming is now unused, remove it.
 1.12 09-Mar-2019  maxv branches: 1.12.10;
Start replacing the x86 PTE bits.
 1.11 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.10 07-Mar-2019  maxv Drop PG_RO, PG_KR and PG_PROT, they are useless and create confusion.
 1.9 13-May-2016  maxv branches: 1.9.18;
KNF, so it appears aligned on NXR.
 1.8 24-Jul-2010  njoly branches: 1.8.18; 1.8.36;
Pull i386 pte.h on amd64 for 32bit compat.
 1.7 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.6 26-Feb-2010  jym branches: 1.6.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.5 28-Jan-2010  mbalmer branches: 1.5.2;
Fix language.
 1.4 16-Apr-2008  cegger branches: 1.4.4; 1.4.18;
use POSIX integer types
 1.3 11-Dec-2005  christos branches: 1.3.74;
merge ktrace-lwp.
 1.2 19-Feb-2004  drochner use no-execute page permissions if supported
 1.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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.3.74.1 02-Jun-2008  mjf Sync with HEAD.
 1.4.18.1 24-Oct-2010  jym Sync with HEAD
 1.4.4.2 11-Aug-2010  yamt sync with head.
 1.4.4.1 11-Mar-2010  yamt sync with head
 1.5.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.5.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.6.2.1 05-Mar-2011  rmind sync with head
 1.8.36.1 29-May-2016  skrll Sync with HEAD
 1.8.18.1 03-Dec-2017  jdolecek update from HEAD
 1.9.18.1 10-Jun-2019  christos Sync with HEAD
 1.12.10.1 25-Apr-2020  bouyer Sync with bouyer-xenpvh-base2 (HEAD)
 1.23 20-Nov-2023  simonb Note some large xstate stack objects what Somebody(tm) should look at
when they find some round tuits.
 1.22 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.21 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.20 02-Dec-2019  kamil branches: 1.20.2;
Define PT_GETXMMREGS and PT_SETXMMREGS in PT_MACHDEP_STRINGS/amd64
 1.19 27-Nov-2019  rin Add support for PT_[GS]ETXMMREGS requests for COMPAT_NETBSD32 on amd64.

For this purpose, PT_[GS]ETXMMREGS are added to amd64/ptrace.h. These
are intended for internal usage for COMPAT_NETBSD32, and therefore not
exposed to userland.

Thanks to kamil, mgorny, and pgoyette for their kind review!

XXX
pullup to netbsd-9
 1.18 27-Nov-2019  rin Rename process_machdep_validxstate() to process_machdep_validfpu(), as
this function will be used to check validity of XMM registers also.
 1.17 27-Nov-2019  rin Fix copy-paste in comment. No binary changes.
 1.16 26-Jun-2019  mgorny 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.15 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.14 04-Jun-2019  mgorny compat32: Translate userland PT_* request values into kernel codes

Currently, the compat32 passes PT_* request values to kernel functions
without translation. This works fine for low PT_* requests that happen
to have the same values both on i386 and amd64. However, for requests
higher than PT_SETFPREGS, the value passed from userland (matching i386
const) does not match the correct kernel (amd64) request. As a result,
e.g. when compat32 process calls PT_GETDBREGS, kernel actually processes
it as PT_SETSTEP.

To resolve this, introduce support for compat32 PT_* request
translation. The interface is based on PTRACE_TRANSLATE_REQUEST32 macro
that is defined to a mapping function on architectures needing it.
In case of amd64, this function maps userland i386 PT_* values into
appropriate amd64 PT_* values.

For the time being, the two additional PT_GETXMMREGS and PT_SETXMMREGS
requests are unsupported due to lack of matching free amd64 constant.
 1.13 07-Feb-2019  kamil Define PTRACE_ILLEGAL_ASM for NetBSD/amd64 in ptrace.h

Use ud2 instruction that is guaranteed to raise an invalid instruction
exception (through SIGILL).

On NetBSD and FreeBSD this instruction raises ILL_PRVOPC, on Linux
ILL_ILLOPN. It's not clear which opion is better "Privileged opcode" vs
"Illegal operand", because ud2 doesn't seem to be a privileged operation
and it doesn't take any operand.

Assume in future changes that this opcode will raise ILL_PRVOPC and keep
it purely for testing purposes of the SIGILL crash type.
 1.12 12-Apr-2017  kamil branches: 1.12.12;
Add new macro PTRACE_BREAKPOINT_ASM in <sys/ptrace.h> MD part

This macro ships with a MD-specific assembly instruction triggering
a software breakpoint.

Missing instruction for powerpc targets.

This code is used in ATF tests (lib/libc/sys/t_ptrace_wait).

Original patch by Nick Hudson, thanks!
 1.11 08-Apr-2017  kamil Add new ptrace(2) API: PT_SETSTEP & PT_CLEARSTEP

These operations allow to mark thread as a single-stepping one.

This allows to i.a.:
- single step and emit a signal (PT_SETSTEP & PT_CONTINUE)
- single step and trace syscall entry and exit (PT_SETSTEP & PT_SYSCALL)

The former is useful for debuggers like GDB or LLDB. The latter can be used
to singlestep a usermode kernel. These examples don't limit use-cases of
this interface.

Define PT_*STEP only for platforms defining PT_STEP.

Add new ATF tests setstep[1234].

These ptrace(2) operations first appeared in FreeBSD.

Sponsored by <The NetBSD Foundation>
 1.10 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.9 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.8 15-Dec-2016  kamil branches: 1.8.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.7 19-Oct-2016  skrll PR kern/51514: ptrace(2) fails for 32-bit process on 64-bit kernel

Updated from the original patch in the PR by me.
 1.6 25-Sep-2015  christos branches: 1.6.2;
For processors that have memory breakpoints, add macros for them to help
libproc
 1.5 17-Sep-2015  christos fix 32 bit build.
 1.4 15-Sep-2015  christos Provide access to pc/sp/syscall-return registers like we have for mcontext
 1.3 16-Apr-2007  njoly branches: 1.3.80; 1.3.100;
Add PT_MACHDEP_STRINGS, for kdump output.
 1.2 12-Mar-2006  cube branches: 1.2.16; 1.2.20; 1.2.22;
Support the generation of coredumps for 32-bits binaries under
COMPAT_NETBSD32. They haven't worked for 5 years.

Silently agreed by the tech-kern readers.

XXX sparc64 MD glue still lacking.
XXX The FPU registers on i386 are not dumped correctly, according to my
XXX tests. It shouldn't be much work for someone who has the slightest
XXX idea of how that stuff is supposed to be laid out on i386.
 1.1 26-Apr-2003  fvdl branches: 1.1.18; 1.1.32; 1.1.34; 1.1.36; 1.1.38;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.38.1 19-Apr-2006  elad sync with head - hopefully this will work
 1.1.36.1 13-Mar-2006  yamt sync with head.
 1.1.34.1 22-Apr-2006  simonb Sync with head.
 1.1.32.1 09-Sep-2006  rpaulo sync with head
 1.1.18.2 03-Sep-2007  yamt sync with head.
 1.1.18.1 21-Jun-2006  yamt sync with head.
 1.2.22.1 11-Jul-2007  mjf Sync with head.
 1.2.20.1 27-May-2007  ad Sync with head.
 1.2.16.1 07-May-2007  yamt sync with head.
 1.3.100.5 28-Aug-2017  skrll Sync with HEAD
 1.3.100.4 05-Feb-2017  skrll Sync with HEAD
 1.3.100.3 05-Dec-2016  skrll Sync with HEAD
 1.3.100.2 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.3.100.1 22-Sep-2015  skrll Sync with HEAD
 1.3.80.1 03-Dec-2017  jdolecek update from HEAD
 1.6.2.4 26-Apr-2017  pgoyette Sync with HEAD
 1.6.2.3 20-Mar-2017  pgoyette Sync with HEAD
 1.6.2.2 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.6.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.8.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.12.12.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.12.12.1 10-Jun-2019  christos Sync with HEAD
 1.20.2.1 17-Jan-2020  ad Sync with head.
 1.2 15-Dec-2009  snj Move to 2-clause license. Approved by HAYAKAWA Koichi (copyright holder).
 1.1 21-Dec-2005  rjs branches: 1.1.18; 1.1.80; 1.1.94;
Add boilerplate for cardbus support.
 1.1.94.1 24-Oct-2010  jym Sync with HEAD
 1.1.80.1 11-Mar-2010  yamt sync with head
 1.1.18.2 21-Jun-2006  yamt sync with head.
 1.1.18.1 21-Dec-2005  yamt file rbus_machdep.h was added on branch yamt-lazymbuf on 2006-06-21 14:48:25 +0000
 1.11 22-May-2022  andvar fix various small typos, mainly in comments.
 1.10 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.9 11-Feb-2014  dsl branches: 1.9.6; 1.9.10; 1.9.14;
Move sys/arch/amd64/amd64/fpu.c and sys/arch/amd64/include/fpu.h
into sys/arch/x86 in preparation for using the same code for i386.
 1.8 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.7 26-Oct-2008  mrg branches: 1.7.28; 1.7.38; 1.7.44;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.6 05-Jan-2008  dsl branches: 1.6.6; 1.6.10; 1.6.16;
Reorder the amd64 trapframe (swap rcx/r10 and add 4 spare slots after r9).
This allows the syscall code to pass the syscall args directly from the
trapframe instead of copying them to a separate structure.
It is still possible that some lurking code still assumes that
'struct trapframe', 'struct mcontext' and 'struct reg' all have the
registers in the same order, but I've fixed enough of them to get gdb working.
 1.5 10-Jul-2006  fvdl branches: 1.5.34; 1.5.40; 1.5.48;
kern/33961: add kgdb support and remove some redundant (and incorrect) register
offset definitions from reg.h
 1.4 11-Dec-2005  christos branches: 1.4.4; 1.4.8; 1.4.16;
merge ktrace-lwp.
 1.3 18-Jun-2004  jmc branches: 1.3.12;
Pull in machine/fpu.h to pick up fxsave64
 1.2 07-Aug-2003  agc branches: 1.2.4;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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.2.4.1 29-Aug-2005  tron Pull up following revision(s) (requested by riz in ticket #5621):
sys/arch/amd64/include/reg.h: revision 1.3
Pull in machine/fpu.h to pick up fxsave64
 1.3.12.2 21-Jan-2008  yamt sync with head
 1.3.12.1 30-Dec-2006  yamt sync with head.
 1.4.16.1 13-Jul-2006  gdamore Merge from HEAD.
 1.4.8.1 11-Aug-2006  yamt sync with head
 1.4.4.1 09-Sep-2006  rpaulo sync with head
 1.5.48.1 08-Jan-2008  bouyer Sync with HEAD
 1.5.40.1 18-Feb-2008  mjf Sync with HEAD.
 1.5.34.1 09-Jan-2008  matt sync with HEAD
 1.6.16.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.6.10.1 04-May-2009  yamt sync with head.
 1.6.6.1 17-Jan-2009  mjf Sync with HEAD.
 1.7.44.1 18-May-2014  rmind sync with head
 1.7.38.2 03-Dec-2017  jdolecek update from HEAD
 1.7.38.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.7.28.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.9.14.1 21-Apr-2017  bouyer Sync with HEAD
 1.9.10.1 20-Mar-2017  pgoyette Sync with HEAD
 1.9.6.1 28-Aug-2017  skrll Sync with HEAD
 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 22-Jan-2020  ad Back out previous.
 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:05:44 +0000
 1.38 17-Apr-2021  rillig sys/arch/amd64: remove trailing whitespace
 1.37 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.36 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.35 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.34 31-Dec-2017  maxv branches: 1.34.2; 1.34.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.33 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.32 01-Nov-2017  maxv Remove unused macros and LDT entries.
 1.31 15-Oct-2017  maxv Use two separate functions: cpu_segregs32_zero and cpu_segregs64_zero. The
way segment registers work on amd64 will diverge between 32bit and 64bit
LWPs.
 1.30 17-Sep-2017  maxv Remove the second argument from USERMODE and KERNELMODE, it is unused
now that we don't have vm86 anymore.
 1.29 05-Feb-2017  maxv branches: 1.29.6;
Remove misleading comment; these macros should not be used if a user LDT
is active.
 1.28 02-Sep-2016  maxv branches: 1.28.2;
Give the structure sizes.
 1.27 27-Aug-2016  maxv Remove idt_init.
 1.26 27-Aug-2016  maxv Rename this value, and use it.
 1.25 21-Aug-2016  maxv KNF, and typo.
 1.24 07-Jan-2013  chs branches: 1.24.12; 1.24.14; 1.24.16; 1.24.18; 1.24.22;
rearrange the LDT entries so that (32-bit) COMPAT_10 binaries work again.
in long mode, call gates use two slots, so the first entry (a call gate)
would overlap the second one (the 32-bit user code descriptor).
 1.23 16-Jun-2012  dsl branches: 1.23.2;
memseg_baseaddr() is only called from valid_user_selector() and
both only locally.
Make static, remove one of the functions, and remove the never-set args.
Code is still very dubious.
 1.22 07-Feb-2011  chs branches: 1.22.4; 1.22.10; 1.22.14; 1.22.16;
move macros for validating fs/gs to segments.h and use them
in the linux32 code as well.
 1.21 05-Sep-2010  chs branches: 1.21.2; 1.21.4;
in check_mcontext32(), accept the LDT selector for 32-bit user code
as well as the GDT selector. fixes PR 43835.
 1.20 07-Jul-2010  chs add the guts of TLS support on amd64. based on joerg's patch,
reworked by me to support 32-bit processes as well.
we now keep %fs and %gs loaded with the user values
while in the kernel, which means we don't need to
reload them when returning to user mode.
 1.19 26-Oct-2008  mrg branches: 1.19.4; 1.19.8; 1.19.10; 1.19.12; 1.19.14; 1.19.16;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.18 19-Apr-2008  cegger branches: 1.18.2; 1.18.8;
idt_* are not implemented for Xen. So don't provide the prototypes for Xen.
 1.17 16-Apr-2008  cegger branches: 1.17.2;
use POSIX integer types
 1.16 26-Dec-2007  yamt branches: 1.16.6;
- 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.15 25-Dec-2007  perry Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.14 23-Nov-2007  bouyer branches: 1.14.2; 1.14.6;
Include opt_xen.h #ifdef _KERNEL_OPT instead of custom logic.
Thanks to Izumi Tsutsui for pointing me at _KERNEL_OPT
 1.13 22-Nov-2007  bouyer Fix bouyer-xenamd64 merge fallout:
we can #include "opt_xen.h" when
#if defined(_KERNEL) && !defined(_RUMPKERNEL) && !defined(_LKM),
#ifdef _KERNEL isn't enough.
 1.12 22-Nov-2007  bouyer only include opt_xen.h #ifdef _KERNEL
 1.11 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.10 18-Oct-2007  yamt branches: 1.10.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.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 26-Sep-2007  mrg branches: 1.8.2;
in VALID_USER_DSEL3() only check the low 16 bits.

this fixes 32bit gmake from occasionally reporting "Error 255" after
a command has successfully run.

lots of help from ad@ and joerg@.
 1.7 19-Aug-2006  dsl branches: 1.7.12; 1.7.20; 1.7.30; 1.7.32; 1.7.34;
de __P()
 1.6 11-Dec-2005  christos branches: 1.6.4; 1.6.8;
merge ktrace-lwp.
 1.5 15-May-2005  fvdl branches: 1.5.2;
Optionally include saving and restoring the 64bit %gs and %fs base register
values in the PCB. Do this in pmap_activate for now (XXX not a good place
for it, but a convenient one).
 1.4 13-Feb-2004  wiz Uppercase CPU, plural is CPUs.
 1.3 13-Oct-2003  fvdl Define a few macros to validate userspace selectors.
 1.2 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.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.2.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 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.5.2.4 21-Jan-2008  yamt sync with head
 1.5.2.3 07-Dec-2007  yamt sync with head
 1.5.2.2 27-Oct-2007  yamt sync with head.
 1.5.2.1 30-Dec-2006  yamt sync with head.
 1.6.8.1 03-Sep-2006  yamt sync with head.
 1.6.4.1 09-Sep-2006  rpaulo sync with head
 1.7.34.2 18-Oct-2007  yamt remove unused GDT_SYS_OFFSET.
 1.7.34.1 06-Oct-2007  yamt sync with head.
 1.7.32.2 09-Jan-2008  matt sync with HEAD
 1.7.32.1 06-Nov-2007  matt sync with HEAD
 1.7.30.3 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.7.30.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.7.30.1 02-Oct-2007  joerg Sync with HEAD.
 1.7.20.1 03-Oct-2007  garbled Sync with HEAD
 1.7.12.3 03-Dec-2007  ad Sync with HEAD.
 1.7.12.2 23-Oct-2007  ad Sync with head.
 1.7.12.1 09-Oct-2007  ad Sync with head.
 1.8.2.2 25-Oct-2007  bouyer Sync with HEAD.
 1.8.2.1 17-Oct-2007  bouyer amd64 (aka x86-64) support for Xen. Based on the OpenBSD port done by
Mathieu Ropert in 2006.
DomU-only for now. An INSTALL_XEN3_DOMU kernel with a ramdisk will boot to
sysinst if you're lucky. Often it panics because a runable LWP has
a NULL stack (really, it's all of l->l_addr which is has been zeroed out
while the process was on the queue !)
TODO:
- bug fixes :)
- Most of the xpq_* functions should be shared with xen/i386
- The xen/i386 assembly bootstrap code should be remplaced with the C
version in xenamd64/amd64/xpmap.c
- see if a config(5) trick could allow to merge xenamd64 back to xen or amd64.
 1.10.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.10.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.14.6.1 02-Jan-2008  bouyer Sync with HEAD
 1.14.2.1 26-Dec-2007  ad Sync with head.
 1.16.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.16.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.17.2.1 18-May-2008  yamt sync with head.
 1.18.8.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.18.2.3 09-Oct-2010  yamt sync with head
 1.18.2.2 11-Aug-2010  yamt sync with head.
 1.18.2.1 04-May-2009  yamt sync with head.
 1.19.16.1 05-Mar-2011  rmind sync with head
 1.19.14.2 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.19.14.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.19.12.1 20-May-2011  matt bring matt-nb5-mips64 up to date with netbsd-5-1-RELEASE (except compat).
 1.19.10.1 07-Sep-2010  bouyer Pull up following revision(s) (requested by chs in ticket #1449):
sys/arch/amd64/amd64/netbsd32_machdep.c: revisions 1.66, 1.67
sys/arch/amd64/include/segments.h: revision 1.21
in check_mcontext32(), accept the LDT selector for 32-bit user code
as well as the GDT selector. fixes PR 43835.
accept the LDT selector in check_sigcontext32() too.
 1.19.8.2 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.19.8.1 24-Oct-2010  jym Sync with HEAD
 1.19.4.1 07-Sep-2010  bouyer Pull up following revision(s) (requested by chs in ticket #1449):
sys/arch/amd64/amd64/netbsd32_machdep.c: revisions 1.66, 1.67
sys/arch/amd64/include/segments.h: revision 1.21
in check_mcontext32(), accept the LDT selector for 32-bit user code
as well as the GDT selector. fixes PR 43835.
accept the LDT selector in check_sigcontext32() too.
 1.21.4.1 08-Feb-2011  bouyer Sync with HEAD
 1.21.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.22.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.22.14.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.22.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.22.4.2 23-Jan-2013  yamt sync with head
 1.22.4.1 30-Oct-2012  yamt sync with head
 1.23.2.2 03-Dec-2017  jdolecek update from HEAD
 1.23.2.1 25-Feb-2013  tls resync with head
 1.24.22.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.24.18.1 20-Mar-2017  pgoyette Sync with HEAD
 1.24.16.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.24.14.2 28-Aug-2017  skrll Sync with HEAD
 1.24.14.1 05-Oct-2016  skrll Sync with HEAD
 1.24.12.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.28.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.29.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.34.4.1 10-Jun-2019  christos Sync with HEAD
 1.34.2.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.2 26-Oct-2008  mrg put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.1 26-Apr-2003  fvdl branches: 1.1.104; 1.1.108; 1.1.114;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.114.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.1.108.1 04-May-2009  yamt sync with head.
 1.1.104.1 17-Jan-2009  mjf Sync with HEAD.
 1.13 27-Oct-2021  thorpej - In sendsig() and sigaction1(), don't hard-code signal trampoline
versions. Instead, use the version constants from <sys/signal.h>
and automatically (and correctly) handle cases where multiple versions
of a particular trampoline flavor exist. Conditionalize support
for sigcontext trampolines on __HAVE_STRUCT_SIGCONTEXT.
- aarch64 and amd64 don't use sigcontext natively, but do need to
support it for 32-bit compatibility; define __HAVE_STRUCT_SIGCONTEXT
conditionally on _KERNEL.
 1.12 02-Jan-2013  dsl This is included into user-programs by signal.h, it shouldn't be
pulling in machine/fpu.h - which doesn't describe anything userspace
(directly) needs.
 1.11 19-Nov-2008  ad branches: 1.11.16; 1.11.26;
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.10 26-Oct-2008  mrg branches: 1.10.2;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.9 18-Feb-2007  pavel branches: 1.9.42; 1.9.46; 1.9.52;
Accept the old ABI versions of signal trampolines for 32-bit
compatibility. Unbreaks the i386 cvsup binary on amd64.

Problem reported by Blair Sadewitz and Viktor Holmlund, fix tested by
Viktor Holmlund.
 1.8 11-Dec-2005  christos branches: 1.8.24; 1.8.26;
merge ktrace-lwp.
 1.7 10-May-2004  drochner branches: 1.7.10; 1.7.12;
SIGTRAMP_VALID() should not pollute the user namespace
 1.6 25-Mar-2004  drochner only accept signal trampoline version 2, and remove "struct sigcontext"
 1.5 25-Nov-2003  christos bye, bye _MCONTEXT_TO_SIGCONTEXT and vice versa.
 1.4 18-Oct-2003  briggs Add SIGTRAMP_VALID().
 1.3 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.2 28-Apr-2003  bjh21 branches: 1.2.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.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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.7.12.1 26-Feb-2007  yamt sync with head.
 1.7.10.1 19-Feb-2007  tron Pull up following revision(s) (requested by pavel in ticket #1669):
sys/arch/amd64/include/signal.h: revision 1.9
Accept the old ABI versions of signal trampolines for 32-bit
compatibility. Unbreaks the i386 cvsup binary on amd64.
Problem reported by Blair Sadewitz and Viktor Holmlund, fix tested by
Viktor Holmlund.
 1.8.26.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.8.24.1 19-Feb-2007  riz Pull up following revision(s) (requested by pavel in ticket #455):
sys/arch/amd64/include/signal.h: revision 1.9
Accept the old ABI versions of signal trampolines for 32-bit
compatibility. Unbreaks the i386 cvsup binary on amd64.
Problem reported by Blair Sadewitz and Viktor Holmlund, fix tested by
Viktor Holmlund.
 1.9.52.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.9.46.1 04-May-2009  yamt sync with head.
 1.9.42.1 17-Jan-2009  mjf Sync with HEAD.
 1.10.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.11.26.1 25-Feb-2013  tls resync with head
 1.11.16.1 23-Jan-2013  yamt sync with head
 1.2 10-Jun-2015  alnsn Include <i386/sljit_machdep.h> for i386 compat build.
 1.1 23-Jul-2014  alnsn branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8;
Rename sljitarch.h to sljit_machdep.h.
 1.1.8.1 22-Sep-2015  skrll Sync with HEAD
 1.1.6.3 03-Dec-2017  jdolecek update from HEAD
 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:02:42 +0000
 1.1.4.1 08-Jul-2015  snj Pull up following revision(s) (requested by alnsn in ticket #872):
sys/arch/amd64/include/sljit_machdep.h: revision 1.2
Include <i386/sljit_machdep.h> for i386 compat build.
 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:49 +0000
 1.3 23-Jul-2014  alnsn Rename sljitarch.h to sljit_machdep.h.
 1.2 17-Nov-2013  alnsn branches: 1.2.2;
Always define SLJIT_CACHE_FLUSH(), start include guards with '_' and use _LP64 guard.
 1.1 13-Oct-2012  alnsn branches: 1.1.2; 1.1.4; 1.1.6;
Enable sljit in amd64 kernel and modules.
 1.1.6.1 18-May-2014  rmind sync with head
 1.1.4.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.4.2 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.1.4.1 13-Oct-2012  tls file sljitarch.h was added on branch tls-maxphys on 2012-11-20 03:00:56 +0000
 1.1.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.1.2.2 30-Oct-2012  yamt sync with head
 1.1.2.1 13-Oct-2012  yamt file sljitarch.h was added on branch yamt-pagecache on 2012-10-30 17:18:45 +0000
 1.2.2.1 10-Aug-2014  tls Rebase.
 1.5 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.4 06-Jun-2007  njoly branches: 1.4.10;
Remove duplicated AMD K8 MSR definitions, already in x86 specialreg.h
file.

ok by xtraeme.
 1.3 11-Dec-2005  christos branches: 1.3.30; 1.3.32; 1.3.38;
merge ktrace-lwp.
 1.2 19-Feb-2004  drochner branches: 1.2.16;
use no-execute page permissions if supported
 1.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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.2.16.1 03-Sep-2007  yamt sync with head.
 1.3.38.1 26-Jun-2007  garbled Sync with HEAD.
 1.3.32.1 11-Jul-2007  mjf Sync with head.
 1.3.30.1 09-Jun-2007  ad Sync with head.
 1.4.10.1 06-Nov-2007  matt sync with HEAD
 1.8 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.7 20-Jun-2011  mrg various build fixes for gcc 4.5. from chuq. XXX i'm not sure all of
these work properly wtf pointer aliasing, but there are no casts at
least...

the lib/libpuffs/puffs_priv.h is definately a real bug fix.

from chuq.
 1.6 26-Oct-2008  mrg branches: 1.6.8; 1.6.26;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.5 11-Dec-2005  christos branches: 1.5.74; 1.5.78; 1.5.84;
merge ktrace-lwp.
 1.4 30-Dec-2004  christos change the definition of va_start for lint.
 1.3 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.2 28-Apr-2003  bjh21 branches: 1.2.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.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.2.2.4 17-Jan-2005  skrll Sync with HEAD.
 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.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.26.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.6.8.1 27-Aug-2011  jym Add/remove files, like in HEAD.
 1.6 16-Apr-2007  ad Share the sysarch stuff between the x86 ports. PR kern/36046.
 1.5 07-Jan-2006  dsl branches: 1.5.24; 1.5.28; 1.5.30;
De __P
Add some 'struct xxx' definitions in the else part of a '#if 0' so that
the function prototypes later down the file don't define the structure
within the argument list.
 1.4 11-Dec-2005  christos branches: 1.4.2;
merge ktrace-lwp.
 1.3 15-May-2005  fvdl branches: 1.3.2;
New definitions for LDT system call arguments, amd64 version. Compatible
with the Linux interface. As yet unused.
 1.2 11-Sep-2003  kleink __{BEGIN,END}_DECLS-wrap prototypes.
 1.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.2.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 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.3.2.2 03-Sep-2007  yamt sync with head.
 1.3.2.1 21-Jun-2006  yamt sync with head.
 1.4.2.1 15-Jan-2006  yamt sync with head.
 1.5.30.1 11-Jul-2007  mjf Sync with head.
 1.5.28.1 27-May-2007  ad Sync with head.
 1.5.24.1 07-May-2007  yamt sync with head.
 1.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.8 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.7 04-Jan-2018  maxv branches: 1.7.2; 1.7.4;
Declare IOMAP_VALIDOFF, not to use ci_tss pointers.
 1.6 12-Jul-2017  maxv rsp2, not 3
 1.5 26-Oct-2008  mrg branches: 1.5.38; 1.5.58;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.4 16-Apr-2008  cegger branches: 1.4.4; 1.4.10;
use POSIX integer types
 1.3 05-Jan-2008  yamt branches: 1.3.6;
- make amd64 use per-cpu tss.
- fix iopl syscall for amd64+xen.
 1.2 25-Dec-2007  perry Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.1 26-Apr-2003  fvdl branches: 1.1.18; 1.1.80; 1.1.86; 1.1.90; 1.1.94;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.94.2 08-Jan-2008  bouyer Sync with HEAD
 1.1.94.1 02-Jan-2008  bouyer Sync with HEAD
 1.1.90.1 26-Dec-2007  ad Sync with head.
 1.1.86.1 18-Feb-2008  mjf Sync with HEAD.
 1.1.80.1 09-Jan-2008  matt sync with HEAD
 1.1.18.1 21-Jan-2008  yamt sync with head
 1.3.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.3.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.4.10.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.4.4.1 04-May-2009  yamt sync with head.
 1.5.58.1 28-Aug-2017  skrll Sync with HEAD
 1.5.38.1 03-Dec-2017  jdolecek update from HEAD
 1.7.4.1 10-Jun-2019  christos Sync with HEAD
 1.7.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.73 08-May-2025  imil Rename BOOTCYCLETIME kernel option and subsequent files to BOOT_DURATION
 1.72 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.71 01-Apr-2021  simonb branches: 1.71.22;
Whitespace: #define<tab>
 1.70 23-Jan-2021  christos branches: 1.70.2;
Document via __HAVE_BUS_SPACE_8 platforms that implement bus_space_*_8
 1.69 01-Aug-2020  jdolecek branches: 1.69.2;
move __HAVE_PCI_MSI_MSIX to <x86/pci_machdep_common.h>
 1.68 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.67 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.66 13-Apr-2020  maxv Add KASAN-DMA support on aarch64, same as amd64. Discussed with skrll@.
 1.65 17-Mar-2020  maxv branches: 1.65.2;
Add a redzone between the pcb and the stack. Sent to port-amd64@.
 1.64 14-Nov-2019  maxv Add support for Kernel Memory Sanitizer (kMSan). It detects uninitialized
memory used by the kernel at run time, and just like kASan and kCSan, it
is an excellent feature. It has already detected 38 uninitialized variables
in the kernel during my testing, which I have since discreetly fixed.

We use two shadows:
- "shad", to track uninitialized memory with a bit granularity (1:1).
Each bit set to 1 in the shad corresponds to one uninitialized bit of
real kernel memory.
- "orig", to track the origin of the memory with a 4-byte granularity
(1:1). Each uint32_t cell in the orig indicates the origin of the
associated uint32_t of real kernel memory.

The memory consumption of these shadows is consequent, so at least 4GB of
RAM is recommended to run kMSan.

The compiler inserts calls to specific __msan_* functions on each memory
access, to manage both the shad and the orig and detect uninitialized
memory accesses that change the execution flow (like an "if" on an
uninitialized variable).

We mark as uninit several types of memory buffers (stack, pools, kmem,
malloc, uvm_km), and check each buffer passed to copyout, copyoutstr,
bwrite, if_transmit_lock and DMA operations, to detect uninitialized memory
that leaves the system. This allows us to detect kernel info leaks in a way
that is more efficient and also more user-friendly than KLEAK.

Contrary to kASan, kMSan requires comprehensive coverage, ie we cannot
tolerate having one non-instrumented function, because this could cause
false positives. kMSan cannot instrument ASM functions, so I converted
most of them to __asm__ inlines, which kMSan is able to instrument. Those
that remain receive special treatment.

Contrary to kASan again, kMSan uses a TLS, so we must context-switch this
TLS during interrupts. We use different contexts depending on the interrupt
level.

The orig tracks precisely the origin of a buffer. We use a special encoding
for the orig values, and pack together in each uint32_t cell of the orig:
- a code designating the type of memory (Stack, Pool, etc), and
- a compressed pointer, which points either (1) to a string containing
the name of the variable associated with the cell, or (2) to an area
in the kernel .text section which we resolve to a symbol name + offset.

This encoding allows us not to consume extra memory for associating
information with each cell, and produces a precise output, that can tell
for example the name of an uninitialized variable on the stack, the
function in which it was pushed on the stack, and the function where we
accessed this uninitialized variable.

kMSan is available with LLVM, but not with GCC.

The code is organized in a way that is similar to kASan and kCSan, so it
means that other architectures than amd64 can be supported.
 1.63 04-Oct-2019  maxv Add DMA instrumentation in KASAN. We note the original buffer and length in
the map, and check the buffer on each bus_dmamap_sync. This allows us to
find DMA buffer overflows and UAFs, which couldn't be found before because
the device accesses to memory are outside of KASAN's control.
 1.62 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.61 22-Sep-2019  maxv Fix KASAN on aarch64: the bus_space_* functions are macros, so we can't
redefine them. Introduce __HAVE_KASAN_INSTR_BUS, which indicates whether
to instrument the bus functions. Defined on amd64 only.
 1.60 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.59 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.58 15-Nov-2018  riastradh Make the direct-map API always available, but fail if KASAN or rump.

(Only for architectures that support it at all; on others,
__HAVE_MM_MD_DIRECT_MAPPED_PHYS/IO are still undefined and the
functions unimplemented.)

This gives modules like zfs an opportunity to use it.

While here, fix the one caller of mm_md_direct_mapped_phys that
ignored the return value (and make sure to call pmap_kremove/update
before uvm_km_free).
 1.57 20-Aug-2018  maxv Add support for kASan on amd64. Written by me, with some parts inspired
from Siddharth Muralee's initial work. This feature can detect several
kinds of memory bugs, and it's an excellent feature.

It can be enabled by uncommenting these three lines in GENERIC:

#makeoptions KASAN=1 # Kernel Address Sanitizer
#options KASAN
#no options SVS

The kernel is compiled without SVS, without DMAP and without PCPU area.
A shadow area is created at boot time, and it can cover the upper 128TB
of the address space. This area is populated gradually as we allocate
memory. With this design the memory consumption is kept at its lowest
level.

The compiler calls the __asan_* functions each time a memory access is
done. We verify whether this access is legal by looking at the shadow
area.

We declare our own special memcpy/memset/etc functions, because the
compiler's builtins don't add the __asan_* instrumentation.

Initially all the mappings are marked as valid. During dynamic
allocations, we add a redzone, which we mark as invalid. Any access on
it will trigger a kASan error message. Additionally, the compiler adds
a redzone on global variables, and we mark these redzones as invalid too.
The illegal-access detection works with a 1-byte granularity.

For now, we cover three areas:

- global variables
- kmem_alloc-ated areas
- malloc-ated areas

More will come, but that's a good start.
 1.56 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.55 16-Mar-2018  maxv branches: 1.55.2;
Remove the __HAVE_CPU_UAREA_ROUTINES code from x86.

It was available only in amd64, and I disabled it a few months ago in
order to support SVS. Regardless of SVS this option was questionable,
since it made stack overflows more difficult to detect.
 1.54 11-Jan-2018  maxv branches: 1.54.2;
Declare new SVS_* variants: SVS_ENTER_NOSTACK and SVS_LEAVE_NOSTACK. Use
SVS_ENTER_NOSTACK in the syscall entry point, and put it before the code
that touches curlwp. (curlwp is located in the direct map.)

Then, disable __HAVE_CPU_UAREA_ROUTINES (to be removed later). This moves
the kernel stack into pmap_kernel(), and not the direct map. That's a
change I've always wanted to make: because of the direct map we can't add
a redzone on the stack, and basically, a stack overflow can go very far
in memory without being detected (as far as erasing all of the system's
memory).

Finally, unmap the direct map from userland.
 1.53 05-Jan-2018  maxv Add a __HAVE_PCPU_AREA option, enabled by default on native amd64 but not
Xen.

With this option, the CPU structures that must always be present in the
CPU's page tables are moved on L4 slot 384, which means address
0xffffc00000000000.

A new pcpu_area structure is defined. It contains shared structures (IDT,
LDT), and then an array of pcpu_entry structures, indexed by cpu_index(ci).
Theoretically the LDT should be in the array, but this will be done later.

During the boot procedure, cpu0 calls pmap_init_pcpu, which creates a
page tree that is able to map the pcpu_area structure entirely. cpu0 then
immediately maps the shared structures. Later, every CPU goes through
cpu_pcpuarea_init, which allocates physical pages and kenters the relevant
pcpu_entry to them. Finally, each pointer is replaced to point to pcpuarea.

The point of this change is to make sure that the structures that must
always be present in the page tables have their own L4 slot. Until now
their L4 slot was that of pmap_kernel, and making a distinction between
what must be mapped and what does not need to be was complicated.

Even in the non-speculative-bug case this change makes some sense: there
are several x86 instructions that leak the addresses of the CPU structures,
and putting these structures inside pmap_kernel actually offered a way to
compute the address of the kernel heap - which would have made ASLR on it
plainly useless, had we implemented that.

Note that, for now, pcpuarea does not contain rsp0.

Unfortunately this change adds many #ifdefs, and makes the code harder to
understand. There is also some duplication, but that will be solved later.
 1.52 26-Jan-2017  christos branches: 1.52.6;
provide __HAVE_COMPAT_NETBSD32 and fix multiple include protection consistently.
 1.51 27-Feb-2016  tls branches: 1.51.2; 1.51.4;
Add cpu_rng, a framework for simple on-CPU random number generators.
 1.50 23-Jan-2016  christos expose the kernel types for standalone code.
 1.49 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.48 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.47 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.46 27-Apr-2015  knakahara add x86 MD MSI/MSI-X support code.
 1.45 03-Apr-2014  christos branches: 1.45.6;
we have cpu_bootconf()
 1.44 20-Mar-2014  christos make pmc compile with amd64
 1.43 01-Dec-2013  christos revert fpu/pcu changes until we figure out what's wrong; they cause random
freezes
 1.42 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.41 21-Jan-2012  chs branches: 1.41.6; 1.41.10;
allocate uareas contiguously and access them via the direct map.
 1.40 04-Dec-2011  chs map all of physical memory using large pages.
ported from openbsd years ago by Murray Armfield,
updated for changes since then by me.
 1.39 06-Jul-2011  dyoung branches: 1.39.2; 1.39.6;
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.38 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.37 12-Mar-2011  joerg branches: 1.37.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.36 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.35 22-Dec-2010  njoly branches: 1.35.2; 1.35.4;
__HAVE_CPU_INFO_FIRST -> __HAVE_CPU_DATA_FIRST.
 1.34 22-Dec-2010  christos Make __HAVE_CPU_DATA_FIRST true
 1.33 11-Dec-2009  matt branches: 1.33.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.32 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.31 05-Apr-2009  tsutsui Use #define<tab> consistently.
 1.30 05-Apr-2009  tsutsui Remove __HAVE_UFS2_BOOT since it belongs to sysinst for now.
"Feel free to change it" by ad@.
 1.29 04-Apr-2009  ad +__HAVE_UFS2_BOOT
 1.28 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.27 26-Oct-2008  mrg branches: 1.27.2; 1.27.8;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.26 21-Feb-2008  ad branches: 1.26.2; 1.26.6; 1.26.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.25 20-Jan-2008  joerg branches: 1.25.2;
Now that __HAVE_TIMECOUNTER and __HAVE_GENERIC_TODR are invariants,
remove the conditionals and the code associated with the undef case.
 1.24 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.23 08-Jan-2008  joerg Switch Xen to generic TODR. Tested by Manuel Bouyer.
 1.22 05-Jan-2008  yamt remove no longer necessary cpu_maxproc.
 1.21 29-Nov-2007  ad branches: 1.21.6;
__HAVE_ATOMIC64_OPS
 1.20 23-Nov-2007  bouyer Include opt_xen.h #ifdef _KERNEL_OPT instead of custom logic.
Thanks to Izumi Tsutsui for pointing me at _KERNEL_OPT
 1.19 22-Nov-2007  bouyer Fix bouyer-xenamd64 merge fallout:
we can #include "opt_xen.h" when
#if defined(_KERNEL) && !defined(_RUMPKERNEL) && !defined(_LKM),
#ifdef _KERNEL isn't enough.
 1.18 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.17 17-Oct-2007  garbled branches: 1.17.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.16 14-Jul-2007  ad branches: 1.16.8; 1.16.10; 1.16.14;
Generic soft interrupts are mandatory.
 1.15 09-Feb-2007  ad branches: 1.15.6; 1.15.12; 1.15.14;
Merge newlock2 to head.
 1.14 03-Sep-2006  perry branches: 1.14.2;
temporarily turn on "__HAVE_GENERIC_TODR"
 1.13 03-Sep-2006  bjh21 Nothing in the kernel now tests __HAVE_NWSCONS, so stop defining it everywhere.
 1.12 07-Jun-2006  kardel convert to timecounters (from branch simonb-timecounters)
 1.11 24-Dec-2005  perry branches: 1.11.4; 1.11.6; 1.11.8; 1.11.14;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.10 11-Dec-2005  christos merge ktrace-lwp.
 1.9 26-Mar-2004  drochner branches: 1.9.16;
nothing cares about __HAVE_SIGINFO anymore, so nuke it
 1.8 21-Jan-2004  mrg back out previous; it was only required for a dead function.
 1.7 20-Jan-2004  jdolecek add register64_t which appears to be necessary for COMPAT_NETBSD32 nowadays
 1.6 18-Jan-2004  martin Do not export __HAVE_RAS to userland. Applications are supposed to try
rasctl() and detect failure with EOPNOTSUPP.
 1.5 06-Oct-2003  fvdl SIGINFO support.
Todo: 32bit compat support (COMPAT_NETBSD32 will not compile right now,
as it won't on other platforms).
 1.4 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.3 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.2 28-Apr-2003  bjh21 branches: 1.2.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.1 26-Apr-2003  fvdl Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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.9.16.9 27-Feb-2008  yamt sync with head.
 1.9.16.8 21-Jan-2008  yamt remove __HAVE_LAZY_MBUF for now as it's incompatible with in_cksum.S.
 1.9.16.7 21-Jan-2008  yamt sync with head
 1.9.16.6 07-Dec-2007  yamt sync with head
 1.9.16.5 03-Sep-2007  yamt sync with head.
 1.9.16.4 26-Feb-2007  yamt sync with head.
 1.9.16.3 30-Dec-2006  yamt sync with head.
 1.9.16.2 21-Jun-2006  yamt sync with head.
 1.9.16.1 07-Jul-2005  yamt define __HAVE_LAZY_MBUF for i386 and amd64.
 1.11.14.1 19-Jun-2006  chap Sync with head.
 1.11.8.2 14-Sep-2006  yamt sync with head.
 1.11.8.1 26-Jun-2006  yamt sync with head.
 1.11.6.1 30-Apr-2006  kardel define __HAVE_TIMECOUNER -> switch to timcounter for amd64
 1.11.4.1 09-Sep-2006  rpaulo sync with head
 1.14.2.1 29-Dec-2006  ad Checkpoint work in progress.
 1.15.14.1 03-Oct-2007  garbled Sync with HEAD
 1.15.12.1 17-Apr-2007  thorpej amd64 has 64-bit atomic ops
 1.15.6.2 03-Dec-2007  ad Sync with HEAD.
 1.15.6.1 15-Jul-2007  ad Sync with head.
 1.16.14.1 17-Oct-2007  bouyer amd64 (aka x86-64) support for Xen. Based on the OpenBSD port done by
Mathieu Ropert in 2006.
DomU-only for now. An INSTALL_XEN3_DOMU kernel with a ramdisk will boot to
sysinst if you're lucky. Often it panics because a runable LWP has
a NULL stack (really, it's all of l->l_addr which is has been zeroed out
while the process was on the queue !)
TODO:
- bug fixes :)
- Most of the xpq_* functions should be shared with xen/i386
- The xen/i386 assembly bootstrap code should be remplaced with the C
version in xenamd64/amd64/xpmap.c
- see if a config(5) trick could allow to merge xenamd64 back to xen or amd64.
 1.16.10.3 23-Mar-2008  matt sync with HEAD
 1.16.10.2 09-Jan-2008  matt sync with HEAD
 1.16.10.1 06-Nov-2007  matt sync with HEAD
 1.16.8.2 03-Dec-2007  joerg Sync with HEAD.
 1.16.8.1 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.17.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.17.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.21.6.4 23-Jan-2008  bouyer Sync with HEAD.
 1.21.6.3 19-Jan-2008  bouyer Sync with HEAD
 1.21.6.2 10-Jan-2008  bouyer Sync with HEAD
 1.21.6.1 08-Jan-2008  bouyer Sync with HEAD
 1.25.2.1 24-Mar-2008  keiichi sync with head.
 1.26.12.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.26.6.2 11-Mar-2010  yamt sync with head
 1.26.6.1 04-May-2009  yamt sync with head.
 1.26.2.2 17-Jan-2009  mjf Sync with HEAD.
 1.26.2.1 21-Feb-2008  mjf file types.h was added on branch mjf-devfs2 on 2009-01-17 13:27:49 +0000
 1.27.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.27.8.5 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.27.8.4 10-Jan-2011  jym Sync with HEAD
 1.27.8.3 24-Oct-2010  jym Sync with HEAD
 1.27.8.2 01-Nov-2009  jym Sync with HEAD.
 1.27.8.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.27.2.1 28-Apr-2009  skrll Sync with HEAD.
 1.33.4.3 21-Apr-2011  rmind sync with head
 1.33.4.2 05-Mar-2011  rmind sync with head
 1.33.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.35.4.1 05-Mar-2011  bouyer Sync with HEAD
 1.35.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.37.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.39.6.1 18-Feb-2012  mrg merge to -current.
 1.39.2.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.39.2.1 17-Apr-2012  yamt sync with head
 1.41.10.1 18-May-2014  rmind sync with head
 1.41.6.2 03-Dec-2017  jdolecek update from HEAD
 1.41.6.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.45.6.4 05-Feb-2017  skrll Sync with HEAD
 1.45.6.3 19-Mar-2016  skrll Sync with HEAD
 1.45.6.2 22-Sep-2015  skrll Sync with HEAD
 1.45.6.1 06-Jun-2015  skrll Sync with HEAD
 1.51.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.51.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.52.6.2 17-Mar-2018  martin Pull up the following revisions, requested by maxv in ticket #637:

sys/arch/amd64/amd64/process_machdep.c 1.33,1.34,1.35 (patch)
sys/arch/amd64/include/types.h 1.55 (patch)
sys/arch/x86/x86/vm_machdep.c 1.33 (patch)

- Reduce the number of places where segment register faults can
occur.
- Remove __HAVE_CPU_UAREA_ROUTINES.
 1.52.6.1 16-Mar-2018  martin Pull up the following revisions (via patch), requested by maxv in #635:

sys/arch/amd64/amd64/gdt.c 1.39-1.45 (patch)
sys/arch/amd64/amd64/amd64/machdep.c 1.284,1.287,1.288 (patch)
sys/arch/amd64/amd64/include/param.h 1.23 (patch)
sys/arch/amd64/include/types.h 1.53 (patch)
sys/arch/x86/include/cpu.h 1.87 (patch)
sys/arch/x86/include/pmap.h 1.73,1.74 (patch)
sys/arch/x86/x86/cpu.c 1.142 (patch)
sys/arch/x86/x86/intr.c 1.117 (partial),1.120 (patch)
sys/arch/x86/x86/pmap.c 1.276 (patch)

Initialize ist0 in cpu_init_tss.
Backport __HAVE_PCPU_AREA.
 1.54.2.4 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.54.2.3 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.54.2.2 28-Jul-2018  pgoyette Sync with HEAD
 1.54.2.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.55.2.4 21-Apr-2020  martin Sync with HEAD
 1.55.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.55.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.55.2.1 10-Jun-2019  christos Sync with HEAD
 1.65.2.1 20-Apr-2020  bouyer Sync with HEAD
 1.69.2.1 03-Apr-2021  thorpej Sync with HEAD.
 1.70.2.1 03-Apr-2021  thorpej Sync with HEAD.
 1.71.22.1 02-Aug-2025  perseant Sync with HEAD
 1.13 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.12 23-Feb-2017  kamil branches: 1.12.12; 1.12.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.11 16-Jan-2017  kamil Allow to mix single-step with hardware assisted watchpoints on amd64

This case needs new handling in trap recognition.

Sponsored by <The NetBSD Foundation>
 1.10 15-Dec-2016  kamil branches: 1.10.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.9 28-Apr-2008  martin branches: 1.9.44; 1.9.64; 1.9.68;
Remove clause 3 and 4 from TNF licenses
 1.8 09-Feb-2007  ad branches: 1.8.44; 1.8.46; 1.8.48;
Merge newlock2 to head.
 1.7 15-Apr-2006  simonb branches: 1.7.8;
The comment says this is the same as the i386 counterpart, so catch
up on de-__P and ANSIficiation that i386 has.
 1.6 16-Feb-2006  perry branches: 1.6.2; 1.6.4; 1.6.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.5 24-Dec-2005  perry branches: 1.5.2; 1.5.4; 1.5.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.4 11-Dec-2005  christos merge ktrace-lwp.
 1.3 31-Oct-2003  cl branches: 1.3.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.2 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.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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.3.16.2 26-Feb-2007  yamt sync with head.
 1.3.16.1 21-Jun-2006  yamt sync with head.
 1.5.6.1 22-Apr-2006  simonb Sync with head.
 1.5.4.1 09-Sep-2006  rpaulo sync with head
 1.5.2.1 18-Feb-2006  yamt sync with head.
 1.6.6.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.6.4.1 19-Apr-2006  elad sync with head - hopefully this will work
 1.6.2.1 24-May-2006  yamt sync with head.
 1.7.8.1 20-Oct-2006  ad Do the priority adjustment in mi_userret().
 1.8.48.1 16-May-2008  yamt sync with head.
 1.8.46.1 18-May-2008  yamt sync with head.
 1.8.44.1 02-Jun-2008  mjf Sync with HEAD.
 1.9.68.2 20-Mar-2017  pgoyette Sync with HEAD
 1.9.68.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.9.64.2 28-Aug-2017  skrll Sync with HEAD
 1.9.64.1 05-Feb-2017  skrll Sync with HEAD
 1.9.44.1 03-Dec-2017  jdolecek update from HEAD
 1.10.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.12.14.1 10-Jun-2019  christos Sync with HEAD
 1.12.12.1 28-Jul-2018  pgoyette Sync with HEAD
 1.5 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.4 26-Oct-2008  mrg branches: 1.4.8;
put the contents of these header files around #ifdef __x86_64__, and
#include the <i386/foo.h> in the #else clause, making these files
largely bit-size independant.
 1.3 11-Dec-2005  christos branches: 1.3.74; 1.3.78; 1.3.84;
merge ktrace-lwp.
 1.2 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.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 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.3.84.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.3.78.1 04-May-2009  yamt sync with head.
 1.3.74.1 17-Jan-2009  mjf Sync with HEAD.
 1.4.8.1 27-Aug-2011  jym Add/remove files, like in HEAD.
 1.55 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.54 26-Nov-2020  christos make the max text size the same as the max data size
 1.53 06-Oct-2020  christos branches: 1.53.2;
GC unused MAXTSIZ32
 1.52 22-Jan-2020  ad Move the UBC defaults into vmparam.h
 1.51 11-Feb-2019  cherry branches: 1.51.6;
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.50 17-Jan-2019  maxv Increase VM_PHYSSEG_MAX from 32 to 64. Saw an example on tech-kern@ of a
heavily fragmented memory map.
 1.49 29-Oct-2018  maya Make VM_MIN_KERNEL_ADDRESS and others available in the _KMEMUSER case
as well. This affects ddb. Tested by htodd.
 1.48 28-Oct-2018  maxv Add #ifdef _KERNEL, vaddr_t does not exist in userland, and we don't want
externs anyway.
 1.47 12-Aug-2018  maxv Randomize the main memory on Xen, same as native. Tested on amd64-dom0.
 1.46 12-Aug-2018  maxv More ASLR: randomize the kernel main memory. VM_MIN_KERNEL_ADDRESS becomes
variable, and its location is chosen at boot time. There is room for
improvement, since for now we ask for an alignment of NBPD_L4.

This is enabled by default in GENERIC, but not in Xen. Tested extensively
on GENERIC and GENERIC_KASLR, XEN3_DOM0 still boots fine.
 1.45 13-Nov-2017  wiz branches: 1.45.2; 1.45.4;
Remove superfluous word in comment. Noted by Geoff Wing.
 1.44 11-Nov-2017  mrg bump PAGER_MAP_DEFAULT_SIZE to 512MB. this should allow more
concurrent IOs to be possible, and i'm unable to see pager_map
contention any more.

other larger platforms should probably do this too.

ok chs@.
 1.43 24-Jun-2017  joerg Update VM_DEFAULT_ADDRESS32_TOPDOWN to include guard area.
 1.42 23-Jun-2017  joerg 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.41 17-Jun-2017  maxv Increase the kernel heap size from 512GB to 32TB, in such a way that it
is able to map the maximum amount of ram supported twice (16TB x 2).
 1.40 15-Jun-2017  maxv Correct these values. They must be consistent with NKL4_MAX_ENTRIES,
otherwise the kernel thinks it has ~126TB of va while pmap knows it
has only 512GB.
 1.39 11-Feb-2017  maxv branches: 1.39.6;
Remove VM_MAX_KERNEL_BUF (unused). Looks like several other ports could
do the same.
 1.38 19-Nov-2016  maxv branches: 1.38.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.37 07-Aug-2016  dholland Remove unused <sys/tree.h>.
 1.36 24-Jul-2014  riastradh branches: 1.36.4; 1.36.8;
Add a FIRST1G page freelist to x86, for old graphics devices.
 1.35 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.34 25-Jan-2014  christos branches: 1.34.2;
delete VM_DEFAULT_ADDRESS; some of those should be GC'ed because they match
the default definition.
 1.33 25-Jan-2014  christos provide propert address defaults for topdown and bottomup allocation
 1.32 13-Nov-2012  chs branches: 1.32.2;
bump VM_PHYSSEG_MAX to 32, we've seen a system where 16 wasn't enough.
 1.31 15-Aug-2012  sborrill branches: 1.31.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.30 07-May-2012  joerg Raise per-image text size limit to 256MB. 64MB has seen already, so
provide some margin of grows.
 1.29 10-Jan-2012  chs branches: 1.29.2;
reduce VM_MAX_KERNEL_ADDRESS so that it does not include
the direct-map or APTE regions.
 1.28 24-Nov-2011  christos branches: 1.28.2;
Bump text size to 128MB to make sure that gcc46 fits. It exceeded 64MB by
a tiny bit.
 1.27 04-Mar-2011  christos branches: 1.27.4;
Revert max stack size change. This is not used anymore for 32 bit binaries.
 1.26 04-Mar-2011  joerg Reduce MAXSSIZ to 64MB, otherwise netbsd32 binaries crash in ld.elf_so,
including the trivial main(){}. Add a warning to not modify this without
testing compatibility mode.
 1.25 17-Feb-2011  drochner make stack size limit (both initial and maximum) for native code
the double of that in 32-but emul mode, so that code which works
in emulation (or on the i386 port) will likely not overflow the
stack if built as native 64-bit program
This is still very conservative.
(before, the max stack size was natively even less than for 32bit emul)
 1.24 14-Nov-2010  uebayasi branches: 1.24.2; 1.24.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.23 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.22 22-Nov-2009  bouyer branches: 1.22.2; 1.22.4;
For amd64, introduce a third free list distinct from the default free list
for memory between 16M and 4G. On large memory machine, this avoids
the 32bit-accessible memory being eaten by various kernel early allocation,
causing 32bit bus_dma(9) memory allocation to fail at boot time.
Tested on a system with 48GB RAM; based on netbsd-5 patch proposed on
port-amd64 3 days ago.
 1.21 06-Mar-2009  joerg 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.20 13-Dec-2008  pooka branches: 1.20.2;
_VMPARAM_H_ -> _$MACHINE_VMPARAM_H_
 1.19 13-Dec-2008  pooka wrap in #ifdef __x86_64__
 1.18 20-Jan-2008  yamt branches: 1.18.6; 1.18.10; 1.18.18; 1.18.20; 1.18.26;
- 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.17 06-Jan-2008  ad #include <sys/mutex.h>
 1.16 22-Nov-2007  bouyer branches: 1.16.6;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.15 18-Oct-2007  yamt branches: 1.15.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.14 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.13 29-Aug-2007  ad branches: 1.13.2; 1.13.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.12 27-Sep-2006  cube branches: 1.12.8; 1.12.16; 1.12.22; 1.12.26; 1.12.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.11 11-Jan-2006  cube branches: 1.11.18; 1.11.20;
Add support for VM_TOPDOWN, and use it unconditionally (just like i386).

For COMPAT_NETBSD32 binaries, use VM_TOPDOWN layout too, and sync some
parameters with their i386 counterpart.

OK'd by fvdl@.
 1.10 11-Dec-2005  christos branches: 1.10.2;
merge ktrace-lwp.
 1.9 30-Jul-2005  wiz Fix typo reported in PR 30872.
 1.8 26-Mar-2005  fvdl branches: 1.8.2;
Fix some things regarding COMPAT_NETBSD32 and limits/VM addresses.

* For sparc64 and amd64, define *SIZ32 VM constants.
* Add a new function pointer to struct emul, pointing at a function
that will return the default VM map address. The default function
is uvm_map_defaultaddr, which just uses the VM_DEFAULT_ADDRESS
macro. This gives emulations control over the default map address,
and allows things to be mapped at the right address (in 32bit range)
for COMPAT_NETBSD32.
* Add code to adjust the data and stack limits when a COMPAT_NETBSD32
or COMPAT_SVR4_32 binary is executed.
* Don't use USRSTACK in kern_resource.c, use p_vmspace->vm_minsaddr
instead (emulations might have set it differently)
* Since this changes struct emul, bump kernel version to 3.99.2

Tested on amd64, compile-tested on sparc64.
 1.7 11-Feb-2005  ws branches: 1.7.4;
Prevent integer overflow.
Fixes PR29332.
 1.6 10-Feb-2005  ws Increase max data size, now that the Xserver can grok it.
(It was the only program that couldn't.)
 1.5 04-Jun-2004  sekiya branches: 1.5.4; 1.5.6;
Use the SPLAY_* macros. Copied from the i386 pmap, okay'ed by fvdl@
 1.4 23-Mar-2004  drochner bump default data size to 256M, enough to build a "-g" kernel
 1.3 17-Oct-2003  fvdl Correct VM_MAXUSER_ADDRESS definitions, it was wasting a few pages.
 1.2 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.1 26-Apr-2003  fvdl branches: 1.1.2;
Rename the x86_64 port to amd64, as this is the actual name used for
the processor family now. x86_64 is kept as the MACHINE_ARCH value,
since it's already widely used (by e.g. the toolchain, etc), and
by other operating systems.
 1.1.2.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.2.5 01-Apr-2005  skrll Sync with HEAD.
 1.1.2.4 15-Feb-2005  skrll Sync with HEAD.
 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.5.6.2 26-Mar-2005  yamt sync with head.
 1.5.6.1 12-Feb-2005  yamt sync with head.
 1.5.4.1 29-Apr-2005  kent sync with -current
 1.7.4.1 18-Sep-2005  tron Pull up following revision(s) (requested by fvdl in ticket #798):
sys/compat/sunos/sunos_exec.c: revision 1.47
sys/compat/pecoff/pecoff_emul.c: revision 1.11
sys/arch/sparc64/sparc64/netbsd32_machdep.c: revision 1.45
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.12
sys/sys/proc.h: revision 1.198
sys/compat/mach/mach_exec.c: revision 1.56
sys/compat/freebsd/freebsd_exec.c: revision 1.27
sys/arch/sparc64/include/vmparam.h: revision 1.27
sys/kern/kern_resource.c: revision 1.91
sys/compat/netbsd32/netbsd32_netbsd.c: revision 1.88
sys/compat/osf1/osf1_exec.c: revision 1.39
sys/compat/svr4_32/svr4_32_resource.c: revision 1.5
sys/compat/ultrix/ultrix_misc.c: revision 1.99
sys/compat/svr4_32/svr4_32_exec.h: revision 1.9
sys/kern/exec_elf32.c: revision 1.103
sys/compat/aoutm68k/aoutm68k_exec.c: revision 1.19
sys/compat/sunos32/sunos32_exec.c: revision 1.20
sys/compat/hpux/hpux_exec.c: revision 1.46
sys/compat/darwin/darwin_exec.c: revision 1.40
sys/kern/sysv_shm.c: revision 1.83
sys/uvm/uvm_extern.h: revision 1.99
sys/uvm/uvm_mmap.c: revision 1.89
sys/kern/kern_exec.c: revision 1.195
sys/compat/netbsd32/netbsd32.h: revision 1.31
sys/arch/sparc64/sparc64/svr4_32_machdep.c: revision 1.20
sys/compat/svr4/svr4_exec.c: revision 1.56
sys/compat/irix/irix_exec.c: revision 1.41
sys/compat/ibcs2/ibcs2_exec.c: revision 1.63
sys/compat/svr4_32/svr4_32_exec.c: revision 1.16
sys/arch/amd64/include/vmparam.h: revision 1.8
sys/compat/linux/common/linux_exec.c: revision 1.73
Fix some things regarding COMPAT_NETBSD32 and limits/VM addresses.
* For sparc64 and amd64, define *SIZ32 VM constants.
* Add a new function pointer to struct emul, pointing at a function
that will return the default VM map address. The default function
is uvm_map_defaultaddr, which just uses the VM_DEFAULT_ADDRESS
macro. This gives emulations control over the default map address,
and allows things to be mapped at the right address (in 32bit range)
for COMPAT_NETBSD32.
* Add code to adjust the data and stack limits when a COMPAT_NETBSD32
or COMPAT_SVR4_32 binary is executed.
* Don't use USRSTACK in kern_resource.c, use p_vmspace->vm_minsaddr
instead (emulations might have set it differently)
* Since this changes struct emul, bump kernel version to 3.99.2
Tested on amd64, compile-tested on sparc64.
 1.8.2.6 21-Jan-2008  yamt sync with head
 1.8.2.5 07-Dec-2007  yamt sync with head
 1.8.2.4 27-Oct-2007  yamt sync with head.
 1.8.2.3 03-Sep-2007  yamt sync with head.
 1.8.2.2 30-Dec-2006  yamt sync with head.
 1.8.2.1 21-Jun-2006  yamt sync with head.
 1.10.2.1 15-Jan-2006  yamt sync with head.
 1.11.20.1 22-Oct-2006  yamt sync with head
 1.11.18.1 18-Nov-2006  ad Sync with head.
 1.12.28.3 23-Mar-2008  matt sync with HEAD
 1.12.28.2 09-Jan-2008  matt sync with HEAD
 1.12.28.1 06-Nov-2007  matt sync with HEAD
 1.12.26.3 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.12.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.12.26.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.12.22.1 03-Sep-2007  skrll Sync with HEAD.
 1.12.16.1 03-Oct-2007  garbled Sync with HEAD
 1.12.8.3 03-Dec-2007  ad Sync with HEAD.
 1.12.8.2 23-Oct-2007  ad Sync with head.
 1.12.8.1 21-Aug-2007  ad amd64 changes, as yet untested:

- Adapt to vmlocking branch.
- Apply TLB shootdown and pv allocation changes to the pmap.
- Make it build.
 1.13.4.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.13.4.1 17-Oct-2007  bouyer amd64 (aka x86-64) support for Xen. Based on the OpenBSD port done by
Mathieu Ropert in 2006.
DomU-only for now. An INSTALL_XEN3_DOMU kernel with a ramdisk will boot to
sysinst if you're lucky. Often it panics because a runable LWP has
a NULL stack (really, it's all of l->l_addr which is has been zeroed out
while the process was on the queue !)
TODO:
- bug fixes :)
- Most of the xpq_* functions should be shared with xen/i386
- The xen/i386 assembly bootstrap code should be remplaced with the C
version in xenamd64/amd64/xpmap.c
- see if a config(5) trick could allow to merge xenamd64 back to xen or amd64.
 1.13.2.5 07-Oct-2007  yamt bump VM_MAX_KERNEL_ADDRESS from 0xffff800100000000 to 0xffffff8000000000.
 1.13.2.4 30-Sep-2007  yamt implement deferred pmap switching for amd64, and make amd64 use
x86 shared pmap code. it makes several i386 pmap improvements available
to amd64, including tlb shootdown reduction and bug fixes from Stephan Uphoff.
 1.13.2.3 29-Sep-2007  yamt fix more space/tab damages.
 1.13.2.2 29-Sep-2007  yamt fix some space/tab damages.
if you want to copy-and-paste code, please do so in a way which
preserves space/tab.
 1.13.2.1 29-Sep-2007  yamt sync a comment with i386
 1.15.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.15.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.16.6.2 20-Jan-2008  bouyer Sync with HEAD
 1.16.6.1 08-Jan-2008  bouyer Sync with HEAD
 1.18.26.1 21-Apr-2010  matt sync to netbsd-5
 1.18.20.1 01-Dec-2009  snj Apply patch (requested by bouyer in ticket 1158):
On amd64, add a third free list distinct from the default free list, holding
RAM between 16Mb and 4Gb. This helps preventing bus_dma(9) memory
allocation failures for 32bit DMA on large-memory machines.
 1.18.18.2 28-Apr-2009  skrll Sync with HEAD.
 1.18.18.1 19-Jan-2009  skrll Sync with HEAD.
 1.18.10.2 11-Mar-2010  yamt sync with head
 1.18.10.1 04-May-2009  yamt sync with head.
 1.18.6.1 17-Jan-2009  mjf Sync with HEAD.
 1.20.2.5 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.20.2.4 10-Jan-2011  jym Sync with HEAD
 1.20.2.3 24-Oct-2010  jym Sync with HEAD
 1.20.2.2 01-Nov-2009  jym Sync with HEAD.
 1.20.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.22.4.1 05-Mar-2011  rmind sync with head
 1.22.2.3 15-Nov-2010  uebayasi Sync with HEAD.
 1.22.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.22.2.1 23-Feb-2010  uebayasi Convert all VM_MDPAGE_INIT()'s to take struct vm_page_md * and paddr_t.
 1.24.4.1 05-Mar-2011  bouyer Sync with HEAD
 1.24.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.27.4.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.27.4.4 16-Jan-2013  yamt sync with (a bit old) head
 1.27.4.3 30-Oct-2012  yamt sync with head
 1.27.4.2 23-May-2012  yamt sync with head.
 1.27.4.1 17-Apr-2012  yamt sync with head
 1.28.2.2 02-Jun-2012  mrg sync to latest -current.
 1.28.2.1 18-Feb-2012  mrg merge to -current.
 1.29.2.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.31.2.3 03-Dec-2017  jdolecek update from HEAD
 1.31.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.31.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.32.2.1 18-May-2014  rmind sync with head
 1.34.2.1 10-Aug-2014  tls Rebase.
 1.36.8.2 20-Mar-2017  pgoyette Sync with HEAD
 1.36.8.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.36.4.3 28-Aug-2017  skrll Sync with HEAD
 1.36.4.2 05-Dec-2016  skrll Sync with HEAD
 1.36.4.1 05-Oct-2016  skrll Sync with HEAD
 1.38.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.39.6.3 27-Jan-2019  martin Pull up following revision(s) (requested by maxv in ticket #1174):

sys/arch/amd64/include/vmparam.h: revision 1.50

Increase VM_PHYSSEG_MAX from 32 to 64. Saw an example on tech-kern@ of a
heavily fragmented memory map.
 1.39.6.2 11-Apr-2018  martin Pull up following revision(s) (requested by mrg in ticket #733):

sys/arch/amd64/include/vmparam.h: revision 1.44
sys/arch/amd64/include/vmparam.h: revision 1.45
sys/arch/sparc64/include/vmparam.h: revision 1.38

bump PAGER_MAP_DEFAULT_SIZE to 512MB. this should allow more
concurrent IOs to be possible, and i'm unable to see pager_map
contention any more.

other larger platforms should probably do this too.
ok chs@.

Remove superfluous word in comment. Noted by Geoff Wing.

Bump PAGER_MAP_DEFAULT_SIZE to 512 MB (like amd64 recently did).
 1.39.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.45.4.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.45.4.1 10-Jun-2019  christos Sync with HEAD
 1.45.2.3 18-Jan-2019  pgoyette Synch with HEAD
 1.45.2.2 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.45.2.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.51.6.1 25-Jan-2020  ad Sync with head.
 1.53.2.1 14-Dec-2020  thorpej Sync w/ HEAD.
 1.3 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.2 11-Dec-2005  christos branches: 1.2.74; 1.2.76; 1.2.78;
merge ktrace-lwp.
 1.1 08-May-2004  kleink branches: 1.1.2;
Factor out W{CHAR,INT}_{MAX,MIN} into their own header file.
 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:31:36 +0000
 1.2.78.1 16-May-2008  yamt sync with head.
 1.2.76.1 18-May-2008  yamt sync with head.
 1.2.74.1 02-Jun-2008  mjf Sync with HEAD.
 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.
 1.1 10-Oct-2017  maxv branches: 1.1.2;
Add the amd64 prekern. It is a kernel relocator used for Kernel ASLR (see
tech-kern@). It works, but is not yet linked to the build system, because
I can't build a distribution right now.
 1.1.2.2 03-Dec-2017  jdolecek update from HEAD
 1.1.2.1 10-Oct-2017  jdolecek file Makefile was added on branch tls-maxphys on 2017-12-03 11:35:47 +0000
 1.9 24-Jun-2024  riastradh amd64/prekern: Add ldscript to DPADD since it affects build output.
 1.8 25-Jul-2018  kamil Specify NOLIBCSANITIZER in x86 bootloader-like code under sys/arch/

Set NOLIBCSANITIZER for i386 and amd64 specific bootloader-like code.
 1.7 02-Jun-2018  christos branches: 1.7.2;
Disable MKSANITIZER
 1.6 23-Dec-2017  ryoon branches: 1.6.2;
Use ldscript from src to fix build.sh build
 1.5 26-Nov-2017  maxv branches: 1.5.2;
Add a PRNG for the prekern, based on SHA512. The formula is basically:

Y0 = SHA512(entropy-file, 256bit rdseed, 64bit rdtsc)
Yn+1 = SHA512(256bit lowerhalf(Yn), 256bit rdseed, 64bit rdtsc)

On each round, random values are taken from the higher half of Yn. If
rdseed is not available, rdrand is used.

The SHA1 checksum of entropy-file is verified. However, the rndsave_t::data
field is not updated by the prekern, because the area is accessed via the
read-only view we created in locore. I like this design, so it will have
to be updated differently.
 1.4 17-Nov-2017  maxv style
 1.3 14-Nov-2017  maxv Add -Wstrict-prototypes, and fix each warning.
 1.2 13-Nov-2017  maxv Link libkern in the prekern, and remove redefined functions.
 1.1 10-Oct-2017  maxv Add the amd64 prekern. It is a kernel relocator used for Kernel ASLR (see
tech-kern@). It works, but is not yet linked to the build system, because
I can't build a distribution right now.
 1.5.2.2 03-Dec-2017  jdolecek update from HEAD
 1.5.2.1 26-Nov-2017  jdolecek file Makefile was added on branch tls-maxphys on 2017-12-03 11:35:48 +0000
 1.6.2.2 28-Jul-2018  pgoyette Sync with HEAD
 1.6.2.1 25-Jun-2018  pgoyette Sync with HEAD
 1.7.2.1 10-Jun-2019  christos Sync with HEAD
 1.7 04-May-2021  khorben prekern: add support for warning messages

As submitted on port-amd64@ (part 1/3)

Tested on NetBSD/amd64.
 1.6 23-May-2020  maxv branches: 1.6.6;
Bump copyrights.
 1.5 23-May-2020  maxv Extract putc().
 1.4 03-Apr-2019  maxv When scrolling the screen don't forget to update the last line. Whatever,
there is no case where the screen scrolls actually.
 1.3 17-Nov-2017  maxv branches: 1.3.2; 1.3.6;
style
 1.2 14-Nov-2017  maxv Add -Wstrict-prototypes, and fix each warning.
 1.1 10-Oct-2017  maxv Add the amd64 prekern. It is a kernel relocator used for Kernel ASLR (see
tech-kern@). It works, but is not yet linked to the build system, because
I can't build a distribution right now.
 1.3.6.1 10-Jun-2019  christos Sync with HEAD
 1.3.2.2 03-Dec-2017  jdolecek update from HEAD
 1.3.2.1 17-Nov-2017  jdolecek file console.c was added on branch tls-maxphys on 2017-12-03 11:35:48 +0000
 1.6.6.1 13-May-2021  thorpej Sync with HEAD.
 1.22 04-May-2021  khorben prekern: add support for warning messages

As submitted on port-amd64@ (part 1/3)

Tested on NetBSD/amd64.
 1.21 07-May-2020  maxv branches: 1.21.6;
Clarify.
 1.20 07-May-2020  maxv If we encounter relocations from a section that the bootloader dropped,
AND if the section is a note, then skip the relocations.

Considering a note that the bootloader dropped, there are two possible
sides for the relocations: (1) the relocations from the note towards the
rest of the binary, and (2) the relocations from the rest of the binary
towards the note.

We skip (1), which is correct, because the notes do not play any role at
run time. If we encounter (2) however then there is a bug in the kernel,
so add a sanity check against that.

This fixes KASLR since the latest Xen changes (which introduced .note.Xen).
 1.19 05-May-2020  maxv Gather the section filtering in a single function, and add a sanity check
when relocating, to make sure the section we're accessing is mappable.

Currently this check fails, because of the Xen section, which has RELAs but
is an unmappable unallocated note.

Also improve the prekern ASSERTs while here.
 1.18 05-Jan-2019  maxv Apply amd64/kobj_machdep.c::rev1.7 to the prekern too, to fix the
relocation with updated binutils.
 1.17 21-Nov-2017  maxv branches: 1.17.2; 1.17.4; 1.17.6;
Clean up and add some ASSERTs.
 1.16 17-Nov-2017  maxv style
 1.15 15-Nov-2017  maxv Small cleanup.
 1.14 15-Nov-2017  maxv Support large pages on KASLR kernels, in a way that does not reduce
randomness, but on the contrary that increases it.

The size of the kernel sub-blocks is changed to be 1MB. This produces a
kernel with sections that are always < 2MB in size, that can fit a large
page.

Each section is put in a 2MB physical chunk. In this chunk, there is a
padding of approximately 1MB. The prekern uses a random offset aligned to
sh_addralign, to shift the section in physical memory.

For example, physical memory layout created by the bootloader for .text.4
and .rodata.0:
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
|+---------------+ |+---------------+ |
|| .text.4 | PAD || .rodata.0 | PAD |
|+---------------+ |+---------------+ |
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
PA PA+2MB PA+4MB

Then, physical memory layout, after having been shifted by the prekern:
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
| P +---------------+ | +---------------+ |
| A | .text.4 | PAD | PAD | .rodata.0 | PAD |
| D +---------------+ | +---------------+ |
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
PA PA+2MB PA+4MB

The kernel maps these 2MB physical chunks with 2MB large pages. Therefore,
randomness is enforced at both the virtual and physical levels, and the
resulting entropy is higher than that of our current implementaion until
now.

The padding around the section is filled by the prekern. Not to consume
too much memory, the sections that are smaller than PAGE_SIZE are mapped
with normal pages - because there is no point in optimizing them. In these
normal pages, the same shift is applied.

This change has two additional advantages: (a) the cache attacks based on
the TLB are mostly mitigated, because even if you are able to determine
that a given page-aligned range is mapped as executable you don't know
where exactly within that range the section actually begins, and (b) given
that we are slightly randomizing the physical layout we are making some
rare physical attacks more difficult to conduct.

NOTE: after this change you need to update GENERIC_KASLR / prekern /
bootloader.
 1.13 14-Nov-2017  maxv Add -Wstrict-prototypes, and fix each warning.
 1.12 13-Nov-2017  maxv One more ASSERT, won't hurt.
 1.11 13-Nov-2017  maxv Don't process ELF sections that don't have the ALLOC flag set.

NOTE: you need to update both the prekern and the bootloader after this
change.
 1.10 13-Nov-2017  maxv Change the mapping logic: don't group sections of the same type into
segments, and rather map each section independently at a random VA.

In particular, .data and .bss are not merged anymore and reside at
different addresses.
 1.9 09-Nov-2017  maxv Define utility functions as inlines in prekern.h.
 1.8 09-Nov-2017  maxv Fill in the page padding. Only .text is pre-filled by the ld script, but
this will change in the future.
 1.7 05-Nov-2017  maxv Mprotect the segments in mm.c using bootspace, and remove the now unused
fields of elfinfo.
 1.6 01-Nov-2017  maxv Handle absolute symbols. Since my linux_sigcode.S::rev1.4 there are two
Elf_Rela that point to the NULL symbol - which the prekern thought was an
external reference.

In the ELF spec, STN_UNDEF means the value of the symbol is zero.
 1.5 29-Oct-2017  maxv Fix a few error messages, and be a little more verbose.
 1.4 29-Oct-2017  maxv Randomize the kernel segments independently. That is to say, put text,
rodata and data at different addresses (and in a random order).

To achieve that, the mapping order in the prekern is changed. Until now,
we were creating the kernel map the following way:
-> choose a random VA
-> map [kernpa_start; kernpa_end[ at this VA
-> parse the ELF structures from there
-> determine where exactly the kernel segments are located
-> relocate etc
Now, we are doing:
-> create a read-only view of [kernpa_start; kernpa_end[
-> from this view, compute the size of the "head" region
-> choose a random VA in the HEAD window, and map the head there
-> for each region in (text, rodata, data, boot)
-> compute the size of the region from the RO view
-> choose a random VA in the KASLR window
-> map the region there
-> relocate etc

Each time we map a region, we initialize its bootspace fields right away.

The "head" region must be put before the other regions in memory, because
the kernel uses (headva + sh_offset) to get the addresses of the symbols,
and the offset is unsigned.

Given that the head does not have an mcmodel constraint, its location is
randomized in a window located below the KASLR window.

The rest of the regions being in the same window, we need to detect
collisions.

Note that the module map is embedded in the "boot" region, and that
therefore its location is randomized too.
 1.3 29-Oct-2017  maxv Add three functions and start using them; will be more useful soon.
 1.2 11-Oct-2017  maxv Make sure we're relocating a relocatable kernel.
 1.1 10-Oct-2017  maxv Add the amd64 prekern. It is a kernel relocator used for Kernel ASLR (see
tech-kern@). It works, but is not yet linked to the build system, because
I can't build a distribution right now.
 1.17.6.1 10-Jun-2019  christos Sync with HEAD
 1.17.4.1 18-Jan-2019  pgoyette Synch with HEAD
 1.17.2.2 03-Dec-2017  jdolecek update from HEAD
 1.17.2.1 21-Nov-2017  jdolecek file elf.c was added on branch tls-maxphys on 2017-12-03 11:35:48 +0000
 1.21.6.1 13-May-2021  thorpej Sync with HEAD.
 1.11 19-Mar-2019  maxv Fix/remove some half-baked stuff I left in the prekern:

- Page-align the idt store, to be extra sure.
- Remove unneeded prototypes.
- Drop the TSS, we don't care and aren't even using it.
- Initialize %ss with a default value.
- Fix three exception handlers, no need to push an error code.

No actual impact, because these things are used only when returning from
exceptions received in the prekern; these exceptions are not supposed to
be ever received, never are, and if they were we wouldn't return anyway.
 1.10 09-Mar-2019  maxv Start replacing the x86 PTE bits.
 1.9 07-Mar-2019  maxv Drop PG_RO, PG_KR and PG_PROT, they are useless and create confusion.
 1.8 25-May-2018  maxv branches: 1.8.2;
Hide a bunch of local symbols.
 1.7 22-Dec-2017  maxv branches: 1.7.2;
Sync comments with reality.
 1.6 26-Nov-2017  maxv branches: 1.6.2;
Add rdrand.
 1.5 14-Nov-2017  maxv Remove XXX: set FRAMESIZE to the kernel value. Verily I don't understand
why we are doing that in the non-kaslr kernels, but let's just reproduce
the behavior.

jump_kernel is changed to use callq, so that the stack alignment is
preserved.
 1.4 10-Nov-2017  maxv Add cpuid and rdseed.
 1.3 29-Oct-2017  maxv Randomize the kernel segments independently. That is to say, put text,
rodata and data at different addresses (and in a random order).

To achieve that, the mapping order in the prekern is changed. Until now,
we were creating the kernel map the following way:
-> choose a random VA
-> map [kernpa_start; kernpa_end[ at this VA
-> parse the ELF structures from there
-> determine where exactly the kernel segments are located
-> relocate etc
Now, we are doing:
-> create a read-only view of [kernpa_start; kernpa_end[
-> from this view, compute the size of the "head" region
-> choose a random VA in the HEAD window, and map the head there
-> for each region in (text, rodata, data, boot)
-> compute the size of the region from the RO view
-> choose a random VA in the KASLR window
-> map the region there
-> relocate etc

Each time we map a region, we initialize its bootspace fields right away.

The "head" region must be put before the other regions in memory, because
the kernel uses (headva + sh_offset) to get the addresses of the symbols,
and the offset is unsigned.

Given that the head does not have an mcmodel constraint, its location is
randomized in a window located below the KASLR window.

The rest of the regions being in the same window, we need to detect
collisions.

Note that the module map is embedded in the "boot" region, and that
therefore its location is randomized too.
 1.2 11-Oct-2017  maxv Remove this #if, these options belong to the kernel and not the prekern.
No real change since eblob is always here. And I was apparently drunk
when writing some comments.
 1.1 10-Oct-2017  maxv Add the amd64 prekern. It is a kernel relocator used for Kernel ASLR (see
tech-kern@). It works, but is not yet linked to the build system, because
I can't build a distribution right now.
 1.6.2.2 03-Dec-2017  jdolecek update from HEAD
 1.6.2.1 26-Nov-2017  jdolecek file locore.S was added on branch tls-maxphys on 2017-12-03 11:35:48 +0000
 1.7.2.1 25-Jun-2018  pgoyette Sync with HEAD
 1.8.2.1 10-Jun-2019  christos Sync with HEAD
 1.28 04-May-2021  khorben prekern: add support for warning messages

As submitted on port-amd64@ (part 1/3)

Tested on NetBSD/amd64.
 1.27 07-May-2020  maxv branches: 1.27.6;
Clarify.
 1.26 07-May-2020  maxv Explain more.
 1.25 15-Feb-2020  maxv Explain more.
 1.24 09-Mar-2019  maxv branches: 1.24.6;
Start replacing the x86 PTE bits.
 1.23 07-Mar-2019  maxv Drop PG_RO, PG_KR and PG_PROT, they are useless and create confusion.
 1.22 20-Jun-2018  maxv branches: 1.22.2;
Add and use bootspace.smodule. Initialize it in locore/prekern to better
hide the specifics from the "upper" layers. This allows for greater
flexibility.
 1.21 21-Dec-2017  maxv branches: 1.21.2;
Remove unused macros.
 1.20 26-Nov-2017  maxv branches: 1.20.2;
Oh, damn. Obviously I forgot one case here: an already-mapped region could
be contained entirely in the region we're trying to create. So go through
another round. While here add mm_reenter_pa, and make sure the va given to
mm_enter_pa does not already point to something.
 1.19 26-Nov-2017  maxv Add a PRNG for the prekern, based on SHA512. The formula is basically:

Y0 = SHA512(entropy-file, 256bit rdseed, 64bit rdtsc)
Yn+1 = SHA512(256bit lowerhalf(Yn), 256bit rdseed, 64bit rdtsc)

On each round, random values are taken from the higher half of Yn. If
rdseed is not available, rdrand is used.

The SHA1 checksum of entropy-file is verified. However, the rndsave_t::data
field is not updated by the prekern, because the area is accessed via the
read-only view we created in locore. I like this design, so it will have
to be updated differently.
 1.18 21-Nov-2017  maxv Clean up and add some ASSERTs.
 1.17 15-Nov-2017  maxv Small cleanup.
 1.16 15-Nov-2017  maxv Mmh, should be <=.
 1.15 15-Nov-2017  maxv Define MM_PROT_* locally.
 1.14 15-Nov-2017  maxv Support large pages on KASLR kernels, in a way that does not reduce
randomness, but on the contrary that increases it.

The size of the kernel sub-blocks is changed to be 1MB. This produces a
kernel with sections that are always < 2MB in size, that can fit a large
page.

Each section is put in a 2MB physical chunk. In this chunk, there is a
padding of approximately 1MB. The prekern uses a random offset aligned to
sh_addralign, to shift the section in physical memory.

For example, physical memory layout created by the bootloader for .text.4
and .rodata.0:
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
|+---------------+ |+---------------+ |
|| .text.4 | PAD || .rodata.0 | PAD |
|+---------------+ |+---------------+ |
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
PA PA+2MB PA+4MB

Then, physical memory layout, after having been shifted by the prekern:
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
| P +---------------+ | +---------------+ |
| A | .text.4 | PAD | PAD | .rodata.0 | PAD |
| D +---------------+ | +---------------+ |
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
PA PA+2MB PA+4MB

The kernel maps these 2MB physical chunks with 2MB large pages. Therefore,
randomness is enforced at both the virtual and physical levels, and the
resulting entropy is higher than that of our current implementaion until
now.

The padding around the section is filled by the prekern. Not to consume
too much memory, the sections that are smaller than PAGE_SIZE are mapped
with normal pages - because there is no point in optimizing them. In these
normal pages, the same shift is applied.

This change has two additional advantages: (a) the cache attacks based on
the TLB are mostly mitigated, because even if you are able to determine
that a given page-aligned range is mapped as executable you don't know
where exactly within that range the section actually begins, and (b) given
that we are slightly randomizing the physical layout we are making some
rare physical attacks more difficult to conduct.

NOTE: after this change you need to update GENERIC_KASLR / prekern /
bootloader.
 1.13 14-Nov-2017  maxv Add -Wstrict-prototypes, and fix each warning.
 1.12 13-Nov-2017  maxv Change the mapping logic: don't group sections of the same type into
segments, and rather map each section independently at a random VA.

In particular, .data and .bss are not merged anymore and reside at
different addresses.
 1.11 11-Nov-2017  maxv Detect collisions from bootspace directly.
 1.10 11-Nov-2017  maxv Modify the layout of the bootspace structure, in such a way that it can
contain several kernel segments of the same type (eg several .text
segments). Some parts are still a bit messy but will be cleaned up soon.

I cannot compile-test this change on i386, but it seems fine enough.

NOTE: you need to rebuild and reinstall a new prekern after this change.
 1.9 09-Nov-2017  maxv Fill in the page padding. Only .text is pre-filled by the ld script, but
this will change in the future.
 1.8 05-Nov-2017  maxv Mprotect the segments in mm.c using bootspace, and remove the now unused
fields of elfinfo.
 1.7 29-Oct-2017  maxv Fix a few error messages, and be a little more verbose.
 1.6 29-Oct-2017  maxv Randomize the kernel segments independently. That is to say, put text,
rodata and data at different addresses (and in a random order).

To achieve that, the mapping order in the prekern is changed. Until now,
we were creating the kernel map the following way:
-> choose a random VA
-> map [kernpa_start; kernpa_end[ at this VA
-> parse the ELF structures from there
-> determine where exactly the kernel segments are located
-> relocate etc
Now, we are doing:
-> create a read-only view of [kernpa_start; kernpa_end[
-> from this view, compute the size of the "head" region
-> choose a random VA in the HEAD window, and map the head there
-> for each region in (text, rodata, data, boot)
-> compute the size of the region from the RO view
-> choose a random VA in the KASLR window
-> map the region there
-> relocate etc

Each time we map a region, we initialize its bootspace fields right away.

The "head" region must be put before the other regions in memory, because
the kernel uses (headva + sh_offset) to get the addresses of the symbols,
and the offset is unsigned.

Given that the head does not have an mcmodel constraint, its location is
randomized in a window located below the KASLR window.

The rest of the regions being in the same window, we need to detect
collisions.

Note that the module map is embedded in the "boot" region, and that
therefore its location is randomized too.
 1.5 28-Oct-2017  maxv Fix a mistake I made in the very first revision. The calculation of the
number of slots was incorrect in some cases, and it could cause the
prekern to fault right away at boot time, or the kernel to fault when
loading kernel modules near the end of the module map.

The variables are divided by PAGE_SIZE to prevent integer overflows.
 1.4 23-Oct-2017  maxv Add two XXXs, so that people don't get confused, a fifth region is needed
anyway.
 1.3 18-Oct-2017  maxv If a branch is already there, use it and don't create a new one. This way
we can call mm_map_tree twice with neighboring regions.
 1.2 15-Oct-2017  maxv Descend the page tree from L4 to L1, instead of allocating a separate
branch and linking it at the end. This way we don't need to allocate VA
from the (tiny) prekern map.
 1.1 10-Oct-2017  maxv Add the amd64 prekern. It is a kernel relocator used for Kernel ASLR (see
tech-kern@). It works, but is not yet linked to the build system, because
I can't build a distribution right now.
 1.20.2.2 03-Dec-2017  jdolecek update from HEAD
 1.20.2.1 26-Nov-2017  jdolecek file mm.c was added on branch tls-maxphys on 2017-12-03 11:35:48 +0000
 1.21.2.1 25-Jun-2018  pgoyette Sync with HEAD
 1.22.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.22.2.1 10-Jun-2019  christos Sync with HEAD
 1.24.6.1 29-Feb-2020  ad Sync with head.
 1.27.6.1 13-May-2021  thorpej Sync with HEAD.
 1.8 21-Aug-2022  mlelstv Adapt to pmap/bootspace migrations.
 1.7 23-May-2020  maxv Bump copyrights.
 1.6 03-Nov-2018  maxv Remove VA_SIGN_POS from the computation of the indexes, it is not needed.
 1.5 12-Aug-2018  maxv Move the PTE area from slot 255 to slot 509. I've never understood why we
put it on 255; the "kernel" half of the VM space begins on slot 256, so
if anything, the PTE area should have been above it, not below.

Virtually extend the user slots in slotspace, because we don't want
(randomized) kernel mappings to land on slot 255.

The prekern is updated accordingly.

Tested on GENERIC, GENERIC_KASLR and XEN3_DOM0.
 1.4 21-Jan-2018  maxv branches: 1.4.2; 1.4.4;
Increase the size of the initial mapping of the kernel. KASLR kernels are
bigger than their GENERIC counterparts, and the limit will soon be hit on
them.
 1.3 17-Nov-2017  maxv branches: 1.3.2;
style
 1.2 05-Nov-2017  maxv Remove unused.
 1.1 10-Oct-2017  maxv Add the amd64 prekern. It is a kernel relocator used for Kernel ASLR (see
tech-kern@). It works, but is not yet linked to the build system, because
I can't build a distribution right now.
 1.3.2.2 03-Dec-2017  jdolecek update from HEAD
 1.3.2.1 17-Nov-2017  jdolecek file pdir.h was added on branch tls-maxphys on 2017-12-03 11:35:48 +0000
 1.4.4.1 10-Jun-2019  christos Sync with HEAD
 1.4.2.2 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.4.2.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.14 04-May-2021  khorben prekern: add support for warning messages

As submitted on port-amd64@ (part 1/3)

Tested on NetBSD/amd64.
 1.13 23-May-2020  maxv branches: 1.13.6;
Bump copyrights.
 1.12 23-May-2020  maxv Hum, forgot to include this file in my "Clarify." commit on mm.c:rev1.27
and elf.c:rev1.21.
 1.11 19-Mar-2019  maxv Fix/remove some half-baked stuff I left in the prekern:

- Page-align the idt store, to be extra sure.
- Remove unneeded prototypes.
- Drop the TSS, we don't care and aren't even using it.
- Initialize %ss with a default value.
- Fix three exception handlers, no need to push an error code.

No actual impact, because these things are used only when returning from
exceptions received in the prekern; these exceptions are not supposed to
be ever received, never are, and if they were we wouldn't return anyway.
 1.10 12-Aug-2018  maxv Move the PTE area from slot 255 to slot 509. I've never understood why we
put it on 255; the "kernel" half of the VM space begins on slot 256, so
if anything, the PTE area should have been above it, not below.

Virtually extend the user slots in slotspace, because we don't want
(randomized) kernel mappings to land on slot 255.

The prekern is updated accordingly.

Tested on GENERIC, GENERIC_KASLR and XEN3_DOM0.
 1.9 02-Aug-2018  maxv Add a "version" field in the prekern_args structure. The kernel checks it,
and if it's not happy it returns back to the prekern.
 1.8 25-May-2018  maxv branches: 1.8.2;
Rename the entry points of the prekern, rename the array and move it into
.rodata.
 1.7 26-Nov-2017  maxv branches: 1.7.2; 1.7.4;
Add a PRNG for the prekern, based on SHA512. The formula is basically:

Y0 = SHA512(entropy-file, 256bit rdseed, 64bit rdtsc)
Yn+1 = SHA512(256bit lowerhalf(Yn), 256bit rdseed, 64bit rdtsc)

On each round, random values are taken from the higher half of Yn. If
rdseed is not available, rdrand is used.

The SHA1 checksum of entropy-file is verified. However, the rndsave_t::data
field is not updated by the prekern, because the area is accessed via the
read-only view we created in locore. I like this design, so it will have
to be updated differently.
 1.6 17-Nov-2017  maxv style
 1.5 14-Nov-2017  maxv Add -Wstrict-prototypes, and fix each warning.
 1.4 05-Nov-2017  maxv Mprotect the segments in mm.c using bootspace, and remove the now unused
fields of elfinfo.
 1.3 29-Oct-2017  maxv Randomize the kernel segments independently. That is to say, put text,
rodata and data at different addresses (and in a random order).

To achieve that, the mapping order in the prekern is changed. Until now,
we were creating the kernel map the following way:
-> choose a random VA
-> map [kernpa_start; kernpa_end[ at this VA
-> parse the ELF structures from there
-> determine where exactly the kernel segments are located
-> relocate etc
Now, we are doing:
-> create a read-only view of [kernpa_start; kernpa_end[
-> from this view, compute the size of the "head" region
-> choose a random VA in the HEAD window, and map the head there
-> for each region in (text, rodata, data, boot)
-> compute the size of the region from the RO view
-> choose a random VA in the KASLR window
-> map the region there
-> relocate etc

Each time we map a region, we initialize its bootspace fields right away.

The "head" region must be put before the other regions in memory, because
the kernel uses (headva + sh_offset) to get the addresses of the symbols,
and the offset is unsigned.

Given that the head does not have an mcmodel constraint, its location is
randomized in a window located below the KASLR window.

The rest of the regions being in the same window, we need to detect
collisions.

Note that the module map is embedded in the "boot" region, and that
therefore its location is randomized too.
 1.2 29-Oct-2017  maxv Add a fifth region, called "head". On kaslr kernels it contains the ELF
Header and the ELF Section Headers. On normal kernels it is empty (the
headers are in the "boot" region).

Note: if you're using GENERIC_KASLR, you also need to rebuild the prekern.
 1.1 10-Oct-2017  maxv Add the amd64 prekern. It is a kernel relocator used for Kernel ASLR (see
tech-kern@). It works, but is not yet linked to the build system, because
I can't build a distribution right now.
 1.7.4.2 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.7.4.1 25-Jun-2018  pgoyette Sync with HEAD
 1.7.2.2 03-Dec-2017  jdolecek update from HEAD
 1.7.2.1 26-Nov-2017  jdolecek file prekern.c was added on branch tls-maxphys on 2017-12-03 11:35:48 +0000
 1.8.2.1 10-Jun-2019  christos Sync with HEAD
 1.13.6.1 13-May-2021  thorpej Sync with HEAD.
 1.25 21-Aug-2022  mlelstv Adapt to pmap/bootspace migrations.
 1.24 04-May-2021  khorben prekern: add support for warning messages

As submitted on port-amd64@ (part 1/3)

Tested on NetBSD/amd64.
 1.23 23-May-2020  maxv branches: 1.23.6;
Bump copyrights.
 1.22 07-May-2020  maxv Forgot to commit this file as part of elf.c::rev1.21 mm.c::rev1.27.
 1.21 05-May-2020  maxv Gather the section filtering in a single function, and add a sanity check
when relocating, to make sure the section we're accessing is mappable.

Currently this check fails, because of the Xen section, which has RELAs but
is an unmappable unallocated note.

Also improve the prekern ASSERTs while here.
 1.20 20-Jun-2018  maxv Add and use bootspace.smodule. Initialize it in locore/prekern to better
hide the specifics from the "upper" layers. This allows for greater
flexibility.
 1.19 15-Jan-2018  christos branches: 1.19.2;
avoid typedef redefinitiones
 1.18 26-Nov-2017  maxv branches: 1.18.2;
Add a PRNG for the prekern, based on SHA512. The formula is basically:

Y0 = SHA512(entropy-file, 256bit rdseed, 64bit rdtsc)
Yn+1 = SHA512(256bit lowerhalf(Yn), 256bit rdseed, 64bit rdtsc)

On each round, random values are taken from the higher half of Yn. If
rdseed is not available, rdrand is used.

The SHA1 checksum of entropy-file is verified. However, the rndsave_t::data
field is not updated by the prekern, because the area is accessed via the
read-only view we created in locore. I like this design, so it will have
to be updated differently.
 1.17 26-Nov-2017  maxv Add rdrand.
 1.16 21-Nov-2017  maxv Clean up and add some ASSERTs.
 1.15 15-Nov-2017  maxv Small cleanup.
 1.14 15-Nov-2017  maxv Define MM_PROT_* locally.
 1.13 15-Nov-2017  maxv Support large pages on KASLR kernels, in a way that does not reduce
randomness, but on the contrary that increases it.

The size of the kernel sub-blocks is changed to be 1MB. This produces a
kernel with sections that are always < 2MB in size, that can fit a large
page.

Each section is put in a 2MB physical chunk. In this chunk, there is a
padding of approximately 1MB. The prekern uses a random offset aligned to
sh_addralign, to shift the section in physical memory.

For example, physical memory layout created by the bootloader for .text.4
and .rodata.0:
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
|+---------------+ |+---------------+ |
|| .text.4 | PAD || .rodata.0 | PAD |
|+---------------+ |+---------------+ |
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
PA PA+2MB PA+4MB

Then, physical memory layout, after having been shifted by the prekern:
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
| P +---------------+ | +---------------+ |
| A | .text.4 | PAD | PAD | .rodata.0 | PAD |
| D +---------------+ | +---------------+ |
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
PA PA+2MB PA+4MB

The kernel maps these 2MB physical chunks with 2MB large pages. Therefore,
randomness is enforced at both the virtual and physical levels, and the
resulting entropy is higher than that of our current implementaion until
now.

The padding around the section is filled by the prekern. Not to consume
too much memory, the sections that are smaller than PAGE_SIZE are mapped
with normal pages - because there is no point in optimizing them. In these
normal pages, the same shift is applied.

This change has two additional advantages: (a) the cache attacks based on
the TLB are mostly mitigated, because even if you are able to determine
that a given page-aligned range is mapped as executable you don't know
where exactly within that range the section actually begins, and (b) given
that we are slightly randomizing the physical layout we are making some
rare physical attacks more difficult to conduct.

NOTE: after this change you need to update GENERIC_KASLR / prekern /
bootloader.
 1.12 14-Nov-2017  maxv Add -Wstrict-prototypes, and fix each warning.
 1.11 13-Nov-2017  maxv Change the mapping logic: don't group sections of the same type into
segments, and rather map each section independently at a random VA.

In particular, .data and .bss are not merged anymore and reside at
different addresses.
 1.10 13-Nov-2017  maxv Link libkern in the prekern, and remove redefined functions.
 1.9 11-Nov-2017  maxv Modify the layout of the bootspace structure, in such a way that it can
contain several kernel segments of the same type (eg several .text
segments). Some parts are still a bit messy but will be cleaned up soon.

I cannot compile-test this change on i386, but it seems fine enough.

NOTE: you need to rebuild and reinstall a new prekern after this change.
 1.8 10-Nov-2017  maxv Implement memcpy, the builtin version does not work with variable sizes.
 1.7 10-Nov-2017  maxv Add cpuid and rdseed.
 1.6 09-Nov-2017  maxv Define utility functions as inlines in prekern.h.
 1.5 09-Nov-2017  maxv Fill in the page padding. Only .text is pre-filled by the ld script, but
this will change in the future.
 1.4 05-Nov-2017  maxv Mprotect the segments in mm.c using bootspace, and remove the now unused
fields of elfinfo.
 1.3 29-Oct-2017  maxv Randomize the kernel segments independently. That is to say, put text,
rodata and data at different addresses (and in a random order).

To achieve that, the mapping order in the prekern is changed. Until now,
we were creating the kernel map the following way:
-> choose a random VA
-> map [kernpa_start; kernpa_end[ at this VA
-> parse the ELF structures from there
-> determine where exactly the kernel segments are located
-> relocate etc
Now, we are doing:
-> create a read-only view of [kernpa_start; kernpa_end[
-> from this view, compute the size of the "head" region
-> choose a random VA in the HEAD window, and map the head there
-> for each region in (text, rodata, data, boot)
-> compute the size of the region from the RO view
-> choose a random VA in the KASLR window
-> map the region there
-> relocate etc

Each time we map a region, we initialize its bootspace fields right away.

The "head" region must be put before the other regions in memory, because
the kernel uses (headva + sh_offset) to get the addresses of the symbols,
and the offset is unsigned.

Given that the head does not have an mcmodel constraint, its location is
randomized in a window located below the KASLR window.

The rest of the regions being in the same window, we need to detect
collisions.

Note that the module map is embedded in the "boot" region, and that
therefore its location is randomized too.
 1.2 29-Oct-2017  maxv Add a fifth region, called "head". On kaslr kernels it contains the ELF
Header and the ELF Section Headers. On normal kernels it is empty (the
headers are in the "boot" region).

Note: if you're using GENERIC_KASLR, you also need to rebuild the prekern.
 1.1 10-Oct-2017  maxv Add the amd64 prekern. It is a kernel relocator used for Kernel ASLR (see
tech-kern@). It works, but is not yet linked to the build system, because
I can't build a distribution right now.
 1.18.2.2 03-Dec-2017  jdolecek update from HEAD
 1.18.2.1 26-Nov-2017  jdolecek file prekern.h was added on branch tls-maxphys on 2017-12-03 11:35:48 +0000
 1.19.2.1 25-Jun-2018  pgoyette Sync with HEAD
 1.23.6.1 13-May-2021  thorpej Sync with HEAD.
 1.2 11-Oct-2017  maxv branches: 1.2.2;
Add an alignment to fill strictly all of the padding; does not increase
the size of the prekern.
 1.1 10-Oct-2017  maxv Add the amd64 prekern. It is a kernel relocator used for Kernel ASLR (see
tech-kern@). It works, but is not yet linked to the build system, because
I can't build a distribution right now.
 1.2.2.2 03-Dec-2017  jdolecek update from HEAD
 1.2.2.1 11-Oct-2017  jdolecek file prekern.ldscript was added on branch tls-maxphys on 2017-12-03 11:35:48 +0000
 1.5 04-May-2021  khorben prekern: add warnings upon problems collecting entropy

As submitted on port-amd64@ (part 3/3)

Tested on NetBSD/amd64.
 1.4 04-May-2021  khorben prekern: do not choke on bad entropy files

As submitted on port-amd64@ (part 2/3)

Tested on NetBSD/amd64.
 1.3 21-May-2020  maxv branches: 1.3.6;
Mmh, should check cpuid_level first.
 1.2 26-Nov-2017  maxv branches: 1.2.2;
I forgot to say in my previous commit that the PRNG is inspired from a
conversation with Taylor and Thor on tech-kern@.

(just add a comment)
 1.1 26-Nov-2017  maxv Add a PRNG for the prekern, based on SHA512. The formula is basically:

Y0 = SHA512(entropy-file, 256bit rdseed, 64bit rdtsc)
Yn+1 = SHA512(256bit lowerhalf(Yn), 256bit rdseed, 64bit rdtsc)

On each round, random values are taken from the higher half of Yn. If
rdseed is not available, rdrand is used.

The SHA1 checksum of entropy-file is verified. However, the rndsave_t::data
field is not updated by the prekern, because the area is accessed via the
read-only view we created in locore. I like this design, so it will have
to be updated differently.
 1.2.2.2 03-Dec-2017  jdolecek update from HEAD
 1.2.2.1 26-Nov-2017  jdolecek file prng.c was added on branch tls-maxphys on 2017-12-03 11:35:48 +0000
 1.3.6.1 13-May-2021  thorpej Sync with HEAD.
 1.3 23-May-2020  maxv Bump copyrights.
 1.2 14-Nov-2017  maxv branches: 1.2.2;
Remove XXX: set FRAMESIZE to the kernel value. Verily I don't understand
why we are doing that in the non-kaslr kernels, but let's just reproduce
the behavior.

jump_kernel is changed to use callq, so that the stack alignment is
preserved.
 1.1 10-Oct-2017  maxv Add the amd64 prekern. It is a kernel relocator used for Kernel ASLR (see
tech-kern@). It works, but is not yet linked to the build system, because
I can't build a distribution right now.
 1.2.2.2 03-Dec-2017  jdolecek update from HEAD
 1.2.2.1 14-Nov-2017  jdolecek file redef.h was added on branch tls-maxphys on 2017-12-03 11:35:48 +0000
 1.6 23-May-2020  maxv Bump copyrights.
 1.5 19-Mar-2019  maxv Fix/remove some half-baked stuff I left in the prekern:

- Page-align the idt store, to be extra sure.
- Remove unneeded prototypes.
- Drop the TSS, we don't care and aren't even using it.
- Initialize %ss with a default value.
- Fix three exception handlers, no need to push an error code.

No actual impact, because these things are used only when returning from
exceptions received in the prekern; these exceptions are not supposed to
be ever received, never are, and if they were we wouldn't return anyway.
 1.4 14-Jul-2018  maxv Drop NENTRY() from the x86 kernels, use ENTRY(). With PMCs (and other hardware
tracing facilities) we have a much better ways of monitoring the CPU activity
than GPROF, without software modification.

Also I think GPROF has never worked, because the 'start' functions of both
i386 and amd64 use ENTRY(), and it would have caused a function call while the
kernel was not yet relocated.
 1.3 25-May-2018  maxv branches: 1.3.2;
Rename the entry points of the prekern, rename the array and move it into
.rodata.
 1.2 22-Dec-2017  maxv branches: 1.2.2;
Sync comments with reality.
 1.1 10-Oct-2017  maxv branches: 1.1.2;
Add the amd64 prekern. It is a kernel relocator used for Kernel ASLR (see
tech-kern@). It works, but is not yet linked to the build system, because
I can't build a distribution right now.
 1.1.2.2 03-Dec-2017  jdolecek update from HEAD
 1.1.2.1 10-Oct-2017  jdolecek file trap.S was added on branch tls-maxphys on 2017-12-03 11:35:48 +0000
 1.2.2.2 28-Jul-2018  pgoyette Sync with HEAD
 1.2.2.1 25-Jun-2018  pgoyette Sync with HEAD
 1.3.2.1 10-Jun-2019  christos Sync with HEAD

RSS XML Feed