History log of /openbsd-current/sys/arch/m88k/m88k/m88k_machdep.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.73 28-May-2024 claudio

cpu_emergency_disable() was only used by mvme88k and can be removed now.

This removes one of the SCHED_LOCK usages in arch.
OK miod@


Revision tags: OPENBSD_7_3_BASE OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.72 06-Jan-2023 miod

Remove copystr(9), unless used internally by copy{in,out}str.


# 1.71 30-Oct-2022 guenther

Simplfity setregs() by passing it the ps_strings and switching
sys_execve() to return EJUSTRETURN.

setregs() is the MD routine used by sys_execve() to set up the
thread's trapframe and PCB such that, on 'return' to userspace, it
has the register values defined by the ABI and otherwise zero. It
had to set the syscall retval[] values previously because the normal
syscall return path overwrites a couple registers with the retval[]
values. By instead returning EJUSTRETURN that and some complexity
with program-counter handling on m88k and sparc64 goes away.

Also, give setregs() add a 'struct ps_strings *arginfo' argument
so powerpc, powerpc64, and sh can directly get argc/argv/envp
values for registers instead of copyin()ing the one in userspace.

Improvements from miod@ and millert@
Testing assistance miod@, kettenis@, and aoyama@
ok miod@ kettenis@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.70 15-Oct-2019 mpi

Reduce the number of places where `p_priority' and `p_stat' are set.

This refactoring will help future scheduler locking, in particular to
shrink the SCHED_LOCK().

No intended behavior change.

ok visa@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.69 22-Oct-2018 krw

More "explicitely" -> "explicitly" in various comments.

ok guenther@ tb@ deraadt@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.68 29-May-2017 mpi

Kill SPINLOCK_SPIN_HOOK, use CPU_BUSY_CYCLE() instead.

ok visa@, kettenis@


Revision tags: OPENBSD_6_1_BASE
# 1.67 19-Mar-2017 miod

Put the address of the per-cpu clock and interrupt registers into the cpu_info
struct, rather than fetching them from arrays every time they are needed.

ok aoyama@


# 1.66 09-Oct-2016 guenther

Tweak the special handling of pid 1 in setregs()...and document that
while it's not 100% correct, it's okay

tested by aoyama@


# 1.65 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


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

no md code wants lockmgr locks, so no md code needs to include sys/lock.h

with and ok miod@


Revision tags: OPENBSD_5_6_BASE
# 1.63 15-Jul-2014 miod

Implement rw_cas() with atomic_cas_ulong() now, instead of a dedicated
routine.


# 1.62 09-Jun-2014 miod

Remove redundant regdump() output.


# 1.61 31-May-2014 miod

In regdump(), print DAE registers when they are valid, regardless of the
exception type.


# 1.60 08-May-2014 miod

Format string fixes for m88k; remove -Wno-format from the m88k kernels.


# 1.59 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.58 07-Oct-2013 miod

Put the kernel VBR page at the beginning of the kernel text, as done on
mvme88k, to be able to unmap the page at address zero in the kernel, and have
the vbr page read-only after being initialized.


Revision tags: OPENBSD_5_4_BASE
# 1.57 17-Jul-2013 miod

Fix setregs() to match prototype. Exposed by recent _types.h change, found the
hard way by aoyama@


# 1.56 15-May-2013 miod

Initialize a teeny few more globals to reasonable values to allow for printf()
to work as soon as cn_tab is initialized. Allows us to correctly printf or
panic early on unrecognized systems. This used to be the case but got lost a
long time ago.


Revision tags: OPENBSD_5_3_BASE
# 1.55 17-Feb-2013 miod

Constify struct cmmu.


# 1.54 26-Jan-2013 miod

Make sure new processes get a clean FPU configuration upon startup, by
resetting the appropriate register in setregs(). Similar in spirit to what
m68k does (restoring a null frame), and necessary since m88k doesn't do lazy
fpu switching.


# 1.53 05-Jan-2013 miod

Switch m88k ports to ELF.


Revision tags: OPENBSD_5_2_BASE
# 1.52 23-Mar-2012 guenther

Make rusage totals, itimers, and profile settings per-process instead
of per-rthread. Handling of per-thread tick and runtime counters
inspired by how FreeBSD does it.

ok kettenis@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.51 23-Dec-2010 miod

The exception vector page on m88k systems has always been the same page as
the one used by the firmware, which (at least on mvme88k) is at address zero.

This is unfortunate, since this means that NULL pointer dereferences in the
kernel are not caught, and writes cause havoc.

This behaviour was necessary to be able to use the PROM system call interface
during early bootstrap, without having to disassemble the VBR page and
update branches - which use pc-relative displacement - if we were to use
a different VBR address.

On mvme88k, change this and actually set up two VBR pages: one, over the PROM
page (except for the system call vectors), and another one in the kernel
image (which will be mapped read-only). We'll run with the PROM page until
the end of autoconf, and then switch to the kernel one, and unmap all the
PROM below it.

As a bonus, the final kernel page can use optimized data access fault
handlers, which do not have to check for faults caused by badaddr(), since
badaddr() is only used during device probe on buses which do not support
hotplug.

There are a few infrastructure collateral damage on aviion and luna88k, but
these ports do not change their behaviour yet.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.50 19-Apr-2009 miod

Rename max_cpus to ncpusfound and compute it regardless of option
MULTIPROCESSOR.


# 1.49 15-Mar-2009 miod

Generic softinterrupt support for m88k based platforms, adapted from arm
with different locking mechanism. 88110 soft ipi are replaced with an
ipi callback which is checked upon return from exception (it can not be kept
as a softintr, as the generic softinterrupt code doesn't have per-cpu
pending softintr queues).


# 1.48 04-Mar-2009 miod

Introduce atomic_clear_int() as an MD atomic operation to perform atomic
exchange with zero; use it in the soft interrupt code to make it simpler
and faster.


# 1.47 04-Mar-2009 miod

Fix stupid logic bug in rw_cas_m88k(), makes NFS much happier on SMP kernels.


Revision tags: OPENBSD_4_5_BASE
# 1.46 20-Feb-2009 miod

atomic_{set,clear}bits_int were not safe enough on 88110 systems, as they
can be interrupted by NMI; move the SMP version of these routines from
inlines to a separate file (kernel text shrinks 20KB...).

Since the implementation for 88110 becomes really hairy, the pre-main() code
is responsible for copying the appropriate code over for kernels configured
for both 88100 and 88110 cpus, to avoid having to choose the atomicity
strategy at runtime. Hairy, I said.

This gets GENERIC.MP run much further on 197DP. Not enough to reach multiuser
mode, but boots up to starting sshd and then panics.


# 1.45 18-Feb-2009 miod

typo


# 1.44 16-Feb-2009 miod

More 88110 SMP work. Contains, horribly entangled:
- dma_cachectl() split into a ``local cpu only'' and ``all cpus'', and an ipi
to broadcast ``local dma_cachectl'' is added.
- cpu_info fields are rearranged, to have the 88100-specific information
and the 88110-specific information overlap, and has many more 88110
ugly things.
- more ipi handling in the 197-specific area. Since it is not possible to
have the second processor receive any hardware interrupt (selection
is done on a level basis via ISEL, and we definitely do not want the
main cpu to lose interrupts), the best we can do is to inflict ourselves
a soft interrupt for late ipi processing. It gets used for softclock and
hardclock on the secondary processor, but since the soft interrupt
dispatcher doesn't have an exception frame, we have to remember parts
of it to build a fake clockframe from the soft ipi handler (ugly but
works).

This now lets GENERIC.MP run a few userland binaries before bugs trigger.


# 1.43 21-Dec-2008 miod

Proper cpu_unidle() function for MP kernels. ok art@ long ago


# 1.42 27-Nov-2008 miod

On 88100 cpus, make sure userland processes start with SNIP and SFIP valid
(i.e. with the valid bit set in them). Found the hard way by Anders Gavare
trying his latest gxemul, proves the hardware is more permitting than one
would expect it to be...


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.41 26-Dec-2007 miod

Remove the last debug bit from the PSR on 88110: do not force memory accesses
instructions to be serialized (this defeats the purpose of having a superscalar
processor, and accesses to volatile variables are done with explicit memory
barriers anyway).

This brings a HUGE speedup: openssl speed -elapsed shows AES is 90% faster,
blowfish is 75% faster, and sha1 is 50% faster. Not so bad!

However, doing this increases the pressure on the processor bus, so it is
necessary to increase the processor bus timeout on 40MHz boards again (to 256
usec). ``black cat'' 50MHz boards seem to be unaffected, so they remain at
64 usec.


# 1.40 15-Dec-2007 miod

Move the cmmu lock back from 8820x-specific code to global, and use it on
MVME197DP to serialize 88410 operations.


# 1.39 09-Dec-2007 miod

I honestly do not remember what 88110 errata convinced me to disable
out-of-order (superscalar) execution on these processors.

Since OoO brings a nice 50% to 250% speedup (as shown by ``openssl speed''),
it is definitely worth enabling.


# 1.38 05-Dec-2007 miod

xmem can not be used as a reliable atomic operation, they way we do them,
so do the naive operations with interrupts disabled, and an interlock held
if MULTIPROCESSOR.


# 1.37 04-Dec-2007 miod

Improve setregs() so that it performs the equivalent of the first two
instructions of the new binary, which allows them to be skipped unconditionaly.


# 1.36 02-Dec-2007 miod

When setting up the vectors page, do not put a nop as the first instruction
if the processor is a 88110, since only the 88100 suffers from the ``will
fetch one instruction too far'' bug.


# 1.35 02-Dec-2007 miod

Provide a specific rw_cas() function for MP kernels, simulating a really
atomic compare-and-swap operation.


# 1.34 22-Nov-2007 miod

Move the cmmu lock to 88200-specific code. 88110 MP code will use ipis
and will not require such a lock.


# 1.33 20-Nov-2007 miod

Fix setregs() on 88110, so that binaries do not skip their first instruction.
Makes binaries beyond init(8) running on MVME197, to some extent.


# 1.32 17-Nov-2007 miod

Replace many ``unsigned'' variables with ``unsigned int'', ``u_int'' or other
appropriate types. No functional change.


# 1.31 15-Nov-2007 miod

Check for curcpu()->ci_softintr being nonzero before invoking dosoftint(),
in the common case, this saves us two potentially expensive setipl() calls.


# 1.30 15-Nov-2007 miod

Resolve the struct trapframe tf_mode/tf_flags duality by getting rid of
the tf_mode name. This field only contains flags used internally by the
exception processing code.


# 1.29 14-Nov-2007 miod

Merge the ci_alive and ci_primary boolean values of struct cpu_info into
a single ci_flags bitfield.

Also, set_cpu_number() will no longer set CIF_PRIMARY on the primary processor,
it's up to the initialization code to do this.


# 1.28 09-Nov-2007 miod

On MULTIPROCESSOR kernels, don't forget to grab the kernel lock when
processing soft interrupts; and there was much rejoicing.


# 1.27 06-Nov-2007 miod

Keep a pending software interrupts mask per processor, instead of having it
global; and only schedule software interrupts on the currently running cpu.


# 1.26 06-Nov-2007 miod

Remove the now unused idle_u, and call the secondary processors startup
stack a startup stack.


# 1.25 29-Oct-2007 miod

When a secondary cpu gets its interrupt pin stuck, be sure to savectx
and put the process it was running back on the run queue (unless this was
the idle proc).


# 1.24 28-Oct-2007 miod

Do not flag a processor as ``alive'' until it really is ready to accept IPIs.


# 1.23 24-Oct-2007 miod

Remove sir_lock, superseded by the atomic bit operations.


# 1.22 10-Oct-2007 art

Make context switching much more MI:
- Move the functionality of choosing a process from cpu_switch into
a much simpler function: cpu_switchto. Instead of having the locore
code walk the run queues, let the MI code choose the process we
want to run and only implement the context switching itself in MD
code.
- Let MD context switching run without worrying about spls or locks.
- Instead of having the idle loop implemented with special contexts
in MD code, implement one idle proc for each cpu. make the idle
loop MI with MD hooks.
- Change the proc lists from the old style vax queues to TAILQs.
- Change the sleep queue from vax queues to TAILQs. This makes
wakeup() go from O(n^2) to O(n)

there will be some MD fallout, but it will be fixed shortly.
There's also a few cleanups to be done after this.

deraadt@, kettenis@ ok


Revision tags: OPENBSD_4_2_BASE
# 1.21 29-May-2007 miod

Use atomic operations to operate on netisr, instead of clearing it at splhigh.
This changes nothing on legacy architectures, but is a bit faster (and simpler)
on the interesting ones.


# 1.20 19-May-2007 miod

Send an IPI in signotify() if the process runs on a different processor,
similar to the fix which went into i386 and amd64 a few weeks ago.


# 1.19 18-May-2007 miod

In spl0(), really process soft interrupts at IPL_SOFT instead of whatever
level we were at.


# 1.18 18-Apr-2007 miod

Use atomic operations to change the pending software interrupt mask.


Revision tags: OPENBSD_4_1_BASE
# 1.17 22-Nov-2006 miod

The softintr lock needs to be an __mp_lock, not a __cpu_simple_lock.


Revision tags: OPENBSD_4_0_BASE
# 1.16 08-May-2006 miod

Replace gazillions of badvaddr() or badwordaddr() calls with badaddr() calls.
With a few prototype declarations shuffling, this finally allows
<machine/locore.h> to die.


# 1.15 08-May-2006 miod

Clean the internal m88k trap type codes; while there, simplify and
factorize the build of the VBR page betweem luna88k and mvme88k.

Tested by aoyama@ and I.


# 1.14 15-Apr-2006 miod

nmihand() is mvme88k only, move it out of m88k common area.


Revision tags: OPENBSD_3_9_BASE
# 1.13 11-Dec-2005 miod

Factorize soft interrupt code between luna88k and mvme88k.


# 1.12 04-Dec-2005 miod

Oops, simplelock leftover.


# 1.11 03-Dec-2005 miod

Replace simplelocks with __cpu_simple_locks for cmmu and pmap locking,
for the MULTIPROCESSOR case.


# 1.10 03-Dec-2005 miod

Switch m88k ports to __HAVE_CPUINFO. Current cpu pointer is held in SR0
on all running processors.
Tested aoyama@ and I


# 1.9 28-Nov-2005 miod

Maintain an interrupt depth counter for CLKF_INTR to be correct.
Tested aoyama@ martin@ and I.


# 1.8 06-Nov-2005 miod

Invoke regdump() on abort if compiled without DDB support.


# 1.7 13-Oct-2005 miod

Merge <machine/cpu_number.h> into <machine/cpu.h>, preparing for intrusive
changes.


# 1.6 12-Oct-2005 miod

Remove commented out dead wrong FPU handling code in setregs().


# 1.5 12-Oct-2005 miod

Stop mapping the u area at fixed UADDR in addition to its actual va.
While there, attempt to clean and comment stack usage in the kernel.
No functional change.

From the m88k SMP tree; help&test martin@


# 1.4 25-Sep-2005 miod

Change the size parameter of cmmu_flush_tlb() from bytes to pages. This makes
things easier for the callers, and allows us to inline the "fewer than 4 pages"
situation for speed.


Revision tags: OPENBSD_3_8_BASE
# 1.3 30-Apr-2005 miod

Use [XNF]IP_ADDR constants rather than their numeric values.


Revision tags: OPENBSD_3_7_BASE
# 1.2 30-Sep-2004 miod

Introduce sparc-like CPU_ISFOO macros, to short-circuit evaluations when
compiling for one flavour only.

This makes code slightly smaller on all m88k-based platforms (my roughly
1KB), and saves more than meets the eye on luna88k, which is m88100-based.


# 1.1 30-Sep-2004 miod

More code shuffling, probably the final touch.


# 1.72 06-Jan-2023 miod

Remove copystr(9), unless used internally by copy{in,out}str.


# 1.71 30-Oct-2022 guenther

Simplfity setregs() by passing it the ps_strings and switching
sys_execve() to return EJUSTRETURN.

setregs() is the MD routine used by sys_execve() to set up the
thread's trapframe and PCB such that, on 'return' to userspace, it
has the register values defined by the ABI and otherwise zero. It
had to set the syscall retval[] values previously because the normal
syscall return path overwrites a couple registers with the retval[]
values. By instead returning EJUSTRETURN that and some complexity
with program-counter handling on m88k and sparc64 goes away.

Also, give setregs() add a 'struct ps_strings *arginfo' argument
so powerpc, powerpc64, and sh can directly get argc/argv/envp
values for registers instead of copyin()ing the one in userspace.

Improvements from miod@ and millert@
Testing assistance miod@, kettenis@, and aoyama@
ok miod@ kettenis@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.70 15-Oct-2019 mpi

Reduce the number of places where `p_priority' and `p_stat' are set.

This refactoring will help future scheduler locking, in particular to
shrink the SCHED_LOCK().

No intended behavior change.

ok visa@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.69 22-Oct-2018 krw

More "explicitely" -> "explicitly" in various comments.

ok guenther@ tb@ deraadt@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.68 29-May-2017 mpi

Kill SPINLOCK_SPIN_HOOK, use CPU_BUSY_CYCLE() instead.

ok visa@, kettenis@


Revision tags: OPENBSD_6_1_BASE
# 1.67 19-Mar-2017 miod

Put the address of the per-cpu clock and interrupt registers into the cpu_info
struct, rather than fetching them from arrays every time they are needed.

ok aoyama@


# 1.66 09-Oct-2016 guenther

Tweak the special handling of pid 1 in setregs()...and document that
while it's not 100% correct, it's okay

tested by aoyama@


# 1.65 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


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

no md code wants lockmgr locks, so no md code needs to include sys/lock.h

with and ok miod@


Revision tags: OPENBSD_5_6_BASE
# 1.63 15-Jul-2014 miod

Implement rw_cas() with atomic_cas_ulong() now, instead of a dedicated
routine.


# 1.62 09-Jun-2014 miod

Remove redundant regdump() output.


# 1.61 31-May-2014 miod

In regdump(), print DAE registers when they are valid, regardless of the
exception type.


# 1.60 08-May-2014 miod

Format string fixes for m88k; remove -Wno-format from the m88k kernels.


# 1.59 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.58 07-Oct-2013 miod

Put the kernel VBR page at the beginning of the kernel text, as done on
mvme88k, to be able to unmap the page at address zero in the kernel, and have
the vbr page read-only after being initialized.


Revision tags: OPENBSD_5_4_BASE
# 1.57 17-Jul-2013 miod

Fix setregs() to match prototype. Exposed by recent _types.h change, found the
hard way by aoyama@


# 1.56 15-May-2013 miod

Initialize a teeny few more globals to reasonable values to allow for printf()
to work as soon as cn_tab is initialized. Allows us to correctly printf or
panic early on unrecognized systems. This used to be the case but got lost a
long time ago.


Revision tags: OPENBSD_5_3_BASE
# 1.55 17-Feb-2013 miod

Constify struct cmmu.


# 1.54 26-Jan-2013 miod

Make sure new processes get a clean FPU configuration upon startup, by
resetting the appropriate register in setregs(). Similar in spirit to what
m68k does (restoring a null frame), and necessary since m88k doesn't do lazy
fpu switching.


# 1.53 05-Jan-2013 miod

Switch m88k ports to ELF.


Revision tags: OPENBSD_5_2_BASE
# 1.52 23-Mar-2012 guenther

Make rusage totals, itimers, and profile settings per-process instead
of per-rthread. Handling of per-thread tick and runtime counters
inspired by how FreeBSD does it.

ok kettenis@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.51 23-Dec-2010 miod

The exception vector page on m88k systems has always been the same page as
the one used by the firmware, which (at least on mvme88k) is at address zero.

This is unfortunate, since this means that NULL pointer dereferences in the
kernel are not caught, and writes cause havoc.

This behaviour was necessary to be able to use the PROM system call interface
during early bootstrap, without having to disassemble the VBR page and
update branches - which use pc-relative displacement - if we were to use
a different VBR address.

On mvme88k, change this and actually set up two VBR pages: one, over the PROM
page (except for the system call vectors), and another one in the kernel
image (which will be mapped read-only). We'll run with the PROM page until
the end of autoconf, and then switch to the kernel one, and unmap all the
PROM below it.

As a bonus, the final kernel page can use optimized data access fault
handlers, which do not have to check for faults caused by badaddr(), since
badaddr() is only used during device probe on buses which do not support
hotplug.

There are a few infrastructure collateral damage on aviion and luna88k, but
these ports do not change their behaviour yet.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.50 19-Apr-2009 miod

Rename max_cpus to ncpusfound and compute it regardless of option
MULTIPROCESSOR.


# 1.49 15-Mar-2009 miod

Generic softinterrupt support for m88k based platforms, adapted from arm
with different locking mechanism. 88110 soft ipi are replaced with an
ipi callback which is checked upon return from exception (it can not be kept
as a softintr, as the generic softinterrupt code doesn't have per-cpu
pending softintr queues).


# 1.48 04-Mar-2009 miod

Introduce atomic_clear_int() as an MD atomic operation to perform atomic
exchange with zero; use it in the soft interrupt code to make it simpler
and faster.


# 1.47 04-Mar-2009 miod

Fix stupid logic bug in rw_cas_m88k(), makes NFS much happier on SMP kernels.


Revision tags: OPENBSD_4_5_BASE
# 1.46 20-Feb-2009 miod

atomic_{set,clear}bits_int were not safe enough on 88110 systems, as they
can be interrupted by NMI; move the SMP version of these routines from
inlines to a separate file (kernel text shrinks 20KB...).

Since the implementation for 88110 becomes really hairy, the pre-main() code
is responsible for copying the appropriate code over for kernels configured
for both 88100 and 88110 cpus, to avoid having to choose the atomicity
strategy at runtime. Hairy, I said.

This gets GENERIC.MP run much further on 197DP. Not enough to reach multiuser
mode, but boots up to starting sshd and then panics.


# 1.45 18-Feb-2009 miod

typo


# 1.44 16-Feb-2009 miod

More 88110 SMP work. Contains, horribly entangled:
- dma_cachectl() split into a ``local cpu only'' and ``all cpus'', and an ipi
to broadcast ``local dma_cachectl'' is added.
- cpu_info fields are rearranged, to have the 88100-specific information
and the 88110-specific information overlap, and has many more 88110
ugly things.
- more ipi handling in the 197-specific area. Since it is not possible to
have the second processor receive any hardware interrupt (selection
is done on a level basis via ISEL, and we definitely do not want the
main cpu to lose interrupts), the best we can do is to inflict ourselves
a soft interrupt for late ipi processing. It gets used for softclock and
hardclock on the secondary processor, but since the soft interrupt
dispatcher doesn't have an exception frame, we have to remember parts
of it to build a fake clockframe from the soft ipi handler (ugly but
works).

This now lets GENERIC.MP run a few userland binaries before bugs trigger.


# 1.43 21-Dec-2008 miod

Proper cpu_unidle() function for MP kernels. ok art@ long ago


# 1.42 27-Nov-2008 miod

On 88100 cpus, make sure userland processes start with SNIP and SFIP valid
(i.e. with the valid bit set in them). Found the hard way by Anders Gavare
trying his latest gxemul, proves the hardware is more permitting than one
would expect it to be...


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.41 26-Dec-2007 miod

Remove the last debug bit from the PSR on 88110: do not force memory accesses
instructions to be serialized (this defeats the purpose of having a superscalar
processor, and accesses to volatile variables are done with explicit memory
barriers anyway).

This brings a HUGE speedup: openssl speed -elapsed shows AES is 90% faster,
blowfish is 75% faster, and sha1 is 50% faster. Not so bad!

However, doing this increases the pressure on the processor bus, so it is
necessary to increase the processor bus timeout on 40MHz boards again (to 256
usec). ``black cat'' 50MHz boards seem to be unaffected, so they remain at
64 usec.


# 1.40 15-Dec-2007 miod

Move the cmmu lock back from 8820x-specific code to global, and use it on
MVME197DP to serialize 88410 operations.


# 1.39 09-Dec-2007 miod

I honestly do not remember what 88110 errata convinced me to disable
out-of-order (superscalar) execution on these processors.

Since OoO brings a nice 50% to 250% speedup (as shown by ``openssl speed''),
it is definitely worth enabling.


# 1.38 05-Dec-2007 miod

xmem can not be used as a reliable atomic operation, they way we do them,
so do the naive operations with interrupts disabled, and an interlock held
if MULTIPROCESSOR.


# 1.37 04-Dec-2007 miod

Improve setregs() so that it performs the equivalent of the first two
instructions of the new binary, which allows them to be skipped unconditionaly.


# 1.36 02-Dec-2007 miod

When setting up the vectors page, do not put a nop as the first instruction
if the processor is a 88110, since only the 88100 suffers from the ``will
fetch one instruction too far'' bug.


# 1.35 02-Dec-2007 miod

Provide a specific rw_cas() function for MP kernels, simulating a really
atomic compare-and-swap operation.


# 1.34 22-Nov-2007 miod

Move the cmmu lock to 88200-specific code. 88110 MP code will use ipis
and will not require such a lock.


# 1.33 20-Nov-2007 miod

Fix setregs() on 88110, so that binaries do not skip their first instruction.
Makes binaries beyond init(8) running on MVME197, to some extent.


# 1.32 17-Nov-2007 miod

Replace many ``unsigned'' variables with ``unsigned int'', ``u_int'' or other
appropriate types. No functional change.


# 1.31 15-Nov-2007 miod

Check for curcpu()->ci_softintr being nonzero before invoking dosoftint(),
in the common case, this saves us two potentially expensive setipl() calls.


# 1.30 15-Nov-2007 miod

Resolve the struct trapframe tf_mode/tf_flags duality by getting rid of
the tf_mode name. This field only contains flags used internally by the
exception processing code.


# 1.29 14-Nov-2007 miod

Merge the ci_alive and ci_primary boolean values of struct cpu_info into
a single ci_flags bitfield.

Also, set_cpu_number() will no longer set CIF_PRIMARY on the primary processor,
it's up to the initialization code to do this.


# 1.28 09-Nov-2007 miod

On MULTIPROCESSOR kernels, don't forget to grab the kernel lock when
processing soft interrupts; and there was much rejoicing.


# 1.27 06-Nov-2007 miod

Keep a pending software interrupts mask per processor, instead of having it
global; and only schedule software interrupts on the currently running cpu.


# 1.26 06-Nov-2007 miod

Remove the now unused idle_u, and call the secondary processors startup
stack a startup stack.


# 1.25 29-Oct-2007 miod

When a secondary cpu gets its interrupt pin stuck, be sure to savectx
and put the process it was running back on the run queue (unless this was
the idle proc).


# 1.24 28-Oct-2007 miod

Do not flag a processor as ``alive'' until it really is ready to accept IPIs.


# 1.23 24-Oct-2007 miod

Remove sir_lock, superseded by the atomic bit operations.


# 1.22 10-Oct-2007 art

Make context switching much more MI:
- Move the functionality of choosing a process from cpu_switch into
a much simpler function: cpu_switchto. Instead of having the locore
code walk the run queues, let the MI code choose the process we
want to run and only implement the context switching itself in MD
code.
- Let MD context switching run without worrying about spls or locks.
- Instead of having the idle loop implemented with special contexts
in MD code, implement one idle proc for each cpu. make the idle
loop MI with MD hooks.
- Change the proc lists from the old style vax queues to TAILQs.
- Change the sleep queue from vax queues to TAILQs. This makes
wakeup() go from O(n^2) to O(n)

there will be some MD fallout, but it will be fixed shortly.
There's also a few cleanups to be done after this.

deraadt@, kettenis@ ok


Revision tags: OPENBSD_4_2_BASE
# 1.21 29-May-2007 miod

Use atomic operations to operate on netisr, instead of clearing it at splhigh.
This changes nothing on legacy architectures, but is a bit faster (and simpler)
on the interesting ones.


# 1.20 19-May-2007 miod

Send an IPI in signotify() if the process runs on a different processor,
similar to the fix which went into i386 and amd64 a few weeks ago.


# 1.19 18-May-2007 miod

In spl0(), really process soft interrupts at IPL_SOFT instead of whatever
level we were at.


# 1.18 18-Apr-2007 miod

Use atomic operations to change the pending software interrupt mask.


Revision tags: OPENBSD_4_1_BASE
# 1.17 22-Nov-2006 miod

The softintr lock needs to be an __mp_lock, not a __cpu_simple_lock.


Revision tags: OPENBSD_4_0_BASE
# 1.16 08-May-2006 miod

Replace gazillions of badvaddr() or badwordaddr() calls with badaddr() calls.
With a few prototype declarations shuffling, this finally allows
<machine/locore.h> to die.


# 1.15 08-May-2006 miod

Clean the internal m88k trap type codes; while there, simplify and
factorize the build of the VBR page betweem luna88k and mvme88k.

Tested by aoyama@ and I.


# 1.14 15-Apr-2006 miod

nmihand() is mvme88k only, move it out of m88k common area.


Revision tags: OPENBSD_3_9_BASE
# 1.13 11-Dec-2005 miod

Factorize soft interrupt code between luna88k and mvme88k.


# 1.12 04-Dec-2005 miod

Oops, simplelock leftover.


# 1.11 03-Dec-2005 miod

Replace simplelocks with __cpu_simple_locks for cmmu and pmap locking,
for the MULTIPROCESSOR case.


# 1.10 03-Dec-2005 miod

Switch m88k ports to __HAVE_CPUINFO. Current cpu pointer is held in SR0
on all running processors.
Tested aoyama@ and I


# 1.9 28-Nov-2005 miod

Maintain an interrupt depth counter for CLKF_INTR to be correct.
Tested aoyama@ martin@ and I.


# 1.8 06-Nov-2005 miod

Invoke regdump() on abort if compiled without DDB support.


# 1.7 13-Oct-2005 miod

Merge <machine/cpu_number.h> into <machine/cpu.h>, preparing for intrusive
changes.


# 1.6 12-Oct-2005 miod

Remove commented out dead wrong FPU handling code in setregs().


# 1.5 12-Oct-2005 miod

Stop mapping the u area at fixed UADDR in addition to its actual va.
While there, attempt to clean and comment stack usage in the kernel.
No functional change.

From the m88k SMP tree; help&test martin@


# 1.4 25-Sep-2005 miod

Change the size parameter of cmmu_flush_tlb() from bytes to pages. This makes
things easier for the callers, and allows us to inline the "fewer than 4 pages"
situation for speed.


Revision tags: OPENBSD_3_8_BASE
# 1.3 30-Apr-2005 miod

Use [XNF]IP_ADDR constants rather than their numeric values.


Revision tags: OPENBSD_3_7_BASE
# 1.2 30-Sep-2004 miod

Introduce sparc-like CPU_ISFOO macros, to short-circuit evaluations when
compiling for one flavour only.

This makes code slightly smaller on all m88k-based platforms (my roughly
1KB), and saves more than meets the eye on luna88k, which is m88100-based.


# 1.1 30-Sep-2004 miod

More code shuffling, probably the final touch.


# 1.71 30-Oct-2022 guenther

Simplfity setregs() by passing it the ps_strings and switching
sys_execve() to return EJUSTRETURN.

setregs() is the MD routine used by sys_execve() to set up the
thread's trapframe and PCB such that, on 'return' to userspace, it
has the register values defined by the ABI and otherwise zero. It
had to set the syscall retval[] values previously because the normal
syscall return path overwrites a couple registers with the retval[]
values. By instead returning EJUSTRETURN that and some complexity
with program-counter handling on m88k and sparc64 goes away.

Also, give setregs() add a 'struct ps_strings *arginfo' argument
so powerpc, powerpc64, and sh can directly get argc/argv/envp
values for registers instead of copyin()ing the one in userspace.

Improvements from miod@ and millert@
Testing assistance miod@, kettenis@, and aoyama@
ok miod@ kettenis@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.70 15-Oct-2019 mpi

Reduce the number of places where `p_priority' and `p_stat' are set.

This refactoring will help future scheduler locking, in particular to
shrink the SCHED_LOCK().

No intended behavior change.

ok visa@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.69 22-Oct-2018 krw

More "explicitely" -> "explicitly" in various comments.

ok guenther@ tb@ deraadt@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.68 29-May-2017 mpi

Kill SPINLOCK_SPIN_HOOK, use CPU_BUSY_CYCLE() instead.

ok visa@, kettenis@


Revision tags: OPENBSD_6_1_BASE
# 1.67 19-Mar-2017 miod

Put the address of the per-cpu clock and interrupt registers into the cpu_info
struct, rather than fetching them from arrays every time they are needed.

ok aoyama@


# 1.66 09-Oct-2016 guenther

Tweak the special handling of pid 1 in setregs()...and document that
while it's not 100% correct, it's okay

tested by aoyama@


# 1.65 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


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

no md code wants lockmgr locks, so no md code needs to include sys/lock.h

with and ok miod@


Revision tags: OPENBSD_5_6_BASE
# 1.63 15-Jul-2014 miod

Implement rw_cas() with atomic_cas_ulong() now, instead of a dedicated
routine.


# 1.62 09-Jun-2014 miod

Remove redundant regdump() output.


# 1.61 31-May-2014 miod

In regdump(), print DAE registers when they are valid, regardless of the
exception type.


# 1.60 08-May-2014 miod

Format string fixes for m88k; remove -Wno-format from the m88k kernels.


# 1.59 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.58 07-Oct-2013 miod

Put the kernel VBR page at the beginning of the kernel text, as done on
mvme88k, to be able to unmap the page at address zero in the kernel, and have
the vbr page read-only after being initialized.


Revision tags: OPENBSD_5_4_BASE
# 1.57 17-Jul-2013 miod

Fix setregs() to match prototype. Exposed by recent _types.h change, found the
hard way by aoyama@


# 1.56 15-May-2013 miod

Initialize a teeny few more globals to reasonable values to allow for printf()
to work as soon as cn_tab is initialized. Allows us to correctly printf or
panic early on unrecognized systems. This used to be the case but got lost a
long time ago.


Revision tags: OPENBSD_5_3_BASE
# 1.55 17-Feb-2013 miod

Constify struct cmmu.


# 1.54 26-Jan-2013 miod

Make sure new processes get a clean FPU configuration upon startup, by
resetting the appropriate register in setregs(). Similar in spirit to what
m68k does (restoring a null frame), and necessary since m88k doesn't do lazy
fpu switching.


# 1.53 05-Jan-2013 miod

Switch m88k ports to ELF.


Revision tags: OPENBSD_5_2_BASE
# 1.52 23-Mar-2012 guenther

Make rusage totals, itimers, and profile settings per-process instead
of per-rthread. Handling of per-thread tick and runtime counters
inspired by how FreeBSD does it.

ok kettenis@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.51 23-Dec-2010 miod

The exception vector page on m88k systems has always been the same page as
the one used by the firmware, which (at least on mvme88k) is at address zero.

This is unfortunate, since this means that NULL pointer dereferences in the
kernel are not caught, and writes cause havoc.

This behaviour was necessary to be able to use the PROM system call interface
during early bootstrap, without having to disassemble the VBR page and
update branches - which use pc-relative displacement - if we were to use
a different VBR address.

On mvme88k, change this and actually set up two VBR pages: one, over the PROM
page (except for the system call vectors), and another one in the kernel
image (which will be mapped read-only). We'll run with the PROM page until
the end of autoconf, and then switch to the kernel one, and unmap all the
PROM below it.

As a bonus, the final kernel page can use optimized data access fault
handlers, which do not have to check for faults caused by badaddr(), since
badaddr() is only used during device probe on buses which do not support
hotplug.

There are a few infrastructure collateral damage on aviion and luna88k, but
these ports do not change their behaviour yet.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.50 19-Apr-2009 miod

Rename max_cpus to ncpusfound and compute it regardless of option
MULTIPROCESSOR.


# 1.49 15-Mar-2009 miod

Generic softinterrupt support for m88k based platforms, adapted from arm
with different locking mechanism. 88110 soft ipi are replaced with an
ipi callback which is checked upon return from exception (it can not be kept
as a softintr, as the generic softinterrupt code doesn't have per-cpu
pending softintr queues).


# 1.48 04-Mar-2009 miod

Introduce atomic_clear_int() as an MD atomic operation to perform atomic
exchange with zero; use it in the soft interrupt code to make it simpler
and faster.


# 1.47 04-Mar-2009 miod

Fix stupid logic bug in rw_cas_m88k(), makes NFS much happier on SMP kernels.


Revision tags: OPENBSD_4_5_BASE
# 1.46 20-Feb-2009 miod

atomic_{set,clear}bits_int were not safe enough on 88110 systems, as they
can be interrupted by NMI; move the SMP version of these routines from
inlines to a separate file (kernel text shrinks 20KB...).

Since the implementation for 88110 becomes really hairy, the pre-main() code
is responsible for copying the appropriate code over for kernels configured
for both 88100 and 88110 cpus, to avoid having to choose the atomicity
strategy at runtime. Hairy, I said.

This gets GENERIC.MP run much further on 197DP. Not enough to reach multiuser
mode, but boots up to starting sshd and then panics.


# 1.45 18-Feb-2009 miod

typo


# 1.44 16-Feb-2009 miod

More 88110 SMP work. Contains, horribly entangled:
- dma_cachectl() split into a ``local cpu only'' and ``all cpus'', and an ipi
to broadcast ``local dma_cachectl'' is added.
- cpu_info fields are rearranged, to have the 88100-specific information
and the 88110-specific information overlap, and has many more 88110
ugly things.
- more ipi handling in the 197-specific area. Since it is not possible to
have the second processor receive any hardware interrupt (selection
is done on a level basis via ISEL, and we definitely do not want the
main cpu to lose interrupts), the best we can do is to inflict ourselves
a soft interrupt for late ipi processing. It gets used for softclock and
hardclock on the secondary processor, but since the soft interrupt
dispatcher doesn't have an exception frame, we have to remember parts
of it to build a fake clockframe from the soft ipi handler (ugly but
works).

This now lets GENERIC.MP run a few userland binaries before bugs trigger.


# 1.43 21-Dec-2008 miod

Proper cpu_unidle() function for MP kernels. ok art@ long ago


# 1.42 27-Nov-2008 miod

On 88100 cpus, make sure userland processes start with SNIP and SFIP valid
(i.e. with the valid bit set in them). Found the hard way by Anders Gavare
trying his latest gxemul, proves the hardware is more permitting than one
would expect it to be...


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.41 26-Dec-2007 miod

Remove the last debug bit from the PSR on 88110: do not force memory accesses
instructions to be serialized (this defeats the purpose of having a superscalar
processor, and accesses to volatile variables are done with explicit memory
barriers anyway).

This brings a HUGE speedup: openssl speed -elapsed shows AES is 90% faster,
blowfish is 75% faster, and sha1 is 50% faster. Not so bad!

However, doing this increases the pressure on the processor bus, so it is
necessary to increase the processor bus timeout on 40MHz boards again (to 256
usec). ``black cat'' 50MHz boards seem to be unaffected, so they remain at
64 usec.


# 1.40 15-Dec-2007 miod

Move the cmmu lock back from 8820x-specific code to global, and use it on
MVME197DP to serialize 88410 operations.


# 1.39 09-Dec-2007 miod

I honestly do not remember what 88110 errata convinced me to disable
out-of-order (superscalar) execution on these processors.

Since OoO brings a nice 50% to 250% speedup (as shown by ``openssl speed''),
it is definitely worth enabling.


# 1.38 05-Dec-2007 miod

xmem can not be used as a reliable atomic operation, they way we do them,
so do the naive operations with interrupts disabled, and an interlock held
if MULTIPROCESSOR.


# 1.37 04-Dec-2007 miod

Improve setregs() so that it performs the equivalent of the first two
instructions of the new binary, which allows them to be skipped unconditionaly.


# 1.36 02-Dec-2007 miod

When setting up the vectors page, do not put a nop as the first instruction
if the processor is a 88110, since only the 88100 suffers from the ``will
fetch one instruction too far'' bug.


# 1.35 02-Dec-2007 miod

Provide a specific rw_cas() function for MP kernels, simulating a really
atomic compare-and-swap operation.


# 1.34 22-Nov-2007 miod

Move the cmmu lock to 88200-specific code. 88110 MP code will use ipis
and will not require such a lock.


# 1.33 20-Nov-2007 miod

Fix setregs() on 88110, so that binaries do not skip their first instruction.
Makes binaries beyond init(8) running on MVME197, to some extent.


# 1.32 17-Nov-2007 miod

Replace many ``unsigned'' variables with ``unsigned int'', ``u_int'' or other
appropriate types. No functional change.


# 1.31 15-Nov-2007 miod

Check for curcpu()->ci_softintr being nonzero before invoking dosoftint(),
in the common case, this saves us two potentially expensive setipl() calls.


# 1.30 15-Nov-2007 miod

Resolve the struct trapframe tf_mode/tf_flags duality by getting rid of
the tf_mode name. This field only contains flags used internally by the
exception processing code.


# 1.29 14-Nov-2007 miod

Merge the ci_alive and ci_primary boolean values of struct cpu_info into
a single ci_flags bitfield.

Also, set_cpu_number() will no longer set CIF_PRIMARY on the primary processor,
it's up to the initialization code to do this.


# 1.28 09-Nov-2007 miod

On MULTIPROCESSOR kernels, don't forget to grab the kernel lock when
processing soft interrupts; and there was much rejoicing.


# 1.27 06-Nov-2007 miod

Keep a pending software interrupts mask per processor, instead of having it
global; and only schedule software interrupts on the currently running cpu.


# 1.26 06-Nov-2007 miod

Remove the now unused idle_u, and call the secondary processors startup
stack a startup stack.


# 1.25 29-Oct-2007 miod

When a secondary cpu gets its interrupt pin stuck, be sure to savectx
and put the process it was running back on the run queue (unless this was
the idle proc).


# 1.24 28-Oct-2007 miod

Do not flag a processor as ``alive'' until it really is ready to accept IPIs.


# 1.23 24-Oct-2007 miod

Remove sir_lock, superseded by the atomic bit operations.


# 1.22 10-Oct-2007 art

Make context switching much more MI:
- Move the functionality of choosing a process from cpu_switch into
a much simpler function: cpu_switchto. Instead of having the locore
code walk the run queues, let the MI code choose the process we
want to run and only implement the context switching itself in MD
code.
- Let MD context switching run without worrying about spls or locks.
- Instead of having the idle loop implemented with special contexts
in MD code, implement one idle proc for each cpu. make the idle
loop MI with MD hooks.
- Change the proc lists from the old style vax queues to TAILQs.
- Change the sleep queue from vax queues to TAILQs. This makes
wakeup() go from O(n^2) to O(n)

there will be some MD fallout, but it will be fixed shortly.
There's also a few cleanups to be done after this.

deraadt@, kettenis@ ok


Revision tags: OPENBSD_4_2_BASE
# 1.21 29-May-2007 miod

Use atomic operations to operate on netisr, instead of clearing it at splhigh.
This changes nothing on legacy architectures, but is a bit faster (and simpler)
on the interesting ones.


# 1.20 19-May-2007 miod

Send an IPI in signotify() if the process runs on a different processor,
similar to the fix which went into i386 and amd64 a few weeks ago.


# 1.19 18-May-2007 miod

In spl0(), really process soft interrupts at IPL_SOFT instead of whatever
level we were at.


# 1.18 18-Apr-2007 miod

Use atomic operations to change the pending software interrupt mask.


Revision tags: OPENBSD_4_1_BASE
# 1.17 22-Nov-2006 miod

The softintr lock needs to be an __mp_lock, not a __cpu_simple_lock.


Revision tags: OPENBSD_4_0_BASE
# 1.16 08-May-2006 miod

Replace gazillions of badvaddr() or badwordaddr() calls with badaddr() calls.
With a few prototype declarations shuffling, this finally allows
<machine/locore.h> to die.


# 1.15 08-May-2006 miod

Clean the internal m88k trap type codes; while there, simplify and
factorize the build of the VBR page betweem luna88k and mvme88k.

Tested by aoyama@ and I.


# 1.14 15-Apr-2006 miod

nmihand() is mvme88k only, move it out of m88k common area.


Revision tags: OPENBSD_3_9_BASE
# 1.13 11-Dec-2005 miod

Factorize soft interrupt code between luna88k and mvme88k.


# 1.12 04-Dec-2005 miod

Oops, simplelock leftover.


# 1.11 03-Dec-2005 miod

Replace simplelocks with __cpu_simple_locks for cmmu and pmap locking,
for the MULTIPROCESSOR case.


# 1.10 03-Dec-2005 miod

Switch m88k ports to __HAVE_CPUINFO. Current cpu pointer is held in SR0
on all running processors.
Tested aoyama@ and I


# 1.9 28-Nov-2005 miod

Maintain an interrupt depth counter for CLKF_INTR to be correct.
Tested aoyama@ martin@ and I.


# 1.8 06-Nov-2005 miod

Invoke regdump() on abort if compiled without DDB support.


# 1.7 13-Oct-2005 miod

Merge <machine/cpu_number.h> into <machine/cpu.h>, preparing for intrusive
changes.


# 1.6 12-Oct-2005 miod

Remove commented out dead wrong FPU handling code in setregs().


# 1.5 12-Oct-2005 miod

Stop mapping the u area at fixed UADDR in addition to its actual va.
While there, attempt to clean and comment stack usage in the kernel.
No functional change.

From the m88k SMP tree; help&test martin@


# 1.4 25-Sep-2005 miod

Change the size parameter of cmmu_flush_tlb() from bytes to pages. This makes
things easier for the callers, and allows us to inline the "fewer than 4 pages"
situation for speed.


Revision tags: OPENBSD_3_8_BASE
# 1.3 30-Apr-2005 miod

Use [XNF]IP_ADDR constants rather than their numeric values.


Revision tags: OPENBSD_3_7_BASE
# 1.2 30-Sep-2004 miod

Introduce sparc-like CPU_ISFOO macros, to short-circuit evaluations when
compiling for one flavour only.

This makes code slightly smaller on all m88k-based platforms (my roughly
1KB), and saves more than meets the eye on luna88k, which is m88100-based.


# 1.1 30-Sep-2004 miod

More code shuffling, probably the final touch.


# 1.70 15-Oct-2019 mpi

Reduce the number of places where `p_priority' and `p_stat' are set.

This refactoring will help future scheduler locking, in particular to
shrink the SCHED_LOCK().

No intended behavior change.

ok visa@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.69 22-Oct-2018 krw

More "explicitely" -> "explicitly" in various comments.

ok guenther@ tb@ deraadt@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.68 29-May-2017 mpi

Kill SPINLOCK_SPIN_HOOK, use CPU_BUSY_CYCLE() instead.

ok visa@, kettenis@


Revision tags: OPENBSD_6_1_BASE
# 1.67 19-Mar-2017 miod

Put the address of the per-cpu clock and interrupt registers into the cpu_info
struct, rather than fetching them from arrays every time they are needed.

ok aoyama@


# 1.66 09-Oct-2016 guenther

Tweak the special handling of pid 1 in setregs()...and document that
while it's not 100% correct, it's okay

tested by aoyama@


# 1.65 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


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

no md code wants lockmgr locks, so no md code needs to include sys/lock.h

with and ok miod@


Revision tags: OPENBSD_5_6_BASE
# 1.63 15-Jul-2014 miod

Implement rw_cas() with atomic_cas_ulong() now, instead of a dedicated
routine.


# 1.62 09-Jun-2014 miod

Remove redundant regdump() output.


# 1.61 31-May-2014 miod

In regdump(), print DAE registers when they are valid, regardless of the
exception type.


# 1.60 08-May-2014 miod

Format string fixes for m88k; remove -Wno-format from the m88k kernels.


# 1.59 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.58 07-Oct-2013 miod

Put the kernel VBR page at the beginning of the kernel text, as done on
mvme88k, to be able to unmap the page at address zero in the kernel, and have
the vbr page read-only after being initialized.


Revision tags: OPENBSD_5_4_BASE
# 1.57 17-Jul-2013 miod

Fix setregs() to match prototype. Exposed by recent _types.h change, found the
hard way by aoyama@


# 1.56 15-May-2013 miod

Initialize a teeny few more globals to reasonable values to allow for printf()
to work as soon as cn_tab is initialized. Allows us to correctly printf or
panic early on unrecognized systems. This used to be the case but got lost a
long time ago.


Revision tags: OPENBSD_5_3_BASE
# 1.55 17-Feb-2013 miod

Constify struct cmmu.


# 1.54 26-Jan-2013 miod

Make sure new processes get a clean FPU configuration upon startup, by
resetting the appropriate register in setregs(). Similar in spirit to what
m68k does (restoring a null frame), and necessary since m88k doesn't do lazy
fpu switching.


# 1.53 05-Jan-2013 miod

Switch m88k ports to ELF.


Revision tags: OPENBSD_5_2_BASE
# 1.52 23-Mar-2012 guenther

Make rusage totals, itimers, and profile settings per-process instead
of per-rthread. Handling of per-thread tick and runtime counters
inspired by how FreeBSD does it.

ok kettenis@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.51 23-Dec-2010 miod

The exception vector page on m88k systems has always been the same page as
the one used by the firmware, which (at least on mvme88k) is at address zero.

This is unfortunate, since this means that NULL pointer dereferences in the
kernel are not caught, and writes cause havoc.

This behaviour was necessary to be able to use the PROM system call interface
during early bootstrap, without having to disassemble the VBR page and
update branches - which use pc-relative displacement - if we were to use
a different VBR address.

On mvme88k, change this and actually set up two VBR pages: one, over the PROM
page (except for the system call vectors), and another one in the kernel
image (which will be mapped read-only). We'll run with the PROM page until
the end of autoconf, and then switch to the kernel one, and unmap all the
PROM below it.

As a bonus, the final kernel page can use optimized data access fault
handlers, which do not have to check for faults caused by badaddr(), since
badaddr() is only used during device probe on buses which do not support
hotplug.

There are a few infrastructure collateral damage on aviion and luna88k, but
these ports do not change their behaviour yet.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.50 19-Apr-2009 miod

Rename max_cpus to ncpusfound and compute it regardless of option
MULTIPROCESSOR.


# 1.49 15-Mar-2009 miod

Generic softinterrupt support for m88k based platforms, adapted from arm
with different locking mechanism. 88110 soft ipi are replaced with an
ipi callback which is checked upon return from exception (it can not be kept
as a softintr, as the generic softinterrupt code doesn't have per-cpu
pending softintr queues).


# 1.48 04-Mar-2009 miod

Introduce atomic_clear_int() as an MD atomic operation to perform atomic
exchange with zero; use it in the soft interrupt code to make it simpler
and faster.


# 1.47 04-Mar-2009 miod

Fix stupid logic bug in rw_cas_m88k(), makes NFS much happier on SMP kernels.


Revision tags: OPENBSD_4_5_BASE
# 1.46 20-Feb-2009 miod

atomic_{set,clear}bits_int were not safe enough on 88110 systems, as they
can be interrupted by NMI; move the SMP version of these routines from
inlines to a separate file (kernel text shrinks 20KB...).

Since the implementation for 88110 becomes really hairy, the pre-main() code
is responsible for copying the appropriate code over for kernels configured
for both 88100 and 88110 cpus, to avoid having to choose the atomicity
strategy at runtime. Hairy, I said.

This gets GENERIC.MP run much further on 197DP. Not enough to reach multiuser
mode, but boots up to starting sshd and then panics.


# 1.45 18-Feb-2009 miod

typo


# 1.44 16-Feb-2009 miod

More 88110 SMP work. Contains, horribly entangled:
- dma_cachectl() split into a ``local cpu only'' and ``all cpus'', and an ipi
to broadcast ``local dma_cachectl'' is added.
- cpu_info fields are rearranged, to have the 88100-specific information
and the 88110-specific information overlap, and has many more 88110
ugly things.
- more ipi handling in the 197-specific area. Since it is not possible to
have the second processor receive any hardware interrupt (selection
is done on a level basis via ISEL, and we definitely do not want the
main cpu to lose interrupts), the best we can do is to inflict ourselves
a soft interrupt for late ipi processing. It gets used for softclock and
hardclock on the secondary processor, but since the soft interrupt
dispatcher doesn't have an exception frame, we have to remember parts
of it to build a fake clockframe from the soft ipi handler (ugly but
works).

This now lets GENERIC.MP run a few userland binaries before bugs trigger.


# 1.43 21-Dec-2008 miod

Proper cpu_unidle() function for MP kernels. ok art@ long ago


# 1.42 27-Nov-2008 miod

On 88100 cpus, make sure userland processes start with SNIP and SFIP valid
(i.e. with the valid bit set in them). Found the hard way by Anders Gavare
trying his latest gxemul, proves the hardware is more permitting than one
would expect it to be...


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.41 26-Dec-2007 miod

Remove the last debug bit from the PSR on 88110: do not force memory accesses
instructions to be serialized (this defeats the purpose of having a superscalar
processor, and accesses to volatile variables are done with explicit memory
barriers anyway).

This brings a HUGE speedup: openssl speed -elapsed shows AES is 90% faster,
blowfish is 75% faster, and sha1 is 50% faster. Not so bad!

However, doing this increases the pressure on the processor bus, so it is
necessary to increase the processor bus timeout on 40MHz boards again (to 256
usec). ``black cat'' 50MHz boards seem to be unaffected, so they remain at
64 usec.


# 1.40 15-Dec-2007 miod

Move the cmmu lock back from 8820x-specific code to global, and use it on
MVME197DP to serialize 88410 operations.


# 1.39 09-Dec-2007 miod

I honestly do not remember what 88110 errata convinced me to disable
out-of-order (superscalar) execution on these processors.

Since OoO brings a nice 50% to 250% speedup (as shown by ``openssl speed''),
it is definitely worth enabling.


# 1.38 05-Dec-2007 miod

xmem can not be used as a reliable atomic operation, they way we do them,
so do the naive operations with interrupts disabled, and an interlock held
if MULTIPROCESSOR.


# 1.37 04-Dec-2007 miod

Improve setregs() so that it performs the equivalent of the first two
instructions of the new binary, which allows them to be skipped unconditionaly.


# 1.36 02-Dec-2007 miod

When setting up the vectors page, do not put a nop as the first instruction
if the processor is a 88110, since only the 88100 suffers from the ``will
fetch one instruction too far'' bug.


# 1.35 02-Dec-2007 miod

Provide a specific rw_cas() function for MP kernels, simulating a really
atomic compare-and-swap operation.


# 1.34 22-Nov-2007 miod

Move the cmmu lock to 88200-specific code. 88110 MP code will use ipis
and will not require such a lock.


# 1.33 20-Nov-2007 miod

Fix setregs() on 88110, so that binaries do not skip their first instruction.
Makes binaries beyond init(8) running on MVME197, to some extent.


# 1.32 17-Nov-2007 miod

Replace many ``unsigned'' variables with ``unsigned int'', ``u_int'' or other
appropriate types. No functional change.


# 1.31 15-Nov-2007 miod

Check for curcpu()->ci_softintr being nonzero before invoking dosoftint(),
in the common case, this saves us two potentially expensive setipl() calls.


# 1.30 15-Nov-2007 miod

Resolve the struct trapframe tf_mode/tf_flags duality by getting rid of
the tf_mode name. This field only contains flags used internally by the
exception processing code.


# 1.29 14-Nov-2007 miod

Merge the ci_alive and ci_primary boolean values of struct cpu_info into
a single ci_flags bitfield.

Also, set_cpu_number() will no longer set CIF_PRIMARY on the primary processor,
it's up to the initialization code to do this.


# 1.28 09-Nov-2007 miod

On MULTIPROCESSOR kernels, don't forget to grab the kernel lock when
processing soft interrupts; and there was much rejoicing.


# 1.27 06-Nov-2007 miod

Keep a pending software interrupts mask per processor, instead of having it
global; and only schedule software interrupts on the currently running cpu.


# 1.26 06-Nov-2007 miod

Remove the now unused idle_u, and call the secondary processors startup
stack a startup stack.


# 1.25 29-Oct-2007 miod

When a secondary cpu gets its interrupt pin stuck, be sure to savectx
and put the process it was running back on the run queue (unless this was
the idle proc).


# 1.24 28-Oct-2007 miod

Do not flag a processor as ``alive'' until it really is ready to accept IPIs.


# 1.23 24-Oct-2007 miod

Remove sir_lock, superseded by the atomic bit operations.


# 1.22 10-Oct-2007 art

Make context switching much more MI:
- Move the functionality of choosing a process from cpu_switch into
a much simpler function: cpu_switchto. Instead of having the locore
code walk the run queues, let the MI code choose the process we
want to run and only implement the context switching itself in MD
code.
- Let MD context switching run without worrying about spls or locks.
- Instead of having the idle loop implemented with special contexts
in MD code, implement one idle proc for each cpu. make the idle
loop MI with MD hooks.
- Change the proc lists from the old style vax queues to TAILQs.
- Change the sleep queue from vax queues to TAILQs. This makes
wakeup() go from O(n^2) to O(n)

there will be some MD fallout, but it will be fixed shortly.
There's also a few cleanups to be done after this.

deraadt@, kettenis@ ok


Revision tags: OPENBSD_4_2_BASE
# 1.21 29-May-2007 miod

Use atomic operations to operate on netisr, instead of clearing it at splhigh.
This changes nothing on legacy architectures, but is a bit faster (and simpler)
on the interesting ones.


# 1.20 19-May-2007 miod

Send an IPI in signotify() if the process runs on a different processor,
similar to the fix which went into i386 and amd64 a few weeks ago.


# 1.19 18-May-2007 miod

In spl0(), really process soft interrupts at IPL_SOFT instead of whatever
level we were at.


# 1.18 18-Apr-2007 miod

Use atomic operations to change the pending software interrupt mask.


Revision tags: OPENBSD_4_1_BASE
# 1.17 22-Nov-2006 miod

The softintr lock needs to be an __mp_lock, not a __cpu_simple_lock.


Revision tags: OPENBSD_4_0_BASE
# 1.16 08-May-2006 miod

Replace gazillions of badvaddr() or badwordaddr() calls with badaddr() calls.
With a few prototype declarations shuffling, this finally allows
<machine/locore.h> to die.


# 1.15 08-May-2006 miod

Clean the internal m88k trap type codes; while there, simplify and
factorize the build of the VBR page betweem luna88k and mvme88k.

Tested by aoyama@ and I.


# 1.14 15-Apr-2006 miod

nmihand() is mvme88k only, move it out of m88k common area.


Revision tags: OPENBSD_3_9_BASE
# 1.13 11-Dec-2005 miod

Factorize soft interrupt code between luna88k and mvme88k.


# 1.12 04-Dec-2005 miod

Oops, simplelock leftover.


# 1.11 03-Dec-2005 miod

Replace simplelocks with __cpu_simple_locks for cmmu and pmap locking,
for the MULTIPROCESSOR case.


# 1.10 03-Dec-2005 miod

Switch m88k ports to __HAVE_CPUINFO. Current cpu pointer is held in SR0
on all running processors.
Tested aoyama@ and I


# 1.9 28-Nov-2005 miod

Maintain an interrupt depth counter for CLKF_INTR to be correct.
Tested aoyama@ martin@ and I.


# 1.8 06-Nov-2005 miod

Invoke regdump() on abort if compiled without DDB support.


# 1.7 13-Oct-2005 miod

Merge <machine/cpu_number.h> into <machine/cpu.h>, preparing for intrusive
changes.


# 1.6 12-Oct-2005 miod

Remove commented out dead wrong FPU handling code in setregs().


# 1.5 12-Oct-2005 miod

Stop mapping the u area at fixed UADDR in addition to its actual va.
While there, attempt to clean and comment stack usage in the kernel.
No functional change.

From the m88k SMP tree; help&test martin@


# 1.4 25-Sep-2005 miod

Change the size parameter of cmmu_flush_tlb() from bytes to pages. This makes
things easier for the callers, and allows us to inline the "fewer than 4 pages"
situation for speed.


Revision tags: OPENBSD_3_8_BASE
# 1.3 30-Apr-2005 miod

Use [XNF]IP_ADDR constants rather than their numeric values.


Revision tags: OPENBSD_3_7_BASE
# 1.2 30-Sep-2004 miod

Introduce sparc-like CPU_ISFOO macros, to short-circuit evaluations when
compiling for one flavour only.

This makes code slightly smaller on all m88k-based platforms (my roughly
1KB), and saves more than meets the eye on luna88k, which is m88100-based.


# 1.1 30-Sep-2004 miod

More code shuffling, probably the final touch.


# 1.69 22-Oct-2018 krw

More "explicitely" -> "explicitly" in various comments.

ok guenther@ tb@ deraadt@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.68 29-May-2017 mpi

Kill SPINLOCK_SPIN_HOOK, use CPU_BUSY_CYCLE() instead.

ok visa@, kettenis@


Revision tags: OPENBSD_6_1_BASE
# 1.67 19-Mar-2017 miod

Put the address of the per-cpu clock and interrupt registers into the cpu_info
struct, rather than fetching them from arrays every time they are needed.

ok aoyama@


# 1.66 09-Oct-2016 guenther

Tweak the special handling of pid 1 in setregs()...and document that
while it's not 100% correct, it's okay

tested by aoyama@


# 1.65 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


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

no md code wants lockmgr locks, so no md code needs to include sys/lock.h

with and ok miod@


Revision tags: OPENBSD_5_6_BASE
# 1.63 15-Jul-2014 miod

Implement rw_cas() with atomic_cas_ulong() now, instead of a dedicated
routine.


# 1.62 09-Jun-2014 miod

Remove redundant regdump() output.


# 1.61 31-May-2014 miod

In regdump(), print DAE registers when they are valid, regardless of the
exception type.


# 1.60 08-May-2014 miod

Format string fixes for m88k; remove -Wno-format from the m88k kernels.


# 1.59 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.58 07-Oct-2013 miod

Put the kernel VBR page at the beginning of the kernel text, as done on
mvme88k, to be able to unmap the page at address zero in the kernel, and have
the vbr page read-only after being initialized.


Revision tags: OPENBSD_5_4_BASE
# 1.57 17-Jul-2013 miod

Fix setregs() to match prototype. Exposed by recent _types.h change, found the
hard way by aoyama@


# 1.56 15-May-2013 miod

Initialize a teeny few more globals to reasonable values to allow for printf()
to work as soon as cn_tab is initialized. Allows us to correctly printf or
panic early on unrecognized systems. This used to be the case but got lost a
long time ago.


Revision tags: OPENBSD_5_3_BASE
# 1.55 17-Feb-2013 miod

Constify struct cmmu.


# 1.54 26-Jan-2013 miod

Make sure new processes get a clean FPU configuration upon startup, by
resetting the appropriate register in setregs(). Similar in spirit to what
m68k does (restoring a null frame), and necessary since m88k doesn't do lazy
fpu switching.


# 1.53 05-Jan-2013 miod

Switch m88k ports to ELF.


Revision tags: OPENBSD_5_2_BASE
# 1.52 23-Mar-2012 guenther

Make rusage totals, itimers, and profile settings per-process instead
of per-rthread. Handling of per-thread tick and runtime counters
inspired by how FreeBSD does it.

ok kettenis@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.51 23-Dec-2010 miod

The exception vector page on m88k systems has always been the same page as
the one used by the firmware, which (at least on mvme88k) is at address zero.

This is unfortunate, since this means that NULL pointer dereferences in the
kernel are not caught, and writes cause havoc.

This behaviour was necessary to be able to use the PROM system call interface
during early bootstrap, without having to disassemble the VBR page and
update branches - which use pc-relative displacement - if we were to use
a different VBR address.

On mvme88k, change this and actually set up two VBR pages: one, over the PROM
page (except for the system call vectors), and another one in the kernel
image (which will be mapped read-only). We'll run with the PROM page until
the end of autoconf, and then switch to the kernel one, and unmap all the
PROM below it.

As a bonus, the final kernel page can use optimized data access fault
handlers, which do not have to check for faults caused by badaddr(), since
badaddr() is only used during device probe on buses which do not support
hotplug.

There are a few infrastructure collateral damage on aviion and luna88k, but
these ports do not change their behaviour yet.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.50 19-Apr-2009 miod

Rename max_cpus to ncpusfound and compute it regardless of option
MULTIPROCESSOR.


# 1.49 15-Mar-2009 miod

Generic softinterrupt support for m88k based platforms, adapted from arm
with different locking mechanism. 88110 soft ipi are replaced with an
ipi callback which is checked upon return from exception (it can not be kept
as a softintr, as the generic softinterrupt code doesn't have per-cpu
pending softintr queues).


# 1.48 04-Mar-2009 miod

Introduce atomic_clear_int() as an MD atomic operation to perform atomic
exchange with zero; use it in the soft interrupt code to make it simpler
and faster.


# 1.47 04-Mar-2009 miod

Fix stupid logic bug in rw_cas_m88k(), makes NFS much happier on SMP kernels.


Revision tags: OPENBSD_4_5_BASE
# 1.46 20-Feb-2009 miod

atomic_{set,clear}bits_int were not safe enough on 88110 systems, as they
can be interrupted by NMI; move the SMP version of these routines from
inlines to a separate file (kernel text shrinks 20KB...).

Since the implementation for 88110 becomes really hairy, the pre-main() code
is responsible for copying the appropriate code over for kernels configured
for both 88100 and 88110 cpus, to avoid having to choose the atomicity
strategy at runtime. Hairy, I said.

This gets GENERIC.MP run much further on 197DP. Not enough to reach multiuser
mode, but boots up to starting sshd and then panics.


# 1.45 18-Feb-2009 miod

typo


# 1.44 16-Feb-2009 miod

More 88110 SMP work. Contains, horribly entangled:
- dma_cachectl() split into a ``local cpu only'' and ``all cpus'', and an ipi
to broadcast ``local dma_cachectl'' is added.
- cpu_info fields are rearranged, to have the 88100-specific information
and the 88110-specific information overlap, and has many more 88110
ugly things.
- more ipi handling in the 197-specific area. Since it is not possible to
have the second processor receive any hardware interrupt (selection
is done on a level basis via ISEL, and we definitely do not want the
main cpu to lose interrupts), the best we can do is to inflict ourselves
a soft interrupt for late ipi processing. It gets used for softclock and
hardclock on the secondary processor, but since the soft interrupt
dispatcher doesn't have an exception frame, we have to remember parts
of it to build a fake clockframe from the soft ipi handler (ugly but
works).

This now lets GENERIC.MP run a few userland binaries before bugs trigger.


# 1.43 21-Dec-2008 miod

Proper cpu_unidle() function for MP kernels. ok art@ long ago


# 1.42 27-Nov-2008 miod

On 88100 cpus, make sure userland processes start with SNIP and SFIP valid
(i.e. with the valid bit set in them). Found the hard way by Anders Gavare
trying his latest gxemul, proves the hardware is more permitting than one
would expect it to be...


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.41 26-Dec-2007 miod

Remove the last debug bit from the PSR on 88110: do not force memory accesses
instructions to be serialized (this defeats the purpose of having a superscalar
processor, and accesses to volatile variables are done with explicit memory
barriers anyway).

This brings a HUGE speedup: openssl speed -elapsed shows AES is 90% faster,
blowfish is 75% faster, and sha1 is 50% faster. Not so bad!

However, doing this increases the pressure on the processor bus, so it is
necessary to increase the processor bus timeout on 40MHz boards again (to 256
usec). ``black cat'' 50MHz boards seem to be unaffected, so they remain at
64 usec.


# 1.40 15-Dec-2007 miod

Move the cmmu lock back from 8820x-specific code to global, and use it on
MVME197DP to serialize 88410 operations.


# 1.39 09-Dec-2007 miod

I honestly do not remember what 88110 errata convinced me to disable
out-of-order (superscalar) execution on these processors.

Since OoO brings a nice 50% to 250% speedup (as shown by ``openssl speed''),
it is definitely worth enabling.


# 1.38 05-Dec-2007 miod

xmem can not be used as a reliable atomic operation, they way we do them,
so do the naive operations with interrupts disabled, and an interlock held
if MULTIPROCESSOR.


# 1.37 04-Dec-2007 miod

Improve setregs() so that it performs the equivalent of the first two
instructions of the new binary, which allows them to be skipped unconditionaly.


# 1.36 02-Dec-2007 miod

When setting up the vectors page, do not put a nop as the first instruction
if the processor is a 88110, since only the 88100 suffers from the ``will
fetch one instruction too far'' bug.


# 1.35 02-Dec-2007 miod

Provide a specific rw_cas() function for MP kernels, simulating a really
atomic compare-and-swap operation.


# 1.34 22-Nov-2007 miod

Move the cmmu lock to 88200-specific code. 88110 MP code will use ipis
and will not require such a lock.


# 1.33 20-Nov-2007 miod

Fix setregs() on 88110, so that binaries do not skip their first instruction.
Makes binaries beyond init(8) running on MVME197, to some extent.


# 1.32 17-Nov-2007 miod

Replace many ``unsigned'' variables with ``unsigned int'', ``u_int'' or other
appropriate types. No functional change.


# 1.31 15-Nov-2007 miod

Check for curcpu()->ci_softintr being nonzero before invoking dosoftint(),
in the common case, this saves us two potentially expensive setipl() calls.


# 1.30 15-Nov-2007 miod

Resolve the struct trapframe tf_mode/tf_flags duality by getting rid of
the tf_mode name. This field only contains flags used internally by the
exception processing code.


# 1.29 14-Nov-2007 miod

Merge the ci_alive and ci_primary boolean values of struct cpu_info into
a single ci_flags bitfield.

Also, set_cpu_number() will no longer set CIF_PRIMARY on the primary processor,
it's up to the initialization code to do this.


# 1.28 09-Nov-2007 miod

On MULTIPROCESSOR kernels, don't forget to grab the kernel lock when
processing soft interrupts; and there was much rejoicing.


# 1.27 06-Nov-2007 miod

Keep a pending software interrupts mask per processor, instead of having it
global; and only schedule software interrupts on the currently running cpu.


# 1.26 06-Nov-2007 miod

Remove the now unused idle_u, and call the secondary processors startup
stack a startup stack.


# 1.25 29-Oct-2007 miod

When a secondary cpu gets its interrupt pin stuck, be sure to savectx
and put the process it was running back on the run queue (unless this was
the idle proc).


# 1.24 28-Oct-2007 miod

Do not flag a processor as ``alive'' until it really is ready to accept IPIs.


# 1.23 24-Oct-2007 miod

Remove sir_lock, superseded by the atomic bit operations.


# 1.22 10-Oct-2007 art

Make context switching much more MI:
- Move the functionality of choosing a process from cpu_switch into
a much simpler function: cpu_switchto. Instead of having the locore
code walk the run queues, let the MI code choose the process we
want to run and only implement the context switching itself in MD
code.
- Let MD context switching run without worrying about spls or locks.
- Instead of having the idle loop implemented with special contexts
in MD code, implement one idle proc for each cpu. make the idle
loop MI with MD hooks.
- Change the proc lists from the old style vax queues to TAILQs.
- Change the sleep queue from vax queues to TAILQs. This makes
wakeup() go from O(n^2) to O(n)

there will be some MD fallout, but it will be fixed shortly.
There's also a few cleanups to be done after this.

deraadt@, kettenis@ ok


Revision tags: OPENBSD_4_2_BASE
# 1.21 29-May-2007 miod

Use atomic operations to operate on netisr, instead of clearing it at splhigh.
This changes nothing on legacy architectures, but is a bit faster (and simpler)
on the interesting ones.


# 1.20 19-May-2007 miod

Send an IPI in signotify() if the process runs on a different processor,
similar to the fix which went into i386 and amd64 a few weeks ago.


# 1.19 18-May-2007 miod

In spl0(), really process soft interrupts at IPL_SOFT instead of whatever
level we were at.


# 1.18 18-Apr-2007 miod

Use atomic operations to change the pending software interrupt mask.


Revision tags: OPENBSD_4_1_BASE
# 1.17 22-Nov-2006 miod

The softintr lock needs to be an __mp_lock, not a __cpu_simple_lock.


Revision tags: OPENBSD_4_0_BASE
# 1.16 08-May-2006 miod

Replace gazillions of badvaddr() or badwordaddr() calls with badaddr() calls.
With a few prototype declarations shuffling, this finally allows
<machine/locore.h> to die.


# 1.15 08-May-2006 miod

Clean the internal m88k trap type codes; while there, simplify and
factorize the build of the VBR page betweem luna88k and mvme88k.

Tested by aoyama@ and I.


# 1.14 15-Apr-2006 miod

nmihand() is mvme88k only, move it out of m88k common area.


Revision tags: OPENBSD_3_9_BASE
# 1.13 11-Dec-2005 miod

Factorize soft interrupt code between luna88k and mvme88k.


# 1.12 04-Dec-2005 miod

Oops, simplelock leftover.


# 1.11 03-Dec-2005 miod

Replace simplelocks with __cpu_simple_locks for cmmu and pmap locking,
for the MULTIPROCESSOR case.


# 1.10 03-Dec-2005 miod

Switch m88k ports to __HAVE_CPUINFO. Current cpu pointer is held in SR0
on all running processors.
Tested aoyama@ and I


# 1.9 28-Nov-2005 miod

Maintain an interrupt depth counter for CLKF_INTR to be correct.
Tested aoyama@ martin@ and I.


# 1.8 06-Nov-2005 miod

Invoke regdump() on abort if compiled without DDB support.


# 1.7 13-Oct-2005 miod

Merge <machine/cpu_number.h> into <machine/cpu.h>, preparing for intrusive
changes.


# 1.6 12-Oct-2005 miod

Remove commented out dead wrong FPU handling code in setregs().


# 1.5 12-Oct-2005 miod

Stop mapping the u area at fixed UADDR in addition to its actual va.
While there, attempt to clean and comment stack usage in the kernel.
No functional change.

From the m88k SMP tree; help&test martin@


# 1.4 25-Sep-2005 miod

Change the size parameter of cmmu_flush_tlb() from bytes to pages. This makes
things easier for the callers, and allows us to inline the "fewer than 4 pages"
situation for speed.


Revision tags: OPENBSD_3_8_BASE
# 1.3 30-Apr-2005 miod

Use [XNF]IP_ADDR constants rather than their numeric values.


Revision tags: OPENBSD_3_7_BASE
# 1.2 30-Sep-2004 miod

Introduce sparc-like CPU_ISFOO macros, to short-circuit evaluations when
compiling for one flavour only.

This makes code slightly smaller on all m88k-based platforms (my roughly
1KB), and saves more than meets the eye on luna88k, which is m88100-based.


# 1.1 30-Sep-2004 miod

More code shuffling, probably the final touch.


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

Kill SPINLOCK_SPIN_HOOK, use CPU_BUSY_CYCLE() instead.

ok visa@, kettenis@


Revision tags: OPENBSD_6_1_BASE
# 1.67 19-Mar-2017 miod

Put the address of the per-cpu clock and interrupt registers into the cpu_info
struct, rather than fetching them from arrays every time they are needed.

ok aoyama@


# 1.66 09-Oct-2016 guenther

Tweak the special handling of pid 1 in setregs()...and document that
while it's not 100% correct, it's okay

tested by aoyama@


# 1.65 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


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

no md code wants lockmgr locks, so no md code needs to include sys/lock.h

with and ok miod@


Revision tags: OPENBSD_5_6_BASE
# 1.63 15-Jul-2014 miod

Implement rw_cas() with atomic_cas_ulong() now, instead of a dedicated
routine.


# 1.62 09-Jun-2014 miod

Remove redundant regdump() output.


# 1.61 31-May-2014 miod

In regdump(), print DAE registers when they are valid, regardless of the
exception type.


# 1.60 08-May-2014 miod

Format string fixes for m88k; remove -Wno-format from the m88k kernels.


# 1.59 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.58 07-Oct-2013 miod

Put the kernel VBR page at the beginning of the kernel text, as done on
mvme88k, to be able to unmap the page at address zero in the kernel, and have
the vbr page read-only after being initialized.


Revision tags: OPENBSD_5_4_BASE
# 1.57 17-Jul-2013 miod

Fix setregs() to match prototype. Exposed by recent _types.h change, found the
hard way by aoyama@


# 1.56 15-May-2013 miod

Initialize a teeny few more globals to reasonable values to allow for printf()
to work as soon as cn_tab is initialized. Allows us to correctly printf or
panic early on unrecognized systems. This used to be the case but got lost a
long time ago.


Revision tags: OPENBSD_5_3_BASE
# 1.55 17-Feb-2013 miod

Constify struct cmmu.


# 1.54 26-Jan-2013 miod

Make sure new processes get a clean FPU configuration upon startup, by
resetting the appropriate register in setregs(). Similar in spirit to what
m68k does (restoring a null frame), and necessary since m88k doesn't do lazy
fpu switching.


# 1.53 05-Jan-2013 miod

Switch m88k ports to ELF.


Revision tags: OPENBSD_5_2_BASE
# 1.52 23-Mar-2012 guenther

Make rusage totals, itimers, and profile settings per-process instead
of per-rthread. Handling of per-thread tick and runtime counters
inspired by how FreeBSD does it.

ok kettenis@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.51 23-Dec-2010 miod

The exception vector page on m88k systems has always been the same page as
the one used by the firmware, which (at least on mvme88k) is at address zero.

This is unfortunate, since this means that NULL pointer dereferences in the
kernel are not caught, and writes cause havoc.

This behaviour was necessary to be able to use the PROM system call interface
during early bootstrap, without having to disassemble the VBR page and
update branches - which use pc-relative displacement - if we were to use
a different VBR address.

On mvme88k, change this and actually set up two VBR pages: one, over the PROM
page (except for the system call vectors), and another one in the kernel
image (which will be mapped read-only). We'll run with the PROM page until
the end of autoconf, and then switch to the kernel one, and unmap all the
PROM below it.

As a bonus, the final kernel page can use optimized data access fault
handlers, which do not have to check for faults caused by badaddr(), since
badaddr() is only used during device probe on buses which do not support
hotplug.

There are a few infrastructure collateral damage on aviion and luna88k, but
these ports do not change their behaviour yet.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.50 19-Apr-2009 miod

Rename max_cpus to ncpusfound and compute it regardless of option
MULTIPROCESSOR.


# 1.49 15-Mar-2009 miod

Generic softinterrupt support for m88k based platforms, adapted from arm
with different locking mechanism. 88110 soft ipi are replaced with an
ipi callback which is checked upon return from exception (it can not be kept
as a softintr, as the generic softinterrupt code doesn't have per-cpu
pending softintr queues).


# 1.48 04-Mar-2009 miod

Introduce atomic_clear_int() as an MD atomic operation to perform atomic
exchange with zero; use it in the soft interrupt code to make it simpler
and faster.


# 1.47 04-Mar-2009 miod

Fix stupid logic bug in rw_cas_m88k(), makes NFS much happier on SMP kernels.


Revision tags: OPENBSD_4_5_BASE
# 1.46 20-Feb-2009 miod

atomic_{set,clear}bits_int were not safe enough on 88110 systems, as they
can be interrupted by NMI; move the SMP version of these routines from
inlines to a separate file (kernel text shrinks 20KB...).

Since the implementation for 88110 becomes really hairy, the pre-main() code
is responsible for copying the appropriate code over for kernels configured
for both 88100 and 88110 cpus, to avoid having to choose the atomicity
strategy at runtime. Hairy, I said.

This gets GENERIC.MP run much further on 197DP. Not enough to reach multiuser
mode, but boots up to starting sshd and then panics.


# 1.45 18-Feb-2009 miod

typo


# 1.44 16-Feb-2009 miod

More 88110 SMP work. Contains, horribly entangled:
- dma_cachectl() split into a ``local cpu only'' and ``all cpus'', and an ipi
to broadcast ``local dma_cachectl'' is added.
- cpu_info fields are rearranged, to have the 88100-specific information
and the 88110-specific information overlap, and has many more 88110
ugly things.
- more ipi handling in the 197-specific area. Since it is not possible to
have the second processor receive any hardware interrupt (selection
is done on a level basis via ISEL, and we definitely do not want the
main cpu to lose interrupts), the best we can do is to inflict ourselves
a soft interrupt for late ipi processing. It gets used for softclock and
hardclock on the secondary processor, but since the soft interrupt
dispatcher doesn't have an exception frame, we have to remember parts
of it to build a fake clockframe from the soft ipi handler (ugly but
works).

This now lets GENERIC.MP run a few userland binaries before bugs trigger.


# 1.43 21-Dec-2008 miod

Proper cpu_unidle() function for MP kernels. ok art@ long ago


# 1.42 27-Nov-2008 miod

On 88100 cpus, make sure userland processes start with SNIP and SFIP valid
(i.e. with the valid bit set in them). Found the hard way by Anders Gavare
trying his latest gxemul, proves the hardware is more permitting than one
would expect it to be...


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.41 26-Dec-2007 miod

Remove the last debug bit from the PSR on 88110: do not force memory accesses
instructions to be serialized (this defeats the purpose of having a superscalar
processor, and accesses to volatile variables are done with explicit memory
barriers anyway).

This brings a HUGE speedup: openssl speed -elapsed shows AES is 90% faster,
blowfish is 75% faster, and sha1 is 50% faster. Not so bad!

However, doing this increases the pressure on the processor bus, so it is
necessary to increase the processor bus timeout on 40MHz boards again (to 256
usec). ``black cat'' 50MHz boards seem to be unaffected, so they remain at
64 usec.


# 1.40 15-Dec-2007 miod

Move the cmmu lock back from 8820x-specific code to global, and use it on
MVME197DP to serialize 88410 operations.


# 1.39 09-Dec-2007 miod

I honestly do not remember what 88110 errata convinced me to disable
out-of-order (superscalar) execution on these processors.

Since OoO brings a nice 50% to 250% speedup (as shown by ``openssl speed''),
it is definitely worth enabling.


# 1.38 05-Dec-2007 miod

xmem can not be used as a reliable atomic operation, they way we do them,
so do the naive operations with interrupts disabled, and an interlock held
if MULTIPROCESSOR.


# 1.37 04-Dec-2007 miod

Improve setregs() so that it performs the equivalent of the first two
instructions of the new binary, which allows them to be skipped unconditionaly.


# 1.36 02-Dec-2007 miod

When setting up the vectors page, do not put a nop as the first instruction
if the processor is a 88110, since only the 88100 suffers from the ``will
fetch one instruction too far'' bug.


# 1.35 02-Dec-2007 miod

Provide a specific rw_cas() function for MP kernels, simulating a really
atomic compare-and-swap operation.


# 1.34 22-Nov-2007 miod

Move the cmmu lock to 88200-specific code. 88110 MP code will use ipis
and will not require such a lock.


# 1.33 20-Nov-2007 miod

Fix setregs() on 88110, so that binaries do not skip their first instruction.
Makes binaries beyond init(8) running on MVME197, to some extent.


# 1.32 17-Nov-2007 miod

Replace many ``unsigned'' variables with ``unsigned int'', ``u_int'' or other
appropriate types. No functional change.


# 1.31 15-Nov-2007 miod

Check for curcpu()->ci_softintr being nonzero before invoking dosoftint(),
in the common case, this saves us two potentially expensive setipl() calls.


# 1.30 15-Nov-2007 miod

Resolve the struct trapframe tf_mode/tf_flags duality by getting rid of
the tf_mode name. This field only contains flags used internally by the
exception processing code.


# 1.29 14-Nov-2007 miod

Merge the ci_alive and ci_primary boolean values of struct cpu_info into
a single ci_flags bitfield.

Also, set_cpu_number() will no longer set CIF_PRIMARY on the primary processor,
it's up to the initialization code to do this.


# 1.28 09-Nov-2007 miod

On MULTIPROCESSOR kernels, don't forget to grab the kernel lock when
processing soft interrupts; and there was much rejoicing.


# 1.27 06-Nov-2007 miod

Keep a pending software interrupts mask per processor, instead of having it
global; and only schedule software interrupts on the currently running cpu.


# 1.26 06-Nov-2007 miod

Remove the now unused idle_u, and call the secondary processors startup
stack a startup stack.


# 1.25 29-Oct-2007 miod

When a secondary cpu gets its interrupt pin stuck, be sure to savectx
and put the process it was running back on the run queue (unless this was
the idle proc).


# 1.24 28-Oct-2007 miod

Do not flag a processor as ``alive'' until it really is ready to accept IPIs.


# 1.23 24-Oct-2007 miod

Remove sir_lock, superseded by the atomic bit operations.


# 1.22 10-Oct-2007 art

Make context switching much more MI:
- Move the functionality of choosing a process from cpu_switch into
a much simpler function: cpu_switchto. Instead of having the locore
code walk the run queues, let the MI code choose the process we
want to run and only implement the context switching itself in MD
code.
- Let MD context switching run without worrying about spls or locks.
- Instead of having the idle loop implemented with special contexts
in MD code, implement one idle proc for each cpu. make the idle
loop MI with MD hooks.
- Change the proc lists from the old style vax queues to TAILQs.
- Change the sleep queue from vax queues to TAILQs. This makes
wakeup() go from O(n^2) to O(n)

there will be some MD fallout, but it will be fixed shortly.
There's also a few cleanups to be done after this.

deraadt@, kettenis@ ok


Revision tags: OPENBSD_4_2_BASE
# 1.21 29-May-2007 miod

Use atomic operations to operate on netisr, instead of clearing it at splhigh.
This changes nothing on legacy architectures, but is a bit faster (and simpler)
on the interesting ones.


# 1.20 19-May-2007 miod

Send an IPI in signotify() if the process runs on a different processor,
similar to the fix which went into i386 and amd64 a few weeks ago.


# 1.19 18-May-2007 miod

In spl0(), really process soft interrupts at IPL_SOFT instead of whatever
level we were at.


# 1.18 18-Apr-2007 miod

Use atomic operations to change the pending software interrupt mask.


Revision tags: OPENBSD_4_1_BASE
# 1.17 22-Nov-2006 miod

The softintr lock needs to be an __mp_lock, not a __cpu_simple_lock.


Revision tags: OPENBSD_4_0_BASE
# 1.16 08-May-2006 miod

Replace gazillions of badvaddr() or badwordaddr() calls with badaddr() calls.
With a few prototype declarations shuffling, this finally allows
<machine/locore.h> to die.


# 1.15 08-May-2006 miod

Clean the internal m88k trap type codes; while there, simplify and
factorize the build of the VBR page betweem luna88k and mvme88k.

Tested by aoyama@ and I.


# 1.14 15-Apr-2006 miod

nmihand() is mvme88k only, move it out of m88k common area.


Revision tags: OPENBSD_3_9_BASE
# 1.13 11-Dec-2005 miod

Factorize soft interrupt code between luna88k and mvme88k.


# 1.12 04-Dec-2005 miod

Oops, simplelock leftover.


# 1.11 03-Dec-2005 miod

Replace simplelocks with __cpu_simple_locks for cmmu and pmap locking,
for the MULTIPROCESSOR case.


# 1.10 03-Dec-2005 miod

Switch m88k ports to __HAVE_CPUINFO. Current cpu pointer is held in SR0
on all running processors.
Tested aoyama@ and I


# 1.9 28-Nov-2005 miod

Maintain an interrupt depth counter for CLKF_INTR to be correct.
Tested aoyama@ martin@ and I.


# 1.8 06-Nov-2005 miod

Invoke regdump() on abort if compiled without DDB support.


# 1.7 13-Oct-2005 miod

Merge <machine/cpu_number.h> into <machine/cpu.h>, preparing for intrusive
changes.


# 1.6 12-Oct-2005 miod

Remove commented out dead wrong FPU handling code in setregs().


# 1.5 12-Oct-2005 miod

Stop mapping the u area at fixed UADDR in addition to its actual va.
While there, attempt to clean and comment stack usage in the kernel.
No functional change.

From the m88k SMP tree; help&test martin@


# 1.4 25-Sep-2005 miod

Change the size parameter of cmmu_flush_tlb() from bytes to pages. This makes
things easier for the callers, and allows us to inline the "fewer than 4 pages"
situation for speed.


Revision tags: OPENBSD_3_8_BASE
# 1.3 30-Apr-2005 miod

Use [XNF]IP_ADDR constants rather than their numeric values.


Revision tags: OPENBSD_3_7_BASE
# 1.2 30-Sep-2004 miod

Introduce sparc-like CPU_ISFOO macros, to short-circuit evaluations when
compiling for one flavour only.

This makes code slightly smaller on all m88k-based platforms (my roughly
1KB), and saves more than meets the eye on luna88k, which is m88100-based.


# 1.1 30-Sep-2004 miod

More code shuffling, probably the final touch.