History log of /openbsd-current/sys/arch/i386/isa/npx.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.76 13-May-2024 jsg

remove prototypes with no matching function
ok mpi@


# 1.75 29-Apr-2024 jsg

remove unused global vars
ok deraadt@ miod@


Revision tags: OPENBSD_7_3_BASE OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.74 30-Jan-2023 jsg

remove unneeded includes in arch/i386
ok krw@ miod@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.73 21-Feb-2022 mpi

Constify struct cfattach.


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.72 24-Sep-2020 deraadt

an ugly white space


# 1.71 19-Aug-2020 mpi

Push KERNEL_LOCK/UNLOCK() dance inside trapsignal().

ok kettenis@, visa@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.70 30-Jul-2018 kettenis

Use the MI interrupt enable/distable API instead of the MD one on i386 and
remove the MD API.

ok deraadt@


# 1.69 11-Apr-2018 bluhm

More steps for i386 Meltdown fix:

- provide struct cpu_info_full
- prepare K-U sections
- reorganize interrupt, trap, syscall entry to use K-U trampoline
- prepare pmap for entering special mappings, the mappings are not
setup yet

This code will already trigger performance issues. We do more tlb
flushes, but we do not unmap the kernel yet. The latter
will be needed to prevent Meltdown.

from hshoexer@; input guenther@; OK mlarkin@ deraadt@


# 1.68 31-Mar-2018 bluhm

Change ci_dev.dv_xname to ci_dev->dv_xname in debugging printf()
to make it compile when enabled.
from hshoexer@


# 1.67 31-Mar-2018 bluhm

Recommit preparation for i386 Meltdown fix after OpenBSD 6.3 release.

- provide a cpu_softc for cpu_attach() etc.
- replace per PCB TSS with per CPU TSS

The first change prepares for cpu_info being embedded in a
cpu_full_info. Therefore during autoconf/cpu_attach we hand down
a softc.

The second change removes the per PCB TSS. We now have one TSS per
CPU, thus in cpu_switchto() we only have to patch the ring 0 stack
pointer instead of loading a new TSS. This also allows for cleaning
up the GDT, so we only have a single slot for the TSS.

from hshoexer@; OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.66 22-Mar-2018 bluhm

iBackout the preparations for fixing Meltdown on i386. The task was
only halfway done and the current state does not help anybody. For
OpenBSD 6.3 release go back to the original code before 2018/03/13.
This gives us a stable release and the changes will come back later.
discussed with guenther@ deraadt@ hshoexer@


# 1.65 13-Mar-2018 bluhm

Preparation for i386 Meltdown fix:

- provide a cpu_softc for cpu_attach() etc.
- replace per PCB TSS with per CPU TSS

The first change prepares for cpu_info being embedded in a
cpu_full_info. Therefore during autoconf/cpu_attach we hand down
a softc.

The second change removes the per PCB TSS. We now have one TSS per
CPU, thus in cpu_switchto() we only have to patch the ring 0 stack
pointer instead of loading a new TSS. This also allows for cleaning
up the GDT, so we only have a single slot for the TSS.

from hshoexer@; OK deraadt@


# 1.64 01-Mar-2018 bluhm

Protect the calls to trapsignal() and psignal() with a kernel lock
when processing an npx interrupt. This fixes a kernel locked
assertion in postsig_done() during the libc ieeefp/except regression
test.
OK visa@


# 1.63 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.62 29-May-2017 mpi

Kill SPINLOCK_SPIN_HOOK, use CPU_BUSY_CYCLE() instead.

ok visa@, kettenis@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.61 11-Feb-2015 dlg

deprecate use of sys/lock.h and replace it with sys/atomic.h or
machine/lock.h as appropriate.


Revision tags: OPENBSD_5_6_BASE
# 1.60 29-Mar-2014 guenther

It's been a quarter century: we can assume volatile is present with that name.

ok dlg@ mpi@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.59 16-Nov-2013 brad

Copied from amd64..

Use an explicit suffix for the "fld" instruction to shut up clang. The correct
instruction is fldl since we try to load a double-precision value.
GCC actually gets it wrong and emits "flds" (which is harmless).

ok guenther@


Revision tags: OPENBSD_5_4_BASE
# 1.58 08-May-2013 tedu

remove stale cyrix emc support, and switch to just using intial npxcw
ok kettenis


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.57 11-Jul-2011 guenther

Revert art@'s moving around of the KERNEL_LOCK()/KERNEL_UNLOCK() calls,
as it causes hangs in some ports, including libsigsegv's configure script

confirmed by krw@, landry@


# 1.56 07-Jul-2011 art

There is a bunch of places in the kernel entry points where we don't
hold the kernel lock, but still need call one function that needs it.

Instead of grabbing the lock all over the place, move the locks into
the affected functions: trapsignal, scdebug*, ktrsyscall, ktrsysret,
systrace_redirect and ADDUPROF. In the cases we already hold the biglock
we'll just recurse.

kettenis@, beck@ ok


# 1.55 06-Jul-2011 art

Clean up after P_BIGLOCK removal.
KERNEL_PROC_LOCK -> KERNEL_LOCK
KERNEL_PROC_UNLOCK -> KERNEL_UNLOCK

oga@ ok


# 1.54 20-Mar-2011 guenther

When reading MXCSR from userland sigcontext or a ptrace request,
mask out invalid bits to prevent a protect fault.

Original diff by joshe@; further feedback and ok kettenis@


Revision tags: OPENBSD_4_9_BASE
# 1.53 29-Sep-2010 joshe

Back out previous, it appears to be broken.


# 1.52 29-Sep-2010 joshe

When reading MXCSR from userland sigcontext, mask out invalid bits.

This prevents a protection fault if a userland signal handler
scribbles all over it's struct sigcontext

Help from and ok guenther@ kettenis@


Revision tags: OPENBSD_4_8_BASE
# 1.51 23-Jul-2010 kettenis

Change the strategy for using the FPU in the kernel. The kernel FPU state
is now shared with all processes/threads. As a result, you can now use the
FPU in true process context (instead of just in kernel threads), but you
need to make sure you restore the default FPU state before calling
fpu_kernel_exit() if you change rounding mode, precision or exception masks.

Lots of discussion with thib@ and Mike Belopuhov.

ok thib@, deraadt@


# 1.50 23-Jul-2010 kettenis

Don't leak the contents of the FPU and SSE registers between processes.

ok deraadt@


# 1.49 21-Jul-2010 kettenis

Make sure that the FPU IPIs shoot down the right FPU context and not the FPU
context of some random process that happened to be switched onto the FPU
after the decision was made to send the IPI.


# 1.48 29-Jun-2010 thib

fpu_kernel_{enter,exit}; Functions to allow the use of
the FPU in the kernel.

From Mike Belopuhov; Little bits by myself.

Comments/OK kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.47 28-Oct-2009 deraadt

delete balony comment; ok kettenis


# 1.46 26-Oct-2009 kettenis

Load %mxcsr when initializing the FPU on machines that support SSE.

ok deraadt@


# 1.45 03-Oct-2009 kettenis

Properly handle XMM exceptions instead of panicing the kernel. Fixes the
issue reported by Slava Pestov.

ok deraadt@


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.44 04-Dec-2008 weingart

branches: 1.44.2; 1.44.6;
Fix "fp_save ipi didn't" panic, and move i386/amd64 closer in the process.
Positive test results by a handful of people. Ok kettenis@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.43 28-Nov-2007 tedu

branches: 1.43.4;
quite a bit of simplification by removing cpu classes.
also assume that 386 cpus are really unknown, and promote them to 486
instead of panic.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.42 18-Oct-2006 tom

Short-circuit the detection of the FPU by checking the CPUID features,
as done in FreeBSD. Fixes problems on AMD Geode LX-800 where our
detection logic doesn't detect the FP exception.

ok deraadt@ kettenis@


# 1.41 19-Sep-2006 jsg

ansi/deregister


Revision tags: OPENBSD_4_0_BASE
# 1.40 25-Jul-2006 kettenis

branches: 1.40.2;
Kill option GPL_MATH_EMULATE.

ok deraadt@ and many others.


# 1.39 19-Apr-2006 mickey

from todays freebsd advisory: fxrstor on amd cpu does not restore fip,fdp,fop thus leaking other proc's execution history; deraadt@ ok


# 1.38 13-Mar-2006 mickey

time-bind and lower power in lock spinning and a couple of other ipi loops by using pause insn; brad@ ok tedu@ ok and feedback krw@ testing


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 06-Jun-2005 mickey

branches: 1.37.2; 1.37.4;
oops. on 686 we count fpswtch in another function...


# 1.36 21-Apr-2005 mickey

count fpu lazy context switches; deraadt@ ok


Revision tags: OPENBSD_3_7_BASE
# 1.35 21-Oct-2004 kettenis

branches: 1.35.2;
SIGFPE signal codes for SSE.
nice deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.34 21-Jul-2004 kettenis

Fix conversion of interrupt frame to trap frame.
ok deraadt@, niklas@


# 1.33 13-Jul-2004 art

Don't assert that P_INMEM is set in p_flag. The assert is only almost
correct because P_INMEM is for various reasons removed before cpu_swapout
is called and cpu_swapout in turn calls npxsave_proc.

deraadt@ ok


# 1.32 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.31 01-Feb-2004 deraadt

Enable FXSR all the time, and cope with NPX/FXSR conversions; from netbsd.
Pass SSE/SSE2/XCRYPT flags out via syctl, and prepare for being able to do
xcrypt-* in userland; ok naddy, tested a lot by pvalchev and jolan, also
works on amd64 in 32bit mode


# 1.30 31-Dec-2003 deraadt

workaround: during npx exception testing, delay(1). For some reason
amd64 (in 32 bit mode) and the new transmeta cpus want this, and lock
up otherwise. very odd.


# 1.29 24-Oct-2003 grange

No need to have several implementations of {read,write}_eflags(),
put it to cpufunc.h.
ok weingart@ tedu@


Revision tags: OPENBSD_3_4_BASE
# 1.28 25-Jul-2003 jason

let ALWAYS_MATH_EMULATE actually compile


# 1.27 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: UBC_SYNC_A
# 1.26 17-Apr-2003 drahn

i386 changes to move to ELF. asm cleanup. Change MAXDSIZ to 512M for 1Gsep.
DARPA funded work.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.25 14-Mar-2002 millert

First round of __P removal in sys


# 1.24 18-Feb-2002 ericj

multi-line string literals are deprecated in gcc 3.0
pr#2379


Revision tags: UBC_BASE
# 1.23 04-Dec-2001 niklas

branches: 1.23.2;
New try at a level based irq system.


# 1.22 18-Nov-2001 aaron

Revert niklas's broken ICU interrupt handling changes; deraadt@ ok


# 1.21 12-Nov-2001 niklas

Redo the ICU interrupt handling system to better emulate an APIC system.
This is done by representing the current blockings of interrupts with
a priority level instead of an interrupt mask. This makes it possible to
share implementations for spl* functions/macros between both ICU
and APIC (a must when going MP) systems. In this process, assign
soft interrupts their own levels to match the way things will be on
APIC systems where they actually will be real interrupts and not just
bits in a pending mask as they are now.
Heavily inspired by Bill Studenmunds SMP work in NetBSD


# 1.20 06-Nov-2001 miod

Replace inclusion of <vm/foo.h> with the correct <uvm/bar.h> when necessary.
(Look ma, I might have broken the tree)


Revision tags: OPENBSD_3_0_BASE
# 1.19 05-May-2001 art

PMAP_NEW and UVM are no longer optional on i386.


Revision tags: OPENBSD_2_9_BASE
# 1.18 09-Apr-2001 tholo

Add emulation of Linux features to procfs; mostly from NetBSD. ok deraadt@


Revision tags: OPENBSD_2_8_BASE
# 1.17 08-Jun-2000 niklas

Add explicit inclusions of signalvar.h to files actually using syms defined
there but relying on an indirect inclusion


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE SMP_BASE kame_19991208
# 1.16 26-Feb-1999 art

branches: 1.16.6;
cnt.foo -> uvmexp.bar in uvm


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.15 22-Feb-1998 niklas

GCC 2.8 Wall


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.14 17-Apr-1997 tholo

Do interrupt time accounting by running interrupt handlers with a seperate
code segment selector (otherwise identical to the standard kernel code
selector); idea by Dave Richards <richards@zso.dec.com>


# 1.13 08-Feb-1997 tholo

Provide more information on FP exceptions


# 1.12 01-Feb-1997 deraadt

add type & union sigval args to sendsig/trapsignal


# 1.11 27-Jan-1997 deraadt

add another parameter to trapsignal() and sendsig() -- fault addr to be
delivered with in the siginfo information


Revision tags: OPENBSD_2_0_BASE
# 1.10 27-Aug-1996 downsj

Add:
* GPL_MATH_EMULATE: fpemul
* ALWAYS_MATH_EMULATE: causes npx probe to always fail.
* better fp context in struct pcb.


# 1.9 25-May-1996 deraadt

sync


# 1.8 07-May-1996 deraadt

sync with 0504; prototype changes


# 1.7 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.6 20-Mar-1996 mickey

Fix back wrong patches.


# 1.5 19-Mar-1996 mickey

Merging w/ NetBSD 021796.
speaker upgraded to the current.
some changes to the VM stuff (ie kern_thread.c added and so).


# 1.4 20-Feb-1996 tholo

Pass device name to interrupt establish routines so it can be recorded in
the device interrupt chain structures (isa, pci)

Move interrupt chain structure definition to <machine/psl.h> so vmstat can
get at it (i386)

Remove hack to count interrupts the old way (i386)


# 1.3 07-Jan-1996 deraadt

from netbsd: Put #includes in the right order


# 1.2 27-Dec-1995 deraadt

from netbsd:
The IST_* and IPL_* constants are not bus-specific; don't treat them as such.


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.75 29-Apr-2024 jsg

remove unused global vars
ok deraadt@ miod@


Revision tags: OPENBSD_7_3_BASE OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.74 30-Jan-2023 jsg

remove unneeded includes in arch/i386
ok krw@ miod@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.73 21-Feb-2022 mpi

Constify struct cfattach.


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.72 24-Sep-2020 deraadt

an ugly white space


# 1.71 19-Aug-2020 mpi

Push KERNEL_LOCK/UNLOCK() dance inside trapsignal().

ok kettenis@, visa@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.70 30-Jul-2018 kettenis

Use the MI interrupt enable/distable API instead of the MD one on i386 and
remove the MD API.

ok deraadt@


# 1.69 11-Apr-2018 bluhm

More steps for i386 Meltdown fix:

- provide struct cpu_info_full
- prepare K-U sections
- reorganize interrupt, trap, syscall entry to use K-U trampoline
- prepare pmap for entering special mappings, the mappings are not
setup yet

This code will already trigger performance issues. We do more tlb
flushes, but we do not unmap the kernel yet. The latter
will be needed to prevent Meltdown.

from hshoexer@; input guenther@; OK mlarkin@ deraadt@


# 1.68 31-Mar-2018 bluhm

Change ci_dev.dv_xname to ci_dev->dv_xname in debugging printf()
to make it compile when enabled.
from hshoexer@


# 1.67 31-Mar-2018 bluhm

Recommit preparation for i386 Meltdown fix after OpenBSD 6.3 release.

- provide a cpu_softc for cpu_attach() etc.
- replace per PCB TSS with per CPU TSS

The first change prepares for cpu_info being embedded in a
cpu_full_info. Therefore during autoconf/cpu_attach we hand down
a softc.

The second change removes the per PCB TSS. We now have one TSS per
CPU, thus in cpu_switchto() we only have to patch the ring 0 stack
pointer instead of loading a new TSS. This also allows for cleaning
up the GDT, so we only have a single slot for the TSS.

from hshoexer@; OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.66 22-Mar-2018 bluhm

iBackout the preparations for fixing Meltdown on i386. The task was
only halfway done and the current state does not help anybody. For
OpenBSD 6.3 release go back to the original code before 2018/03/13.
This gives us a stable release and the changes will come back later.
discussed with guenther@ deraadt@ hshoexer@


# 1.65 13-Mar-2018 bluhm

Preparation for i386 Meltdown fix:

- provide a cpu_softc for cpu_attach() etc.
- replace per PCB TSS with per CPU TSS

The first change prepares for cpu_info being embedded in a
cpu_full_info. Therefore during autoconf/cpu_attach we hand down
a softc.

The second change removes the per PCB TSS. We now have one TSS per
CPU, thus in cpu_switchto() we only have to patch the ring 0 stack
pointer instead of loading a new TSS. This also allows for cleaning
up the GDT, so we only have a single slot for the TSS.

from hshoexer@; OK deraadt@


# 1.64 01-Mar-2018 bluhm

Protect the calls to trapsignal() and psignal() with a kernel lock
when processing an npx interrupt. This fixes a kernel locked
assertion in postsig_done() during the libc ieeefp/except regression
test.
OK visa@


# 1.63 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.62 29-May-2017 mpi

Kill SPINLOCK_SPIN_HOOK, use CPU_BUSY_CYCLE() instead.

ok visa@, kettenis@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.61 11-Feb-2015 dlg

deprecate use of sys/lock.h and replace it with sys/atomic.h or
machine/lock.h as appropriate.


Revision tags: OPENBSD_5_6_BASE
# 1.60 29-Mar-2014 guenther

It's been a quarter century: we can assume volatile is present with that name.

ok dlg@ mpi@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.59 16-Nov-2013 brad

Copied from amd64..

Use an explicit suffix for the "fld" instruction to shut up clang. The correct
instruction is fldl since we try to load a double-precision value.
GCC actually gets it wrong and emits "flds" (which is harmless).

ok guenther@


Revision tags: OPENBSD_5_4_BASE
# 1.58 08-May-2013 tedu

remove stale cyrix emc support, and switch to just using intial npxcw
ok kettenis


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.57 11-Jul-2011 guenther

Revert art@'s moving around of the KERNEL_LOCK()/KERNEL_UNLOCK() calls,
as it causes hangs in some ports, including libsigsegv's configure script

confirmed by krw@, landry@


# 1.56 07-Jul-2011 art

There is a bunch of places in the kernel entry points where we don't
hold the kernel lock, but still need call one function that needs it.

Instead of grabbing the lock all over the place, move the locks into
the affected functions: trapsignal, scdebug*, ktrsyscall, ktrsysret,
systrace_redirect and ADDUPROF. In the cases we already hold the biglock
we'll just recurse.

kettenis@, beck@ ok


# 1.55 06-Jul-2011 art

Clean up after P_BIGLOCK removal.
KERNEL_PROC_LOCK -> KERNEL_LOCK
KERNEL_PROC_UNLOCK -> KERNEL_UNLOCK

oga@ ok


# 1.54 20-Mar-2011 guenther

When reading MXCSR from userland sigcontext or a ptrace request,
mask out invalid bits to prevent a protect fault.

Original diff by joshe@; further feedback and ok kettenis@


Revision tags: OPENBSD_4_9_BASE
# 1.53 29-Sep-2010 joshe

Back out previous, it appears to be broken.


# 1.52 29-Sep-2010 joshe

When reading MXCSR from userland sigcontext, mask out invalid bits.

This prevents a protection fault if a userland signal handler
scribbles all over it's struct sigcontext

Help from and ok guenther@ kettenis@


Revision tags: OPENBSD_4_8_BASE
# 1.51 23-Jul-2010 kettenis

Change the strategy for using the FPU in the kernel. The kernel FPU state
is now shared with all processes/threads. As a result, you can now use the
FPU in true process context (instead of just in kernel threads), but you
need to make sure you restore the default FPU state before calling
fpu_kernel_exit() if you change rounding mode, precision or exception masks.

Lots of discussion with thib@ and Mike Belopuhov.

ok thib@, deraadt@


# 1.50 23-Jul-2010 kettenis

Don't leak the contents of the FPU and SSE registers between processes.

ok deraadt@


# 1.49 21-Jul-2010 kettenis

Make sure that the FPU IPIs shoot down the right FPU context and not the FPU
context of some random process that happened to be switched onto the FPU
after the decision was made to send the IPI.


# 1.48 29-Jun-2010 thib

fpu_kernel_{enter,exit}; Functions to allow the use of
the FPU in the kernel.

From Mike Belopuhov; Little bits by myself.

Comments/OK kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.47 28-Oct-2009 deraadt

delete balony comment; ok kettenis


# 1.46 26-Oct-2009 kettenis

Load %mxcsr when initializing the FPU on machines that support SSE.

ok deraadt@


# 1.45 03-Oct-2009 kettenis

Properly handle XMM exceptions instead of panicing the kernel. Fixes the
issue reported by Slava Pestov.

ok deraadt@


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.44 04-Dec-2008 weingart

branches: 1.44.2; 1.44.6;
Fix "fp_save ipi didn't" panic, and move i386/amd64 closer in the process.
Positive test results by a handful of people. Ok kettenis@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.43 28-Nov-2007 tedu

branches: 1.43.4;
quite a bit of simplification by removing cpu classes.
also assume that 386 cpus are really unknown, and promote them to 486
instead of panic.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.42 18-Oct-2006 tom

Short-circuit the detection of the FPU by checking the CPUID features,
as done in FreeBSD. Fixes problems on AMD Geode LX-800 where our
detection logic doesn't detect the FP exception.

ok deraadt@ kettenis@


# 1.41 19-Sep-2006 jsg

ansi/deregister


Revision tags: OPENBSD_4_0_BASE
# 1.40 25-Jul-2006 kettenis

branches: 1.40.2;
Kill option GPL_MATH_EMULATE.

ok deraadt@ and many others.


# 1.39 19-Apr-2006 mickey

from todays freebsd advisory: fxrstor on amd cpu does not restore fip,fdp,fop thus leaking other proc's execution history; deraadt@ ok


# 1.38 13-Mar-2006 mickey

time-bind and lower power in lock spinning and a couple of other ipi loops by using pause insn; brad@ ok tedu@ ok and feedback krw@ testing


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 06-Jun-2005 mickey

branches: 1.37.2; 1.37.4;
oops. on 686 we count fpswtch in another function...


# 1.36 21-Apr-2005 mickey

count fpu lazy context switches; deraadt@ ok


Revision tags: OPENBSD_3_7_BASE
# 1.35 21-Oct-2004 kettenis

branches: 1.35.2;
SIGFPE signal codes for SSE.
nice deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.34 21-Jul-2004 kettenis

Fix conversion of interrupt frame to trap frame.
ok deraadt@, niklas@


# 1.33 13-Jul-2004 art

Don't assert that P_INMEM is set in p_flag. The assert is only almost
correct because P_INMEM is for various reasons removed before cpu_swapout
is called and cpu_swapout in turn calls npxsave_proc.

deraadt@ ok


# 1.32 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.31 01-Feb-2004 deraadt

Enable FXSR all the time, and cope with NPX/FXSR conversions; from netbsd.
Pass SSE/SSE2/XCRYPT flags out via syctl, and prepare for being able to do
xcrypt-* in userland; ok naddy, tested a lot by pvalchev and jolan, also
works on amd64 in 32bit mode


# 1.30 31-Dec-2003 deraadt

workaround: during npx exception testing, delay(1). For some reason
amd64 (in 32 bit mode) and the new transmeta cpus want this, and lock
up otherwise. very odd.


# 1.29 24-Oct-2003 grange

No need to have several implementations of {read,write}_eflags(),
put it to cpufunc.h.
ok weingart@ tedu@


Revision tags: OPENBSD_3_4_BASE
# 1.28 25-Jul-2003 jason

let ALWAYS_MATH_EMULATE actually compile


# 1.27 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: UBC_SYNC_A
# 1.26 17-Apr-2003 drahn

i386 changes to move to ELF. asm cleanup. Change MAXDSIZ to 512M for 1Gsep.
DARPA funded work.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.25 14-Mar-2002 millert

First round of __P removal in sys


# 1.24 18-Feb-2002 ericj

multi-line string literals are deprecated in gcc 3.0
pr#2379


Revision tags: UBC_BASE
# 1.23 04-Dec-2001 niklas

branches: 1.23.2;
New try at a level based irq system.


# 1.22 18-Nov-2001 aaron

Revert niklas's broken ICU interrupt handling changes; deraadt@ ok


# 1.21 12-Nov-2001 niklas

Redo the ICU interrupt handling system to better emulate an APIC system.
This is done by representing the current blockings of interrupts with
a priority level instead of an interrupt mask. This makes it possible to
share implementations for spl* functions/macros between both ICU
and APIC (a must when going MP) systems. In this process, assign
soft interrupts their own levels to match the way things will be on
APIC systems where they actually will be real interrupts and not just
bits in a pending mask as they are now.
Heavily inspired by Bill Studenmunds SMP work in NetBSD


# 1.20 06-Nov-2001 miod

Replace inclusion of <vm/foo.h> with the correct <uvm/bar.h> when necessary.
(Look ma, I might have broken the tree)


Revision tags: OPENBSD_3_0_BASE
# 1.19 05-May-2001 art

PMAP_NEW and UVM are no longer optional on i386.


Revision tags: OPENBSD_2_9_BASE
# 1.18 09-Apr-2001 tholo

Add emulation of Linux features to procfs; mostly from NetBSD. ok deraadt@


Revision tags: OPENBSD_2_8_BASE
# 1.17 08-Jun-2000 niklas

Add explicit inclusions of signalvar.h to files actually using syms defined
there but relying on an indirect inclusion


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE SMP_BASE kame_19991208
# 1.16 26-Feb-1999 art

branches: 1.16.6;
cnt.foo -> uvmexp.bar in uvm


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.15 22-Feb-1998 niklas

GCC 2.8 Wall


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.14 17-Apr-1997 tholo

Do interrupt time accounting by running interrupt handlers with a seperate
code segment selector (otherwise identical to the standard kernel code
selector); idea by Dave Richards <richards@zso.dec.com>


# 1.13 08-Feb-1997 tholo

Provide more information on FP exceptions


# 1.12 01-Feb-1997 deraadt

add type & union sigval args to sendsig/trapsignal


# 1.11 27-Jan-1997 deraadt

add another parameter to trapsignal() and sendsig() -- fault addr to be
delivered with in the siginfo information


Revision tags: OPENBSD_2_0_BASE
# 1.10 27-Aug-1996 downsj

Add:
* GPL_MATH_EMULATE: fpemul
* ALWAYS_MATH_EMULATE: causes npx probe to always fail.
* better fp context in struct pcb.


# 1.9 25-May-1996 deraadt

sync


# 1.8 07-May-1996 deraadt

sync with 0504; prototype changes


# 1.7 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.6 20-Mar-1996 mickey

Fix back wrong patches.


# 1.5 19-Mar-1996 mickey

Merging w/ NetBSD 021796.
speaker upgraded to the current.
some changes to the VM stuff (ie kern_thread.c added and so).


# 1.4 20-Feb-1996 tholo

Pass device name to interrupt establish routines so it can be recorded in
the device interrupt chain structures (isa, pci)

Move interrupt chain structure definition to <machine/psl.h> so vmstat can
get at it (i386)

Remove hack to count interrupts the old way (i386)


# 1.3 07-Jan-1996 deraadt

from netbsd: Put #includes in the right order


# 1.2 27-Dec-1995 deraadt

from netbsd:
The IST_* and IPL_* constants are not bus-specific; don't treat them as such.


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.74 30-Jan-2023 jsg

remove unneeded includes in arch/i386
ok krw@ miod@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.73 21-Feb-2022 mpi

Constify struct cfattach.


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.72 24-Sep-2020 deraadt

an ugly white space


# 1.71 19-Aug-2020 mpi

Push KERNEL_LOCK/UNLOCK() dance inside trapsignal().

ok kettenis@, visa@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.70 30-Jul-2018 kettenis

Use the MI interrupt enable/distable API instead of the MD one on i386 and
remove the MD API.

ok deraadt@


# 1.69 11-Apr-2018 bluhm

More steps for i386 Meltdown fix:

- provide struct cpu_info_full
- prepare K-U sections
- reorganize interrupt, trap, syscall entry to use K-U trampoline
- prepare pmap for entering special mappings, the mappings are not
setup yet

This code will already trigger performance issues. We do more tlb
flushes, but we do not unmap the kernel yet. The latter
will be needed to prevent Meltdown.

from hshoexer@; input guenther@; OK mlarkin@ deraadt@


# 1.68 31-Mar-2018 bluhm

Change ci_dev.dv_xname to ci_dev->dv_xname in debugging printf()
to make it compile when enabled.
from hshoexer@


# 1.67 31-Mar-2018 bluhm

Recommit preparation for i386 Meltdown fix after OpenBSD 6.3 release.

- provide a cpu_softc for cpu_attach() etc.
- replace per PCB TSS with per CPU TSS

The first change prepares for cpu_info being embedded in a
cpu_full_info. Therefore during autoconf/cpu_attach we hand down
a softc.

The second change removes the per PCB TSS. We now have one TSS per
CPU, thus in cpu_switchto() we only have to patch the ring 0 stack
pointer instead of loading a new TSS. This also allows for cleaning
up the GDT, so we only have a single slot for the TSS.

from hshoexer@; OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.66 22-Mar-2018 bluhm

iBackout the preparations for fixing Meltdown on i386. The task was
only halfway done and the current state does not help anybody. For
OpenBSD 6.3 release go back to the original code before 2018/03/13.
This gives us a stable release and the changes will come back later.
discussed with guenther@ deraadt@ hshoexer@


# 1.65 13-Mar-2018 bluhm

Preparation for i386 Meltdown fix:

- provide a cpu_softc for cpu_attach() etc.
- replace per PCB TSS with per CPU TSS

The first change prepares for cpu_info being embedded in a
cpu_full_info. Therefore during autoconf/cpu_attach we hand down
a softc.

The second change removes the per PCB TSS. We now have one TSS per
CPU, thus in cpu_switchto() we only have to patch the ring 0 stack
pointer instead of loading a new TSS. This also allows for cleaning
up the GDT, so we only have a single slot for the TSS.

from hshoexer@; OK deraadt@


# 1.64 01-Mar-2018 bluhm

Protect the calls to trapsignal() and psignal() with a kernel lock
when processing an npx interrupt. This fixes a kernel locked
assertion in postsig_done() during the libc ieeefp/except regression
test.
OK visa@


# 1.63 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.62 29-May-2017 mpi

Kill SPINLOCK_SPIN_HOOK, use CPU_BUSY_CYCLE() instead.

ok visa@, kettenis@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.61 11-Feb-2015 dlg

deprecate use of sys/lock.h and replace it with sys/atomic.h or
machine/lock.h as appropriate.


Revision tags: OPENBSD_5_6_BASE
# 1.60 29-Mar-2014 guenther

It's been a quarter century: we can assume volatile is present with that name.

ok dlg@ mpi@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.59 16-Nov-2013 brad

Copied from amd64..

Use an explicit suffix for the "fld" instruction to shut up clang. The correct
instruction is fldl since we try to load a double-precision value.
GCC actually gets it wrong and emits "flds" (which is harmless).

ok guenther@


Revision tags: OPENBSD_5_4_BASE
# 1.58 08-May-2013 tedu

remove stale cyrix emc support, and switch to just using intial npxcw
ok kettenis


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.57 11-Jul-2011 guenther

Revert art@'s moving around of the KERNEL_LOCK()/KERNEL_UNLOCK() calls,
as it causes hangs in some ports, including libsigsegv's configure script

confirmed by krw@, landry@


# 1.56 07-Jul-2011 art

There is a bunch of places in the kernel entry points where we don't
hold the kernel lock, but still need call one function that needs it.

Instead of grabbing the lock all over the place, move the locks into
the affected functions: trapsignal, scdebug*, ktrsyscall, ktrsysret,
systrace_redirect and ADDUPROF. In the cases we already hold the biglock
we'll just recurse.

kettenis@, beck@ ok


# 1.55 06-Jul-2011 art

Clean up after P_BIGLOCK removal.
KERNEL_PROC_LOCK -> KERNEL_LOCK
KERNEL_PROC_UNLOCK -> KERNEL_UNLOCK

oga@ ok


# 1.54 20-Mar-2011 guenther

When reading MXCSR from userland sigcontext or a ptrace request,
mask out invalid bits to prevent a protect fault.

Original diff by joshe@; further feedback and ok kettenis@


Revision tags: OPENBSD_4_9_BASE
# 1.53 29-Sep-2010 joshe

Back out previous, it appears to be broken.


# 1.52 29-Sep-2010 joshe

When reading MXCSR from userland sigcontext, mask out invalid bits.

This prevents a protection fault if a userland signal handler
scribbles all over it's struct sigcontext

Help from and ok guenther@ kettenis@


Revision tags: OPENBSD_4_8_BASE
# 1.51 23-Jul-2010 kettenis

Change the strategy for using the FPU in the kernel. The kernel FPU state
is now shared with all processes/threads. As a result, you can now use the
FPU in true process context (instead of just in kernel threads), but you
need to make sure you restore the default FPU state before calling
fpu_kernel_exit() if you change rounding mode, precision or exception masks.

Lots of discussion with thib@ and Mike Belopuhov.

ok thib@, deraadt@


# 1.50 23-Jul-2010 kettenis

Don't leak the contents of the FPU and SSE registers between processes.

ok deraadt@


# 1.49 21-Jul-2010 kettenis

Make sure that the FPU IPIs shoot down the right FPU context and not the FPU
context of some random process that happened to be switched onto the FPU
after the decision was made to send the IPI.


# 1.48 29-Jun-2010 thib

fpu_kernel_{enter,exit}; Functions to allow the use of
the FPU in the kernel.

From Mike Belopuhov; Little bits by myself.

Comments/OK kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.47 28-Oct-2009 deraadt

delete balony comment; ok kettenis


# 1.46 26-Oct-2009 kettenis

Load %mxcsr when initializing the FPU on machines that support SSE.

ok deraadt@


# 1.45 03-Oct-2009 kettenis

Properly handle XMM exceptions instead of panicing the kernel. Fixes the
issue reported by Slava Pestov.

ok deraadt@


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.44 04-Dec-2008 weingart

branches: 1.44.2; 1.44.6;
Fix "fp_save ipi didn't" panic, and move i386/amd64 closer in the process.
Positive test results by a handful of people. Ok kettenis@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.43 28-Nov-2007 tedu

branches: 1.43.4;
quite a bit of simplification by removing cpu classes.
also assume that 386 cpus are really unknown, and promote them to 486
instead of panic.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.42 18-Oct-2006 tom

Short-circuit the detection of the FPU by checking the CPUID features,
as done in FreeBSD. Fixes problems on AMD Geode LX-800 where our
detection logic doesn't detect the FP exception.

ok deraadt@ kettenis@


# 1.41 19-Sep-2006 jsg

ansi/deregister


Revision tags: OPENBSD_4_0_BASE
# 1.40 25-Jul-2006 kettenis

branches: 1.40.2;
Kill option GPL_MATH_EMULATE.

ok deraadt@ and many others.


# 1.39 19-Apr-2006 mickey

from todays freebsd advisory: fxrstor on amd cpu does not restore fip,fdp,fop thus leaking other proc's execution history; deraadt@ ok


# 1.38 13-Mar-2006 mickey

time-bind and lower power in lock spinning and a couple of other ipi loops by using pause insn; brad@ ok tedu@ ok and feedback krw@ testing


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 06-Jun-2005 mickey

branches: 1.37.2; 1.37.4;
oops. on 686 we count fpswtch in another function...


# 1.36 21-Apr-2005 mickey

count fpu lazy context switches; deraadt@ ok


Revision tags: OPENBSD_3_7_BASE
# 1.35 21-Oct-2004 kettenis

branches: 1.35.2;
SIGFPE signal codes for SSE.
nice deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.34 21-Jul-2004 kettenis

Fix conversion of interrupt frame to trap frame.
ok deraadt@, niklas@


# 1.33 13-Jul-2004 art

Don't assert that P_INMEM is set in p_flag. The assert is only almost
correct because P_INMEM is for various reasons removed before cpu_swapout
is called and cpu_swapout in turn calls npxsave_proc.

deraadt@ ok


# 1.32 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.31 01-Feb-2004 deraadt

Enable FXSR all the time, and cope with NPX/FXSR conversions; from netbsd.
Pass SSE/SSE2/XCRYPT flags out via syctl, and prepare for being able to do
xcrypt-* in userland; ok naddy, tested a lot by pvalchev and jolan, also
works on amd64 in 32bit mode


# 1.30 31-Dec-2003 deraadt

workaround: during npx exception testing, delay(1). For some reason
amd64 (in 32 bit mode) and the new transmeta cpus want this, and lock
up otherwise. very odd.


# 1.29 24-Oct-2003 grange

No need to have several implementations of {read,write}_eflags(),
put it to cpufunc.h.
ok weingart@ tedu@


Revision tags: OPENBSD_3_4_BASE
# 1.28 25-Jul-2003 jason

let ALWAYS_MATH_EMULATE actually compile


# 1.27 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: UBC_SYNC_A
# 1.26 17-Apr-2003 drahn

i386 changes to move to ELF. asm cleanup. Change MAXDSIZ to 512M for 1Gsep.
DARPA funded work.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.25 14-Mar-2002 millert

First round of __P removal in sys


# 1.24 18-Feb-2002 ericj

multi-line string literals are deprecated in gcc 3.0
pr#2379


Revision tags: UBC_BASE
# 1.23 04-Dec-2001 niklas

branches: 1.23.2;
New try at a level based irq system.


# 1.22 18-Nov-2001 aaron

Revert niklas's broken ICU interrupt handling changes; deraadt@ ok


# 1.21 12-Nov-2001 niklas

Redo the ICU interrupt handling system to better emulate an APIC system.
This is done by representing the current blockings of interrupts with
a priority level instead of an interrupt mask. This makes it possible to
share implementations for spl* functions/macros between both ICU
and APIC (a must when going MP) systems. In this process, assign
soft interrupts their own levels to match the way things will be on
APIC systems where they actually will be real interrupts and not just
bits in a pending mask as they are now.
Heavily inspired by Bill Studenmunds SMP work in NetBSD


# 1.20 06-Nov-2001 miod

Replace inclusion of <vm/foo.h> with the correct <uvm/bar.h> when necessary.
(Look ma, I might have broken the tree)


Revision tags: OPENBSD_3_0_BASE
# 1.19 05-May-2001 art

PMAP_NEW and UVM are no longer optional on i386.


Revision tags: OPENBSD_2_9_BASE
# 1.18 09-Apr-2001 tholo

Add emulation of Linux features to procfs; mostly from NetBSD. ok deraadt@


Revision tags: OPENBSD_2_8_BASE
# 1.17 08-Jun-2000 niklas

Add explicit inclusions of signalvar.h to files actually using syms defined
there but relying on an indirect inclusion


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE SMP_BASE kame_19991208
# 1.16 26-Feb-1999 art

branches: 1.16.6;
cnt.foo -> uvmexp.bar in uvm


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.15 22-Feb-1998 niklas

GCC 2.8 Wall


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.14 17-Apr-1997 tholo

Do interrupt time accounting by running interrupt handlers with a seperate
code segment selector (otherwise identical to the standard kernel code
selector); idea by Dave Richards <richards@zso.dec.com>


# 1.13 08-Feb-1997 tholo

Provide more information on FP exceptions


# 1.12 01-Feb-1997 deraadt

add type & union sigval args to sendsig/trapsignal


# 1.11 27-Jan-1997 deraadt

add another parameter to trapsignal() and sendsig() -- fault addr to be
delivered with in the siginfo information


Revision tags: OPENBSD_2_0_BASE
# 1.10 27-Aug-1996 downsj

Add:
* GPL_MATH_EMULATE: fpemul
* ALWAYS_MATH_EMULATE: causes npx probe to always fail.
* better fp context in struct pcb.


# 1.9 25-May-1996 deraadt

sync


# 1.8 07-May-1996 deraadt

sync with 0504; prototype changes


# 1.7 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.6 20-Mar-1996 mickey

Fix back wrong patches.


# 1.5 19-Mar-1996 mickey

Merging w/ NetBSD 021796.
speaker upgraded to the current.
some changes to the VM stuff (ie kern_thread.c added and so).


# 1.4 20-Feb-1996 tholo

Pass device name to interrupt establish routines so it can be recorded in
the device interrupt chain structures (isa, pci)

Move interrupt chain structure definition to <machine/psl.h> so vmstat can
get at it (i386)

Remove hack to count interrupts the old way (i386)


# 1.3 07-Jan-1996 deraadt

from netbsd: Put #includes in the right order


# 1.2 27-Dec-1995 deraadt

from netbsd:
The IST_* and IPL_* constants are not bus-specific; don't treat them as such.


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.73 21-Feb-2022 mpi

Constify struct cfattach.


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.72 24-Sep-2020 deraadt

an ugly white space


# 1.71 19-Aug-2020 mpi

Push KERNEL_LOCK/UNLOCK() dance inside trapsignal().

ok kettenis@, visa@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.70 30-Jul-2018 kettenis

Use the MI interrupt enable/distable API instead of the MD one on i386 and
remove the MD API.

ok deraadt@


# 1.69 11-Apr-2018 bluhm

More steps for i386 Meltdown fix:

- provide struct cpu_info_full
- prepare K-U sections
- reorganize interrupt, trap, syscall entry to use K-U trampoline
- prepare pmap for entering special mappings, the mappings are not
setup yet

This code will already trigger performance issues. We do more tlb
flushes, but we do not unmap the kernel yet. The latter
will be needed to prevent Meltdown.

from hshoexer@; input guenther@; OK mlarkin@ deraadt@


# 1.68 31-Mar-2018 bluhm

Change ci_dev.dv_xname to ci_dev->dv_xname in debugging printf()
to make it compile when enabled.
from hshoexer@


# 1.67 31-Mar-2018 bluhm

Recommit preparation for i386 Meltdown fix after OpenBSD 6.3 release.

- provide a cpu_softc for cpu_attach() etc.
- replace per PCB TSS with per CPU TSS

The first change prepares for cpu_info being embedded in a
cpu_full_info. Therefore during autoconf/cpu_attach we hand down
a softc.

The second change removes the per PCB TSS. We now have one TSS per
CPU, thus in cpu_switchto() we only have to patch the ring 0 stack
pointer instead of loading a new TSS. This also allows for cleaning
up the GDT, so we only have a single slot for the TSS.

from hshoexer@; OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.66 22-Mar-2018 bluhm

iBackout the preparations for fixing Meltdown on i386. The task was
only halfway done and the current state does not help anybody. For
OpenBSD 6.3 release go back to the original code before 2018/03/13.
This gives us a stable release and the changes will come back later.
discussed with guenther@ deraadt@ hshoexer@


# 1.65 13-Mar-2018 bluhm

Preparation for i386 Meltdown fix:

- provide a cpu_softc for cpu_attach() etc.
- replace per PCB TSS with per CPU TSS

The first change prepares for cpu_info being embedded in a
cpu_full_info. Therefore during autoconf/cpu_attach we hand down
a softc.

The second change removes the per PCB TSS. We now have one TSS per
CPU, thus in cpu_switchto() we only have to patch the ring 0 stack
pointer instead of loading a new TSS. This also allows for cleaning
up the GDT, so we only have a single slot for the TSS.

from hshoexer@; OK deraadt@


# 1.64 01-Mar-2018 bluhm

Protect the calls to trapsignal() and psignal() with a kernel lock
when processing an npx interrupt. This fixes a kernel locked
assertion in postsig_done() during the libc ieeefp/except regression
test.
OK visa@


# 1.63 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.62 29-May-2017 mpi

Kill SPINLOCK_SPIN_HOOK, use CPU_BUSY_CYCLE() instead.

ok visa@, kettenis@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.61 11-Feb-2015 dlg

deprecate use of sys/lock.h and replace it with sys/atomic.h or
machine/lock.h as appropriate.


Revision tags: OPENBSD_5_6_BASE
# 1.60 29-Mar-2014 guenther

It's been a quarter century: we can assume volatile is present with that name.

ok dlg@ mpi@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.59 16-Nov-2013 brad

Copied from amd64..

Use an explicit suffix for the "fld" instruction to shut up clang. The correct
instruction is fldl since we try to load a double-precision value.
GCC actually gets it wrong and emits "flds" (which is harmless).

ok guenther@


Revision tags: OPENBSD_5_4_BASE
# 1.58 08-May-2013 tedu

remove stale cyrix emc support, and switch to just using intial npxcw
ok kettenis


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.57 11-Jul-2011 guenther

Revert art@'s moving around of the KERNEL_LOCK()/KERNEL_UNLOCK() calls,
as it causes hangs in some ports, including libsigsegv's configure script

confirmed by krw@, landry@


# 1.56 07-Jul-2011 art

There is a bunch of places in the kernel entry points where we don't
hold the kernel lock, but still need call one function that needs it.

Instead of grabbing the lock all over the place, move the locks into
the affected functions: trapsignal, scdebug*, ktrsyscall, ktrsysret,
systrace_redirect and ADDUPROF. In the cases we already hold the biglock
we'll just recurse.

kettenis@, beck@ ok


# 1.55 06-Jul-2011 art

Clean up after P_BIGLOCK removal.
KERNEL_PROC_LOCK -> KERNEL_LOCK
KERNEL_PROC_UNLOCK -> KERNEL_UNLOCK

oga@ ok


# 1.54 20-Mar-2011 guenther

When reading MXCSR from userland sigcontext or a ptrace request,
mask out invalid bits to prevent a protect fault.

Original diff by joshe@; further feedback and ok kettenis@


Revision tags: OPENBSD_4_9_BASE
# 1.53 29-Sep-2010 joshe

Back out previous, it appears to be broken.


# 1.52 29-Sep-2010 joshe

When reading MXCSR from userland sigcontext, mask out invalid bits.

This prevents a protection fault if a userland signal handler
scribbles all over it's struct sigcontext

Help from and ok guenther@ kettenis@


Revision tags: OPENBSD_4_8_BASE
# 1.51 23-Jul-2010 kettenis

Change the strategy for using the FPU in the kernel. The kernel FPU state
is now shared with all processes/threads. As a result, you can now use the
FPU in true process context (instead of just in kernel threads), but you
need to make sure you restore the default FPU state before calling
fpu_kernel_exit() if you change rounding mode, precision or exception masks.

Lots of discussion with thib@ and Mike Belopuhov.

ok thib@, deraadt@


# 1.50 23-Jul-2010 kettenis

Don't leak the contents of the FPU and SSE registers between processes.

ok deraadt@


# 1.49 21-Jul-2010 kettenis

Make sure that the FPU IPIs shoot down the right FPU context and not the FPU
context of some random process that happened to be switched onto the FPU
after the decision was made to send the IPI.


# 1.48 29-Jun-2010 thib

fpu_kernel_{enter,exit}; Functions to allow the use of
the FPU in the kernel.

From Mike Belopuhov; Little bits by myself.

Comments/OK kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.47 28-Oct-2009 deraadt

delete balony comment; ok kettenis


# 1.46 26-Oct-2009 kettenis

Load %mxcsr when initializing the FPU on machines that support SSE.

ok deraadt@


# 1.45 03-Oct-2009 kettenis

Properly handle XMM exceptions instead of panicing the kernel. Fixes the
issue reported by Slava Pestov.

ok deraadt@


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.44 04-Dec-2008 weingart

branches: 1.44.2; 1.44.6;
Fix "fp_save ipi didn't" panic, and move i386/amd64 closer in the process.
Positive test results by a handful of people. Ok kettenis@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.43 28-Nov-2007 tedu

branches: 1.43.4;
quite a bit of simplification by removing cpu classes.
also assume that 386 cpus are really unknown, and promote them to 486
instead of panic.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.42 18-Oct-2006 tom

Short-circuit the detection of the FPU by checking the CPUID features,
as done in FreeBSD. Fixes problems on AMD Geode LX-800 where our
detection logic doesn't detect the FP exception.

ok deraadt@ kettenis@


# 1.41 19-Sep-2006 jsg

ansi/deregister


Revision tags: OPENBSD_4_0_BASE
# 1.40 25-Jul-2006 kettenis

branches: 1.40.2;
Kill option GPL_MATH_EMULATE.

ok deraadt@ and many others.


# 1.39 19-Apr-2006 mickey

from todays freebsd advisory: fxrstor on amd cpu does not restore fip,fdp,fop thus leaking other proc's execution history; deraadt@ ok


# 1.38 13-Mar-2006 mickey

time-bind and lower power in lock spinning and a couple of other ipi loops by using pause insn; brad@ ok tedu@ ok and feedback krw@ testing


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 06-Jun-2005 mickey

branches: 1.37.2; 1.37.4;
oops. on 686 we count fpswtch in another function...


# 1.36 21-Apr-2005 mickey

count fpu lazy context switches; deraadt@ ok


Revision tags: OPENBSD_3_7_BASE
# 1.35 21-Oct-2004 kettenis

branches: 1.35.2;
SIGFPE signal codes for SSE.
nice deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.34 21-Jul-2004 kettenis

Fix conversion of interrupt frame to trap frame.
ok deraadt@, niklas@


# 1.33 13-Jul-2004 art

Don't assert that P_INMEM is set in p_flag. The assert is only almost
correct because P_INMEM is for various reasons removed before cpu_swapout
is called and cpu_swapout in turn calls npxsave_proc.

deraadt@ ok


# 1.32 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.31 01-Feb-2004 deraadt

Enable FXSR all the time, and cope with NPX/FXSR conversions; from netbsd.
Pass SSE/SSE2/XCRYPT flags out via syctl, and prepare for being able to do
xcrypt-* in userland; ok naddy, tested a lot by pvalchev and jolan, also
works on amd64 in 32bit mode


# 1.30 31-Dec-2003 deraadt

workaround: during npx exception testing, delay(1). For some reason
amd64 (in 32 bit mode) and the new transmeta cpus want this, and lock
up otherwise. very odd.


# 1.29 24-Oct-2003 grange

No need to have several implementations of {read,write}_eflags(),
put it to cpufunc.h.
ok weingart@ tedu@


Revision tags: OPENBSD_3_4_BASE
# 1.28 25-Jul-2003 jason

let ALWAYS_MATH_EMULATE actually compile


# 1.27 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: UBC_SYNC_A
# 1.26 17-Apr-2003 drahn

i386 changes to move to ELF. asm cleanup. Change MAXDSIZ to 512M for 1Gsep.
DARPA funded work.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.25 14-Mar-2002 millert

First round of __P removal in sys


# 1.24 18-Feb-2002 ericj

multi-line string literals are deprecated in gcc 3.0
pr#2379


Revision tags: UBC_BASE
# 1.23 04-Dec-2001 niklas

branches: 1.23.2;
New try at a level based irq system.


# 1.22 18-Nov-2001 aaron

Revert niklas's broken ICU interrupt handling changes; deraadt@ ok


# 1.21 12-Nov-2001 niklas

Redo the ICU interrupt handling system to better emulate an APIC system.
This is done by representing the current blockings of interrupts with
a priority level instead of an interrupt mask. This makes it possible to
share implementations for spl* functions/macros between both ICU
and APIC (a must when going MP) systems. In this process, assign
soft interrupts their own levels to match the way things will be on
APIC systems where they actually will be real interrupts and not just
bits in a pending mask as they are now.
Heavily inspired by Bill Studenmunds SMP work in NetBSD


# 1.20 06-Nov-2001 miod

Replace inclusion of <vm/foo.h> with the correct <uvm/bar.h> when necessary.
(Look ma, I might have broken the tree)


Revision tags: OPENBSD_3_0_BASE
# 1.19 05-May-2001 art

PMAP_NEW and UVM are no longer optional on i386.


Revision tags: OPENBSD_2_9_BASE
# 1.18 09-Apr-2001 tholo

Add emulation of Linux features to procfs; mostly from NetBSD. ok deraadt@


Revision tags: OPENBSD_2_8_BASE
# 1.17 08-Jun-2000 niklas

Add explicit inclusions of signalvar.h to files actually using syms defined
there but relying on an indirect inclusion


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE SMP_BASE kame_19991208
# 1.16 26-Feb-1999 art

branches: 1.16.6;
cnt.foo -> uvmexp.bar in uvm


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.15 22-Feb-1998 niklas

GCC 2.8 Wall


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.14 17-Apr-1997 tholo

Do interrupt time accounting by running interrupt handlers with a seperate
code segment selector (otherwise identical to the standard kernel code
selector); idea by Dave Richards <richards@zso.dec.com>


# 1.13 08-Feb-1997 tholo

Provide more information on FP exceptions


# 1.12 01-Feb-1997 deraadt

add type & union sigval args to sendsig/trapsignal


# 1.11 27-Jan-1997 deraadt

add another parameter to trapsignal() and sendsig() -- fault addr to be
delivered with in the siginfo information


Revision tags: OPENBSD_2_0_BASE
# 1.10 27-Aug-1996 downsj

Add:
* GPL_MATH_EMULATE: fpemul
* ALWAYS_MATH_EMULATE: causes npx probe to always fail.
* better fp context in struct pcb.


# 1.9 25-May-1996 deraadt

sync


# 1.8 07-May-1996 deraadt

sync with 0504; prototype changes


# 1.7 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.6 20-Mar-1996 mickey

Fix back wrong patches.


# 1.5 19-Mar-1996 mickey

Merging w/ NetBSD 021796.
speaker upgraded to the current.
some changes to the VM stuff (ie kern_thread.c added and so).


# 1.4 20-Feb-1996 tholo

Pass device name to interrupt establish routines so it can be recorded in
the device interrupt chain structures (isa, pci)

Move interrupt chain structure definition to <machine/psl.h> so vmstat can
get at it (i386)

Remove hack to count interrupts the old way (i386)


# 1.3 07-Jan-1996 deraadt

from netbsd: Put #includes in the right order


# 1.2 27-Dec-1995 deraadt

from netbsd:
The IST_* and IPL_* constants are not bus-specific; don't treat them as such.


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.72 24-Sep-2020 deraadt

an ugly white space


# 1.71 19-Aug-2020 mpi

Push KERNEL_LOCK/UNLOCK() dance inside trapsignal().

ok kettenis@, visa@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.70 30-Jul-2018 kettenis

Use the MI interrupt enable/distable API instead of the MD one on i386 and
remove the MD API.

ok deraadt@


# 1.69 11-Apr-2018 bluhm

More steps for i386 Meltdown fix:

- provide struct cpu_info_full
- prepare K-U sections
- reorganize interrupt, trap, syscall entry to use K-U trampoline
- prepare pmap for entering special mappings, the mappings are not
setup yet

This code will already trigger performance issues. We do more tlb
flushes, but we do not unmap the kernel yet. The latter
will be needed to prevent Meltdown.

from hshoexer@; input guenther@; OK mlarkin@ deraadt@


# 1.68 31-Mar-2018 bluhm

Change ci_dev.dv_xname to ci_dev->dv_xname in debugging printf()
to make it compile when enabled.
from hshoexer@


# 1.67 31-Mar-2018 bluhm

Recommit preparation for i386 Meltdown fix after OpenBSD 6.3 release.

- provide a cpu_softc for cpu_attach() etc.
- replace per PCB TSS with per CPU TSS

The first change prepares for cpu_info being embedded in a
cpu_full_info. Therefore during autoconf/cpu_attach we hand down
a softc.

The second change removes the per PCB TSS. We now have one TSS per
CPU, thus in cpu_switchto() we only have to patch the ring 0 stack
pointer instead of loading a new TSS. This also allows for cleaning
up the GDT, so we only have a single slot for the TSS.

from hshoexer@; OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.66 22-Mar-2018 bluhm

iBackout the preparations for fixing Meltdown on i386. The task was
only halfway done and the current state does not help anybody. For
OpenBSD 6.3 release go back to the original code before 2018/03/13.
This gives us a stable release and the changes will come back later.
discussed with guenther@ deraadt@ hshoexer@


# 1.65 13-Mar-2018 bluhm

Preparation for i386 Meltdown fix:

- provide a cpu_softc for cpu_attach() etc.
- replace per PCB TSS with per CPU TSS

The first change prepares for cpu_info being embedded in a
cpu_full_info. Therefore during autoconf/cpu_attach we hand down
a softc.

The second change removes the per PCB TSS. We now have one TSS per
CPU, thus in cpu_switchto() we only have to patch the ring 0 stack
pointer instead of loading a new TSS. This also allows for cleaning
up the GDT, so we only have a single slot for the TSS.

from hshoexer@; OK deraadt@


# 1.64 01-Mar-2018 bluhm

Protect the calls to trapsignal() and psignal() with a kernel lock
when processing an npx interrupt. This fixes a kernel locked
assertion in postsig_done() during the libc ieeefp/except regression
test.
OK visa@


# 1.63 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.62 29-May-2017 mpi

Kill SPINLOCK_SPIN_HOOK, use CPU_BUSY_CYCLE() instead.

ok visa@, kettenis@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.61 11-Feb-2015 dlg

deprecate use of sys/lock.h and replace it with sys/atomic.h or
machine/lock.h as appropriate.


Revision tags: OPENBSD_5_6_BASE
# 1.60 29-Mar-2014 guenther

It's been a quarter century: we can assume volatile is present with that name.

ok dlg@ mpi@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.59 16-Nov-2013 brad

Copied from amd64..

Use an explicit suffix for the "fld" instruction to shut up clang. The correct
instruction is fldl since we try to load a double-precision value.
GCC actually gets it wrong and emits "flds" (which is harmless).

ok guenther@


Revision tags: OPENBSD_5_4_BASE
# 1.58 08-May-2013 tedu

remove stale cyrix emc support, and switch to just using intial npxcw
ok kettenis


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.57 11-Jul-2011 guenther

Revert art@'s moving around of the KERNEL_LOCK()/KERNEL_UNLOCK() calls,
as it causes hangs in some ports, including libsigsegv's configure script

confirmed by krw@, landry@


# 1.56 07-Jul-2011 art

There is a bunch of places in the kernel entry points where we don't
hold the kernel lock, but still need call one function that needs it.

Instead of grabbing the lock all over the place, move the locks into
the affected functions: trapsignal, scdebug*, ktrsyscall, ktrsysret,
systrace_redirect and ADDUPROF. In the cases we already hold the biglock
we'll just recurse.

kettenis@, beck@ ok


# 1.55 06-Jul-2011 art

Clean up after P_BIGLOCK removal.
KERNEL_PROC_LOCK -> KERNEL_LOCK
KERNEL_PROC_UNLOCK -> KERNEL_UNLOCK

oga@ ok


# 1.54 20-Mar-2011 guenther

When reading MXCSR from userland sigcontext or a ptrace request,
mask out invalid bits to prevent a protect fault.

Original diff by joshe@; further feedback and ok kettenis@


Revision tags: OPENBSD_4_9_BASE
# 1.53 29-Sep-2010 joshe

Back out previous, it appears to be broken.


# 1.52 29-Sep-2010 joshe

When reading MXCSR from userland sigcontext, mask out invalid bits.

This prevents a protection fault if a userland signal handler
scribbles all over it's struct sigcontext

Help from and ok guenther@ kettenis@


Revision tags: OPENBSD_4_8_BASE
# 1.51 23-Jul-2010 kettenis

Change the strategy for using the FPU in the kernel. The kernel FPU state
is now shared with all processes/threads. As a result, you can now use the
FPU in true process context (instead of just in kernel threads), but you
need to make sure you restore the default FPU state before calling
fpu_kernel_exit() if you change rounding mode, precision or exception masks.

Lots of discussion with thib@ and Mike Belopuhov.

ok thib@, deraadt@


# 1.50 23-Jul-2010 kettenis

Don't leak the contents of the FPU and SSE registers between processes.

ok deraadt@


# 1.49 21-Jul-2010 kettenis

Make sure that the FPU IPIs shoot down the right FPU context and not the FPU
context of some random process that happened to be switched onto the FPU
after the decision was made to send the IPI.


# 1.48 29-Jun-2010 thib

fpu_kernel_{enter,exit}; Functions to allow the use of
the FPU in the kernel.

From Mike Belopuhov; Little bits by myself.

Comments/OK kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.47 28-Oct-2009 deraadt

delete balony comment; ok kettenis


# 1.46 26-Oct-2009 kettenis

Load %mxcsr when initializing the FPU on machines that support SSE.

ok deraadt@


# 1.45 03-Oct-2009 kettenis

Properly handle XMM exceptions instead of panicing the kernel. Fixes the
issue reported by Slava Pestov.

ok deraadt@


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.44 04-Dec-2008 weingart

branches: 1.44.2; 1.44.6;
Fix "fp_save ipi didn't" panic, and move i386/amd64 closer in the process.
Positive test results by a handful of people. Ok kettenis@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.43 28-Nov-2007 tedu

branches: 1.43.4;
quite a bit of simplification by removing cpu classes.
also assume that 386 cpus are really unknown, and promote them to 486
instead of panic.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.42 18-Oct-2006 tom

Short-circuit the detection of the FPU by checking the CPUID features,
as done in FreeBSD. Fixes problems on AMD Geode LX-800 where our
detection logic doesn't detect the FP exception.

ok deraadt@ kettenis@


# 1.41 19-Sep-2006 jsg

ansi/deregister


Revision tags: OPENBSD_4_0_BASE
# 1.40 25-Jul-2006 kettenis

branches: 1.40.2;
Kill option GPL_MATH_EMULATE.

ok deraadt@ and many others.


# 1.39 19-Apr-2006 mickey

from todays freebsd advisory: fxrstor on amd cpu does not restore fip,fdp,fop thus leaking other proc's execution history; deraadt@ ok


# 1.38 13-Mar-2006 mickey

time-bind and lower power in lock spinning and a couple of other ipi loops by using pause insn; brad@ ok tedu@ ok and feedback krw@ testing


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 06-Jun-2005 mickey

branches: 1.37.2; 1.37.4;
oops. on 686 we count fpswtch in another function...


# 1.36 21-Apr-2005 mickey

count fpu lazy context switches; deraadt@ ok


Revision tags: OPENBSD_3_7_BASE
# 1.35 21-Oct-2004 kettenis

branches: 1.35.2;
SIGFPE signal codes for SSE.
nice deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.34 21-Jul-2004 kettenis

Fix conversion of interrupt frame to trap frame.
ok deraadt@, niklas@


# 1.33 13-Jul-2004 art

Don't assert that P_INMEM is set in p_flag. The assert is only almost
correct because P_INMEM is for various reasons removed before cpu_swapout
is called and cpu_swapout in turn calls npxsave_proc.

deraadt@ ok


# 1.32 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.31 01-Feb-2004 deraadt

Enable FXSR all the time, and cope with NPX/FXSR conversions; from netbsd.
Pass SSE/SSE2/XCRYPT flags out via syctl, and prepare for being able to do
xcrypt-* in userland; ok naddy, tested a lot by pvalchev and jolan, also
works on amd64 in 32bit mode


# 1.30 31-Dec-2003 deraadt

workaround: during npx exception testing, delay(1). For some reason
amd64 (in 32 bit mode) and the new transmeta cpus want this, and lock
up otherwise. very odd.


# 1.29 24-Oct-2003 grange

No need to have several implementations of {read,write}_eflags(),
put it to cpufunc.h.
ok weingart@ tedu@


Revision tags: OPENBSD_3_4_BASE
# 1.28 25-Jul-2003 jason

let ALWAYS_MATH_EMULATE actually compile


# 1.27 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: UBC_SYNC_A
# 1.26 17-Apr-2003 drahn

i386 changes to move to ELF. asm cleanup. Change MAXDSIZ to 512M for 1Gsep.
DARPA funded work.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.25 14-Mar-2002 millert

First round of __P removal in sys


# 1.24 18-Feb-2002 ericj

multi-line string literals are deprecated in gcc 3.0
pr#2379


Revision tags: UBC_BASE
# 1.23 04-Dec-2001 niklas

branches: 1.23.2;
New try at a level based irq system.


# 1.22 18-Nov-2001 aaron

Revert niklas's broken ICU interrupt handling changes; deraadt@ ok


# 1.21 12-Nov-2001 niklas

Redo the ICU interrupt handling system to better emulate an APIC system.
This is done by representing the current blockings of interrupts with
a priority level instead of an interrupt mask. This makes it possible to
share implementations for spl* functions/macros between both ICU
and APIC (a must when going MP) systems. In this process, assign
soft interrupts their own levels to match the way things will be on
APIC systems where they actually will be real interrupts and not just
bits in a pending mask as they are now.
Heavily inspired by Bill Studenmunds SMP work in NetBSD


# 1.20 06-Nov-2001 miod

Replace inclusion of <vm/foo.h> with the correct <uvm/bar.h> when necessary.
(Look ma, I might have broken the tree)


Revision tags: OPENBSD_3_0_BASE
# 1.19 05-May-2001 art

PMAP_NEW and UVM are no longer optional on i386.


Revision tags: OPENBSD_2_9_BASE
# 1.18 09-Apr-2001 tholo

Add emulation of Linux features to procfs; mostly from NetBSD. ok deraadt@


Revision tags: OPENBSD_2_8_BASE
# 1.17 08-Jun-2000 niklas

Add explicit inclusions of signalvar.h to files actually using syms defined
there but relying on an indirect inclusion


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE SMP_BASE kame_19991208
# 1.16 26-Feb-1999 art

branches: 1.16.6;
cnt.foo -> uvmexp.bar in uvm


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.15 22-Feb-1998 niklas

GCC 2.8 Wall


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.14 17-Apr-1997 tholo

Do interrupt time accounting by running interrupt handlers with a seperate
code segment selector (otherwise identical to the standard kernel code
selector); idea by Dave Richards <richards@zso.dec.com>


# 1.13 08-Feb-1997 tholo

Provide more information on FP exceptions


# 1.12 01-Feb-1997 deraadt

add type & union sigval args to sendsig/trapsignal


# 1.11 27-Jan-1997 deraadt

add another parameter to trapsignal() and sendsig() -- fault addr to be
delivered with in the siginfo information


Revision tags: OPENBSD_2_0_BASE
# 1.10 27-Aug-1996 downsj

Add:
* GPL_MATH_EMULATE: fpemul
* ALWAYS_MATH_EMULATE: causes npx probe to always fail.
* better fp context in struct pcb.


# 1.9 25-May-1996 deraadt

sync


# 1.8 07-May-1996 deraadt

sync with 0504; prototype changes


# 1.7 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.6 20-Mar-1996 mickey

Fix back wrong patches.


# 1.5 19-Mar-1996 mickey

Merging w/ NetBSD 021796.
speaker upgraded to the current.
some changes to the VM stuff (ie kern_thread.c added and so).


# 1.4 20-Feb-1996 tholo

Pass device name to interrupt establish routines so it can be recorded in
the device interrupt chain structures (isa, pci)

Move interrupt chain structure definition to <machine/psl.h> so vmstat can
get at it (i386)

Remove hack to count interrupts the old way (i386)


# 1.3 07-Jan-1996 deraadt

from netbsd: Put #includes in the right order


# 1.2 27-Dec-1995 deraadt

from netbsd:
The IST_* and IPL_* constants are not bus-specific; don't treat them as such.


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.71 19-Aug-2020 mpi

Push KERNEL_LOCK/UNLOCK() dance inside trapsignal().

ok kettenis@, visa@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.70 30-Jul-2018 kettenis

Use the MI interrupt enable/distable API instead of the MD one on i386 and
remove the MD API.

ok deraadt@


# 1.69 11-Apr-2018 bluhm

More steps for i386 Meltdown fix:

- provide struct cpu_info_full
- prepare K-U sections
- reorganize interrupt, trap, syscall entry to use K-U trampoline
- prepare pmap for entering special mappings, the mappings are not
setup yet

This code will already trigger performance issues. We do more tlb
flushes, but we do not unmap the kernel yet. The latter
will be needed to prevent Meltdown.

from hshoexer@; input guenther@; OK mlarkin@ deraadt@


# 1.68 31-Mar-2018 bluhm

Change ci_dev.dv_xname to ci_dev->dv_xname in debugging printf()
to make it compile when enabled.
from hshoexer@


# 1.67 31-Mar-2018 bluhm

Recommit preparation for i386 Meltdown fix after OpenBSD 6.3 release.

- provide a cpu_softc for cpu_attach() etc.
- replace per PCB TSS with per CPU TSS

The first change prepares for cpu_info being embedded in a
cpu_full_info. Therefore during autoconf/cpu_attach we hand down
a softc.

The second change removes the per PCB TSS. We now have one TSS per
CPU, thus in cpu_switchto() we only have to patch the ring 0 stack
pointer instead of loading a new TSS. This also allows for cleaning
up the GDT, so we only have a single slot for the TSS.

from hshoexer@; OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.66 22-Mar-2018 bluhm

iBackout the preparations for fixing Meltdown on i386. The task was
only halfway done and the current state does not help anybody. For
OpenBSD 6.3 release go back to the original code before 2018/03/13.
This gives us a stable release and the changes will come back later.
discussed with guenther@ deraadt@ hshoexer@


# 1.65 13-Mar-2018 bluhm

Preparation for i386 Meltdown fix:

- provide a cpu_softc for cpu_attach() etc.
- replace per PCB TSS with per CPU TSS

The first change prepares for cpu_info being embedded in a
cpu_full_info. Therefore during autoconf/cpu_attach we hand down
a softc.

The second change removes the per PCB TSS. We now have one TSS per
CPU, thus in cpu_switchto() we only have to patch the ring 0 stack
pointer instead of loading a new TSS. This also allows for cleaning
up the GDT, so we only have a single slot for the TSS.

from hshoexer@; OK deraadt@


# 1.64 01-Mar-2018 bluhm

Protect the calls to trapsignal() and psignal() with a kernel lock
when processing an npx interrupt. This fixes a kernel locked
assertion in postsig_done() during the libc ieeefp/except regression
test.
OK visa@


# 1.63 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.62 29-May-2017 mpi

Kill SPINLOCK_SPIN_HOOK, use CPU_BUSY_CYCLE() instead.

ok visa@, kettenis@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.61 11-Feb-2015 dlg

deprecate use of sys/lock.h and replace it with sys/atomic.h or
machine/lock.h as appropriate.


Revision tags: OPENBSD_5_6_BASE
# 1.60 29-Mar-2014 guenther

It's been a quarter century: we can assume volatile is present with that name.

ok dlg@ mpi@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.59 16-Nov-2013 brad

Copied from amd64..

Use an explicit suffix for the "fld" instruction to shut up clang. The correct
instruction is fldl since we try to load a double-precision value.
GCC actually gets it wrong and emits "flds" (which is harmless).

ok guenther@


Revision tags: OPENBSD_5_4_BASE
# 1.58 08-May-2013 tedu

remove stale cyrix emc support, and switch to just using intial npxcw
ok kettenis


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.57 11-Jul-2011 guenther

Revert art@'s moving around of the KERNEL_LOCK()/KERNEL_UNLOCK() calls,
as it causes hangs in some ports, including libsigsegv's configure script

confirmed by krw@, landry@


# 1.56 07-Jul-2011 art

There is a bunch of places in the kernel entry points where we don't
hold the kernel lock, but still need call one function that needs it.

Instead of grabbing the lock all over the place, move the locks into
the affected functions: trapsignal, scdebug*, ktrsyscall, ktrsysret,
systrace_redirect and ADDUPROF. In the cases we already hold the biglock
we'll just recurse.

kettenis@, beck@ ok


# 1.55 06-Jul-2011 art

Clean up after P_BIGLOCK removal.
KERNEL_PROC_LOCK -> KERNEL_LOCK
KERNEL_PROC_UNLOCK -> KERNEL_UNLOCK

oga@ ok


# 1.54 20-Mar-2011 guenther

When reading MXCSR from userland sigcontext or a ptrace request,
mask out invalid bits to prevent a protect fault.

Original diff by joshe@; further feedback and ok kettenis@


Revision tags: OPENBSD_4_9_BASE
# 1.53 29-Sep-2010 joshe

Back out previous, it appears to be broken.


# 1.52 29-Sep-2010 joshe

When reading MXCSR from userland sigcontext, mask out invalid bits.

This prevents a protection fault if a userland signal handler
scribbles all over it's struct sigcontext

Help from and ok guenther@ kettenis@


Revision tags: OPENBSD_4_8_BASE
# 1.51 23-Jul-2010 kettenis

Change the strategy for using the FPU in the kernel. The kernel FPU state
is now shared with all processes/threads. As a result, you can now use the
FPU in true process context (instead of just in kernel threads), but you
need to make sure you restore the default FPU state before calling
fpu_kernel_exit() if you change rounding mode, precision or exception masks.

Lots of discussion with thib@ and Mike Belopuhov.

ok thib@, deraadt@


# 1.50 23-Jul-2010 kettenis

Don't leak the contents of the FPU and SSE registers between processes.

ok deraadt@


# 1.49 21-Jul-2010 kettenis

Make sure that the FPU IPIs shoot down the right FPU context and not the FPU
context of some random process that happened to be switched onto the FPU
after the decision was made to send the IPI.


# 1.48 29-Jun-2010 thib

fpu_kernel_{enter,exit}; Functions to allow the use of
the FPU in the kernel.

From Mike Belopuhov; Little bits by myself.

Comments/OK kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.47 28-Oct-2009 deraadt

delete balony comment; ok kettenis


# 1.46 26-Oct-2009 kettenis

Load %mxcsr when initializing the FPU on machines that support SSE.

ok deraadt@


# 1.45 03-Oct-2009 kettenis

Properly handle XMM exceptions instead of panicing the kernel. Fixes the
issue reported by Slava Pestov.

ok deraadt@


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.44 04-Dec-2008 weingart

branches: 1.44.2; 1.44.6;
Fix "fp_save ipi didn't" panic, and move i386/amd64 closer in the process.
Positive test results by a handful of people. Ok kettenis@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.43 28-Nov-2007 tedu

branches: 1.43.4;
quite a bit of simplification by removing cpu classes.
also assume that 386 cpus are really unknown, and promote them to 486
instead of panic.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.42 18-Oct-2006 tom

Short-circuit the detection of the FPU by checking the CPUID features,
as done in FreeBSD. Fixes problems on AMD Geode LX-800 where our
detection logic doesn't detect the FP exception.

ok deraadt@ kettenis@


# 1.41 19-Sep-2006 jsg

ansi/deregister


Revision tags: OPENBSD_4_0_BASE
# 1.40 25-Jul-2006 kettenis

branches: 1.40.2;
Kill option GPL_MATH_EMULATE.

ok deraadt@ and many others.


# 1.39 19-Apr-2006 mickey

from todays freebsd advisory: fxrstor on amd cpu does not restore fip,fdp,fop thus leaking other proc's execution history; deraadt@ ok


# 1.38 13-Mar-2006 mickey

time-bind and lower power in lock spinning and a couple of other ipi loops by using pause insn; brad@ ok tedu@ ok and feedback krw@ testing


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 06-Jun-2005 mickey

branches: 1.37.2; 1.37.4;
oops. on 686 we count fpswtch in another function...


# 1.36 21-Apr-2005 mickey

count fpu lazy context switches; deraadt@ ok


Revision tags: OPENBSD_3_7_BASE
# 1.35 21-Oct-2004 kettenis

branches: 1.35.2;
SIGFPE signal codes for SSE.
nice deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.34 21-Jul-2004 kettenis

Fix conversion of interrupt frame to trap frame.
ok deraadt@, niklas@


# 1.33 13-Jul-2004 art

Don't assert that P_INMEM is set in p_flag. The assert is only almost
correct because P_INMEM is for various reasons removed before cpu_swapout
is called and cpu_swapout in turn calls npxsave_proc.

deraadt@ ok


# 1.32 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.31 01-Feb-2004 deraadt

Enable FXSR all the time, and cope with NPX/FXSR conversions; from netbsd.
Pass SSE/SSE2/XCRYPT flags out via syctl, and prepare for being able to do
xcrypt-* in userland; ok naddy, tested a lot by pvalchev and jolan, also
works on amd64 in 32bit mode


# 1.30 31-Dec-2003 deraadt

workaround: during npx exception testing, delay(1). For some reason
amd64 (in 32 bit mode) and the new transmeta cpus want this, and lock
up otherwise. very odd.


# 1.29 24-Oct-2003 grange

No need to have several implementations of {read,write}_eflags(),
put it to cpufunc.h.
ok weingart@ tedu@


Revision tags: OPENBSD_3_4_BASE
# 1.28 25-Jul-2003 jason

let ALWAYS_MATH_EMULATE actually compile


# 1.27 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: UBC_SYNC_A
# 1.26 17-Apr-2003 drahn

i386 changes to move to ELF. asm cleanup. Change MAXDSIZ to 512M for 1Gsep.
DARPA funded work.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.25 14-Mar-2002 millert

First round of __P removal in sys


# 1.24 18-Feb-2002 ericj

multi-line string literals are deprecated in gcc 3.0
pr#2379


Revision tags: UBC_BASE
# 1.23 04-Dec-2001 niklas

branches: 1.23.2;
New try at a level based irq system.


# 1.22 18-Nov-2001 aaron

Revert niklas's broken ICU interrupt handling changes; deraadt@ ok


# 1.21 12-Nov-2001 niklas

Redo the ICU interrupt handling system to better emulate an APIC system.
This is done by representing the current blockings of interrupts with
a priority level instead of an interrupt mask. This makes it possible to
share implementations for spl* functions/macros between both ICU
and APIC (a must when going MP) systems. In this process, assign
soft interrupts their own levels to match the way things will be on
APIC systems where they actually will be real interrupts and not just
bits in a pending mask as they are now.
Heavily inspired by Bill Studenmunds SMP work in NetBSD


# 1.20 06-Nov-2001 miod

Replace inclusion of <vm/foo.h> with the correct <uvm/bar.h> when necessary.
(Look ma, I might have broken the tree)


Revision tags: OPENBSD_3_0_BASE
# 1.19 05-May-2001 art

PMAP_NEW and UVM are no longer optional on i386.


Revision tags: OPENBSD_2_9_BASE
# 1.18 09-Apr-2001 tholo

Add emulation of Linux features to procfs; mostly from NetBSD. ok deraadt@


Revision tags: OPENBSD_2_8_BASE
# 1.17 08-Jun-2000 niklas

Add explicit inclusions of signalvar.h to files actually using syms defined
there but relying on an indirect inclusion


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE SMP_BASE kame_19991208
# 1.16 26-Feb-1999 art

branches: 1.16.6;
cnt.foo -> uvmexp.bar in uvm


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.15 22-Feb-1998 niklas

GCC 2.8 Wall


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.14 17-Apr-1997 tholo

Do interrupt time accounting by running interrupt handlers with a seperate
code segment selector (otherwise identical to the standard kernel code
selector); idea by Dave Richards <richards@zso.dec.com>


# 1.13 08-Feb-1997 tholo

Provide more information on FP exceptions


# 1.12 01-Feb-1997 deraadt

add type & union sigval args to sendsig/trapsignal


# 1.11 27-Jan-1997 deraadt

add another parameter to trapsignal() and sendsig() -- fault addr to be
delivered with in the siginfo information


Revision tags: OPENBSD_2_0_BASE
# 1.10 27-Aug-1996 downsj

Add:
* GPL_MATH_EMULATE: fpemul
* ALWAYS_MATH_EMULATE: causes npx probe to always fail.
* better fp context in struct pcb.


# 1.9 25-May-1996 deraadt

sync


# 1.8 07-May-1996 deraadt

sync with 0504; prototype changes


# 1.7 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.6 20-Mar-1996 mickey

Fix back wrong patches.


# 1.5 19-Mar-1996 mickey

Merging w/ NetBSD 021796.
speaker upgraded to the current.
some changes to the VM stuff (ie kern_thread.c added and so).


# 1.4 20-Feb-1996 tholo

Pass device name to interrupt establish routines so it can be recorded in
the device interrupt chain structures (isa, pci)

Move interrupt chain structure definition to <machine/psl.h> so vmstat can
get at it (i386)

Remove hack to count interrupts the old way (i386)


# 1.3 07-Jan-1996 deraadt

from netbsd: Put #includes in the right order


# 1.2 27-Dec-1995 deraadt

from netbsd:
The IST_* and IPL_* constants are not bus-specific; don't treat them as such.


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.70 30-Jul-2018 kettenis

Use the MI interrupt enable/distable API instead of the MD one on i386 and
remove the MD API.

ok deraadt@


# 1.69 11-Apr-2018 bluhm

More steps for i386 Meltdown fix:

- provide struct cpu_info_full
- prepare K-U sections
- reorganize interrupt, trap, syscall entry to use K-U trampoline
- prepare pmap for entering special mappings, the mappings are not
setup yet

This code will already trigger performance issues. We do more tlb
flushes, but we do not unmap the kernel yet. The latter
will be needed to prevent Meltdown.

from hshoexer@; input guenther@; OK mlarkin@ deraadt@


# 1.68 31-Mar-2018 bluhm

Change ci_dev.dv_xname to ci_dev->dv_xname in debugging printf()
to make it compile when enabled.
from hshoexer@


# 1.67 31-Mar-2018 bluhm

Recommit preparation for i386 Meltdown fix after OpenBSD 6.3 release.

- provide a cpu_softc for cpu_attach() etc.
- replace per PCB TSS with per CPU TSS

The first change prepares for cpu_info being embedded in a
cpu_full_info. Therefore during autoconf/cpu_attach we hand down
a softc.

The second change removes the per PCB TSS. We now have one TSS per
CPU, thus in cpu_switchto() we only have to patch the ring 0 stack
pointer instead of loading a new TSS. This also allows for cleaning
up the GDT, so we only have a single slot for the TSS.

from hshoexer@; OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.66 22-Mar-2018 bluhm

iBackout the preparations for fixing Meltdown on i386. The task was
only halfway done and the current state does not help anybody. For
OpenBSD 6.3 release go back to the original code before 2018/03/13.
This gives us a stable release and the changes will come back later.
discussed with guenther@ deraadt@ hshoexer@


# 1.65 13-Mar-2018 bluhm

Preparation for i386 Meltdown fix:

- provide a cpu_softc for cpu_attach() etc.
- replace per PCB TSS with per CPU TSS

The first change prepares for cpu_info being embedded in a
cpu_full_info. Therefore during autoconf/cpu_attach we hand down
a softc.

The second change removes the per PCB TSS. We now have one TSS per
CPU, thus in cpu_switchto() we only have to patch the ring 0 stack
pointer instead of loading a new TSS. This also allows for cleaning
up the GDT, so we only have a single slot for the TSS.

from hshoexer@; OK deraadt@


# 1.64 01-Mar-2018 bluhm

Protect the calls to trapsignal() and psignal() with a kernel lock
when processing an npx interrupt. This fixes a kernel locked
assertion in postsig_done() during the libc ieeefp/except regression
test.
OK visa@


# 1.63 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.62 29-May-2017 mpi

Kill SPINLOCK_SPIN_HOOK, use CPU_BUSY_CYCLE() instead.

ok visa@, kettenis@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.61 11-Feb-2015 dlg

deprecate use of sys/lock.h and replace it with sys/atomic.h or
machine/lock.h as appropriate.


Revision tags: OPENBSD_5_6_BASE
# 1.60 29-Mar-2014 guenther

It's been a quarter century: we can assume volatile is present with that name.

ok dlg@ mpi@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.59 16-Nov-2013 brad

Copied from amd64..

Use an explicit suffix for the "fld" instruction to shut up clang. The correct
instruction is fldl since we try to load a double-precision value.
GCC actually gets it wrong and emits "flds" (which is harmless).

ok guenther@


Revision tags: OPENBSD_5_4_BASE
# 1.58 08-May-2013 tedu

remove stale cyrix emc support, and switch to just using intial npxcw
ok kettenis


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.57 11-Jul-2011 guenther

Revert art@'s moving around of the KERNEL_LOCK()/KERNEL_UNLOCK() calls,
as it causes hangs in some ports, including libsigsegv's configure script

confirmed by krw@, landry@


# 1.56 07-Jul-2011 art

There is a bunch of places in the kernel entry points where we don't
hold the kernel lock, but still need call one function that needs it.

Instead of grabbing the lock all over the place, move the locks into
the affected functions: trapsignal, scdebug*, ktrsyscall, ktrsysret,
systrace_redirect and ADDUPROF. In the cases we already hold the biglock
we'll just recurse.

kettenis@, beck@ ok


# 1.55 06-Jul-2011 art

Clean up after P_BIGLOCK removal.
KERNEL_PROC_LOCK -> KERNEL_LOCK
KERNEL_PROC_UNLOCK -> KERNEL_UNLOCK

oga@ ok


# 1.54 20-Mar-2011 guenther

When reading MXCSR from userland sigcontext or a ptrace request,
mask out invalid bits to prevent a protect fault.

Original diff by joshe@; further feedback and ok kettenis@


Revision tags: OPENBSD_4_9_BASE
# 1.53 29-Sep-2010 joshe

Back out previous, it appears to be broken.


# 1.52 29-Sep-2010 joshe

When reading MXCSR from userland sigcontext, mask out invalid bits.

This prevents a protection fault if a userland signal handler
scribbles all over it's struct sigcontext

Help from and ok guenther@ kettenis@


Revision tags: OPENBSD_4_8_BASE
# 1.51 23-Jul-2010 kettenis

Change the strategy for using the FPU in the kernel. The kernel FPU state
is now shared with all processes/threads. As a result, you can now use the
FPU in true process context (instead of just in kernel threads), but you
need to make sure you restore the default FPU state before calling
fpu_kernel_exit() if you change rounding mode, precision or exception masks.

Lots of discussion with thib@ and Mike Belopuhov.

ok thib@, deraadt@


# 1.50 23-Jul-2010 kettenis

Don't leak the contents of the FPU and SSE registers between processes.

ok deraadt@


# 1.49 21-Jul-2010 kettenis

Make sure that the FPU IPIs shoot down the right FPU context and not the FPU
context of some random process that happened to be switched onto the FPU
after the decision was made to send the IPI.


# 1.48 29-Jun-2010 thib

fpu_kernel_{enter,exit}; Functions to allow the use of
the FPU in the kernel.

From Mike Belopuhov; Little bits by myself.

Comments/OK kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.47 28-Oct-2009 deraadt

delete balony comment; ok kettenis


# 1.46 26-Oct-2009 kettenis

Load %mxcsr when initializing the FPU on machines that support SSE.

ok deraadt@


# 1.45 03-Oct-2009 kettenis

Properly handle XMM exceptions instead of panicing the kernel. Fixes the
issue reported by Slava Pestov.

ok deraadt@


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.44 04-Dec-2008 weingart

branches: 1.44.2; 1.44.6;
Fix "fp_save ipi didn't" panic, and move i386/amd64 closer in the process.
Positive test results by a handful of people. Ok kettenis@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.43 28-Nov-2007 tedu

branches: 1.43.4;
quite a bit of simplification by removing cpu classes.
also assume that 386 cpus are really unknown, and promote them to 486
instead of panic.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.42 18-Oct-2006 tom

Short-circuit the detection of the FPU by checking the CPUID features,
as done in FreeBSD. Fixes problems on AMD Geode LX-800 where our
detection logic doesn't detect the FP exception.

ok deraadt@ kettenis@


# 1.41 19-Sep-2006 jsg

ansi/deregister


Revision tags: OPENBSD_4_0_BASE
# 1.40 25-Jul-2006 kettenis

branches: 1.40.2;
Kill option GPL_MATH_EMULATE.

ok deraadt@ and many others.


# 1.39 19-Apr-2006 mickey

from todays freebsd advisory: fxrstor on amd cpu does not restore fip,fdp,fop thus leaking other proc's execution history; deraadt@ ok


# 1.38 13-Mar-2006 mickey

time-bind and lower power in lock spinning and a couple of other ipi loops by using pause insn; brad@ ok tedu@ ok and feedback krw@ testing


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 06-Jun-2005 mickey

branches: 1.37.2; 1.37.4;
oops. on 686 we count fpswtch in another function...


# 1.36 21-Apr-2005 mickey

count fpu lazy context switches; deraadt@ ok


Revision tags: OPENBSD_3_7_BASE
# 1.35 21-Oct-2004 kettenis

branches: 1.35.2;
SIGFPE signal codes for SSE.
nice deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.34 21-Jul-2004 kettenis

Fix conversion of interrupt frame to trap frame.
ok deraadt@, niklas@


# 1.33 13-Jul-2004 art

Don't assert that P_INMEM is set in p_flag. The assert is only almost
correct because P_INMEM is for various reasons removed before cpu_swapout
is called and cpu_swapout in turn calls npxsave_proc.

deraadt@ ok


# 1.32 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.31 01-Feb-2004 deraadt

Enable FXSR all the time, and cope with NPX/FXSR conversions; from netbsd.
Pass SSE/SSE2/XCRYPT flags out via syctl, and prepare for being able to do
xcrypt-* in userland; ok naddy, tested a lot by pvalchev and jolan, also
works on amd64 in 32bit mode


# 1.30 31-Dec-2003 deraadt

workaround: during npx exception testing, delay(1). For some reason
amd64 (in 32 bit mode) and the new transmeta cpus want this, and lock
up otherwise. very odd.


# 1.29 24-Oct-2003 grange

No need to have several implementations of {read,write}_eflags(),
put it to cpufunc.h.
ok weingart@ tedu@


Revision tags: OPENBSD_3_4_BASE
# 1.28 25-Jul-2003 jason

let ALWAYS_MATH_EMULATE actually compile


# 1.27 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: UBC_SYNC_A
# 1.26 17-Apr-2003 drahn

i386 changes to move to ELF. asm cleanup. Change MAXDSIZ to 512M for 1Gsep.
DARPA funded work.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.25 14-Mar-2002 millert

First round of __P removal in sys


# 1.24 18-Feb-2002 ericj

multi-line string literals are deprecated in gcc 3.0
pr#2379


Revision tags: UBC_BASE
# 1.23 04-Dec-2001 niklas

branches: 1.23.2;
New try at a level based irq system.


# 1.22 18-Nov-2001 aaron

Revert niklas's broken ICU interrupt handling changes; deraadt@ ok


# 1.21 12-Nov-2001 niklas

Redo the ICU interrupt handling system to better emulate an APIC system.
This is done by representing the current blockings of interrupts with
a priority level instead of an interrupt mask. This makes it possible to
share implementations for spl* functions/macros between both ICU
and APIC (a must when going MP) systems. In this process, assign
soft interrupts their own levels to match the way things will be on
APIC systems where they actually will be real interrupts and not just
bits in a pending mask as they are now.
Heavily inspired by Bill Studenmunds SMP work in NetBSD


# 1.20 06-Nov-2001 miod

Replace inclusion of <vm/foo.h> with the correct <uvm/bar.h> when necessary.
(Look ma, I might have broken the tree)


Revision tags: OPENBSD_3_0_BASE
# 1.19 05-May-2001 art

PMAP_NEW and UVM are no longer optional on i386.


Revision tags: OPENBSD_2_9_BASE
# 1.18 09-Apr-2001 tholo

Add emulation of Linux features to procfs; mostly from NetBSD. ok deraadt@


Revision tags: OPENBSD_2_8_BASE
# 1.17 08-Jun-2000 niklas

Add explicit inclusions of signalvar.h to files actually using syms defined
there but relying on an indirect inclusion


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE SMP_BASE kame_19991208
# 1.16 26-Feb-1999 art

branches: 1.16.6;
cnt.foo -> uvmexp.bar in uvm


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.15 22-Feb-1998 niklas

GCC 2.8 Wall


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.14 17-Apr-1997 tholo

Do interrupt time accounting by running interrupt handlers with a seperate
code segment selector (otherwise identical to the standard kernel code
selector); idea by Dave Richards <richards@zso.dec.com>


# 1.13 08-Feb-1997 tholo

Provide more information on FP exceptions


# 1.12 01-Feb-1997 deraadt

add type & union sigval args to sendsig/trapsignal


# 1.11 27-Jan-1997 deraadt

add another parameter to trapsignal() and sendsig() -- fault addr to be
delivered with in the siginfo information


Revision tags: OPENBSD_2_0_BASE
# 1.10 27-Aug-1996 downsj

Add:
* GPL_MATH_EMULATE: fpemul
* ALWAYS_MATH_EMULATE: causes npx probe to always fail.
* better fp context in struct pcb.


# 1.9 25-May-1996 deraadt

sync


# 1.8 07-May-1996 deraadt

sync with 0504; prototype changes


# 1.7 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.6 20-Mar-1996 mickey

Fix back wrong patches.


# 1.5 19-Mar-1996 mickey

Merging w/ NetBSD 021796.
speaker upgraded to the current.
some changes to the VM stuff (ie kern_thread.c added and so).


# 1.4 20-Feb-1996 tholo

Pass device name to interrupt establish routines so it can be recorded in
the device interrupt chain structures (isa, pci)

Move interrupt chain structure definition to <machine/psl.h> so vmstat can
get at it (i386)

Remove hack to count interrupts the old way (i386)


# 1.3 07-Jan-1996 deraadt

from netbsd: Put #includes in the right order


# 1.2 27-Dec-1995 deraadt

from netbsd:
The IST_* and IPL_* constants are not bus-specific; don't treat them as such.


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.69 11-Apr-2018 bluhm

More steps for i386 Meltdown fix:

- provide struct cpu_info_full
- prepare K-U sections
- reorganize interrupt, trap, syscall entry to use K-U trampoline
- prepare pmap for entering special mappings, the mappings are not
setup yet

This code will already trigger performance issues. We do more tlb
flushes, but we do not unmap the kernel yet. The latter
will be needed to prevent Meltdown.

from hshoexer@; input guenther@; OK mlarkin@ deraadt@


# 1.68 31-Mar-2018 bluhm

Change ci_dev.dv_xname to ci_dev->dv_xname in debugging printf()
to make it compile when enabled.
from hshoexer@


# 1.67 31-Mar-2018 bluhm

Recommit preparation for i386 Meltdown fix after OpenBSD 6.3 release.

- provide a cpu_softc for cpu_attach() etc.
- replace per PCB TSS with per CPU TSS

The first change prepares for cpu_info being embedded in a
cpu_full_info. Therefore during autoconf/cpu_attach we hand down
a softc.

The second change removes the per PCB TSS. We now have one TSS per
CPU, thus in cpu_switchto() we only have to patch the ring 0 stack
pointer instead of loading a new TSS. This also allows for cleaning
up the GDT, so we only have a single slot for the TSS.

from hshoexer@; OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.66 22-Mar-2018 bluhm

iBackout the preparations for fixing Meltdown on i386. The task was
only halfway done and the current state does not help anybody. For
OpenBSD 6.3 release go back to the original code before 2018/03/13.
This gives us a stable release and the changes will come back later.
discussed with guenther@ deraadt@ hshoexer@


# 1.65 13-Mar-2018 bluhm

Preparation for i386 Meltdown fix:

- provide a cpu_softc for cpu_attach() etc.
- replace per PCB TSS with per CPU TSS

The first change prepares for cpu_info being embedded in a
cpu_full_info. Therefore during autoconf/cpu_attach we hand down
a softc.

The second change removes the per PCB TSS. We now have one TSS per
CPU, thus in cpu_switchto() we only have to patch the ring 0 stack
pointer instead of loading a new TSS. This also allows for cleaning
up the GDT, so we only have a single slot for the TSS.

from hshoexer@; OK deraadt@


# 1.64 01-Mar-2018 bluhm

Protect the calls to trapsignal() and psignal() with a kernel lock
when processing an npx interrupt. This fixes a kernel locked
assertion in postsig_done() during the libc ieeefp/except regression
test.
OK visa@


# 1.63 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.62 29-May-2017 mpi

Kill SPINLOCK_SPIN_HOOK, use CPU_BUSY_CYCLE() instead.

ok visa@, kettenis@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.61 11-Feb-2015 dlg

deprecate use of sys/lock.h and replace it with sys/atomic.h or
machine/lock.h as appropriate.


Revision tags: OPENBSD_5_6_BASE
# 1.60 29-Mar-2014 guenther

It's been a quarter century: we can assume volatile is present with that name.

ok dlg@ mpi@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.59 16-Nov-2013 brad

Copied from amd64..

Use an explicit suffix for the "fld" instruction to shut up clang. The correct
instruction is fldl since we try to load a double-precision value.
GCC actually gets it wrong and emits "flds" (which is harmless).

ok guenther@


Revision tags: OPENBSD_5_4_BASE
# 1.58 08-May-2013 tedu

remove stale cyrix emc support, and switch to just using intial npxcw
ok kettenis


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.57 11-Jul-2011 guenther

Revert art@'s moving around of the KERNEL_LOCK()/KERNEL_UNLOCK() calls,
as it causes hangs in some ports, including libsigsegv's configure script

confirmed by krw@, landry@


# 1.56 07-Jul-2011 art

There is a bunch of places in the kernel entry points where we don't
hold the kernel lock, but still need call one function that needs it.

Instead of grabbing the lock all over the place, move the locks into
the affected functions: trapsignal, scdebug*, ktrsyscall, ktrsysret,
systrace_redirect and ADDUPROF. In the cases we already hold the biglock
we'll just recurse.

kettenis@, beck@ ok


# 1.55 06-Jul-2011 art

Clean up after P_BIGLOCK removal.
KERNEL_PROC_LOCK -> KERNEL_LOCK
KERNEL_PROC_UNLOCK -> KERNEL_UNLOCK

oga@ ok


# 1.54 20-Mar-2011 guenther

When reading MXCSR from userland sigcontext or a ptrace request,
mask out invalid bits to prevent a protect fault.

Original diff by joshe@; further feedback and ok kettenis@


Revision tags: OPENBSD_4_9_BASE
# 1.53 29-Sep-2010 joshe

Back out previous, it appears to be broken.


# 1.52 29-Sep-2010 joshe

When reading MXCSR from userland sigcontext, mask out invalid bits.

This prevents a protection fault if a userland signal handler
scribbles all over it's struct sigcontext

Help from and ok guenther@ kettenis@


Revision tags: OPENBSD_4_8_BASE
# 1.51 23-Jul-2010 kettenis

Change the strategy for using the FPU in the kernel. The kernel FPU state
is now shared with all processes/threads. As a result, you can now use the
FPU in true process context (instead of just in kernel threads), but you
need to make sure you restore the default FPU state before calling
fpu_kernel_exit() if you change rounding mode, precision or exception masks.

Lots of discussion with thib@ and Mike Belopuhov.

ok thib@, deraadt@


# 1.50 23-Jul-2010 kettenis

Don't leak the contents of the FPU and SSE registers between processes.

ok deraadt@


# 1.49 21-Jul-2010 kettenis

Make sure that the FPU IPIs shoot down the right FPU context and not the FPU
context of some random process that happened to be switched onto the FPU
after the decision was made to send the IPI.


# 1.48 29-Jun-2010 thib

fpu_kernel_{enter,exit}; Functions to allow the use of
the FPU in the kernel.

From Mike Belopuhov; Little bits by myself.

Comments/OK kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.47 28-Oct-2009 deraadt

delete balony comment; ok kettenis


# 1.46 26-Oct-2009 kettenis

Load %mxcsr when initializing the FPU on machines that support SSE.

ok deraadt@


# 1.45 03-Oct-2009 kettenis

Properly handle XMM exceptions instead of panicing the kernel. Fixes the
issue reported by Slava Pestov.

ok deraadt@


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.44 04-Dec-2008 weingart

branches: 1.44.2; 1.44.6;
Fix "fp_save ipi didn't" panic, and move i386/amd64 closer in the process.
Positive test results by a handful of people. Ok kettenis@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.43 28-Nov-2007 tedu

branches: 1.43.4;
quite a bit of simplification by removing cpu classes.
also assume that 386 cpus are really unknown, and promote them to 486
instead of panic.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.42 18-Oct-2006 tom

Short-circuit the detection of the FPU by checking the CPUID features,
as done in FreeBSD. Fixes problems on AMD Geode LX-800 where our
detection logic doesn't detect the FP exception.

ok deraadt@ kettenis@


# 1.41 19-Sep-2006 jsg

ansi/deregister


Revision tags: OPENBSD_4_0_BASE
# 1.40 25-Jul-2006 kettenis

branches: 1.40.2;
Kill option GPL_MATH_EMULATE.

ok deraadt@ and many others.


# 1.39 19-Apr-2006 mickey

from todays freebsd advisory: fxrstor on amd cpu does not restore fip,fdp,fop thus leaking other proc's execution history; deraadt@ ok


# 1.38 13-Mar-2006 mickey

time-bind and lower power in lock spinning and a couple of other ipi loops by using pause insn; brad@ ok tedu@ ok and feedback krw@ testing


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 06-Jun-2005 mickey

branches: 1.37.2; 1.37.4;
oops. on 686 we count fpswtch in another function...


# 1.36 21-Apr-2005 mickey

count fpu lazy context switches; deraadt@ ok


Revision tags: OPENBSD_3_7_BASE
# 1.35 21-Oct-2004 kettenis

branches: 1.35.2;
SIGFPE signal codes for SSE.
nice deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.34 21-Jul-2004 kettenis

Fix conversion of interrupt frame to trap frame.
ok deraadt@, niklas@


# 1.33 13-Jul-2004 art

Don't assert that P_INMEM is set in p_flag. The assert is only almost
correct because P_INMEM is for various reasons removed before cpu_swapout
is called and cpu_swapout in turn calls npxsave_proc.

deraadt@ ok


# 1.32 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.31 01-Feb-2004 deraadt

Enable FXSR all the time, and cope with NPX/FXSR conversions; from netbsd.
Pass SSE/SSE2/XCRYPT flags out via syctl, and prepare for being able to do
xcrypt-* in userland; ok naddy, tested a lot by pvalchev and jolan, also
works on amd64 in 32bit mode


# 1.30 31-Dec-2003 deraadt

workaround: during npx exception testing, delay(1). For some reason
amd64 (in 32 bit mode) and the new transmeta cpus want this, and lock
up otherwise. very odd.


# 1.29 24-Oct-2003 grange

No need to have several implementations of {read,write}_eflags(),
put it to cpufunc.h.
ok weingart@ tedu@


Revision tags: OPENBSD_3_4_BASE
# 1.28 25-Jul-2003 jason

let ALWAYS_MATH_EMULATE actually compile


# 1.27 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: UBC_SYNC_A
# 1.26 17-Apr-2003 drahn

i386 changes to move to ELF. asm cleanup. Change MAXDSIZ to 512M for 1Gsep.
DARPA funded work.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.25 14-Mar-2002 millert

First round of __P removal in sys


# 1.24 18-Feb-2002 ericj

multi-line string literals are deprecated in gcc 3.0
pr#2379


Revision tags: UBC_BASE
# 1.23 04-Dec-2001 niklas

branches: 1.23.2;
New try at a level based irq system.


# 1.22 18-Nov-2001 aaron

Revert niklas's broken ICU interrupt handling changes; deraadt@ ok


# 1.21 12-Nov-2001 niklas

Redo the ICU interrupt handling system to better emulate an APIC system.
This is done by representing the current blockings of interrupts with
a priority level instead of an interrupt mask. This makes it possible to
share implementations for spl* functions/macros between both ICU
and APIC (a must when going MP) systems. In this process, assign
soft interrupts their own levels to match the way things will be on
APIC systems where they actually will be real interrupts and not just
bits in a pending mask as they are now.
Heavily inspired by Bill Studenmunds SMP work in NetBSD


# 1.20 06-Nov-2001 miod

Replace inclusion of <vm/foo.h> with the correct <uvm/bar.h> when necessary.
(Look ma, I might have broken the tree)


Revision tags: OPENBSD_3_0_BASE
# 1.19 05-May-2001 art

PMAP_NEW and UVM are no longer optional on i386.


Revision tags: OPENBSD_2_9_BASE
# 1.18 09-Apr-2001 tholo

Add emulation of Linux features to procfs; mostly from NetBSD. ok deraadt@


Revision tags: OPENBSD_2_8_BASE
# 1.17 08-Jun-2000 niklas

Add explicit inclusions of signalvar.h to files actually using syms defined
there but relying on an indirect inclusion


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE SMP_BASE kame_19991208
# 1.16 26-Feb-1999 art

branches: 1.16.6;
cnt.foo -> uvmexp.bar in uvm


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.15 22-Feb-1998 niklas

GCC 2.8 Wall


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.14 17-Apr-1997 tholo

Do interrupt time accounting by running interrupt handlers with a seperate
code segment selector (otherwise identical to the standard kernel code
selector); idea by Dave Richards <richards@zso.dec.com>


# 1.13 08-Feb-1997 tholo

Provide more information on FP exceptions


# 1.12 01-Feb-1997 deraadt

add type & union sigval args to sendsig/trapsignal


# 1.11 27-Jan-1997 deraadt

add another parameter to trapsignal() and sendsig() -- fault addr to be
delivered with in the siginfo information


Revision tags: OPENBSD_2_0_BASE
# 1.10 27-Aug-1996 downsj

Add:
* GPL_MATH_EMULATE: fpemul
* ALWAYS_MATH_EMULATE: causes npx probe to always fail.
* better fp context in struct pcb.


# 1.9 25-May-1996 deraadt

sync


# 1.8 07-May-1996 deraadt

sync with 0504; prototype changes


# 1.7 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.6 20-Mar-1996 mickey

Fix back wrong patches.


# 1.5 19-Mar-1996 mickey

Merging w/ NetBSD 021796.
speaker upgraded to the current.
some changes to the VM stuff (ie kern_thread.c added and so).


# 1.4 20-Feb-1996 tholo

Pass device name to interrupt establish routines so it can be recorded in
the device interrupt chain structures (isa, pci)

Move interrupt chain structure definition to <machine/psl.h> so vmstat can
get at it (i386)

Remove hack to count interrupts the old way (i386)


# 1.3 07-Jan-1996 deraadt

from netbsd: Put #includes in the right order


# 1.2 27-Dec-1995 deraadt

from netbsd:
The IST_* and IPL_* constants are not bus-specific; don't treat them as such.


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.68 31-Mar-2018 bluhm

Change ci_dev.dv_xname to ci_dev->dv_xname in debugging printf()
to make it compile when enabled.
from hshoexer@


# 1.67 31-Mar-2018 bluhm

Recommit preparation for i386 Meltdown fix after OpenBSD 6.3 release.

- provide a cpu_softc for cpu_attach() etc.
- replace per PCB TSS with per CPU TSS

The first change prepares for cpu_info being embedded in a
cpu_full_info. Therefore during autoconf/cpu_attach we hand down
a softc.

The second change removes the per PCB TSS. We now have one TSS per
CPU, thus in cpu_switchto() we only have to patch the ring 0 stack
pointer instead of loading a new TSS. This also allows for cleaning
up the GDT, so we only have a single slot for the TSS.

from hshoexer@; OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.66 22-Mar-2018 bluhm

iBackout the preparations for fixing Meltdown on i386. The task was
only halfway done and the current state does not help anybody. For
OpenBSD 6.3 release go back to the original code before 2018/03/13.
This gives us a stable release and the changes will come back later.
discussed with guenther@ deraadt@ hshoexer@


# 1.65 13-Mar-2018 bluhm

Preparation for i386 Meltdown fix:

- provide a cpu_softc for cpu_attach() etc.
- replace per PCB TSS with per CPU TSS

The first change prepares for cpu_info being embedded in a
cpu_full_info. Therefore during autoconf/cpu_attach we hand down
a softc.

The second change removes the per PCB TSS. We now have one TSS per
CPU, thus in cpu_switchto() we only have to patch the ring 0 stack
pointer instead of loading a new TSS. This also allows for cleaning
up the GDT, so we only have a single slot for the TSS.

from hshoexer@; OK deraadt@


# 1.64 01-Mar-2018 bluhm

Protect the calls to trapsignal() and psignal() with a kernel lock
when processing an npx interrupt. This fixes a kernel locked
assertion in postsig_done() during the libc ieeefp/except regression
test.
OK visa@


# 1.63 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.62 29-May-2017 mpi

Kill SPINLOCK_SPIN_HOOK, use CPU_BUSY_CYCLE() instead.

ok visa@, kettenis@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.61 11-Feb-2015 dlg

deprecate use of sys/lock.h and replace it with sys/atomic.h or
machine/lock.h as appropriate.


Revision tags: OPENBSD_5_6_BASE
# 1.60 29-Mar-2014 guenther

It's been a quarter century: we can assume volatile is present with that name.

ok dlg@ mpi@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.59 16-Nov-2013 brad

Copied from amd64..

Use an explicit suffix for the "fld" instruction to shut up clang. The correct
instruction is fldl since we try to load a double-precision value.
GCC actually gets it wrong and emits "flds" (which is harmless).

ok guenther@


Revision tags: OPENBSD_5_4_BASE
# 1.58 08-May-2013 tedu

remove stale cyrix emc support, and switch to just using intial npxcw
ok kettenis


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.57 11-Jul-2011 guenther

Revert art@'s moving around of the KERNEL_LOCK()/KERNEL_UNLOCK() calls,
as it causes hangs in some ports, including libsigsegv's configure script

confirmed by krw@, landry@


# 1.56 07-Jul-2011 art

There is a bunch of places in the kernel entry points where we don't
hold the kernel lock, but still need call one function that needs it.

Instead of grabbing the lock all over the place, move the locks into
the affected functions: trapsignal, scdebug*, ktrsyscall, ktrsysret,
systrace_redirect and ADDUPROF. In the cases we already hold the biglock
we'll just recurse.

kettenis@, beck@ ok


# 1.55 06-Jul-2011 art

Clean up after P_BIGLOCK removal.
KERNEL_PROC_LOCK -> KERNEL_LOCK
KERNEL_PROC_UNLOCK -> KERNEL_UNLOCK

oga@ ok


# 1.54 20-Mar-2011 guenther

When reading MXCSR from userland sigcontext or a ptrace request,
mask out invalid bits to prevent a protect fault.

Original diff by joshe@; further feedback and ok kettenis@


Revision tags: OPENBSD_4_9_BASE
# 1.53 29-Sep-2010 joshe

Back out previous, it appears to be broken.


# 1.52 29-Sep-2010 joshe

When reading MXCSR from userland sigcontext, mask out invalid bits.

This prevents a protection fault if a userland signal handler
scribbles all over it's struct sigcontext

Help from and ok guenther@ kettenis@


Revision tags: OPENBSD_4_8_BASE
# 1.51 23-Jul-2010 kettenis

Change the strategy for using the FPU in the kernel. The kernel FPU state
is now shared with all processes/threads. As a result, you can now use the
FPU in true process context (instead of just in kernel threads), but you
need to make sure you restore the default FPU state before calling
fpu_kernel_exit() if you change rounding mode, precision or exception masks.

Lots of discussion with thib@ and Mike Belopuhov.

ok thib@, deraadt@


# 1.50 23-Jul-2010 kettenis

Don't leak the contents of the FPU and SSE registers between processes.

ok deraadt@


# 1.49 21-Jul-2010 kettenis

Make sure that the FPU IPIs shoot down the right FPU context and not the FPU
context of some random process that happened to be switched onto the FPU
after the decision was made to send the IPI.


# 1.48 29-Jun-2010 thib

fpu_kernel_{enter,exit}; Functions to allow the use of
the FPU in the kernel.

From Mike Belopuhov; Little bits by myself.

Comments/OK kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.47 28-Oct-2009 deraadt

delete balony comment; ok kettenis


# 1.46 26-Oct-2009 kettenis

Load %mxcsr when initializing the FPU on machines that support SSE.

ok deraadt@


# 1.45 03-Oct-2009 kettenis

Properly handle XMM exceptions instead of panicing the kernel. Fixes the
issue reported by Slava Pestov.

ok deraadt@


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.44 04-Dec-2008 weingart

branches: 1.44.2; 1.44.6;
Fix "fp_save ipi didn't" panic, and move i386/amd64 closer in the process.
Positive test results by a handful of people. Ok kettenis@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.43 28-Nov-2007 tedu

branches: 1.43.4;
quite a bit of simplification by removing cpu classes.
also assume that 386 cpus are really unknown, and promote them to 486
instead of panic.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.42 18-Oct-2006 tom

Short-circuit the detection of the FPU by checking the CPUID features,
as done in FreeBSD. Fixes problems on AMD Geode LX-800 where our
detection logic doesn't detect the FP exception.

ok deraadt@ kettenis@


# 1.41 19-Sep-2006 jsg

ansi/deregister


Revision tags: OPENBSD_4_0_BASE
# 1.40 25-Jul-2006 kettenis

branches: 1.40.2;
Kill option GPL_MATH_EMULATE.

ok deraadt@ and many others.


# 1.39 19-Apr-2006 mickey

from todays freebsd advisory: fxrstor on amd cpu does not restore fip,fdp,fop thus leaking other proc's execution history; deraadt@ ok


# 1.38 13-Mar-2006 mickey

time-bind and lower power in lock spinning and a couple of other ipi loops by using pause insn; brad@ ok tedu@ ok and feedback krw@ testing


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 06-Jun-2005 mickey

branches: 1.37.2; 1.37.4;
oops. on 686 we count fpswtch in another function...


# 1.36 21-Apr-2005 mickey

count fpu lazy context switches; deraadt@ ok


Revision tags: OPENBSD_3_7_BASE
# 1.35 21-Oct-2004 kettenis

branches: 1.35.2;
SIGFPE signal codes for SSE.
nice deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.34 21-Jul-2004 kettenis

Fix conversion of interrupt frame to trap frame.
ok deraadt@, niklas@


# 1.33 13-Jul-2004 art

Don't assert that P_INMEM is set in p_flag. The assert is only almost
correct because P_INMEM is for various reasons removed before cpu_swapout
is called and cpu_swapout in turn calls npxsave_proc.

deraadt@ ok


# 1.32 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.31 01-Feb-2004 deraadt

Enable FXSR all the time, and cope with NPX/FXSR conversions; from netbsd.
Pass SSE/SSE2/XCRYPT flags out via syctl, and prepare for being able to do
xcrypt-* in userland; ok naddy, tested a lot by pvalchev and jolan, also
works on amd64 in 32bit mode


# 1.30 31-Dec-2003 deraadt

workaround: during npx exception testing, delay(1). For some reason
amd64 (in 32 bit mode) and the new transmeta cpus want this, and lock
up otherwise. very odd.


# 1.29 24-Oct-2003 grange

No need to have several implementations of {read,write}_eflags(),
put it to cpufunc.h.
ok weingart@ tedu@


Revision tags: OPENBSD_3_4_BASE
# 1.28 25-Jul-2003 jason

let ALWAYS_MATH_EMULATE actually compile


# 1.27 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: UBC_SYNC_A
# 1.26 17-Apr-2003 drahn

i386 changes to move to ELF. asm cleanup. Change MAXDSIZ to 512M for 1Gsep.
DARPA funded work.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.25 14-Mar-2002 millert

First round of __P removal in sys


# 1.24 18-Feb-2002 ericj

multi-line string literals are deprecated in gcc 3.0
pr#2379


Revision tags: UBC_BASE
# 1.23 04-Dec-2001 niklas

branches: 1.23.2;
New try at a level based irq system.


# 1.22 18-Nov-2001 aaron

Revert niklas's broken ICU interrupt handling changes; deraadt@ ok


# 1.21 12-Nov-2001 niklas

Redo the ICU interrupt handling system to better emulate an APIC system.
This is done by representing the current blockings of interrupts with
a priority level instead of an interrupt mask. This makes it possible to
share implementations for spl* functions/macros between both ICU
and APIC (a must when going MP) systems. In this process, assign
soft interrupts their own levels to match the way things will be on
APIC systems where they actually will be real interrupts and not just
bits in a pending mask as they are now.
Heavily inspired by Bill Studenmunds SMP work in NetBSD


# 1.20 06-Nov-2001 miod

Replace inclusion of <vm/foo.h> with the correct <uvm/bar.h> when necessary.
(Look ma, I might have broken the tree)


Revision tags: OPENBSD_3_0_BASE
# 1.19 05-May-2001 art

PMAP_NEW and UVM are no longer optional on i386.


Revision tags: OPENBSD_2_9_BASE
# 1.18 09-Apr-2001 tholo

Add emulation of Linux features to procfs; mostly from NetBSD. ok deraadt@


Revision tags: OPENBSD_2_8_BASE
# 1.17 08-Jun-2000 niklas

Add explicit inclusions of signalvar.h to files actually using syms defined
there but relying on an indirect inclusion


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE SMP_BASE kame_19991208
# 1.16 26-Feb-1999 art

branches: 1.16.6;
cnt.foo -> uvmexp.bar in uvm


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.15 22-Feb-1998 niklas

GCC 2.8 Wall


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.14 17-Apr-1997 tholo

Do interrupt time accounting by running interrupt handlers with a seperate
code segment selector (otherwise identical to the standard kernel code
selector); idea by Dave Richards <richards@zso.dec.com>


# 1.13 08-Feb-1997 tholo

Provide more information on FP exceptions


# 1.12 01-Feb-1997 deraadt

add type & union sigval args to sendsig/trapsignal


# 1.11 27-Jan-1997 deraadt

add another parameter to trapsignal() and sendsig() -- fault addr to be
delivered with in the siginfo information


Revision tags: OPENBSD_2_0_BASE
# 1.10 27-Aug-1996 downsj

Add:
* GPL_MATH_EMULATE: fpemul
* ALWAYS_MATH_EMULATE: causes npx probe to always fail.
* better fp context in struct pcb.


# 1.9 25-May-1996 deraadt

sync


# 1.8 07-May-1996 deraadt

sync with 0504; prototype changes


# 1.7 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.6 20-Mar-1996 mickey

Fix back wrong patches.


# 1.5 19-Mar-1996 mickey

Merging w/ NetBSD 021796.
speaker upgraded to the current.
some changes to the VM stuff (ie kern_thread.c added and so).


# 1.4 20-Feb-1996 tholo

Pass device name to interrupt establish routines so it can be recorded in
the device interrupt chain structures (isa, pci)

Move interrupt chain structure definition to <machine/psl.h> so vmstat can
get at it (i386)

Remove hack to count interrupts the old way (i386)


# 1.3 07-Jan-1996 deraadt

from netbsd: Put #includes in the right order


# 1.2 27-Dec-1995 deraadt

from netbsd:
The IST_* and IPL_* constants are not bus-specific; don't treat them as such.


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.64 01-Mar-2018 bluhm

Protect the calls to trapsignal() and psignal() with a kernel lock
when processing an npx interrupt. This fixes a kernel locked
assertion in postsig_done() during the libc ieeefp/except regression
test.
OK visa@


# 1.63 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.62 29-May-2017 mpi

Kill SPINLOCK_SPIN_HOOK, use CPU_BUSY_CYCLE() instead.

ok visa@, kettenis@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.61 11-Feb-2015 dlg

deprecate use of sys/lock.h and replace it with sys/atomic.h or
machine/lock.h as appropriate.


Revision tags: OPENBSD_5_6_BASE
# 1.60 29-Mar-2014 guenther

It's been a quarter century: we can assume volatile is present with that name.

ok dlg@ mpi@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.59 16-Nov-2013 brad

Copied from amd64..

Use an explicit suffix for the "fld" instruction to shut up clang. The correct
instruction is fldl since we try to load a double-precision value.
GCC actually gets it wrong and emits "flds" (which is harmless).

ok guenther@


Revision tags: OPENBSD_5_4_BASE
# 1.58 08-May-2013 tedu

remove stale cyrix emc support, and switch to just using intial npxcw
ok kettenis


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.57 11-Jul-2011 guenther

Revert art@'s moving around of the KERNEL_LOCK()/KERNEL_UNLOCK() calls,
as it causes hangs in some ports, including libsigsegv's configure script

confirmed by krw@, landry@


# 1.56 07-Jul-2011 art

There is a bunch of places in the kernel entry points where we don't
hold the kernel lock, but still need call one function that needs it.

Instead of grabbing the lock all over the place, move the locks into
the affected functions: trapsignal, scdebug*, ktrsyscall, ktrsysret,
systrace_redirect and ADDUPROF. In the cases we already hold the biglock
we'll just recurse.

kettenis@, beck@ ok


# 1.55 06-Jul-2011 art

Clean up after P_BIGLOCK removal.
KERNEL_PROC_LOCK -> KERNEL_LOCK
KERNEL_PROC_UNLOCK -> KERNEL_UNLOCK

oga@ ok


# 1.54 20-Mar-2011 guenther

When reading MXCSR from userland sigcontext or a ptrace request,
mask out invalid bits to prevent a protect fault.

Original diff by joshe@; further feedback and ok kettenis@


Revision tags: OPENBSD_4_9_BASE
# 1.53 29-Sep-2010 joshe

Back out previous, it appears to be broken.


# 1.52 29-Sep-2010 joshe

When reading MXCSR from userland sigcontext, mask out invalid bits.

This prevents a protection fault if a userland signal handler
scribbles all over it's struct sigcontext

Help from and ok guenther@ kettenis@


Revision tags: OPENBSD_4_8_BASE
# 1.51 23-Jul-2010 kettenis

Change the strategy for using the FPU in the kernel. The kernel FPU state
is now shared with all processes/threads. As a result, you can now use the
FPU in true process context (instead of just in kernel threads), but you
need to make sure you restore the default FPU state before calling
fpu_kernel_exit() if you change rounding mode, precision or exception masks.

Lots of discussion with thib@ and Mike Belopuhov.

ok thib@, deraadt@


# 1.50 23-Jul-2010 kettenis

Don't leak the contents of the FPU and SSE registers between processes.

ok deraadt@


# 1.49 21-Jul-2010 kettenis

Make sure that the FPU IPIs shoot down the right FPU context and not the FPU
context of some random process that happened to be switched onto the FPU
after the decision was made to send the IPI.


# 1.48 29-Jun-2010 thib

fpu_kernel_{enter,exit}; Functions to allow the use of
the FPU in the kernel.

From Mike Belopuhov; Little bits by myself.

Comments/OK kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.47 28-Oct-2009 deraadt

delete balony comment; ok kettenis


# 1.46 26-Oct-2009 kettenis

Load %mxcsr when initializing the FPU on machines that support SSE.

ok deraadt@


# 1.45 03-Oct-2009 kettenis

Properly handle XMM exceptions instead of panicing the kernel. Fixes the
issue reported by Slava Pestov.

ok deraadt@


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.44 04-Dec-2008 weingart

branches: 1.44.2; 1.44.6;
Fix "fp_save ipi didn't" panic, and move i386/amd64 closer in the process.
Positive test results by a handful of people. Ok kettenis@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.43 28-Nov-2007 tedu

branches: 1.43.4;
quite a bit of simplification by removing cpu classes.
also assume that 386 cpus are really unknown, and promote them to 486
instead of panic.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.42 18-Oct-2006 tom

Short-circuit the detection of the FPU by checking the CPUID features,
as done in FreeBSD. Fixes problems on AMD Geode LX-800 where our
detection logic doesn't detect the FP exception.

ok deraadt@ kettenis@


# 1.41 19-Sep-2006 jsg

ansi/deregister


Revision tags: OPENBSD_4_0_BASE
# 1.40 25-Jul-2006 kettenis

branches: 1.40.2;
Kill option GPL_MATH_EMULATE.

ok deraadt@ and many others.


# 1.39 19-Apr-2006 mickey

from todays freebsd advisory: fxrstor on amd cpu does not restore fip,fdp,fop thus leaking other proc's execution history; deraadt@ ok


# 1.38 13-Mar-2006 mickey

time-bind and lower power in lock spinning and a couple of other ipi loops by using pause insn; brad@ ok tedu@ ok and feedback krw@ testing


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 06-Jun-2005 mickey

branches: 1.37.2; 1.37.4;
oops. on 686 we count fpswtch in another function...


# 1.36 21-Apr-2005 mickey

count fpu lazy context switches; deraadt@ ok


Revision tags: OPENBSD_3_7_BASE
# 1.35 21-Oct-2004 kettenis

branches: 1.35.2;
SIGFPE signal codes for SSE.
nice deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.34 21-Jul-2004 kettenis

Fix conversion of interrupt frame to trap frame.
ok deraadt@, niklas@


# 1.33 13-Jul-2004 art

Don't assert that P_INMEM is set in p_flag. The assert is only almost
correct because P_INMEM is for various reasons removed before cpu_swapout
is called and cpu_swapout in turn calls npxsave_proc.

deraadt@ ok


# 1.32 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.31 01-Feb-2004 deraadt

Enable FXSR all the time, and cope with NPX/FXSR conversions; from netbsd.
Pass SSE/SSE2/XCRYPT flags out via syctl, and prepare for being able to do
xcrypt-* in userland; ok naddy, tested a lot by pvalchev and jolan, also
works on amd64 in 32bit mode


# 1.30 31-Dec-2003 deraadt

workaround: during npx exception testing, delay(1). For some reason
amd64 (in 32 bit mode) and the new transmeta cpus want this, and lock
up otherwise. very odd.


# 1.29 24-Oct-2003 grange

No need to have several implementations of {read,write}_eflags(),
put it to cpufunc.h.
ok weingart@ tedu@


Revision tags: OPENBSD_3_4_BASE
# 1.28 25-Jul-2003 jason

let ALWAYS_MATH_EMULATE actually compile


# 1.27 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: UBC_SYNC_A
# 1.26 17-Apr-2003 drahn

i386 changes to move to ELF. asm cleanup. Change MAXDSIZ to 512M for 1Gsep.
DARPA funded work.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.25 14-Mar-2002 millert

First round of __P removal in sys


# 1.24 18-Feb-2002 ericj

multi-line string literals are deprecated in gcc 3.0
pr#2379


Revision tags: UBC_BASE
# 1.23 04-Dec-2001 niklas

branches: 1.23.2;
New try at a level based irq system.


# 1.22 18-Nov-2001 aaron

Revert niklas's broken ICU interrupt handling changes; deraadt@ ok


# 1.21 12-Nov-2001 niklas

Redo the ICU interrupt handling system to better emulate an APIC system.
This is done by representing the current blockings of interrupts with
a priority level instead of an interrupt mask. This makes it possible to
share implementations for spl* functions/macros between both ICU
and APIC (a must when going MP) systems. In this process, assign
soft interrupts their own levels to match the way things will be on
APIC systems where they actually will be real interrupts and not just
bits in a pending mask as they are now.
Heavily inspired by Bill Studenmunds SMP work in NetBSD


# 1.20 06-Nov-2001 miod

Replace inclusion of <vm/foo.h> with the correct <uvm/bar.h> when necessary.
(Look ma, I might have broken the tree)


Revision tags: OPENBSD_3_0_BASE
# 1.19 05-May-2001 art

PMAP_NEW and UVM are no longer optional on i386.


Revision tags: OPENBSD_2_9_BASE
# 1.18 09-Apr-2001 tholo

Add emulation of Linux features to procfs; mostly from NetBSD. ok deraadt@


Revision tags: OPENBSD_2_8_BASE
# 1.17 08-Jun-2000 niklas

Add explicit inclusions of signalvar.h to files actually using syms defined
there but relying on an indirect inclusion


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE SMP_BASE kame_19991208
# 1.16 26-Feb-1999 art

branches: 1.16.6;
cnt.foo -> uvmexp.bar in uvm


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.15 22-Feb-1998 niklas

GCC 2.8 Wall


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.14 17-Apr-1997 tholo

Do interrupt time accounting by running interrupt handlers with a seperate
code segment selector (otherwise identical to the standard kernel code
selector); idea by Dave Richards <richards@zso.dec.com>


# 1.13 08-Feb-1997 tholo

Provide more information on FP exceptions


# 1.12 01-Feb-1997 deraadt

add type & union sigval args to sendsig/trapsignal


# 1.11 27-Jan-1997 deraadt

add another parameter to trapsignal() and sendsig() -- fault addr to be
delivered with in the siginfo information


Revision tags: OPENBSD_2_0_BASE
# 1.10 27-Aug-1996 downsj

Add:
* GPL_MATH_EMULATE: fpemul
* ALWAYS_MATH_EMULATE: causes npx probe to always fail.
* better fp context in struct pcb.


# 1.9 25-May-1996 deraadt

sync


# 1.8 07-May-1996 deraadt

sync with 0504; prototype changes


# 1.7 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.6 20-Mar-1996 mickey

Fix back wrong patches.


# 1.5 19-Mar-1996 mickey

Merging w/ NetBSD 021796.
speaker upgraded to the current.
some changes to the VM stuff (ie kern_thread.c added and so).


# 1.4 20-Feb-1996 tholo

Pass device name to interrupt establish routines so it can be recorded in
the device interrupt chain structures (isa, pci)

Move interrupt chain structure definition to <machine/psl.h> so vmstat can
get at it (i386)

Remove hack to count interrupts the old way (i386)


# 1.3 07-Jan-1996 deraadt

from netbsd: Put #includes in the right order


# 1.2 27-Dec-1995 deraadt

from netbsd:
The IST_* and IPL_* constants are not bus-specific; don't treat them as such.


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.63 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.62 29-May-2017 mpi

Kill SPINLOCK_SPIN_HOOK, use CPU_BUSY_CYCLE() instead.

ok visa@, kettenis@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.61 11-Feb-2015 dlg

deprecate use of sys/lock.h and replace it with sys/atomic.h or
machine/lock.h as appropriate.


Revision tags: OPENBSD_5_6_BASE
# 1.60 29-Mar-2014 guenther

It's been a quarter century: we can assume volatile is present with that name.

ok dlg@ mpi@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.59 16-Nov-2013 brad

Copied from amd64..

Use an explicit suffix for the "fld" instruction to shut up clang. The correct
instruction is fldl since we try to load a double-precision value.
GCC actually gets it wrong and emits "flds" (which is harmless).

ok guenther@


Revision tags: OPENBSD_5_4_BASE
# 1.58 08-May-2013 tedu

remove stale cyrix emc support, and switch to just using intial npxcw
ok kettenis


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.57 11-Jul-2011 guenther

Revert art@'s moving around of the KERNEL_LOCK()/KERNEL_UNLOCK() calls,
as it causes hangs in some ports, including libsigsegv's configure script

confirmed by krw@, landry@


# 1.56 07-Jul-2011 art

There is a bunch of places in the kernel entry points where we don't
hold the kernel lock, but still need call one function that needs it.

Instead of grabbing the lock all over the place, move the locks into
the affected functions: trapsignal, scdebug*, ktrsyscall, ktrsysret,
systrace_redirect and ADDUPROF. In the cases we already hold the biglock
we'll just recurse.

kettenis@, beck@ ok


# 1.55 06-Jul-2011 art

Clean up after P_BIGLOCK removal.
KERNEL_PROC_LOCK -> KERNEL_LOCK
KERNEL_PROC_UNLOCK -> KERNEL_UNLOCK

oga@ ok


# 1.54 20-Mar-2011 guenther

When reading MXCSR from userland sigcontext or a ptrace request,
mask out invalid bits to prevent a protect fault.

Original diff by joshe@; further feedback and ok kettenis@


Revision tags: OPENBSD_4_9_BASE
# 1.53 29-Sep-2010 joshe

Back out previous, it appears to be broken.


# 1.52 29-Sep-2010 joshe

When reading MXCSR from userland sigcontext, mask out invalid bits.

This prevents a protection fault if a userland signal handler
scribbles all over it's struct sigcontext

Help from and ok guenther@ kettenis@


Revision tags: OPENBSD_4_8_BASE
# 1.51 23-Jul-2010 kettenis

Change the strategy for using the FPU in the kernel. The kernel FPU state
is now shared with all processes/threads. As a result, you can now use the
FPU in true process context (instead of just in kernel threads), but you
need to make sure you restore the default FPU state before calling
fpu_kernel_exit() if you change rounding mode, precision or exception masks.

Lots of discussion with thib@ and Mike Belopuhov.

ok thib@, deraadt@


# 1.50 23-Jul-2010 kettenis

Don't leak the contents of the FPU and SSE registers between processes.

ok deraadt@


# 1.49 21-Jul-2010 kettenis

Make sure that the FPU IPIs shoot down the right FPU context and not the FPU
context of some random process that happened to be switched onto the FPU
after the decision was made to send the IPI.


# 1.48 29-Jun-2010 thib

fpu_kernel_{enter,exit}; Functions to allow the use of
the FPU in the kernel.

From Mike Belopuhov; Little bits by myself.

Comments/OK kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.47 28-Oct-2009 deraadt

delete balony comment; ok kettenis


# 1.46 26-Oct-2009 kettenis

Load %mxcsr when initializing the FPU on machines that support SSE.

ok deraadt@


# 1.45 03-Oct-2009 kettenis

Properly handle XMM exceptions instead of panicing the kernel. Fixes the
issue reported by Slava Pestov.

ok deraadt@


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.44 04-Dec-2008 weingart

branches: 1.44.2; 1.44.6;
Fix "fp_save ipi didn't" panic, and move i386/amd64 closer in the process.
Positive test results by a handful of people. Ok kettenis@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.43 28-Nov-2007 tedu

branches: 1.43.4;
quite a bit of simplification by removing cpu classes.
also assume that 386 cpus are really unknown, and promote them to 486
instead of panic.


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.42 18-Oct-2006 tom

Short-circuit the detection of the FPU by checking the CPUID features,
as done in FreeBSD. Fixes problems on AMD Geode LX-800 where our
detection logic doesn't detect the FP exception.

ok deraadt@ kettenis@


# 1.41 19-Sep-2006 jsg

ansi/deregister


Revision tags: OPENBSD_4_0_BASE
# 1.40 25-Jul-2006 kettenis

branches: 1.40.2;
Kill option GPL_MATH_EMULATE.

ok deraadt@ and many others.


# 1.39 19-Apr-2006 mickey

from todays freebsd advisory: fxrstor on amd cpu does not restore fip,fdp,fop thus leaking other proc's execution history; deraadt@ ok


# 1.38 13-Mar-2006 mickey

time-bind and lower power in lock spinning and a couple of other ipi loops by using pause insn; brad@ ok tedu@ ok and feedback krw@ testing


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 06-Jun-2005 mickey

branches: 1.37.2; 1.37.4;
oops. on 686 we count fpswtch in another function...


# 1.36 21-Apr-2005 mickey

count fpu lazy context switches; deraadt@ ok


Revision tags: OPENBSD_3_7_BASE
# 1.35 21-Oct-2004 kettenis

branches: 1.35.2;
SIGFPE signal codes for SSE.
nice deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.34 21-Jul-2004 kettenis

Fix conversion of interrupt frame to trap frame.
ok deraadt@, niklas@


# 1.33 13-Jul-2004 art

Don't assert that P_INMEM is set in p_flag. The assert is only almost
correct because P_INMEM is for various reasons removed before cpu_swapout
is called and cpu_swapout in turn calls npxsave_proc.

deraadt@ ok


# 1.32 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.31 01-Feb-2004 deraadt

Enable FXSR all the time, and cope with NPX/FXSR conversions; from netbsd.
Pass SSE/SSE2/XCRYPT flags out via syctl, and prepare for being able to do
xcrypt-* in userland; ok naddy, tested a lot by pvalchev and jolan, also
works on amd64 in 32bit mode


# 1.30 31-Dec-2003 deraadt

workaround: during npx exception testing, delay(1). For some reason
amd64 (in 32 bit mode) and the new transmeta cpus want this, and lock
up otherwise. very odd.


# 1.29 24-Oct-2003 grange

No need to have several implementations of {read,write}_eflags(),
put it to cpufunc.h.
ok weingart@ tedu@


Revision tags: OPENBSD_3_4_BASE
# 1.28 25-Jul-2003 jason

let ALWAYS_MATH_EMULATE actually compile


# 1.27 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: UBC_SYNC_A
# 1.26 17-Apr-2003 drahn

i386 changes to move to ELF. asm cleanup. Change MAXDSIZ to 512M for 1Gsep.
DARPA funded work.


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE UBC_SYNC_B
# 1.25 14-Mar-2002 millert

First round of __P removal in sys


# 1.24 18-Feb-2002 ericj

multi-line string literals are deprecated in gcc 3.0
pr#2379


Revision tags: UBC_BASE
# 1.23 04-Dec-2001 niklas

branches: 1.23.2;
New try at a level based irq system.


# 1.22 18-Nov-2001 aaron

Revert niklas's broken ICU interrupt handling changes; deraadt@ ok


# 1.21 12-Nov-2001 niklas

Redo the ICU interrupt handling system to better emulate an APIC system.
This is done by representing the current blockings of interrupts with
a priority level instead of an interrupt mask. This makes it possible to
share implementations for spl* functions/macros between both ICU
and APIC (a must when going MP) systems. In this process, assign
soft interrupts their own levels to match the way things will be on
APIC systems where they actually will be real interrupts and not just
bits in a pending mask as they are now.
Heavily inspired by Bill Studenmunds SMP work in NetBSD


# 1.20 06-Nov-2001 miod

Replace inclusion of <vm/foo.h> with the correct <uvm/bar.h> when necessary.
(Look ma, I might have broken the tree)


Revision tags: OPENBSD_3_0_BASE
# 1.19 05-May-2001 art

PMAP_NEW and UVM are no longer optional on i386.


Revision tags: OPENBSD_2_9_BASE
# 1.18 09-Apr-2001 tholo

Add emulation of Linux features to procfs; mostly from NetBSD. ok deraadt@


Revision tags: OPENBSD_2_8_BASE
# 1.17 08-Jun-2000 niklas

Add explicit inclusions of signalvar.h to files actually using syms defined
there but relying on an indirect inclusion


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE SMP_BASE kame_19991208
# 1.16 26-Feb-1999 art

branches: 1.16.6;
cnt.foo -> uvmexp.bar in uvm


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.15 22-Feb-1998 niklas

GCC 2.8 Wall


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.14 17-Apr-1997 tholo

Do interrupt time accounting by running interrupt handlers with a seperate
code segment selector (otherwise identical to the standard kernel code
selector); idea by Dave Richards <richards@zso.dec.com>


# 1.13 08-Feb-1997 tholo

Provide more information on FP exceptions


# 1.12 01-Feb-1997 deraadt

add type & union sigval args to sendsig/trapsignal


# 1.11 27-Jan-1997 deraadt

add another parameter to trapsignal() and sendsig() -- fault addr to be
delivered with in the siginfo information


Revision tags: OPENBSD_2_0_BASE
# 1.10 27-Aug-1996 downsj

Add:
* GPL_MATH_EMULATE: fpemul
* ALWAYS_MATH_EMULATE: causes npx probe to always fail.
* better fp context in struct pcb.


# 1.9 25-May-1996 deraadt

sync


# 1.8 07-May-1996 deraadt

sync with 0504; prototype changes


# 1.7 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.6 20-Mar-1996 mickey

Fix back wrong patches.


# 1.5 19-Mar-1996 mickey

Merging w/ NetBSD 021796.
speaker upgraded to the current.
some changes to the VM stuff (ie kern_thread.c added and so).


# 1.4 20-Feb-1996 tholo

Pass device name to interrupt establish routines so it can be recorded in
the device interrupt chain structures (isa, pci)

Move interrupt chain structure definition to <machine/psl.h> so vmstat can
get at it (i386)

Remove hack to count interrupts the old way (i386)


# 1.3 07-Jan-1996 deraadt

from netbsd: Put #includes in the right order


# 1.2 27-Dec-1995 deraadt

from netbsd:
The IST_* and IPL_* constants are not bus-specific; don't treat them as such.


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision