History log of /openbsd-current/sys/arch/hppa/hppa/machdep.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.270 22-May-2024 jsg

remove prototypes with no matching function; ok miod@


# 1.269 14-Apr-2024 jsg

with empty body loops, put final semicolon on a new line for readability
ok bluhm@ jca@


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

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


# 1.267 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_7_2_BASE
# 1.266 10-Aug-2022 jsg

match other archs use %s for version printf


Revision tags: OPENBSD_7_1_BASE
# 1.265 06-Oct-2021 claudio

Change sendsig() interface so that the MD code does not need to access
data from struct process anymore. This changes how siginfo and onstack
are accessed and make sendsig() more MP friendly.
With and OK semarie@ OK kettenis@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.264 11-Mar-2021 jsg

spelling


# 1.263 09-Jan-2021 kettenis

"encoding of diag instructions is hard, let's go shopping"

Clean up things a bit, adding documentation about the source of the
information about these instructions.

From miod@


# 1.262 08-Nov-2020 mpi

In case of failure, call sigexit() from trapsignal instead of sensig().

Simplify MD code and reduce the amount of recursion into the signal code
which helps when dealing with locks.

ok cheloha@, deraadt@


# 1.261 21-Oct-2020 deraadt

hppa also has a similar to arm64: copyout(9), copyinstr(9) and
copyoutstr(9) should bail out properly if they are called with a
length of 0.
ok kettenis@


Revision tags: OPENBSD_6_8_BASE
# 1.260 14-Jun-2020 naddy

Implement cpu_rnd_messybits() as a read of the cycle counter register.
ok dlg@ deraadt@


# 1.259 31-May-2020 dlg

introduce "cpu_rnd_messybits" for use instead of nanotime in dev/rnd.c.

rnd.c uses nanotime to get access to some bits that change quickly
between events that it can mix into the entropy pool. it doesn't
use nanotime to get a monotonically increasing set or ordered and
accurate timestamps, it just wants something with bits that change.

there's been discussions for years about letting rnd use a clock
that's super fast to read, but not necessarily accurate, but it
wasn't until recently that i figured out it wasn't interested in
time at all, so things like keeping a fast clock coherent between
cpu cores or correct according to ntp is unecessary. this means we
can just let rnd read the cycle counters on cpus and things will
be fine. cpus with cycle counters that vary in their speed and
arent kept consistent between cores may even be desirable in this
context.

so this is the first step in converting rnd.c to reading cycle
counter. it copies the nanotime backend to each arch, and they can
replace it with something MD as a second step later on.

djm@ suggested rnd_messybytes, but we landed on cpu_rnd_messybits.
thanks to visa for his eyes.
ok deraadt@ visa@
deraadt@ says he will help handle any MD fallout that occurs.


# 1.258 16-May-2020 kettenis

Make inittodr() and resettodr() MI.

ok deraadt@, mpi@, visa@
ok cheloha@ as well (would have preferred in new file for this code)


# 1.257 11-May-2020 kettenis

Initialize the timeval passed to todr_gettime() with the base time from
the file system such that implementations can use it to guess the right
century.

ok mpi@


Revision tags: OPENBSD_6_7_BASE
# 1.256 01-May-2020 kettenis

Use the same inittodr()/resettodr() implementation as on
amd64/arm64/armv7/i386/sparc64 and move it to the end of machdep.c. Rework the
actual implementation for the MC14818 compatible RTC into something that can
be used as a todr_handle just like on amd64.

ok mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.255 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


Revision tags: OPENBSD_6_4_BASE
# 1.254 20-Jul-2018 guenther

Missed a 'ksi' -> '*ksip' change in previous commit


# 1.253 10-Jul-2018 guenther

Move from sendsig() to its callers the initsiginfo() calls and
instead of passing sendsig() the code+type+val, pass a siginfo_t*
to copy from. Eliminate the indirection through struct emul for
sendsig(); we no longer have a SunOS4-compat version of sendsig()

ok deraadt@


# 1.252 22-May-2018 guenther

Delete antique sigdebug definitions

ok kettenis@


# 1.251 12-Apr-2018 deraadt

Implement MAP_STACK option for mmap(). Synchronous faults (pagefault and
syscall) confirm the stack register points at MAP_STACK memory, otherwise
SIGSEGV is delivered. sigaltstack() and pthread_attr_setstack() are modified
to create a MAP_STACK sub-region which satisfies alignment requirements.
Observe that MAP_STACK can only be set/cleared by mmap(), which zeroes the
contents of the region -- there is no mprotect() equivalent operation, so
there is no MAP_STACK-adding gadget.
This opportunistic software-emulation of a stack protection bit makes
stack-pivot operations during ROPchain fragile (kind of like removing a
tool from the toolbox).
original discussion with tedu, uvm work by stefan, testing by mortimer
ok kettenis


Revision tags: OPENBSD_6_3_BASE
# 1.250 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.249 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


Revision tags: OPENBSD_6_2_BASE
# 1.248 18-May-2017 kettenis

Implement copyin32(9).

"your chicken scratches look fine to me" deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.247 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

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


# 1.246 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.245 21-May-2016 deraadt

hand-massage sendsig() and sys_sigreturn() to be much more similar.
ok guenther kettenis


# 1.244 10-May-2016 deraadt

SROP mitigation. sendsig() stores a (per-process ^ &sigcontext) cookie
inside the sigcontext. sigreturn(2) checks syscall entry was from the
exact PC addr in the (per-process ASLR) sigtramp, verifies the cookie,
and clears it to prevent sigcontext reuse.
not yet tested on landisk, sparc, *88k, socppc.
ok kettenis


# 1.243 20-Apr-2016 dlg

pool_setipl for floating point context things

ok kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.242 21-Oct-2015 mpi

Do not call uvm_swap_finicrypt_all() a second time in dumpsys().

ok tedu@, deraadt@, miod@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.241 20-Jan-2015 kettenis

Move ps_strings "after" the random stackgap. This makes its location a
per-process value, and therefpore turns the VM_PSSTRINGS sysctl into a
per-process one as well. This gets rid of a pointer to the bottom of the
stack at a fixed location. Also clears the road for unmapping the stackgap.

ok deraadt@


# 1.240 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.239 25-Oct-2014 kettenis

Remove vmmap; it isn't used.

ok jsing@


# 1.238 23-Oct-2014 miod

Correctly set up the HPMC trap entry: according to the PA-RISC Firmware
Architecture Reference Specification, the sum of the 8 trap entry words
*and* of the payload which address and length are to be set at well-known
positions in the aforementioned trap entry, needs to be zero; the existing
code was only enforcing that the sum of the trap entry words is zero.

This matches what Linux and NetBSD do.

ok kettenis@


# 1.237 23-Oct-2014 miod

Revert limiting physmem to 2GB; the culprit was likely in uvm and uvm has
changed a lot in the last 5 years; verified to work on a 3GB system, in
snapshots for a few weeks already.


# 1.236 22-Sep-2014 dlg

implement atomic_{cas,swap}_{uint,ulong,ptr} and
atomic_{add,sub}_{int,long}_nv. sys/atomic.h turns these into the
rest of the atomic api.

on uniprocessor hppa systems "atomic" operations are implemented
as a non-interruptable sequence by disabling all interrupts on the
cpu, doing the operation, and then restoring the interrupt mask.

this isnt enough on MP systems, so we added a global atomic memory
mutex that is taken inside the interrupt disabling above to coordinate
operations between cpus.

this is a lot of overhead though cos mutexes dance around with ipls,
which is unecessary in our case because of the interrupt disabling
that is already done. also, hppa spinlocks are implemented with
ldcw which requires the word it operates on to be 16 byte aligned.
mutexes arent guaranteed to have this alignment so they compensate
by having lots of words inside themselves so they can hit the
appropriate one to use for the ldcw op.

with this in mind, this change pulls __cpu_simple_locks, which are
simply ldcw spinlocks with a 16 byte aligned word, out of
src/sys/arch/hppa/include/lock.h into src/sys/arch/hppa/include/atomic.h
so atomic.h can use them. lock.h includes atomic.h, so it still
gets and provides the same functionality as before.

finally, this also pulls the rwlock cas implementation apart. cas
ops now share the same serialising lock on MP systems as the other
memory operations, and rw_cas is defined as a wrapper around
atomic_cas_uint.

ok kettenis@


# 1.235 19-Sep-2014 kettenis

Use config_suspend_all(9).


# 1.234 18-Aug-2014 dlg

dont rely on mbuf.h to provide pool.h.

ok miod@, who has offerred to help with any MD fallout
ok guenther@


Revision tags: OPENBSD_5_6_BASE
# 1.233 22-Jul-2014 uebayasi

boot(9): Reduce diffs between hppa & hppa64 (& others)


# 1.232 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.231 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.230 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.229 13-Jul-2014 miod

These still need <sys/reboot.h> for the RB_ constants.


# 1.228 12-Jul-2014 uebayasi

reboot(9), panic(9): Call panic(9) for unrecoverable MD H/W errors (NMIs)

Some architectures have ability to detect hardware sanity and notify system
(NMI, firmware callback, etc.). Handle these hardware severe errors, same
as software errors, with panic(9).

According to miod@, SGI IP27 NMI is triggered by pushing some "hidden" button,
which "usual" users/admins don't know. Pushing such a button is "RB_USERREQ"
(human-triggered) in that the button is pushed by a human, but not "RB_USERREQ"
in that no user intervention in system (== no command input) is done. miod@
agreed that changing these from RB_USERREQ to !RB_USERREQ (== panic(9)) is
not a big problem.

OK miod@ kettenis@


# 1.227 12-Jul-2014 uebayasi

boot(9), reboot(9): Migrate MD callers of boot(9) to reboot(9)

I have found that some ports call boot(9) from machine-dependent code to
reboot system. These should be changed to either:

- Sending signal to init(8) to trigger it to shutdown system cleanly, like
acpi(4) does, in cases where found problems don't prevent system from working
immediately, or

- Just doing panic(9) if the situation is severely broken.

For now, just rewrite boot() to reboot(). Actual fixes follow.

Discussed with & OK from kettenis@


# 1.226 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.225 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.224 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.223 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.222 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.221 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.220 08-May-2014 miod

Format string fixes and removal of -Wno-format for hppa kernels.


# 1.219 08-Apr-2014 mpi

Less <uvm/uvm.h>


# 1.218 04-Apr-2014 miod

If the PDC_COPROC call fails, and we are running on a PA 1.1 system, assume
the usual 1.1 coprocessor mask, instead of using zero and having every
userland process dying with signal 4.

The circumstances under which this call fails are unclear and could be
tied to specific PROM version (I have tried overzealous stack alignment and
other tricks, to no avail). Interestingly enough, the 715/75 system which
hits this problem, only triggers it when booting from disk, and never when
booting from network.

This diff is an ugly bandaid until the problem is better understood. Or maybe
it is not worth investigating, seeing that Linux hardcodes the coprocessor
mask and never issues PDC_COPROC calls; I wonder what HP/UX does.

In my tree for over 18 months; "Looks like a nice hack" deraadt@
715/75 system provided by Sebastiaan Indesteege, thanks!


# 1.217 29-Mar-2014 guenther

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

ok dlg@ mpi@ deraadt@


# 1.216 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


# 1.215 22-Mar-2014 guenther

Move p_sigacts from struct proc to struct process.

testing help mpi@


# 1.214 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


Revision tags: OPENBSD_5_5_BASE
# 1.213 23-Nov-2013 uebayasi

Run doshutdownhooks() and config_suspend() even when boot() is called while
cold != 0. Indent and make hppa/hppa64 boot() closer to others.

OK kettenis@


# 1.212 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


Revision tags: OPENBSD_5_4_BASE
# 1.211 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


Revision tags: OPENBSD_5_3_BASE
# 1.210 02-Dec-2012 guenther

Determine whether we're currently on the alternative signal stack
dynamically, by comparing the stack pointer against the altstack
base and size, so that you get the correct answer if you longjmp
out of the signal handler, as tested by regress/sys/kern/stackjmp/.
Also, fix alt stack handling on vax, where it was completely broken.

Testing and corrections by miod@, krw@, tobiasu@, pirofti@


# 1.209 26-Oct-2012 kettenis

Properly clear trap frame in setregs() to avoid leaking registers across exec.

ok jsing@


# 1.208 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.207 07-Oct-2012 kettenis

Align the stack on a 64-byte boundary as required by "The 32-bit PA-RISC
Run-time Architecture Document". GCC relies on this to properly align
stack variables.

ok guenther@, beck@


Revision tags: OPENBSD_5_2_BASE
# 1.206 21-Jun-2012 guenther

__tfork() needs to set the stack address of the new thread in the kernel,
so that it can't get a signal while still running on the parent thread's
stack. Also, pass in sizeof(struct __tfork) to provide forward compat
when more members are added. This is an ABI change, so switch syscall
numbers and bump lib majors this time.

ok deraadt@ matthew@


Revision tags: OPENBSD_5_1_BASE
# 1.205 20-Sep-2011 miod

Clear RB_POWERDOWN early in boot() on systems which can not powerdown and
which firmware does not send spin up commands to the disks, in case the
operator changes his mind and reboots instead of manually powering down
after the system has halted.
ok kettenis@


Revision tags: OPENBSD_5_0_BASE
# 1.204 05-Jul-2011 guenther

Recommit the reverted sigacts change now that the NFS use-after-free
problem has been tracked down. This fixes the sharing of the signal
handling state: shared bits go in sigacts, per-rthread bits goes in
struct proc.

ok deraadt@


# 1.203 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.202 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.201 18-Apr-2011 guenther

Revert the sigacts diff: NFS can apparently retain pointers to processes
until they're zombies and then send them signals (for intr mounts). Until
that is untangled, the sigacts change is unsafe. sthen@ was the victim
for this one


# 1.200 15-Apr-2011 guenther

Correct the sharing of the signal handling state: stuff that should
be shared (p_sigignore, p_sigcatch, P_NOCLDSTOP, P_NOCLDWAIT) moves
to struct sigacts, wihle stuff that should be per rthread (ps_oldmask,
SAS_OLDMASK, ps_sigstk) moves to struct proc. Treat the coredumping
state bits (ps_sig, ps_code, ps_type, ps_sigval) as per-rthread
until our locking around coredumping is better.

Oh, and remove the old SunOS-compat ps_usertramp member.

"I like the sound of this" tedu@


Revision tags: OPENBSD_4_9_BASE
# 1.199 14-Jan-2011 jsing

Halt secondary CPUs when shutting down or rebooting. This should prevent
occasional hangs during reboot.

ok kettenis@


# 1.198 04-Jan-2011 jasper

- de-register. no binary change.

ok jsing@


# 1.197 01-Jan-2011 jasper

Move setting cpu_hzticks to the clock initialization function, like
other ports (e.g. hppa64) do.

ok jsing@ kettenis@


# 1.196 01-Jan-2011 jasper

- ansify

ok jsing@ kettenis@


# 1.195 30-Dec-2010 jsing

Turn signotify() into a function that also calls cpu_unidle().

ok kettenis@


# 1.194 20-Nov-2010 miod

This is a first step towards getting rid of avail_start and avail_end in the
kernel, currently limited to low-hanging fruit: these variables were used
by bus_dma to specify the range in which to allocate memory, back when
uvm_pglistalloc() was stupid and would not walk the vm_physseg[].

Nowadays, except on some platforms for early initialization, these variables
are not used, or do not need to be global variables. Therefore:
- remove `extern' declarations of avail_start and avail_end (or close cousins,
such as arm physical_start and physical_end) from files which no longer need
to use them.
- make them local variables whenever possible.
- remove them when they are assigned to but no longer used.


Revision tags: OPENBSD_4_8_BASE
# 1.193 01-Jul-2010 jsing

Create a struct to store FP state and include a pointer to the CPU that
currently holds the FPU context for this process. This will be soon used
to implement FPU shootdowns on multiprocessor kernels.

ok kettenis@


# 1.192 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.191 29-Jun-2010 jsing

Factor out code used to save and flushe process FPU context.

ok kettenis@


# 1.190 29-Jun-2010 jsing

Store pointer to process FPU state in struct cpu_info.

ok kettenis@


# 1.189 27-Jun-2010 thib

uvm constraints. Add two mandatory MD symbols, uvm_md_constraints
which contains the constraints for DMA/memory allocation for each
architecture, and dma_constraints which contains the range of addresses
that are dma accessable by the system.

This is based on ariane@'s physcontig diff, with lots of bugfixes and
additions the following additions by my self:

Introduce a new function pool_set_constraints() which sets the address
range for which we allocate pages for the pool from, this is now used
for the mbuf/mbuf cluster pools to keep them dma accessible.

The !direct archs no longer stuff pages into the kernel object in
uvm_km_getpage_pla but rather do a pmap_extract() in uvm_km_putpages.

Tested heavily by my self on i386, amd64 and sparc64. Some tests on
alpha and SGI.

"commit it" beck, art, oga, deraadt
"i like the diff" deraadt


# 1.188 27-Jun-2010 jsing

Use a mutex to make atomic operations atomic on multiprocessor kernels.

ok kettenis@


# 1.187 10-Jun-2010 deraadt

Declare safepri at the MD level on each platform, so that the kern_synch.c
does not have to deal with it as a common. Some platforms may be missed
by this commit... if you spot one, fix it the same way.
ok miod


# 1.186 09-Jun-2010 miod

Move declaration of cn_tab from dev/cons.c to dev/cninit.c, or appropriate
md files for ports which do not use dev/cninit.c. This gets rid of a common
at kernel link time.
feedback drahn@ ok deraadt@


# 1.185 24-May-2010 deraadt

Add missing prototypes
ok jsing kettenis


# 1.184 09-May-2010 kettenis

Prevent "taken branch" exceptions from kernel space by clearing the PSL_T
bit before we enter a signal handler.

"if you say so" miod@, "seems to make sense" jsing@


# 1.183 02-May-2010 kettenis

Properly initialize the members of `struct mdproc' that deal with
single-stepping when we fork and reset them upon exec.

ok miod@


# 1.182 27-Apr-2010 kettenis

Avoid null-pointer dereference by giving proc0 a place to store its
floating-point registers. Pointed out by Nick Hudson.

ok miod@, jsing@


# 1.181 19-Apr-2010 jsing

Make the Processor Status Word (PSW) a per-CPU value.

ok kettenis@


# 1.180 01-Apr-2010 jsing

Allow for multiple CPUs by moving to an array of cpu_info.

ok kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.179 31-Dec-2009 jsing

Make cpl and cpu_inintr per CPU variables. For locore.S, cpl becomes an
offset within cpu_primary_info - this will need to be revisited shortly.

ok kettenis@


# 1.178 11-Aug-2009 miod

Do not bother initializing bufpages in the md code if the computation is
exactly the same the mi could will use if bufinit() is invoked with
bufpages == 0.


# 1.177 11-Aug-2009 miod

With the SysV memory allocation changes, allocsys() doesn't do anything
anymore. Get rid of it completely.


# 1.176 09-Aug-2009 blambert

Rototill system V message queues.

No longer allocate a static amount of memory for messages in MD
boot path; message queues, message metadata, and message data now
all use dynamic memory, which means that runtime sysctls should now
be trivial to implement.

Since I'm going to be around all week to fix any breakage, this should
probably just go in now.


# 1.175 02-Aug-2009 beck

Dynamic buffer cache support - a re-commit of what was backed out
after c2k9

allows buffer cache to be extended and grow/shrink dynamically

tested by many, ok oga@, "why not just commit it" deraadt@


# 1.174 29-Jul-2009 kettenis

Get rid of non-equivalent aliases of the pcb by moving the fpu state out
of the pcb and using the p_addr member of 'struct proc' to calculate the
address of the kernel stack when switching to virtual mode after taking a trap.
Remove the now unecessary cache flushes; they're actually harmful since they
create non-equivalent aliases. This seems to fix the memory corruption we
have been observing from time to time.

This diff does not rename fpu_curpcb, which is now somewhat incorrectly named.
I hope to change things back again as soon as we are able to map the pcb 1:1.


Revision tags: OPENBSD_4_6_BASE
# 1.173 15-Jun-2009 beck

Back out all the buffer cache changes I committed during c2k9. This reverts three
commits:

1) The sysctl allowing bufcachepercent to be changed at boot time.
2) The change moving the buffer cache hash chains to a red-black tree
3) The dynamic buffer cache (Which depended on the earlier too).

ok on the backout from marco and todd


# 1.172 03-Jun-2009 beck

add kern.bufcachepercent sysctl to allow adjusting the buffer cache
size on a running system.
ok art@, oga@


Revision tags: OPENBSD_4_5_BASE
# 1.171 14-Feb-2009 kettenis

Limit the amount of physical memory to 2GB. Using more causes memory
corruption on PA-RISC 2.0 systems (and there are very few PA-RISC 1.1
systems that support more than 2GB).

ok miod@


# 1.170 04-Feb-2009 miod

On systems with split BTLB, do not bother trying to insert DBTLB entries,
as PDC will lie to us pretending it did while it didn't.

ok kettenis@


# 1.169 04-Feb-2009 miod

Unify memory size reports a bit more: always report size in MB, and report
reserved memory on alpha and hppa on its own line (as done on sgi).


Revision tags: OPENBSD_4_4_BASE
# 1.168 14-Jul-2008 miod

Be sure to propagate PSL_O in psw on PCXU* processors to userland processes
and signal handlers.
ok kettenis@


# 1.167 27-Jun-2008 miod

Clear swap encryption keys before dumping a kernel image.


# 1.166 09-Apr-2008 deraadt

Add new stub uvm_shutdown() and call it from the right place in MD boot()


Revision tags: OPENBSD_4_3_BASE
# 1.165 22-Sep-2007 martin

replace even more ctob and btoc with ptoa and atop respectively plus
uvm_extern.h where needed


Revision tags: OPENBSD_4_2_BASE
# 1.164 22-Jul-2007 kettenis

Move hppa to __HAVE_TIMECOUNTERS.


# 1.163 20-Jul-2007 kettenis

Give hppa the blink_led API from sparc64, and the associated machdep.led_blink
sysctl.


# 1.162 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.161 14-Jul-2007 kettenis

Make sigreturn(2) set the proper space ID for the instruction queue. Fixes
a few more pthreads regression tests.

ok miod@


# 1.160 10-Jul-2007 kettenis

Don't trust the privilige level in the sigcontext passed to sigreturn(2).

ok miod@


# 1.159 24-Jun-2007 kettenis

Crank initial storage for extents a bit. We really should allocate extents
using malloc once vm is initialised, but this will do for now.

ok deraadt@


# 1.158 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.157 27-May-2007 miod

Make sure the minaddr hint for uvm_km_suballoc() calls is always initialized.
ok pedro@


# 1.156 26-May-2007 pedro

Dynamic buffer cache. Initial diff from mickey@, okay art@ beck@ toby@
deraadt@ dlg@.


# 1.155 21-May-2007 kettenis

Add support for 8700/pcxw2 cpu.


# 1.154 21-May-2007 kettenis

Ask firmware for reset before trying ourselves; needed for four-digit b/c/j
workstations.

tested by otto@, krw@; ok deraadt@


# 1.153 17-May-2007 art

Limit hppa buffer cache to 30%. It used to be 70% because stack garbage
that was used for minaddr instead of the proper vm_map_min(kernel_map)
(fixed in this diff).

From mickey. art@ ok


# 1.152 14-May-2007 martin

move hppa to __HAVE_CPUINFO

input from miod@, ok kettenis@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.151 28-May-2006 martin

minor nit, use CPU ID instead of FPU ID for BTLB parameters after passing
all kludges


# 1.150 15-Apr-2006 martin

make warning about missing HPT support DEBUG for now

ok mickey@


Revision tags: OPENBSD_3_9_BASE
# 1.149 26-Oct-2005 martin

no more hppa_round_page() and hppa_trunc_page() macros

ok mickey@


Revision tags: OPENBSD_3_8_BASE
# 1.148 06-Aug-2005 miod

We do not need a char machine_arch[] constant.
ok deraadt@


# 1.147 11-Jul-2005 mickey

align some stupid comments


# 1.146 10-May-2005 mickey

set pcsq in case we get signal delivery once interrupted from the gateway page; from chs


# 1.145 18-Apr-2005 mickey

do not do some of the initmsgbuf()s job


# 1.144 07-Apr-2005 mickey

on some machines it's possible to limit the amount of physmem initialised dring post so having msgbuf at the end of memory shall work


# 1.143 07-Apr-2005 mickey

64bit-friendly pdc.h and iomod.h and correspondent changes elsewhere


# 1.142 26-Mar-2005 mickey

md parts for hpux_compa code; some problems w/ signals delivery still exist


Revision tags: OPENBSD_3_7_BASE
# 1.141 24-Feb-2005 mickey

do not even ask for btlb on 8k cpus as pdc pretends there is some but then it does not work; found w/ Moritz Kiese <mbk@mytum.de> on c180; add a debug print and fix pcxu entry


# 1.140 17-Nov-2004 mickey

print real/avail/bufcache sizes as unsigned


# 1.139 26-Oct-2004 mickey

disable sid hashing on pcxu and above


# 1.138 14-Oct-2004 mickey

a bit larger delays during boot() to let msgs appear


# 1.137 19-Sep-2004 mickey

turn totalphysmem into physmem and name old physmem into smth it really is


# 1.136 18-Sep-2004 mickey

oops


# 1.135 15-Sep-2004 mickey

add pcxu tlb handlers and cpu probing
add u2/uturn ioa driver in dumb mode now
enable pcxu/pcxw support


# 1.134 14-Sep-2004 mickey

store fpu version for later use. make sure to proper store/clear fpu state in fork/exec/exit/sendsig


# 1.133 14-Sep-2004 mickey

error out from btlb_insert() if there is none


Revision tags: OPENBSD_3_6_BASE
# 1.132 01-Jul-2004 mickey

have separate insn and data cache all-flushers


# 1.131 30-Jun-2004 mickey

allow forced fpu emulation through a sysctl


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.130 13-May-2004 mickey

8ks do not have hvt


# 1.129 05-May-2004 mickey

much easier tlb handler branch patching


# 1.128 05-May-2004 mickey

do not engage HPT on PCXT' (yet)


# 1.127 08-Apr-2004 mickey

repair pcxs/t confoosion


# 1.126 07-Apr-2004 mickey

update copyright; miod@ is fine w/ files where he holds it too


Revision tags: OPENBSD_3_5_BASE
# 1.125 10-Mar-2004 tom

Ensure that we obey a user's ddb> boot reboot command even if the system
is cold (during startup).

This adds RB_USERREQ to sys/reboot.h, uses it in the ddb commands, and
ensures that */*/machdep.c:boot() won't set RB_HALT when cold if this
flag is set.

ok deraadt@


# 1.124 14-Feb-2004 grange

Simplify hw.{cpuspeed,setperf} api moving all the sysctl stuff
from the underlying callbacks.

Testing hppa mickey@, ppc drahn@
Ok markus@ tedu@


# 1.123 05-Jan-2004 mickey

kill debugging code that is not needed anymore


# 1.122 23-Dec-2003 mickey

provide cpuspeed fluff


# 1.121 20-Dec-2003 miod

Don't let microtime() return a struct timeval with exactly 1000000 microseconds.


# 1.120 18-Dec-2003 mickey

spls do not protect cpu_itmr and thus time might jump back sometimes due to cpu_itmr modified to a higher value than a read itmr; found and testing by miod@


# 1.119 17-Dec-2003 mickey

in the real mem print do not include reserved for prom into used by openbsd


# 1.118 10-Dec-2003 mickey

for unaligned btlb mapping attempts -- just fail


# 1.117 24-Nov-2003 mickey

experimental support for HVT as a 2nd level tlb


# 1.116 15-Oct-2003 mickey

less global name space pollution


# 1.115 05-Oct-2003 mickey

reload the itmr as soon as we get the intr to avoid lagging on slower machines


# 1.114 25-Sep-2003 mickey

some pcxl2 do not report fpus -- assume it's there


Revision tags: OPENBSD_3_4_BASE
# 1.113 04-Sep-2003 mickey

a better cpu identification; testing by miod


# 1.112 31-Aug-2003 miod

pdc_model needs to be visible from cpu.c


# 1.111 20-Aug-2003 mickey

missing nl in debugging prontf


# 1.110 07-Aug-2003 mickey

dead proto


# 1.109 07-Aug-2003 mickey

first allocate space on stack then copyout signal shits. add a DEBUG check for a whacky user pc (as impossible due to the recent trap.c change)


# 1.108 03-Aug-2003 mickey

clear branch and nullify bits in psw on sending a signal


# 1.107 30-Jul-2003 mickey

deduce the leds address from the model number and thus make some more use of that lichtenblinkenschmutz on some more machinens


# 1.106 22-May-2003 mickey

imprecision in delay_init()


# 1.105 18-May-2003 mickey

save the fpu state for the signal handler. this is essential
as the fpu regs can be used by the gcc even for non-fpu
means and data copying.
rearrange the sigcontext a bit to include only the general
registers that are needed restoring upon return and thus
less waste of space and make up some space for the fpu regs.

ALL software that used the signal context on the stack
needs at least rebuilding now. a new snap has bin built as well.


Revision tags: UBC_SYNC_A
# 1.104 11-May-2003 deraadt

string cleaning; krw ok


# 1.103 07-Apr-2003 mickey

s/HP9000/HP 9000/; from weissmanndude


Revision tags: OPENBSD_3_3_BASE
# 1.102 18-Feb-2003 deraadt

knf; mickey ok


# 1.101 12-Feb-2003 jason

How uncommon... hppa only has one common: msgbufmapped (decl'd in /sys/kern)


# 1.100 12-Feb-2003 mickey

only align the first stack frame onto the minimal required alignment


# 1.99 10-Feb-2003 mickey

fix pcs and pcxt recognition. from weissmanndude


# 1.98 22-Jan-2003 mickey

consistantly use uvm_prot_* vs vm_prot_* evewrhere


# 1.97 14-Jan-2003 mickey

fix cutnpaste in the cpu table for the itlbna field; from herr weissmanndude


# 1.96 14-Jan-2003 mickey

need pdc_hwtlb always; pt out by herr weissmanndude


# 1.95 13-Jan-2003 mickey

fix the logic in hvt probing


# 1.94 09-Jan-2003 miod

Remove fetch(9) and store(9) functions from the kernel, and replace the few
remaining instances of them with appropriate copy(9) usage.

ok art@, tested on all arches unless my memory is non-ECC


# 1.93 19-Dec-2002 mickey

setregs: put the whole frame setup into one place


# 1.92 19-Dec-2002 mickey

level 0x16 is really an l2


# 1.91 17-Dec-2002 millert

Make SysV-style shared memory and semaphore limits sysctl'able.
Instead of allocating a static amount of memory for the data
structures via valloc() in allocsys(), allocate things dynamically
using pool(9) when possible and malloc(9) when not. The various
members of struct seminfo and struct shminfo are in kern.seminfo
and kern.shminfo respectively (not all members of kern.seminfo are
changable).

The data structures used still leave something to be desired but
things are not made worse in that respect by this commit.


# 1.90 27-Nov-2002 mickey

no wrapper arounf hardclock(), use CPU_CLOCKUPDATE, real microtime; miod ok


# 1.89 08-Nov-2002 mickey

Don't uvm_useracc the user sigcontext in sys_sigreturn and then access
the user addresses directly from the kernel. copyin is faster and can
correctly deal properly with mappings that uvm_useracc thinks are
correct but will fault anyway (to figure out how to generate such
mappings is left as en excercise for the reader).


# 1.88 01-Nov-2002 mickey

add a missing delay after printf on halt[-p], proper arg for a cold hook


Revision tags: UBC_SYNC_B
# 1.87 22-Oct-2002 mickey

do not force single-user; pt out by fries@


# 1.86 15-Oct-2002 mickey

missing initmsgbuf(), noticed by miod@


# 1.85 13-Oct-2002 mickey

track the end of physmem for use in dmmem_alloc


# 1.84 07-Oct-2002 mickey

s/PSW_/PSL_/ to match other archs


# 1.83 07-Oct-2002 mickey

proper terminate the user stack on signal


# 1.82 07-Oct-2002 mickey

on implementations w/ fpu included unimplemented instructions
are signaled through the exception trap w/ invalid opcode marked
instruction in the exception registers, not through the emulation
trap (as long as the fpu is enabled, of course).
parse emulation from the exception trap as well as the emulation
trap and fix the dispatcher into usable condition.
parse invalid op exception on trap and signal the user appropriately.
reset the exception on exec and for child on fork.
the later is appropriate since exceptions are delayed until next
fpu instruction, which was in the parent indeed, let him get it.
save parent's fpu context on fork before cipying it, if the
parent owned the fpu.


Revision tags: OPENBSD_3_2_BASE
# 1.81 23-Sep-2002 mickey

parisc level 0x10 is just an overclocked 0xe


# 1.80 17-Sep-2002 mickey

handle fpu exceptions properly, might use a regress, i guess


# 1.79 11-Sep-2002 mickey

provide a convinient reset label


# 1.78 11-Sep-2002 mickey

stack grows the other way, but the frame is the other way to that. hehe


# 1.77 09-Sep-2002 mickey

set up the frame flags and a user frame better on exec


# 1.76 03-Aug-2002 mickey

rework boot() w/o a goto


# 1.75 25-Jul-2002 mickey

missing arg in the call to the pdc_call since some old times


# 1.74 25-Jul-2002 mickey

kcopy is a space-to-space copy from kernel space, to guess where, -- to the same kernel space, just error on fault


# 1.73 20-Jul-2002 art

Instead of copying out the signal trampoline on top of the stack, create
an uvm aobj, copy out the signal trampoline into it and share that page
among all processes for the same emulation.

This also requires us to actually be able to tell signal code where the
trampoline is located, so introduce a new field in struct proc - p_sigcode
that is a pointer to sigcode. This allows us to remove all the ugly
calculations of the signal trampoline address done in every sendsig
function in the tree (that's why so many files are changed).

Tested by various people. ok deraadt@


# 1.72 14-May-2002 mickey

disable sid hashing while still in real mode, alos print the parisc arch once and not per each cpu since they are not intermixable architecture-wise


# 1.71 13-May-2002 mickey

ldi-ldo whatever was in the table, be that much clever


# 1.70 08-May-2002 mickey

print parisc level w/ the the parisc version, not for each cpu


# 1.69 08-May-2002 mickey

kill debugging printfski


# 1.68 22-Apr-2002 mickey

no longer batc the data, only the code.
this removes a constraint and an ld.script dependancy
for the .data and the dynamically allocated kernel
structures existed w/ batcing. also makes pmap_steal_memory
obsolete and replaced w/ the pmap_virtual_space.
implement batching for pmap_remove to avoid
zeroing out the pte entries if pde will be removed anyway.


# 1.67 21-Apr-2002 mickey

better buf's mapping and less magic constants in checking for io space cachability


Revision tags: OPENBSD_3_1_BASE
# 1.66 26-Mar-2002 mickey

if cannot guess cpu model default to the lowest supported one


# 1.65 25-Mar-2002 deraadt

spelling


# 1.64 23-Mar-2002 espie

Add variables for config(8) -e time tweak of systemV shared memory
parameters.

Ok millert@, miod@, maja@


# 1.63 19-Mar-2002 mickey

mtcpu seq requires a pre-sync, implement hpt init for pcxl


# 1.62 15-Mar-2002 mickey

rewrite a pmap to use multilevel page tables.
lower 12 bits contain the perms, no unused bits left,
but a couple for off-tlb use (as the ref implemented now).
do not use the hvt, which might get some use later
if proven to speed thigs up, tlb handlers would po
another dozen of insns though, but if that's worth its...
move on the data seg and map kernel text rdonly (idea form fredette),
since all of the page0 mods done before that we are all fine
except for some viper fluff, but later w/ that.
this also picks up a bit more of ddb magic for bpt and ss.
tlb handlers can use a little bit more of attention,
but things, visually, seem to be much faster already, --
sorry, no benchmarks for now.

* effort sponsored in part by the `henry st. old ale house'
* and mr.pete and mr.lee in particular in thier generous entrirety.
* the proj took a little more that 72man*h as it was expected,
* but within murhy's law estimations.


# 1.61 14-Mar-2002 millert

First round of __P removal in sys


# 1.60 20-Feb-2002 mickey

setup power failure handler (for sw-controlled power button), move toc handler


# 1.59 17-Feb-2002 maja

Patch from Daniel Lucq <daniel@lucq.org>

The patch allows you to change the value of NMBCLUSTERS, BUFCACHEPERCENT
and NKMEMPAGES using the config command, instead of recompiling the kernel.

This is the kernel part of the patch. I have compiled it on i386, sparc64,
alpha and macppc. -moj ok art@ maja@


# 1.58 12-Feb-2002 mickey

support 712's programmable power switch, no interrupt yet


# 1.57 12-Feb-2002 mickey

small repairs to hpmc and toc handlers


# 1.56 11-Feb-2002 mickey

disable fpu on csw, print fpu version on cpu line, if present


# 1.55 07-Feb-2002 mickey

fix sigdebug cases; init sigcontext before it's used (;


# 1.54 06-Feb-2002 mickey

implement signal delivery; based on fredette@'s work


# 1.53 03-Feb-2002 mickey

restore hpt size computation, does not break things as i thought


# 1.52 02-Feb-2002 mickey

fix 'physmem' usage


# 1.51 02-Feb-2002 mickey

implement the rest of /dev/mem devices; from netbsd


# 1.50 23-Jan-2002 art

move mb_map allocation to mbinit()


# 1.49 23-Jan-2002 art

move definition of mb_map from zillions of machdep.c to uipc_mbuf.c


# 1.48 16-Jan-2002 miod

Don't include <sys/map.h> when you don't need what's in it.


Revision tags: UBC_BASE
# 1.47 02-Dec-2001 mickey

branches: 1.47.2;
increase fixed extent storage


# 1.46 28-Nov-2001 art

zap some typedefs.
vm_map_t -> struct vm_map *
vm_map_entry_t -> struct vm_map_entry *
simple_lock_data_t -> struct simplelock

(uvm not done yet, coming in the next commit)


# 1.45 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.44 24-Nov-2001 miod

Harmonize boot() logic across arches:
- ensure RB_DUMP | RB_HALT will cause a dump
- or RB_HALT if (cold)
While there, honor RB_TIMEBAD on sparc64.


# 1.43 09-Nov-2001 art

nswbuf hasn't been used for ages. gc.


# 1.42 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.41 06-Nov-2001 miod

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


Revision tags: OPENBSD_3_0_BASE
# 1.40 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.39 12-Sep-2001 art

mbutl no more


# 1.38 23-Aug-2001 art

We can now move timeout_init into main().


# 1.37 23-Aug-2001 art

Remove even more old timeout tentacles.


# 1.36 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.35 05-Jul-2001 art

Get rid of REAL_CLISTS. It was never implemented and the tentacles are
everywhhere.


# 1.34 17-May-2001 provos

convert mbuf and cluster allocation to pool, mostly from NetBSD
okay art@ miod@


# 1.33 05-May-2001 art

Rename configure() to cpu_configure().
Move it from cpu_startup() to main().


# 1.32 05-May-2001 art

Get rid of CLSIZE and all related stuff.
CLSIZE -> 1
CLBYTES -> PAGE_SIZE
OLOFSET -> PAGE_MASK
etc.
At the same time some archs needed some cleaning in vmparam.h so that
goes in at the same time.


Revision tags: OPENBSD_2_9_BASE
# 1.31 29-Mar-2001 mickey

cpudev_data.h here needed not


# 1.30 22-Mar-2001 mickey

shuffle the tlb handlers a little,
make a new one for na data fault,
since those w/ hpt need it.


Revision tags: OPENBSD_2_8_BASE
# 1.29 15-Aug-2000 mickey

two btlb routines (i & d) for pcxs


# 1.28 15-Aug-2000 mickey

expand per-cpu control routines switch


# 1.27 08-Aug-2000 mickey

print btlb params w/ BTLBDEBUG; from Havard.Eidnes@runit.sintef.no


# 1.26 02-Jul-2000 mickey

no bays for stinger


Revision tags: OPENBSD_2_7_BASE
# 1.25 23-Mar-2000 mickey

new cpu type switch code.
initializes tlb miss handlers correspondent to probed cpu features.
also btlb load routine.
versions written are for pcxl and others.
cpu-dep btlb loaders are missing, only generic for now.


# 1.24 23-Mar-2000 art

New API for timeouts. Replaces the old timeout()/untimeout() API and
makes it the callers responsibility to allocate resources for the
timeouts.

This is a KISS implementation and does _not_ solve the problems of slow
handling of a large number of pending timeouts (this will be solved in
future work) (although hardclock is now guarateed to take constant time
for handling of timeouts).

Old timeout() and untimeout() are implemented as wrappers around the new
API and kept for compatibility. They will be removed as soon as all
subsystems are converted to use the new API.


# 1.23 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


# 1.22 22-Feb-2000 mickey

blah, blah, blah, msgbuf


Revision tags: SMP_BASE
# 1.21 09-Feb-2000 mickey

branches: 1.21.2;
heartbeat -- yeah we have a patch for that


# 1.20 25-Jan-2000 mickey

better copy and zero inlines in locore;
proper setregs() in machedep;
start of hpmc handler;
some cleanup here and there;


# 1.19 17-Jan-2000 mickey

remove unneeded stuff from setregs; force single-user for now, enable signal debug


# 1.18 11-Jan-2000 mickey

s/fpu_curproc/fpu_curpcb/ which also points into physical.
move it's definition into locore (where it's used the most).
adjust fpu context switch and save on swapout accordingly.
fix context save (in switch).
add accounting for fpu context switches (since it differes
from proc switching, we might get provided w/ some usefull
numbers as to how effective this lazy switch technique is).
enable handling fpu/sfu exceptions.


# 1.17 31-Dec-1999 mickey

don't bother about pidr3 and pidr4


# 1.16 17-Dec-1999 mickey

fix the panic message for sti memory mapping


Revision tags: kame_19991208
# 1.15 25-Nov-1999 mickey

bus stuff is in mainbus now, the rest is rewritten many ways


Revision tags: OPENBSD_2_6_BASE
# 1.14 20-Sep-1999 mickey

fix uvm_pagealloc() call


# 1.13 03-Sep-1999 art

Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.12 14-Aug-1999 mickey

proper debugging ifdefs


# 1.11 21-Jul-1999 mickey

rewrite the tlb miss handler and tlb dirty handler.
optimize for HVT usage (when compiled for proper cpu type).
drop hpt_* global variables, use info from control registers instead.
there are still ways to improve the tlb handlers tho.
machdep also prints cache and tlb coherence states (not related to the above).
You eat greenish muffin. --More-- You write real code.


# 1.10 12-Jul-1999 mickey

allocate 5% bufcache if <=16M memory installed


# 1.9 12-Jun-1999 mickey

hppa_init() now takes an argument from locore,
meaning the start of available memory.
cleanup machdep somewhat.
fix vm_map.pmap vs vm_pmap isue; 10x art@


# 1.8 23-May-1999 mickey

new swap stuff


# 1.7 21-May-1999 mickey

group all theMD f;ags together, add interrupt recursion one


# 1.6 21-May-1999 mickey

define fpu_curproc


# 1.5 20-Apr-1999 mickey

do lazy blok mapping of io space in bus_*
add copy{in,out}*, kcopy, etc
boot routines
cpu-id-hpux-compat stuff
rest of scheduler and such
uvm


Revision tags: OPENBSD_2_5_BASE
# 1.4 17-Feb-1999 mickey

print pa-risc here as well, since, finally, cpu will have to print processor type


# 1.3 04-Jan-1999 mickey

better cache handling in bus_space_barrier(), seem to work now


# 1.2 03-Jan-1999 mickey

implement bus_space_{un,}map w/ extents


# 1.1 30-Dec-1998 mickey

machdep; more work needed


# 1.269 14-Apr-2024 jsg

with empty body loops, put final semicolon on a new line for readability
ok bluhm@ jca@


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

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


# 1.267 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_7_2_BASE
# 1.266 10-Aug-2022 jsg

match other archs use %s for version printf


Revision tags: OPENBSD_7_1_BASE
# 1.265 06-Oct-2021 claudio

Change sendsig() interface so that the MD code does not need to access
data from struct process anymore. This changes how siginfo and onstack
are accessed and make sendsig() more MP friendly.
With and OK semarie@ OK kettenis@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.264 11-Mar-2021 jsg

spelling


# 1.263 09-Jan-2021 kettenis

"encoding of diag instructions is hard, let's go shopping"

Clean up things a bit, adding documentation about the source of the
information about these instructions.

From miod@


# 1.262 08-Nov-2020 mpi

In case of failure, call sigexit() from trapsignal instead of sensig().

Simplify MD code and reduce the amount of recursion into the signal code
which helps when dealing with locks.

ok cheloha@, deraadt@


# 1.261 21-Oct-2020 deraadt

hppa also has a similar to arm64: copyout(9), copyinstr(9) and
copyoutstr(9) should bail out properly if they are called with a
length of 0.
ok kettenis@


Revision tags: OPENBSD_6_8_BASE
# 1.260 14-Jun-2020 naddy

Implement cpu_rnd_messybits() as a read of the cycle counter register.
ok dlg@ deraadt@


# 1.259 31-May-2020 dlg

introduce "cpu_rnd_messybits" for use instead of nanotime in dev/rnd.c.

rnd.c uses nanotime to get access to some bits that change quickly
between events that it can mix into the entropy pool. it doesn't
use nanotime to get a monotonically increasing set or ordered and
accurate timestamps, it just wants something with bits that change.

there's been discussions for years about letting rnd use a clock
that's super fast to read, but not necessarily accurate, but it
wasn't until recently that i figured out it wasn't interested in
time at all, so things like keeping a fast clock coherent between
cpu cores or correct according to ntp is unecessary. this means we
can just let rnd read the cycle counters on cpus and things will
be fine. cpus with cycle counters that vary in their speed and
arent kept consistent between cores may even be desirable in this
context.

so this is the first step in converting rnd.c to reading cycle
counter. it copies the nanotime backend to each arch, and they can
replace it with something MD as a second step later on.

djm@ suggested rnd_messybytes, but we landed on cpu_rnd_messybits.
thanks to visa for his eyes.
ok deraadt@ visa@
deraadt@ says he will help handle any MD fallout that occurs.


# 1.258 16-May-2020 kettenis

Make inittodr() and resettodr() MI.

ok deraadt@, mpi@, visa@
ok cheloha@ as well (would have preferred in new file for this code)


# 1.257 11-May-2020 kettenis

Initialize the timeval passed to todr_gettime() with the base time from
the file system such that implementations can use it to guess the right
century.

ok mpi@


Revision tags: OPENBSD_6_7_BASE
# 1.256 01-May-2020 kettenis

Use the same inittodr()/resettodr() implementation as on
amd64/arm64/armv7/i386/sparc64 and move it to the end of machdep.c. Rework the
actual implementation for the MC14818 compatible RTC into something that can
be used as a todr_handle just like on amd64.

ok mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.255 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


Revision tags: OPENBSD_6_4_BASE
# 1.254 20-Jul-2018 guenther

Missed a 'ksi' -> '*ksip' change in previous commit


# 1.253 10-Jul-2018 guenther

Move from sendsig() to its callers the initsiginfo() calls and
instead of passing sendsig() the code+type+val, pass a siginfo_t*
to copy from. Eliminate the indirection through struct emul for
sendsig(); we no longer have a SunOS4-compat version of sendsig()

ok deraadt@


# 1.252 22-May-2018 guenther

Delete antique sigdebug definitions

ok kettenis@


# 1.251 12-Apr-2018 deraadt

Implement MAP_STACK option for mmap(). Synchronous faults (pagefault and
syscall) confirm the stack register points at MAP_STACK memory, otherwise
SIGSEGV is delivered. sigaltstack() and pthread_attr_setstack() are modified
to create a MAP_STACK sub-region which satisfies alignment requirements.
Observe that MAP_STACK can only be set/cleared by mmap(), which zeroes the
contents of the region -- there is no mprotect() equivalent operation, so
there is no MAP_STACK-adding gadget.
This opportunistic software-emulation of a stack protection bit makes
stack-pivot operations during ROPchain fragile (kind of like removing a
tool from the toolbox).
original discussion with tedu, uvm work by stefan, testing by mortimer
ok kettenis


Revision tags: OPENBSD_6_3_BASE
# 1.250 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.249 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


Revision tags: OPENBSD_6_2_BASE
# 1.248 18-May-2017 kettenis

Implement copyin32(9).

"your chicken scratches look fine to me" deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.247 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

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


# 1.246 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.245 21-May-2016 deraadt

hand-massage sendsig() and sys_sigreturn() to be much more similar.
ok guenther kettenis


# 1.244 10-May-2016 deraadt

SROP mitigation. sendsig() stores a (per-process ^ &sigcontext) cookie
inside the sigcontext. sigreturn(2) checks syscall entry was from the
exact PC addr in the (per-process ASLR) sigtramp, verifies the cookie,
and clears it to prevent sigcontext reuse.
not yet tested on landisk, sparc, *88k, socppc.
ok kettenis


# 1.243 20-Apr-2016 dlg

pool_setipl for floating point context things

ok kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.242 21-Oct-2015 mpi

Do not call uvm_swap_finicrypt_all() a second time in dumpsys().

ok tedu@, deraadt@, miod@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.241 20-Jan-2015 kettenis

Move ps_strings "after" the random stackgap. This makes its location a
per-process value, and therefpore turns the VM_PSSTRINGS sysctl into a
per-process one as well. This gets rid of a pointer to the bottom of the
stack at a fixed location. Also clears the road for unmapping the stackgap.

ok deraadt@


# 1.240 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.239 25-Oct-2014 kettenis

Remove vmmap; it isn't used.

ok jsing@


# 1.238 23-Oct-2014 miod

Correctly set up the HPMC trap entry: according to the PA-RISC Firmware
Architecture Reference Specification, the sum of the 8 trap entry words
*and* of the payload which address and length are to be set at well-known
positions in the aforementioned trap entry, needs to be zero; the existing
code was only enforcing that the sum of the trap entry words is zero.

This matches what Linux and NetBSD do.

ok kettenis@


# 1.237 23-Oct-2014 miod

Revert limiting physmem to 2GB; the culprit was likely in uvm and uvm has
changed a lot in the last 5 years; verified to work on a 3GB system, in
snapshots for a few weeks already.


# 1.236 22-Sep-2014 dlg

implement atomic_{cas,swap}_{uint,ulong,ptr} and
atomic_{add,sub}_{int,long}_nv. sys/atomic.h turns these into the
rest of the atomic api.

on uniprocessor hppa systems "atomic" operations are implemented
as a non-interruptable sequence by disabling all interrupts on the
cpu, doing the operation, and then restoring the interrupt mask.

this isnt enough on MP systems, so we added a global atomic memory
mutex that is taken inside the interrupt disabling above to coordinate
operations between cpus.

this is a lot of overhead though cos mutexes dance around with ipls,
which is unecessary in our case because of the interrupt disabling
that is already done. also, hppa spinlocks are implemented with
ldcw which requires the word it operates on to be 16 byte aligned.
mutexes arent guaranteed to have this alignment so they compensate
by having lots of words inside themselves so they can hit the
appropriate one to use for the ldcw op.

with this in mind, this change pulls __cpu_simple_locks, which are
simply ldcw spinlocks with a 16 byte aligned word, out of
src/sys/arch/hppa/include/lock.h into src/sys/arch/hppa/include/atomic.h
so atomic.h can use them. lock.h includes atomic.h, so it still
gets and provides the same functionality as before.

finally, this also pulls the rwlock cas implementation apart. cas
ops now share the same serialising lock on MP systems as the other
memory operations, and rw_cas is defined as a wrapper around
atomic_cas_uint.

ok kettenis@


# 1.235 19-Sep-2014 kettenis

Use config_suspend_all(9).


# 1.234 18-Aug-2014 dlg

dont rely on mbuf.h to provide pool.h.

ok miod@, who has offerred to help with any MD fallout
ok guenther@


Revision tags: OPENBSD_5_6_BASE
# 1.233 22-Jul-2014 uebayasi

boot(9): Reduce diffs between hppa & hppa64 (& others)


# 1.232 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.231 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.230 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.229 13-Jul-2014 miod

These still need <sys/reboot.h> for the RB_ constants.


# 1.228 12-Jul-2014 uebayasi

reboot(9), panic(9): Call panic(9) for unrecoverable MD H/W errors (NMIs)

Some architectures have ability to detect hardware sanity and notify system
(NMI, firmware callback, etc.). Handle these hardware severe errors, same
as software errors, with panic(9).

According to miod@, SGI IP27 NMI is triggered by pushing some "hidden" button,
which "usual" users/admins don't know. Pushing such a button is "RB_USERREQ"
(human-triggered) in that the button is pushed by a human, but not "RB_USERREQ"
in that no user intervention in system (== no command input) is done. miod@
agreed that changing these from RB_USERREQ to !RB_USERREQ (== panic(9)) is
not a big problem.

OK miod@ kettenis@


# 1.227 12-Jul-2014 uebayasi

boot(9), reboot(9): Migrate MD callers of boot(9) to reboot(9)

I have found that some ports call boot(9) from machine-dependent code to
reboot system. These should be changed to either:

- Sending signal to init(8) to trigger it to shutdown system cleanly, like
acpi(4) does, in cases where found problems don't prevent system from working
immediately, or

- Just doing panic(9) if the situation is severely broken.

For now, just rewrite boot() to reboot(). Actual fixes follow.

Discussed with & OK from kettenis@


# 1.226 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.225 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.224 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.223 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.222 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.221 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.220 08-May-2014 miod

Format string fixes and removal of -Wno-format for hppa kernels.


# 1.219 08-Apr-2014 mpi

Less <uvm/uvm.h>


# 1.218 04-Apr-2014 miod

If the PDC_COPROC call fails, and we are running on a PA 1.1 system, assume
the usual 1.1 coprocessor mask, instead of using zero and having every
userland process dying with signal 4.

The circumstances under which this call fails are unclear and could be
tied to specific PROM version (I have tried overzealous stack alignment and
other tricks, to no avail). Interestingly enough, the 715/75 system which
hits this problem, only triggers it when booting from disk, and never when
booting from network.

This diff is an ugly bandaid until the problem is better understood. Or maybe
it is not worth investigating, seeing that Linux hardcodes the coprocessor
mask and never issues PDC_COPROC calls; I wonder what HP/UX does.

In my tree for over 18 months; "Looks like a nice hack" deraadt@
715/75 system provided by Sebastiaan Indesteege, thanks!


# 1.217 29-Mar-2014 guenther

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

ok dlg@ mpi@ deraadt@


# 1.216 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


# 1.215 22-Mar-2014 guenther

Move p_sigacts from struct proc to struct process.

testing help mpi@


# 1.214 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


Revision tags: OPENBSD_5_5_BASE
# 1.213 23-Nov-2013 uebayasi

Run doshutdownhooks() and config_suspend() even when boot() is called while
cold != 0. Indent and make hppa/hppa64 boot() closer to others.

OK kettenis@


# 1.212 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


Revision tags: OPENBSD_5_4_BASE
# 1.211 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


Revision tags: OPENBSD_5_3_BASE
# 1.210 02-Dec-2012 guenther

Determine whether we're currently on the alternative signal stack
dynamically, by comparing the stack pointer against the altstack
base and size, so that you get the correct answer if you longjmp
out of the signal handler, as tested by regress/sys/kern/stackjmp/.
Also, fix alt stack handling on vax, where it was completely broken.

Testing and corrections by miod@, krw@, tobiasu@, pirofti@


# 1.209 26-Oct-2012 kettenis

Properly clear trap frame in setregs() to avoid leaking registers across exec.

ok jsing@


# 1.208 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.207 07-Oct-2012 kettenis

Align the stack on a 64-byte boundary as required by "The 32-bit PA-RISC
Run-time Architecture Document". GCC relies on this to properly align
stack variables.

ok guenther@, beck@


Revision tags: OPENBSD_5_2_BASE
# 1.206 21-Jun-2012 guenther

__tfork() needs to set the stack address of the new thread in the kernel,
so that it can't get a signal while still running on the parent thread's
stack. Also, pass in sizeof(struct __tfork) to provide forward compat
when more members are added. This is an ABI change, so switch syscall
numbers and bump lib majors this time.

ok deraadt@ matthew@


Revision tags: OPENBSD_5_1_BASE
# 1.205 20-Sep-2011 miod

Clear RB_POWERDOWN early in boot() on systems which can not powerdown and
which firmware does not send spin up commands to the disks, in case the
operator changes his mind and reboots instead of manually powering down
after the system has halted.
ok kettenis@


Revision tags: OPENBSD_5_0_BASE
# 1.204 05-Jul-2011 guenther

Recommit the reverted sigacts change now that the NFS use-after-free
problem has been tracked down. This fixes the sharing of the signal
handling state: shared bits go in sigacts, per-rthread bits goes in
struct proc.

ok deraadt@


# 1.203 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.202 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.201 18-Apr-2011 guenther

Revert the sigacts diff: NFS can apparently retain pointers to processes
until they're zombies and then send them signals (for intr mounts). Until
that is untangled, the sigacts change is unsafe. sthen@ was the victim
for this one


# 1.200 15-Apr-2011 guenther

Correct the sharing of the signal handling state: stuff that should
be shared (p_sigignore, p_sigcatch, P_NOCLDSTOP, P_NOCLDWAIT) moves
to struct sigacts, wihle stuff that should be per rthread (ps_oldmask,
SAS_OLDMASK, ps_sigstk) moves to struct proc. Treat the coredumping
state bits (ps_sig, ps_code, ps_type, ps_sigval) as per-rthread
until our locking around coredumping is better.

Oh, and remove the old SunOS-compat ps_usertramp member.

"I like the sound of this" tedu@


Revision tags: OPENBSD_4_9_BASE
# 1.199 14-Jan-2011 jsing

Halt secondary CPUs when shutting down or rebooting. This should prevent
occasional hangs during reboot.

ok kettenis@


# 1.198 04-Jan-2011 jasper

- de-register. no binary change.

ok jsing@


# 1.197 01-Jan-2011 jasper

Move setting cpu_hzticks to the clock initialization function, like
other ports (e.g. hppa64) do.

ok jsing@ kettenis@


# 1.196 01-Jan-2011 jasper

- ansify

ok jsing@ kettenis@


# 1.195 30-Dec-2010 jsing

Turn signotify() into a function that also calls cpu_unidle().

ok kettenis@


# 1.194 20-Nov-2010 miod

This is a first step towards getting rid of avail_start and avail_end in the
kernel, currently limited to low-hanging fruit: these variables were used
by bus_dma to specify the range in which to allocate memory, back when
uvm_pglistalloc() was stupid and would not walk the vm_physseg[].

Nowadays, except on some platforms for early initialization, these variables
are not used, or do not need to be global variables. Therefore:
- remove `extern' declarations of avail_start and avail_end (or close cousins,
such as arm physical_start and physical_end) from files which no longer need
to use them.
- make them local variables whenever possible.
- remove them when they are assigned to but no longer used.


Revision tags: OPENBSD_4_8_BASE
# 1.193 01-Jul-2010 jsing

Create a struct to store FP state and include a pointer to the CPU that
currently holds the FPU context for this process. This will be soon used
to implement FPU shootdowns on multiprocessor kernels.

ok kettenis@


# 1.192 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.191 29-Jun-2010 jsing

Factor out code used to save and flushe process FPU context.

ok kettenis@


# 1.190 29-Jun-2010 jsing

Store pointer to process FPU state in struct cpu_info.

ok kettenis@


# 1.189 27-Jun-2010 thib

uvm constraints. Add two mandatory MD symbols, uvm_md_constraints
which contains the constraints for DMA/memory allocation for each
architecture, and dma_constraints which contains the range of addresses
that are dma accessable by the system.

This is based on ariane@'s physcontig diff, with lots of bugfixes and
additions the following additions by my self:

Introduce a new function pool_set_constraints() which sets the address
range for which we allocate pages for the pool from, this is now used
for the mbuf/mbuf cluster pools to keep them dma accessible.

The !direct archs no longer stuff pages into the kernel object in
uvm_km_getpage_pla but rather do a pmap_extract() in uvm_km_putpages.

Tested heavily by my self on i386, amd64 and sparc64. Some tests on
alpha and SGI.

"commit it" beck, art, oga, deraadt
"i like the diff" deraadt


# 1.188 27-Jun-2010 jsing

Use a mutex to make atomic operations atomic on multiprocessor kernels.

ok kettenis@


# 1.187 10-Jun-2010 deraadt

Declare safepri at the MD level on each platform, so that the kern_synch.c
does not have to deal with it as a common. Some platforms may be missed
by this commit... if you spot one, fix it the same way.
ok miod


# 1.186 09-Jun-2010 miod

Move declaration of cn_tab from dev/cons.c to dev/cninit.c, or appropriate
md files for ports which do not use dev/cninit.c. This gets rid of a common
at kernel link time.
feedback drahn@ ok deraadt@


# 1.185 24-May-2010 deraadt

Add missing prototypes
ok jsing kettenis


# 1.184 09-May-2010 kettenis

Prevent "taken branch" exceptions from kernel space by clearing the PSL_T
bit before we enter a signal handler.

"if you say so" miod@, "seems to make sense" jsing@


# 1.183 02-May-2010 kettenis

Properly initialize the members of `struct mdproc' that deal with
single-stepping when we fork and reset them upon exec.

ok miod@


# 1.182 27-Apr-2010 kettenis

Avoid null-pointer dereference by giving proc0 a place to store its
floating-point registers. Pointed out by Nick Hudson.

ok miod@, jsing@


# 1.181 19-Apr-2010 jsing

Make the Processor Status Word (PSW) a per-CPU value.

ok kettenis@


# 1.180 01-Apr-2010 jsing

Allow for multiple CPUs by moving to an array of cpu_info.

ok kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.179 31-Dec-2009 jsing

Make cpl and cpu_inintr per CPU variables. For locore.S, cpl becomes an
offset within cpu_primary_info - this will need to be revisited shortly.

ok kettenis@


# 1.178 11-Aug-2009 miod

Do not bother initializing bufpages in the md code if the computation is
exactly the same the mi could will use if bufinit() is invoked with
bufpages == 0.


# 1.177 11-Aug-2009 miod

With the SysV memory allocation changes, allocsys() doesn't do anything
anymore. Get rid of it completely.


# 1.176 09-Aug-2009 blambert

Rototill system V message queues.

No longer allocate a static amount of memory for messages in MD
boot path; message queues, message metadata, and message data now
all use dynamic memory, which means that runtime sysctls should now
be trivial to implement.

Since I'm going to be around all week to fix any breakage, this should
probably just go in now.


# 1.175 02-Aug-2009 beck

Dynamic buffer cache support - a re-commit of what was backed out
after c2k9

allows buffer cache to be extended and grow/shrink dynamically

tested by many, ok oga@, "why not just commit it" deraadt@


# 1.174 29-Jul-2009 kettenis

Get rid of non-equivalent aliases of the pcb by moving the fpu state out
of the pcb and using the p_addr member of 'struct proc' to calculate the
address of the kernel stack when switching to virtual mode after taking a trap.
Remove the now unecessary cache flushes; they're actually harmful since they
create non-equivalent aliases. This seems to fix the memory corruption we
have been observing from time to time.

This diff does not rename fpu_curpcb, which is now somewhat incorrectly named.
I hope to change things back again as soon as we are able to map the pcb 1:1.


Revision tags: OPENBSD_4_6_BASE
# 1.173 15-Jun-2009 beck

Back out all the buffer cache changes I committed during c2k9. This reverts three
commits:

1) The sysctl allowing bufcachepercent to be changed at boot time.
2) The change moving the buffer cache hash chains to a red-black tree
3) The dynamic buffer cache (Which depended on the earlier too).

ok on the backout from marco and todd


# 1.172 03-Jun-2009 beck

add kern.bufcachepercent sysctl to allow adjusting the buffer cache
size on a running system.
ok art@, oga@


Revision tags: OPENBSD_4_5_BASE
# 1.171 14-Feb-2009 kettenis

Limit the amount of physical memory to 2GB. Using more causes memory
corruption on PA-RISC 2.0 systems (and there are very few PA-RISC 1.1
systems that support more than 2GB).

ok miod@


# 1.170 04-Feb-2009 miod

On systems with split BTLB, do not bother trying to insert DBTLB entries,
as PDC will lie to us pretending it did while it didn't.

ok kettenis@


# 1.169 04-Feb-2009 miod

Unify memory size reports a bit more: always report size in MB, and report
reserved memory on alpha and hppa on its own line (as done on sgi).


Revision tags: OPENBSD_4_4_BASE
# 1.168 14-Jul-2008 miod

Be sure to propagate PSL_O in psw on PCXU* processors to userland processes
and signal handlers.
ok kettenis@


# 1.167 27-Jun-2008 miod

Clear swap encryption keys before dumping a kernel image.


# 1.166 09-Apr-2008 deraadt

Add new stub uvm_shutdown() and call it from the right place in MD boot()


Revision tags: OPENBSD_4_3_BASE
# 1.165 22-Sep-2007 martin

replace even more ctob and btoc with ptoa and atop respectively plus
uvm_extern.h where needed


Revision tags: OPENBSD_4_2_BASE
# 1.164 22-Jul-2007 kettenis

Move hppa to __HAVE_TIMECOUNTERS.


# 1.163 20-Jul-2007 kettenis

Give hppa the blink_led API from sparc64, and the associated machdep.led_blink
sysctl.


# 1.162 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.161 14-Jul-2007 kettenis

Make sigreturn(2) set the proper space ID for the instruction queue. Fixes
a few more pthreads regression tests.

ok miod@


# 1.160 10-Jul-2007 kettenis

Don't trust the privilige level in the sigcontext passed to sigreturn(2).

ok miod@


# 1.159 24-Jun-2007 kettenis

Crank initial storage for extents a bit. We really should allocate extents
using malloc once vm is initialised, but this will do for now.

ok deraadt@


# 1.158 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.157 27-May-2007 miod

Make sure the minaddr hint for uvm_km_suballoc() calls is always initialized.
ok pedro@


# 1.156 26-May-2007 pedro

Dynamic buffer cache. Initial diff from mickey@, okay art@ beck@ toby@
deraadt@ dlg@.


# 1.155 21-May-2007 kettenis

Add support for 8700/pcxw2 cpu.


# 1.154 21-May-2007 kettenis

Ask firmware for reset before trying ourselves; needed for four-digit b/c/j
workstations.

tested by otto@, krw@; ok deraadt@


# 1.153 17-May-2007 art

Limit hppa buffer cache to 30%. It used to be 70% because stack garbage
that was used for minaddr instead of the proper vm_map_min(kernel_map)
(fixed in this diff).

From mickey. art@ ok


# 1.152 14-May-2007 martin

move hppa to __HAVE_CPUINFO

input from miod@, ok kettenis@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.151 28-May-2006 martin

minor nit, use CPU ID instead of FPU ID for BTLB parameters after passing
all kludges


# 1.150 15-Apr-2006 martin

make warning about missing HPT support DEBUG for now

ok mickey@


Revision tags: OPENBSD_3_9_BASE
# 1.149 26-Oct-2005 martin

no more hppa_round_page() and hppa_trunc_page() macros

ok mickey@


Revision tags: OPENBSD_3_8_BASE
# 1.148 06-Aug-2005 miod

We do not need a char machine_arch[] constant.
ok deraadt@


# 1.147 11-Jul-2005 mickey

align some stupid comments


# 1.146 10-May-2005 mickey

set pcsq in case we get signal delivery once interrupted from the gateway page; from chs


# 1.145 18-Apr-2005 mickey

do not do some of the initmsgbuf()s job


# 1.144 07-Apr-2005 mickey

on some machines it's possible to limit the amount of physmem initialised dring post so having msgbuf at the end of memory shall work


# 1.143 07-Apr-2005 mickey

64bit-friendly pdc.h and iomod.h and correspondent changes elsewhere


# 1.142 26-Mar-2005 mickey

md parts for hpux_compa code; some problems w/ signals delivery still exist


Revision tags: OPENBSD_3_7_BASE
# 1.141 24-Feb-2005 mickey

do not even ask for btlb on 8k cpus as pdc pretends there is some but then it does not work; found w/ Moritz Kiese <mbk@mytum.de> on c180; add a debug print and fix pcxu entry


# 1.140 17-Nov-2004 mickey

print real/avail/bufcache sizes as unsigned


# 1.139 26-Oct-2004 mickey

disable sid hashing on pcxu and above


# 1.138 14-Oct-2004 mickey

a bit larger delays during boot() to let msgs appear


# 1.137 19-Sep-2004 mickey

turn totalphysmem into physmem and name old physmem into smth it really is


# 1.136 18-Sep-2004 mickey

oops


# 1.135 15-Sep-2004 mickey

add pcxu tlb handlers and cpu probing
add u2/uturn ioa driver in dumb mode now
enable pcxu/pcxw support


# 1.134 14-Sep-2004 mickey

store fpu version for later use. make sure to proper store/clear fpu state in fork/exec/exit/sendsig


# 1.133 14-Sep-2004 mickey

error out from btlb_insert() if there is none


Revision tags: OPENBSD_3_6_BASE
# 1.132 01-Jul-2004 mickey

have separate insn and data cache all-flushers


# 1.131 30-Jun-2004 mickey

allow forced fpu emulation through a sysctl


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.130 13-May-2004 mickey

8ks do not have hvt


# 1.129 05-May-2004 mickey

much easier tlb handler branch patching


# 1.128 05-May-2004 mickey

do not engage HPT on PCXT' (yet)


# 1.127 08-Apr-2004 mickey

repair pcxs/t confoosion


# 1.126 07-Apr-2004 mickey

update copyright; miod@ is fine w/ files where he holds it too


Revision tags: OPENBSD_3_5_BASE
# 1.125 10-Mar-2004 tom

Ensure that we obey a user's ddb> boot reboot command even if the system
is cold (during startup).

This adds RB_USERREQ to sys/reboot.h, uses it in the ddb commands, and
ensures that */*/machdep.c:boot() won't set RB_HALT when cold if this
flag is set.

ok deraadt@


# 1.124 14-Feb-2004 grange

Simplify hw.{cpuspeed,setperf} api moving all the sysctl stuff
from the underlying callbacks.

Testing hppa mickey@, ppc drahn@
Ok markus@ tedu@


# 1.123 05-Jan-2004 mickey

kill debugging code that is not needed anymore


# 1.122 23-Dec-2003 mickey

provide cpuspeed fluff


# 1.121 20-Dec-2003 miod

Don't let microtime() return a struct timeval with exactly 1000000 microseconds.


# 1.120 18-Dec-2003 mickey

spls do not protect cpu_itmr and thus time might jump back sometimes due to cpu_itmr modified to a higher value than a read itmr; found and testing by miod@


# 1.119 17-Dec-2003 mickey

in the real mem print do not include reserved for prom into used by openbsd


# 1.118 10-Dec-2003 mickey

for unaligned btlb mapping attempts -- just fail


# 1.117 24-Nov-2003 mickey

experimental support for HVT as a 2nd level tlb


# 1.116 15-Oct-2003 mickey

less global name space pollution


# 1.115 05-Oct-2003 mickey

reload the itmr as soon as we get the intr to avoid lagging on slower machines


# 1.114 25-Sep-2003 mickey

some pcxl2 do not report fpus -- assume it's there


Revision tags: OPENBSD_3_4_BASE
# 1.113 04-Sep-2003 mickey

a better cpu identification; testing by miod


# 1.112 31-Aug-2003 miod

pdc_model needs to be visible from cpu.c


# 1.111 20-Aug-2003 mickey

missing nl in debugging prontf


# 1.110 07-Aug-2003 mickey

dead proto


# 1.109 07-Aug-2003 mickey

first allocate space on stack then copyout signal shits. add a DEBUG check for a whacky user pc (as impossible due to the recent trap.c change)


# 1.108 03-Aug-2003 mickey

clear branch and nullify bits in psw on sending a signal


# 1.107 30-Jul-2003 mickey

deduce the leds address from the model number and thus make some more use of that lichtenblinkenschmutz on some more machinens


# 1.106 22-May-2003 mickey

imprecision in delay_init()


# 1.105 18-May-2003 mickey

save the fpu state for the signal handler. this is essential
as the fpu regs can be used by the gcc even for non-fpu
means and data copying.
rearrange the sigcontext a bit to include only the general
registers that are needed restoring upon return and thus
less waste of space and make up some space for the fpu regs.

ALL software that used the signal context on the stack
needs at least rebuilding now. a new snap has bin built as well.


Revision tags: UBC_SYNC_A
# 1.104 11-May-2003 deraadt

string cleaning; krw ok


# 1.103 07-Apr-2003 mickey

s/HP9000/HP 9000/; from weissmanndude


Revision tags: OPENBSD_3_3_BASE
# 1.102 18-Feb-2003 deraadt

knf; mickey ok


# 1.101 12-Feb-2003 jason

How uncommon... hppa only has one common: msgbufmapped (decl'd in /sys/kern)


# 1.100 12-Feb-2003 mickey

only align the first stack frame onto the minimal required alignment


# 1.99 10-Feb-2003 mickey

fix pcs and pcxt recognition. from weissmanndude


# 1.98 22-Jan-2003 mickey

consistantly use uvm_prot_* vs vm_prot_* evewrhere


# 1.97 14-Jan-2003 mickey

fix cutnpaste in the cpu table for the itlbna field; from herr weissmanndude


# 1.96 14-Jan-2003 mickey

need pdc_hwtlb always; pt out by herr weissmanndude


# 1.95 13-Jan-2003 mickey

fix the logic in hvt probing


# 1.94 09-Jan-2003 miod

Remove fetch(9) and store(9) functions from the kernel, and replace the few
remaining instances of them with appropriate copy(9) usage.

ok art@, tested on all arches unless my memory is non-ECC


# 1.93 19-Dec-2002 mickey

setregs: put the whole frame setup into one place


# 1.92 19-Dec-2002 mickey

level 0x16 is really an l2


# 1.91 17-Dec-2002 millert

Make SysV-style shared memory and semaphore limits sysctl'able.
Instead of allocating a static amount of memory for the data
structures via valloc() in allocsys(), allocate things dynamically
using pool(9) when possible and malloc(9) when not. The various
members of struct seminfo and struct shminfo are in kern.seminfo
and kern.shminfo respectively (not all members of kern.seminfo are
changable).

The data structures used still leave something to be desired but
things are not made worse in that respect by this commit.


# 1.90 27-Nov-2002 mickey

no wrapper arounf hardclock(), use CPU_CLOCKUPDATE, real microtime; miod ok


# 1.89 08-Nov-2002 mickey

Don't uvm_useracc the user sigcontext in sys_sigreturn and then access
the user addresses directly from the kernel. copyin is faster and can
correctly deal properly with mappings that uvm_useracc thinks are
correct but will fault anyway (to figure out how to generate such
mappings is left as en excercise for the reader).


# 1.88 01-Nov-2002 mickey

add a missing delay after printf on halt[-p], proper arg for a cold hook


Revision tags: UBC_SYNC_B
# 1.87 22-Oct-2002 mickey

do not force single-user; pt out by fries@


# 1.86 15-Oct-2002 mickey

missing initmsgbuf(), noticed by miod@


# 1.85 13-Oct-2002 mickey

track the end of physmem for use in dmmem_alloc


# 1.84 07-Oct-2002 mickey

s/PSW_/PSL_/ to match other archs


# 1.83 07-Oct-2002 mickey

proper terminate the user stack on signal


# 1.82 07-Oct-2002 mickey

on implementations w/ fpu included unimplemented instructions
are signaled through the exception trap w/ invalid opcode marked
instruction in the exception registers, not through the emulation
trap (as long as the fpu is enabled, of course).
parse emulation from the exception trap as well as the emulation
trap and fix the dispatcher into usable condition.
parse invalid op exception on trap and signal the user appropriately.
reset the exception on exec and for child on fork.
the later is appropriate since exceptions are delayed until next
fpu instruction, which was in the parent indeed, let him get it.
save parent's fpu context on fork before cipying it, if the
parent owned the fpu.


Revision tags: OPENBSD_3_2_BASE
# 1.81 23-Sep-2002 mickey

parisc level 0x10 is just an overclocked 0xe


# 1.80 17-Sep-2002 mickey

handle fpu exceptions properly, might use a regress, i guess


# 1.79 11-Sep-2002 mickey

provide a convinient reset label


# 1.78 11-Sep-2002 mickey

stack grows the other way, but the frame is the other way to that. hehe


# 1.77 09-Sep-2002 mickey

set up the frame flags and a user frame better on exec


# 1.76 03-Aug-2002 mickey

rework boot() w/o a goto


# 1.75 25-Jul-2002 mickey

missing arg in the call to the pdc_call since some old times


# 1.74 25-Jul-2002 mickey

kcopy is a space-to-space copy from kernel space, to guess where, -- to the same kernel space, just error on fault


# 1.73 20-Jul-2002 art

Instead of copying out the signal trampoline on top of the stack, create
an uvm aobj, copy out the signal trampoline into it and share that page
among all processes for the same emulation.

This also requires us to actually be able to tell signal code where the
trampoline is located, so introduce a new field in struct proc - p_sigcode
that is a pointer to sigcode. This allows us to remove all the ugly
calculations of the signal trampoline address done in every sendsig
function in the tree (that's why so many files are changed).

Tested by various people. ok deraadt@


# 1.72 14-May-2002 mickey

disable sid hashing while still in real mode, alos print the parisc arch once and not per each cpu since they are not intermixable architecture-wise


# 1.71 13-May-2002 mickey

ldi-ldo whatever was in the table, be that much clever


# 1.70 08-May-2002 mickey

print parisc level w/ the the parisc version, not for each cpu


# 1.69 08-May-2002 mickey

kill debugging printfski


# 1.68 22-Apr-2002 mickey

no longer batc the data, only the code.
this removes a constraint and an ld.script dependancy
for the .data and the dynamically allocated kernel
structures existed w/ batcing. also makes pmap_steal_memory
obsolete and replaced w/ the pmap_virtual_space.
implement batching for pmap_remove to avoid
zeroing out the pte entries if pde will be removed anyway.


# 1.67 21-Apr-2002 mickey

better buf's mapping and less magic constants in checking for io space cachability


Revision tags: OPENBSD_3_1_BASE
# 1.66 26-Mar-2002 mickey

if cannot guess cpu model default to the lowest supported one


# 1.65 25-Mar-2002 deraadt

spelling


# 1.64 23-Mar-2002 espie

Add variables for config(8) -e time tweak of systemV shared memory
parameters.

Ok millert@, miod@, maja@


# 1.63 19-Mar-2002 mickey

mtcpu seq requires a pre-sync, implement hpt init for pcxl


# 1.62 15-Mar-2002 mickey

rewrite a pmap to use multilevel page tables.
lower 12 bits contain the perms, no unused bits left,
but a couple for off-tlb use (as the ref implemented now).
do not use the hvt, which might get some use later
if proven to speed thigs up, tlb handlers would po
another dozen of insns though, but if that's worth its...
move on the data seg and map kernel text rdonly (idea form fredette),
since all of the page0 mods done before that we are all fine
except for some viper fluff, but later w/ that.
this also picks up a bit more of ddb magic for bpt and ss.
tlb handlers can use a little bit more of attention,
but things, visually, seem to be much faster already, --
sorry, no benchmarks for now.

* effort sponsored in part by the `henry st. old ale house'
* and mr.pete and mr.lee in particular in thier generous entrirety.
* the proj took a little more that 72man*h as it was expected,
* but within murhy's law estimations.


# 1.61 14-Mar-2002 millert

First round of __P removal in sys


# 1.60 20-Feb-2002 mickey

setup power failure handler (for sw-controlled power button), move toc handler


# 1.59 17-Feb-2002 maja

Patch from Daniel Lucq <daniel@lucq.org>

The patch allows you to change the value of NMBCLUSTERS, BUFCACHEPERCENT
and NKMEMPAGES using the config command, instead of recompiling the kernel.

This is the kernel part of the patch. I have compiled it on i386, sparc64,
alpha and macppc. -moj ok art@ maja@


# 1.58 12-Feb-2002 mickey

support 712's programmable power switch, no interrupt yet


# 1.57 12-Feb-2002 mickey

small repairs to hpmc and toc handlers


# 1.56 11-Feb-2002 mickey

disable fpu on csw, print fpu version on cpu line, if present


# 1.55 07-Feb-2002 mickey

fix sigdebug cases; init sigcontext before it's used (;


# 1.54 06-Feb-2002 mickey

implement signal delivery; based on fredette@'s work


# 1.53 03-Feb-2002 mickey

restore hpt size computation, does not break things as i thought


# 1.52 02-Feb-2002 mickey

fix 'physmem' usage


# 1.51 02-Feb-2002 mickey

implement the rest of /dev/mem devices; from netbsd


# 1.50 23-Jan-2002 art

move mb_map allocation to mbinit()


# 1.49 23-Jan-2002 art

move definition of mb_map from zillions of machdep.c to uipc_mbuf.c


# 1.48 16-Jan-2002 miod

Don't include <sys/map.h> when you don't need what's in it.


Revision tags: UBC_BASE
# 1.47 02-Dec-2001 mickey

branches: 1.47.2;
increase fixed extent storage


# 1.46 28-Nov-2001 art

zap some typedefs.
vm_map_t -> struct vm_map *
vm_map_entry_t -> struct vm_map_entry *
simple_lock_data_t -> struct simplelock

(uvm not done yet, coming in the next commit)


# 1.45 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.44 24-Nov-2001 miod

Harmonize boot() logic across arches:
- ensure RB_DUMP | RB_HALT will cause a dump
- or RB_HALT if (cold)
While there, honor RB_TIMEBAD on sparc64.


# 1.43 09-Nov-2001 art

nswbuf hasn't been used for ages. gc.


# 1.42 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.41 06-Nov-2001 miod

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


Revision tags: OPENBSD_3_0_BASE
# 1.40 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.39 12-Sep-2001 art

mbutl no more


# 1.38 23-Aug-2001 art

We can now move timeout_init into main().


# 1.37 23-Aug-2001 art

Remove even more old timeout tentacles.


# 1.36 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.35 05-Jul-2001 art

Get rid of REAL_CLISTS. It was never implemented and the tentacles are
everywhhere.


# 1.34 17-May-2001 provos

convert mbuf and cluster allocation to pool, mostly from NetBSD
okay art@ miod@


# 1.33 05-May-2001 art

Rename configure() to cpu_configure().
Move it from cpu_startup() to main().


# 1.32 05-May-2001 art

Get rid of CLSIZE and all related stuff.
CLSIZE -> 1
CLBYTES -> PAGE_SIZE
OLOFSET -> PAGE_MASK
etc.
At the same time some archs needed some cleaning in vmparam.h so that
goes in at the same time.


Revision tags: OPENBSD_2_9_BASE
# 1.31 29-Mar-2001 mickey

cpudev_data.h here needed not


# 1.30 22-Mar-2001 mickey

shuffle the tlb handlers a little,
make a new one for na data fault,
since those w/ hpt need it.


Revision tags: OPENBSD_2_8_BASE
# 1.29 15-Aug-2000 mickey

two btlb routines (i & d) for pcxs


# 1.28 15-Aug-2000 mickey

expand per-cpu control routines switch


# 1.27 08-Aug-2000 mickey

print btlb params w/ BTLBDEBUG; from Havard.Eidnes@runit.sintef.no


# 1.26 02-Jul-2000 mickey

no bays for stinger


Revision tags: OPENBSD_2_7_BASE
# 1.25 23-Mar-2000 mickey

new cpu type switch code.
initializes tlb miss handlers correspondent to probed cpu features.
also btlb load routine.
versions written are for pcxl and others.
cpu-dep btlb loaders are missing, only generic for now.


# 1.24 23-Mar-2000 art

New API for timeouts. Replaces the old timeout()/untimeout() API and
makes it the callers responsibility to allocate resources for the
timeouts.

This is a KISS implementation and does _not_ solve the problems of slow
handling of a large number of pending timeouts (this will be solved in
future work) (although hardclock is now guarateed to take constant time
for handling of timeouts).

Old timeout() and untimeout() are implemented as wrappers around the new
API and kept for compatibility. They will be removed as soon as all
subsystems are converted to use the new API.


# 1.23 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


# 1.22 22-Feb-2000 mickey

blah, blah, blah, msgbuf


Revision tags: SMP_BASE
# 1.21 09-Feb-2000 mickey

branches: 1.21.2;
heartbeat -- yeah we have a patch for that


# 1.20 25-Jan-2000 mickey

better copy and zero inlines in locore;
proper setregs() in machedep;
start of hpmc handler;
some cleanup here and there;


# 1.19 17-Jan-2000 mickey

remove unneeded stuff from setregs; force single-user for now, enable signal debug


# 1.18 11-Jan-2000 mickey

s/fpu_curproc/fpu_curpcb/ which also points into physical.
move it's definition into locore (where it's used the most).
adjust fpu context switch and save on swapout accordingly.
fix context save (in switch).
add accounting for fpu context switches (since it differes
from proc switching, we might get provided w/ some usefull
numbers as to how effective this lazy switch technique is).
enable handling fpu/sfu exceptions.


# 1.17 31-Dec-1999 mickey

don't bother about pidr3 and pidr4


# 1.16 17-Dec-1999 mickey

fix the panic message for sti memory mapping


Revision tags: kame_19991208
# 1.15 25-Nov-1999 mickey

bus stuff is in mainbus now, the rest is rewritten many ways


Revision tags: OPENBSD_2_6_BASE
# 1.14 20-Sep-1999 mickey

fix uvm_pagealloc() call


# 1.13 03-Sep-1999 art

Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.12 14-Aug-1999 mickey

proper debugging ifdefs


# 1.11 21-Jul-1999 mickey

rewrite the tlb miss handler and tlb dirty handler.
optimize for HVT usage (when compiled for proper cpu type).
drop hpt_* global variables, use info from control registers instead.
there are still ways to improve the tlb handlers tho.
machdep also prints cache and tlb coherence states (not related to the above).
You eat greenish muffin. --More-- You write real code.


# 1.10 12-Jul-1999 mickey

allocate 5% bufcache if <=16M memory installed


# 1.9 12-Jun-1999 mickey

hppa_init() now takes an argument from locore,
meaning the start of available memory.
cleanup machdep somewhat.
fix vm_map.pmap vs vm_pmap isue; 10x art@


# 1.8 23-May-1999 mickey

new swap stuff


# 1.7 21-May-1999 mickey

group all theMD f;ags together, add interrupt recursion one


# 1.6 21-May-1999 mickey

define fpu_curproc


# 1.5 20-Apr-1999 mickey

do lazy blok mapping of io space in bus_*
add copy{in,out}*, kcopy, etc
boot routines
cpu-id-hpux-compat stuff
rest of scheduler and such
uvm


Revision tags: OPENBSD_2_5_BASE
# 1.4 17-Feb-1999 mickey

print pa-risc here as well, since, finally, cpu will have to print processor type


# 1.3 04-Jan-1999 mickey

better cache handling in bus_space_barrier(), seem to work now


# 1.2 03-Jan-1999 mickey

implement bus_space_{un,}map w/ extents


# 1.1 30-Dec-1998 mickey

machdep; more work needed


# 1.268 06-Jan-2023 miod

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


# 1.267 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_7_2_BASE
# 1.266 10-Aug-2022 jsg

match other archs use %s for version printf


Revision tags: OPENBSD_7_1_BASE
# 1.265 06-Oct-2021 claudio

Change sendsig() interface so that the MD code does not need to access
data from struct process anymore. This changes how siginfo and onstack
are accessed and make sendsig() more MP friendly.
With and OK semarie@ OK kettenis@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.264 11-Mar-2021 jsg

spelling


# 1.263 09-Jan-2021 kettenis

"encoding of diag instructions is hard, let's go shopping"

Clean up things a bit, adding documentation about the source of the
information about these instructions.

From miod@


# 1.262 08-Nov-2020 mpi

In case of failure, call sigexit() from trapsignal instead of sensig().

Simplify MD code and reduce the amount of recursion into the signal code
which helps when dealing with locks.

ok cheloha@, deraadt@


# 1.261 21-Oct-2020 deraadt

hppa also has a similar to arm64: copyout(9), copyinstr(9) and
copyoutstr(9) should bail out properly if they are called with a
length of 0.
ok kettenis@


Revision tags: OPENBSD_6_8_BASE
# 1.260 14-Jun-2020 naddy

Implement cpu_rnd_messybits() as a read of the cycle counter register.
ok dlg@ deraadt@


# 1.259 31-May-2020 dlg

introduce "cpu_rnd_messybits" for use instead of nanotime in dev/rnd.c.

rnd.c uses nanotime to get access to some bits that change quickly
between events that it can mix into the entropy pool. it doesn't
use nanotime to get a monotonically increasing set or ordered and
accurate timestamps, it just wants something with bits that change.

there's been discussions for years about letting rnd use a clock
that's super fast to read, but not necessarily accurate, but it
wasn't until recently that i figured out it wasn't interested in
time at all, so things like keeping a fast clock coherent between
cpu cores or correct according to ntp is unecessary. this means we
can just let rnd read the cycle counters on cpus and things will
be fine. cpus with cycle counters that vary in their speed and
arent kept consistent between cores may even be desirable in this
context.

so this is the first step in converting rnd.c to reading cycle
counter. it copies the nanotime backend to each arch, and they can
replace it with something MD as a second step later on.

djm@ suggested rnd_messybytes, but we landed on cpu_rnd_messybits.
thanks to visa for his eyes.
ok deraadt@ visa@
deraadt@ says he will help handle any MD fallout that occurs.


# 1.258 16-May-2020 kettenis

Make inittodr() and resettodr() MI.

ok deraadt@, mpi@, visa@
ok cheloha@ as well (would have preferred in new file for this code)


# 1.257 11-May-2020 kettenis

Initialize the timeval passed to todr_gettime() with the base time from
the file system such that implementations can use it to guess the right
century.

ok mpi@


Revision tags: OPENBSD_6_7_BASE
# 1.256 01-May-2020 kettenis

Use the same inittodr()/resettodr() implementation as on
amd64/arm64/armv7/i386/sparc64 and move it to the end of machdep.c. Rework the
actual implementation for the MC14818 compatible RTC into something that can
be used as a todr_handle just like on amd64.

ok mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.255 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


Revision tags: OPENBSD_6_4_BASE
# 1.254 20-Jul-2018 guenther

Missed a 'ksi' -> '*ksip' change in previous commit


# 1.253 10-Jul-2018 guenther

Move from sendsig() to its callers the initsiginfo() calls and
instead of passing sendsig() the code+type+val, pass a siginfo_t*
to copy from. Eliminate the indirection through struct emul for
sendsig(); we no longer have a SunOS4-compat version of sendsig()

ok deraadt@


# 1.252 22-May-2018 guenther

Delete antique sigdebug definitions

ok kettenis@


# 1.251 12-Apr-2018 deraadt

Implement MAP_STACK option for mmap(). Synchronous faults (pagefault and
syscall) confirm the stack register points at MAP_STACK memory, otherwise
SIGSEGV is delivered. sigaltstack() and pthread_attr_setstack() are modified
to create a MAP_STACK sub-region which satisfies alignment requirements.
Observe that MAP_STACK can only be set/cleared by mmap(), which zeroes the
contents of the region -- there is no mprotect() equivalent operation, so
there is no MAP_STACK-adding gadget.
This opportunistic software-emulation of a stack protection bit makes
stack-pivot operations during ROPchain fragile (kind of like removing a
tool from the toolbox).
original discussion with tedu, uvm work by stefan, testing by mortimer
ok kettenis


Revision tags: OPENBSD_6_3_BASE
# 1.250 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.249 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


Revision tags: OPENBSD_6_2_BASE
# 1.248 18-May-2017 kettenis

Implement copyin32(9).

"your chicken scratches look fine to me" deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.247 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

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


# 1.246 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.245 21-May-2016 deraadt

hand-massage sendsig() and sys_sigreturn() to be much more similar.
ok guenther kettenis


# 1.244 10-May-2016 deraadt

SROP mitigation. sendsig() stores a (per-process ^ &sigcontext) cookie
inside the sigcontext. sigreturn(2) checks syscall entry was from the
exact PC addr in the (per-process ASLR) sigtramp, verifies the cookie,
and clears it to prevent sigcontext reuse.
not yet tested on landisk, sparc, *88k, socppc.
ok kettenis


# 1.243 20-Apr-2016 dlg

pool_setipl for floating point context things

ok kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.242 21-Oct-2015 mpi

Do not call uvm_swap_finicrypt_all() a second time in dumpsys().

ok tedu@, deraadt@, miod@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.241 20-Jan-2015 kettenis

Move ps_strings "after" the random stackgap. This makes its location a
per-process value, and therefpore turns the VM_PSSTRINGS sysctl into a
per-process one as well. This gets rid of a pointer to the bottom of the
stack at a fixed location. Also clears the road for unmapping the stackgap.

ok deraadt@


# 1.240 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.239 25-Oct-2014 kettenis

Remove vmmap; it isn't used.

ok jsing@


# 1.238 23-Oct-2014 miod

Correctly set up the HPMC trap entry: according to the PA-RISC Firmware
Architecture Reference Specification, the sum of the 8 trap entry words
*and* of the payload which address and length are to be set at well-known
positions in the aforementioned trap entry, needs to be zero; the existing
code was only enforcing that the sum of the trap entry words is zero.

This matches what Linux and NetBSD do.

ok kettenis@


# 1.237 23-Oct-2014 miod

Revert limiting physmem to 2GB; the culprit was likely in uvm and uvm has
changed a lot in the last 5 years; verified to work on a 3GB system, in
snapshots for a few weeks already.


# 1.236 22-Sep-2014 dlg

implement atomic_{cas,swap}_{uint,ulong,ptr} and
atomic_{add,sub}_{int,long}_nv. sys/atomic.h turns these into the
rest of the atomic api.

on uniprocessor hppa systems "atomic" operations are implemented
as a non-interruptable sequence by disabling all interrupts on the
cpu, doing the operation, and then restoring the interrupt mask.

this isnt enough on MP systems, so we added a global atomic memory
mutex that is taken inside the interrupt disabling above to coordinate
operations between cpus.

this is a lot of overhead though cos mutexes dance around with ipls,
which is unecessary in our case because of the interrupt disabling
that is already done. also, hppa spinlocks are implemented with
ldcw which requires the word it operates on to be 16 byte aligned.
mutexes arent guaranteed to have this alignment so they compensate
by having lots of words inside themselves so they can hit the
appropriate one to use for the ldcw op.

with this in mind, this change pulls __cpu_simple_locks, which are
simply ldcw spinlocks with a 16 byte aligned word, out of
src/sys/arch/hppa/include/lock.h into src/sys/arch/hppa/include/atomic.h
so atomic.h can use them. lock.h includes atomic.h, so it still
gets and provides the same functionality as before.

finally, this also pulls the rwlock cas implementation apart. cas
ops now share the same serialising lock on MP systems as the other
memory operations, and rw_cas is defined as a wrapper around
atomic_cas_uint.

ok kettenis@


# 1.235 19-Sep-2014 kettenis

Use config_suspend_all(9).


# 1.234 18-Aug-2014 dlg

dont rely on mbuf.h to provide pool.h.

ok miod@, who has offerred to help with any MD fallout
ok guenther@


Revision tags: OPENBSD_5_6_BASE
# 1.233 22-Jul-2014 uebayasi

boot(9): Reduce diffs between hppa & hppa64 (& others)


# 1.232 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.231 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.230 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.229 13-Jul-2014 miod

These still need <sys/reboot.h> for the RB_ constants.


# 1.228 12-Jul-2014 uebayasi

reboot(9), panic(9): Call panic(9) for unrecoverable MD H/W errors (NMIs)

Some architectures have ability to detect hardware sanity and notify system
(NMI, firmware callback, etc.). Handle these hardware severe errors, same
as software errors, with panic(9).

According to miod@, SGI IP27 NMI is triggered by pushing some "hidden" button,
which "usual" users/admins don't know. Pushing such a button is "RB_USERREQ"
(human-triggered) in that the button is pushed by a human, but not "RB_USERREQ"
in that no user intervention in system (== no command input) is done. miod@
agreed that changing these from RB_USERREQ to !RB_USERREQ (== panic(9)) is
not a big problem.

OK miod@ kettenis@


# 1.227 12-Jul-2014 uebayasi

boot(9), reboot(9): Migrate MD callers of boot(9) to reboot(9)

I have found that some ports call boot(9) from machine-dependent code to
reboot system. These should be changed to either:

- Sending signal to init(8) to trigger it to shutdown system cleanly, like
acpi(4) does, in cases where found problems don't prevent system from working
immediately, or

- Just doing panic(9) if the situation is severely broken.

For now, just rewrite boot() to reboot(). Actual fixes follow.

Discussed with & OK from kettenis@


# 1.226 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.225 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.224 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.223 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.222 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.221 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.220 08-May-2014 miod

Format string fixes and removal of -Wno-format for hppa kernels.


# 1.219 08-Apr-2014 mpi

Less <uvm/uvm.h>


# 1.218 04-Apr-2014 miod

If the PDC_COPROC call fails, and we are running on a PA 1.1 system, assume
the usual 1.1 coprocessor mask, instead of using zero and having every
userland process dying with signal 4.

The circumstances under which this call fails are unclear and could be
tied to specific PROM version (I have tried overzealous stack alignment and
other tricks, to no avail). Interestingly enough, the 715/75 system which
hits this problem, only triggers it when booting from disk, and never when
booting from network.

This diff is an ugly bandaid until the problem is better understood. Or maybe
it is not worth investigating, seeing that Linux hardcodes the coprocessor
mask and never issues PDC_COPROC calls; I wonder what HP/UX does.

In my tree for over 18 months; "Looks like a nice hack" deraadt@
715/75 system provided by Sebastiaan Indesteege, thanks!


# 1.217 29-Mar-2014 guenther

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

ok dlg@ mpi@ deraadt@


# 1.216 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


# 1.215 22-Mar-2014 guenther

Move p_sigacts from struct proc to struct process.

testing help mpi@


# 1.214 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


Revision tags: OPENBSD_5_5_BASE
# 1.213 23-Nov-2013 uebayasi

Run doshutdownhooks() and config_suspend() even when boot() is called while
cold != 0. Indent and make hppa/hppa64 boot() closer to others.

OK kettenis@


# 1.212 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


Revision tags: OPENBSD_5_4_BASE
# 1.211 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


Revision tags: OPENBSD_5_3_BASE
# 1.210 02-Dec-2012 guenther

Determine whether we're currently on the alternative signal stack
dynamically, by comparing the stack pointer against the altstack
base and size, so that you get the correct answer if you longjmp
out of the signal handler, as tested by regress/sys/kern/stackjmp/.
Also, fix alt stack handling on vax, where it was completely broken.

Testing and corrections by miod@, krw@, tobiasu@, pirofti@


# 1.209 26-Oct-2012 kettenis

Properly clear trap frame in setregs() to avoid leaking registers across exec.

ok jsing@


# 1.208 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.207 07-Oct-2012 kettenis

Align the stack on a 64-byte boundary as required by "The 32-bit PA-RISC
Run-time Architecture Document". GCC relies on this to properly align
stack variables.

ok guenther@, beck@


Revision tags: OPENBSD_5_2_BASE
# 1.206 21-Jun-2012 guenther

__tfork() needs to set the stack address of the new thread in the kernel,
so that it can't get a signal while still running on the parent thread's
stack. Also, pass in sizeof(struct __tfork) to provide forward compat
when more members are added. This is an ABI change, so switch syscall
numbers and bump lib majors this time.

ok deraadt@ matthew@


Revision tags: OPENBSD_5_1_BASE
# 1.205 20-Sep-2011 miod

Clear RB_POWERDOWN early in boot() on systems which can not powerdown and
which firmware does not send spin up commands to the disks, in case the
operator changes his mind and reboots instead of manually powering down
after the system has halted.
ok kettenis@


Revision tags: OPENBSD_5_0_BASE
# 1.204 05-Jul-2011 guenther

Recommit the reverted sigacts change now that the NFS use-after-free
problem has been tracked down. This fixes the sharing of the signal
handling state: shared bits go in sigacts, per-rthread bits goes in
struct proc.

ok deraadt@


# 1.203 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.202 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.201 18-Apr-2011 guenther

Revert the sigacts diff: NFS can apparently retain pointers to processes
until they're zombies and then send them signals (for intr mounts). Until
that is untangled, the sigacts change is unsafe. sthen@ was the victim
for this one


# 1.200 15-Apr-2011 guenther

Correct the sharing of the signal handling state: stuff that should
be shared (p_sigignore, p_sigcatch, P_NOCLDSTOP, P_NOCLDWAIT) moves
to struct sigacts, wihle stuff that should be per rthread (ps_oldmask,
SAS_OLDMASK, ps_sigstk) moves to struct proc. Treat the coredumping
state bits (ps_sig, ps_code, ps_type, ps_sigval) as per-rthread
until our locking around coredumping is better.

Oh, and remove the old SunOS-compat ps_usertramp member.

"I like the sound of this" tedu@


Revision tags: OPENBSD_4_9_BASE
# 1.199 14-Jan-2011 jsing

Halt secondary CPUs when shutting down or rebooting. This should prevent
occasional hangs during reboot.

ok kettenis@


# 1.198 04-Jan-2011 jasper

- de-register. no binary change.

ok jsing@


# 1.197 01-Jan-2011 jasper

Move setting cpu_hzticks to the clock initialization function, like
other ports (e.g. hppa64) do.

ok jsing@ kettenis@


# 1.196 01-Jan-2011 jasper

- ansify

ok jsing@ kettenis@


# 1.195 30-Dec-2010 jsing

Turn signotify() into a function that also calls cpu_unidle().

ok kettenis@


# 1.194 20-Nov-2010 miod

This is a first step towards getting rid of avail_start and avail_end in the
kernel, currently limited to low-hanging fruit: these variables were used
by bus_dma to specify the range in which to allocate memory, back when
uvm_pglistalloc() was stupid and would not walk the vm_physseg[].

Nowadays, except on some platforms for early initialization, these variables
are not used, or do not need to be global variables. Therefore:
- remove `extern' declarations of avail_start and avail_end (or close cousins,
such as arm physical_start and physical_end) from files which no longer need
to use them.
- make them local variables whenever possible.
- remove them when they are assigned to but no longer used.


Revision tags: OPENBSD_4_8_BASE
# 1.193 01-Jul-2010 jsing

Create a struct to store FP state and include a pointer to the CPU that
currently holds the FPU context for this process. This will be soon used
to implement FPU shootdowns on multiprocessor kernels.

ok kettenis@


# 1.192 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.191 29-Jun-2010 jsing

Factor out code used to save and flushe process FPU context.

ok kettenis@


# 1.190 29-Jun-2010 jsing

Store pointer to process FPU state in struct cpu_info.

ok kettenis@


# 1.189 27-Jun-2010 thib

uvm constraints. Add two mandatory MD symbols, uvm_md_constraints
which contains the constraints for DMA/memory allocation for each
architecture, and dma_constraints which contains the range of addresses
that are dma accessable by the system.

This is based on ariane@'s physcontig diff, with lots of bugfixes and
additions the following additions by my self:

Introduce a new function pool_set_constraints() which sets the address
range for which we allocate pages for the pool from, this is now used
for the mbuf/mbuf cluster pools to keep them dma accessible.

The !direct archs no longer stuff pages into the kernel object in
uvm_km_getpage_pla but rather do a pmap_extract() in uvm_km_putpages.

Tested heavily by my self on i386, amd64 and sparc64. Some tests on
alpha and SGI.

"commit it" beck, art, oga, deraadt
"i like the diff" deraadt


# 1.188 27-Jun-2010 jsing

Use a mutex to make atomic operations atomic on multiprocessor kernels.

ok kettenis@


# 1.187 10-Jun-2010 deraadt

Declare safepri at the MD level on each platform, so that the kern_synch.c
does not have to deal with it as a common. Some platforms may be missed
by this commit... if you spot one, fix it the same way.
ok miod


# 1.186 09-Jun-2010 miod

Move declaration of cn_tab from dev/cons.c to dev/cninit.c, or appropriate
md files for ports which do not use dev/cninit.c. This gets rid of a common
at kernel link time.
feedback drahn@ ok deraadt@


# 1.185 24-May-2010 deraadt

Add missing prototypes
ok jsing kettenis


# 1.184 09-May-2010 kettenis

Prevent "taken branch" exceptions from kernel space by clearing the PSL_T
bit before we enter a signal handler.

"if you say so" miod@, "seems to make sense" jsing@


# 1.183 02-May-2010 kettenis

Properly initialize the members of `struct mdproc' that deal with
single-stepping when we fork and reset them upon exec.

ok miod@


# 1.182 27-Apr-2010 kettenis

Avoid null-pointer dereference by giving proc0 a place to store its
floating-point registers. Pointed out by Nick Hudson.

ok miod@, jsing@


# 1.181 19-Apr-2010 jsing

Make the Processor Status Word (PSW) a per-CPU value.

ok kettenis@


# 1.180 01-Apr-2010 jsing

Allow for multiple CPUs by moving to an array of cpu_info.

ok kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.179 31-Dec-2009 jsing

Make cpl and cpu_inintr per CPU variables. For locore.S, cpl becomes an
offset within cpu_primary_info - this will need to be revisited shortly.

ok kettenis@


# 1.178 11-Aug-2009 miod

Do not bother initializing bufpages in the md code if the computation is
exactly the same the mi could will use if bufinit() is invoked with
bufpages == 0.


# 1.177 11-Aug-2009 miod

With the SysV memory allocation changes, allocsys() doesn't do anything
anymore. Get rid of it completely.


# 1.176 09-Aug-2009 blambert

Rototill system V message queues.

No longer allocate a static amount of memory for messages in MD
boot path; message queues, message metadata, and message data now
all use dynamic memory, which means that runtime sysctls should now
be trivial to implement.

Since I'm going to be around all week to fix any breakage, this should
probably just go in now.


# 1.175 02-Aug-2009 beck

Dynamic buffer cache support - a re-commit of what was backed out
after c2k9

allows buffer cache to be extended and grow/shrink dynamically

tested by many, ok oga@, "why not just commit it" deraadt@


# 1.174 29-Jul-2009 kettenis

Get rid of non-equivalent aliases of the pcb by moving the fpu state out
of the pcb and using the p_addr member of 'struct proc' to calculate the
address of the kernel stack when switching to virtual mode after taking a trap.
Remove the now unecessary cache flushes; they're actually harmful since they
create non-equivalent aliases. This seems to fix the memory corruption we
have been observing from time to time.

This diff does not rename fpu_curpcb, which is now somewhat incorrectly named.
I hope to change things back again as soon as we are able to map the pcb 1:1.


Revision tags: OPENBSD_4_6_BASE
# 1.173 15-Jun-2009 beck

Back out all the buffer cache changes I committed during c2k9. This reverts three
commits:

1) The sysctl allowing bufcachepercent to be changed at boot time.
2) The change moving the buffer cache hash chains to a red-black tree
3) The dynamic buffer cache (Which depended on the earlier too).

ok on the backout from marco and todd


# 1.172 03-Jun-2009 beck

add kern.bufcachepercent sysctl to allow adjusting the buffer cache
size on a running system.
ok art@, oga@


Revision tags: OPENBSD_4_5_BASE
# 1.171 14-Feb-2009 kettenis

Limit the amount of physical memory to 2GB. Using more causes memory
corruption on PA-RISC 2.0 systems (and there are very few PA-RISC 1.1
systems that support more than 2GB).

ok miod@


# 1.170 04-Feb-2009 miod

On systems with split BTLB, do not bother trying to insert DBTLB entries,
as PDC will lie to us pretending it did while it didn't.

ok kettenis@


# 1.169 04-Feb-2009 miod

Unify memory size reports a bit more: always report size in MB, and report
reserved memory on alpha and hppa on its own line (as done on sgi).


Revision tags: OPENBSD_4_4_BASE
# 1.168 14-Jul-2008 miod

Be sure to propagate PSL_O in psw on PCXU* processors to userland processes
and signal handlers.
ok kettenis@


# 1.167 27-Jun-2008 miod

Clear swap encryption keys before dumping a kernel image.


# 1.166 09-Apr-2008 deraadt

Add new stub uvm_shutdown() and call it from the right place in MD boot()


Revision tags: OPENBSD_4_3_BASE
# 1.165 22-Sep-2007 martin

replace even more ctob and btoc with ptoa and atop respectively plus
uvm_extern.h where needed


Revision tags: OPENBSD_4_2_BASE
# 1.164 22-Jul-2007 kettenis

Move hppa to __HAVE_TIMECOUNTERS.


# 1.163 20-Jul-2007 kettenis

Give hppa the blink_led API from sparc64, and the associated machdep.led_blink
sysctl.


# 1.162 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.161 14-Jul-2007 kettenis

Make sigreturn(2) set the proper space ID for the instruction queue. Fixes
a few more pthreads regression tests.

ok miod@


# 1.160 10-Jul-2007 kettenis

Don't trust the privilige level in the sigcontext passed to sigreturn(2).

ok miod@


# 1.159 24-Jun-2007 kettenis

Crank initial storage for extents a bit. We really should allocate extents
using malloc once vm is initialised, but this will do for now.

ok deraadt@


# 1.158 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.157 27-May-2007 miod

Make sure the minaddr hint for uvm_km_suballoc() calls is always initialized.
ok pedro@


# 1.156 26-May-2007 pedro

Dynamic buffer cache. Initial diff from mickey@, okay art@ beck@ toby@
deraadt@ dlg@.


# 1.155 21-May-2007 kettenis

Add support for 8700/pcxw2 cpu.


# 1.154 21-May-2007 kettenis

Ask firmware for reset before trying ourselves; needed for four-digit b/c/j
workstations.

tested by otto@, krw@; ok deraadt@


# 1.153 17-May-2007 art

Limit hppa buffer cache to 30%. It used to be 70% because stack garbage
that was used for minaddr instead of the proper vm_map_min(kernel_map)
(fixed in this diff).

From mickey. art@ ok


# 1.152 14-May-2007 martin

move hppa to __HAVE_CPUINFO

input from miod@, ok kettenis@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.151 28-May-2006 martin

minor nit, use CPU ID instead of FPU ID for BTLB parameters after passing
all kludges


# 1.150 15-Apr-2006 martin

make warning about missing HPT support DEBUG for now

ok mickey@


Revision tags: OPENBSD_3_9_BASE
# 1.149 26-Oct-2005 martin

no more hppa_round_page() and hppa_trunc_page() macros

ok mickey@


Revision tags: OPENBSD_3_8_BASE
# 1.148 06-Aug-2005 miod

We do not need a char machine_arch[] constant.
ok deraadt@


# 1.147 11-Jul-2005 mickey

align some stupid comments


# 1.146 10-May-2005 mickey

set pcsq in case we get signal delivery once interrupted from the gateway page; from chs


# 1.145 18-Apr-2005 mickey

do not do some of the initmsgbuf()s job


# 1.144 07-Apr-2005 mickey

on some machines it's possible to limit the amount of physmem initialised dring post so having msgbuf at the end of memory shall work


# 1.143 07-Apr-2005 mickey

64bit-friendly pdc.h and iomod.h and correspondent changes elsewhere


# 1.142 26-Mar-2005 mickey

md parts for hpux_compa code; some problems w/ signals delivery still exist


Revision tags: OPENBSD_3_7_BASE
# 1.141 24-Feb-2005 mickey

do not even ask for btlb on 8k cpus as pdc pretends there is some but then it does not work; found w/ Moritz Kiese <mbk@mytum.de> on c180; add a debug print and fix pcxu entry


# 1.140 17-Nov-2004 mickey

print real/avail/bufcache sizes as unsigned


# 1.139 26-Oct-2004 mickey

disable sid hashing on pcxu and above


# 1.138 14-Oct-2004 mickey

a bit larger delays during boot() to let msgs appear


# 1.137 19-Sep-2004 mickey

turn totalphysmem into physmem and name old physmem into smth it really is


# 1.136 18-Sep-2004 mickey

oops


# 1.135 15-Sep-2004 mickey

add pcxu tlb handlers and cpu probing
add u2/uturn ioa driver in dumb mode now
enable pcxu/pcxw support


# 1.134 14-Sep-2004 mickey

store fpu version for later use. make sure to proper store/clear fpu state in fork/exec/exit/sendsig


# 1.133 14-Sep-2004 mickey

error out from btlb_insert() if there is none


Revision tags: OPENBSD_3_6_BASE
# 1.132 01-Jul-2004 mickey

have separate insn and data cache all-flushers


# 1.131 30-Jun-2004 mickey

allow forced fpu emulation through a sysctl


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.130 13-May-2004 mickey

8ks do not have hvt


# 1.129 05-May-2004 mickey

much easier tlb handler branch patching


# 1.128 05-May-2004 mickey

do not engage HPT on PCXT' (yet)


# 1.127 08-Apr-2004 mickey

repair pcxs/t confoosion


# 1.126 07-Apr-2004 mickey

update copyright; miod@ is fine w/ files where he holds it too


Revision tags: OPENBSD_3_5_BASE
# 1.125 10-Mar-2004 tom

Ensure that we obey a user's ddb> boot reboot command even if the system
is cold (during startup).

This adds RB_USERREQ to sys/reboot.h, uses it in the ddb commands, and
ensures that */*/machdep.c:boot() won't set RB_HALT when cold if this
flag is set.

ok deraadt@


# 1.124 14-Feb-2004 grange

Simplify hw.{cpuspeed,setperf} api moving all the sysctl stuff
from the underlying callbacks.

Testing hppa mickey@, ppc drahn@
Ok markus@ tedu@


# 1.123 05-Jan-2004 mickey

kill debugging code that is not needed anymore


# 1.122 23-Dec-2003 mickey

provide cpuspeed fluff


# 1.121 20-Dec-2003 miod

Don't let microtime() return a struct timeval with exactly 1000000 microseconds.


# 1.120 18-Dec-2003 mickey

spls do not protect cpu_itmr and thus time might jump back sometimes due to cpu_itmr modified to a higher value than a read itmr; found and testing by miod@


# 1.119 17-Dec-2003 mickey

in the real mem print do not include reserved for prom into used by openbsd


# 1.118 10-Dec-2003 mickey

for unaligned btlb mapping attempts -- just fail


# 1.117 24-Nov-2003 mickey

experimental support for HVT as a 2nd level tlb


# 1.116 15-Oct-2003 mickey

less global name space pollution


# 1.115 05-Oct-2003 mickey

reload the itmr as soon as we get the intr to avoid lagging on slower machines


# 1.114 25-Sep-2003 mickey

some pcxl2 do not report fpus -- assume it's there


Revision tags: OPENBSD_3_4_BASE
# 1.113 04-Sep-2003 mickey

a better cpu identification; testing by miod


# 1.112 31-Aug-2003 miod

pdc_model needs to be visible from cpu.c


# 1.111 20-Aug-2003 mickey

missing nl in debugging prontf


# 1.110 07-Aug-2003 mickey

dead proto


# 1.109 07-Aug-2003 mickey

first allocate space on stack then copyout signal shits. add a DEBUG check for a whacky user pc (as impossible due to the recent trap.c change)


# 1.108 03-Aug-2003 mickey

clear branch and nullify bits in psw on sending a signal


# 1.107 30-Jul-2003 mickey

deduce the leds address from the model number and thus make some more use of that lichtenblinkenschmutz on some more machinens


# 1.106 22-May-2003 mickey

imprecision in delay_init()


# 1.105 18-May-2003 mickey

save the fpu state for the signal handler. this is essential
as the fpu regs can be used by the gcc even for non-fpu
means and data copying.
rearrange the sigcontext a bit to include only the general
registers that are needed restoring upon return and thus
less waste of space and make up some space for the fpu regs.

ALL software that used the signal context on the stack
needs at least rebuilding now. a new snap has bin built as well.


Revision tags: UBC_SYNC_A
# 1.104 11-May-2003 deraadt

string cleaning; krw ok


# 1.103 07-Apr-2003 mickey

s/HP9000/HP 9000/; from weissmanndude


Revision tags: OPENBSD_3_3_BASE
# 1.102 18-Feb-2003 deraadt

knf; mickey ok


# 1.101 12-Feb-2003 jason

How uncommon... hppa only has one common: msgbufmapped (decl'd in /sys/kern)


# 1.100 12-Feb-2003 mickey

only align the first stack frame onto the minimal required alignment


# 1.99 10-Feb-2003 mickey

fix pcs and pcxt recognition. from weissmanndude


# 1.98 22-Jan-2003 mickey

consistantly use uvm_prot_* vs vm_prot_* evewrhere


# 1.97 14-Jan-2003 mickey

fix cutnpaste in the cpu table for the itlbna field; from herr weissmanndude


# 1.96 14-Jan-2003 mickey

need pdc_hwtlb always; pt out by herr weissmanndude


# 1.95 13-Jan-2003 mickey

fix the logic in hvt probing


# 1.94 09-Jan-2003 miod

Remove fetch(9) and store(9) functions from the kernel, and replace the few
remaining instances of them with appropriate copy(9) usage.

ok art@, tested on all arches unless my memory is non-ECC


# 1.93 19-Dec-2002 mickey

setregs: put the whole frame setup into one place


# 1.92 19-Dec-2002 mickey

level 0x16 is really an l2


# 1.91 17-Dec-2002 millert

Make SysV-style shared memory and semaphore limits sysctl'able.
Instead of allocating a static amount of memory for the data
structures via valloc() in allocsys(), allocate things dynamically
using pool(9) when possible and malloc(9) when not. The various
members of struct seminfo and struct shminfo are in kern.seminfo
and kern.shminfo respectively (not all members of kern.seminfo are
changable).

The data structures used still leave something to be desired but
things are not made worse in that respect by this commit.


# 1.90 27-Nov-2002 mickey

no wrapper arounf hardclock(), use CPU_CLOCKUPDATE, real microtime; miod ok


# 1.89 08-Nov-2002 mickey

Don't uvm_useracc the user sigcontext in sys_sigreturn and then access
the user addresses directly from the kernel. copyin is faster and can
correctly deal properly with mappings that uvm_useracc thinks are
correct but will fault anyway (to figure out how to generate such
mappings is left as en excercise for the reader).


# 1.88 01-Nov-2002 mickey

add a missing delay after printf on halt[-p], proper arg for a cold hook


Revision tags: UBC_SYNC_B
# 1.87 22-Oct-2002 mickey

do not force single-user; pt out by fries@


# 1.86 15-Oct-2002 mickey

missing initmsgbuf(), noticed by miod@


# 1.85 13-Oct-2002 mickey

track the end of physmem for use in dmmem_alloc


# 1.84 07-Oct-2002 mickey

s/PSW_/PSL_/ to match other archs


# 1.83 07-Oct-2002 mickey

proper terminate the user stack on signal


# 1.82 07-Oct-2002 mickey

on implementations w/ fpu included unimplemented instructions
are signaled through the exception trap w/ invalid opcode marked
instruction in the exception registers, not through the emulation
trap (as long as the fpu is enabled, of course).
parse emulation from the exception trap as well as the emulation
trap and fix the dispatcher into usable condition.
parse invalid op exception on trap and signal the user appropriately.
reset the exception on exec and for child on fork.
the later is appropriate since exceptions are delayed until next
fpu instruction, which was in the parent indeed, let him get it.
save parent's fpu context on fork before cipying it, if the
parent owned the fpu.


Revision tags: OPENBSD_3_2_BASE
# 1.81 23-Sep-2002 mickey

parisc level 0x10 is just an overclocked 0xe


# 1.80 17-Sep-2002 mickey

handle fpu exceptions properly, might use a regress, i guess


# 1.79 11-Sep-2002 mickey

provide a convinient reset label


# 1.78 11-Sep-2002 mickey

stack grows the other way, but the frame is the other way to that. hehe


# 1.77 09-Sep-2002 mickey

set up the frame flags and a user frame better on exec


# 1.76 03-Aug-2002 mickey

rework boot() w/o a goto


# 1.75 25-Jul-2002 mickey

missing arg in the call to the pdc_call since some old times


# 1.74 25-Jul-2002 mickey

kcopy is a space-to-space copy from kernel space, to guess where, -- to the same kernel space, just error on fault


# 1.73 20-Jul-2002 art

Instead of copying out the signal trampoline on top of the stack, create
an uvm aobj, copy out the signal trampoline into it and share that page
among all processes for the same emulation.

This also requires us to actually be able to tell signal code where the
trampoline is located, so introduce a new field in struct proc - p_sigcode
that is a pointer to sigcode. This allows us to remove all the ugly
calculations of the signal trampoline address done in every sendsig
function in the tree (that's why so many files are changed).

Tested by various people. ok deraadt@


# 1.72 14-May-2002 mickey

disable sid hashing while still in real mode, alos print the parisc arch once and not per each cpu since they are not intermixable architecture-wise


# 1.71 13-May-2002 mickey

ldi-ldo whatever was in the table, be that much clever


# 1.70 08-May-2002 mickey

print parisc level w/ the the parisc version, not for each cpu


# 1.69 08-May-2002 mickey

kill debugging printfski


# 1.68 22-Apr-2002 mickey

no longer batc the data, only the code.
this removes a constraint and an ld.script dependancy
for the .data and the dynamically allocated kernel
structures existed w/ batcing. also makes pmap_steal_memory
obsolete and replaced w/ the pmap_virtual_space.
implement batching for pmap_remove to avoid
zeroing out the pte entries if pde will be removed anyway.


# 1.67 21-Apr-2002 mickey

better buf's mapping and less magic constants in checking for io space cachability


Revision tags: OPENBSD_3_1_BASE
# 1.66 26-Mar-2002 mickey

if cannot guess cpu model default to the lowest supported one


# 1.65 25-Mar-2002 deraadt

spelling


# 1.64 23-Mar-2002 espie

Add variables for config(8) -e time tweak of systemV shared memory
parameters.

Ok millert@, miod@, maja@


# 1.63 19-Mar-2002 mickey

mtcpu seq requires a pre-sync, implement hpt init for pcxl


# 1.62 15-Mar-2002 mickey

rewrite a pmap to use multilevel page tables.
lower 12 bits contain the perms, no unused bits left,
but a couple for off-tlb use (as the ref implemented now).
do not use the hvt, which might get some use later
if proven to speed thigs up, tlb handlers would po
another dozen of insns though, but if that's worth its...
move on the data seg and map kernel text rdonly (idea form fredette),
since all of the page0 mods done before that we are all fine
except for some viper fluff, but later w/ that.
this also picks up a bit more of ddb magic for bpt and ss.
tlb handlers can use a little bit more of attention,
but things, visually, seem to be much faster already, --
sorry, no benchmarks for now.

* effort sponsored in part by the `henry st. old ale house'
* and mr.pete and mr.lee in particular in thier generous entrirety.
* the proj took a little more that 72man*h as it was expected,
* but within murhy's law estimations.


# 1.61 14-Mar-2002 millert

First round of __P removal in sys


# 1.60 20-Feb-2002 mickey

setup power failure handler (for sw-controlled power button), move toc handler


# 1.59 17-Feb-2002 maja

Patch from Daniel Lucq <daniel@lucq.org>

The patch allows you to change the value of NMBCLUSTERS, BUFCACHEPERCENT
and NKMEMPAGES using the config command, instead of recompiling the kernel.

This is the kernel part of the patch. I have compiled it on i386, sparc64,
alpha and macppc. -moj ok art@ maja@


# 1.58 12-Feb-2002 mickey

support 712's programmable power switch, no interrupt yet


# 1.57 12-Feb-2002 mickey

small repairs to hpmc and toc handlers


# 1.56 11-Feb-2002 mickey

disable fpu on csw, print fpu version on cpu line, if present


# 1.55 07-Feb-2002 mickey

fix sigdebug cases; init sigcontext before it's used (;


# 1.54 06-Feb-2002 mickey

implement signal delivery; based on fredette@'s work


# 1.53 03-Feb-2002 mickey

restore hpt size computation, does not break things as i thought


# 1.52 02-Feb-2002 mickey

fix 'physmem' usage


# 1.51 02-Feb-2002 mickey

implement the rest of /dev/mem devices; from netbsd


# 1.50 23-Jan-2002 art

move mb_map allocation to mbinit()


# 1.49 23-Jan-2002 art

move definition of mb_map from zillions of machdep.c to uipc_mbuf.c


# 1.48 16-Jan-2002 miod

Don't include <sys/map.h> when you don't need what's in it.


Revision tags: UBC_BASE
# 1.47 02-Dec-2001 mickey

branches: 1.47.2;
increase fixed extent storage


# 1.46 28-Nov-2001 art

zap some typedefs.
vm_map_t -> struct vm_map *
vm_map_entry_t -> struct vm_map_entry *
simple_lock_data_t -> struct simplelock

(uvm not done yet, coming in the next commit)


# 1.45 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.44 24-Nov-2001 miod

Harmonize boot() logic across arches:
- ensure RB_DUMP | RB_HALT will cause a dump
- or RB_HALT if (cold)
While there, honor RB_TIMEBAD on sparc64.


# 1.43 09-Nov-2001 art

nswbuf hasn't been used for ages. gc.


# 1.42 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.41 06-Nov-2001 miod

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


Revision tags: OPENBSD_3_0_BASE
# 1.40 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.39 12-Sep-2001 art

mbutl no more


# 1.38 23-Aug-2001 art

We can now move timeout_init into main().


# 1.37 23-Aug-2001 art

Remove even more old timeout tentacles.


# 1.36 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.35 05-Jul-2001 art

Get rid of REAL_CLISTS. It was never implemented and the tentacles are
everywhhere.


# 1.34 17-May-2001 provos

convert mbuf and cluster allocation to pool, mostly from NetBSD
okay art@ miod@


# 1.33 05-May-2001 art

Rename configure() to cpu_configure().
Move it from cpu_startup() to main().


# 1.32 05-May-2001 art

Get rid of CLSIZE and all related stuff.
CLSIZE -> 1
CLBYTES -> PAGE_SIZE
OLOFSET -> PAGE_MASK
etc.
At the same time some archs needed some cleaning in vmparam.h so that
goes in at the same time.


Revision tags: OPENBSD_2_9_BASE
# 1.31 29-Mar-2001 mickey

cpudev_data.h here needed not


# 1.30 22-Mar-2001 mickey

shuffle the tlb handlers a little,
make a new one for na data fault,
since those w/ hpt need it.


Revision tags: OPENBSD_2_8_BASE
# 1.29 15-Aug-2000 mickey

two btlb routines (i & d) for pcxs


# 1.28 15-Aug-2000 mickey

expand per-cpu control routines switch


# 1.27 08-Aug-2000 mickey

print btlb params w/ BTLBDEBUG; from Havard.Eidnes@runit.sintef.no


# 1.26 02-Jul-2000 mickey

no bays for stinger


Revision tags: OPENBSD_2_7_BASE
# 1.25 23-Mar-2000 mickey

new cpu type switch code.
initializes tlb miss handlers correspondent to probed cpu features.
also btlb load routine.
versions written are for pcxl and others.
cpu-dep btlb loaders are missing, only generic for now.


# 1.24 23-Mar-2000 art

New API for timeouts. Replaces the old timeout()/untimeout() API and
makes it the callers responsibility to allocate resources for the
timeouts.

This is a KISS implementation and does _not_ solve the problems of slow
handling of a large number of pending timeouts (this will be solved in
future work) (although hardclock is now guarateed to take constant time
for handling of timeouts).

Old timeout() and untimeout() are implemented as wrappers around the new
API and kept for compatibility. They will be removed as soon as all
subsystems are converted to use the new API.


# 1.23 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


# 1.22 22-Feb-2000 mickey

blah, blah, blah, msgbuf


Revision tags: SMP_BASE
# 1.21 09-Feb-2000 mickey

branches: 1.21.2;
heartbeat -- yeah we have a patch for that


# 1.20 25-Jan-2000 mickey

better copy and zero inlines in locore;
proper setregs() in machedep;
start of hpmc handler;
some cleanup here and there;


# 1.19 17-Jan-2000 mickey

remove unneeded stuff from setregs; force single-user for now, enable signal debug


# 1.18 11-Jan-2000 mickey

s/fpu_curproc/fpu_curpcb/ which also points into physical.
move it's definition into locore (where it's used the most).
adjust fpu context switch and save on swapout accordingly.
fix context save (in switch).
add accounting for fpu context switches (since it differes
from proc switching, we might get provided w/ some usefull
numbers as to how effective this lazy switch technique is).
enable handling fpu/sfu exceptions.


# 1.17 31-Dec-1999 mickey

don't bother about pidr3 and pidr4


# 1.16 17-Dec-1999 mickey

fix the panic message for sti memory mapping


Revision tags: kame_19991208
# 1.15 25-Nov-1999 mickey

bus stuff is in mainbus now, the rest is rewritten many ways


Revision tags: OPENBSD_2_6_BASE
# 1.14 20-Sep-1999 mickey

fix uvm_pagealloc() call


# 1.13 03-Sep-1999 art

Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.12 14-Aug-1999 mickey

proper debugging ifdefs


# 1.11 21-Jul-1999 mickey

rewrite the tlb miss handler and tlb dirty handler.
optimize for HVT usage (when compiled for proper cpu type).
drop hpt_* global variables, use info from control registers instead.
there are still ways to improve the tlb handlers tho.
machdep also prints cache and tlb coherence states (not related to the above).
You eat greenish muffin. --More-- You write real code.


# 1.10 12-Jul-1999 mickey

allocate 5% bufcache if <=16M memory installed


# 1.9 12-Jun-1999 mickey

hppa_init() now takes an argument from locore,
meaning the start of available memory.
cleanup machdep somewhat.
fix vm_map.pmap vs vm_pmap isue; 10x art@


# 1.8 23-May-1999 mickey

new swap stuff


# 1.7 21-May-1999 mickey

group all theMD f;ags together, add interrupt recursion one


# 1.6 21-May-1999 mickey

define fpu_curproc


# 1.5 20-Apr-1999 mickey

do lazy blok mapping of io space in bus_*
add copy{in,out}*, kcopy, etc
boot routines
cpu-id-hpux-compat stuff
rest of scheduler and such
uvm


Revision tags: OPENBSD_2_5_BASE
# 1.4 17-Feb-1999 mickey

print pa-risc here as well, since, finally, cpu will have to print processor type


# 1.3 04-Jan-1999 mickey

better cache handling in bus_space_barrier(), seem to work now


# 1.2 03-Jan-1999 mickey

implement bus_space_{un,}map w/ extents


# 1.1 30-Dec-1998 mickey

machdep; more work needed


# 1.267 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_7_2_BASE
# 1.266 10-Aug-2022 jsg

match other archs use %s for version printf


Revision tags: OPENBSD_7_1_BASE
# 1.265 06-Oct-2021 claudio

Change sendsig() interface so that the MD code does not need to access
data from struct process anymore. This changes how siginfo and onstack
are accessed and make sendsig() more MP friendly.
With and OK semarie@ OK kettenis@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.264 11-Mar-2021 jsg

spelling


# 1.263 09-Jan-2021 kettenis

"encoding of diag instructions is hard, let's go shopping"

Clean up things a bit, adding documentation about the source of the
information about these instructions.

From miod@


# 1.262 08-Nov-2020 mpi

In case of failure, call sigexit() from trapsignal instead of sensig().

Simplify MD code and reduce the amount of recursion into the signal code
which helps when dealing with locks.

ok cheloha@, deraadt@


# 1.261 21-Oct-2020 deraadt

hppa also has a similar to arm64: copyout(9), copyinstr(9) and
copyoutstr(9) should bail out properly if they are called with a
length of 0.
ok kettenis@


Revision tags: OPENBSD_6_8_BASE
# 1.260 14-Jun-2020 naddy

Implement cpu_rnd_messybits() as a read of the cycle counter register.
ok dlg@ deraadt@


# 1.259 31-May-2020 dlg

introduce "cpu_rnd_messybits" for use instead of nanotime in dev/rnd.c.

rnd.c uses nanotime to get access to some bits that change quickly
between events that it can mix into the entropy pool. it doesn't
use nanotime to get a monotonically increasing set or ordered and
accurate timestamps, it just wants something with bits that change.

there's been discussions for years about letting rnd use a clock
that's super fast to read, but not necessarily accurate, but it
wasn't until recently that i figured out it wasn't interested in
time at all, so things like keeping a fast clock coherent between
cpu cores or correct according to ntp is unecessary. this means we
can just let rnd read the cycle counters on cpus and things will
be fine. cpus with cycle counters that vary in their speed and
arent kept consistent between cores may even be desirable in this
context.

so this is the first step in converting rnd.c to reading cycle
counter. it copies the nanotime backend to each arch, and they can
replace it with something MD as a second step later on.

djm@ suggested rnd_messybytes, but we landed on cpu_rnd_messybits.
thanks to visa for his eyes.
ok deraadt@ visa@
deraadt@ says he will help handle any MD fallout that occurs.


# 1.258 16-May-2020 kettenis

Make inittodr() and resettodr() MI.

ok deraadt@, mpi@, visa@
ok cheloha@ as well (would have preferred in new file for this code)


# 1.257 11-May-2020 kettenis

Initialize the timeval passed to todr_gettime() with the base time from
the file system such that implementations can use it to guess the right
century.

ok mpi@


Revision tags: OPENBSD_6_7_BASE
# 1.256 01-May-2020 kettenis

Use the same inittodr()/resettodr() implementation as on
amd64/arm64/armv7/i386/sparc64 and move it to the end of machdep.c. Rework the
actual implementation for the MC14818 compatible RTC into something that can
be used as a todr_handle just like on amd64.

ok mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.255 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


Revision tags: OPENBSD_6_4_BASE
# 1.254 20-Jul-2018 guenther

Missed a 'ksi' -> '*ksip' change in previous commit


# 1.253 10-Jul-2018 guenther

Move from sendsig() to its callers the initsiginfo() calls and
instead of passing sendsig() the code+type+val, pass a siginfo_t*
to copy from. Eliminate the indirection through struct emul for
sendsig(); we no longer have a SunOS4-compat version of sendsig()

ok deraadt@


# 1.252 22-May-2018 guenther

Delete antique sigdebug definitions

ok kettenis@


# 1.251 12-Apr-2018 deraadt

Implement MAP_STACK option for mmap(). Synchronous faults (pagefault and
syscall) confirm the stack register points at MAP_STACK memory, otherwise
SIGSEGV is delivered. sigaltstack() and pthread_attr_setstack() are modified
to create a MAP_STACK sub-region which satisfies alignment requirements.
Observe that MAP_STACK can only be set/cleared by mmap(), which zeroes the
contents of the region -- there is no mprotect() equivalent operation, so
there is no MAP_STACK-adding gadget.
This opportunistic software-emulation of a stack protection bit makes
stack-pivot operations during ROPchain fragile (kind of like removing a
tool from the toolbox).
original discussion with tedu, uvm work by stefan, testing by mortimer
ok kettenis


Revision tags: OPENBSD_6_3_BASE
# 1.250 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.249 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


Revision tags: OPENBSD_6_2_BASE
# 1.248 18-May-2017 kettenis

Implement copyin32(9).

"your chicken scratches look fine to me" deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.247 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

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


# 1.246 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.245 21-May-2016 deraadt

hand-massage sendsig() and sys_sigreturn() to be much more similar.
ok guenther kettenis


# 1.244 10-May-2016 deraadt

SROP mitigation. sendsig() stores a (per-process ^ &sigcontext) cookie
inside the sigcontext. sigreturn(2) checks syscall entry was from the
exact PC addr in the (per-process ASLR) sigtramp, verifies the cookie,
and clears it to prevent sigcontext reuse.
not yet tested on landisk, sparc, *88k, socppc.
ok kettenis


# 1.243 20-Apr-2016 dlg

pool_setipl for floating point context things

ok kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.242 21-Oct-2015 mpi

Do not call uvm_swap_finicrypt_all() a second time in dumpsys().

ok tedu@, deraadt@, miod@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.241 20-Jan-2015 kettenis

Move ps_strings "after" the random stackgap. This makes its location a
per-process value, and therefpore turns the VM_PSSTRINGS sysctl into a
per-process one as well. This gets rid of a pointer to the bottom of the
stack at a fixed location. Also clears the road for unmapping the stackgap.

ok deraadt@


# 1.240 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.239 25-Oct-2014 kettenis

Remove vmmap; it isn't used.

ok jsing@


# 1.238 23-Oct-2014 miod

Correctly set up the HPMC trap entry: according to the PA-RISC Firmware
Architecture Reference Specification, the sum of the 8 trap entry words
*and* of the payload which address and length are to be set at well-known
positions in the aforementioned trap entry, needs to be zero; the existing
code was only enforcing that the sum of the trap entry words is zero.

This matches what Linux and NetBSD do.

ok kettenis@


# 1.237 23-Oct-2014 miod

Revert limiting physmem to 2GB; the culprit was likely in uvm and uvm has
changed a lot in the last 5 years; verified to work on a 3GB system, in
snapshots for a few weeks already.


# 1.236 22-Sep-2014 dlg

implement atomic_{cas,swap}_{uint,ulong,ptr} and
atomic_{add,sub}_{int,long}_nv. sys/atomic.h turns these into the
rest of the atomic api.

on uniprocessor hppa systems "atomic" operations are implemented
as a non-interruptable sequence by disabling all interrupts on the
cpu, doing the operation, and then restoring the interrupt mask.

this isnt enough on MP systems, so we added a global atomic memory
mutex that is taken inside the interrupt disabling above to coordinate
operations between cpus.

this is a lot of overhead though cos mutexes dance around with ipls,
which is unecessary in our case because of the interrupt disabling
that is already done. also, hppa spinlocks are implemented with
ldcw which requires the word it operates on to be 16 byte aligned.
mutexes arent guaranteed to have this alignment so they compensate
by having lots of words inside themselves so they can hit the
appropriate one to use for the ldcw op.

with this in mind, this change pulls __cpu_simple_locks, which are
simply ldcw spinlocks with a 16 byte aligned word, out of
src/sys/arch/hppa/include/lock.h into src/sys/arch/hppa/include/atomic.h
so atomic.h can use them. lock.h includes atomic.h, so it still
gets and provides the same functionality as before.

finally, this also pulls the rwlock cas implementation apart. cas
ops now share the same serialising lock on MP systems as the other
memory operations, and rw_cas is defined as a wrapper around
atomic_cas_uint.

ok kettenis@


# 1.235 19-Sep-2014 kettenis

Use config_suspend_all(9).


# 1.234 18-Aug-2014 dlg

dont rely on mbuf.h to provide pool.h.

ok miod@, who has offerred to help with any MD fallout
ok guenther@


Revision tags: OPENBSD_5_6_BASE
# 1.233 22-Jul-2014 uebayasi

boot(9): Reduce diffs between hppa & hppa64 (& others)


# 1.232 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.231 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.230 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.229 13-Jul-2014 miod

These still need <sys/reboot.h> for the RB_ constants.


# 1.228 12-Jul-2014 uebayasi

reboot(9), panic(9): Call panic(9) for unrecoverable MD H/W errors (NMIs)

Some architectures have ability to detect hardware sanity and notify system
(NMI, firmware callback, etc.). Handle these hardware severe errors, same
as software errors, with panic(9).

According to miod@, SGI IP27 NMI is triggered by pushing some "hidden" button,
which "usual" users/admins don't know. Pushing such a button is "RB_USERREQ"
(human-triggered) in that the button is pushed by a human, but not "RB_USERREQ"
in that no user intervention in system (== no command input) is done. miod@
agreed that changing these from RB_USERREQ to !RB_USERREQ (== panic(9)) is
not a big problem.

OK miod@ kettenis@


# 1.227 12-Jul-2014 uebayasi

boot(9), reboot(9): Migrate MD callers of boot(9) to reboot(9)

I have found that some ports call boot(9) from machine-dependent code to
reboot system. These should be changed to either:

- Sending signal to init(8) to trigger it to shutdown system cleanly, like
acpi(4) does, in cases where found problems don't prevent system from working
immediately, or

- Just doing panic(9) if the situation is severely broken.

For now, just rewrite boot() to reboot(). Actual fixes follow.

Discussed with & OK from kettenis@


# 1.226 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.225 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.224 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.223 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.222 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.221 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.220 08-May-2014 miod

Format string fixes and removal of -Wno-format for hppa kernels.


# 1.219 08-Apr-2014 mpi

Less <uvm/uvm.h>


# 1.218 04-Apr-2014 miod

If the PDC_COPROC call fails, and we are running on a PA 1.1 system, assume
the usual 1.1 coprocessor mask, instead of using zero and having every
userland process dying with signal 4.

The circumstances under which this call fails are unclear and could be
tied to specific PROM version (I have tried overzealous stack alignment and
other tricks, to no avail). Interestingly enough, the 715/75 system which
hits this problem, only triggers it when booting from disk, and never when
booting from network.

This diff is an ugly bandaid until the problem is better understood. Or maybe
it is not worth investigating, seeing that Linux hardcodes the coprocessor
mask and never issues PDC_COPROC calls; I wonder what HP/UX does.

In my tree for over 18 months; "Looks like a nice hack" deraadt@
715/75 system provided by Sebastiaan Indesteege, thanks!


# 1.217 29-Mar-2014 guenther

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

ok dlg@ mpi@ deraadt@


# 1.216 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


# 1.215 22-Mar-2014 guenther

Move p_sigacts from struct proc to struct process.

testing help mpi@


# 1.214 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


Revision tags: OPENBSD_5_5_BASE
# 1.213 23-Nov-2013 uebayasi

Run doshutdownhooks() and config_suspend() even when boot() is called while
cold != 0. Indent and make hppa/hppa64 boot() closer to others.

OK kettenis@


# 1.212 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


Revision tags: OPENBSD_5_4_BASE
# 1.211 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


Revision tags: OPENBSD_5_3_BASE
# 1.210 02-Dec-2012 guenther

Determine whether we're currently on the alternative signal stack
dynamically, by comparing the stack pointer against the altstack
base and size, so that you get the correct answer if you longjmp
out of the signal handler, as tested by regress/sys/kern/stackjmp/.
Also, fix alt stack handling on vax, where it was completely broken.

Testing and corrections by miod@, krw@, tobiasu@, pirofti@


# 1.209 26-Oct-2012 kettenis

Properly clear trap frame in setregs() to avoid leaking registers across exec.

ok jsing@


# 1.208 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.207 07-Oct-2012 kettenis

Align the stack on a 64-byte boundary as required by "The 32-bit PA-RISC
Run-time Architecture Document". GCC relies on this to properly align
stack variables.

ok guenther@, beck@


Revision tags: OPENBSD_5_2_BASE
# 1.206 21-Jun-2012 guenther

__tfork() needs to set the stack address of the new thread in the kernel,
so that it can't get a signal while still running on the parent thread's
stack. Also, pass in sizeof(struct __tfork) to provide forward compat
when more members are added. This is an ABI change, so switch syscall
numbers and bump lib majors this time.

ok deraadt@ matthew@


Revision tags: OPENBSD_5_1_BASE
# 1.205 20-Sep-2011 miod

Clear RB_POWERDOWN early in boot() on systems which can not powerdown and
which firmware does not send spin up commands to the disks, in case the
operator changes his mind and reboots instead of manually powering down
after the system has halted.
ok kettenis@


Revision tags: OPENBSD_5_0_BASE
# 1.204 05-Jul-2011 guenther

Recommit the reverted sigacts change now that the NFS use-after-free
problem has been tracked down. This fixes the sharing of the signal
handling state: shared bits go in sigacts, per-rthread bits goes in
struct proc.

ok deraadt@


# 1.203 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.202 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.201 18-Apr-2011 guenther

Revert the sigacts diff: NFS can apparently retain pointers to processes
until they're zombies and then send them signals (for intr mounts). Until
that is untangled, the sigacts change is unsafe. sthen@ was the victim
for this one


# 1.200 15-Apr-2011 guenther

Correct the sharing of the signal handling state: stuff that should
be shared (p_sigignore, p_sigcatch, P_NOCLDSTOP, P_NOCLDWAIT) moves
to struct sigacts, wihle stuff that should be per rthread (ps_oldmask,
SAS_OLDMASK, ps_sigstk) moves to struct proc. Treat the coredumping
state bits (ps_sig, ps_code, ps_type, ps_sigval) as per-rthread
until our locking around coredumping is better.

Oh, and remove the old SunOS-compat ps_usertramp member.

"I like the sound of this" tedu@


Revision tags: OPENBSD_4_9_BASE
# 1.199 14-Jan-2011 jsing

Halt secondary CPUs when shutting down or rebooting. This should prevent
occasional hangs during reboot.

ok kettenis@


# 1.198 04-Jan-2011 jasper

- de-register. no binary change.

ok jsing@


# 1.197 01-Jan-2011 jasper

Move setting cpu_hzticks to the clock initialization function, like
other ports (e.g. hppa64) do.

ok jsing@ kettenis@


# 1.196 01-Jan-2011 jasper

- ansify

ok jsing@ kettenis@


# 1.195 30-Dec-2010 jsing

Turn signotify() into a function that also calls cpu_unidle().

ok kettenis@


# 1.194 20-Nov-2010 miod

This is a first step towards getting rid of avail_start and avail_end in the
kernel, currently limited to low-hanging fruit: these variables were used
by bus_dma to specify the range in which to allocate memory, back when
uvm_pglistalloc() was stupid and would not walk the vm_physseg[].

Nowadays, except on some platforms for early initialization, these variables
are not used, or do not need to be global variables. Therefore:
- remove `extern' declarations of avail_start and avail_end (or close cousins,
such as arm physical_start and physical_end) from files which no longer need
to use them.
- make them local variables whenever possible.
- remove them when they are assigned to but no longer used.


Revision tags: OPENBSD_4_8_BASE
# 1.193 01-Jul-2010 jsing

Create a struct to store FP state and include a pointer to the CPU that
currently holds the FPU context for this process. This will be soon used
to implement FPU shootdowns on multiprocessor kernels.

ok kettenis@


# 1.192 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.191 29-Jun-2010 jsing

Factor out code used to save and flushe process FPU context.

ok kettenis@


# 1.190 29-Jun-2010 jsing

Store pointer to process FPU state in struct cpu_info.

ok kettenis@


# 1.189 27-Jun-2010 thib

uvm constraints. Add two mandatory MD symbols, uvm_md_constraints
which contains the constraints for DMA/memory allocation for each
architecture, and dma_constraints which contains the range of addresses
that are dma accessable by the system.

This is based on ariane@'s physcontig diff, with lots of bugfixes and
additions the following additions by my self:

Introduce a new function pool_set_constraints() which sets the address
range for which we allocate pages for the pool from, this is now used
for the mbuf/mbuf cluster pools to keep them dma accessible.

The !direct archs no longer stuff pages into the kernel object in
uvm_km_getpage_pla but rather do a pmap_extract() in uvm_km_putpages.

Tested heavily by my self on i386, amd64 and sparc64. Some tests on
alpha and SGI.

"commit it" beck, art, oga, deraadt
"i like the diff" deraadt


# 1.188 27-Jun-2010 jsing

Use a mutex to make atomic operations atomic on multiprocessor kernels.

ok kettenis@


# 1.187 10-Jun-2010 deraadt

Declare safepri at the MD level on each platform, so that the kern_synch.c
does not have to deal with it as a common. Some platforms may be missed
by this commit... if you spot one, fix it the same way.
ok miod


# 1.186 09-Jun-2010 miod

Move declaration of cn_tab from dev/cons.c to dev/cninit.c, or appropriate
md files for ports which do not use dev/cninit.c. This gets rid of a common
at kernel link time.
feedback drahn@ ok deraadt@


# 1.185 24-May-2010 deraadt

Add missing prototypes
ok jsing kettenis


# 1.184 09-May-2010 kettenis

Prevent "taken branch" exceptions from kernel space by clearing the PSL_T
bit before we enter a signal handler.

"if you say so" miod@, "seems to make sense" jsing@


# 1.183 02-May-2010 kettenis

Properly initialize the members of `struct mdproc' that deal with
single-stepping when we fork and reset them upon exec.

ok miod@


# 1.182 27-Apr-2010 kettenis

Avoid null-pointer dereference by giving proc0 a place to store its
floating-point registers. Pointed out by Nick Hudson.

ok miod@, jsing@


# 1.181 19-Apr-2010 jsing

Make the Processor Status Word (PSW) a per-CPU value.

ok kettenis@


# 1.180 01-Apr-2010 jsing

Allow for multiple CPUs by moving to an array of cpu_info.

ok kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.179 31-Dec-2009 jsing

Make cpl and cpu_inintr per CPU variables. For locore.S, cpl becomes an
offset within cpu_primary_info - this will need to be revisited shortly.

ok kettenis@


# 1.178 11-Aug-2009 miod

Do not bother initializing bufpages in the md code if the computation is
exactly the same the mi could will use if bufinit() is invoked with
bufpages == 0.


# 1.177 11-Aug-2009 miod

With the SysV memory allocation changes, allocsys() doesn't do anything
anymore. Get rid of it completely.


# 1.176 09-Aug-2009 blambert

Rototill system V message queues.

No longer allocate a static amount of memory for messages in MD
boot path; message queues, message metadata, and message data now
all use dynamic memory, which means that runtime sysctls should now
be trivial to implement.

Since I'm going to be around all week to fix any breakage, this should
probably just go in now.


# 1.175 02-Aug-2009 beck

Dynamic buffer cache support - a re-commit of what was backed out
after c2k9

allows buffer cache to be extended and grow/shrink dynamically

tested by many, ok oga@, "why not just commit it" deraadt@


# 1.174 29-Jul-2009 kettenis

Get rid of non-equivalent aliases of the pcb by moving the fpu state out
of the pcb and using the p_addr member of 'struct proc' to calculate the
address of the kernel stack when switching to virtual mode after taking a trap.
Remove the now unecessary cache flushes; they're actually harmful since they
create non-equivalent aliases. This seems to fix the memory corruption we
have been observing from time to time.

This diff does not rename fpu_curpcb, which is now somewhat incorrectly named.
I hope to change things back again as soon as we are able to map the pcb 1:1.


Revision tags: OPENBSD_4_6_BASE
# 1.173 15-Jun-2009 beck

Back out all the buffer cache changes I committed during c2k9. This reverts three
commits:

1) The sysctl allowing bufcachepercent to be changed at boot time.
2) The change moving the buffer cache hash chains to a red-black tree
3) The dynamic buffer cache (Which depended on the earlier too).

ok on the backout from marco and todd


# 1.172 03-Jun-2009 beck

add kern.bufcachepercent sysctl to allow adjusting the buffer cache
size on a running system.
ok art@, oga@


Revision tags: OPENBSD_4_5_BASE
# 1.171 14-Feb-2009 kettenis

Limit the amount of physical memory to 2GB. Using more causes memory
corruption on PA-RISC 2.0 systems (and there are very few PA-RISC 1.1
systems that support more than 2GB).

ok miod@


# 1.170 04-Feb-2009 miod

On systems with split BTLB, do not bother trying to insert DBTLB entries,
as PDC will lie to us pretending it did while it didn't.

ok kettenis@


# 1.169 04-Feb-2009 miod

Unify memory size reports a bit more: always report size in MB, and report
reserved memory on alpha and hppa on its own line (as done on sgi).


Revision tags: OPENBSD_4_4_BASE
# 1.168 14-Jul-2008 miod

Be sure to propagate PSL_O in psw on PCXU* processors to userland processes
and signal handlers.
ok kettenis@


# 1.167 27-Jun-2008 miod

Clear swap encryption keys before dumping a kernel image.


# 1.166 09-Apr-2008 deraadt

Add new stub uvm_shutdown() and call it from the right place in MD boot()


Revision tags: OPENBSD_4_3_BASE
# 1.165 22-Sep-2007 martin

replace even more ctob and btoc with ptoa and atop respectively plus
uvm_extern.h where needed


Revision tags: OPENBSD_4_2_BASE
# 1.164 22-Jul-2007 kettenis

Move hppa to __HAVE_TIMECOUNTERS.


# 1.163 20-Jul-2007 kettenis

Give hppa the blink_led API from sparc64, and the associated machdep.led_blink
sysctl.


# 1.162 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.161 14-Jul-2007 kettenis

Make sigreturn(2) set the proper space ID for the instruction queue. Fixes
a few more pthreads regression tests.

ok miod@


# 1.160 10-Jul-2007 kettenis

Don't trust the privilige level in the sigcontext passed to sigreturn(2).

ok miod@


# 1.159 24-Jun-2007 kettenis

Crank initial storage for extents a bit. We really should allocate extents
using malloc once vm is initialised, but this will do for now.

ok deraadt@


# 1.158 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.157 27-May-2007 miod

Make sure the minaddr hint for uvm_km_suballoc() calls is always initialized.
ok pedro@


# 1.156 26-May-2007 pedro

Dynamic buffer cache. Initial diff from mickey@, okay art@ beck@ toby@
deraadt@ dlg@.


# 1.155 21-May-2007 kettenis

Add support for 8700/pcxw2 cpu.


# 1.154 21-May-2007 kettenis

Ask firmware for reset before trying ourselves; needed for four-digit b/c/j
workstations.

tested by otto@, krw@; ok deraadt@


# 1.153 17-May-2007 art

Limit hppa buffer cache to 30%. It used to be 70% because stack garbage
that was used for minaddr instead of the proper vm_map_min(kernel_map)
(fixed in this diff).

From mickey. art@ ok


# 1.152 14-May-2007 martin

move hppa to __HAVE_CPUINFO

input from miod@, ok kettenis@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.151 28-May-2006 martin

minor nit, use CPU ID instead of FPU ID for BTLB parameters after passing
all kludges


# 1.150 15-Apr-2006 martin

make warning about missing HPT support DEBUG for now

ok mickey@


Revision tags: OPENBSD_3_9_BASE
# 1.149 26-Oct-2005 martin

no more hppa_round_page() and hppa_trunc_page() macros

ok mickey@


Revision tags: OPENBSD_3_8_BASE
# 1.148 06-Aug-2005 miod

We do not need a char machine_arch[] constant.
ok deraadt@


# 1.147 11-Jul-2005 mickey

align some stupid comments


# 1.146 10-May-2005 mickey

set pcsq in case we get signal delivery once interrupted from the gateway page; from chs


# 1.145 18-Apr-2005 mickey

do not do some of the initmsgbuf()s job


# 1.144 07-Apr-2005 mickey

on some machines it's possible to limit the amount of physmem initialised dring post so having msgbuf at the end of memory shall work


# 1.143 07-Apr-2005 mickey

64bit-friendly pdc.h and iomod.h and correspondent changes elsewhere


# 1.142 26-Mar-2005 mickey

md parts for hpux_compa code; some problems w/ signals delivery still exist


Revision tags: OPENBSD_3_7_BASE
# 1.141 24-Feb-2005 mickey

do not even ask for btlb on 8k cpus as pdc pretends there is some but then it does not work; found w/ Moritz Kiese <mbk@mytum.de> on c180; add a debug print and fix pcxu entry


# 1.140 17-Nov-2004 mickey

print real/avail/bufcache sizes as unsigned


# 1.139 26-Oct-2004 mickey

disable sid hashing on pcxu and above


# 1.138 14-Oct-2004 mickey

a bit larger delays during boot() to let msgs appear


# 1.137 19-Sep-2004 mickey

turn totalphysmem into physmem and name old physmem into smth it really is


# 1.136 18-Sep-2004 mickey

oops


# 1.135 15-Sep-2004 mickey

add pcxu tlb handlers and cpu probing
add u2/uturn ioa driver in dumb mode now
enable pcxu/pcxw support


# 1.134 14-Sep-2004 mickey

store fpu version for later use. make sure to proper store/clear fpu state in fork/exec/exit/sendsig


# 1.133 14-Sep-2004 mickey

error out from btlb_insert() if there is none


Revision tags: OPENBSD_3_6_BASE
# 1.132 01-Jul-2004 mickey

have separate insn and data cache all-flushers


# 1.131 30-Jun-2004 mickey

allow forced fpu emulation through a sysctl


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.130 13-May-2004 mickey

8ks do not have hvt


# 1.129 05-May-2004 mickey

much easier tlb handler branch patching


# 1.128 05-May-2004 mickey

do not engage HPT on PCXT' (yet)


# 1.127 08-Apr-2004 mickey

repair pcxs/t confoosion


# 1.126 07-Apr-2004 mickey

update copyright; miod@ is fine w/ files where he holds it too


Revision tags: OPENBSD_3_5_BASE
# 1.125 10-Mar-2004 tom

Ensure that we obey a user's ddb> boot reboot command even if the system
is cold (during startup).

This adds RB_USERREQ to sys/reboot.h, uses it in the ddb commands, and
ensures that */*/machdep.c:boot() won't set RB_HALT when cold if this
flag is set.

ok deraadt@


# 1.124 14-Feb-2004 grange

Simplify hw.{cpuspeed,setperf} api moving all the sysctl stuff
from the underlying callbacks.

Testing hppa mickey@, ppc drahn@
Ok markus@ tedu@


# 1.123 05-Jan-2004 mickey

kill debugging code that is not needed anymore


# 1.122 23-Dec-2003 mickey

provide cpuspeed fluff


# 1.121 20-Dec-2003 miod

Don't let microtime() return a struct timeval with exactly 1000000 microseconds.


# 1.120 18-Dec-2003 mickey

spls do not protect cpu_itmr and thus time might jump back sometimes due to cpu_itmr modified to a higher value than a read itmr; found and testing by miod@


# 1.119 17-Dec-2003 mickey

in the real mem print do not include reserved for prom into used by openbsd


# 1.118 10-Dec-2003 mickey

for unaligned btlb mapping attempts -- just fail


# 1.117 24-Nov-2003 mickey

experimental support for HVT as a 2nd level tlb


# 1.116 15-Oct-2003 mickey

less global name space pollution


# 1.115 05-Oct-2003 mickey

reload the itmr as soon as we get the intr to avoid lagging on slower machines


# 1.114 25-Sep-2003 mickey

some pcxl2 do not report fpus -- assume it's there


Revision tags: OPENBSD_3_4_BASE
# 1.113 04-Sep-2003 mickey

a better cpu identification; testing by miod


# 1.112 31-Aug-2003 miod

pdc_model needs to be visible from cpu.c


# 1.111 20-Aug-2003 mickey

missing nl in debugging prontf


# 1.110 07-Aug-2003 mickey

dead proto


# 1.109 07-Aug-2003 mickey

first allocate space on stack then copyout signal shits. add a DEBUG check for a whacky user pc (as impossible due to the recent trap.c change)


# 1.108 03-Aug-2003 mickey

clear branch and nullify bits in psw on sending a signal


# 1.107 30-Jul-2003 mickey

deduce the leds address from the model number and thus make some more use of that lichtenblinkenschmutz on some more machinens


# 1.106 22-May-2003 mickey

imprecision in delay_init()


# 1.105 18-May-2003 mickey

save the fpu state for the signal handler. this is essential
as the fpu regs can be used by the gcc even for non-fpu
means and data copying.
rearrange the sigcontext a bit to include only the general
registers that are needed restoring upon return and thus
less waste of space and make up some space for the fpu regs.

ALL software that used the signal context on the stack
needs at least rebuilding now. a new snap has bin built as well.


Revision tags: UBC_SYNC_A
# 1.104 11-May-2003 deraadt

string cleaning; krw ok


# 1.103 07-Apr-2003 mickey

s/HP9000/HP 9000/; from weissmanndude


Revision tags: OPENBSD_3_3_BASE
# 1.102 18-Feb-2003 deraadt

knf; mickey ok


# 1.101 12-Feb-2003 jason

How uncommon... hppa only has one common: msgbufmapped (decl'd in /sys/kern)


# 1.100 12-Feb-2003 mickey

only align the first stack frame onto the minimal required alignment


# 1.99 10-Feb-2003 mickey

fix pcs and pcxt recognition. from weissmanndude


# 1.98 22-Jan-2003 mickey

consistantly use uvm_prot_* vs vm_prot_* evewrhere


# 1.97 14-Jan-2003 mickey

fix cutnpaste in the cpu table for the itlbna field; from herr weissmanndude


# 1.96 14-Jan-2003 mickey

need pdc_hwtlb always; pt out by herr weissmanndude


# 1.95 13-Jan-2003 mickey

fix the logic in hvt probing


# 1.94 09-Jan-2003 miod

Remove fetch(9) and store(9) functions from the kernel, and replace the few
remaining instances of them with appropriate copy(9) usage.

ok art@, tested on all arches unless my memory is non-ECC


# 1.93 19-Dec-2002 mickey

setregs: put the whole frame setup into one place


# 1.92 19-Dec-2002 mickey

level 0x16 is really an l2


# 1.91 17-Dec-2002 millert

Make SysV-style shared memory and semaphore limits sysctl'able.
Instead of allocating a static amount of memory for the data
structures via valloc() in allocsys(), allocate things dynamically
using pool(9) when possible and malloc(9) when not. The various
members of struct seminfo and struct shminfo are in kern.seminfo
and kern.shminfo respectively (not all members of kern.seminfo are
changable).

The data structures used still leave something to be desired but
things are not made worse in that respect by this commit.


# 1.90 27-Nov-2002 mickey

no wrapper arounf hardclock(), use CPU_CLOCKUPDATE, real microtime; miod ok


# 1.89 08-Nov-2002 mickey

Don't uvm_useracc the user sigcontext in sys_sigreturn and then access
the user addresses directly from the kernel. copyin is faster and can
correctly deal properly with mappings that uvm_useracc thinks are
correct but will fault anyway (to figure out how to generate such
mappings is left as en excercise for the reader).


# 1.88 01-Nov-2002 mickey

add a missing delay after printf on halt[-p], proper arg for a cold hook


Revision tags: UBC_SYNC_B
# 1.87 22-Oct-2002 mickey

do not force single-user; pt out by fries@


# 1.86 15-Oct-2002 mickey

missing initmsgbuf(), noticed by miod@


# 1.85 13-Oct-2002 mickey

track the end of physmem for use in dmmem_alloc


# 1.84 07-Oct-2002 mickey

s/PSW_/PSL_/ to match other archs


# 1.83 07-Oct-2002 mickey

proper terminate the user stack on signal


# 1.82 07-Oct-2002 mickey

on implementations w/ fpu included unimplemented instructions
are signaled through the exception trap w/ invalid opcode marked
instruction in the exception registers, not through the emulation
trap (as long as the fpu is enabled, of course).
parse emulation from the exception trap as well as the emulation
trap and fix the dispatcher into usable condition.
parse invalid op exception on trap and signal the user appropriately.
reset the exception on exec and for child on fork.
the later is appropriate since exceptions are delayed until next
fpu instruction, which was in the parent indeed, let him get it.
save parent's fpu context on fork before cipying it, if the
parent owned the fpu.


Revision tags: OPENBSD_3_2_BASE
# 1.81 23-Sep-2002 mickey

parisc level 0x10 is just an overclocked 0xe


# 1.80 17-Sep-2002 mickey

handle fpu exceptions properly, might use a regress, i guess


# 1.79 11-Sep-2002 mickey

provide a convinient reset label


# 1.78 11-Sep-2002 mickey

stack grows the other way, but the frame is the other way to that. hehe


# 1.77 09-Sep-2002 mickey

set up the frame flags and a user frame better on exec


# 1.76 03-Aug-2002 mickey

rework boot() w/o a goto


# 1.75 25-Jul-2002 mickey

missing arg in the call to the pdc_call since some old times


# 1.74 25-Jul-2002 mickey

kcopy is a space-to-space copy from kernel space, to guess where, -- to the same kernel space, just error on fault


# 1.73 20-Jul-2002 art

Instead of copying out the signal trampoline on top of the stack, create
an uvm aobj, copy out the signal trampoline into it and share that page
among all processes for the same emulation.

This also requires us to actually be able to tell signal code where the
trampoline is located, so introduce a new field in struct proc - p_sigcode
that is a pointer to sigcode. This allows us to remove all the ugly
calculations of the signal trampoline address done in every sendsig
function in the tree (that's why so many files are changed).

Tested by various people. ok deraadt@


# 1.72 14-May-2002 mickey

disable sid hashing while still in real mode, alos print the parisc arch once and not per each cpu since they are not intermixable architecture-wise


# 1.71 13-May-2002 mickey

ldi-ldo whatever was in the table, be that much clever


# 1.70 08-May-2002 mickey

print parisc level w/ the the parisc version, not for each cpu


# 1.69 08-May-2002 mickey

kill debugging printfski


# 1.68 22-Apr-2002 mickey

no longer batc the data, only the code.
this removes a constraint and an ld.script dependancy
for the .data and the dynamically allocated kernel
structures existed w/ batcing. also makes pmap_steal_memory
obsolete and replaced w/ the pmap_virtual_space.
implement batching for pmap_remove to avoid
zeroing out the pte entries if pde will be removed anyway.


# 1.67 21-Apr-2002 mickey

better buf's mapping and less magic constants in checking for io space cachability


Revision tags: OPENBSD_3_1_BASE
# 1.66 26-Mar-2002 mickey

if cannot guess cpu model default to the lowest supported one


# 1.65 25-Mar-2002 deraadt

spelling


# 1.64 23-Mar-2002 espie

Add variables for config(8) -e time tweak of systemV shared memory
parameters.

Ok millert@, miod@, maja@


# 1.63 19-Mar-2002 mickey

mtcpu seq requires a pre-sync, implement hpt init for pcxl


# 1.62 15-Mar-2002 mickey

rewrite a pmap to use multilevel page tables.
lower 12 bits contain the perms, no unused bits left,
but a couple for off-tlb use (as the ref implemented now).
do not use the hvt, which might get some use later
if proven to speed thigs up, tlb handlers would po
another dozen of insns though, but if that's worth its...
move on the data seg and map kernel text rdonly (idea form fredette),
since all of the page0 mods done before that we are all fine
except for some viper fluff, but later w/ that.
this also picks up a bit more of ddb magic for bpt and ss.
tlb handlers can use a little bit more of attention,
but things, visually, seem to be much faster already, --
sorry, no benchmarks for now.

* effort sponsored in part by the `henry st. old ale house'
* and mr.pete and mr.lee in particular in thier generous entrirety.
* the proj took a little more that 72man*h as it was expected,
* but within murhy's law estimations.


# 1.61 14-Mar-2002 millert

First round of __P removal in sys


# 1.60 20-Feb-2002 mickey

setup power failure handler (for sw-controlled power button), move toc handler


# 1.59 17-Feb-2002 maja

Patch from Daniel Lucq <daniel@lucq.org>

The patch allows you to change the value of NMBCLUSTERS, BUFCACHEPERCENT
and NKMEMPAGES using the config command, instead of recompiling the kernel.

This is the kernel part of the patch. I have compiled it on i386, sparc64,
alpha and macppc. -moj ok art@ maja@


# 1.58 12-Feb-2002 mickey

support 712's programmable power switch, no interrupt yet


# 1.57 12-Feb-2002 mickey

small repairs to hpmc and toc handlers


# 1.56 11-Feb-2002 mickey

disable fpu on csw, print fpu version on cpu line, if present


# 1.55 07-Feb-2002 mickey

fix sigdebug cases; init sigcontext before it's used (;


# 1.54 06-Feb-2002 mickey

implement signal delivery; based on fredette@'s work


# 1.53 03-Feb-2002 mickey

restore hpt size computation, does not break things as i thought


# 1.52 02-Feb-2002 mickey

fix 'physmem' usage


# 1.51 02-Feb-2002 mickey

implement the rest of /dev/mem devices; from netbsd


# 1.50 23-Jan-2002 art

move mb_map allocation to mbinit()


# 1.49 23-Jan-2002 art

move definition of mb_map from zillions of machdep.c to uipc_mbuf.c


# 1.48 16-Jan-2002 miod

Don't include <sys/map.h> when you don't need what's in it.


Revision tags: UBC_BASE
# 1.47 02-Dec-2001 mickey

branches: 1.47.2;
increase fixed extent storage


# 1.46 28-Nov-2001 art

zap some typedefs.
vm_map_t -> struct vm_map *
vm_map_entry_t -> struct vm_map_entry *
simple_lock_data_t -> struct simplelock

(uvm not done yet, coming in the next commit)


# 1.45 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.44 24-Nov-2001 miod

Harmonize boot() logic across arches:
- ensure RB_DUMP | RB_HALT will cause a dump
- or RB_HALT if (cold)
While there, honor RB_TIMEBAD on sparc64.


# 1.43 09-Nov-2001 art

nswbuf hasn't been used for ages. gc.


# 1.42 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.41 06-Nov-2001 miod

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


Revision tags: OPENBSD_3_0_BASE
# 1.40 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.39 12-Sep-2001 art

mbutl no more


# 1.38 23-Aug-2001 art

We can now move timeout_init into main().


# 1.37 23-Aug-2001 art

Remove even more old timeout tentacles.


# 1.36 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.35 05-Jul-2001 art

Get rid of REAL_CLISTS. It was never implemented and the tentacles are
everywhhere.


# 1.34 17-May-2001 provos

convert mbuf and cluster allocation to pool, mostly from NetBSD
okay art@ miod@


# 1.33 05-May-2001 art

Rename configure() to cpu_configure().
Move it from cpu_startup() to main().


# 1.32 05-May-2001 art

Get rid of CLSIZE and all related stuff.
CLSIZE -> 1
CLBYTES -> PAGE_SIZE
OLOFSET -> PAGE_MASK
etc.
At the same time some archs needed some cleaning in vmparam.h so that
goes in at the same time.


Revision tags: OPENBSD_2_9_BASE
# 1.31 29-Mar-2001 mickey

cpudev_data.h here needed not


# 1.30 22-Mar-2001 mickey

shuffle the tlb handlers a little,
make a new one for na data fault,
since those w/ hpt need it.


Revision tags: OPENBSD_2_8_BASE
# 1.29 15-Aug-2000 mickey

two btlb routines (i & d) for pcxs


# 1.28 15-Aug-2000 mickey

expand per-cpu control routines switch


# 1.27 08-Aug-2000 mickey

print btlb params w/ BTLBDEBUG; from Havard.Eidnes@runit.sintef.no


# 1.26 02-Jul-2000 mickey

no bays for stinger


Revision tags: OPENBSD_2_7_BASE
# 1.25 23-Mar-2000 mickey

new cpu type switch code.
initializes tlb miss handlers correspondent to probed cpu features.
also btlb load routine.
versions written are for pcxl and others.
cpu-dep btlb loaders are missing, only generic for now.


# 1.24 23-Mar-2000 art

New API for timeouts. Replaces the old timeout()/untimeout() API and
makes it the callers responsibility to allocate resources for the
timeouts.

This is a KISS implementation and does _not_ solve the problems of slow
handling of a large number of pending timeouts (this will be solved in
future work) (although hardclock is now guarateed to take constant time
for handling of timeouts).

Old timeout() and untimeout() are implemented as wrappers around the new
API and kept for compatibility. They will be removed as soon as all
subsystems are converted to use the new API.


# 1.23 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


# 1.22 22-Feb-2000 mickey

blah, blah, blah, msgbuf


Revision tags: SMP_BASE
# 1.21 09-Feb-2000 mickey

branches: 1.21.2;
heartbeat -- yeah we have a patch for that


# 1.20 25-Jan-2000 mickey

better copy and zero inlines in locore;
proper setregs() in machedep;
start of hpmc handler;
some cleanup here and there;


# 1.19 17-Jan-2000 mickey

remove unneeded stuff from setregs; force single-user for now, enable signal debug


# 1.18 11-Jan-2000 mickey

s/fpu_curproc/fpu_curpcb/ which also points into physical.
move it's definition into locore (where it's used the most).
adjust fpu context switch and save on swapout accordingly.
fix context save (in switch).
add accounting for fpu context switches (since it differes
from proc switching, we might get provided w/ some usefull
numbers as to how effective this lazy switch technique is).
enable handling fpu/sfu exceptions.


# 1.17 31-Dec-1999 mickey

don't bother about pidr3 and pidr4


# 1.16 17-Dec-1999 mickey

fix the panic message for sti memory mapping


Revision tags: kame_19991208
# 1.15 25-Nov-1999 mickey

bus stuff is in mainbus now, the rest is rewritten many ways


Revision tags: OPENBSD_2_6_BASE
# 1.14 20-Sep-1999 mickey

fix uvm_pagealloc() call


# 1.13 03-Sep-1999 art

Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.12 14-Aug-1999 mickey

proper debugging ifdefs


# 1.11 21-Jul-1999 mickey

rewrite the tlb miss handler and tlb dirty handler.
optimize for HVT usage (when compiled for proper cpu type).
drop hpt_* global variables, use info from control registers instead.
there are still ways to improve the tlb handlers tho.
machdep also prints cache and tlb coherence states (not related to the above).
You eat greenish muffin. --More-- You write real code.


# 1.10 12-Jul-1999 mickey

allocate 5% bufcache if <=16M memory installed


# 1.9 12-Jun-1999 mickey

hppa_init() now takes an argument from locore,
meaning the start of available memory.
cleanup machdep somewhat.
fix vm_map.pmap vs vm_pmap isue; 10x art@


# 1.8 23-May-1999 mickey

new swap stuff


# 1.7 21-May-1999 mickey

group all theMD f;ags together, add interrupt recursion one


# 1.6 21-May-1999 mickey

define fpu_curproc


# 1.5 20-Apr-1999 mickey

do lazy blok mapping of io space in bus_*
add copy{in,out}*, kcopy, etc
boot routines
cpu-id-hpux-compat stuff
rest of scheduler and such
uvm


Revision tags: OPENBSD_2_5_BASE
# 1.4 17-Feb-1999 mickey

print pa-risc here as well, since, finally, cpu will have to print processor type


# 1.3 04-Jan-1999 mickey

better cache handling in bus_space_barrier(), seem to work now


# 1.2 03-Jan-1999 mickey

implement bus_space_{un,}map w/ extents


# 1.1 30-Dec-1998 mickey

machdep; more work needed


# 1.266 10-Aug-2022 jsg

match other archs use %s for version printf


Revision tags: OPENBSD_7_1_BASE
# 1.265 06-Oct-2021 claudio

Change sendsig() interface so that the MD code does not need to access
data from struct process anymore. This changes how siginfo and onstack
are accessed and make sendsig() more MP friendly.
With and OK semarie@ OK kettenis@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.264 11-Mar-2021 jsg

spelling


# 1.263 09-Jan-2021 kettenis

"encoding of diag instructions is hard, let's go shopping"

Clean up things a bit, adding documentation about the source of the
information about these instructions.

From miod@


# 1.262 08-Nov-2020 mpi

In case of failure, call sigexit() from trapsignal instead of sensig().

Simplify MD code and reduce the amount of recursion into the signal code
which helps when dealing with locks.

ok cheloha@, deraadt@


# 1.261 21-Oct-2020 deraadt

hppa also has a similar to arm64: copyout(9), copyinstr(9) and
copyoutstr(9) should bail out properly if they are called with a
length of 0.
ok kettenis@


Revision tags: OPENBSD_6_8_BASE
# 1.260 14-Jun-2020 naddy

Implement cpu_rnd_messybits() as a read of the cycle counter register.
ok dlg@ deraadt@


# 1.259 31-May-2020 dlg

introduce "cpu_rnd_messybits" for use instead of nanotime in dev/rnd.c.

rnd.c uses nanotime to get access to some bits that change quickly
between events that it can mix into the entropy pool. it doesn't
use nanotime to get a monotonically increasing set or ordered and
accurate timestamps, it just wants something with bits that change.

there's been discussions for years about letting rnd use a clock
that's super fast to read, but not necessarily accurate, but it
wasn't until recently that i figured out it wasn't interested in
time at all, so things like keeping a fast clock coherent between
cpu cores or correct according to ntp is unecessary. this means we
can just let rnd read the cycle counters on cpus and things will
be fine. cpus with cycle counters that vary in their speed and
arent kept consistent between cores may even be desirable in this
context.

so this is the first step in converting rnd.c to reading cycle
counter. it copies the nanotime backend to each arch, and they can
replace it with something MD as a second step later on.

djm@ suggested rnd_messybytes, but we landed on cpu_rnd_messybits.
thanks to visa for his eyes.
ok deraadt@ visa@
deraadt@ says he will help handle any MD fallout that occurs.


# 1.258 16-May-2020 kettenis

Make inittodr() and resettodr() MI.

ok deraadt@, mpi@, visa@
ok cheloha@ as well (would have preferred in new file for this code)


# 1.257 11-May-2020 kettenis

Initialize the timeval passed to todr_gettime() with the base time from
the file system such that implementations can use it to guess the right
century.

ok mpi@


Revision tags: OPENBSD_6_7_BASE
# 1.256 01-May-2020 kettenis

Use the same inittodr()/resettodr() implementation as on
amd64/arm64/armv7/i386/sparc64 and move it to the end of machdep.c. Rework the
actual implementation for the MC14818 compatible RTC into something that can
be used as a todr_handle just like on amd64.

ok mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.255 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


Revision tags: OPENBSD_6_4_BASE
# 1.254 20-Jul-2018 guenther

Missed a 'ksi' -> '*ksip' change in previous commit


# 1.253 10-Jul-2018 guenther

Move from sendsig() to its callers the initsiginfo() calls and
instead of passing sendsig() the code+type+val, pass a siginfo_t*
to copy from. Eliminate the indirection through struct emul for
sendsig(); we no longer have a SunOS4-compat version of sendsig()

ok deraadt@


# 1.252 22-May-2018 guenther

Delete antique sigdebug definitions

ok kettenis@


# 1.251 12-Apr-2018 deraadt

Implement MAP_STACK option for mmap(). Synchronous faults (pagefault and
syscall) confirm the stack register points at MAP_STACK memory, otherwise
SIGSEGV is delivered. sigaltstack() and pthread_attr_setstack() are modified
to create a MAP_STACK sub-region which satisfies alignment requirements.
Observe that MAP_STACK can only be set/cleared by mmap(), which zeroes the
contents of the region -- there is no mprotect() equivalent operation, so
there is no MAP_STACK-adding gadget.
This opportunistic software-emulation of a stack protection bit makes
stack-pivot operations during ROPchain fragile (kind of like removing a
tool from the toolbox).
original discussion with tedu, uvm work by stefan, testing by mortimer
ok kettenis


Revision tags: OPENBSD_6_3_BASE
# 1.250 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.249 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


Revision tags: OPENBSD_6_2_BASE
# 1.248 18-May-2017 kettenis

Implement copyin32(9).

"your chicken scratches look fine to me" deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.247 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

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


# 1.246 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.245 21-May-2016 deraadt

hand-massage sendsig() and sys_sigreturn() to be much more similar.
ok guenther kettenis


# 1.244 10-May-2016 deraadt

SROP mitigation. sendsig() stores a (per-process ^ &sigcontext) cookie
inside the sigcontext. sigreturn(2) checks syscall entry was from the
exact PC addr in the (per-process ASLR) sigtramp, verifies the cookie,
and clears it to prevent sigcontext reuse.
not yet tested on landisk, sparc, *88k, socppc.
ok kettenis


# 1.243 20-Apr-2016 dlg

pool_setipl for floating point context things

ok kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.242 21-Oct-2015 mpi

Do not call uvm_swap_finicrypt_all() a second time in dumpsys().

ok tedu@, deraadt@, miod@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.241 20-Jan-2015 kettenis

Move ps_strings "after" the random stackgap. This makes its location a
per-process value, and therefpore turns the VM_PSSTRINGS sysctl into a
per-process one as well. This gets rid of a pointer to the bottom of the
stack at a fixed location. Also clears the road for unmapping the stackgap.

ok deraadt@


# 1.240 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.239 25-Oct-2014 kettenis

Remove vmmap; it isn't used.

ok jsing@


# 1.238 23-Oct-2014 miod

Correctly set up the HPMC trap entry: according to the PA-RISC Firmware
Architecture Reference Specification, the sum of the 8 trap entry words
*and* of the payload which address and length are to be set at well-known
positions in the aforementioned trap entry, needs to be zero; the existing
code was only enforcing that the sum of the trap entry words is zero.

This matches what Linux and NetBSD do.

ok kettenis@


# 1.237 23-Oct-2014 miod

Revert limiting physmem to 2GB; the culprit was likely in uvm and uvm has
changed a lot in the last 5 years; verified to work on a 3GB system, in
snapshots for a few weeks already.


# 1.236 22-Sep-2014 dlg

implement atomic_{cas,swap}_{uint,ulong,ptr} and
atomic_{add,sub}_{int,long}_nv. sys/atomic.h turns these into the
rest of the atomic api.

on uniprocessor hppa systems "atomic" operations are implemented
as a non-interruptable sequence by disabling all interrupts on the
cpu, doing the operation, and then restoring the interrupt mask.

this isnt enough on MP systems, so we added a global atomic memory
mutex that is taken inside the interrupt disabling above to coordinate
operations between cpus.

this is a lot of overhead though cos mutexes dance around with ipls,
which is unecessary in our case because of the interrupt disabling
that is already done. also, hppa spinlocks are implemented with
ldcw which requires the word it operates on to be 16 byte aligned.
mutexes arent guaranteed to have this alignment so they compensate
by having lots of words inside themselves so they can hit the
appropriate one to use for the ldcw op.

with this in mind, this change pulls __cpu_simple_locks, which are
simply ldcw spinlocks with a 16 byte aligned word, out of
src/sys/arch/hppa/include/lock.h into src/sys/arch/hppa/include/atomic.h
so atomic.h can use them. lock.h includes atomic.h, so it still
gets and provides the same functionality as before.

finally, this also pulls the rwlock cas implementation apart. cas
ops now share the same serialising lock on MP systems as the other
memory operations, and rw_cas is defined as a wrapper around
atomic_cas_uint.

ok kettenis@


# 1.235 19-Sep-2014 kettenis

Use config_suspend_all(9).


# 1.234 18-Aug-2014 dlg

dont rely on mbuf.h to provide pool.h.

ok miod@, who has offerred to help with any MD fallout
ok guenther@


Revision tags: OPENBSD_5_6_BASE
# 1.233 22-Jul-2014 uebayasi

boot(9): Reduce diffs between hppa & hppa64 (& others)


# 1.232 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.231 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.230 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.229 13-Jul-2014 miod

These still need <sys/reboot.h> for the RB_ constants.


# 1.228 12-Jul-2014 uebayasi

reboot(9), panic(9): Call panic(9) for unrecoverable MD H/W errors (NMIs)

Some architectures have ability to detect hardware sanity and notify system
(NMI, firmware callback, etc.). Handle these hardware severe errors, same
as software errors, with panic(9).

According to miod@, SGI IP27 NMI is triggered by pushing some "hidden" button,
which "usual" users/admins don't know. Pushing such a button is "RB_USERREQ"
(human-triggered) in that the button is pushed by a human, but not "RB_USERREQ"
in that no user intervention in system (== no command input) is done. miod@
agreed that changing these from RB_USERREQ to !RB_USERREQ (== panic(9)) is
not a big problem.

OK miod@ kettenis@


# 1.227 12-Jul-2014 uebayasi

boot(9), reboot(9): Migrate MD callers of boot(9) to reboot(9)

I have found that some ports call boot(9) from machine-dependent code to
reboot system. These should be changed to either:

- Sending signal to init(8) to trigger it to shutdown system cleanly, like
acpi(4) does, in cases where found problems don't prevent system from working
immediately, or

- Just doing panic(9) if the situation is severely broken.

For now, just rewrite boot() to reboot(). Actual fixes follow.

Discussed with & OK from kettenis@


# 1.226 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.225 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.224 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.223 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.222 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.221 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.220 08-May-2014 miod

Format string fixes and removal of -Wno-format for hppa kernels.


# 1.219 08-Apr-2014 mpi

Less <uvm/uvm.h>


# 1.218 04-Apr-2014 miod

If the PDC_COPROC call fails, and we are running on a PA 1.1 system, assume
the usual 1.1 coprocessor mask, instead of using zero and having every
userland process dying with signal 4.

The circumstances under which this call fails are unclear and could be
tied to specific PROM version (I have tried overzealous stack alignment and
other tricks, to no avail). Interestingly enough, the 715/75 system which
hits this problem, only triggers it when booting from disk, and never when
booting from network.

This diff is an ugly bandaid until the problem is better understood. Or maybe
it is not worth investigating, seeing that Linux hardcodes the coprocessor
mask and never issues PDC_COPROC calls; I wonder what HP/UX does.

In my tree for over 18 months; "Looks like a nice hack" deraadt@
715/75 system provided by Sebastiaan Indesteege, thanks!


# 1.217 29-Mar-2014 guenther

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

ok dlg@ mpi@ deraadt@


# 1.216 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


# 1.215 22-Mar-2014 guenther

Move p_sigacts from struct proc to struct process.

testing help mpi@


# 1.214 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


Revision tags: OPENBSD_5_5_BASE
# 1.213 23-Nov-2013 uebayasi

Run doshutdownhooks() and config_suspend() even when boot() is called while
cold != 0. Indent and make hppa/hppa64 boot() closer to others.

OK kettenis@


# 1.212 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


Revision tags: OPENBSD_5_4_BASE
# 1.211 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


Revision tags: OPENBSD_5_3_BASE
# 1.210 02-Dec-2012 guenther

Determine whether we're currently on the alternative signal stack
dynamically, by comparing the stack pointer against the altstack
base and size, so that you get the correct answer if you longjmp
out of the signal handler, as tested by regress/sys/kern/stackjmp/.
Also, fix alt stack handling on vax, where it was completely broken.

Testing and corrections by miod@, krw@, tobiasu@, pirofti@


# 1.209 26-Oct-2012 kettenis

Properly clear trap frame in setregs() to avoid leaking registers across exec.

ok jsing@


# 1.208 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.207 07-Oct-2012 kettenis

Align the stack on a 64-byte boundary as required by "The 32-bit PA-RISC
Run-time Architecture Document". GCC relies on this to properly align
stack variables.

ok guenther@, beck@


Revision tags: OPENBSD_5_2_BASE
# 1.206 21-Jun-2012 guenther

__tfork() needs to set the stack address of the new thread in the kernel,
so that it can't get a signal while still running on the parent thread's
stack. Also, pass in sizeof(struct __tfork) to provide forward compat
when more members are added. This is an ABI change, so switch syscall
numbers and bump lib majors this time.

ok deraadt@ matthew@


Revision tags: OPENBSD_5_1_BASE
# 1.205 20-Sep-2011 miod

Clear RB_POWERDOWN early in boot() on systems which can not powerdown and
which firmware does not send spin up commands to the disks, in case the
operator changes his mind and reboots instead of manually powering down
after the system has halted.
ok kettenis@


Revision tags: OPENBSD_5_0_BASE
# 1.204 05-Jul-2011 guenther

Recommit the reverted sigacts change now that the NFS use-after-free
problem has been tracked down. This fixes the sharing of the signal
handling state: shared bits go in sigacts, per-rthread bits goes in
struct proc.

ok deraadt@


# 1.203 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.202 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.201 18-Apr-2011 guenther

Revert the sigacts diff: NFS can apparently retain pointers to processes
until they're zombies and then send them signals (for intr mounts). Until
that is untangled, the sigacts change is unsafe. sthen@ was the victim
for this one


# 1.200 15-Apr-2011 guenther

Correct the sharing of the signal handling state: stuff that should
be shared (p_sigignore, p_sigcatch, P_NOCLDSTOP, P_NOCLDWAIT) moves
to struct sigacts, wihle stuff that should be per rthread (ps_oldmask,
SAS_OLDMASK, ps_sigstk) moves to struct proc. Treat the coredumping
state bits (ps_sig, ps_code, ps_type, ps_sigval) as per-rthread
until our locking around coredumping is better.

Oh, and remove the old SunOS-compat ps_usertramp member.

"I like the sound of this" tedu@


Revision tags: OPENBSD_4_9_BASE
# 1.199 14-Jan-2011 jsing

Halt secondary CPUs when shutting down or rebooting. This should prevent
occasional hangs during reboot.

ok kettenis@


# 1.198 04-Jan-2011 jasper

- de-register. no binary change.

ok jsing@


# 1.197 01-Jan-2011 jasper

Move setting cpu_hzticks to the clock initialization function, like
other ports (e.g. hppa64) do.

ok jsing@ kettenis@


# 1.196 01-Jan-2011 jasper

- ansify

ok jsing@ kettenis@


# 1.195 30-Dec-2010 jsing

Turn signotify() into a function that also calls cpu_unidle().

ok kettenis@


# 1.194 20-Nov-2010 miod

This is a first step towards getting rid of avail_start and avail_end in the
kernel, currently limited to low-hanging fruit: these variables were used
by bus_dma to specify the range in which to allocate memory, back when
uvm_pglistalloc() was stupid and would not walk the vm_physseg[].

Nowadays, except on some platforms for early initialization, these variables
are not used, or do not need to be global variables. Therefore:
- remove `extern' declarations of avail_start and avail_end (or close cousins,
such as arm physical_start and physical_end) from files which no longer need
to use them.
- make them local variables whenever possible.
- remove them when they are assigned to but no longer used.


Revision tags: OPENBSD_4_8_BASE
# 1.193 01-Jul-2010 jsing

Create a struct to store FP state and include a pointer to the CPU that
currently holds the FPU context for this process. This will be soon used
to implement FPU shootdowns on multiprocessor kernels.

ok kettenis@


# 1.192 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.191 29-Jun-2010 jsing

Factor out code used to save and flushe process FPU context.

ok kettenis@


# 1.190 29-Jun-2010 jsing

Store pointer to process FPU state in struct cpu_info.

ok kettenis@


# 1.189 27-Jun-2010 thib

uvm constraints. Add two mandatory MD symbols, uvm_md_constraints
which contains the constraints for DMA/memory allocation for each
architecture, and dma_constraints which contains the range of addresses
that are dma accessable by the system.

This is based on ariane@'s physcontig diff, with lots of bugfixes and
additions the following additions by my self:

Introduce a new function pool_set_constraints() which sets the address
range for which we allocate pages for the pool from, this is now used
for the mbuf/mbuf cluster pools to keep them dma accessible.

The !direct archs no longer stuff pages into the kernel object in
uvm_km_getpage_pla but rather do a pmap_extract() in uvm_km_putpages.

Tested heavily by my self on i386, amd64 and sparc64. Some tests on
alpha and SGI.

"commit it" beck, art, oga, deraadt
"i like the diff" deraadt


# 1.188 27-Jun-2010 jsing

Use a mutex to make atomic operations atomic on multiprocessor kernels.

ok kettenis@


# 1.187 10-Jun-2010 deraadt

Declare safepri at the MD level on each platform, so that the kern_synch.c
does not have to deal with it as a common. Some platforms may be missed
by this commit... if you spot one, fix it the same way.
ok miod


# 1.186 09-Jun-2010 miod

Move declaration of cn_tab from dev/cons.c to dev/cninit.c, or appropriate
md files for ports which do not use dev/cninit.c. This gets rid of a common
at kernel link time.
feedback drahn@ ok deraadt@


# 1.185 24-May-2010 deraadt

Add missing prototypes
ok jsing kettenis


# 1.184 09-May-2010 kettenis

Prevent "taken branch" exceptions from kernel space by clearing the PSL_T
bit before we enter a signal handler.

"if you say so" miod@, "seems to make sense" jsing@


# 1.183 02-May-2010 kettenis

Properly initialize the members of `struct mdproc' that deal with
single-stepping when we fork and reset them upon exec.

ok miod@


# 1.182 27-Apr-2010 kettenis

Avoid null-pointer dereference by giving proc0 a place to store its
floating-point registers. Pointed out by Nick Hudson.

ok miod@, jsing@


# 1.181 19-Apr-2010 jsing

Make the Processor Status Word (PSW) a per-CPU value.

ok kettenis@


# 1.180 01-Apr-2010 jsing

Allow for multiple CPUs by moving to an array of cpu_info.

ok kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.179 31-Dec-2009 jsing

Make cpl and cpu_inintr per CPU variables. For locore.S, cpl becomes an
offset within cpu_primary_info - this will need to be revisited shortly.

ok kettenis@


# 1.178 11-Aug-2009 miod

Do not bother initializing bufpages in the md code if the computation is
exactly the same the mi could will use if bufinit() is invoked with
bufpages == 0.


# 1.177 11-Aug-2009 miod

With the SysV memory allocation changes, allocsys() doesn't do anything
anymore. Get rid of it completely.


# 1.176 09-Aug-2009 blambert

Rototill system V message queues.

No longer allocate a static amount of memory for messages in MD
boot path; message queues, message metadata, and message data now
all use dynamic memory, which means that runtime sysctls should now
be trivial to implement.

Since I'm going to be around all week to fix any breakage, this should
probably just go in now.


# 1.175 02-Aug-2009 beck

Dynamic buffer cache support - a re-commit of what was backed out
after c2k9

allows buffer cache to be extended and grow/shrink dynamically

tested by many, ok oga@, "why not just commit it" deraadt@


# 1.174 29-Jul-2009 kettenis

Get rid of non-equivalent aliases of the pcb by moving the fpu state out
of the pcb and using the p_addr member of 'struct proc' to calculate the
address of the kernel stack when switching to virtual mode after taking a trap.
Remove the now unecessary cache flushes; they're actually harmful since they
create non-equivalent aliases. This seems to fix the memory corruption we
have been observing from time to time.

This diff does not rename fpu_curpcb, which is now somewhat incorrectly named.
I hope to change things back again as soon as we are able to map the pcb 1:1.


Revision tags: OPENBSD_4_6_BASE
# 1.173 15-Jun-2009 beck

Back out all the buffer cache changes I committed during c2k9. This reverts three
commits:

1) The sysctl allowing bufcachepercent to be changed at boot time.
2) The change moving the buffer cache hash chains to a red-black tree
3) The dynamic buffer cache (Which depended on the earlier too).

ok on the backout from marco and todd


# 1.172 03-Jun-2009 beck

add kern.bufcachepercent sysctl to allow adjusting the buffer cache
size on a running system.
ok art@, oga@


Revision tags: OPENBSD_4_5_BASE
# 1.171 14-Feb-2009 kettenis

Limit the amount of physical memory to 2GB. Using more causes memory
corruption on PA-RISC 2.0 systems (and there are very few PA-RISC 1.1
systems that support more than 2GB).

ok miod@


# 1.170 04-Feb-2009 miod

On systems with split BTLB, do not bother trying to insert DBTLB entries,
as PDC will lie to us pretending it did while it didn't.

ok kettenis@


# 1.169 04-Feb-2009 miod

Unify memory size reports a bit more: always report size in MB, and report
reserved memory on alpha and hppa on its own line (as done on sgi).


Revision tags: OPENBSD_4_4_BASE
# 1.168 14-Jul-2008 miod

Be sure to propagate PSL_O in psw on PCXU* processors to userland processes
and signal handlers.
ok kettenis@


# 1.167 27-Jun-2008 miod

Clear swap encryption keys before dumping a kernel image.


# 1.166 09-Apr-2008 deraadt

Add new stub uvm_shutdown() and call it from the right place in MD boot()


Revision tags: OPENBSD_4_3_BASE
# 1.165 22-Sep-2007 martin

replace even more ctob and btoc with ptoa and atop respectively plus
uvm_extern.h where needed


Revision tags: OPENBSD_4_2_BASE
# 1.164 22-Jul-2007 kettenis

Move hppa to __HAVE_TIMECOUNTERS.


# 1.163 20-Jul-2007 kettenis

Give hppa the blink_led API from sparc64, and the associated machdep.led_blink
sysctl.


# 1.162 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.161 14-Jul-2007 kettenis

Make sigreturn(2) set the proper space ID for the instruction queue. Fixes
a few more pthreads regression tests.

ok miod@


# 1.160 10-Jul-2007 kettenis

Don't trust the privilige level in the sigcontext passed to sigreturn(2).

ok miod@


# 1.159 24-Jun-2007 kettenis

Crank initial storage for extents a bit. We really should allocate extents
using malloc once vm is initialised, but this will do for now.

ok deraadt@


# 1.158 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.157 27-May-2007 miod

Make sure the minaddr hint for uvm_km_suballoc() calls is always initialized.
ok pedro@


# 1.156 26-May-2007 pedro

Dynamic buffer cache. Initial diff from mickey@, okay art@ beck@ toby@
deraadt@ dlg@.


# 1.155 21-May-2007 kettenis

Add support for 8700/pcxw2 cpu.


# 1.154 21-May-2007 kettenis

Ask firmware for reset before trying ourselves; needed for four-digit b/c/j
workstations.

tested by otto@, krw@; ok deraadt@


# 1.153 17-May-2007 art

Limit hppa buffer cache to 30%. It used to be 70% because stack garbage
that was used for minaddr instead of the proper vm_map_min(kernel_map)
(fixed in this diff).

From mickey. art@ ok


# 1.152 14-May-2007 martin

move hppa to __HAVE_CPUINFO

input from miod@, ok kettenis@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.151 28-May-2006 martin

minor nit, use CPU ID instead of FPU ID for BTLB parameters after passing
all kludges


# 1.150 15-Apr-2006 martin

make warning about missing HPT support DEBUG for now

ok mickey@


Revision tags: OPENBSD_3_9_BASE
# 1.149 26-Oct-2005 martin

no more hppa_round_page() and hppa_trunc_page() macros

ok mickey@


Revision tags: OPENBSD_3_8_BASE
# 1.148 06-Aug-2005 miod

We do not need a char machine_arch[] constant.
ok deraadt@


# 1.147 11-Jul-2005 mickey

align some stupid comments


# 1.146 10-May-2005 mickey

set pcsq in case we get signal delivery once interrupted from the gateway page; from chs


# 1.145 18-Apr-2005 mickey

do not do some of the initmsgbuf()s job


# 1.144 07-Apr-2005 mickey

on some machines it's possible to limit the amount of physmem initialised dring post so having msgbuf at the end of memory shall work


# 1.143 07-Apr-2005 mickey

64bit-friendly pdc.h and iomod.h and correspondent changes elsewhere


# 1.142 26-Mar-2005 mickey

md parts for hpux_compa code; some problems w/ signals delivery still exist


Revision tags: OPENBSD_3_7_BASE
# 1.141 24-Feb-2005 mickey

do not even ask for btlb on 8k cpus as pdc pretends there is some but then it does not work; found w/ Moritz Kiese <mbk@mytum.de> on c180; add a debug print and fix pcxu entry


# 1.140 17-Nov-2004 mickey

print real/avail/bufcache sizes as unsigned


# 1.139 26-Oct-2004 mickey

disable sid hashing on pcxu and above


# 1.138 14-Oct-2004 mickey

a bit larger delays during boot() to let msgs appear


# 1.137 19-Sep-2004 mickey

turn totalphysmem into physmem and name old physmem into smth it really is


# 1.136 18-Sep-2004 mickey

oops


# 1.135 15-Sep-2004 mickey

add pcxu tlb handlers and cpu probing
add u2/uturn ioa driver in dumb mode now
enable pcxu/pcxw support


# 1.134 14-Sep-2004 mickey

store fpu version for later use. make sure to proper store/clear fpu state in fork/exec/exit/sendsig


# 1.133 14-Sep-2004 mickey

error out from btlb_insert() if there is none


Revision tags: OPENBSD_3_6_BASE
# 1.132 01-Jul-2004 mickey

have separate insn and data cache all-flushers


# 1.131 30-Jun-2004 mickey

allow forced fpu emulation through a sysctl


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.130 13-May-2004 mickey

8ks do not have hvt


# 1.129 05-May-2004 mickey

much easier tlb handler branch patching


# 1.128 05-May-2004 mickey

do not engage HPT on PCXT' (yet)


# 1.127 08-Apr-2004 mickey

repair pcxs/t confoosion


# 1.126 07-Apr-2004 mickey

update copyright; miod@ is fine w/ files where he holds it too


Revision tags: OPENBSD_3_5_BASE
# 1.125 10-Mar-2004 tom

Ensure that we obey a user's ddb> boot reboot command even if the system
is cold (during startup).

This adds RB_USERREQ to sys/reboot.h, uses it in the ddb commands, and
ensures that */*/machdep.c:boot() won't set RB_HALT when cold if this
flag is set.

ok deraadt@


# 1.124 14-Feb-2004 grange

Simplify hw.{cpuspeed,setperf} api moving all the sysctl stuff
from the underlying callbacks.

Testing hppa mickey@, ppc drahn@
Ok markus@ tedu@


# 1.123 05-Jan-2004 mickey

kill debugging code that is not needed anymore


# 1.122 23-Dec-2003 mickey

provide cpuspeed fluff


# 1.121 20-Dec-2003 miod

Don't let microtime() return a struct timeval with exactly 1000000 microseconds.


# 1.120 18-Dec-2003 mickey

spls do not protect cpu_itmr and thus time might jump back sometimes due to cpu_itmr modified to a higher value than a read itmr; found and testing by miod@


# 1.119 17-Dec-2003 mickey

in the real mem print do not include reserved for prom into used by openbsd


# 1.118 10-Dec-2003 mickey

for unaligned btlb mapping attempts -- just fail


# 1.117 24-Nov-2003 mickey

experimental support for HVT as a 2nd level tlb


# 1.116 15-Oct-2003 mickey

less global name space pollution


# 1.115 05-Oct-2003 mickey

reload the itmr as soon as we get the intr to avoid lagging on slower machines


# 1.114 25-Sep-2003 mickey

some pcxl2 do not report fpus -- assume it's there


Revision tags: OPENBSD_3_4_BASE
# 1.113 04-Sep-2003 mickey

a better cpu identification; testing by miod


# 1.112 31-Aug-2003 miod

pdc_model needs to be visible from cpu.c


# 1.111 20-Aug-2003 mickey

missing nl in debugging prontf


# 1.110 07-Aug-2003 mickey

dead proto


# 1.109 07-Aug-2003 mickey

first allocate space on stack then copyout signal shits. add a DEBUG check for a whacky user pc (as impossible due to the recent trap.c change)


# 1.108 03-Aug-2003 mickey

clear branch and nullify bits in psw on sending a signal


# 1.107 30-Jul-2003 mickey

deduce the leds address from the model number and thus make some more use of that lichtenblinkenschmutz on some more machinens


# 1.106 22-May-2003 mickey

imprecision in delay_init()


# 1.105 18-May-2003 mickey

save the fpu state for the signal handler. this is essential
as the fpu regs can be used by the gcc even for non-fpu
means and data copying.
rearrange the sigcontext a bit to include only the general
registers that are needed restoring upon return and thus
less waste of space and make up some space for the fpu regs.

ALL software that used the signal context on the stack
needs at least rebuilding now. a new snap has bin built as well.


Revision tags: UBC_SYNC_A
# 1.104 11-May-2003 deraadt

string cleaning; krw ok


# 1.103 07-Apr-2003 mickey

s/HP9000/HP 9000/; from weissmanndude


Revision tags: OPENBSD_3_3_BASE
# 1.102 18-Feb-2003 deraadt

knf; mickey ok


# 1.101 12-Feb-2003 jason

How uncommon... hppa only has one common: msgbufmapped (decl'd in /sys/kern)


# 1.100 12-Feb-2003 mickey

only align the first stack frame onto the minimal required alignment


# 1.99 10-Feb-2003 mickey

fix pcs and pcxt recognition. from weissmanndude


# 1.98 22-Jan-2003 mickey

consistantly use uvm_prot_* vs vm_prot_* evewrhere


# 1.97 14-Jan-2003 mickey

fix cutnpaste in the cpu table for the itlbna field; from herr weissmanndude


# 1.96 14-Jan-2003 mickey

need pdc_hwtlb always; pt out by herr weissmanndude


# 1.95 13-Jan-2003 mickey

fix the logic in hvt probing


# 1.94 09-Jan-2003 miod

Remove fetch(9) and store(9) functions from the kernel, and replace the few
remaining instances of them with appropriate copy(9) usage.

ok art@, tested on all arches unless my memory is non-ECC


# 1.93 19-Dec-2002 mickey

setregs: put the whole frame setup into one place


# 1.92 19-Dec-2002 mickey

level 0x16 is really an l2


# 1.91 17-Dec-2002 millert

Make SysV-style shared memory and semaphore limits sysctl'able.
Instead of allocating a static amount of memory for the data
structures via valloc() in allocsys(), allocate things dynamically
using pool(9) when possible and malloc(9) when not. The various
members of struct seminfo and struct shminfo are in kern.seminfo
and kern.shminfo respectively (not all members of kern.seminfo are
changable).

The data structures used still leave something to be desired but
things are not made worse in that respect by this commit.


# 1.90 27-Nov-2002 mickey

no wrapper arounf hardclock(), use CPU_CLOCKUPDATE, real microtime; miod ok


# 1.89 08-Nov-2002 mickey

Don't uvm_useracc the user sigcontext in sys_sigreturn and then access
the user addresses directly from the kernel. copyin is faster and can
correctly deal properly with mappings that uvm_useracc thinks are
correct but will fault anyway (to figure out how to generate such
mappings is left as en excercise for the reader).


# 1.88 01-Nov-2002 mickey

add a missing delay after printf on halt[-p], proper arg for a cold hook


Revision tags: UBC_SYNC_B
# 1.87 22-Oct-2002 mickey

do not force single-user; pt out by fries@


# 1.86 15-Oct-2002 mickey

missing initmsgbuf(), noticed by miod@


# 1.85 13-Oct-2002 mickey

track the end of physmem for use in dmmem_alloc


# 1.84 07-Oct-2002 mickey

s/PSW_/PSL_/ to match other archs


# 1.83 07-Oct-2002 mickey

proper terminate the user stack on signal


# 1.82 07-Oct-2002 mickey

on implementations w/ fpu included unimplemented instructions
are signaled through the exception trap w/ invalid opcode marked
instruction in the exception registers, not through the emulation
trap (as long as the fpu is enabled, of course).
parse emulation from the exception trap as well as the emulation
trap and fix the dispatcher into usable condition.
parse invalid op exception on trap and signal the user appropriately.
reset the exception on exec and for child on fork.
the later is appropriate since exceptions are delayed until next
fpu instruction, which was in the parent indeed, let him get it.
save parent's fpu context on fork before cipying it, if the
parent owned the fpu.


Revision tags: OPENBSD_3_2_BASE
# 1.81 23-Sep-2002 mickey

parisc level 0x10 is just an overclocked 0xe


# 1.80 17-Sep-2002 mickey

handle fpu exceptions properly, might use a regress, i guess


# 1.79 11-Sep-2002 mickey

provide a convinient reset label


# 1.78 11-Sep-2002 mickey

stack grows the other way, but the frame is the other way to that. hehe


# 1.77 09-Sep-2002 mickey

set up the frame flags and a user frame better on exec


# 1.76 03-Aug-2002 mickey

rework boot() w/o a goto


# 1.75 25-Jul-2002 mickey

missing arg in the call to the pdc_call since some old times


# 1.74 25-Jul-2002 mickey

kcopy is a space-to-space copy from kernel space, to guess where, -- to the same kernel space, just error on fault


# 1.73 20-Jul-2002 art

Instead of copying out the signal trampoline on top of the stack, create
an uvm aobj, copy out the signal trampoline into it and share that page
among all processes for the same emulation.

This also requires us to actually be able to tell signal code where the
trampoline is located, so introduce a new field in struct proc - p_sigcode
that is a pointer to sigcode. This allows us to remove all the ugly
calculations of the signal trampoline address done in every sendsig
function in the tree (that's why so many files are changed).

Tested by various people. ok deraadt@


# 1.72 14-May-2002 mickey

disable sid hashing while still in real mode, alos print the parisc arch once and not per each cpu since they are not intermixable architecture-wise


# 1.71 13-May-2002 mickey

ldi-ldo whatever was in the table, be that much clever


# 1.70 08-May-2002 mickey

print parisc level w/ the the parisc version, not for each cpu


# 1.69 08-May-2002 mickey

kill debugging printfski


# 1.68 22-Apr-2002 mickey

no longer batc the data, only the code.
this removes a constraint and an ld.script dependancy
for the .data and the dynamically allocated kernel
structures existed w/ batcing. also makes pmap_steal_memory
obsolete and replaced w/ the pmap_virtual_space.
implement batching for pmap_remove to avoid
zeroing out the pte entries if pde will be removed anyway.


# 1.67 21-Apr-2002 mickey

better buf's mapping and less magic constants in checking for io space cachability


Revision tags: OPENBSD_3_1_BASE
# 1.66 26-Mar-2002 mickey

if cannot guess cpu model default to the lowest supported one


# 1.65 25-Mar-2002 deraadt

spelling


# 1.64 23-Mar-2002 espie

Add variables for config(8) -e time tweak of systemV shared memory
parameters.

Ok millert@, miod@, maja@


# 1.63 19-Mar-2002 mickey

mtcpu seq requires a pre-sync, implement hpt init for pcxl


# 1.62 15-Mar-2002 mickey

rewrite a pmap to use multilevel page tables.
lower 12 bits contain the perms, no unused bits left,
but a couple for off-tlb use (as the ref implemented now).
do not use the hvt, which might get some use later
if proven to speed thigs up, tlb handlers would po
another dozen of insns though, but if that's worth its...
move on the data seg and map kernel text rdonly (idea form fredette),
since all of the page0 mods done before that we are all fine
except for some viper fluff, but later w/ that.
this also picks up a bit more of ddb magic for bpt and ss.
tlb handlers can use a little bit more of attention,
but things, visually, seem to be much faster already, --
sorry, no benchmarks for now.

* effort sponsored in part by the `henry st. old ale house'
* and mr.pete and mr.lee in particular in thier generous entrirety.
* the proj took a little more that 72man*h as it was expected,
* but within murhy's law estimations.


# 1.61 14-Mar-2002 millert

First round of __P removal in sys


# 1.60 20-Feb-2002 mickey

setup power failure handler (for sw-controlled power button), move toc handler


# 1.59 17-Feb-2002 maja

Patch from Daniel Lucq <daniel@lucq.org>

The patch allows you to change the value of NMBCLUSTERS, BUFCACHEPERCENT
and NKMEMPAGES using the config command, instead of recompiling the kernel.

This is the kernel part of the patch. I have compiled it on i386, sparc64,
alpha and macppc. -moj ok art@ maja@


# 1.58 12-Feb-2002 mickey

support 712's programmable power switch, no interrupt yet


# 1.57 12-Feb-2002 mickey

small repairs to hpmc and toc handlers


# 1.56 11-Feb-2002 mickey

disable fpu on csw, print fpu version on cpu line, if present


# 1.55 07-Feb-2002 mickey

fix sigdebug cases; init sigcontext before it's used (;


# 1.54 06-Feb-2002 mickey

implement signal delivery; based on fredette@'s work


# 1.53 03-Feb-2002 mickey

restore hpt size computation, does not break things as i thought


# 1.52 02-Feb-2002 mickey

fix 'physmem' usage


# 1.51 02-Feb-2002 mickey

implement the rest of /dev/mem devices; from netbsd


# 1.50 23-Jan-2002 art

move mb_map allocation to mbinit()


# 1.49 23-Jan-2002 art

move definition of mb_map from zillions of machdep.c to uipc_mbuf.c


# 1.48 16-Jan-2002 miod

Don't include <sys/map.h> when you don't need what's in it.


Revision tags: UBC_BASE
# 1.47 02-Dec-2001 mickey

branches: 1.47.2;
increase fixed extent storage


# 1.46 28-Nov-2001 art

zap some typedefs.
vm_map_t -> struct vm_map *
vm_map_entry_t -> struct vm_map_entry *
simple_lock_data_t -> struct simplelock

(uvm not done yet, coming in the next commit)


# 1.45 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.44 24-Nov-2001 miod

Harmonize boot() logic across arches:
- ensure RB_DUMP | RB_HALT will cause a dump
- or RB_HALT if (cold)
While there, honor RB_TIMEBAD on sparc64.


# 1.43 09-Nov-2001 art

nswbuf hasn't been used for ages. gc.


# 1.42 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.41 06-Nov-2001 miod

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


Revision tags: OPENBSD_3_0_BASE
# 1.40 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.39 12-Sep-2001 art

mbutl no more


# 1.38 23-Aug-2001 art

We can now move timeout_init into main().


# 1.37 23-Aug-2001 art

Remove even more old timeout tentacles.


# 1.36 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.35 05-Jul-2001 art

Get rid of REAL_CLISTS. It was never implemented and the tentacles are
everywhhere.


# 1.34 17-May-2001 provos

convert mbuf and cluster allocation to pool, mostly from NetBSD
okay art@ miod@


# 1.33 05-May-2001 art

Rename configure() to cpu_configure().
Move it from cpu_startup() to main().


# 1.32 05-May-2001 art

Get rid of CLSIZE and all related stuff.
CLSIZE -> 1
CLBYTES -> PAGE_SIZE
OLOFSET -> PAGE_MASK
etc.
At the same time some archs needed some cleaning in vmparam.h so that
goes in at the same time.


Revision tags: OPENBSD_2_9_BASE
# 1.31 29-Mar-2001 mickey

cpudev_data.h here needed not


# 1.30 22-Mar-2001 mickey

shuffle the tlb handlers a little,
make a new one for na data fault,
since those w/ hpt need it.


Revision tags: OPENBSD_2_8_BASE
# 1.29 15-Aug-2000 mickey

two btlb routines (i & d) for pcxs


# 1.28 15-Aug-2000 mickey

expand per-cpu control routines switch


# 1.27 08-Aug-2000 mickey

print btlb params w/ BTLBDEBUG; from Havard.Eidnes@runit.sintef.no


# 1.26 02-Jul-2000 mickey

no bays for stinger


Revision tags: OPENBSD_2_7_BASE
# 1.25 23-Mar-2000 mickey

new cpu type switch code.
initializes tlb miss handlers correspondent to probed cpu features.
also btlb load routine.
versions written are for pcxl and others.
cpu-dep btlb loaders are missing, only generic for now.


# 1.24 23-Mar-2000 art

New API for timeouts. Replaces the old timeout()/untimeout() API and
makes it the callers responsibility to allocate resources for the
timeouts.

This is a KISS implementation and does _not_ solve the problems of slow
handling of a large number of pending timeouts (this will be solved in
future work) (although hardclock is now guarateed to take constant time
for handling of timeouts).

Old timeout() and untimeout() are implemented as wrappers around the new
API and kept for compatibility. They will be removed as soon as all
subsystems are converted to use the new API.


# 1.23 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


# 1.22 22-Feb-2000 mickey

blah, blah, blah, msgbuf


Revision tags: SMP_BASE
# 1.21 09-Feb-2000 mickey

branches: 1.21.2;
heartbeat -- yeah we have a patch for that


# 1.20 25-Jan-2000 mickey

better copy and zero inlines in locore;
proper setregs() in machedep;
start of hpmc handler;
some cleanup here and there;


# 1.19 17-Jan-2000 mickey

remove unneeded stuff from setregs; force single-user for now, enable signal debug


# 1.18 11-Jan-2000 mickey

s/fpu_curproc/fpu_curpcb/ which also points into physical.
move it's definition into locore (where it's used the most).
adjust fpu context switch and save on swapout accordingly.
fix context save (in switch).
add accounting for fpu context switches (since it differes
from proc switching, we might get provided w/ some usefull
numbers as to how effective this lazy switch technique is).
enable handling fpu/sfu exceptions.


# 1.17 31-Dec-1999 mickey

don't bother about pidr3 and pidr4


# 1.16 17-Dec-1999 mickey

fix the panic message for sti memory mapping


Revision tags: kame_19991208
# 1.15 25-Nov-1999 mickey

bus stuff is in mainbus now, the rest is rewritten many ways


Revision tags: OPENBSD_2_6_BASE
# 1.14 20-Sep-1999 mickey

fix uvm_pagealloc() call


# 1.13 03-Sep-1999 art

Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.12 14-Aug-1999 mickey

proper debugging ifdefs


# 1.11 21-Jul-1999 mickey

rewrite the tlb miss handler and tlb dirty handler.
optimize for HVT usage (when compiled for proper cpu type).
drop hpt_* global variables, use info from control registers instead.
there are still ways to improve the tlb handlers tho.
machdep also prints cache and tlb coherence states (not related to the above).
You eat greenish muffin. --More-- You write real code.


# 1.10 12-Jul-1999 mickey

allocate 5% bufcache if <=16M memory installed


# 1.9 12-Jun-1999 mickey

hppa_init() now takes an argument from locore,
meaning the start of available memory.
cleanup machdep somewhat.
fix vm_map.pmap vs vm_pmap isue; 10x art@


# 1.8 23-May-1999 mickey

new swap stuff


# 1.7 21-May-1999 mickey

group all theMD f;ags together, add interrupt recursion one


# 1.6 21-May-1999 mickey

define fpu_curproc


# 1.5 20-Apr-1999 mickey

do lazy blok mapping of io space in bus_*
add copy{in,out}*, kcopy, etc
boot routines
cpu-id-hpux-compat stuff
rest of scheduler and such
uvm


Revision tags: OPENBSD_2_5_BASE
# 1.4 17-Feb-1999 mickey

print pa-risc here as well, since, finally, cpu will have to print processor type


# 1.3 04-Jan-1999 mickey

better cache handling in bus_space_barrier(), seem to work now


# 1.2 03-Jan-1999 mickey

implement bus_space_{un,}map w/ extents


# 1.1 30-Dec-1998 mickey

machdep; more work needed


# 1.265 06-Oct-2021 claudio

Change sendsig() interface so that the MD code does not need to access
data from struct process anymore. This changes how siginfo and onstack
are accessed and make sendsig() more MP friendly.
With and OK semarie@ OK kettenis@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.264 11-Mar-2021 jsg

spelling


# 1.263 09-Jan-2021 kettenis

"encoding of diag instructions is hard, let's go shopping"

Clean up things a bit, adding documentation about the source of the
information about these instructions.

From miod@


# 1.262 08-Nov-2020 mpi

In case of failure, call sigexit() from trapsignal instead of sensig().

Simplify MD code and reduce the amount of recursion into the signal code
which helps when dealing with locks.

ok cheloha@, deraadt@


# 1.261 21-Oct-2020 deraadt

hppa also has a similar to arm64: copyout(9), copyinstr(9) and
copyoutstr(9) should bail out properly if they are called with a
length of 0.
ok kettenis@


Revision tags: OPENBSD_6_8_BASE
# 1.260 14-Jun-2020 naddy

Implement cpu_rnd_messybits() as a read of the cycle counter register.
ok dlg@ deraadt@


# 1.259 31-May-2020 dlg

introduce "cpu_rnd_messybits" for use instead of nanotime in dev/rnd.c.

rnd.c uses nanotime to get access to some bits that change quickly
between events that it can mix into the entropy pool. it doesn't
use nanotime to get a monotonically increasing set or ordered and
accurate timestamps, it just wants something with bits that change.

there's been discussions for years about letting rnd use a clock
that's super fast to read, but not necessarily accurate, but it
wasn't until recently that i figured out it wasn't interested in
time at all, so things like keeping a fast clock coherent between
cpu cores or correct according to ntp is unecessary. this means we
can just let rnd read the cycle counters on cpus and things will
be fine. cpus with cycle counters that vary in their speed and
arent kept consistent between cores may even be desirable in this
context.

so this is the first step in converting rnd.c to reading cycle
counter. it copies the nanotime backend to each arch, and they can
replace it with something MD as a second step later on.

djm@ suggested rnd_messybytes, but we landed on cpu_rnd_messybits.
thanks to visa for his eyes.
ok deraadt@ visa@
deraadt@ says he will help handle any MD fallout that occurs.


# 1.258 16-May-2020 kettenis

Make inittodr() and resettodr() MI.

ok deraadt@, mpi@, visa@
ok cheloha@ as well (would have preferred in new file for this code)


# 1.257 11-May-2020 kettenis

Initialize the timeval passed to todr_gettime() with the base time from
the file system such that implementations can use it to guess the right
century.

ok mpi@


Revision tags: OPENBSD_6_7_BASE
# 1.256 01-May-2020 kettenis

Use the same inittodr()/resettodr() implementation as on
amd64/arm64/armv7/i386/sparc64 and move it to the end of machdep.c. Rework the
actual implementation for the MC14818 compatible RTC into something that can
be used as a todr_handle just like on amd64.

ok mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.255 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


Revision tags: OPENBSD_6_4_BASE
# 1.254 20-Jul-2018 guenther

Missed a 'ksi' -> '*ksip' change in previous commit


# 1.253 10-Jul-2018 guenther

Move from sendsig() to its callers the initsiginfo() calls and
instead of passing sendsig() the code+type+val, pass a siginfo_t*
to copy from. Eliminate the indirection through struct emul for
sendsig(); we no longer have a SunOS4-compat version of sendsig()

ok deraadt@


# 1.252 22-May-2018 guenther

Delete antique sigdebug definitions

ok kettenis@


# 1.251 12-Apr-2018 deraadt

Implement MAP_STACK option for mmap(). Synchronous faults (pagefault and
syscall) confirm the stack register points at MAP_STACK memory, otherwise
SIGSEGV is delivered. sigaltstack() and pthread_attr_setstack() are modified
to create a MAP_STACK sub-region which satisfies alignment requirements.
Observe that MAP_STACK can only be set/cleared by mmap(), which zeroes the
contents of the region -- there is no mprotect() equivalent operation, so
there is no MAP_STACK-adding gadget.
This opportunistic software-emulation of a stack protection bit makes
stack-pivot operations during ROPchain fragile (kind of like removing a
tool from the toolbox).
original discussion with tedu, uvm work by stefan, testing by mortimer
ok kettenis


Revision tags: OPENBSD_6_3_BASE
# 1.250 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.249 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


Revision tags: OPENBSD_6_2_BASE
# 1.248 18-May-2017 kettenis

Implement copyin32(9).

"your chicken scratches look fine to me" deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.247 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

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


# 1.246 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.245 21-May-2016 deraadt

hand-massage sendsig() and sys_sigreturn() to be much more similar.
ok guenther kettenis


# 1.244 10-May-2016 deraadt

SROP mitigation. sendsig() stores a (per-process ^ &sigcontext) cookie
inside the sigcontext. sigreturn(2) checks syscall entry was from the
exact PC addr in the (per-process ASLR) sigtramp, verifies the cookie,
and clears it to prevent sigcontext reuse.
not yet tested on landisk, sparc, *88k, socppc.
ok kettenis


# 1.243 20-Apr-2016 dlg

pool_setipl for floating point context things

ok kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.242 21-Oct-2015 mpi

Do not call uvm_swap_finicrypt_all() a second time in dumpsys().

ok tedu@, deraadt@, miod@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.241 20-Jan-2015 kettenis

Move ps_strings "after" the random stackgap. This makes its location a
per-process value, and therefpore turns the VM_PSSTRINGS sysctl into a
per-process one as well. This gets rid of a pointer to the bottom of the
stack at a fixed location. Also clears the road for unmapping the stackgap.

ok deraadt@


# 1.240 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.239 25-Oct-2014 kettenis

Remove vmmap; it isn't used.

ok jsing@


# 1.238 23-Oct-2014 miod

Correctly set up the HPMC trap entry: according to the PA-RISC Firmware
Architecture Reference Specification, the sum of the 8 trap entry words
*and* of the payload which address and length are to be set at well-known
positions in the aforementioned trap entry, needs to be zero; the existing
code was only enforcing that the sum of the trap entry words is zero.

This matches what Linux and NetBSD do.

ok kettenis@


# 1.237 23-Oct-2014 miod

Revert limiting physmem to 2GB; the culprit was likely in uvm and uvm has
changed a lot in the last 5 years; verified to work on a 3GB system, in
snapshots for a few weeks already.


# 1.236 22-Sep-2014 dlg

implement atomic_{cas,swap}_{uint,ulong,ptr} and
atomic_{add,sub}_{int,long}_nv. sys/atomic.h turns these into the
rest of the atomic api.

on uniprocessor hppa systems "atomic" operations are implemented
as a non-interruptable sequence by disabling all interrupts on the
cpu, doing the operation, and then restoring the interrupt mask.

this isnt enough on MP systems, so we added a global atomic memory
mutex that is taken inside the interrupt disabling above to coordinate
operations between cpus.

this is a lot of overhead though cos mutexes dance around with ipls,
which is unecessary in our case because of the interrupt disabling
that is already done. also, hppa spinlocks are implemented with
ldcw which requires the word it operates on to be 16 byte aligned.
mutexes arent guaranteed to have this alignment so they compensate
by having lots of words inside themselves so they can hit the
appropriate one to use for the ldcw op.

with this in mind, this change pulls __cpu_simple_locks, which are
simply ldcw spinlocks with a 16 byte aligned word, out of
src/sys/arch/hppa/include/lock.h into src/sys/arch/hppa/include/atomic.h
so atomic.h can use them. lock.h includes atomic.h, so it still
gets and provides the same functionality as before.

finally, this also pulls the rwlock cas implementation apart. cas
ops now share the same serialising lock on MP systems as the other
memory operations, and rw_cas is defined as a wrapper around
atomic_cas_uint.

ok kettenis@


# 1.235 19-Sep-2014 kettenis

Use config_suspend_all(9).


# 1.234 18-Aug-2014 dlg

dont rely on mbuf.h to provide pool.h.

ok miod@, who has offerred to help with any MD fallout
ok guenther@


Revision tags: OPENBSD_5_6_BASE
# 1.233 22-Jul-2014 uebayasi

boot(9): Reduce diffs between hppa & hppa64 (& others)


# 1.232 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.231 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.230 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.229 13-Jul-2014 miod

These still need <sys/reboot.h> for the RB_ constants.


# 1.228 12-Jul-2014 uebayasi

reboot(9), panic(9): Call panic(9) for unrecoverable MD H/W errors (NMIs)

Some architectures have ability to detect hardware sanity and notify system
(NMI, firmware callback, etc.). Handle these hardware severe errors, same
as software errors, with panic(9).

According to miod@, SGI IP27 NMI is triggered by pushing some "hidden" button,
which "usual" users/admins don't know. Pushing such a button is "RB_USERREQ"
(human-triggered) in that the button is pushed by a human, but not "RB_USERREQ"
in that no user intervention in system (== no command input) is done. miod@
agreed that changing these from RB_USERREQ to !RB_USERREQ (== panic(9)) is
not a big problem.

OK miod@ kettenis@


# 1.227 12-Jul-2014 uebayasi

boot(9), reboot(9): Migrate MD callers of boot(9) to reboot(9)

I have found that some ports call boot(9) from machine-dependent code to
reboot system. These should be changed to either:

- Sending signal to init(8) to trigger it to shutdown system cleanly, like
acpi(4) does, in cases where found problems don't prevent system from working
immediately, or

- Just doing panic(9) if the situation is severely broken.

For now, just rewrite boot() to reboot(). Actual fixes follow.

Discussed with & OK from kettenis@


# 1.226 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.225 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.224 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.223 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.222 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.221 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.220 08-May-2014 miod

Format string fixes and removal of -Wno-format for hppa kernels.


# 1.219 08-Apr-2014 mpi

Less <uvm/uvm.h>


# 1.218 04-Apr-2014 miod

If the PDC_COPROC call fails, and we are running on a PA 1.1 system, assume
the usual 1.1 coprocessor mask, instead of using zero and having every
userland process dying with signal 4.

The circumstances under which this call fails are unclear and could be
tied to specific PROM version (I have tried overzealous stack alignment and
other tricks, to no avail). Interestingly enough, the 715/75 system which
hits this problem, only triggers it when booting from disk, and never when
booting from network.

This diff is an ugly bandaid until the problem is better understood. Or maybe
it is not worth investigating, seeing that Linux hardcodes the coprocessor
mask and never issues PDC_COPROC calls; I wonder what HP/UX does.

In my tree for over 18 months; "Looks like a nice hack" deraadt@
715/75 system provided by Sebastiaan Indesteege, thanks!


# 1.217 29-Mar-2014 guenther

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

ok dlg@ mpi@ deraadt@


# 1.216 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


# 1.215 22-Mar-2014 guenther

Move p_sigacts from struct proc to struct process.

testing help mpi@


# 1.214 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


Revision tags: OPENBSD_5_5_BASE
# 1.213 23-Nov-2013 uebayasi

Run doshutdownhooks() and config_suspend() even when boot() is called while
cold != 0. Indent and make hppa/hppa64 boot() closer to others.

OK kettenis@


# 1.212 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


Revision tags: OPENBSD_5_4_BASE
# 1.211 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


Revision tags: OPENBSD_5_3_BASE
# 1.210 02-Dec-2012 guenther

Determine whether we're currently on the alternative signal stack
dynamically, by comparing the stack pointer against the altstack
base and size, so that you get the correct answer if you longjmp
out of the signal handler, as tested by regress/sys/kern/stackjmp/.
Also, fix alt stack handling on vax, where it was completely broken.

Testing and corrections by miod@, krw@, tobiasu@, pirofti@


# 1.209 26-Oct-2012 kettenis

Properly clear trap frame in setregs() to avoid leaking registers across exec.

ok jsing@


# 1.208 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.207 07-Oct-2012 kettenis

Align the stack on a 64-byte boundary as required by "The 32-bit PA-RISC
Run-time Architecture Document". GCC relies on this to properly align
stack variables.

ok guenther@, beck@


Revision tags: OPENBSD_5_2_BASE
# 1.206 21-Jun-2012 guenther

__tfork() needs to set the stack address of the new thread in the kernel,
so that it can't get a signal while still running on the parent thread's
stack. Also, pass in sizeof(struct __tfork) to provide forward compat
when more members are added. This is an ABI change, so switch syscall
numbers and bump lib majors this time.

ok deraadt@ matthew@


Revision tags: OPENBSD_5_1_BASE
# 1.205 20-Sep-2011 miod

Clear RB_POWERDOWN early in boot() on systems which can not powerdown and
which firmware does not send spin up commands to the disks, in case the
operator changes his mind and reboots instead of manually powering down
after the system has halted.
ok kettenis@


Revision tags: OPENBSD_5_0_BASE
# 1.204 05-Jul-2011 guenther

Recommit the reverted sigacts change now that the NFS use-after-free
problem has been tracked down. This fixes the sharing of the signal
handling state: shared bits go in sigacts, per-rthread bits goes in
struct proc.

ok deraadt@


# 1.203 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.202 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.201 18-Apr-2011 guenther

Revert the sigacts diff: NFS can apparently retain pointers to processes
until they're zombies and then send them signals (for intr mounts). Until
that is untangled, the sigacts change is unsafe. sthen@ was the victim
for this one


# 1.200 15-Apr-2011 guenther

Correct the sharing of the signal handling state: stuff that should
be shared (p_sigignore, p_sigcatch, P_NOCLDSTOP, P_NOCLDWAIT) moves
to struct sigacts, wihle stuff that should be per rthread (ps_oldmask,
SAS_OLDMASK, ps_sigstk) moves to struct proc. Treat the coredumping
state bits (ps_sig, ps_code, ps_type, ps_sigval) as per-rthread
until our locking around coredumping is better.

Oh, and remove the old SunOS-compat ps_usertramp member.

"I like the sound of this" tedu@


Revision tags: OPENBSD_4_9_BASE
# 1.199 14-Jan-2011 jsing

Halt secondary CPUs when shutting down or rebooting. This should prevent
occasional hangs during reboot.

ok kettenis@


# 1.198 04-Jan-2011 jasper

- de-register. no binary change.

ok jsing@


# 1.197 01-Jan-2011 jasper

Move setting cpu_hzticks to the clock initialization function, like
other ports (e.g. hppa64) do.

ok jsing@ kettenis@


# 1.196 01-Jan-2011 jasper

- ansify

ok jsing@ kettenis@


# 1.195 30-Dec-2010 jsing

Turn signotify() into a function that also calls cpu_unidle().

ok kettenis@


# 1.194 20-Nov-2010 miod

This is a first step towards getting rid of avail_start and avail_end in the
kernel, currently limited to low-hanging fruit: these variables were used
by bus_dma to specify the range in which to allocate memory, back when
uvm_pglistalloc() was stupid and would not walk the vm_physseg[].

Nowadays, except on some platforms for early initialization, these variables
are not used, or do not need to be global variables. Therefore:
- remove `extern' declarations of avail_start and avail_end (or close cousins,
such as arm physical_start and physical_end) from files which no longer need
to use them.
- make them local variables whenever possible.
- remove them when they are assigned to but no longer used.


Revision tags: OPENBSD_4_8_BASE
# 1.193 01-Jul-2010 jsing

Create a struct to store FP state and include a pointer to the CPU that
currently holds the FPU context for this process. This will be soon used
to implement FPU shootdowns on multiprocessor kernels.

ok kettenis@


# 1.192 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.191 29-Jun-2010 jsing

Factor out code used to save and flushe process FPU context.

ok kettenis@


# 1.190 29-Jun-2010 jsing

Store pointer to process FPU state in struct cpu_info.

ok kettenis@


# 1.189 27-Jun-2010 thib

uvm constraints. Add two mandatory MD symbols, uvm_md_constraints
which contains the constraints for DMA/memory allocation for each
architecture, and dma_constraints which contains the range of addresses
that are dma accessable by the system.

This is based on ariane@'s physcontig diff, with lots of bugfixes and
additions the following additions by my self:

Introduce a new function pool_set_constraints() which sets the address
range for which we allocate pages for the pool from, this is now used
for the mbuf/mbuf cluster pools to keep them dma accessible.

The !direct archs no longer stuff pages into the kernel object in
uvm_km_getpage_pla but rather do a pmap_extract() in uvm_km_putpages.

Tested heavily by my self on i386, amd64 and sparc64. Some tests on
alpha and SGI.

"commit it" beck, art, oga, deraadt
"i like the diff" deraadt


# 1.188 27-Jun-2010 jsing

Use a mutex to make atomic operations atomic on multiprocessor kernels.

ok kettenis@


# 1.187 10-Jun-2010 deraadt

Declare safepri at the MD level on each platform, so that the kern_synch.c
does not have to deal with it as a common. Some platforms may be missed
by this commit... if you spot one, fix it the same way.
ok miod


# 1.186 09-Jun-2010 miod

Move declaration of cn_tab from dev/cons.c to dev/cninit.c, or appropriate
md files for ports which do not use dev/cninit.c. This gets rid of a common
at kernel link time.
feedback drahn@ ok deraadt@


# 1.185 24-May-2010 deraadt

Add missing prototypes
ok jsing kettenis


# 1.184 09-May-2010 kettenis

Prevent "taken branch" exceptions from kernel space by clearing the PSL_T
bit before we enter a signal handler.

"if you say so" miod@, "seems to make sense" jsing@


# 1.183 02-May-2010 kettenis

Properly initialize the members of `struct mdproc' that deal with
single-stepping when we fork and reset them upon exec.

ok miod@


# 1.182 27-Apr-2010 kettenis

Avoid null-pointer dereference by giving proc0 a place to store its
floating-point registers. Pointed out by Nick Hudson.

ok miod@, jsing@


# 1.181 19-Apr-2010 jsing

Make the Processor Status Word (PSW) a per-CPU value.

ok kettenis@


# 1.180 01-Apr-2010 jsing

Allow for multiple CPUs by moving to an array of cpu_info.

ok kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.179 31-Dec-2009 jsing

Make cpl and cpu_inintr per CPU variables. For locore.S, cpl becomes an
offset within cpu_primary_info - this will need to be revisited shortly.

ok kettenis@


# 1.178 11-Aug-2009 miod

Do not bother initializing bufpages in the md code if the computation is
exactly the same the mi could will use if bufinit() is invoked with
bufpages == 0.


# 1.177 11-Aug-2009 miod

With the SysV memory allocation changes, allocsys() doesn't do anything
anymore. Get rid of it completely.


# 1.176 09-Aug-2009 blambert

Rototill system V message queues.

No longer allocate a static amount of memory for messages in MD
boot path; message queues, message metadata, and message data now
all use dynamic memory, which means that runtime sysctls should now
be trivial to implement.

Since I'm going to be around all week to fix any breakage, this should
probably just go in now.


# 1.175 02-Aug-2009 beck

Dynamic buffer cache support - a re-commit of what was backed out
after c2k9

allows buffer cache to be extended and grow/shrink dynamically

tested by many, ok oga@, "why not just commit it" deraadt@


# 1.174 29-Jul-2009 kettenis

Get rid of non-equivalent aliases of the pcb by moving the fpu state out
of the pcb and using the p_addr member of 'struct proc' to calculate the
address of the kernel stack when switching to virtual mode after taking a trap.
Remove the now unecessary cache flushes; they're actually harmful since they
create non-equivalent aliases. This seems to fix the memory corruption we
have been observing from time to time.

This diff does not rename fpu_curpcb, which is now somewhat incorrectly named.
I hope to change things back again as soon as we are able to map the pcb 1:1.


Revision tags: OPENBSD_4_6_BASE
# 1.173 15-Jun-2009 beck

Back out all the buffer cache changes I committed during c2k9. This reverts three
commits:

1) The sysctl allowing bufcachepercent to be changed at boot time.
2) The change moving the buffer cache hash chains to a red-black tree
3) The dynamic buffer cache (Which depended on the earlier too).

ok on the backout from marco and todd


# 1.172 03-Jun-2009 beck

add kern.bufcachepercent sysctl to allow adjusting the buffer cache
size on a running system.
ok art@, oga@


Revision tags: OPENBSD_4_5_BASE
# 1.171 14-Feb-2009 kettenis

Limit the amount of physical memory to 2GB. Using more causes memory
corruption on PA-RISC 2.0 systems (and there are very few PA-RISC 1.1
systems that support more than 2GB).

ok miod@


# 1.170 04-Feb-2009 miod

On systems with split BTLB, do not bother trying to insert DBTLB entries,
as PDC will lie to us pretending it did while it didn't.

ok kettenis@


# 1.169 04-Feb-2009 miod

Unify memory size reports a bit more: always report size in MB, and report
reserved memory on alpha and hppa on its own line (as done on sgi).


Revision tags: OPENBSD_4_4_BASE
# 1.168 14-Jul-2008 miod

Be sure to propagate PSL_O in psw on PCXU* processors to userland processes
and signal handlers.
ok kettenis@


# 1.167 27-Jun-2008 miod

Clear swap encryption keys before dumping a kernel image.


# 1.166 09-Apr-2008 deraadt

Add new stub uvm_shutdown() and call it from the right place in MD boot()


Revision tags: OPENBSD_4_3_BASE
# 1.165 22-Sep-2007 martin

replace even more ctob and btoc with ptoa and atop respectively plus
uvm_extern.h where needed


Revision tags: OPENBSD_4_2_BASE
# 1.164 22-Jul-2007 kettenis

Move hppa to __HAVE_TIMECOUNTERS.


# 1.163 20-Jul-2007 kettenis

Give hppa the blink_led API from sparc64, and the associated machdep.led_blink
sysctl.


# 1.162 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.161 14-Jul-2007 kettenis

Make sigreturn(2) set the proper space ID for the instruction queue. Fixes
a few more pthreads regression tests.

ok miod@


# 1.160 10-Jul-2007 kettenis

Don't trust the privilige level in the sigcontext passed to sigreturn(2).

ok miod@


# 1.159 24-Jun-2007 kettenis

Crank initial storage for extents a bit. We really should allocate extents
using malloc once vm is initialised, but this will do for now.

ok deraadt@


# 1.158 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.157 27-May-2007 miod

Make sure the minaddr hint for uvm_km_suballoc() calls is always initialized.
ok pedro@


# 1.156 26-May-2007 pedro

Dynamic buffer cache. Initial diff from mickey@, okay art@ beck@ toby@
deraadt@ dlg@.


# 1.155 21-May-2007 kettenis

Add support for 8700/pcxw2 cpu.


# 1.154 21-May-2007 kettenis

Ask firmware for reset before trying ourselves; needed for four-digit b/c/j
workstations.

tested by otto@, krw@; ok deraadt@


# 1.153 17-May-2007 art

Limit hppa buffer cache to 30%. It used to be 70% because stack garbage
that was used for minaddr instead of the proper vm_map_min(kernel_map)
(fixed in this diff).

From mickey. art@ ok


# 1.152 14-May-2007 martin

move hppa to __HAVE_CPUINFO

input from miod@, ok kettenis@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.151 28-May-2006 martin

minor nit, use CPU ID instead of FPU ID for BTLB parameters after passing
all kludges


# 1.150 15-Apr-2006 martin

make warning about missing HPT support DEBUG for now

ok mickey@


Revision tags: OPENBSD_3_9_BASE
# 1.149 26-Oct-2005 martin

no more hppa_round_page() and hppa_trunc_page() macros

ok mickey@


Revision tags: OPENBSD_3_8_BASE
# 1.148 06-Aug-2005 miod

We do not need a char machine_arch[] constant.
ok deraadt@


# 1.147 11-Jul-2005 mickey

align some stupid comments


# 1.146 10-May-2005 mickey

set pcsq in case we get signal delivery once interrupted from the gateway page; from chs


# 1.145 18-Apr-2005 mickey

do not do some of the initmsgbuf()s job


# 1.144 07-Apr-2005 mickey

on some machines it's possible to limit the amount of physmem initialised dring post so having msgbuf at the end of memory shall work


# 1.143 07-Apr-2005 mickey

64bit-friendly pdc.h and iomod.h and correspondent changes elsewhere


# 1.142 26-Mar-2005 mickey

md parts for hpux_compa code; some problems w/ signals delivery still exist


Revision tags: OPENBSD_3_7_BASE
# 1.141 24-Feb-2005 mickey

do not even ask for btlb on 8k cpus as pdc pretends there is some but then it does not work; found w/ Moritz Kiese <mbk@mytum.de> on c180; add a debug print and fix pcxu entry


# 1.140 17-Nov-2004 mickey

print real/avail/bufcache sizes as unsigned


# 1.139 26-Oct-2004 mickey

disable sid hashing on pcxu and above


# 1.138 14-Oct-2004 mickey

a bit larger delays during boot() to let msgs appear


# 1.137 19-Sep-2004 mickey

turn totalphysmem into physmem and name old physmem into smth it really is


# 1.136 18-Sep-2004 mickey

oops


# 1.135 15-Sep-2004 mickey

add pcxu tlb handlers and cpu probing
add u2/uturn ioa driver in dumb mode now
enable pcxu/pcxw support


# 1.134 14-Sep-2004 mickey

store fpu version for later use. make sure to proper store/clear fpu state in fork/exec/exit/sendsig


# 1.133 14-Sep-2004 mickey

error out from btlb_insert() if there is none


Revision tags: OPENBSD_3_6_BASE
# 1.132 01-Jul-2004 mickey

have separate insn and data cache all-flushers


# 1.131 30-Jun-2004 mickey

allow forced fpu emulation through a sysctl


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.130 13-May-2004 mickey

8ks do not have hvt


# 1.129 05-May-2004 mickey

much easier tlb handler branch patching


# 1.128 05-May-2004 mickey

do not engage HPT on PCXT' (yet)


# 1.127 08-Apr-2004 mickey

repair pcxs/t confoosion


# 1.126 07-Apr-2004 mickey

update copyright; miod@ is fine w/ files where he holds it too


Revision tags: OPENBSD_3_5_BASE
# 1.125 10-Mar-2004 tom

Ensure that we obey a user's ddb> boot reboot command even if the system
is cold (during startup).

This adds RB_USERREQ to sys/reboot.h, uses it in the ddb commands, and
ensures that */*/machdep.c:boot() won't set RB_HALT when cold if this
flag is set.

ok deraadt@


# 1.124 14-Feb-2004 grange

Simplify hw.{cpuspeed,setperf} api moving all the sysctl stuff
from the underlying callbacks.

Testing hppa mickey@, ppc drahn@
Ok markus@ tedu@


# 1.123 05-Jan-2004 mickey

kill debugging code that is not needed anymore


# 1.122 23-Dec-2003 mickey

provide cpuspeed fluff


# 1.121 20-Dec-2003 miod

Don't let microtime() return a struct timeval with exactly 1000000 microseconds.


# 1.120 18-Dec-2003 mickey

spls do not protect cpu_itmr and thus time might jump back sometimes due to cpu_itmr modified to a higher value than a read itmr; found and testing by miod@


# 1.119 17-Dec-2003 mickey

in the real mem print do not include reserved for prom into used by openbsd


# 1.118 10-Dec-2003 mickey

for unaligned btlb mapping attempts -- just fail


# 1.117 24-Nov-2003 mickey

experimental support for HVT as a 2nd level tlb


# 1.116 15-Oct-2003 mickey

less global name space pollution


# 1.115 05-Oct-2003 mickey

reload the itmr as soon as we get the intr to avoid lagging on slower machines


# 1.114 25-Sep-2003 mickey

some pcxl2 do not report fpus -- assume it's there


Revision tags: OPENBSD_3_4_BASE
# 1.113 04-Sep-2003 mickey

a better cpu identification; testing by miod


# 1.112 31-Aug-2003 miod

pdc_model needs to be visible from cpu.c


# 1.111 20-Aug-2003 mickey

missing nl in debugging prontf


# 1.110 07-Aug-2003 mickey

dead proto


# 1.109 07-Aug-2003 mickey

first allocate space on stack then copyout signal shits. add a DEBUG check for a whacky user pc (as impossible due to the recent trap.c change)


# 1.108 03-Aug-2003 mickey

clear branch and nullify bits in psw on sending a signal


# 1.107 30-Jul-2003 mickey

deduce the leds address from the model number and thus make some more use of that lichtenblinkenschmutz on some more machinens


# 1.106 22-May-2003 mickey

imprecision in delay_init()


# 1.105 18-May-2003 mickey

save the fpu state for the signal handler. this is essential
as the fpu regs can be used by the gcc even for non-fpu
means and data copying.
rearrange the sigcontext a bit to include only the general
registers that are needed restoring upon return and thus
less waste of space and make up some space for the fpu regs.

ALL software that used the signal context on the stack
needs at least rebuilding now. a new snap has bin built as well.


Revision tags: UBC_SYNC_A
# 1.104 11-May-2003 deraadt

string cleaning; krw ok


# 1.103 07-Apr-2003 mickey

s/HP9000/HP 9000/; from weissmanndude


Revision tags: OPENBSD_3_3_BASE
# 1.102 18-Feb-2003 deraadt

knf; mickey ok


# 1.101 12-Feb-2003 jason

How uncommon... hppa only has one common: msgbufmapped (decl'd in /sys/kern)


# 1.100 12-Feb-2003 mickey

only align the first stack frame onto the minimal required alignment


# 1.99 10-Feb-2003 mickey

fix pcs and pcxt recognition. from weissmanndude


# 1.98 22-Jan-2003 mickey

consistantly use uvm_prot_* vs vm_prot_* evewrhere


# 1.97 14-Jan-2003 mickey

fix cutnpaste in the cpu table for the itlbna field; from herr weissmanndude


# 1.96 14-Jan-2003 mickey

need pdc_hwtlb always; pt out by herr weissmanndude


# 1.95 13-Jan-2003 mickey

fix the logic in hvt probing


# 1.94 09-Jan-2003 miod

Remove fetch(9) and store(9) functions from the kernel, and replace the few
remaining instances of them with appropriate copy(9) usage.

ok art@, tested on all arches unless my memory is non-ECC


# 1.93 19-Dec-2002 mickey

setregs: put the whole frame setup into one place


# 1.92 19-Dec-2002 mickey

level 0x16 is really an l2


# 1.91 17-Dec-2002 millert

Make SysV-style shared memory and semaphore limits sysctl'able.
Instead of allocating a static amount of memory for the data
structures via valloc() in allocsys(), allocate things dynamically
using pool(9) when possible and malloc(9) when not. The various
members of struct seminfo and struct shminfo are in kern.seminfo
and kern.shminfo respectively (not all members of kern.seminfo are
changable).

The data structures used still leave something to be desired but
things are not made worse in that respect by this commit.


# 1.90 27-Nov-2002 mickey

no wrapper arounf hardclock(), use CPU_CLOCKUPDATE, real microtime; miod ok


# 1.89 08-Nov-2002 mickey

Don't uvm_useracc the user sigcontext in sys_sigreturn and then access
the user addresses directly from the kernel. copyin is faster and can
correctly deal properly with mappings that uvm_useracc thinks are
correct but will fault anyway (to figure out how to generate such
mappings is left as en excercise for the reader).


# 1.88 01-Nov-2002 mickey

add a missing delay after printf on halt[-p], proper arg for a cold hook


Revision tags: UBC_SYNC_B
# 1.87 22-Oct-2002 mickey

do not force single-user; pt out by fries@


# 1.86 15-Oct-2002 mickey

missing initmsgbuf(), noticed by miod@


# 1.85 13-Oct-2002 mickey

track the end of physmem for use in dmmem_alloc


# 1.84 07-Oct-2002 mickey

s/PSW_/PSL_/ to match other archs


# 1.83 07-Oct-2002 mickey

proper terminate the user stack on signal


# 1.82 07-Oct-2002 mickey

on implementations w/ fpu included unimplemented instructions
are signaled through the exception trap w/ invalid opcode marked
instruction in the exception registers, not through the emulation
trap (as long as the fpu is enabled, of course).
parse emulation from the exception trap as well as the emulation
trap and fix the dispatcher into usable condition.
parse invalid op exception on trap and signal the user appropriately.
reset the exception on exec and for child on fork.
the later is appropriate since exceptions are delayed until next
fpu instruction, which was in the parent indeed, let him get it.
save parent's fpu context on fork before cipying it, if the
parent owned the fpu.


Revision tags: OPENBSD_3_2_BASE
# 1.81 23-Sep-2002 mickey

parisc level 0x10 is just an overclocked 0xe


# 1.80 17-Sep-2002 mickey

handle fpu exceptions properly, might use a regress, i guess


# 1.79 11-Sep-2002 mickey

provide a convinient reset label


# 1.78 11-Sep-2002 mickey

stack grows the other way, but the frame is the other way to that. hehe


# 1.77 09-Sep-2002 mickey

set up the frame flags and a user frame better on exec


# 1.76 03-Aug-2002 mickey

rework boot() w/o a goto


# 1.75 25-Jul-2002 mickey

missing arg in the call to the pdc_call since some old times


# 1.74 25-Jul-2002 mickey

kcopy is a space-to-space copy from kernel space, to guess where, -- to the same kernel space, just error on fault


# 1.73 20-Jul-2002 art

Instead of copying out the signal trampoline on top of the stack, create
an uvm aobj, copy out the signal trampoline into it and share that page
among all processes for the same emulation.

This also requires us to actually be able to tell signal code where the
trampoline is located, so introduce a new field in struct proc - p_sigcode
that is a pointer to sigcode. This allows us to remove all the ugly
calculations of the signal trampoline address done in every sendsig
function in the tree (that's why so many files are changed).

Tested by various people. ok deraadt@


# 1.72 14-May-2002 mickey

disable sid hashing while still in real mode, alos print the parisc arch once and not per each cpu since they are not intermixable architecture-wise


# 1.71 13-May-2002 mickey

ldi-ldo whatever was in the table, be that much clever


# 1.70 08-May-2002 mickey

print parisc level w/ the the parisc version, not for each cpu


# 1.69 08-May-2002 mickey

kill debugging printfski


# 1.68 22-Apr-2002 mickey

no longer batc the data, only the code.
this removes a constraint and an ld.script dependancy
for the .data and the dynamically allocated kernel
structures existed w/ batcing. also makes pmap_steal_memory
obsolete and replaced w/ the pmap_virtual_space.
implement batching for pmap_remove to avoid
zeroing out the pte entries if pde will be removed anyway.


# 1.67 21-Apr-2002 mickey

better buf's mapping and less magic constants in checking for io space cachability


Revision tags: OPENBSD_3_1_BASE
# 1.66 26-Mar-2002 mickey

if cannot guess cpu model default to the lowest supported one


# 1.65 25-Mar-2002 deraadt

spelling


# 1.64 23-Mar-2002 espie

Add variables for config(8) -e time tweak of systemV shared memory
parameters.

Ok millert@, miod@, maja@


# 1.63 19-Mar-2002 mickey

mtcpu seq requires a pre-sync, implement hpt init for pcxl


# 1.62 15-Mar-2002 mickey

rewrite a pmap to use multilevel page tables.
lower 12 bits contain the perms, no unused bits left,
but a couple for off-tlb use (as the ref implemented now).
do not use the hvt, which might get some use later
if proven to speed thigs up, tlb handlers would po
another dozen of insns though, but if that's worth its...
move on the data seg and map kernel text rdonly (idea form fredette),
since all of the page0 mods done before that we are all fine
except for some viper fluff, but later w/ that.
this also picks up a bit more of ddb magic for bpt and ss.
tlb handlers can use a little bit more of attention,
but things, visually, seem to be much faster already, --
sorry, no benchmarks for now.

* effort sponsored in part by the `henry st. old ale house'
* and mr.pete and mr.lee in particular in thier generous entrirety.
* the proj took a little more that 72man*h as it was expected,
* but within murhy's law estimations.


# 1.61 14-Mar-2002 millert

First round of __P removal in sys


# 1.60 20-Feb-2002 mickey

setup power failure handler (for sw-controlled power button), move toc handler


# 1.59 17-Feb-2002 maja

Patch from Daniel Lucq <daniel@lucq.org>

The patch allows you to change the value of NMBCLUSTERS, BUFCACHEPERCENT
and NKMEMPAGES using the config command, instead of recompiling the kernel.

This is the kernel part of the patch. I have compiled it on i386, sparc64,
alpha and macppc. -moj ok art@ maja@


# 1.58 12-Feb-2002 mickey

support 712's programmable power switch, no interrupt yet


# 1.57 12-Feb-2002 mickey

small repairs to hpmc and toc handlers


# 1.56 11-Feb-2002 mickey

disable fpu on csw, print fpu version on cpu line, if present


# 1.55 07-Feb-2002 mickey

fix sigdebug cases; init sigcontext before it's used (;


# 1.54 06-Feb-2002 mickey

implement signal delivery; based on fredette@'s work


# 1.53 03-Feb-2002 mickey

restore hpt size computation, does not break things as i thought


# 1.52 02-Feb-2002 mickey

fix 'physmem' usage


# 1.51 02-Feb-2002 mickey

implement the rest of /dev/mem devices; from netbsd


# 1.50 23-Jan-2002 art

move mb_map allocation to mbinit()


# 1.49 23-Jan-2002 art

move definition of mb_map from zillions of machdep.c to uipc_mbuf.c


# 1.48 16-Jan-2002 miod

Don't include <sys/map.h> when you don't need what's in it.


Revision tags: UBC_BASE
# 1.47 02-Dec-2001 mickey

branches: 1.47.2;
increase fixed extent storage


# 1.46 28-Nov-2001 art

zap some typedefs.
vm_map_t -> struct vm_map *
vm_map_entry_t -> struct vm_map_entry *
simple_lock_data_t -> struct simplelock

(uvm not done yet, coming in the next commit)


# 1.45 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.44 24-Nov-2001 miod

Harmonize boot() logic across arches:
- ensure RB_DUMP | RB_HALT will cause a dump
- or RB_HALT if (cold)
While there, honor RB_TIMEBAD on sparc64.


# 1.43 09-Nov-2001 art

nswbuf hasn't been used for ages. gc.


# 1.42 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.41 06-Nov-2001 miod

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


Revision tags: OPENBSD_3_0_BASE
# 1.40 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.39 12-Sep-2001 art

mbutl no more


# 1.38 23-Aug-2001 art

We can now move timeout_init into main().


# 1.37 23-Aug-2001 art

Remove even more old timeout tentacles.


# 1.36 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.35 05-Jul-2001 art

Get rid of REAL_CLISTS. It was never implemented and the tentacles are
everywhhere.


# 1.34 17-May-2001 provos

convert mbuf and cluster allocation to pool, mostly from NetBSD
okay art@ miod@


# 1.33 05-May-2001 art

Rename configure() to cpu_configure().
Move it from cpu_startup() to main().


# 1.32 05-May-2001 art

Get rid of CLSIZE and all related stuff.
CLSIZE -> 1
CLBYTES -> PAGE_SIZE
OLOFSET -> PAGE_MASK
etc.
At the same time some archs needed some cleaning in vmparam.h so that
goes in at the same time.


Revision tags: OPENBSD_2_9_BASE
# 1.31 29-Mar-2001 mickey

cpudev_data.h here needed not


# 1.30 22-Mar-2001 mickey

shuffle the tlb handlers a little,
make a new one for na data fault,
since those w/ hpt need it.


Revision tags: OPENBSD_2_8_BASE
# 1.29 15-Aug-2000 mickey

two btlb routines (i & d) for pcxs


# 1.28 15-Aug-2000 mickey

expand per-cpu control routines switch


# 1.27 08-Aug-2000 mickey

print btlb params w/ BTLBDEBUG; from Havard.Eidnes@runit.sintef.no


# 1.26 02-Jul-2000 mickey

no bays for stinger


Revision tags: OPENBSD_2_7_BASE
# 1.25 23-Mar-2000 mickey

new cpu type switch code.
initializes tlb miss handlers correspondent to probed cpu features.
also btlb load routine.
versions written are for pcxl and others.
cpu-dep btlb loaders are missing, only generic for now.


# 1.24 23-Mar-2000 art

New API for timeouts. Replaces the old timeout()/untimeout() API and
makes it the callers responsibility to allocate resources for the
timeouts.

This is a KISS implementation and does _not_ solve the problems of slow
handling of a large number of pending timeouts (this will be solved in
future work) (although hardclock is now guarateed to take constant time
for handling of timeouts).

Old timeout() and untimeout() are implemented as wrappers around the new
API and kept for compatibility. They will be removed as soon as all
subsystems are converted to use the new API.


# 1.23 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


# 1.22 22-Feb-2000 mickey

blah, blah, blah, msgbuf


Revision tags: SMP_BASE
# 1.21 09-Feb-2000 mickey

branches: 1.21.2;
heartbeat -- yeah we have a patch for that


# 1.20 25-Jan-2000 mickey

better copy and zero inlines in locore;
proper setregs() in machedep;
start of hpmc handler;
some cleanup here and there;


# 1.19 17-Jan-2000 mickey

remove unneeded stuff from setregs; force single-user for now, enable signal debug


# 1.18 11-Jan-2000 mickey

s/fpu_curproc/fpu_curpcb/ which also points into physical.
move it's definition into locore (where it's used the most).
adjust fpu context switch and save on swapout accordingly.
fix context save (in switch).
add accounting for fpu context switches (since it differes
from proc switching, we might get provided w/ some usefull
numbers as to how effective this lazy switch technique is).
enable handling fpu/sfu exceptions.


# 1.17 31-Dec-1999 mickey

don't bother about pidr3 and pidr4


# 1.16 17-Dec-1999 mickey

fix the panic message for sti memory mapping


Revision tags: kame_19991208
# 1.15 25-Nov-1999 mickey

bus stuff is in mainbus now, the rest is rewritten many ways


Revision tags: OPENBSD_2_6_BASE
# 1.14 20-Sep-1999 mickey

fix uvm_pagealloc() call


# 1.13 03-Sep-1999 art

Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.12 14-Aug-1999 mickey

proper debugging ifdefs


# 1.11 21-Jul-1999 mickey

rewrite the tlb miss handler and tlb dirty handler.
optimize for HVT usage (when compiled for proper cpu type).
drop hpt_* global variables, use info from control registers instead.
there are still ways to improve the tlb handlers tho.
machdep also prints cache and tlb coherence states (not related to the above).
You eat greenish muffin. --More-- You write real code.


# 1.10 12-Jul-1999 mickey

allocate 5% bufcache if <=16M memory installed


# 1.9 12-Jun-1999 mickey

hppa_init() now takes an argument from locore,
meaning the start of available memory.
cleanup machdep somewhat.
fix vm_map.pmap vs vm_pmap isue; 10x art@


# 1.8 23-May-1999 mickey

new swap stuff


# 1.7 21-May-1999 mickey

group all theMD f;ags together, add interrupt recursion one


# 1.6 21-May-1999 mickey

define fpu_curproc


# 1.5 20-Apr-1999 mickey

do lazy blok mapping of io space in bus_*
add copy{in,out}*, kcopy, etc
boot routines
cpu-id-hpux-compat stuff
rest of scheduler and such
uvm


Revision tags: OPENBSD_2_5_BASE
# 1.4 17-Feb-1999 mickey

print pa-risc here as well, since, finally, cpu will have to print processor type


# 1.3 04-Jan-1999 mickey

better cache handling in bus_space_barrier(), seem to work now


# 1.2 03-Jan-1999 mickey

implement bus_space_{un,}map w/ extents


# 1.1 30-Dec-1998 mickey

machdep; more work needed


# 1.264 11-Mar-2021 jsg

spelling


# 1.263 09-Jan-2021 kettenis

"encoding of diag instructions is hard, let's go shopping"

Clean up things a bit, adding documentation about the source of the
information about these instructions.

From miod@


# 1.262 08-Nov-2020 mpi

In case of failure, call sigexit() from trapsignal instead of sensig().

Simplify MD code and reduce the amount of recursion into the signal code
which helps when dealing with locks.

ok cheloha@, deraadt@


# 1.261 21-Oct-2020 deraadt

hppa also has a similar to arm64: copyout(9), copyinstr(9) and
copyoutstr(9) should bail out properly if they are called with a
length of 0.
ok kettenis@


Revision tags: OPENBSD_6_8_BASE
# 1.260 14-Jun-2020 naddy

Implement cpu_rnd_messybits() as a read of the cycle counter register.
ok dlg@ deraadt@


# 1.259 31-May-2020 dlg

introduce "cpu_rnd_messybits" for use instead of nanotime in dev/rnd.c.

rnd.c uses nanotime to get access to some bits that change quickly
between events that it can mix into the entropy pool. it doesn't
use nanotime to get a monotonically increasing set or ordered and
accurate timestamps, it just wants something with bits that change.

there's been discussions for years about letting rnd use a clock
that's super fast to read, but not necessarily accurate, but it
wasn't until recently that i figured out it wasn't interested in
time at all, so things like keeping a fast clock coherent between
cpu cores or correct according to ntp is unecessary. this means we
can just let rnd read the cycle counters on cpus and things will
be fine. cpus with cycle counters that vary in their speed and
arent kept consistent between cores may even be desirable in this
context.

so this is the first step in converting rnd.c to reading cycle
counter. it copies the nanotime backend to each arch, and they can
replace it with something MD as a second step later on.

djm@ suggested rnd_messybytes, but we landed on cpu_rnd_messybits.
thanks to visa for his eyes.
ok deraadt@ visa@
deraadt@ says he will help handle any MD fallout that occurs.


# 1.258 16-May-2020 kettenis

Make inittodr() and resettodr() MI.

ok deraadt@, mpi@, visa@
ok cheloha@ as well (would have preferred in new file for this code)


# 1.257 11-May-2020 kettenis

Initialize the timeval passed to todr_gettime() with the base time from
the file system such that implementations can use it to guess the right
century.

ok mpi@


Revision tags: OPENBSD_6_7_BASE
# 1.256 01-May-2020 kettenis

Use the same inittodr()/resettodr() implementation as on
amd64/arm64/armv7/i386/sparc64 and move it to the end of machdep.c. Rework the
actual implementation for the MC14818 compatible RTC into something that can
be used as a todr_handle just like on amd64.

ok mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.255 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


Revision tags: OPENBSD_6_4_BASE
# 1.254 20-Jul-2018 guenther

Missed a 'ksi' -> '*ksip' change in previous commit


# 1.253 10-Jul-2018 guenther

Move from sendsig() to its callers the initsiginfo() calls and
instead of passing sendsig() the code+type+val, pass a siginfo_t*
to copy from. Eliminate the indirection through struct emul for
sendsig(); we no longer have a SunOS4-compat version of sendsig()

ok deraadt@


# 1.252 22-May-2018 guenther

Delete antique sigdebug definitions

ok kettenis@


# 1.251 12-Apr-2018 deraadt

Implement MAP_STACK option for mmap(). Synchronous faults (pagefault and
syscall) confirm the stack register points at MAP_STACK memory, otherwise
SIGSEGV is delivered. sigaltstack() and pthread_attr_setstack() are modified
to create a MAP_STACK sub-region which satisfies alignment requirements.
Observe that MAP_STACK can only be set/cleared by mmap(), which zeroes the
contents of the region -- there is no mprotect() equivalent operation, so
there is no MAP_STACK-adding gadget.
This opportunistic software-emulation of a stack protection bit makes
stack-pivot operations during ROPchain fragile (kind of like removing a
tool from the toolbox).
original discussion with tedu, uvm work by stefan, testing by mortimer
ok kettenis


Revision tags: OPENBSD_6_3_BASE
# 1.250 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.249 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


Revision tags: OPENBSD_6_2_BASE
# 1.248 18-May-2017 kettenis

Implement copyin32(9).

"your chicken scratches look fine to me" deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.247 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

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


# 1.246 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.245 21-May-2016 deraadt

hand-massage sendsig() and sys_sigreturn() to be much more similar.
ok guenther kettenis


# 1.244 10-May-2016 deraadt

SROP mitigation. sendsig() stores a (per-process ^ &sigcontext) cookie
inside the sigcontext. sigreturn(2) checks syscall entry was from the
exact PC addr in the (per-process ASLR) sigtramp, verifies the cookie,
and clears it to prevent sigcontext reuse.
not yet tested on landisk, sparc, *88k, socppc.
ok kettenis


# 1.243 20-Apr-2016 dlg

pool_setipl for floating point context things

ok kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.242 21-Oct-2015 mpi

Do not call uvm_swap_finicrypt_all() a second time in dumpsys().

ok tedu@, deraadt@, miod@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.241 20-Jan-2015 kettenis

Move ps_strings "after" the random stackgap. This makes its location a
per-process value, and therefpore turns the VM_PSSTRINGS sysctl into a
per-process one as well. This gets rid of a pointer to the bottom of the
stack at a fixed location. Also clears the road for unmapping the stackgap.

ok deraadt@


# 1.240 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.239 25-Oct-2014 kettenis

Remove vmmap; it isn't used.

ok jsing@


# 1.238 23-Oct-2014 miod

Correctly set up the HPMC trap entry: according to the PA-RISC Firmware
Architecture Reference Specification, the sum of the 8 trap entry words
*and* of the payload which address and length are to be set at well-known
positions in the aforementioned trap entry, needs to be zero; the existing
code was only enforcing that the sum of the trap entry words is zero.

This matches what Linux and NetBSD do.

ok kettenis@


# 1.237 23-Oct-2014 miod

Revert limiting physmem to 2GB; the culprit was likely in uvm and uvm has
changed a lot in the last 5 years; verified to work on a 3GB system, in
snapshots for a few weeks already.


# 1.236 22-Sep-2014 dlg

implement atomic_{cas,swap}_{uint,ulong,ptr} and
atomic_{add,sub}_{int,long}_nv. sys/atomic.h turns these into the
rest of the atomic api.

on uniprocessor hppa systems "atomic" operations are implemented
as a non-interruptable sequence by disabling all interrupts on the
cpu, doing the operation, and then restoring the interrupt mask.

this isnt enough on MP systems, so we added a global atomic memory
mutex that is taken inside the interrupt disabling above to coordinate
operations between cpus.

this is a lot of overhead though cos mutexes dance around with ipls,
which is unecessary in our case because of the interrupt disabling
that is already done. also, hppa spinlocks are implemented with
ldcw which requires the word it operates on to be 16 byte aligned.
mutexes arent guaranteed to have this alignment so they compensate
by having lots of words inside themselves so they can hit the
appropriate one to use for the ldcw op.

with this in mind, this change pulls __cpu_simple_locks, which are
simply ldcw spinlocks with a 16 byte aligned word, out of
src/sys/arch/hppa/include/lock.h into src/sys/arch/hppa/include/atomic.h
so atomic.h can use them. lock.h includes atomic.h, so it still
gets and provides the same functionality as before.

finally, this also pulls the rwlock cas implementation apart. cas
ops now share the same serialising lock on MP systems as the other
memory operations, and rw_cas is defined as a wrapper around
atomic_cas_uint.

ok kettenis@


# 1.235 19-Sep-2014 kettenis

Use config_suspend_all(9).


# 1.234 18-Aug-2014 dlg

dont rely on mbuf.h to provide pool.h.

ok miod@, who has offerred to help with any MD fallout
ok guenther@


Revision tags: OPENBSD_5_6_BASE
# 1.233 22-Jul-2014 uebayasi

boot(9): Reduce diffs between hppa & hppa64 (& others)


# 1.232 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.231 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.230 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.229 13-Jul-2014 miod

These still need <sys/reboot.h> for the RB_ constants.


# 1.228 12-Jul-2014 uebayasi

reboot(9), panic(9): Call panic(9) for unrecoverable MD H/W errors (NMIs)

Some architectures have ability to detect hardware sanity and notify system
(NMI, firmware callback, etc.). Handle these hardware severe errors, same
as software errors, with panic(9).

According to miod@, SGI IP27 NMI is triggered by pushing some "hidden" button,
which "usual" users/admins don't know. Pushing such a button is "RB_USERREQ"
(human-triggered) in that the button is pushed by a human, but not "RB_USERREQ"
in that no user intervention in system (== no command input) is done. miod@
agreed that changing these from RB_USERREQ to !RB_USERREQ (== panic(9)) is
not a big problem.

OK miod@ kettenis@


# 1.227 12-Jul-2014 uebayasi

boot(9), reboot(9): Migrate MD callers of boot(9) to reboot(9)

I have found that some ports call boot(9) from machine-dependent code to
reboot system. These should be changed to either:

- Sending signal to init(8) to trigger it to shutdown system cleanly, like
acpi(4) does, in cases where found problems don't prevent system from working
immediately, or

- Just doing panic(9) if the situation is severely broken.

For now, just rewrite boot() to reboot(). Actual fixes follow.

Discussed with & OK from kettenis@


# 1.226 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.225 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.224 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.223 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.222 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.221 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.220 08-May-2014 miod

Format string fixes and removal of -Wno-format for hppa kernels.


# 1.219 08-Apr-2014 mpi

Less <uvm/uvm.h>


# 1.218 04-Apr-2014 miod

If the PDC_COPROC call fails, and we are running on a PA 1.1 system, assume
the usual 1.1 coprocessor mask, instead of using zero and having every
userland process dying with signal 4.

The circumstances under which this call fails are unclear and could be
tied to specific PROM version (I have tried overzealous stack alignment and
other tricks, to no avail). Interestingly enough, the 715/75 system which
hits this problem, only triggers it when booting from disk, and never when
booting from network.

This diff is an ugly bandaid until the problem is better understood. Or maybe
it is not worth investigating, seeing that Linux hardcodes the coprocessor
mask and never issues PDC_COPROC calls; I wonder what HP/UX does.

In my tree for over 18 months; "Looks like a nice hack" deraadt@
715/75 system provided by Sebastiaan Indesteege, thanks!


# 1.217 29-Mar-2014 guenther

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

ok dlg@ mpi@ deraadt@


# 1.216 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


# 1.215 22-Mar-2014 guenther

Move p_sigacts from struct proc to struct process.

testing help mpi@


# 1.214 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


Revision tags: OPENBSD_5_5_BASE
# 1.213 23-Nov-2013 uebayasi

Run doshutdownhooks() and config_suspend() even when boot() is called while
cold != 0. Indent and make hppa/hppa64 boot() closer to others.

OK kettenis@


# 1.212 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


Revision tags: OPENBSD_5_4_BASE
# 1.211 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


Revision tags: OPENBSD_5_3_BASE
# 1.210 02-Dec-2012 guenther

Determine whether we're currently on the alternative signal stack
dynamically, by comparing the stack pointer against the altstack
base and size, so that you get the correct answer if you longjmp
out of the signal handler, as tested by regress/sys/kern/stackjmp/.
Also, fix alt stack handling on vax, where it was completely broken.

Testing and corrections by miod@, krw@, tobiasu@, pirofti@


# 1.209 26-Oct-2012 kettenis

Properly clear trap frame in setregs() to avoid leaking registers across exec.

ok jsing@


# 1.208 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.207 07-Oct-2012 kettenis

Align the stack on a 64-byte boundary as required by "The 32-bit PA-RISC
Run-time Architecture Document". GCC relies on this to properly align
stack variables.

ok guenther@, beck@


Revision tags: OPENBSD_5_2_BASE
# 1.206 21-Jun-2012 guenther

__tfork() needs to set the stack address of the new thread in the kernel,
so that it can't get a signal while still running on the parent thread's
stack. Also, pass in sizeof(struct __tfork) to provide forward compat
when more members are added. This is an ABI change, so switch syscall
numbers and bump lib majors this time.

ok deraadt@ matthew@


Revision tags: OPENBSD_5_1_BASE
# 1.205 20-Sep-2011 miod

Clear RB_POWERDOWN early in boot() on systems which can not powerdown and
which firmware does not send spin up commands to the disks, in case the
operator changes his mind and reboots instead of manually powering down
after the system has halted.
ok kettenis@


Revision tags: OPENBSD_5_0_BASE
# 1.204 05-Jul-2011 guenther

Recommit the reverted sigacts change now that the NFS use-after-free
problem has been tracked down. This fixes the sharing of the signal
handling state: shared bits go in sigacts, per-rthread bits goes in
struct proc.

ok deraadt@


# 1.203 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.202 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.201 18-Apr-2011 guenther

Revert the sigacts diff: NFS can apparently retain pointers to processes
until they're zombies and then send them signals (for intr mounts). Until
that is untangled, the sigacts change is unsafe. sthen@ was the victim
for this one


# 1.200 15-Apr-2011 guenther

Correct the sharing of the signal handling state: stuff that should
be shared (p_sigignore, p_sigcatch, P_NOCLDSTOP, P_NOCLDWAIT) moves
to struct sigacts, wihle stuff that should be per rthread (ps_oldmask,
SAS_OLDMASK, ps_sigstk) moves to struct proc. Treat the coredumping
state bits (ps_sig, ps_code, ps_type, ps_sigval) as per-rthread
until our locking around coredumping is better.

Oh, and remove the old SunOS-compat ps_usertramp member.

"I like the sound of this" tedu@


Revision tags: OPENBSD_4_9_BASE
# 1.199 14-Jan-2011 jsing

Halt secondary CPUs when shutting down or rebooting. This should prevent
occasional hangs during reboot.

ok kettenis@


# 1.198 04-Jan-2011 jasper

- de-register. no binary change.

ok jsing@


# 1.197 01-Jan-2011 jasper

Move setting cpu_hzticks to the clock initialization function, like
other ports (e.g. hppa64) do.

ok jsing@ kettenis@


# 1.196 01-Jan-2011 jasper

- ansify

ok jsing@ kettenis@


# 1.195 30-Dec-2010 jsing

Turn signotify() into a function that also calls cpu_unidle().

ok kettenis@


# 1.194 20-Nov-2010 miod

This is a first step towards getting rid of avail_start and avail_end in the
kernel, currently limited to low-hanging fruit: these variables were used
by bus_dma to specify the range in which to allocate memory, back when
uvm_pglistalloc() was stupid and would not walk the vm_physseg[].

Nowadays, except on some platforms for early initialization, these variables
are not used, or do not need to be global variables. Therefore:
- remove `extern' declarations of avail_start and avail_end (or close cousins,
such as arm physical_start and physical_end) from files which no longer need
to use them.
- make them local variables whenever possible.
- remove them when they are assigned to but no longer used.


Revision tags: OPENBSD_4_8_BASE
# 1.193 01-Jul-2010 jsing

Create a struct to store FP state and include a pointer to the CPU that
currently holds the FPU context for this process. This will be soon used
to implement FPU shootdowns on multiprocessor kernels.

ok kettenis@


# 1.192 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.191 29-Jun-2010 jsing

Factor out code used to save and flushe process FPU context.

ok kettenis@


# 1.190 29-Jun-2010 jsing

Store pointer to process FPU state in struct cpu_info.

ok kettenis@


# 1.189 27-Jun-2010 thib

uvm constraints. Add two mandatory MD symbols, uvm_md_constraints
which contains the constraints for DMA/memory allocation for each
architecture, and dma_constraints which contains the range of addresses
that are dma accessable by the system.

This is based on ariane@'s physcontig diff, with lots of bugfixes and
additions the following additions by my self:

Introduce a new function pool_set_constraints() which sets the address
range for which we allocate pages for the pool from, this is now used
for the mbuf/mbuf cluster pools to keep them dma accessible.

The !direct archs no longer stuff pages into the kernel object in
uvm_km_getpage_pla but rather do a pmap_extract() in uvm_km_putpages.

Tested heavily by my self on i386, amd64 and sparc64. Some tests on
alpha and SGI.

"commit it" beck, art, oga, deraadt
"i like the diff" deraadt


# 1.188 27-Jun-2010 jsing

Use a mutex to make atomic operations atomic on multiprocessor kernels.

ok kettenis@


# 1.187 10-Jun-2010 deraadt

Declare safepri at the MD level on each platform, so that the kern_synch.c
does not have to deal with it as a common. Some platforms may be missed
by this commit... if you spot one, fix it the same way.
ok miod


# 1.186 09-Jun-2010 miod

Move declaration of cn_tab from dev/cons.c to dev/cninit.c, or appropriate
md files for ports which do not use dev/cninit.c. This gets rid of a common
at kernel link time.
feedback drahn@ ok deraadt@


# 1.185 24-May-2010 deraadt

Add missing prototypes
ok jsing kettenis


# 1.184 09-May-2010 kettenis

Prevent "taken branch" exceptions from kernel space by clearing the PSL_T
bit before we enter a signal handler.

"if you say so" miod@, "seems to make sense" jsing@


# 1.183 02-May-2010 kettenis

Properly initialize the members of `struct mdproc' that deal with
single-stepping when we fork and reset them upon exec.

ok miod@


# 1.182 27-Apr-2010 kettenis

Avoid null-pointer dereference by giving proc0 a place to store its
floating-point registers. Pointed out by Nick Hudson.

ok miod@, jsing@


# 1.181 19-Apr-2010 jsing

Make the Processor Status Word (PSW) a per-CPU value.

ok kettenis@


# 1.180 01-Apr-2010 jsing

Allow for multiple CPUs by moving to an array of cpu_info.

ok kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.179 31-Dec-2009 jsing

Make cpl and cpu_inintr per CPU variables. For locore.S, cpl becomes an
offset within cpu_primary_info - this will need to be revisited shortly.

ok kettenis@


# 1.178 11-Aug-2009 miod

Do not bother initializing bufpages in the md code if the computation is
exactly the same the mi could will use if bufinit() is invoked with
bufpages == 0.


# 1.177 11-Aug-2009 miod

With the SysV memory allocation changes, allocsys() doesn't do anything
anymore. Get rid of it completely.


# 1.176 09-Aug-2009 blambert

Rototill system V message queues.

No longer allocate a static amount of memory for messages in MD
boot path; message queues, message metadata, and message data now
all use dynamic memory, which means that runtime sysctls should now
be trivial to implement.

Since I'm going to be around all week to fix any breakage, this should
probably just go in now.


# 1.175 02-Aug-2009 beck

Dynamic buffer cache support - a re-commit of what was backed out
after c2k9

allows buffer cache to be extended and grow/shrink dynamically

tested by many, ok oga@, "why not just commit it" deraadt@


# 1.174 29-Jul-2009 kettenis

Get rid of non-equivalent aliases of the pcb by moving the fpu state out
of the pcb and using the p_addr member of 'struct proc' to calculate the
address of the kernel stack when switching to virtual mode after taking a trap.
Remove the now unecessary cache flushes; they're actually harmful since they
create non-equivalent aliases. This seems to fix the memory corruption we
have been observing from time to time.

This diff does not rename fpu_curpcb, which is now somewhat incorrectly named.
I hope to change things back again as soon as we are able to map the pcb 1:1.


Revision tags: OPENBSD_4_6_BASE
# 1.173 15-Jun-2009 beck

Back out all the buffer cache changes I committed during c2k9. This reverts three
commits:

1) The sysctl allowing bufcachepercent to be changed at boot time.
2) The change moving the buffer cache hash chains to a red-black tree
3) The dynamic buffer cache (Which depended on the earlier too).

ok on the backout from marco and todd


# 1.172 03-Jun-2009 beck

add kern.bufcachepercent sysctl to allow adjusting the buffer cache
size on a running system.
ok art@, oga@


Revision tags: OPENBSD_4_5_BASE
# 1.171 14-Feb-2009 kettenis

Limit the amount of physical memory to 2GB. Using more causes memory
corruption on PA-RISC 2.0 systems (and there are very few PA-RISC 1.1
systems that support more than 2GB).

ok miod@


# 1.170 04-Feb-2009 miod

On systems with split BTLB, do not bother trying to insert DBTLB entries,
as PDC will lie to us pretending it did while it didn't.

ok kettenis@


# 1.169 04-Feb-2009 miod

Unify memory size reports a bit more: always report size in MB, and report
reserved memory on alpha and hppa on its own line (as done on sgi).


Revision tags: OPENBSD_4_4_BASE
# 1.168 14-Jul-2008 miod

Be sure to propagate PSL_O in psw on PCXU* processors to userland processes
and signal handlers.
ok kettenis@


# 1.167 27-Jun-2008 miod

Clear swap encryption keys before dumping a kernel image.


# 1.166 09-Apr-2008 deraadt

Add new stub uvm_shutdown() and call it from the right place in MD boot()


Revision tags: OPENBSD_4_3_BASE
# 1.165 22-Sep-2007 martin

replace even more ctob and btoc with ptoa and atop respectively plus
uvm_extern.h where needed


Revision tags: OPENBSD_4_2_BASE
# 1.164 22-Jul-2007 kettenis

Move hppa to __HAVE_TIMECOUNTERS.


# 1.163 20-Jul-2007 kettenis

Give hppa the blink_led API from sparc64, and the associated machdep.led_blink
sysctl.


# 1.162 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.161 14-Jul-2007 kettenis

Make sigreturn(2) set the proper space ID for the instruction queue. Fixes
a few more pthreads regression tests.

ok miod@


# 1.160 10-Jul-2007 kettenis

Don't trust the privilige level in the sigcontext passed to sigreturn(2).

ok miod@


# 1.159 24-Jun-2007 kettenis

Crank initial storage for extents a bit. We really should allocate extents
using malloc once vm is initialised, but this will do for now.

ok deraadt@


# 1.158 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.157 27-May-2007 miod

Make sure the minaddr hint for uvm_km_suballoc() calls is always initialized.
ok pedro@


# 1.156 26-May-2007 pedro

Dynamic buffer cache. Initial diff from mickey@, okay art@ beck@ toby@
deraadt@ dlg@.


# 1.155 21-May-2007 kettenis

Add support for 8700/pcxw2 cpu.


# 1.154 21-May-2007 kettenis

Ask firmware for reset before trying ourselves; needed for four-digit b/c/j
workstations.

tested by otto@, krw@; ok deraadt@


# 1.153 17-May-2007 art

Limit hppa buffer cache to 30%. It used to be 70% because stack garbage
that was used for minaddr instead of the proper vm_map_min(kernel_map)
(fixed in this diff).

From mickey. art@ ok


# 1.152 14-May-2007 martin

move hppa to __HAVE_CPUINFO

input from miod@, ok kettenis@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.151 28-May-2006 martin

minor nit, use CPU ID instead of FPU ID for BTLB parameters after passing
all kludges


# 1.150 15-Apr-2006 martin

make warning about missing HPT support DEBUG for now

ok mickey@


Revision tags: OPENBSD_3_9_BASE
# 1.149 26-Oct-2005 martin

no more hppa_round_page() and hppa_trunc_page() macros

ok mickey@


Revision tags: OPENBSD_3_8_BASE
# 1.148 06-Aug-2005 miod

We do not need a char machine_arch[] constant.
ok deraadt@


# 1.147 11-Jul-2005 mickey

align some stupid comments


# 1.146 10-May-2005 mickey

set pcsq in case we get signal delivery once interrupted from the gateway page; from chs


# 1.145 18-Apr-2005 mickey

do not do some of the initmsgbuf()s job


# 1.144 07-Apr-2005 mickey

on some machines it's possible to limit the amount of physmem initialised dring post so having msgbuf at the end of memory shall work


# 1.143 07-Apr-2005 mickey

64bit-friendly pdc.h and iomod.h and correspondent changes elsewhere


# 1.142 26-Mar-2005 mickey

md parts for hpux_compa code; some problems w/ signals delivery still exist


Revision tags: OPENBSD_3_7_BASE
# 1.141 24-Feb-2005 mickey

do not even ask for btlb on 8k cpus as pdc pretends there is some but then it does not work; found w/ Moritz Kiese <mbk@mytum.de> on c180; add a debug print and fix pcxu entry


# 1.140 17-Nov-2004 mickey

print real/avail/bufcache sizes as unsigned


# 1.139 26-Oct-2004 mickey

disable sid hashing on pcxu and above


# 1.138 14-Oct-2004 mickey

a bit larger delays during boot() to let msgs appear


# 1.137 19-Sep-2004 mickey

turn totalphysmem into physmem and name old physmem into smth it really is


# 1.136 18-Sep-2004 mickey

oops


# 1.135 15-Sep-2004 mickey

add pcxu tlb handlers and cpu probing
add u2/uturn ioa driver in dumb mode now
enable pcxu/pcxw support


# 1.134 14-Sep-2004 mickey

store fpu version for later use. make sure to proper store/clear fpu state in fork/exec/exit/sendsig


# 1.133 14-Sep-2004 mickey

error out from btlb_insert() if there is none


Revision tags: OPENBSD_3_6_BASE
# 1.132 01-Jul-2004 mickey

have separate insn and data cache all-flushers


# 1.131 30-Jun-2004 mickey

allow forced fpu emulation through a sysctl


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.130 13-May-2004 mickey

8ks do not have hvt


# 1.129 05-May-2004 mickey

much easier tlb handler branch patching


# 1.128 05-May-2004 mickey

do not engage HPT on PCXT' (yet)


# 1.127 08-Apr-2004 mickey

repair pcxs/t confoosion


# 1.126 07-Apr-2004 mickey

update copyright; miod@ is fine w/ files where he holds it too


Revision tags: OPENBSD_3_5_BASE
# 1.125 10-Mar-2004 tom

Ensure that we obey a user's ddb> boot reboot command even if the system
is cold (during startup).

This adds RB_USERREQ to sys/reboot.h, uses it in the ddb commands, and
ensures that */*/machdep.c:boot() won't set RB_HALT when cold if this
flag is set.

ok deraadt@


# 1.124 14-Feb-2004 grange

Simplify hw.{cpuspeed,setperf} api moving all the sysctl stuff
from the underlying callbacks.

Testing hppa mickey@, ppc drahn@
Ok markus@ tedu@


# 1.123 05-Jan-2004 mickey

kill debugging code that is not needed anymore


# 1.122 23-Dec-2003 mickey

provide cpuspeed fluff


# 1.121 20-Dec-2003 miod

Don't let microtime() return a struct timeval with exactly 1000000 microseconds.


# 1.120 18-Dec-2003 mickey

spls do not protect cpu_itmr and thus time might jump back sometimes due to cpu_itmr modified to a higher value than a read itmr; found and testing by miod@


# 1.119 17-Dec-2003 mickey

in the real mem print do not include reserved for prom into used by openbsd


# 1.118 10-Dec-2003 mickey

for unaligned btlb mapping attempts -- just fail


# 1.117 24-Nov-2003 mickey

experimental support for HVT as a 2nd level tlb


# 1.116 15-Oct-2003 mickey

less global name space pollution


# 1.115 05-Oct-2003 mickey

reload the itmr as soon as we get the intr to avoid lagging on slower machines


# 1.114 25-Sep-2003 mickey

some pcxl2 do not report fpus -- assume it's there


Revision tags: OPENBSD_3_4_BASE
# 1.113 04-Sep-2003 mickey

a better cpu identification; testing by miod


# 1.112 31-Aug-2003 miod

pdc_model needs to be visible from cpu.c


# 1.111 20-Aug-2003 mickey

missing nl in debugging prontf


# 1.110 07-Aug-2003 mickey

dead proto


# 1.109 07-Aug-2003 mickey

first allocate space on stack then copyout signal shits. add a DEBUG check for a whacky user pc (as impossible due to the recent trap.c change)


# 1.108 03-Aug-2003 mickey

clear branch and nullify bits in psw on sending a signal


# 1.107 30-Jul-2003 mickey

deduce the leds address from the model number and thus make some more use of that lichtenblinkenschmutz on some more machinens


# 1.106 22-May-2003 mickey

imprecision in delay_init()


# 1.105 18-May-2003 mickey

save the fpu state for the signal handler. this is essential
as the fpu regs can be used by the gcc even for non-fpu
means and data copying.
rearrange the sigcontext a bit to include only the general
registers that are needed restoring upon return and thus
less waste of space and make up some space for the fpu regs.

ALL software that used the signal context on the stack
needs at least rebuilding now. a new snap has bin built as well.


Revision tags: UBC_SYNC_A
# 1.104 11-May-2003 deraadt

string cleaning; krw ok


# 1.103 07-Apr-2003 mickey

s/HP9000/HP 9000/; from weissmanndude


Revision tags: OPENBSD_3_3_BASE
# 1.102 18-Feb-2003 deraadt

knf; mickey ok


# 1.101 12-Feb-2003 jason

How uncommon... hppa only has one common: msgbufmapped (decl'd in /sys/kern)


# 1.100 12-Feb-2003 mickey

only align the first stack frame onto the minimal required alignment


# 1.99 10-Feb-2003 mickey

fix pcs and pcxt recognition. from weissmanndude


# 1.98 22-Jan-2003 mickey

consistantly use uvm_prot_* vs vm_prot_* evewrhere


# 1.97 14-Jan-2003 mickey

fix cutnpaste in the cpu table for the itlbna field; from herr weissmanndude


# 1.96 14-Jan-2003 mickey

need pdc_hwtlb always; pt out by herr weissmanndude


# 1.95 13-Jan-2003 mickey

fix the logic in hvt probing


# 1.94 09-Jan-2003 miod

Remove fetch(9) and store(9) functions from the kernel, and replace the few
remaining instances of them with appropriate copy(9) usage.

ok art@, tested on all arches unless my memory is non-ECC


# 1.93 19-Dec-2002 mickey

setregs: put the whole frame setup into one place


# 1.92 19-Dec-2002 mickey

level 0x16 is really an l2


# 1.91 17-Dec-2002 millert

Make SysV-style shared memory and semaphore limits sysctl'able.
Instead of allocating a static amount of memory for the data
structures via valloc() in allocsys(), allocate things dynamically
using pool(9) when possible and malloc(9) when not. The various
members of struct seminfo and struct shminfo are in kern.seminfo
and kern.shminfo respectively (not all members of kern.seminfo are
changable).

The data structures used still leave something to be desired but
things are not made worse in that respect by this commit.


# 1.90 27-Nov-2002 mickey

no wrapper arounf hardclock(), use CPU_CLOCKUPDATE, real microtime; miod ok


# 1.89 08-Nov-2002 mickey

Don't uvm_useracc the user sigcontext in sys_sigreturn and then access
the user addresses directly from the kernel. copyin is faster and can
correctly deal properly with mappings that uvm_useracc thinks are
correct but will fault anyway (to figure out how to generate such
mappings is left as en excercise for the reader).


# 1.88 01-Nov-2002 mickey

add a missing delay after printf on halt[-p], proper arg for a cold hook


Revision tags: UBC_SYNC_B
# 1.87 22-Oct-2002 mickey

do not force single-user; pt out by fries@


# 1.86 15-Oct-2002 mickey

missing initmsgbuf(), noticed by miod@


# 1.85 13-Oct-2002 mickey

track the end of physmem for use in dmmem_alloc


# 1.84 07-Oct-2002 mickey

s/PSW_/PSL_/ to match other archs


# 1.83 07-Oct-2002 mickey

proper terminate the user stack on signal


# 1.82 07-Oct-2002 mickey

on implementations w/ fpu included unimplemented instructions
are signaled through the exception trap w/ invalid opcode marked
instruction in the exception registers, not through the emulation
trap (as long as the fpu is enabled, of course).
parse emulation from the exception trap as well as the emulation
trap and fix the dispatcher into usable condition.
parse invalid op exception on trap and signal the user appropriately.
reset the exception on exec and for child on fork.
the later is appropriate since exceptions are delayed until next
fpu instruction, which was in the parent indeed, let him get it.
save parent's fpu context on fork before cipying it, if the
parent owned the fpu.


Revision tags: OPENBSD_3_2_BASE
# 1.81 23-Sep-2002 mickey

parisc level 0x10 is just an overclocked 0xe


# 1.80 17-Sep-2002 mickey

handle fpu exceptions properly, might use a regress, i guess


# 1.79 11-Sep-2002 mickey

provide a convinient reset label


# 1.78 11-Sep-2002 mickey

stack grows the other way, but the frame is the other way to that. hehe


# 1.77 09-Sep-2002 mickey

set up the frame flags and a user frame better on exec


# 1.76 03-Aug-2002 mickey

rework boot() w/o a goto


# 1.75 25-Jul-2002 mickey

missing arg in the call to the pdc_call since some old times


# 1.74 25-Jul-2002 mickey

kcopy is a space-to-space copy from kernel space, to guess where, -- to the same kernel space, just error on fault


# 1.73 20-Jul-2002 art

Instead of copying out the signal trampoline on top of the stack, create
an uvm aobj, copy out the signal trampoline into it and share that page
among all processes for the same emulation.

This also requires us to actually be able to tell signal code where the
trampoline is located, so introduce a new field in struct proc - p_sigcode
that is a pointer to sigcode. This allows us to remove all the ugly
calculations of the signal trampoline address done in every sendsig
function in the tree (that's why so many files are changed).

Tested by various people. ok deraadt@


# 1.72 14-May-2002 mickey

disable sid hashing while still in real mode, alos print the parisc arch once and not per each cpu since they are not intermixable architecture-wise


# 1.71 13-May-2002 mickey

ldi-ldo whatever was in the table, be that much clever


# 1.70 08-May-2002 mickey

print parisc level w/ the the parisc version, not for each cpu


# 1.69 08-May-2002 mickey

kill debugging printfski


# 1.68 22-Apr-2002 mickey

no longer batc the data, only the code.
this removes a constraint and an ld.script dependancy
for the .data and the dynamically allocated kernel
structures existed w/ batcing. also makes pmap_steal_memory
obsolete and replaced w/ the pmap_virtual_space.
implement batching for pmap_remove to avoid
zeroing out the pte entries if pde will be removed anyway.


# 1.67 21-Apr-2002 mickey

better buf's mapping and less magic constants in checking for io space cachability


Revision tags: OPENBSD_3_1_BASE
# 1.66 26-Mar-2002 mickey

if cannot guess cpu model default to the lowest supported one


# 1.65 25-Mar-2002 deraadt

spelling


# 1.64 23-Mar-2002 espie

Add variables for config(8) -e time tweak of systemV shared memory
parameters.

Ok millert@, miod@, maja@


# 1.63 19-Mar-2002 mickey

mtcpu seq requires a pre-sync, implement hpt init for pcxl


# 1.62 15-Mar-2002 mickey

rewrite a pmap to use multilevel page tables.
lower 12 bits contain the perms, no unused bits left,
but a couple for off-tlb use (as the ref implemented now).
do not use the hvt, which might get some use later
if proven to speed thigs up, tlb handlers would po
another dozen of insns though, but if that's worth its...
move on the data seg and map kernel text rdonly (idea form fredette),
since all of the page0 mods done before that we are all fine
except for some viper fluff, but later w/ that.
this also picks up a bit more of ddb magic for bpt and ss.
tlb handlers can use a little bit more of attention,
but things, visually, seem to be much faster already, --
sorry, no benchmarks for now.

* effort sponsored in part by the `henry st. old ale house'
* and mr.pete and mr.lee in particular in thier generous entrirety.
* the proj took a little more that 72man*h as it was expected,
* but within murhy's law estimations.


# 1.61 14-Mar-2002 millert

First round of __P removal in sys


# 1.60 20-Feb-2002 mickey

setup power failure handler (for sw-controlled power button), move toc handler


# 1.59 17-Feb-2002 maja

Patch from Daniel Lucq <daniel@lucq.org>

The patch allows you to change the value of NMBCLUSTERS, BUFCACHEPERCENT
and NKMEMPAGES using the config command, instead of recompiling the kernel.

This is the kernel part of the patch. I have compiled it on i386, sparc64,
alpha and macppc. -moj ok art@ maja@


# 1.58 12-Feb-2002 mickey

support 712's programmable power switch, no interrupt yet


# 1.57 12-Feb-2002 mickey

small repairs to hpmc and toc handlers


# 1.56 11-Feb-2002 mickey

disable fpu on csw, print fpu version on cpu line, if present


# 1.55 07-Feb-2002 mickey

fix sigdebug cases; init sigcontext before it's used (;


# 1.54 06-Feb-2002 mickey

implement signal delivery; based on fredette@'s work


# 1.53 03-Feb-2002 mickey

restore hpt size computation, does not break things as i thought


# 1.52 02-Feb-2002 mickey

fix 'physmem' usage


# 1.51 02-Feb-2002 mickey

implement the rest of /dev/mem devices; from netbsd


# 1.50 23-Jan-2002 art

move mb_map allocation to mbinit()


# 1.49 23-Jan-2002 art

move definition of mb_map from zillions of machdep.c to uipc_mbuf.c


# 1.48 16-Jan-2002 miod

Don't include <sys/map.h> when you don't need what's in it.


Revision tags: UBC_BASE
# 1.47 02-Dec-2001 mickey

branches: 1.47.2;
increase fixed extent storage


# 1.46 28-Nov-2001 art

zap some typedefs.
vm_map_t -> struct vm_map *
vm_map_entry_t -> struct vm_map_entry *
simple_lock_data_t -> struct simplelock

(uvm not done yet, coming in the next commit)


# 1.45 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.44 24-Nov-2001 miod

Harmonize boot() logic across arches:
- ensure RB_DUMP | RB_HALT will cause a dump
- or RB_HALT if (cold)
While there, honor RB_TIMEBAD on sparc64.


# 1.43 09-Nov-2001 art

nswbuf hasn't been used for ages. gc.


# 1.42 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.41 06-Nov-2001 miod

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


Revision tags: OPENBSD_3_0_BASE
# 1.40 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.39 12-Sep-2001 art

mbutl no more


# 1.38 23-Aug-2001 art

We can now move timeout_init into main().


# 1.37 23-Aug-2001 art

Remove even more old timeout tentacles.


# 1.36 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.35 05-Jul-2001 art

Get rid of REAL_CLISTS. It was never implemented and the tentacles are
everywhhere.


# 1.34 17-May-2001 provos

convert mbuf and cluster allocation to pool, mostly from NetBSD
okay art@ miod@


# 1.33 05-May-2001 art

Rename configure() to cpu_configure().
Move it from cpu_startup() to main().


# 1.32 05-May-2001 art

Get rid of CLSIZE and all related stuff.
CLSIZE -> 1
CLBYTES -> PAGE_SIZE
OLOFSET -> PAGE_MASK
etc.
At the same time some archs needed some cleaning in vmparam.h so that
goes in at the same time.


Revision tags: OPENBSD_2_9_BASE
# 1.31 29-Mar-2001 mickey

cpudev_data.h here needed not


# 1.30 22-Mar-2001 mickey

shuffle the tlb handlers a little,
make a new one for na data fault,
since those w/ hpt need it.


Revision tags: OPENBSD_2_8_BASE
# 1.29 15-Aug-2000 mickey

two btlb routines (i & d) for pcxs


# 1.28 15-Aug-2000 mickey

expand per-cpu control routines switch


# 1.27 08-Aug-2000 mickey

print btlb params w/ BTLBDEBUG; from Havard.Eidnes@runit.sintef.no


# 1.26 02-Jul-2000 mickey

no bays for stinger


Revision tags: OPENBSD_2_7_BASE
# 1.25 23-Mar-2000 mickey

new cpu type switch code.
initializes tlb miss handlers correspondent to probed cpu features.
also btlb load routine.
versions written are for pcxl and others.
cpu-dep btlb loaders are missing, only generic for now.


# 1.24 23-Mar-2000 art

New API for timeouts. Replaces the old timeout()/untimeout() API and
makes it the callers responsibility to allocate resources for the
timeouts.

This is a KISS implementation and does _not_ solve the problems of slow
handling of a large number of pending timeouts (this will be solved in
future work) (although hardclock is now guarateed to take constant time
for handling of timeouts).

Old timeout() and untimeout() are implemented as wrappers around the new
API and kept for compatibility. They will be removed as soon as all
subsystems are converted to use the new API.


# 1.23 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


# 1.22 22-Feb-2000 mickey

blah, blah, blah, msgbuf


Revision tags: SMP_BASE
# 1.21 09-Feb-2000 mickey

branches: 1.21.2;
heartbeat -- yeah we have a patch for that


# 1.20 25-Jan-2000 mickey

better copy and zero inlines in locore;
proper setregs() in machedep;
start of hpmc handler;
some cleanup here and there;


# 1.19 17-Jan-2000 mickey

remove unneeded stuff from setregs; force single-user for now, enable signal debug


# 1.18 11-Jan-2000 mickey

s/fpu_curproc/fpu_curpcb/ which also points into physical.
move it's definition into locore (where it's used the most).
adjust fpu context switch and save on swapout accordingly.
fix context save (in switch).
add accounting for fpu context switches (since it differes
from proc switching, we might get provided w/ some usefull
numbers as to how effective this lazy switch technique is).
enable handling fpu/sfu exceptions.


# 1.17 31-Dec-1999 mickey

don't bother about pidr3 and pidr4


# 1.16 17-Dec-1999 mickey

fix the panic message for sti memory mapping


Revision tags: kame_19991208
# 1.15 25-Nov-1999 mickey

bus stuff is in mainbus now, the rest is rewritten many ways


Revision tags: OPENBSD_2_6_BASE
# 1.14 20-Sep-1999 mickey

fix uvm_pagealloc() call


# 1.13 03-Sep-1999 art

Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.12 14-Aug-1999 mickey

proper debugging ifdefs


# 1.11 21-Jul-1999 mickey

rewrite the tlb miss handler and tlb dirty handler.
optimize for HVT usage (when compiled for proper cpu type).
drop hpt_* global variables, use info from control registers instead.
there are still ways to improve the tlb handlers tho.
machdep also prints cache and tlb coherence states (not related to the above).
You eat greenish muffin. --More-- You write real code.


# 1.10 12-Jul-1999 mickey

allocate 5% bufcache if <=16M memory installed


# 1.9 12-Jun-1999 mickey

hppa_init() now takes an argument from locore,
meaning the start of available memory.
cleanup machdep somewhat.
fix vm_map.pmap vs vm_pmap isue; 10x art@


# 1.8 23-May-1999 mickey

new swap stuff


# 1.7 21-May-1999 mickey

group all theMD f;ags together, add interrupt recursion one


# 1.6 21-May-1999 mickey

define fpu_curproc


# 1.5 20-Apr-1999 mickey

do lazy blok mapping of io space in bus_*
add copy{in,out}*, kcopy, etc
boot routines
cpu-id-hpux-compat stuff
rest of scheduler and such
uvm


Revision tags: OPENBSD_2_5_BASE
# 1.4 17-Feb-1999 mickey

print pa-risc here as well, since, finally, cpu will have to print processor type


# 1.3 04-Jan-1999 mickey

better cache handling in bus_space_barrier(), seem to work now


# 1.2 03-Jan-1999 mickey

implement bus_space_{un,}map w/ extents


# 1.1 30-Dec-1998 mickey

machdep; more work needed


# 1.263 09-Jan-2021 kettenis

"encoding of diag instructions is hard, let's go shopping"

Clean up things a bit, adding documentation about the source of the
information about these instructions.

From miod@


# 1.262 08-Nov-2020 mpi

In case of failure, call sigexit() from trapsignal instead of sensig().

Simplify MD code and reduce the amount of recursion into the signal code
which helps when dealing with locks.

ok cheloha@, deraadt@


# 1.261 21-Oct-2020 deraadt

hppa also has a similar to arm64: copyout(9), copyinstr(9) and
copyoutstr(9) should bail out properly if they are called with a
length of 0.
ok kettenis@


Revision tags: OPENBSD_6_8_BASE
# 1.260 14-Jun-2020 naddy

Implement cpu_rnd_messybits() as a read of the cycle counter register.
ok dlg@ deraadt@


# 1.259 31-May-2020 dlg

introduce "cpu_rnd_messybits" for use instead of nanotime in dev/rnd.c.

rnd.c uses nanotime to get access to some bits that change quickly
between events that it can mix into the entropy pool. it doesn't
use nanotime to get a monotonically increasing set or ordered and
accurate timestamps, it just wants something with bits that change.

there's been discussions for years about letting rnd use a clock
that's super fast to read, but not necessarily accurate, but it
wasn't until recently that i figured out it wasn't interested in
time at all, so things like keeping a fast clock coherent between
cpu cores or correct according to ntp is unecessary. this means we
can just let rnd read the cycle counters on cpus and things will
be fine. cpus with cycle counters that vary in their speed and
arent kept consistent between cores may even be desirable in this
context.

so this is the first step in converting rnd.c to reading cycle
counter. it copies the nanotime backend to each arch, and they can
replace it with something MD as a second step later on.

djm@ suggested rnd_messybytes, but we landed on cpu_rnd_messybits.
thanks to visa for his eyes.
ok deraadt@ visa@
deraadt@ says he will help handle any MD fallout that occurs.


# 1.258 16-May-2020 kettenis

Make inittodr() and resettodr() MI.

ok deraadt@, mpi@, visa@
ok cheloha@ as well (would have preferred in new file for this code)


# 1.257 11-May-2020 kettenis

Initialize the timeval passed to todr_gettime() with the base time from
the file system such that implementations can use it to guess the right
century.

ok mpi@


Revision tags: OPENBSD_6_7_BASE
# 1.256 01-May-2020 kettenis

Use the same inittodr()/resettodr() implementation as on
amd64/arm64/armv7/i386/sparc64 and move it to the end of machdep.c. Rework the
actual implementation for the MC14818 compatible RTC into something that can
be used as a todr_handle just like on amd64.

ok mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.255 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


Revision tags: OPENBSD_6_4_BASE
# 1.254 20-Jul-2018 guenther

Missed a 'ksi' -> '*ksip' change in previous commit


# 1.253 10-Jul-2018 guenther

Move from sendsig() to its callers the initsiginfo() calls and
instead of passing sendsig() the code+type+val, pass a siginfo_t*
to copy from. Eliminate the indirection through struct emul for
sendsig(); we no longer have a SunOS4-compat version of sendsig()

ok deraadt@


# 1.252 22-May-2018 guenther

Delete antique sigdebug definitions

ok kettenis@


# 1.251 12-Apr-2018 deraadt

Implement MAP_STACK option for mmap(). Synchronous faults (pagefault and
syscall) confirm the stack register points at MAP_STACK memory, otherwise
SIGSEGV is delivered. sigaltstack() and pthread_attr_setstack() are modified
to create a MAP_STACK sub-region which satisfies alignment requirements.
Observe that MAP_STACK can only be set/cleared by mmap(), which zeroes the
contents of the region -- there is no mprotect() equivalent operation, so
there is no MAP_STACK-adding gadget.
This opportunistic software-emulation of a stack protection bit makes
stack-pivot operations during ROPchain fragile (kind of like removing a
tool from the toolbox).
original discussion with tedu, uvm work by stefan, testing by mortimer
ok kettenis


Revision tags: OPENBSD_6_3_BASE
# 1.250 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.249 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


Revision tags: OPENBSD_6_2_BASE
# 1.248 18-May-2017 kettenis

Implement copyin32(9).

"your chicken scratches look fine to me" deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.247 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

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


# 1.246 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.245 21-May-2016 deraadt

hand-massage sendsig() and sys_sigreturn() to be much more similar.
ok guenther kettenis


# 1.244 10-May-2016 deraadt

SROP mitigation. sendsig() stores a (per-process ^ &sigcontext) cookie
inside the sigcontext. sigreturn(2) checks syscall entry was from the
exact PC addr in the (per-process ASLR) sigtramp, verifies the cookie,
and clears it to prevent sigcontext reuse.
not yet tested on landisk, sparc, *88k, socppc.
ok kettenis


# 1.243 20-Apr-2016 dlg

pool_setipl for floating point context things

ok kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.242 21-Oct-2015 mpi

Do not call uvm_swap_finicrypt_all() a second time in dumpsys().

ok tedu@, deraadt@, miod@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.241 20-Jan-2015 kettenis

Move ps_strings "after" the random stackgap. This makes its location a
per-process value, and therefpore turns the VM_PSSTRINGS sysctl into a
per-process one as well. This gets rid of a pointer to the bottom of the
stack at a fixed location. Also clears the road for unmapping the stackgap.

ok deraadt@


# 1.240 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.239 25-Oct-2014 kettenis

Remove vmmap; it isn't used.

ok jsing@


# 1.238 23-Oct-2014 miod

Correctly set up the HPMC trap entry: according to the PA-RISC Firmware
Architecture Reference Specification, the sum of the 8 trap entry words
*and* of the payload which address and length are to be set at well-known
positions in the aforementioned trap entry, needs to be zero; the existing
code was only enforcing that the sum of the trap entry words is zero.

This matches what Linux and NetBSD do.

ok kettenis@


# 1.237 23-Oct-2014 miod

Revert limiting physmem to 2GB; the culprit was likely in uvm and uvm has
changed a lot in the last 5 years; verified to work on a 3GB system, in
snapshots for a few weeks already.


# 1.236 22-Sep-2014 dlg

implement atomic_{cas,swap}_{uint,ulong,ptr} and
atomic_{add,sub}_{int,long}_nv. sys/atomic.h turns these into the
rest of the atomic api.

on uniprocessor hppa systems "atomic" operations are implemented
as a non-interruptable sequence by disabling all interrupts on the
cpu, doing the operation, and then restoring the interrupt mask.

this isnt enough on MP systems, so we added a global atomic memory
mutex that is taken inside the interrupt disabling above to coordinate
operations between cpus.

this is a lot of overhead though cos mutexes dance around with ipls,
which is unecessary in our case because of the interrupt disabling
that is already done. also, hppa spinlocks are implemented with
ldcw which requires the word it operates on to be 16 byte aligned.
mutexes arent guaranteed to have this alignment so they compensate
by having lots of words inside themselves so they can hit the
appropriate one to use for the ldcw op.

with this in mind, this change pulls __cpu_simple_locks, which are
simply ldcw spinlocks with a 16 byte aligned word, out of
src/sys/arch/hppa/include/lock.h into src/sys/arch/hppa/include/atomic.h
so atomic.h can use them. lock.h includes atomic.h, so it still
gets and provides the same functionality as before.

finally, this also pulls the rwlock cas implementation apart. cas
ops now share the same serialising lock on MP systems as the other
memory operations, and rw_cas is defined as a wrapper around
atomic_cas_uint.

ok kettenis@


# 1.235 19-Sep-2014 kettenis

Use config_suspend_all(9).


# 1.234 18-Aug-2014 dlg

dont rely on mbuf.h to provide pool.h.

ok miod@, who has offerred to help with any MD fallout
ok guenther@


Revision tags: OPENBSD_5_6_BASE
# 1.233 22-Jul-2014 uebayasi

boot(9): Reduce diffs between hppa & hppa64 (& others)


# 1.232 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.231 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.230 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.229 13-Jul-2014 miod

These still need <sys/reboot.h> for the RB_ constants.


# 1.228 12-Jul-2014 uebayasi

reboot(9), panic(9): Call panic(9) for unrecoverable MD H/W errors (NMIs)

Some architectures have ability to detect hardware sanity and notify system
(NMI, firmware callback, etc.). Handle these hardware severe errors, same
as software errors, with panic(9).

According to miod@, SGI IP27 NMI is triggered by pushing some "hidden" button,
which "usual" users/admins don't know. Pushing such a button is "RB_USERREQ"
(human-triggered) in that the button is pushed by a human, but not "RB_USERREQ"
in that no user intervention in system (== no command input) is done. miod@
agreed that changing these from RB_USERREQ to !RB_USERREQ (== panic(9)) is
not a big problem.

OK miod@ kettenis@


# 1.227 12-Jul-2014 uebayasi

boot(9), reboot(9): Migrate MD callers of boot(9) to reboot(9)

I have found that some ports call boot(9) from machine-dependent code to
reboot system. These should be changed to either:

- Sending signal to init(8) to trigger it to shutdown system cleanly, like
acpi(4) does, in cases where found problems don't prevent system from working
immediately, or

- Just doing panic(9) if the situation is severely broken.

For now, just rewrite boot() to reboot(). Actual fixes follow.

Discussed with & OK from kettenis@


# 1.226 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.225 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.224 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.223 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.222 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.221 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.220 08-May-2014 miod

Format string fixes and removal of -Wno-format for hppa kernels.


# 1.219 08-Apr-2014 mpi

Less <uvm/uvm.h>


# 1.218 04-Apr-2014 miod

If the PDC_COPROC call fails, and we are running on a PA 1.1 system, assume
the usual 1.1 coprocessor mask, instead of using zero and having every
userland process dying with signal 4.

The circumstances under which this call fails are unclear and could be
tied to specific PROM version (I have tried overzealous stack alignment and
other tricks, to no avail). Interestingly enough, the 715/75 system which
hits this problem, only triggers it when booting from disk, and never when
booting from network.

This diff is an ugly bandaid until the problem is better understood. Or maybe
it is not worth investigating, seeing that Linux hardcodes the coprocessor
mask and never issues PDC_COPROC calls; I wonder what HP/UX does.

In my tree for over 18 months; "Looks like a nice hack" deraadt@
715/75 system provided by Sebastiaan Indesteege, thanks!


# 1.217 29-Mar-2014 guenther

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

ok dlg@ mpi@ deraadt@


# 1.216 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


# 1.215 22-Mar-2014 guenther

Move p_sigacts from struct proc to struct process.

testing help mpi@


# 1.214 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


Revision tags: OPENBSD_5_5_BASE
# 1.213 23-Nov-2013 uebayasi

Run doshutdownhooks() and config_suspend() even when boot() is called while
cold != 0. Indent and make hppa/hppa64 boot() closer to others.

OK kettenis@


# 1.212 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


Revision tags: OPENBSD_5_4_BASE
# 1.211 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


Revision tags: OPENBSD_5_3_BASE
# 1.210 02-Dec-2012 guenther

Determine whether we're currently on the alternative signal stack
dynamically, by comparing the stack pointer against the altstack
base and size, so that you get the correct answer if you longjmp
out of the signal handler, as tested by regress/sys/kern/stackjmp/.
Also, fix alt stack handling on vax, where it was completely broken.

Testing and corrections by miod@, krw@, tobiasu@, pirofti@


# 1.209 26-Oct-2012 kettenis

Properly clear trap frame in setregs() to avoid leaking registers across exec.

ok jsing@


# 1.208 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.207 07-Oct-2012 kettenis

Align the stack on a 64-byte boundary as required by "The 32-bit PA-RISC
Run-time Architecture Document". GCC relies on this to properly align
stack variables.

ok guenther@, beck@


Revision tags: OPENBSD_5_2_BASE
# 1.206 21-Jun-2012 guenther

__tfork() needs to set the stack address of the new thread in the kernel,
so that it can't get a signal while still running on the parent thread's
stack. Also, pass in sizeof(struct __tfork) to provide forward compat
when more members are added. This is an ABI change, so switch syscall
numbers and bump lib majors this time.

ok deraadt@ matthew@


Revision tags: OPENBSD_5_1_BASE
# 1.205 20-Sep-2011 miod

Clear RB_POWERDOWN early in boot() on systems which can not powerdown and
which firmware does not send spin up commands to the disks, in case the
operator changes his mind and reboots instead of manually powering down
after the system has halted.
ok kettenis@


Revision tags: OPENBSD_5_0_BASE
# 1.204 05-Jul-2011 guenther

Recommit the reverted sigacts change now that the NFS use-after-free
problem has been tracked down. This fixes the sharing of the signal
handling state: shared bits go in sigacts, per-rthread bits goes in
struct proc.

ok deraadt@


# 1.203 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.202 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.201 18-Apr-2011 guenther

Revert the sigacts diff: NFS can apparently retain pointers to processes
until they're zombies and then send them signals (for intr mounts). Until
that is untangled, the sigacts change is unsafe. sthen@ was the victim
for this one


# 1.200 15-Apr-2011 guenther

Correct the sharing of the signal handling state: stuff that should
be shared (p_sigignore, p_sigcatch, P_NOCLDSTOP, P_NOCLDWAIT) moves
to struct sigacts, wihle stuff that should be per rthread (ps_oldmask,
SAS_OLDMASK, ps_sigstk) moves to struct proc. Treat the coredumping
state bits (ps_sig, ps_code, ps_type, ps_sigval) as per-rthread
until our locking around coredumping is better.

Oh, and remove the old SunOS-compat ps_usertramp member.

"I like the sound of this" tedu@


Revision tags: OPENBSD_4_9_BASE
# 1.199 14-Jan-2011 jsing

Halt secondary CPUs when shutting down or rebooting. This should prevent
occasional hangs during reboot.

ok kettenis@


# 1.198 04-Jan-2011 jasper

- de-register. no binary change.

ok jsing@


# 1.197 01-Jan-2011 jasper

Move setting cpu_hzticks to the clock initialization function, like
other ports (e.g. hppa64) do.

ok jsing@ kettenis@


# 1.196 01-Jan-2011 jasper

- ansify

ok jsing@ kettenis@


# 1.195 30-Dec-2010 jsing

Turn signotify() into a function that also calls cpu_unidle().

ok kettenis@


# 1.194 20-Nov-2010 miod

This is a first step towards getting rid of avail_start and avail_end in the
kernel, currently limited to low-hanging fruit: these variables were used
by bus_dma to specify the range in which to allocate memory, back when
uvm_pglistalloc() was stupid and would not walk the vm_physseg[].

Nowadays, except on some platforms for early initialization, these variables
are not used, or do not need to be global variables. Therefore:
- remove `extern' declarations of avail_start and avail_end (or close cousins,
such as arm physical_start and physical_end) from files which no longer need
to use them.
- make them local variables whenever possible.
- remove them when they are assigned to but no longer used.


Revision tags: OPENBSD_4_8_BASE
# 1.193 01-Jul-2010 jsing

Create a struct to store FP state and include a pointer to the CPU that
currently holds the FPU context for this process. This will be soon used
to implement FPU shootdowns on multiprocessor kernels.

ok kettenis@


# 1.192 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.191 29-Jun-2010 jsing

Factor out code used to save and flushe process FPU context.

ok kettenis@


# 1.190 29-Jun-2010 jsing

Store pointer to process FPU state in struct cpu_info.

ok kettenis@


# 1.189 27-Jun-2010 thib

uvm constraints. Add two mandatory MD symbols, uvm_md_constraints
which contains the constraints for DMA/memory allocation for each
architecture, and dma_constraints which contains the range of addresses
that are dma accessable by the system.

This is based on ariane@'s physcontig diff, with lots of bugfixes and
additions the following additions by my self:

Introduce a new function pool_set_constraints() which sets the address
range for which we allocate pages for the pool from, this is now used
for the mbuf/mbuf cluster pools to keep them dma accessible.

The !direct archs no longer stuff pages into the kernel object in
uvm_km_getpage_pla but rather do a pmap_extract() in uvm_km_putpages.

Tested heavily by my self on i386, amd64 and sparc64. Some tests on
alpha and SGI.

"commit it" beck, art, oga, deraadt
"i like the diff" deraadt


# 1.188 27-Jun-2010 jsing

Use a mutex to make atomic operations atomic on multiprocessor kernels.

ok kettenis@


# 1.187 10-Jun-2010 deraadt

Declare safepri at the MD level on each platform, so that the kern_synch.c
does not have to deal with it as a common. Some platforms may be missed
by this commit... if you spot one, fix it the same way.
ok miod


# 1.186 09-Jun-2010 miod

Move declaration of cn_tab from dev/cons.c to dev/cninit.c, or appropriate
md files for ports which do not use dev/cninit.c. This gets rid of a common
at kernel link time.
feedback drahn@ ok deraadt@


# 1.185 24-May-2010 deraadt

Add missing prototypes
ok jsing kettenis


# 1.184 09-May-2010 kettenis

Prevent "taken branch" exceptions from kernel space by clearing the PSL_T
bit before we enter a signal handler.

"if you say so" miod@, "seems to make sense" jsing@


# 1.183 02-May-2010 kettenis

Properly initialize the members of `struct mdproc' that deal with
single-stepping when we fork and reset them upon exec.

ok miod@


# 1.182 27-Apr-2010 kettenis

Avoid null-pointer dereference by giving proc0 a place to store its
floating-point registers. Pointed out by Nick Hudson.

ok miod@, jsing@


# 1.181 19-Apr-2010 jsing

Make the Processor Status Word (PSW) a per-CPU value.

ok kettenis@


# 1.180 01-Apr-2010 jsing

Allow for multiple CPUs by moving to an array of cpu_info.

ok kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.179 31-Dec-2009 jsing

Make cpl and cpu_inintr per CPU variables. For locore.S, cpl becomes an
offset within cpu_primary_info - this will need to be revisited shortly.

ok kettenis@


# 1.178 11-Aug-2009 miod

Do not bother initializing bufpages in the md code if the computation is
exactly the same the mi could will use if bufinit() is invoked with
bufpages == 0.


# 1.177 11-Aug-2009 miod

With the SysV memory allocation changes, allocsys() doesn't do anything
anymore. Get rid of it completely.


# 1.176 09-Aug-2009 blambert

Rototill system V message queues.

No longer allocate a static amount of memory for messages in MD
boot path; message queues, message metadata, and message data now
all use dynamic memory, which means that runtime sysctls should now
be trivial to implement.

Since I'm going to be around all week to fix any breakage, this should
probably just go in now.


# 1.175 02-Aug-2009 beck

Dynamic buffer cache support - a re-commit of what was backed out
after c2k9

allows buffer cache to be extended and grow/shrink dynamically

tested by many, ok oga@, "why not just commit it" deraadt@


# 1.174 29-Jul-2009 kettenis

Get rid of non-equivalent aliases of the pcb by moving the fpu state out
of the pcb and using the p_addr member of 'struct proc' to calculate the
address of the kernel stack when switching to virtual mode after taking a trap.
Remove the now unecessary cache flushes; they're actually harmful since they
create non-equivalent aliases. This seems to fix the memory corruption we
have been observing from time to time.

This diff does not rename fpu_curpcb, which is now somewhat incorrectly named.
I hope to change things back again as soon as we are able to map the pcb 1:1.


Revision tags: OPENBSD_4_6_BASE
# 1.173 15-Jun-2009 beck

Back out all the buffer cache changes I committed during c2k9. This reverts three
commits:

1) The sysctl allowing bufcachepercent to be changed at boot time.
2) The change moving the buffer cache hash chains to a red-black tree
3) The dynamic buffer cache (Which depended on the earlier too).

ok on the backout from marco and todd


# 1.172 03-Jun-2009 beck

add kern.bufcachepercent sysctl to allow adjusting the buffer cache
size on a running system.
ok art@, oga@


Revision tags: OPENBSD_4_5_BASE
# 1.171 14-Feb-2009 kettenis

Limit the amount of physical memory to 2GB. Using more causes memory
corruption on PA-RISC 2.0 systems (and there are very few PA-RISC 1.1
systems that support more than 2GB).

ok miod@


# 1.170 04-Feb-2009 miod

On systems with split BTLB, do not bother trying to insert DBTLB entries,
as PDC will lie to us pretending it did while it didn't.

ok kettenis@


# 1.169 04-Feb-2009 miod

Unify memory size reports a bit more: always report size in MB, and report
reserved memory on alpha and hppa on its own line (as done on sgi).


Revision tags: OPENBSD_4_4_BASE
# 1.168 14-Jul-2008 miod

Be sure to propagate PSL_O in psw on PCXU* processors to userland processes
and signal handlers.
ok kettenis@


# 1.167 27-Jun-2008 miod

Clear swap encryption keys before dumping a kernel image.


# 1.166 09-Apr-2008 deraadt

Add new stub uvm_shutdown() and call it from the right place in MD boot()


Revision tags: OPENBSD_4_3_BASE
# 1.165 22-Sep-2007 martin

replace even more ctob and btoc with ptoa and atop respectively plus
uvm_extern.h where needed


Revision tags: OPENBSD_4_2_BASE
# 1.164 22-Jul-2007 kettenis

Move hppa to __HAVE_TIMECOUNTERS.


# 1.163 20-Jul-2007 kettenis

Give hppa the blink_led API from sparc64, and the associated machdep.led_blink
sysctl.


# 1.162 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.161 14-Jul-2007 kettenis

Make sigreturn(2) set the proper space ID for the instruction queue. Fixes
a few more pthreads regression tests.

ok miod@


# 1.160 10-Jul-2007 kettenis

Don't trust the privilige level in the sigcontext passed to sigreturn(2).

ok miod@


# 1.159 24-Jun-2007 kettenis

Crank initial storage for extents a bit. We really should allocate extents
using malloc once vm is initialised, but this will do for now.

ok deraadt@


# 1.158 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.157 27-May-2007 miod

Make sure the minaddr hint for uvm_km_suballoc() calls is always initialized.
ok pedro@


# 1.156 26-May-2007 pedro

Dynamic buffer cache. Initial diff from mickey@, okay art@ beck@ toby@
deraadt@ dlg@.


# 1.155 21-May-2007 kettenis

Add support for 8700/pcxw2 cpu.


# 1.154 21-May-2007 kettenis

Ask firmware for reset before trying ourselves; needed for four-digit b/c/j
workstations.

tested by otto@, krw@; ok deraadt@


# 1.153 17-May-2007 art

Limit hppa buffer cache to 30%. It used to be 70% because stack garbage
that was used for minaddr instead of the proper vm_map_min(kernel_map)
(fixed in this diff).

From mickey. art@ ok


# 1.152 14-May-2007 martin

move hppa to __HAVE_CPUINFO

input from miod@, ok kettenis@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.151 28-May-2006 martin

minor nit, use CPU ID instead of FPU ID for BTLB parameters after passing
all kludges


# 1.150 15-Apr-2006 martin

make warning about missing HPT support DEBUG for now

ok mickey@


Revision tags: OPENBSD_3_9_BASE
# 1.149 26-Oct-2005 martin

no more hppa_round_page() and hppa_trunc_page() macros

ok mickey@


Revision tags: OPENBSD_3_8_BASE
# 1.148 06-Aug-2005 miod

We do not need a char machine_arch[] constant.
ok deraadt@


# 1.147 11-Jul-2005 mickey

align some stupid comments


# 1.146 10-May-2005 mickey

set pcsq in case we get signal delivery once interrupted from the gateway page; from chs


# 1.145 18-Apr-2005 mickey

do not do some of the initmsgbuf()s job


# 1.144 07-Apr-2005 mickey

on some machines it's possible to limit the amount of physmem initialised dring post so having msgbuf at the end of memory shall work


# 1.143 07-Apr-2005 mickey

64bit-friendly pdc.h and iomod.h and correspondent changes elsewhere


# 1.142 26-Mar-2005 mickey

md parts for hpux_compa code; some problems w/ signals delivery still exist


Revision tags: OPENBSD_3_7_BASE
# 1.141 24-Feb-2005 mickey

do not even ask for btlb on 8k cpus as pdc pretends there is some but then it does not work; found w/ Moritz Kiese <mbk@mytum.de> on c180; add a debug print and fix pcxu entry


# 1.140 17-Nov-2004 mickey

print real/avail/bufcache sizes as unsigned


# 1.139 26-Oct-2004 mickey

disable sid hashing on pcxu and above


# 1.138 14-Oct-2004 mickey

a bit larger delays during boot() to let msgs appear


# 1.137 19-Sep-2004 mickey

turn totalphysmem into physmem and name old physmem into smth it really is


# 1.136 18-Sep-2004 mickey

oops


# 1.135 15-Sep-2004 mickey

add pcxu tlb handlers and cpu probing
add u2/uturn ioa driver in dumb mode now
enable pcxu/pcxw support


# 1.134 14-Sep-2004 mickey

store fpu version for later use. make sure to proper store/clear fpu state in fork/exec/exit/sendsig


# 1.133 14-Sep-2004 mickey

error out from btlb_insert() if there is none


Revision tags: OPENBSD_3_6_BASE
# 1.132 01-Jul-2004 mickey

have separate insn and data cache all-flushers


# 1.131 30-Jun-2004 mickey

allow forced fpu emulation through a sysctl


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.130 13-May-2004 mickey

8ks do not have hvt


# 1.129 05-May-2004 mickey

much easier tlb handler branch patching


# 1.128 05-May-2004 mickey

do not engage HPT on PCXT' (yet)


# 1.127 08-Apr-2004 mickey

repair pcxs/t confoosion


# 1.126 07-Apr-2004 mickey

update copyright; miod@ is fine w/ files where he holds it too


Revision tags: OPENBSD_3_5_BASE
# 1.125 10-Mar-2004 tom

Ensure that we obey a user's ddb> boot reboot command even if the system
is cold (during startup).

This adds RB_USERREQ to sys/reboot.h, uses it in the ddb commands, and
ensures that */*/machdep.c:boot() won't set RB_HALT when cold if this
flag is set.

ok deraadt@


# 1.124 14-Feb-2004 grange

Simplify hw.{cpuspeed,setperf} api moving all the sysctl stuff
from the underlying callbacks.

Testing hppa mickey@, ppc drahn@
Ok markus@ tedu@


# 1.123 05-Jan-2004 mickey

kill debugging code that is not needed anymore


# 1.122 23-Dec-2003 mickey

provide cpuspeed fluff


# 1.121 20-Dec-2003 miod

Don't let microtime() return a struct timeval with exactly 1000000 microseconds.


# 1.120 18-Dec-2003 mickey

spls do not protect cpu_itmr and thus time might jump back sometimes due to cpu_itmr modified to a higher value than a read itmr; found and testing by miod@


# 1.119 17-Dec-2003 mickey

in the real mem print do not include reserved for prom into used by openbsd


# 1.118 10-Dec-2003 mickey

for unaligned btlb mapping attempts -- just fail


# 1.117 24-Nov-2003 mickey

experimental support for HVT as a 2nd level tlb


# 1.116 15-Oct-2003 mickey

less global name space pollution


# 1.115 05-Oct-2003 mickey

reload the itmr as soon as we get the intr to avoid lagging on slower machines


# 1.114 25-Sep-2003 mickey

some pcxl2 do not report fpus -- assume it's there


Revision tags: OPENBSD_3_4_BASE
# 1.113 04-Sep-2003 mickey

a better cpu identification; testing by miod


# 1.112 31-Aug-2003 miod

pdc_model needs to be visible from cpu.c


# 1.111 20-Aug-2003 mickey

missing nl in debugging prontf


# 1.110 07-Aug-2003 mickey

dead proto


# 1.109 07-Aug-2003 mickey

first allocate space on stack then copyout signal shits. add a DEBUG check for a whacky user pc (as impossible due to the recent trap.c change)


# 1.108 03-Aug-2003 mickey

clear branch and nullify bits in psw on sending a signal


# 1.107 30-Jul-2003 mickey

deduce the leds address from the model number and thus make some more use of that lichtenblinkenschmutz on some more machinens


# 1.106 22-May-2003 mickey

imprecision in delay_init()


# 1.105 18-May-2003 mickey

save the fpu state for the signal handler. this is essential
as the fpu regs can be used by the gcc even for non-fpu
means and data copying.
rearrange the sigcontext a bit to include only the general
registers that are needed restoring upon return and thus
less waste of space and make up some space for the fpu regs.

ALL software that used the signal context on the stack
needs at least rebuilding now. a new snap has bin built as well.


Revision tags: UBC_SYNC_A
# 1.104 11-May-2003 deraadt

string cleaning; krw ok


# 1.103 07-Apr-2003 mickey

s/HP9000/HP 9000/; from weissmanndude


Revision tags: OPENBSD_3_3_BASE
# 1.102 18-Feb-2003 deraadt

knf; mickey ok


# 1.101 12-Feb-2003 jason

How uncommon... hppa only has one common: msgbufmapped (decl'd in /sys/kern)


# 1.100 12-Feb-2003 mickey

only align the first stack frame onto the minimal required alignment


# 1.99 10-Feb-2003 mickey

fix pcs and pcxt recognition. from weissmanndude


# 1.98 22-Jan-2003 mickey

consistantly use uvm_prot_* vs vm_prot_* evewrhere


# 1.97 14-Jan-2003 mickey

fix cutnpaste in the cpu table for the itlbna field; from herr weissmanndude


# 1.96 14-Jan-2003 mickey

need pdc_hwtlb always; pt out by herr weissmanndude


# 1.95 13-Jan-2003 mickey

fix the logic in hvt probing


# 1.94 09-Jan-2003 miod

Remove fetch(9) and store(9) functions from the kernel, and replace the few
remaining instances of them with appropriate copy(9) usage.

ok art@, tested on all arches unless my memory is non-ECC


# 1.93 19-Dec-2002 mickey

setregs: put the whole frame setup into one place


# 1.92 19-Dec-2002 mickey

level 0x16 is really an l2


# 1.91 17-Dec-2002 millert

Make SysV-style shared memory and semaphore limits sysctl'able.
Instead of allocating a static amount of memory for the data
structures via valloc() in allocsys(), allocate things dynamically
using pool(9) when possible and malloc(9) when not. The various
members of struct seminfo and struct shminfo are in kern.seminfo
and kern.shminfo respectively (not all members of kern.seminfo are
changable).

The data structures used still leave something to be desired but
things are not made worse in that respect by this commit.


# 1.90 27-Nov-2002 mickey

no wrapper arounf hardclock(), use CPU_CLOCKUPDATE, real microtime; miod ok


# 1.89 08-Nov-2002 mickey

Don't uvm_useracc the user sigcontext in sys_sigreturn and then access
the user addresses directly from the kernel. copyin is faster and can
correctly deal properly with mappings that uvm_useracc thinks are
correct but will fault anyway (to figure out how to generate such
mappings is left as en excercise for the reader).


# 1.88 01-Nov-2002 mickey

add a missing delay after printf on halt[-p], proper arg for a cold hook


Revision tags: UBC_SYNC_B
# 1.87 22-Oct-2002 mickey

do not force single-user; pt out by fries@


# 1.86 15-Oct-2002 mickey

missing initmsgbuf(), noticed by miod@


# 1.85 13-Oct-2002 mickey

track the end of physmem for use in dmmem_alloc


# 1.84 07-Oct-2002 mickey

s/PSW_/PSL_/ to match other archs


# 1.83 07-Oct-2002 mickey

proper terminate the user stack on signal


# 1.82 07-Oct-2002 mickey

on implementations w/ fpu included unimplemented instructions
are signaled through the exception trap w/ invalid opcode marked
instruction in the exception registers, not through the emulation
trap (as long as the fpu is enabled, of course).
parse emulation from the exception trap as well as the emulation
trap and fix the dispatcher into usable condition.
parse invalid op exception on trap and signal the user appropriately.
reset the exception on exec and for child on fork.
the later is appropriate since exceptions are delayed until next
fpu instruction, which was in the parent indeed, let him get it.
save parent's fpu context on fork before cipying it, if the
parent owned the fpu.


Revision tags: OPENBSD_3_2_BASE
# 1.81 23-Sep-2002 mickey

parisc level 0x10 is just an overclocked 0xe


# 1.80 17-Sep-2002 mickey

handle fpu exceptions properly, might use a regress, i guess


# 1.79 11-Sep-2002 mickey

provide a convinient reset label


# 1.78 11-Sep-2002 mickey

stack grows the other way, but the frame is the other way to that. hehe


# 1.77 09-Sep-2002 mickey

set up the frame flags and a user frame better on exec


# 1.76 03-Aug-2002 mickey

rework boot() w/o a goto


# 1.75 25-Jul-2002 mickey

missing arg in the call to the pdc_call since some old times


# 1.74 25-Jul-2002 mickey

kcopy is a space-to-space copy from kernel space, to guess where, -- to the same kernel space, just error on fault


# 1.73 20-Jul-2002 art

Instead of copying out the signal trampoline on top of the stack, create
an uvm aobj, copy out the signal trampoline into it and share that page
among all processes for the same emulation.

This also requires us to actually be able to tell signal code where the
trampoline is located, so introduce a new field in struct proc - p_sigcode
that is a pointer to sigcode. This allows us to remove all the ugly
calculations of the signal trampoline address done in every sendsig
function in the tree (that's why so many files are changed).

Tested by various people. ok deraadt@


# 1.72 14-May-2002 mickey

disable sid hashing while still in real mode, alos print the parisc arch once and not per each cpu since they are not intermixable architecture-wise


# 1.71 13-May-2002 mickey

ldi-ldo whatever was in the table, be that much clever


# 1.70 08-May-2002 mickey

print parisc level w/ the the parisc version, not for each cpu


# 1.69 08-May-2002 mickey

kill debugging printfski


# 1.68 22-Apr-2002 mickey

no longer batc the data, only the code.
this removes a constraint and an ld.script dependancy
for the .data and the dynamically allocated kernel
structures existed w/ batcing. also makes pmap_steal_memory
obsolete and replaced w/ the pmap_virtual_space.
implement batching for pmap_remove to avoid
zeroing out the pte entries if pde will be removed anyway.


# 1.67 21-Apr-2002 mickey

better buf's mapping and less magic constants in checking for io space cachability


Revision tags: OPENBSD_3_1_BASE
# 1.66 26-Mar-2002 mickey

if cannot guess cpu model default to the lowest supported one


# 1.65 25-Mar-2002 deraadt

spelling


# 1.64 23-Mar-2002 espie

Add variables for config(8) -e time tweak of systemV shared memory
parameters.

Ok millert@, miod@, maja@


# 1.63 19-Mar-2002 mickey

mtcpu seq requires a pre-sync, implement hpt init for pcxl


# 1.62 15-Mar-2002 mickey

rewrite a pmap to use multilevel page tables.
lower 12 bits contain the perms, no unused bits left,
but a couple for off-tlb use (as the ref implemented now).
do not use the hvt, which might get some use later
if proven to speed thigs up, tlb handlers would po
another dozen of insns though, but if that's worth its...
move on the data seg and map kernel text rdonly (idea form fredette),
since all of the page0 mods done before that we are all fine
except for some viper fluff, but later w/ that.
this also picks up a bit more of ddb magic for bpt and ss.
tlb handlers can use a little bit more of attention,
but things, visually, seem to be much faster already, --
sorry, no benchmarks for now.

* effort sponsored in part by the `henry st. old ale house'
* and mr.pete and mr.lee in particular in thier generous entrirety.
* the proj took a little more that 72man*h as it was expected,
* but within murhy's law estimations.


# 1.61 14-Mar-2002 millert

First round of __P removal in sys


# 1.60 20-Feb-2002 mickey

setup power failure handler (for sw-controlled power button), move toc handler


# 1.59 17-Feb-2002 maja

Patch from Daniel Lucq <daniel@lucq.org>

The patch allows you to change the value of NMBCLUSTERS, BUFCACHEPERCENT
and NKMEMPAGES using the config command, instead of recompiling the kernel.

This is the kernel part of the patch. I have compiled it on i386, sparc64,
alpha and macppc. -moj ok art@ maja@


# 1.58 12-Feb-2002 mickey

support 712's programmable power switch, no interrupt yet


# 1.57 12-Feb-2002 mickey

small repairs to hpmc and toc handlers


# 1.56 11-Feb-2002 mickey

disable fpu on csw, print fpu version on cpu line, if present


# 1.55 07-Feb-2002 mickey

fix sigdebug cases; init sigcontext before it's used (;


# 1.54 06-Feb-2002 mickey

implement signal delivery; based on fredette@'s work


# 1.53 03-Feb-2002 mickey

restore hpt size computation, does not break things as i thought


# 1.52 02-Feb-2002 mickey

fix 'physmem' usage


# 1.51 02-Feb-2002 mickey

implement the rest of /dev/mem devices; from netbsd


# 1.50 23-Jan-2002 art

move mb_map allocation to mbinit()


# 1.49 23-Jan-2002 art

move definition of mb_map from zillions of machdep.c to uipc_mbuf.c


# 1.48 16-Jan-2002 miod

Don't include <sys/map.h> when you don't need what's in it.


Revision tags: UBC_BASE
# 1.47 02-Dec-2001 mickey

branches: 1.47.2;
increase fixed extent storage


# 1.46 28-Nov-2001 art

zap some typedefs.
vm_map_t -> struct vm_map *
vm_map_entry_t -> struct vm_map_entry *
simple_lock_data_t -> struct simplelock

(uvm not done yet, coming in the next commit)


# 1.45 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.44 24-Nov-2001 miod

Harmonize boot() logic across arches:
- ensure RB_DUMP | RB_HALT will cause a dump
- or RB_HALT if (cold)
While there, honor RB_TIMEBAD on sparc64.


# 1.43 09-Nov-2001 art

nswbuf hasn't been used for ages. gc.


# 1.42 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.41 06-Nov-2001 miod

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


Revision tags: OPENBSD_3_0_BASE
# 1.40 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.39 12-Sep-2001 art

mbutl no more


# 1.38 23-Aug-2001 art

We can now move timeout_init into main().


# 1.37 23-Aug-2001 art

Remove even more old timeout tentacles.


# 1.36 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.35 05-Jul-2001 art

Get rid of REAL_CLISTS. It was never implemented and the tentacles are
everywhhere.


# 1.34 17-May-2001 provos

convert mbuf and cluster allocation to pool, mostly from NetBSD
okay art@ miod@


# 1.33 05-May-2001 art

Rename configure() to cpu_configure().
Move it from cpu_startup() to main().


# 1.32 05-May-2001 art

Get rid of CLSIZE and all related stuff.
CLSIZE -> 1
CLBYTES -> PAGE_SIZE
OLOFSET -> PAGE_MASK
etc.
At the same time some archs needed some cleaning in vmparam.h so that
goes in at the same time.


Revision tags: OPENBSD_2_9_BASE
# 1.31 29-Mar-2001 mickey

cpudev_data.h here needed not


# 1.30 22-Mar-2001 mickey

shuffle the tlb handlers a little,
make a new one for na data fault,
since those w/ hpt need it.


Revision tags: OPENBSD_2_8_BASE
# 1.29 15-Aug-2000 mickey

two btlb routines (i & d) for pcxs


# 1.28 15-Aug-2000 mickey

expand per-cpu control routines switch


# 1.27 08-Aug-2000 mickey

print btlb params w/ BTLBDEBUG; from Havard.Eidnes@runit.sintef.no


# 1.26 02-Jul-2000 mickey

no bays for stinger


Revision tags: OPENBSD_2_7_BASE
# 1.25 23-Mar-2000 mickey

new cpu type switch code.
initializes tlb miss handlers correspondent to probed cpu features.
also btlb load routine.
versions written are for pcxl and others.
cpu-dep btlb loaders are missing, only generic for now.


# 1.24 23-Mar-2000 art

New API for timeouts. Replaces the old timeout()/untimeout() API and
makes it the callers responsibility to allocate resources for the
timeouts.

This is a KISS implementation and does _not_ solve the problems of slow
handling of a large number of pending timeouts (this will be solved in
future work) (although hardclock is now guarateed to take constant time
for handling of timeouts).

Old timeout() and untimeout() are implemented as wrappers around the new
API and kept for compatibility. They will be removed as soon as all
subsystems are converted to use the new API.


# 1.23 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


# 1.22 22-Feb-2000 mickey

blah, blah, blah, msgbuf


Revision tags: SMP_BASE
# 1.21 09-Feb-2000 mickey

branches: 1.21.2;
heartbeat -- yeah we have a patch for that


# 1.20 25-Jan-2000 mickey

better copy and zero inlines in locore;
proper setregs() in machedep;
start of hpmc handler;
some cleanup here and there;


# 1.19 17-Jan-2000 mickey

remove unneeded stuff from setregs; force single-user for now, enable signal debug


# 1.18 11-Jan-2000 mickey

s/fpu_curproc/fpu_curpcb/ which also points into physical.
move it's definition into locore (where it's used the most).
adjust fpu context switch and save on swapout accordingly.
fix context save (in switch).
add accounting for fpu context switches (since it differes
from proc switching, we might get provided w/ some usefull
numbers as to how effective this lazy switch technique is).
enable handling fpu/sfu exceptions.


# 1.17 31-Dec-1999 mickey

don't bother about pidr3 and pidr4


# 1.16 17-Dec-1999 mickey

fix the panic message for sti memory mapping


Revision tags: kame_19991208
# 1.15 25-Nov-1999 mickey

bus stuff is in mainbus now, the rest is rewritten many ways


Revision tags: OPENBSD_2_6_BASE
# 1.14 20-Sep-1999 mickey

fix uvm_pagealloc() call


# 1.13 03-Sep-1999 art

Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.12 14-Aug-1999 mickey

proper debugging ifdefs


# 1.11 21-Jul-1999 mickey

rewrite the tlb miss handler and tlb dirty handler.
optimize for HVT usage (when compiled for proper cpu type).
drop hpt_* global variables, use info from control registers instead.
there are still ways to improve the tlb handlers tho.
machdep also prints cache and tlb coherence states (not related to the above).
You eat greenish muffin. --More-- You write real code.


# 1.10 12-Jul-1999 mickey

allocate 5% bufcache if <=16M memory installed


# 1.9 12-Jun-1999 mickey

hppa_init() now takes an argument from locore,
meaning the start of available memory.
cleanup machdep somewhat.
fix vm_map.pmap vs vm_pmap isue; 10x art@


# 1.8 23-May-1999 mickey

new swap stuff


# 1.7 21-May-1999 mickey

group all theMD f;ags together, add interrupt recursion one


# 1.6 21-May-1999 mickey

define fpu_curproc


# 1.5 20-Apr-1999 mickey

do lazy blok mapping of io space in bus_*
add copy{in,out}*, kcopy, etc
boot routines
cpu-id-hpux-compat stuff
rest of scheduler and such
uvm


Revision tags: OPENBSD_2_5_BASE
# 1.4 17-Feb-1999 mickey

print pa-risc here as well, since, finally, cpu will have to print processor type


# 1.3 04-Jan-1999 mickey

better cache handling in bus_space_barrier(), seem to work now


# 1.2 03-Jan-1999 mickey

implement bus_space_{un,}map w/ extents


# 1.1 30-Dec-1998 mickey

machdep; more work needed


# 1.262 08-Nov-2020 mpi

In case of failure, call sigexit() from trapsignal instead of sensig().

Simplify MD code and reduce the amount of recursion into the signal code
which helps when dealing with locks.

ok cheloha@, deraadt@


# 1.261 21-Oct-2020 deraadt

hppa also has a similar to arm64: copyout(9), copyinstr(9) and
copyoutstr(9) should bail out properly if they are called with a
length of 0.
ok kettenis@


Revision tags: OPENBSD_6_8_BASE
# 1.260 14-Jun-2020 naddy

Implement cpu_rnd_messybits() as a read of the cycle counter register.
ok dlg@ deraadt@


# 1.259 31-May-2020 dlg

introduce "cpu_rnd_messybits" for use instead of nanotime in dev/rnd.c.

rnd.c uses nanotime to get access to some bits that change quickly
between events that it can mix into the entropy pool. it doesn't
use nanotime to get a monotonically increasing set or ordered and
accurate timestamps, it just wants something with bits that change.

there's been discussions for years about letting rnd use a clock
that's super fast to read, but not necessarily accurate, but it
wasn't until recently that i figured out it wasn't interested in
time at all, so things like keeping a fast clock coherent between
cpu cores or correct according to ntp is unecessary. this means we
can just let rnd read the cycle counters on cpus and things will
be fine. cpus with cycle counters that vary in their speed and
arent kept consistent between cores may even be desirable in this
context.

so this is the first step in converting rnd.c to reading cycle
counter. it copies the nanotime backend to each arch, and they can
replace it with something MD as a second step later on.

djm@ suggested rnd_messybytes, but we landed on cpu_rnd_messybits.
thanks to visa for his eyes.
ok deraadt@ visa@
deraadt@ says he will help handle any MD fallout that occurs.


# 1.258 16-May-2020 kettenis

Make inittodr() and resettodr() MI.

ok deraadt@, mpi@, visa@
ok cheloha@ as well (would have preferred in new file for this code)


# 1.257 11-May-2020 kettenis

Initialize the timeval passed to todr_gettime() with the base time from
the file system such that implementations can use it to guess the right
century.

ok mpi@


Revision tags: OPENBSD_6_7_BASE
# 1.256 01-May-2020 kettenis

Use the same inittodr()/resettodr() implementation as on
amd64/arm64/armv7/i386/sparc64 and move it to the end of machdep.c. Rework the
actual implementation for the MC14818 compatible RTC into something that can
be used as a todr_handle just like on amd64.

ok mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.255 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


Revision tags: OPENBSD_6_4_BASE
# 1.254 20-Jul-2018 guenther

Missed a 'ksi' -> '*ksip' change in previous commit


# 1.253 10-Jul-2018 guenther

Move from sendsig() to its callers the initsiginfo() calls and
instead of passing sendsig() the code+type+val, pass a siginfo_t*
to copy from. Eliminate the indirection through struct emul for
sendsig(); we no longer have a SunOS4-compat version of sendsig()

ok deraadt@


# 1.252 22-May-2018 guenther

Delete antique sigdebug definitions

ok kettenis@


# 1.251 12-Apr-2018 deraadt

Implement MAP_STACK option for mmap(). Synchronous faults (pagefault and
syscall) confirm the stack register points at MAP_STACK memory, otherwise
SIGSEGV is delivered. sigaltstack() and pthread_attr_setstack() are modified
to create a MAP_STACK sub-region which satisfies alignment requirements.
Observe that MAP_STACK can only be set/cleared by mmap(), which zeroes the
contents of the region -- there is no mprotect() equivalent operation, so
there is no MAP_STACK-adding gadget.
This opportunistic software-emulation of a stack protection bit makes
stack-pivot operations during ROPchain fragile (kind of like removing a
tool from the toolbox).
original discussion with tedu, uvm work by stefan, testing by mortimer
ok kettenis


Revision tags: OPENBSD_6_3_BASE
# 1.250 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.249 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


Revision tags: OPENBSD_6_2_BASE
# 1.248 18-May-2017 kettenis

Implement copyin32(9).

"your chicken scratches look fine to me" deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.247 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

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


# 1.246 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.245 21-May-2016 deraadt

hand-massage sendsig() and sys_sigreturn() to be much more similar.
ok guenther kettenis


# 1.244 10-May-2016 deraadt

SROP mitigation. sendsig() stores a (per-process ^ &sigcontext) cookie
inside the sigcontext. sigreturn(2) checks syscall entry was from the
exact PC addr in the (per-process ASLR) sigtramp, verifies the cookie,
and clears it to prevent sigcontext reuse.
not yet tested on landisk, sparc, *88k, socppc.
ok kettenis


# 1.243 20-Apr-2016 dlg

pool_setipl for floating point context things

ok kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.242 21-Oct-2015 mpi

Do not call uvm_swap_finicrypt_all() a second time in dumpsys().

ok tedu@, deraadt@, miod@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.241 20-Jan-2015 kettenis

Move ps_strings "after" the random stackgap. This makes its location a
per-process value, and therefpore turns the VM_PSSTRINGS sysctl into a
per-process one as well. This gets rid of a pointer to the bottom of the
stack at a fixed location. Also clears the road for unmapping the stackgap.

ok deraadt@


# 1.240 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.239 25-Oct-2014 kettenis

Remove vmmap; it isn't used.

ok jsing@


# 1.238 23-Oct-2014 miod

Correctly set up the HPMC trap entry: according to the PA-RISC Firmware
Architecture Reference Specification, the sum of the 8 trap entry words
*and* of the payload which address and length are to be set at well-known
positions in the aforementioned trap entry, needs to be zero; the existing
code was only enforcing that the sum of the trap entry words is zero.

This matches what Linux and NetBSD do.

ok kettenis@


# 1.237 23-Oct-2014 miod

Revert limiting physmem to 2GB; the culprit was likely in uvm and uvm has
changed a lot in the last 5 years; verified to work on a 3GB system, in
snapshots for a few weeks already.


# 1.236 22-Sep-2014 dlg

implement atomic_{cas,swap}_{uint,ulong,ptr} and
atomic_{add,sub}_{int,long}_nv. sys/atomic.h turns these into the
rest of the atomic api.

on uniprocessor hppa systems "atomic" operations are implemented
as a non-interruptable sequence by disabling all interrupts on the
cpu, doing the operation, and then restoring the interrupt mask.

this isnt enough on MP systems, so we added a global atomic memory
mutex that is taken inside the interrupt disabling above to coordinate
operations between cpus.

this is a lot of overhead though cos mutexes dance around with ipls,
which is unecessary in our case because of the interrupt disabling
that is already done. also, hppa spinlocks are implemented with
ldcw which requires the word it operates on to be 16 byte aligned.
mutexes arent guaranteed to have this alignment so they compensate
by having lots of words inside themselves so they can hit the
appropriate one to use for the ldcw op.

with this in mind, this change pulls __cpu_simple_locks, which are
simply ldcw spinlocks with a 16 byte aligned word, out of
src/sys/arch/hppa/include/lock.h into src/sys/arch/hppa/include/atomic.h
so atomic.h can use them. lock.h includes atomic.h, so it still
gets and provides the same functionality as before.

finally, this also pulls the rwlock cas implementation apart. cas
ops now share the same serialising lock on MP systems as the other
memory operations, and rw_cas is defined as a wrapper around
atomic_cas_uint.

ok kettenis@


# 1.235 19-Sep-2014 kettenis

Use config_suspend_all(9).


# 1.234 18-Aug-2014 dlg

dont rely on mbuf.h to provide pool.h.

ok miod@, who has offerred to help with any MD fallout
ok guenther@


Revision tags: OPENBSD_5_6_BASE
# 1.233 22-Jul-2014 uebayasi

boot(9): Reduce diffs between hppa & hppa64 (& others)


# 1.232 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.231 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.230 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.229 13-Jul-2014 miod

These still need <sys/reboot.h> for the RB_ constants.


# 1.228 12-Jul-2014 uebayasi

reboot(9), panic(9): Call panic(9) for unrecoverable MD H/W errors (NMIs)

Some architectures have ability to detect hardware sanity and notify system
(NMI, firmware callback, etc.). Handle these hardware severe errors, same
as software errors, with panic(9).

According to miod@, SGI IP27 NMI is triggered by pushing some "hidden" button,
which "usual" users/admins don't know. Pushing such a button is "RB_USERREQ"
(human-triggered) in that the button is pushed by a human, but not "RB_USERREQ"
in that no user intervention in system (== no command input) is done. miod@
agreed that changing these from RB_USERREQ to !RB_USERREQ (== panic(9)) is
not a big problem.

OK miod@ kettenis@


# 1.227 12-Jul-2014 uebayasi

boot(9), reboot(9): Migrate MD callers of boot(9) to reboot(9)

I have found that some ports call boot(9) from machine-dependent code to
reboot system. These should be changed to either:

- Sending signal to init(8) to trigger it to shutdown system cleanly, like
acpi(4) does, in cases where found problems don't prevent system from working
immediately, or

- Just doing panic(9) if the situation is severely broken.

For now, just rewrite boot() to reboot(). Actual fixes follow.

Discussed with & OK from kettenis@


# 1.226 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.225 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.224 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.223 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.222 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.221 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.220 08-May-2014 miod

Format string fixes and removal of -Wno-format for hppa kernels.


# 1.219 08-Apr-2014 mpi

Less <uvm/uvm.h>


# 1.218 04-Apr-2014 miod

If the PDC_COPROC call fails, and we are running on a PA 1.1 system, assume
the usual 1.1 coprocessor mask, instead of using zero and having every
userland process dying with signal 4.

The circumstances under which this call fails are unclear and could be
tied to specific PROM version (I have tried overzealous stack alignment and
other tricks, to no avail). Interestingly enough, the 715/75 system which
hits this problem, only triggers it when booting from disk, and never when
booting from network.

This diff is an ugly bandaid until the problem is better understood. Or maybe
it is not worth investigating, seeing that Linux hardcodes the coprocessor
mask and never issues PDC_COPROC calls; I wonder what HP/UX does.

In my tree for over 18 months; "Looks like a nice hack" deraadt@
715/75 system provided by Sebastiaan Indesteege, thanks!


# 1.217 29-Mar-2014 guenther

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

ok dlg@ mpi@ deraadt@


# 1.216 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


# 1.215 22-Mar-2014 guenther

Move p_sigacts from struct proc to struct process.

testing help mpi@


# 1.214 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


Revision tags: OPENBSD_5_5_BASE
# 1.213 23-Nov-2013 uebayasi

Run doshutdownhooks() and config_suspend() even when boot() is called while
cold != 0. Indent and make hppa/hppa64 boot() closer to others.

OK kettenis@


# 1.212 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


Revision tags: OPENBSD_5_4_BASE
# 1.211 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


Revision tags: OPENBSD_5_3_BASE
# 1.210 02-Dec-2012 guenther

Determine whether we're currently on the alternative signal stack
dynamically, by comparing the stack pointer against the altstack
base and size, so that you get the correct answer if you longjmp
out of the signal handler, as tested by regress/sys/kern/stackjmp/.
Also, fix alt stack handling on vax, where it was completely broken.

Testing and corrections by miod@, krw@, tobiasu@, pirofti@


# 1.209 26-Oct-2012 kettenis

Properly clear trap frame in setregs() to avoid leaking registers across exec.

ok jsing@


# 1.208 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.207 07-Oct-2012 kettenis

Align the stack on a 64-byte boundary as required by "The 32-bit PA-RISC
Run-time Architecture Document". GCC relies on this to properly align
stack variables.

ok guenther@, beck@


Revision tags: OPENBSD_5_2_BASE
# 1.206 21-Jun-2012 guenther

__tfork() needs to set the stack address of the new thread in the kernel,
so that it can't get a signal while still running on the parent thread's
stack. Also, pass in sizeof(struct __tfork) to provide forward compat
when more members are added. This is an ABI change, so switch syscall
numbers and bump lib majors this time.

ok deraadt@ matthew@


Revision tags: OPENBSD_5_1_BASE
# 1.205 20-Sep-2011 miod

Clear RB_POWERDOWN early in boot() on systems which can not powerdown and
which firmware does not send spin up commands to the disks, in case the
operator changes his mind and reboots instead of manually powering down
after the system has halted.
ok kettenis@


Revision tags: OPENBSD_5_0_BASE
# 1.204 05-Jul-2011 guenther

Recommit the reverted sigacts change now that the NFS use-after-free
problem has been tracked down. This fixes the sharing of the signal
handling state: shared bits go in sigacts, per-rthread bits goes in
struct proc.

ok deraadt@


# 1.203 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.202 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.201 18-Apr-2011 guenther

Revert the sigacts diff: NFS can apparently retain pointers to processes
until they're zombies and then send them signals (for intr mounts). Until
that is untangled, the sigacts change is unsafe. sthen@ was the victim
for this one


# 1.200 15-Apr-2011 guenther

Correct the sharing of the signal handling state: stuff that should
be shared (p_sigignore, p_sigcatch, P_NOCLDSTOP, P_NOCLDWAIT) moves
to struct sigacts, wihle stuff that should be per rthread (ps_oldmask,
SAS_OLDMASK, ps_sigstk) moves to struct proc. Treat the coredumping
state bits (ps_sig, ps_code, ps_type, ps_sigval) as per-rthread
until our locking around coredumping is better.

Oh, and remove the old SunOS-compat ps_usertramp member.

"I like the sound of this" tedu@


Revision tags: OPENBSD_4_9_BASE
# 1.199 14-Jan-2011 jsing

Halt secondary CPUs when shutting down or rebooting. This should prevent
occasional hangs during reboot.

ok kettenis@


# 1.198 04-Jan-2011 jasper

- de-register. no binary change.

ok jsing@


# 1.197 01-Jan-2011 jasper

Move setting cpu_hzticks to the clock initialization function, like
other ports (e.g. hppa64) do.

ok jsing@ kettenis@


# 1.196 01-Jan-2011 jasper

- ansify

ok jsing@ kettenis@


# 1.195 30-Dec-2010 jsing

Turn signotify() into a function that also calls cpu_unidle().

ok kettenis@


# 1.194 20-Nov-2010 miod

This is a first step towards getting rid of avail_start and avail_end in the
kernel, currently limited to low-hanging fruit: these variables were used
by bus_dma to specify the range in which to allocate memory, back when
uvm_pglistalloc() was stupid and would not walk the vm_physseg[].

Nowadays, except on some platforms for early initialization, these variables
are not used, or do not need to be global variables. Therefore:
- remove `extern' declarations of avail_start and avail_end (or close cousins,
such as arm physical_start and physical_end) from files which no longer need
to use them.
- make them local variables whenever possible.
- remove them when they are assigned to but no longer used.


Revision tags: OPENBSD_4_8_BASE
# 1.193 01-Jul-2010 jsing

Create a struct to store FP state and include a pointer to the CPU that
currently holds the FPU context for this process. This will be soon used
to implement FPU shootdowns on multiprocessor kernels.

ok kettenis@


# 1.192 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.191 29-Jun-2010 jsing

Factor out code used to save and flushe process FPU context.

ok kettenis@


# 1.190 29-Jun-2010 jsing

Store pointer to process FPU state in struct cpu_info.

ok kettenis@


# 1.189 27-Jun-2010 thib

uvm constraints. Add two mandatory MD symbols, uvm_md_constraints
which contains the constraints for DMA/memory allocation for each
architecture, and dma_constraints which contains the range of addresses
that are dma accessable by the system.

This is based on ariane@'s physcontig diff, with lots of bugfixes and
additions the following additions by my self:

Introduce a new function pool_set_constraints() which sets the address
range for which we allocate pages for the pool from, this is now used
for the mbuf/mbuf cluster pools to keep them dma accessible.

The !direct archs no longer stuff pages into the kernel object in
uvm_km_getpage_pla but rather do a pmap_extract() in uvm_km_putpages.

Tested heavily by my self on i386, amd64 and sparc64. Some tests on
alpha and SGI.

"commit it" beck, art, oga, deraadt
"i like the diff" deraadt


# 1.188 27-Jun-2010 jsing

Use a mutex to make atomic operations atomic on multiprocessor kernels.

ok kettenis@


# 1.187 10-Jun-2010 deraadt

Declare safepri at the MD level on each platform, so that the kern_synch.c
does not have to deal with it as a common. Some platforms may be missed
by this commit... if you spot one, fix it the same way.
ok miod


# 1.186 09-Jun-2010 miod

Move declaration of cn_tab from dev/cons.c to dev/cninit.c, or appropriate
md files for ports which do not use dev/cninit.c. This gets rid of a common
at kernel link time.
feedback drahn@ ok deraadt@


# 1.185 24-May-2010 deraadt

Add missing prototypes
ok jsing kettenis


# 1.184 09-May-2010 kettenis

Prevent "taken branch" exceptions from kernel space by clearing the PSL_T
bit before we enter a signal handler.

"if you say so" miod@, "seems to make sense" jsing@


# 1.183 02-May-2010 kettenis

Properly initialize the members of `struct mdproc' that deal with
single-stepping when we fork and reset them upon exec.

ok miod@


# 1.182 27-Apr-2010 kettenis

Avoid null-pointer dereference by giving proc0 a place to store its
floating-point registers. Pointed out by Nick Hudson.

ok miod@, jsing@


# 1.181 19-Apr-2010 jsing

Make the Processor Status Word (PSW) a per-CPU value.

ok kettenis@


# 1.180 01-Apr-2010 jsing

Allow for multiple CPUs by moving to an array of cpu_info.

ok kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.179 31-Dec-2009 jsing

Make cpl and cpu_inintr per CPU variables. For locore.S, cpl becomes an
offset within cpu_primary_info - this will need to be revisited shortly.

ok kettenis@


# 1.178 11-Aug-2009 miod

Do not bother initializing bufpages in the md code if the computation is
exactly the same the mi could will use if bufinit() is invoked with
bufpages == 0.


# 1.177 11-Aug-2009 miod

With the SysV memory allocation changes, allocsys() doesn't do anything
anymore. Get rid of it completely.


# 1.176 09-Aug-2009 blambert

Rototill system V message queues.

No longer allocate a static amount of memory for messages in MD
boot path; message queues, message metadata, and message data now
all use dynamic memory, which means that runtime sysctls should now
be trivial to implement.

Since I'm going to be around all week to fix any breakage, this should
probably just go in now.


# 1.175 02-Aug-2009 beck

Dynamic buffer cache support - a re-commit of what was backed out
after c2k9

allows buffer cache to be extended and grow/shrink dynamically

tested by many, ok oga@, "why not just commit it" deraadt@


# 1.174 29-Jul-2009 kettenis

Get rid of non-equivalent aliases of the pcb by moving the fpu state out
of the pcb and using the p_addr member of 'struct proc' to calculate the
address of the kernel stack when switching to virtual mode after taking a trap.
Remove the now unecessary cache flushes; they're actually harmful since they
create non-equivalent aliases. This seems to fix the memory corruption we
have been observing from time to time.

This diff does not rename fpu_curpcb, which is now somewhat incorrectly named.
I hope to change things back again as soon as we are able to map the pcb 1:1.


Revision tags: OPENBSD_4_6_BASE
# 1.173 15-Jun-2009 beck

Back out all the buffer cache changes I committed during c2k9. This reverts three
commits:

1) The sysctl allowing bufcachepercent to be changed at boot time.
2) The change moving the buffer cache hash chains to a red-black tree
3) The dynamic buffer cache (Which depended on the earlier too).

ok on the backout from marco and todd


# 1.172 03-Jun-2009 beck

add kern.bufcachepercent sysctl to allow adjusting the buffer cache
size on a running system.
ok art@, oga@


Revision tags: OPENBSD_4_5_BASE
# 1.171 14-Feb-2009 kettenis

Limit the amount of physical memory to 2GB. Using more causes memory
corruption on PA-RISC 2.0 systems (and there are very few PA-RISC 1.1
systems that support more than 2GB).

ok miod@


# 1.170 04-Feb-2009 miod

On systems with split BTLB, do not bother trying to insert DBTLB entries,
as PDC will lie to us pretending it did while it didn't.

ok kettenis@


# 1.169 04-Feb-2009 miod

Unify memory size reports a bit more: always report size in MB, and report
reserved memory on alpha and hppa on its own line (as done on sgi).


Revision tags: OPENBSD_4_4_BASE
# 1.168 14-Jul-2008 miod

Be sure to propagate PSL_O in psw on PCXU* processors to userland processes
and signal handlers.
ok kettenis@


# 1.167 27-Jun-2008 miod

Clear swap encryption keys before dumping a kernel image.


# 1.166 09-Apr-2008 deraadt

Add new stub uvm_shutdown() and call it from the right place in MD boot()


Revision tags: OPENBSD_4_3_BASE
# 1.165 22-Sep-2007 martin

replace even more ctob and btoc with ptoa and atop respectively plus
uvm_extern.h where needed


Revision tags: OPENBSD_4_2_BASE
# 1.164 22-Jul-2007 kettenis

Move hppa to __HAVE_TIMECOUNTERS.


# 1.163 20-Jul-2007 kettenis

Give hppa the blink_led API from sparc64, and the associated machdep.led_blink
sysctl.


# 1.162 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.161 14-Jul-2007 kettenis

Make sigreturn(2) set the proper space ID for the instruction queue. Fixes
a few more pthreads regression tests.

ok miod@


# 1.160 10-Jul-2007 kettenis

Don't trust the privilige level in the sigcontext passed to sigreturn(2).

ok miod@


# 1.159 24-Jun-2007 kettenis

Crank initial storage for extents a bit. We really should allocate extents
using malloc once vm is initialised, but this will do for now.

ok deraadt@


# 1.158 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.157 27-May-2007 miod

Make sure the minaddr hint for uvm_km_suballoc() calls is always initialized.
ok pedro@


# 1.156 26-May-2007 pedro

Dynamic buffer cache. Initial diff from mickey@, okay art@ beck@ toby@
deraadt@ dlg@.


# 1.155 21-May-2007 kettenis

Add support for 8700/pcxw2 cpu.


# 1.154 21-May-2007 kettenis

Ask firmware for reset before trying ourselves; needed for four-digit b/c/j
workstations.

tested by otto@, krw@; ok deraadt@


# 1.153 17-May-2007 art

Limit hppa buffer cache to 30%. It used to be 70% because stack garbage
that was used for minaddr instead of the proper vm_map_min(kernel_map)
(fixed in this diff).

From mickey. art@ ok


# 1.152 14-May-2007 martin

move hppa to __HAVE_CPUINFO

input from miod@, ok kettenis@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.151 28-May-2006 martin

minor nit, use CPU ID instead of FPU ID for BTLB parameters after passing
all kludges


# 1.150 15-Apr-2006 martin

make warning about missing HPT support DEBUG for now

ok mickey@


Revision tags: OPENBSD_3_9_BASE
# 1.149 26-Oct-2005 martin

no more hppa_round_page() and hppa_trunc_page() macros

ok mickey@


Revision tags: OPENBSD_3_8_BASE
# 1.148 06-Aug-2005 miod

We do not need a char machine_arch[] constant.
ok deraadt@


# 1.147 11-Jul-2005 mickey

align some stupid comments


# 1.146 10-May-2005 mickey

set pcsq in case we get signal delivery once interrupted from the gateway page; from chs


# 1.145 18-Apr-2005 mickey

do not do some of the initmsgbuf()s job


# 1.144 07-Apr-2005 mickey

on some machines it's possible to limit the amount of physmem initialised dring post so having msgbuf at the end of memory shall work


# 1.143 07-Apr-2005 mickey

64bit-friendly pdc.h and iomod.h and correspondent changes elsewhere


# 1.142 26-Mar-2005 mickey

md parts for hpux_compa code; some problems w/ signals delivery still exist


Revision tags: OPENBSD_3_7_BASE
# 1.141 24-Feb-2005 mickey

do not even ask for btlb on 8k cpus as pdc pretends there is some but then it does not work; found w/ Moritz Kiese <mbk@mytum.de> on c180; add a debug print and fix pcxu entry


# 1.140 17-Nov-2004 mickey

print real/avail/bufcache sizes as unsigned


# 1.139 26-Oct-2004 mickey

disable sid hashing on pcxu and above


# 1.138 14-Oct-2004 mickey

a bit larger delays during boot() to let msgs appear


# 1.137 19-Sep-2004 mickey

turn totalphysmem into physmem and name old physmem into smth it really is


# 1.136 18-Sep-2004 mickey

oops


# 1.135 15-Sep-2004 mickey

add pcxu tlb handlers and cpu probing
add u2/uturn ioa driver in dumb mode now
enable pcxu/pcxw support


# 1.134 14-Sep-2004 mickey

store fpu version for later use. make sure to proper store/clear fpu state in fork/exec/exit/sendsig


# 1.133 14-Sep-2004 mickey

error out from btlb_insert() if there is none


Revision tags: OPENBSD_3_6_BASE
# 1.132 01-Jul-2004 mickey

have separate insn and data cache all-flushers


# 1.131 30-Jun-2004 mickey

allow forced fpu emulation through a sysctl


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.130 13-May-2004 mickey

8ks do not have hvt


# 1.129 05-May-2004 mickey

much easier tlb handler branch patching


# 1.128 05-May-2004 mickey

do not engage HPT on PCXT' (yet)


# 1.127 08-Apr-2004 mickey

repair pcxs/t confoosion


# 1.126 07-Apr-2004 mickey

update copyright; miod@ is fine w/ files where he holds it too


Revision tags: OPENBSD_3_5_BASE
# 1.125 10-Mar-2004 tom

Ensure that we obey a user's ddb> boot reboot command even if the system
is cold (during startup).

This adds RB_USERREQ to sys/reboot.h, uses it in the ddb commands, and
ensures that */*/machdep.c:boot() won't set RB_HALT when cold if this
flag is set.

ok deraadt@


# 1.124 14-Feb-2004 grange

Simplify hw.{cpuspeed,setperf} api moving all the sysctl stuff
from the underlying callbacks.

Testing hppa mickey@, ppc drahn@
Ok markus@ tedu@


# 1.123 05-Jan-2004 mickey

kill debugging code that is not needed anymore


# 1.122 23-Dec-2003 mickey

provide cpuspeed fluff


# 1.121 20-Dec-2003 miod

Don't let microtime() return a struct timeval with exactly 1000000 microseconds.


# 1.120 18-Dec-2003 mickey

spls do not protect cpu_itmr and thus time might jump back sometimes due to cpu_itmr modified to a higher value than a read itmr; found and testing by miod@


# 1.119 17-Dec-2003 mickey

in the real mem print do not include reserved for prom into used by openbsd


# 1.118 10-Dec-2003 mickey

for unaligned btlb mapping attempts -- just fail


# 1.117 24-Nov-2003 mickey

experimental support for HVT as a 2nd level tlb


# 1.116 15-Oct-2003 mickey

less global name space pollution


# 1.115 05-Oct-2003 mickey

reload the itmr as soon as we get the intr to avoid lagging on slower machines


# 1.114 25-Sep-2003 mickey

some pcxl2 do not report fpus -- assume it's there


Revision tags: OPENBSD_3_4_BASE
# 1.113 04-Sep-2003 mickey

a better cpu identification; testing by miod


# 1.112 31-Aug-2003 miod

pdc_model needs to be visible from cpu.c


# 1.111 20-Aug-2003 mickey

missing nl in debugging prontf


# 1.110 07-Aug-2003 mickey

dead proto


# 1.109 07-Aug-2003 mickey

first allocate space on stack then copyout signal shits. add a DEBUG check for a whacky user pc (as impossible due to the recent trap.c change)


# 1.108 03-Aug-2003 mickey

clear branch and nullify bits in psw on sending a signal


# 1.107 30-Jul-2003 mickey

deduce the leds address from the model number and thus make some more use of that lichtenblinkenschmutz on some more machinens


# 1.106 22-May-2003 mickey

imprecision in delay_init()


# 1.105 18-May-2003 mickey

save the fpu state for the signal handler. this is essential
as the fpu regs can be used by the gcc even for non-fpu
means and data copying.
rearrange the sigcontext a bit to include only the general
registers that are needed restoring upon return and thus
less waste of space and make up some space for the fpu regs.

ALL software that used the signal context on the stack
needs at least rebuilding now. a new snap has bin built as well.


Revision tags: UBC_SYNC_A
# 1.104 11-May-2003 deraadt

string cleaning; krw ok


# 1.103 07-Apr-2003 mickey

s/HP9000/HP 9000/; from weissmanndude


Revision tags: OPENBSD_3_3_BASE
# 1.102 18-Feb-2003 deraadt

knf; mickey ok


# 1.101 12-Feb-2003 jason

How uncommon... hppa only has one common: msgbufmapped (decl'd in /sys/kern)


# 1.100 12-Feb-2003 mickey

only align the first stack frame onto the minimal required alignment


# 1.99 10-Feb-2003 mickey

fix pcs and pcxt recognition. from weissmanndude


# 1.98 22-Jan-2003 mickey

consistantly use uvm_prot_* vs vm_prot_* evewrhere


# 1.97 14-Jan-2003 mickey

fix cutnpaste in the cpu table for the itlbna field; from herr weissmanndude


# 1.96 14-Jan-2003 mickey

need pdc_hwtlb always; pt out by herr weissmanndude


# 1.95 13-Jan-2003 mickey

fix the logic in hvt probing


# 1.94 09-Jan-2003 miod

Remove fetch(9) and store(9) functions from the kernel, and replace the few
remaining instances of them with appropriate copy(9) usage.

ok art@, tested on all arches unless my memory is non-ECC


# 1.93 19-Dec-2002 mickey

setregs: put the whole frame setup into one place


# 1.92 19-Dec-2002 mickey

level 0x16 is really an l2


# 1.91 17-Dec-2002 millert

Make SysV-style shared memory and semaphore limits sysctl'able.
Instead of allocating a static amount of memory for the data
structures via valloc() in allocsys(), allocate things dynamically
using pool(9) when possible and malloc(9) when not. The various
members of struct seminfo and struct shminfo are in kern.seminfo
and kern.shminfo respectively (not all members of kern.seminfo are
changable).

The data structures used still leave something to be desired but
things are not made worse in that respect by this commit.


# 1.90 27-Nov-2002 mickey

no wrapper arounf hardclock(), use CPU_CLOCKUPDATE, real microtime; miod ok


# 1.89 08-Nov-2002 mickey

Don't uvm_useracc the user sigcontext in sys_sigreturn and then access
the user addresses directly from the kernel. copyin is faster and can
correctly deal properly with mappings that uvm_useracc thinks are
correct but will fault anyway (to figure out how to generate such
mappings is left as en excercise for the reader).


# 1.88 01-Nov-2002 mickey

add a missing delay after printf on halt[-p], proper arg for a cold hook


Revision tags: UBC_SYNC_B
# 1.87 22-Oct-2002 mickey

do not force single-user; pt out by fries@


# 1.86 15-Oct-2002 mickey

missing initmsgbuf(), noticed by miod@


# 1.85 13-Oct-2002 mickey

track the end of physmem for use in dmmem_alloc


# 1.84 07-Oct-2002 mickey

s/PSW_/PSL_/ to match other archs


# 1.83 07-Oct-2002 mickey

proper terminate the user stack on signal


# 1.82 07-Oct-2002 mickey

on implementations w/ fpu included unimplemented instructions
are signaled through the exception trap w/ invalid opcode marked
instruction in the exception registers, not through the emulation
trap (as long as the fpu is enabled, of course).
parse emulation from the exception trap as well as the emulation
trap and fix the dispatcher into usable condition.
parse invalid op exception on trap and signal the user appropriately.
reset the exception on exec and for child on fork.
the later is appropriate since exceptions are delayed until next
fpu instruction, which was in the parent indeed, let him get it.
save parent's fpu context on fork before cipying it, if the
parent owned the fpu.


Revision tags: OPENBSD_3_2_BASE
# 1.81 23-Sep-2002 mickey

parisc level 0x10 is just an overclocked 0xe


# 1.80 17-Sep-2002 mickey

handle fpu exceptions properly, might use a regress, i guess


# 1.79 11-Sep-2002 mickey

provide a convinient reset label


# 1.78 11-Sep-2002 mickey

stack grows the other way, but the frame is the other way to that. hehe


# 1.77 09-Sep-2002 mickey

set up the frame flags and a user frame better on exec


# 1.76 03-Aug-2002 mickey

rework boot() w/o a goto


# 1.75 25-Jul-2002 mickey

missing arg in the call to the pdc_call since some old times


# 1.74 25-Jul-2002 mickey

kcopy is a space-to-space copy from kernel space, to guess where, -- to the same kernel space, just error on fault


# 1.73 20-Jul-2002 art

Instead of copying out the signal trampoline on top of the stack, create
an uvm aobj, copy out the signal trampoline into it and share that page
among all processes for the same emulation.

This also requires us to actually be able to tell signal code where the
trampoline is located, so introduce a new field in struct proc - p_sigcode
that is a pointer to sigcode. This allows us to remove all the ugly
calculations of the signal trampoline address done in every sendsig
function in the tree (that's why so many files are changed).

Tested by various people. ok deraadt@


# 1.72 14-May-2002 mickey

disable sid hashing while still in real mode, alos print the parisc arch once and not per each cpu since they are not intermixable architecture-wise


# 1.71 13-May-2002 mickey

ldi-ldo whatever was in the table, be that much clever


# 1.70 08-May-2002 mickey

print parisc level w/ the the parisc version, not for each cpu


# 1.69 08-May-2002 mickey

kill debugging printfski


# 1.68 22-Apr-2002 mickey

no longer batc the data, only the code.
this removes a constraint and an ld.script dependancy
for the .data and the dynamically allocated kernel
structures existed w/ batcing. also makes pmap_steal_memory
obsolete and replaced w/ the pmap_virtual_space.
implement batching for pmap_remove to avoid
zeroing out the pte entries if pde will be removed anyway.


# 1.67 21-Apr-2002 mickey

better buf's mapping and less magic constants in checking for io space cachability


Revision tags: OPENBSD_3_1_BASE
# 1.66 26-Mar-2002 mickey

if cannot guess cpu model default to the lowest supported one


# 1.65 25-Mar-2002 deraadt

spelling


# 1.64 23-Mar-2002 espie

Add variables for config(8) -e time tweak of systemV shared memory
parameters.

Ok millert@, miod@, maja@


# 1.63 19-Mar-2002 mickey

mtcpu seq requires a pre-sync, implement hpt init for pcxl


# 1.62 15-Mar-2002 mickey

rewrite a pmap to use multilevel page tables.
lower 12 bits contain the perms, no unused bits left,
but a couple for off-tlb use (as the ref implemented now).
do not use the hvt, which might get some use later
if proven to speed thigs up, tlb handlers would po
another dozen of insns though, but if that's worth its...
move on the data seg and map kernel text rdonly (idea form fredette),
since all of the page0 mods done before that we are all fine
except for some viper fluff, but later w/ that.
this also picks up a bit more of ddb magic for bpt and ss.
tlb handlers can use a little bit more of attention,
but things, visually, seem to be much faster already, --
sorry, no benchmarks for now.

* effort sponsored in part by the `henry st. old ale house'
* and mr.pete and mr.lee in particular in thier generous entrirety.
* the proj took a little more that 72man*h as it was expected,
* but within murhy's law estimations.


# 1.61 14-Mar-2002 millert

First round of __P removal in sys


# 1.60 20-Feb-2002 mickey

setup power failure handler (for sw-controlled power button), move toc handler


# 1.59 17-Feb-2002 maja

Patch from Daniel Lucq <daniel@lucq.org>

The patch allows you to change the value of NMBCLUSTERS, BUFCACHEPERCENT
and NKMEMPAGES using the config command, instead of recompiling the kernel.

This is the kernel part of the patch. I have compiled it on i386, sparc64,
alpha and macppc. -moj ok art@ maja@


# 1.58 12-Feb-2002 mickey

support 712's programmable power switch, no interrupt yet


# 1.57 12-Feb-2002 mickey

small repairs to hpmc and toc handlers


# 1.56 11-Feb-2002 mickey

disable fpu on csw, print fpu version on cpu line, if present


# 1.55 07-Feb-2002 mickey

fix sigdebug cases; init sigcontext before it's used (;


# 1.54 06-Feb-2002 mickey

implement signal delivery; based on fredette@'s work


# 1.53 03-Feb-2002 mickey

restore hpt size computation, does not break things as i thought


# 1.52 02-Feb-2002 mickey

fix 'physmem' usage


# 1.51 02-Feb-2002 mickey

implement the rest of /dev/mem devices; from netbsd


# 1.50 23-Jan-2002 art

move mb_map allocation to mbinit()


# 1.49 23-Jan-2002 art

move definition of mb_map from zillions of machdep.c to uipc_mbuf.c


# 1.48 16-Jan-2002 miod

Don't include <sys/map.h> when you don't need what's in it.


Revision tags: UBC_BASE
# 1.47 02-Dec-2001 mickey

branches: 1.47.2;
increase fixed extent storage


# 1.46 28-Nov-2001 art

zap some typedefs.
vm_map_t -> struct vm_map *
vm_map_entry_t -> struct vm_map_entry *
simple_lock_data_t -> struct simplelock

(uvm not done yet, coming in the next commit)


# 1.45 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.44 24-Nov-2001 miod

Harmonize boot() logic across arches:
- ensure RB_DUMP | RB_HALT will cause a dump
- or RB_HALT if (cold)
While there, honor RB_TIMEBAD on sparc64.


# 1.43 09-Nov-2001 art

nswbuf hasn't been used for ages. gc.


# 1.42 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.41 06-Nov-2001 miod

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


Revision tags: OPENBSD_3_0_BASE
# 1.40 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.39 12-Sep-2001 art

mbutl no more


# 1.38 23-Aug-2001 art

We can now move timeout_init into main().


# 1.37 23-Aug-2001 art

Remove even more old timeout tentacles.


# 1.36 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.35 05-Jul-2001 art

Get rid of REAL_CLISTS. It was never implemented and the tentacles are
everywhhere.


# 1.34 17-May-2001 provos

convert mbuf and cluster allocation to pool, mostly from NetBSD
okay art@ miod@


# 1.33 05-May-2001 art

Rename configure() to cpu_configure().
Move it from cpu_startup() to main().


# 1.32 05-May-2001 art

Get rid of CLSIZE and all related stuff.
CLSIZE -> 1
CLBYTES -> PAGE_SIZE
OLOFSET -> PAGE_MASK
etc.
At the same time some archs needed some cleaning in vmparam.h so that
goes in at the same time.


Revision tags: OPENBSD_2_9_BASE
# 1.31 29-Mar-2001 mickey

cpudev_data.h here needed not


# 1.30 22-Mar-2001 mickey

shuffle the tlb handlers a little,
make a new one for na data fault,
since those w/ hpt need it.


Revision tags: OPENBSD_2_8_BASE
# 1.29 15-Aug-2000 mickey

two btlb routines (i & d) for pcxs


# 1.28 15-Aug-2000 mickey

expand per-cpu control routines switch


# 1.27 08-Aug-2000 mickey

print btlb params w/ BTLBDEBUG; from Havard.Eidnes@runit.sintef.no


# 1.26 02-Jul-2000 mickey

no bays for stinger


Revision tags: OPENBSD_2_7_BASE
# 1.25 23-Mar-2000 mickey

new cpu type switch code.
initializes tlb miss handlers correspondent to probed cpu features.
also btlb load routine.
versions written are for pcxl and others.
cpu-dep btlb loaders are missing, only generic for now.


# 1.24 23-Mar-2000 art

New API for timeouts. Replaces the old timeout()/untimeout() API and
makes it the callers responsibility to allocate resources for the
timeouts.

This is a KISS implementation and does _not_ solve the problems of slow
handling of a large number of pending timeouts (this will be solved in
future work) (although hardclock is now guarateed to take constant time
for handling of timeouts).

Old timeout() and untimeout() are implemented as wrappers around the new
API and kept for compatibility. They will be removed as soon as all
subsystems are converted to use the new API.


# 1.23 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


# 1.22 22-Feb-2000 mickey

blah, blah, blah, msgbuf


Revision tags: SMP_BASE
# 1.21 09-Feb-2000 mickey

branches: 1.21.2;
heartbeat -- yeah we have a patch for that


# 1.20 25-Jan-2000 mickey

better copy and zero inlines in locore;
proper setregs() in machedep;
start of hpmc handler;
some cleanup here and there;


# 1.19 17-Jan-2000 mickey

remove unneeded stuff from setregs; force single-user for now, enable signal debug


# 1.18 11-Jan-2000 mickey

s/fpu_curproc/fpu_curpcb/ which also points into physical.
move it's definition into locore (where it's used the most).
adjust fpu context switch and save on swapout accordingly.
fix context save (in switch).
add accounting for fpu context switches (since it differes
from proc switching, we might get provided w/ some usefull
numbers as to how effective this lazy switch technique is).
enable handling fpu/sfu exceptions.


# 1.17 31-Dec-1999 mickey

don't bother about pidr3 and pidr4


# 1.16 17-Dec-1999 mickey

fix the panic message for sti memory mapping


Revision tags: kame_19991208
# 1.15 25-Nov-1999 mickey

bus stuff is in mainbus now, the rest is rewritten many ways


Revision tags: OPENBSD_2_6_BASE
# 1.14 20-Sep-1999 mickey

fix uvm_pagealloc() call


# 1.13 03-Sep-1999 art

Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.12 14-Aug-1999 mickey

proper debugging ifdefs


# 1.11 21-Jul-1999 mickey

rewrite the tlb miss handler and tlb dirty handler.
optimize for HVT usage (when compiled for proper cpu type).
drop hpt_* global variables, use info from control registers instead.
there are still ways to improve the tlb handlers tho.
machdep also prints cache and tlb coherence states (not related to the above).
You eat greenish muffin. --More-- You write real code.


# 1.10 12-Jul-1999 mickey

allocate 5% bufcache if <=16M memory installed


# 1.9 12-Jun-1999 mickey

hppa_init() now takes an argument from locore,
meaning the start of available memory.
cleanup machdep somewhat.
fix vm_map.pmap vs vm_pmap isue; 10x art@


# 1.8 23-May-1999 mickey

new swap stuff


# 1.7 21-May-1999 mickey

group all theMD f;ags together, add interrupt recursion one


# 1.6 21-May-1999 mickey

define fpu_curproc


# 1.5 20-Apr-1999 mickey

do lazy blok mapping of io space in bus_*
add copy{in,out}*, kcopy, etc
boot routines
cpu-id-hpux-compat stuff
rest of scheduler and such
uvm


Revision tags: OPENBSD_2_5_BASE
# 1.4 17-Feb-1999 mickey

print pa-risc here as well, since, finally, cpu will have to print processor type


# 1.3 04-Jan-1999 mickey

better cache handling in bus_space_barrier(), seem to work now


# 1.2 03-Jan-1999 mickey

implement bus_space_{un,}map w/ extents


# 1.1 30-Dec-1998 mickey

machdep; more work needed


# 1.261 21-Oct-2020 deraadt

hppa also has a similar to arm64: copyout(9), copyinstr(9) and
copyoutstr(9) should bail out properly if they are called with a
length of 0.
ok kettenis@


Revision tags: OPENBSD_6_8_BASE
# 1.260 14-Jun-2020 naddy

Implement cpu_rnd_messybits() as a read of the cycle counter register.
ok dlg@ deraadt@


# 1.259 31-May-2020 dlg

introduce "cpu_rnd_messybits" for use instead of nanotime in dev/rnd.c.

rnd.c uses nanotime to get access to some bits that change quickly
between events that it can mix into the entropy pool. it doesn't
use nanotime to get a monotonically increasing set or ordered and
accurate timestamps, it just wants something with bits that change.

there's been discussions for years about letting rnd use a clock
that's super fast to read, but not necessarily accurate, but it
wasn't until recently that i figured out it wasn't interested in
time at all, so things like keeping a fast clock coherent between
cpu cores or correct according to ntp is unecessary. this means we
can just let rnd read the cycle counters on cpus and things will
be fine. cpus with cycle counters that vary in their speed and
arent kept consistent between cores may even be desirable in this
context.

so this is the first step in converting rnd.c to reading cycle
counter. it copies the nanotime backend to each arch, and they can
replace it with something MD as a second step later on.

djm@ suggested rnd_messybytes, but we landed on cpu_rnd_messybits.
thanks to visa for his eyes.
ok deraadt@ visa@
deraadt@ says he will help handle any MD fallout that occurs.


# 1.258 16-May-2020 kettenis

Make inittodr() and resettodr() MI.

ok deraadt@, mpi@, visa@
ok cheloha@ as well (would have preferred in new file for this code)


# 1.257 11-May-2020 kettenis

Initialize the timeval passed to todr_gettime() with the base time from
the file system such that implementations can use it to guess the right
century.

ok mpi@


Revision tags: OPENBSD_6_7_BASE
# 1.256 01-May-2020 kettenis

Use the same inittodr()/resettodr() implementation as on
amd64/arm64/armv7/i386/sparc64 and move it to the end of machdep.c. Rework the
actual implementation for the MC14818 compatible RTC into something that can
be used as a todr_handle just like on amd64.

ok mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.255 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


Revision tags: OPENBSD_6_4_BASE
# 1.254 20-Jul-2018 guenther

Missed a 'ksi' -> '*ksip' change in previous commit


# 1.253 10-Jul-2018 guenther

Move from sendsig() to its callers the initsiginfo() calls and
instead of passing sendsig() the code+type+val, pass a siginfo_t*
to copy from. Eliminate the indirection through struct emul for
sendsig(); we no longer have a SunOS4-compat version of sendsig()

ok deraadt@


# 1.252 22-May-2018 guenther

Delete antique sigdebug definitions

ok kettenis@


# 1.251 12-Apr-2018 deraadt

Implement MAP_STACK option for mmap(). Synchronous faults (pagefault and
syscall) confirm the stack register points at MAP_STACK memory, otherwise
SIGSEGV is delivered. sigaltstack() and pthread_attr_setstack() are modified
to create a MAP_STACK sub-region which satisfies alignment requirements.
Observe that MAP_STACK can only be set/cleared by mmap(), which zeroes the
contents of the region -- there is no mprotect() equivalent operation, so
there is no MAP_STACK-adding gadget.
This opportunistic software-emulation of a stack protection bit makes
stack-pivot operations during ROPchain fragile (kind of like removing a
tool from the toolbox).
original discussion with tedu, uvm work by stefan, testing by mortimer
ok kettenis


Revision tags: OPENBSD_6_3_BASE
# 1.250 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.249 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


Revision tags: OPENBSD_6_2_BASE
# 1.248 18-May-2017 kettenis

Implement copyin32(9).

"your chicken scratches look fine to me" deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.247 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

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


# 1.246 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.245 21-May-2016 deraadt

hand-massage sendsig() and sys_sigreturn() to be much more similar.
ok guenther kettenis


# 1.244 10-May-2016 deraadt

SROP mitigation. sendsig() stores a (per-process ^ &sigcontext) cookie
inside the sigcontext. sigreturn(2) checks syscall entry was from the
exact PC addr in the (per-process ASLR) sigtramp, verifies the cookie,
and clears it to prevent sigcontext reuse.
not yet tested on landisk, sparc, *88k, socppc.
ok kettenis


# 1.243 20-Apr-2016 dlg

pool_setipl for floating point context things

ok kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.242 21-Oct-2015 mpi

Do not call uvm_swap_finicrypt_all() a second time in dumpsys().

ok tedu@, deraadt@, miod@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.241 20-Jan-2015 kettenis

Move ps_strings "after" the random stackgap. This makes its location a
per-process value, and therefpore turns the VM_PSSTRINGS sysctl into a
per-process one as well. This gets rid of a pointer to the bottom of the
stack at a fixed location. Also clears the road for unmapping the stackgap.

ok deraadt@


# 1.240 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.239 25-Oct-2014 kettenis

Remove vmmap; it isn't used.

ok jsing@


# 1.238 23-Oct-2014 miod

Correctly set up the HPMC trap entry: according to the PA-RISC Firmware
Architecture Reference Specification, the sum of the 8 trap entry words
*and* of the payload which address and length are to be set at well-known
positions in the aforementioned trap entry, needs to be zero; the existing
code was only enforcing that the sum of the trap entry words is zero.

This matches what Linux and NetBSD do.

ok kettenis@


# 1.237 23-Oct-2014 miod

Revert limiting physmem to 2GB; the culprit was likely in uvm and uvm has
changed a lot in the last 5 years; verified to work on a 3GB system, in
snapshots for a few weeks already.


# 1.236 22-Sep-2014 dlg

implement atomic_{cas,swap}_{uint,ulong,ptr} and
atomic_{add,sub}_{int,long}_nv. sys/atomic.h turns these into the
rest of the atomic api.

on uniprocessor hppa systems "atomic" operations are implemented
as a non-interruptable sequence by disabling all interrupts on the
cpu, doing the operation, and then restoring the interrupt mask.

this isnt enough on MP systems, so we added a global atomic memory
mutex that is taken inside the interrupt disabling above to coordinate
operations between cpus.

this is a lot of overhead though cos mutexes dance around with ipls,
which is unecessary in our case because of the interrupt disabling
that is already done. also, hppa spinlocks are implemented with
ldcw which requires the word it operates on to be 16 byte aligned.
mutexes arent guaranteed to have this alignment so they compensate
by having lots of words inside themselves so they can hit the
appropriate one to use for the ldcw op.

with this in mind, this change pulls __cpu_simple_locks, which are
simply ldcw spinlocks with a 16 byte aligned word, out of
src/sys/arch/hppa/include/lock.h into src/sys/arch/hppa/include/atomic.h
so atomic.h can use them. lock.h includes atomic.h, so it still
gets and provides the same functionality as before.

finally, this also pulls the rwlock cas implementation apart. cas
ops now share the same serialising lock on MP systems as the other
memory operations, and rw_cas is defined as a wrapper around
atomic_cas_uint.

ok kettenis@


# 1.235 19-Sep-2014 kettenis

Use config_suspend_all(9).


# 1.234 18-Aug-2014 dlg

dont rely on mbuf.h to provide pool.h.

ok miod@, who has offerred to help with any MD fallout
ok guenther@


Revision tags: OPENBSD_5_6_BASE
# 1.233 22-Jul-2014 uebayasi

boot(9): Reduce diffs between hppa & hppa64 (& others)


# 1.232 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.231 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.230 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.229 13-Jul-2014 miod

These still need <sys/reboot.h> for the RB_ constants.


# 1.228 12-Jul-2014 uebayasi

reboot(9), panic(9): Call panic(9) for unrecoverable MD H/W errors (NMIs)

Some architectures have ability to detect hardware sanity and notify system
(NMI, firmware callback, etc.). Handle these hardware severe errors, same
as software errors, with panic(9).

According to miod@, SGI IP27 NMI is triggered by pushing some "hidden" button,
which "usual" users/admins don't know. Pushing such a button is "RB_USERREQ"
(human-triggered) in that the button is pushed by a human, but not "RB_USERREQ"
in that no user intervention in system (== no command input) is done. miod@
agreed that changing these from RB_USERREQ to !RB_USERREQ (== panic(9)) is
not a big problem.

OK miod@ kettenis@


# 1.227 12-Jul-2014 uebayasi

boot(9), reboot(9): Migrate MD callers of boot(9) to reboot(9)

I have found that some ports call boot(9) from machine-dependent code to
reboot system. These should be changed to either:

- Sending signal to init(8) to trigger it to shutdown system cleanly, like
acpi(4) does, in cases where found problems don't prevent system from working
immediately, or

- Just doing panic(9) if the situation is severely broken.

For now, just rewrite boot() to reboot(). Actual fixes follow.

Discussed with & OK from kettenis@


# 1.226 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.225 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.224 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.223 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.222 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.221 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.220 08-May-2014 miod

Format string fixes and removal of -Wno-format for hppa kernels.


# 1.219 08-Apr-2014 mpi

Less <uvm/uvm.h>


# 1.218 04-Apr-2014 miod

If the PDC_COPROC call fails, and we are running on a PA 1.1 system, assume
the usual 1.1 coprocessor mask, instead of using zero and having every
userland process dying with signal 4.

The circumstances under which this call fails are unclear and could be
tied to specific PROM version (I have tried overzealous stack alignment and
other tricks, to no avail). Interestingly enough, the 715/75 system which
hits this problem, only triggers it when booting from disk, and never when
booting from network.

This diff is an ugly bandaid until the problem is better understood. Or maybe
it is not worth investigating, seeing that Linux hardcodes the coprocessor
mask and never issues PDC_COPROC calls; I wonder what HP/UX does.

In my tree for over 18 months; "Looks like a nice hack" deraadt@
715/75 system provided by Sebastiaan Indesteege, thanks!


# 1.217 29-Mar-2014 guenther

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

ok dlg@ mpi@ deraadt@


# 1.216 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


# 1.215 22-Mar-2014 guenther

Move p_sigacts from struct proc to struct process.

testing help mpi@


# 1.214 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


Revision tags: OPENBSD_5_5_BASE
# 1.213 23-Nov-2013 uebayasi

Run doshutdownhooks() and config_suspend() even when boot() is called while
cold != 0. Indent and make hppa/hppa64 boot() closer to others.

OK kettenis@


# 1.212 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


Revision tags: OPENBSD_5_4_BASE
# 1.211 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


Revision tags: OPENBSD_5_3_BASE
# 1.210 02-Dec-2012 guenther

Determine whether we're currently on the alternative signal stack
dynamically, by comparing the stack pointer against the altstack
base and size, so that you get the correct answer if you longjmp
out of the signal handler, as tested by regress/sys/kern/stackjmp/.
Also, fix alt stack handling on vax, where it was completely broken.

Testing and corrections by miod@, krw@, tobiasu@, pirofti@


# 1.209 26-Oct-2012 kettenis

Properly clear trap frame in setregs() to avoid leaking registers across exec.

ok jsing@


# 1.208 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.207 07-Oct-2012 kettenis

Align the stack on a 64-byte boundary as required by "The 32-bit PA-RISC
Run-time Architecture Document". GCC relies on this to properly align
stack variables.

ok guenther@, beck@


Revision tags: OPENBSD_5_2_BASE
# 1.206 21-Jun-2012 guenther

__tfork() needs to set the stack address of the new thread in the kernel,
so that it can't get a signal while still running on the parent thread's
stack. Also, pass in sizeof(struct __tfork) to provide forward compat
when more members are added. This is an ABI change, so switch syscall
numbers and bump lib majors this time.

ok deraadt@ matthew@


Revision tags: OPENBSD_5_1_BASE
# 1.205 20-Sep-2011 miod

Clear RB_POWERDOWN early in boot() on systems which can not powerdown and
which firmware does not send spin up commands to the disks, in case the
operator changes his mind and reboots instead of manually powering down
after the system has halted.
ok kettenis@


Revision tags: OPENBSD_5_0_BASE
# 1.204 05-Jul-2011 guenther

Recommit the reverted sigacts change now that the NFS use-after-free
problem has been tracked down. This fixes the sharing of the signal
handling state: shared bits go in sigacts, per-rthread bits goes in
struct proc.

ok deraadt@


# 1.203 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.202 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.201 18-Apr-2011 guenther

Revert the sigacts diff: NFS can apparently retain pointers to processes
until they're zombies and then send them signals (for intr mounts). Until
that is untangled, the sigacts change is unsafe. sthen@ was the victim
for this one


# 1.200 15-Apr-2011 guenther

Correct the sharing of the signal handling state: stuff that should
be shared (p_sigignore, p_sigcatch, P_NOCLDSTOP, P_NOCLDWAIT) moves
to struct sigacts, wihle stuff that should be per rthread (ps_oldmask,
SAS_OLDMASK, ps_sigstk) moves to struct proc. Treat the coredumping
state bits (ps_sig, ps_code, ps_type, ps_sigval) as per-rthread
until our locking around coredumping is better.

Oh, and remove the old SunOS-compat ps_usertramp member.

"I like the sound of this" tedu@


Revision tags: OPENBSD_4_9_BASE
# 1.199 14-Jan-2011 jsing

Halt secondary CPUs when shutting down or rebooting. This should prevent
occasional hangs during reboot.

ok kettenis@


# 1.198 04-Jan-2011 jasper

- de-register. no binary change.

ok jsing@


# 1.197 01-Jan-2011 jasper

Move setting cpu_hzticks to the clock initialization function, like
other ports (e.g. hppa64) do.

ok jsing@ kettenis@


# 1.196 01-Jan-2011 jasper

- ansify

ok jsing@ kettenis@


# 1.195 30-Dec-2010 jsing

Turn signotify() into a function that also calls cpu_unidle().

ok kettenis@


# 1.194 20-Nov-2010 miod

This is a first step towards getting rid of avail_start and avail_end in the
kernel, currently limited to low-hanging fruit: these variables were used
by bus_dma to specify the range in which to allocate memory, back when
uvm_pglistalloc() was stupid and would not walk the vm_physseg[].

Nowadays, except on some platforms for early initialization, these variables
are not used, or do not need to be global variables. Therefore:
- remove `extern' declarations of avail_start and avail_end (or close cousins,
such as arm physical_start and physical_end) from files which no longer need
to use them.
- make them local variables whenever possible.
- remove them when they are assigned to but no longer used.


Revision tags: OPENBSD_4_8_BASE
# 1.193 01-Jul-2010 jsing

Create a struct to store FP state and include a pointer to the CPU that
currently holds the FPU context for this process. This will be soon used
to implement FPU shootdowns on multiprocessor kernels.

ok kettenis@


# 1.192 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.191 29-Jun-2010 jsing

Factor out code used to save and flushe process FPU context.

ok kettenis@


# 1.190 29-Jun-2010 jsing

Store pointer to process FPU state in struct cpu_info.

ok kettenis@


# 1.189 27-Jun-2010 thib

uvm constraints. Add two mandatory MD symbols, uvm_md_constraints
which contains the constraints for DMA/memory allocation for each
architecture, and dma_constraints which contains the range of addresses
that are dma accessable by the system.

This is based on ariane@'s physcontig diff, with lots of bugfixes and
additions the following additions by my self:

Introduce a new function pool_set_constraints() which sets the address
range for which we allocate pages for the pool from, this is now used
for the mbuf/mbuf cluster pools to keep them dma accessible.

The !direct archs no longer stuff pages into the kernel object in
uvm_km_getpage_pla but rather do a pmap_extract() in uvm_km_putpages.

Tested heavily by my self on i386, amd64 and sparc64. Some tests on
alpha and SGI.

"commit it" beck, art, oga, deraadt
"i like the diff" deraadt


# 1.188 27-Jun-2010 jsing

Use a mutex to make atomic operations atomic on multiprocessor kernels.

ok kettenis@


# 1.187 10-Jun-2010 deraadt

Declare safepri at the MD level on each platform, so that the kern_synch.c
does not have to deal with it as a common. Some platforms may be missed
by this commit... if you spot one, fix it the same way.
ok miod


# 1.186 09-Jun-2010 miod

Move declaration of cn_tab from dev/cons.c to dev/cninit.c, or appropriate
md files for ports which do not use dev/cninit.c. This gets rid of a common
at kernel link time.
feedback drahn@ ok deraadt@


# 1.185 24-May-2010 deraadt

Add missing prototypes
ok jsing kettenis


# 1.184 09-May-2010 kettenis

Prevent "taken branch" exceptions from kernel space by clearing the PSL_T
bit before we enter a signal handler.

"if you say so" miod@, "seems to make sense" jsing@


# 1.183 02-May-2010 kettenis

Properly initialize the members of `struct mdproc' that deal with
single-stepping when we fork and reset them upon exec.

ok miod@


# 1.182 27-Apr-2010 kettenis

Avoid null-pointer dereference by giving proc0 a place to store its
floating-point registers. Pointed out by Nick Hudson.

ok miod@, jsing@


# 1.181 19-Apr-2010 jsing

Make the Processor Status Word (PSW) a per-CPU value.

ok kettenis@


# 1.180 01-Apr-2010 jsing

Allow for multiple CPUs by moving to an array of cpu_info.

ok kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.179 31-Dec-2009 jsing

Make cpl and cpu_inintr per CPU variables. For locore.S, cpl becomes an
offset within cpu_primary_info - this will need to be revisited shortly.

ok kettenis@


# 1.178 11-Aug-2009 miod

Do not bother initializing bufpages in the md code if the computation is
exactly the same the mi could will use if bufinit() is invoked with
bufpages == 0.


# 1.177 11-Aug-2009 miod

With the SysV memory allocation changes, allocsys() doesn't do anything
anymore. Get rid of it completely.


# 1.176 09-Aug-2009 blambert

Rototill system V message queues.

No longer allocate a static amount of memory for messages in MD
boot path; message queues, message metadata, and message data now
all use dynamic memory, which means that runtime sysctls should now
be trivial to implement.

Since I'm going to be around all week to fix any breakage, this should
probably just go in now.


# 1.175 02-Aug-2009 beck

Dynamic buffer cache support - a re-commit of what was backed out
after c2k9

allows buffer cache to be extended and grow/shrink dynamically

tested by many, ok oga@, "why not just commit it" deraadt@


# 1.174 29-Jul-2009 kettenis

Get rid of non-equivalent aliases of the pcb by moving the fpu state out
of the pcb and using the p_addr member of 'struct proc' to calculate the
address of the kernel stack when switching to virtual mode after taking a trap.
Remove the now unecessary cache flushes; they're actually harmful since they
create non-equivalent aliases. This seems to fix the memory corruption we
have been observing from time to time.

This diff does not rename fpu_curpcb, which is now somewhat incorrectly named.
I hope to change things back again as soon as we are able to map the pcb 1:1.


Revision tags: OPENBSD_4_6_BASE
# 1.173 15-Jun-2009 beck

Back out all the buffer cache changes I committed during c2k9. This reverts three
commits:

1) The sysctl allowing bufcachepercent to be changed at boot time.
2) The change moving the buffer cache hash chains to a red-black tree
3) The dynamic buffer cache (Which depended on the earlier too).

ok on the backout from marco and todd


# 1.172 03-Jun-2009 beck

add kern.bufcachepercent sysctl to allow adjusting the buffer cache
size on a running system.
ok art@, oga@


Revision tags: OPENBSD_4_5_BASE
# 1.171 14-Feb-2009 kettenis

Limit the amount of physical memory to 2GB. Using more causes memory
corruption on PA-RISC 2.0 systems (and there are very few PA-RISC 1.1
systems that support more than 2GB).

ok miod@


# 1.170 04-Feb-2009 miod

On systems with split BTLB, do not bother trying to insert DBTLB entries,
as PDC will lie to us pretending it did while it didn't.

ok kettenis@


# 1.169 04-Feb-2009 miod

Unify memory size reports a bit more: always report size in MB, and report
reserved memory on alpha and hppa on its own line (as done on sgi).


Revision tags: OPENBSD_4_4_BASE
# 1.168 14-Jul-2008 miod

Be sure to propagate PSL_O in psw on PCXU* processors to userland processes
and signal handlers.
ok kettenis@


# 1.167 27-Jun-2008 miod

Clear swap encryption keys before dumping a kernel image.


# 1.166 09-Apr-2008 deraadt

Add new stub uvm_shutdown() and call it from the right place in MD boot()


Revision tags: OPENBSD_4_3_BASE
# 1.165 22-Sep-2007 martin

replace even more ctob and btoc with ptoa and atop respectively plus
uvm_extern.h where needed


Revision tags: OPENBSD_4_2_BASE
# 1.164 22-Jul-2007 kettenis

Move hppa to __HAVE_TIMECOUNTERS.


# 1.163 20-Jul-2007 kettenis

Give hppa the blink_led API from sparc64, and the associated machdep.led_blink
sysctl.


# 1.162 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.161 14-Jul-2007 kettenis

Make sigreturn(2) set the proper space ID for the instruction queue. Fixes
a few more pthreads regression tests.

ok miod@


# 1.160 10-Jul-2007 kettenis

Don't trust the privilige level in the sigcontext passed to sigreturn(2).

ok miod@


# 1.159 24-Jun-2007 kettenis

Crank initial storage for extents a bit. We really should allocate extents
using malloc once vm is initialised, but this will do for now.

ok deraadt@


# 1.158 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.157 27-May-2007 miod

Make sure the minaddr hint for uvm_km_suballoc() calls is always initialized.
ok pedro@


# 1.156 26-May-2007 pedro

Dynamic buffer cache. Initial diff from mickey@, okay art@ beck@ toby@
deraadt@ dlg@.


# 1.155 21-May-2007 kettenis

Add support for 8700/pcxw2 cpu.


# 1.154 21-May-2007 kettenis

Ask firmware for reset before trying ourselves; needed for four-digit b/c/j
workstations.

tested by otto@, krw@; ok deraadt@


# 1.153 17-May-2007 art

Limit hppa buffer cache to 30%. It used to be 70% because stack garbage
that was used for minaddr instead of the proper vm_map_min(kernel_map)
(fixed in this diff).

From mickey. art@ ok


# 1.152 14-May-2007 martin

move hppa to __HAVE_CPUINFO

input from miod@, ok kettenis@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.151 28-May-2006 martin

minor nit, use CPU ID instead of FPU ID for BTLB parameters after passing
all kludges


# 1.150 15-Apr-2006 martin

make warning about missing HPT support DEBUG for now

ok mickey@


Revision tags: OPENBSD_3_9_BASE
# 1.149 26-Oct-2005 martin

no more hppa_round_page() and hppa_trunc_page() macros

ok mickey@


Revision tags: OPENBSD_3_8_BASE
# 1.148 06-Aug-2005 miod

We do not need a char machine_arch[] constant.
ok deraadt@


# 1.147 11-Jul-2005 mickey

align some stupid comments


# 1.146 10-May-2005 mickey

set pcsq in case we get signal delivery once interrupted from the gateway page; from chs


# 1.145 18-Apr-2005 mickey

do not do some of the initmsgbuf()s job


# 1.144 07-Apr-2005 mickey

on some machines it's possible to limit the amount of physmem initialised dring post so having msgbuf at the end of memory shall work


# 1.143 07-Apr-2005 mickey

64bit-friendly pdc.h and iomod.h and correspondent changes elsewhere


# 1.142 26-Mar-2005 mickey

md parts for hpux_compa code; some problems w/ signals delivery still exist


Revision tags: OPENBSD_3_7_BASE
# 1.141 24-Feb-2005 mickey

do not even ask for btlb on 8k cpus as pdc pretends there is some but then it does not work; found w/ Moritz Kiese <mbk@mytum.de> on c180; add a debug print and fix pcxu entry


# 1.140 17-Nov-2004 mickey

print real/avail/bufcache sizes as unsigned


# 1.139 26-Oct-2004 mickey

disable sid hashing on pcxu and above


# 1.138 14-Oct-2004 mickey

a bit larger delays during boot() to let msgs appear


# 1.137 19-Sep-2004 mickey

turn totalphysmem into physmem and name old physmem into smth it really is


# 1.136 18-Sep-2004 mickey

oops


# 1.135 15-Sep-2004 mickey

add pcxu tlb handlers and cpu probing
add u2/uturn ioa driver in dumb mode now
enable pcxu/pcxw support


# 1.134 14-Sep-2004 mickey

store fpu version for later use. make sure to proper store/clear fpu state in fork/exec/exit/sendsig


# 1.133 14-Sep-2004 mickey

error out from btlb_insert() if there is none


Revision tags: OPENBSD_3_6_BASE
# 1.132 01-Jul-2004 mickey

have separate insn and data cache all-flushers


# 1.131 30-Jun-2004 mickey

allow forced fpu emulation through a sysctl


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.130 13-May-2004 mickey

8ks do not have hvt


# 1.129 05-May-2004 mickey

much easier tlb handler branch patching


# 1.128 05-May-2004 mickey

do not engage HPT on PCXT' (yet)


# 1.127 08-Apr-2004 mickey

repair pcxs/t confoosion


# 1.126 07-Apr-2004 mickey

update copyright; miod@ is fine w/ files where he holds it too


Revision tags: OPENBSD_3_5_BASE
# 1.125 10-Mar-2004 tom

Ensure that we obey a user's ddb> boot reboot command even if the system
is cold (during startup).

This adds RB_USERREQ to sys/reboot.h, uses it in the ddb commands, and
ensures that */*/machdep.c:boot() won't set RB_HALT when cold if this
flag is set.

ok deraadt@


# 1.124 14-Feb-2004 grange

Simplify hw.{cpuspeed,setperf} api moving all the sysctl stuff
from the underlying callbacks.

Testing hppa mickey@, ppc drahn@
Ok markus@ tedu@


# 1.123 05-Jan-2004 mickey

kill debugging code that is not needed anymore


# 1.122 23-Dec-2003 mickey

provide cpuspeed fluff


# 1.121 20-Dec-2003 miod

Don't let microtime() return a struct timeval with exactly 1000000 microseconds.


# 1.120 18-Dec-2003 mickey

spls do not protect cpu_itmr and thus time might jump back sometimes due to cpu_itmr modified to a higher value than a read itmr; found and testing by miod@


# 1.119 17-Dec-2003 mickey

in the real mem print do not include reserved for prom into used by openbsd


# 1.118 10-Dec-2003 mickey

for unaligned btlb mapping attempts -- just fail


# 1.117 24-Nov-2003 mickey

experimental support for HVT as a 2nd level tlb


# 1.116 15-Oct-2003 mickey

less global name space pollution


# 1.115 05-Oct-2003 mickey

reload the itmr as soon as we get the intr to avoid lagging on slower machines


# 1.114 25-Sep-2003 mickey

some pcxl2 do not report fpus -- assume it's there


Revision tags: OPENBSD_3_4_BASE
# 1.113 04-Sep-2003 mickey

a better cpu identification; testing by miod


# 1.112 31-Aug-2003 miod

pdc_model needs to be visible from cpu.c


# 1.111 20-Aug-2003 mickey

missing nl in debugging prontf


# 1.110 07-Aug-2003 mickey

dead proto


# 1.109 07-Aug-2003 mickey

first allocate space on stack then copyout signal shits. add a DEBUG check for a whacky user pc (as impossible due to the recent trap.c change)


# 1.108 03-Aug-2003 mickey

clear branch and nullify bits in psw on sending a signal


# 1.107 30-Jul-2003 mickey

deduce the leds address from the model number and thus make some more use of that lichtenblinkenschmutz on some more machinens


# 1.106 22-May-2003 mickey

imprecision in delay_init()


# 1.105 18-May-2003 mickey

save the fpu state for the signal handler. this is essential
as the fpu regs can be used by the gcc even for non-fpu
means and data copying.
rearrange the sigcontext a bit to include only the general
registers that are needed restoring upon return and thus
less waste of space and make up some space for the fpu regs.

ALL software that used the signal context on the stack
needs at least rebuilding now. a new snap has bin built as well.


Revision tags: UBC_SYNC_A
# 1.104 11-May-2003 deraadt

string cleaning; krw ok


# 1.103 07-Apr-2003 mickey

s/HP9000/HP 9000/; from weissmanndude


Revision tags: OPENBSD_3_3_BASE
# 1.102 18-Feb-2003 deraadt

knf; mickey ok


# 1.101 12-Feb-2003 jason

How uncommon... hppa only has one common: msgbufmapped (decl'd in /sys/kern)


# 1.100 12-Feb-2003 mickey

only align the first stack frame onto the minimal required alignment


# 1.99 10-Feb-2003 mickey

fix pcs and pcxt recognition. from weissmanndude


# 1.98 22-Jan-2003 mickey

consistantly use uvm_prot_* vs vm_prot_* evewrhere


# 1.97 14-Jan-2003 mickey

fix cutnpaste in the cpu table for the itlbna field; from herr weissmanndude


# 1.96 14-Jan-2003 mickey

need pdc_hwtlb always; pt out by herr weissmanndude


# 1.95 13-Jan-2003 mickey

fix the logic in hvt probing


# 1.94 09-Jan-2003 miod

Remove fetch(9) and store(9) functions from the kernel, and replace the few
remaining instances of them with appropriate copy(9) usage.

ok art@, tested on all arches unless my memory is non-ECC


# 1.93 19-Dec-2002 mickey

setregs: put the whole frame setup into one place


# 1.92 19-Dec-2002 mickey

level 0x16 is really an l2


# 1.91 17-Dec-2002 millert

Make SysV-style shared memory and semaphore limits sysctl'able.
Instead of allocating a static amount of memory for the data
structures via valloc() in allocsys(), allocate things dynamically
using pool(9) when possible and malloc(9) when not. The various
members of struct seminfo and struct shminfo are in kern.seminfo
and kern.shminfo respectively (not all members of kern.seminfo are
changable).

The data structures used still leave something to be desired but
things are not made worse in that respect by this commit.


# 1.90 27-Nov-2002 mickey

no wrapper arounf hardclock(), use CPU_CLOCKUPDATE, real microtime; miod ok


# 1.89 08-Nov-2002 mickey

Don't uvm_useracc the user sigcontext in sys_sigreturn and then access
the user addresses directly from the kernel. copyin is faster and can
correctly deal properly with mappings that uvm_useracc thinks are
correct but will fault anyway (to figure out how to generate such
mappings is left as en excercise for the reader).


# 1.88 01-Nov-2002 mickey

add a missing delay after printf on halt[-p], proper arg for a cold hook


Revision tags: UBC_SYNC_B
# 1.87 22-Oct-2002 mickey

do not force single-user; pt out by fries@


# 1.86 15-Oct-2002 mickey

missing initmsgbuf(), noticed by miod@


# 1.85 13-Oct-2002 mickey

track the end of physmem for use in dmmem_alloc


# 1.84 07-Oct-2002 mickey

s/PSW_/PSL_/ to match other archs


# 1.83 07-Oct-2002 mickey

proper terminate the user stack on signal


# 1.82 07-Oct-2002 mickey

on implementations w/ fpu included unimplemented instructions
are signaled through the exception trap w/ invalid opcode marked
instruction in the exception registers, not through the emulation
trap (as long as the fpu is enabled, of course).
parse emulation from the exception trap as well as the emulation
trap and fix the dispatcher into usable condition.
parse invalid op exception on trap and signal the user appropriately.
reset the exception on exec and for child on fork.
the later is appropriate since exceptions are delayed until next
fpu instruction, which was in the parent indeed, let him get it.
save parent's fpu context on fork before cipying it, if the
parent owned the fpu.


Revision tags: OPENBSD_3_2_BASE
# 1.81 23-Sep-2002 mickey

parisc level 0x10 is just an overclocked 0xe


# 1.80 17-Sep-2002 mickey

handle fpu exceptions properly, might use a regress, i guess


# 1.79 11-Sep-2002 mickey

provide a convinient reset label


# 1.78 11-Sep-2002 mickey

stack grows the other way, but the frame is the other way to that. hehe


# 1.77 09-Sep-2002 mickey

set up the frame flags and a user frame better on exec


# 1.76 03-Aug-2002 mickey

rework boot() w/o a goto


# 1.75 25-Jul-2002 mickey

missing arg in the call to the pdc_call since some old times


# 1.74 25-Jul-2002 mickey

kcopy is a space-to-space copy from kernel space, to guess where, -- to the same kernel space, just error on fault


# 1.73 20-Jul-2002 art

Instead of copying out the signal trampoline on top of the stack, create
an uvm aobj, copy out the signal trampoline into it and share that page
among all processes for the same emulation.

This also requires us to actually be able to tell signal code where the
trampoline is located, so introduce a new field in struct proc - p_sigcode
that is a pointer to sigcode. This allows us to remove all the ugly
calculations of the signal trampoline address done in every sendsig
function in the tree (that's why so many files are changed).

Tested by various people. ok deraadt@


# 1.72 14-May-2002 mickey

disable sid hashing while still in real mode, alos print the parisc arch once and not per each cpu since they are not intermixable architecture-wise


# 1.71 13-May-2002 mickey

ldi-ldo whatever was in the table, be that much clever


# 1.70 08-May-2002 mickey

print parisc level w/ the the parisc version, not for each cpu


# 1.69 08-May-2002 mickey

kill debugging printfski


# 1.68 22-Apr-2002 mickey

no longer batc the data, only the code.
this removes a constraint and an ld.script dependancy
for the .data and the dynamically allocated kernel
structures existed w/ batcing. also makes pmap_steal_memory
obsolete and replaced w/ the pmap_virtual_space.
implement batching for pmap_remove to avoid
zeroing out the pte entries if pde will be removed anyway.


# 1.67 21-Apr-2002 mickey

better buf's mapping and less magic constants in checking for io space cachability


Revision tags: OPENBSD_3_1_BASE
# 1.66 26-Mar-2002 mickey

if cannot guess cpu model default to the lowest supported one


# 1.65 25-Mar-2002 deraadt

spelling


# 1.64 23-Mar-2002 espie

Add variables for config(8) -e time tweak of systemV shared memory
parameters.

Ok millert@, miod@, maja@


# 1.63 19-Mar-2002 mickey

mtcpu seq requires a pre-sync, implement hpt init for pcxl


# 1.62 15-Mar-2002 mickey

rewrite a pmap to use multilevel page tables.
lower 12 bits contain the perms, no unused bits left,
but a couple for off-tlb use (as the ref implemented now).
do not use the hvt, which might get some use later
if proven to speed thigs up, tlb handlers would po
another dozen of insns though, but if that's worth its...
move on the data seg and map kernel text rdonly (idea form fredette),
since all of the page0 mods done before that we are all fine
except for some viper fluff, but later w/ that.
this also picks up a bit more of ddb magic for bpt and ss.
tlb handlers can use a little bit more of attention,
but things, visually, seem to be much faster already, --
sorry, no benchmarks for now.

* effort sponsored in part by the `henry st. old ale house'
* and mr.pete and mr.lee in particular in thier generous entrirety.
* the proj took a little more that 72man*h as it was expected,
* but within murhy's law estimations.


# 1.61 14-Mar-2002 millert

First round of __P removal in sys


# 1.60 20-Feb-2002 mickey

setup power failure handler (for sw-controlled power button), move toc handler


# 1.59 17-Feb-2002 maja

Patch from Daniel Lucq <daniel@lucq.org>

The patch allows you to change the value of NMBCLUSTERS, BUFCACHEPERCENT
and NKMEMPAGES using the config command, instead of recompiling the kernel.

This is the kernel part of the patch. I have compiled it on i386, sparc64,
alpha and macppc. -moj ok art@ maja@


# 1.58 12-Feb-2002 mickey

support 712's programmable power switch, no interrupt yet


# 1.57 12-Feb-2002 mickey

small repairs to hpmc and toc handlers


# 1.56 11-Feb-2002 mickey

disable fpu on csw, print fpu version on cpu line, if present


# 1.55 07-Feb-2002 mickey

fix sigdebug cases; init sigcontext before it's used (;


# 1.54 06-Feb-2002 mickey

implement signal delivery; based on fredette@'s work


# 1.53 03-Feb-2002 mickey

restore hpt size computation, does not break things as i thought


# 1.52 02-Feb-2002 mickey

fix 'physmem' usage


# 1.51 02-Feb-2002 mickey

implement the rest of /dev/mem devices; from netbsd


# 1.50 23-Jan-2002 art

move mb_map allocation to mbinit()


# 1.49 23-Jan-2002 art

move definition of mb_map from zillions of machdep.c to uipc_mbuf.c


# 1.48 16-Jan-2002 miod

Don't include <sys/map.h> when you don't need what's in it.


Revision tags: UBC_BASE
# 1.47 02-Dec-2001 mickey

branches: 1.47.2;
increase fixed extent storage


# 1.46 28-Nov-2001 art

zap some typedefs.
vm_map_t -> struct vm_map *
vm_map_entry_t -> struct vm_map_entry *
simple_lock_data_t -> struct simplelock

(uvm not done yet, coming in the next commit)


# 1.45 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.44 24-Nov-2001 miod

Harmonize boot() logic across arches:
- ensure RB_DUMP | RB_HALT will cause a dump
- or RB_HALT if (cold)
While there, honor RB_TIMEBAD on sparc64.


# 1.43 09-Nov-2001 art

nswbuf hasn't been used for ages. gc.


# 1.42 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.41 06-Nov-2001 miod

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


Revision tags: OPENBSD_3_0_BASE
# 1.40 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.39 12-Sep-2001 art

mbutl no more


# 1.38 23-Aug-2001 art

We can now move timeout_init into main().


# 1.37 23-Aug-2001 art

Remove even more old timeout tentacles.


# 1.36 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.35 05-Jul-2001 art

Get rid of REAL_CLISTS. It was never implemented and the tentacles are
everywhhere.


# 1.34 17-May-2001 provos

convert mbuf and cluster allocation to pool, mostly from NetBSD
okay art@ miod@


# 1.33 05-May-2001 art

Rename configure() to cpu_configure().
Move it from cpu_startup() to main().


# 1.32 05-May-2001 art

Get rid of CLSIZE and all related stuff.
CLSIZE -> 1
CLBYTES -> PAGE_SIZE
OLOFSET -> PAGE_MASK
etc.
At the same time some archs needed some cleaning in vmparam.h so that
goes in at the same time.


Revision tags: OPENBSD_2_9_BASE
# 1.31 29-Mar-2001 mickey

cpudev_data.h here needed not


# 1.30 22-Mar-2001 mickey

shuffle the tlb handlers a little,
make a new one for na data fault,
since those w/ hpt need it.


Revision tags: OPENBSD_2_8_BASE
# 1.29 15-Aug-2000 mickey

two btlb routines (i & d) for pcxs


# 1.28 15-Aug-2000 mickey

expand per-cpu control routines switch


# 1.27 08-Aug-2000 mickey

print btlb params w/ BTLBDEBUG; from Havard.Eidnes@runit.sintef.no


# 1.26 02-Jul-2000 mickey

no bays for stinger


Revision tags: OPENBSD_2_7_BASE
# 1.25 23-Mar-2000 mickey

new cpu type switch code.
initializes tlb miss handlers correspondent to probed cpu features.
also btlb load routine.
versions written are for pcxl and others.
cpu-dep btlb loaders are missing, only generic for now.


# 1.24 23-Mar-2000 art

New API for timeouts. Replaces the old timeout()/untimeout() API and
makes it the callers responsibility to allocate resources for the
timeouts.

This is a KISS implementation and does _not_ solve the problems of slow
handling of a large number of pending timeouts (this will be solved in
future work) (although hardclock is now guarateed to take constant time
for handling of timeouts).

Old timeout() and untimeout() are implemented as wrappers around the new
API and kept for compatibility. They will be removed as soon as all
subsystems are converted to use the new API.


# 1.23 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


# 1.22 22-Feb-2000 mickey

blah, blah, blah, msgbuf


Revision tags: SMP_BASE
# 1.21 09-Feb-2000 mickey

branches: 1.21.2;
heartbeat -- yeah we have a patch for that


# 1.20 25-Jan-2000 mickey

better copy and zero inlines in locore;
proper setregs() in machedep;
start of hpmc handler;
some cleanup here and there;


# 1.19 17-Jan-2000 mickey

remove unneeded stuff from setregs; force single-user for now, enable signal debug


# 1.18 11-Jan-2000 mickey

s/fpu_curproc/fpu_curpcb/ which also points into physical.
move it's definition into locore (where it's used the most).
adjust fpu context switch and save on swapout accordingly.
fix context save (in switch).
add accounting for fpu context switches (since it differes
from proc switching, we might get provided w/ some usefull
numbers as to how effective this lazy switch technique is).
enable handling fpu/sfu exceptions.


# 1.17 31-Dec-1999 mickey

don't bother about pidr3 and pidr4


# 1.16 17-Dec-1999 mickey

fix the panic message for sti memory mapping


Revision tags: kame_19991208
# 1.15 25-Nov-1999 mickey

bus stuff is in mainbus now, the rest is rewritten many ways


Revision tags: OPENBSD_2_6_BASE
# 1.14 20-Sep-1999 mickey

fix uvm_pagealloc() call


# 1.13 03-Sep-1999 art

Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.12 14-Aug-1999 mickey

proper debugging ifdefs


# 1.11 21-Jul-1999 mickey

rewrite the tlb miss handler and tlb dirty handler.
optimize for HVT usage (when compiled for proper cpu type).
drop hpt_* global variables, use info from control registers instead.
there are still ways to improve the tlb handlers tho.
machdep also prints cache and tlb coherence states (not related to the above).
You eat greenish muffin. --More-- You write real code.


# 1.10 12-Jul-1999 mickey

allocate 5% bufcache if <=16M memory installed


# 1.9 12-Jun-1999 mickey

hppa_init() now takes an argument from locore,
meaning the start of available memory.
cleanup machdep somewhat.
fix vm_map.pmap vs vm_pmap isue; 10x art@


# 1.8 23-May-1999 mickey

new swap stuff


# 1.7 21-May-1999 mickey

group all theMD f;ags together, add interrupt recursion one


# 1.6 21-May-1999 mickey

define fpu_curproc


# 1.5 20-Apr-1999 mickey

do lazy blok mapping of io space in bus_*
add copy{in,out}*, kcopy, etc
boot routines
cpu-id-hpux-compat stuff
rest of scheduler and such
uvm


Revision tags: OPENBSD_2_5_BASE
# 1.4 17-Feb-1999 mickey

print pa-risc here as well, since, finally, cpu will have to print processor type


# 1.3 04-Jan-1999 mickey

better cache handling in bus_space_barrier(), seem to work now


# 1.2 03-Jan-1999 mickey

implement bus_space_{un,}map w/ extents


# 1.1 30-Dec-1998 mickey

machdep; more work needed


# 1.260 14-Jun-2020 naddy

Implement cpu_rnd_messybits() as a read of the cycle counter register.
ok dlg@ deraadt@


# 1.259 31-May-2020 dlg

introduce "cpu_rnd_messybits" for use instead of nanotime in dev/rnd.c.

rnd.c uses nanotime to get access to some bits that change quickly
between events that it can mix into the entropy pool. it doesn't
use nanotime to get a monotonically increasing set or ordered and
accurate timestamps, it just wants something with bits that change.

there's been discussions for years about letting rnd use a clock
that's super fast to read, but not necessarily accurate, but it
wasn't until recently that i figured out it wasn't interested in
time at all, so things like keeping a fast clock coherent between
cpu cores or correct according to ntp is unecessary. this means we
can just let rnd read the cycle counters on cpus and things will
be fine. cpus with cycle counters that vary in their speed and
arent kept consistent between cores may even be desirable in this
context.

so this is the first step in converting rnd.c to reading cycle
counter. it copies the nanotime backend to each arch, and they can
replace it with something MD as a second step later on.

djm@ suggested rnd_messybytes, but we landed on cpu_rnd_messybits.
thanks to visa for his eyes.
ok deraadt@ visa@
deraadt@ says he will help handle any MD fallout that occurs.


# 1.258 16-May-2020 kettenis

Make inittodr() and resettodr() MI.

ok deraadt@, mpi@, visa@
ok cheloha@ as well (would have preferred in new file for this code)


# 1.257 11-May-2020 kettenis

Initialize the timeval passed to todr_gettime() with the base time from
the file system such that implementations can use it to guess the right
century.

ok mpi@


Revision tags: OPENBSD_6_7_BASE
# 1.256 01-May-2020 kettenis

Use the same inittodr()/resettodr() implementation as on
amd64/arm64/armv7/i386/sparc64 and move it to the end of machdep.c. Rework the
actual implementation for the MC14818 compatible RTC into something that can
be used as a todr_handle just like on amd64.

ok mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.255 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


Revision tags: OPENBSD_6_4_BASE
# 1.254 20-Jul-2018 guenther

Missed a 'ksi' -> '*ksip' change in previous commit


# 1.253 10-Jul-2018 guenther

Move from sendsig() to its callers the initsiginfo() calls and
instead of passing sendsig() the code+type+val, pass a siginfo_t*
to copy from. Eliminate the indirection through struct emul for
sendsig(); we no longer have a SunOS4-compat version of sendsig()

ok deraadt@


# 1.252 22-May-2018 guenther

Delete antique sigdebug definitions

ok kettenis@


# 1.251 12-Apr-2018 deraadt

Implement MAP_STACK option for mmap(). Synchronous faults (pagefault and
syscall) confirm the stack register points at MAP_STACK memory, otherwise
SIGSEGV is delivered. sigaltstack() and pthread_attr_setstack() are modified
to create a MAP_STACK sub-region which satisfies alignment requirements.
Observe that MAP_STACK can only be set/cleared by mmap(), which zeroes the
contents of the region -- there is no mprotect() equivalent operation, so
there is no MAP_STACK-adding gadget.
This opportunistic software-emulation of a stack protection bit makes
stack-pivot operations during ROPchain fragile (kind of like removing a
tool from the toolbox).
original discussion with tedu, uvm work by stefan, testing by mortimer
ok kettenis


Revision tags: OPENBSD_6_3_BASE
# 1.250 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.249 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


Revision tags: OPENBSD_6_2_BASE
# 1.248 18-May-2017 kettenis

Implement copyin32(9).

"your chicken scratches look fine to me" deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.247 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

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


# 1.246 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.245 21-May-2016 deraadt

hand-massage sendsig() and sys_sigreturn() to be much more similar.
ok guenther kettenis


# 1.244 10-May-2016 deraadt

SROP mitigation. sendsig() stores a (per-process ^ &sigcontext) cookie
inside the sigcontext. sigreturn(2) checks syscall entry was from the
exact PC addr in the (per-process ASLR) sigtramp, verifies the cookie,
and clears it to prevent sigcontext reuse.
not yet tested on landisk, sparc, *88k, socppc.
ok kettenis


# 1.243 20-Apr-2016 dlg

pool_setipl for floating point context things

ok kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.242 21-Oct-2015 mpi

Do not call uvm_swap_finicrypt_all() a second time in dumpsys().

ok tedu@, deraadt@, miod@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.241 20-Jan-2015 kettenis

Move ps_strings "after" the random stackgap. This makes its location a
per-process value, and therefpore turns the VM_PSSTRINGS sysctl into a
per-process one as well. This gets rid of a pointer to the bottom of the
stack at a fixed location. Also clears the road for unmapping the stackgap.

ok deraadt@


# 1.240 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.239 25-Oct-2014 kettenis

Remove vmmap; it isn't used.

ok jsing@


# 1.238 23-Oct-2014 miod

Correctly set up the HPMC trap entry: according to the PA-RISC Firmware
Architecture Reference Specification, the sum of the 8 trap entry words
*and* of the payload which address and length are to be set at well-known
positions in the aforementioned trap entry, needs to be zero; the existing
code was only enforcing that the sum of the trap entry words is zero.

This matches what Linux and NetBSD do.

ok kettenis@


# 1.237 23-Oct-2014 miod

Revert limiting physmem to 2GB; the culprit was likely in uvm and uvm has
changed a lot in the last 5 years; verified to work on a 3GB system, in
snapshots for a few weeks already.


# 1.236 22-Sep-2014 dlg

implement atomic_{cas,swap}_{uint,ulong,ptr} and
atomic_{add,sub}_{int,long}_nv. sys/atomic.h turns these into the
rest of the atomic api.

on uniprocessor hppa systems "atomic" operations are implemented
as a non-interruptable sequence by disabling all interrupts on the
cpu, doing the operation, and then restoring the interrupt mask.

this isnt enough on MP systems, so we added a global atomic memory
mutex that is taken inside the interrupt disabling above to coordinate
operations between cpus.

this is a lot of overhead though cos mutexes dance around with ipls,
which is unecessary in our case because of the interrupt disabling
that is already done. also, hppa spinlocks are implemented with
ldcw which requires the word it operates on to be 16 byte aligned.
mutexes arent guaranteed to have this alignment so they compensate
by having lots of words inside themselves so they can hit the
appropriate one to use for the ldcw op.

with this in mind, this change pulls __cpu_simple_locks, which are
simply ldcw spinlocks with a 16 byte aligned word, out of
src/sys/arch/hppa/include/lock.h into src/sys/arch/hppa/include/atomic.h
so atomic.h can use them. lock.h includes atomic.h, so it still
gets and provides the same functionality as before.

finally, this also pulls the rwlock cas implementation apart. cas
ops now share the same serialising lock on MP systems as the other
memory operations, and rw_cas is defined as a wrapper around
atomic_cas_uint.

ok kettenis@


# 1.235 19-Sep-2014 kettenis

Use config_suspend_all(9).


# 1.234 18-Aug-2014 dlg

dont rely on mbuf.h to provide pool.h.

ok miod@, who has offerred to help with any MD fallout
ok guenther@


Revision tags: OPENBSD_5_6_BASE
# 1.233 22-Jul-2014 uebayasi

boot(9): Reduce diffs between hppa & hppa64 (& others)


# 1.232 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.231 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.230 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.229 13-Jul-2014 miod

These still need <sys/reboot.h> for the RB_ constants.


# 1.228 12-Jul-2014 uebayasi

reboot(9), panic(9): Call panic(9) for unrecoverable MD H/W errors (NMIs)

Some architectures have ability to detect hardware sanity and notify system
(NMI, firmware callback, etc.). Handle these hardware severe errors, same
as software errors, with panic(9).

According to miod@, SGI IP27 NMI is triggered by pushing some "hidden" button,
which "usual" users/admins don't know. Pushing such a button is "RB_USERREQ"
(human-triggered) in that the button is pushed by a human, but not "RB_USERREQ"
in that no user intervention in system (== no command input) is done. miod@
agreed that changing these from RB_USERREQ to !RB_USERREQ (== panic(9)) is
not a big problem.

OK miod@ kettenis@


# 1.227 12-Jul-2014 uebayasi

boot(9), reboot(9): Migrate MD callers of boot(9) to reboot(9)

I have found that some ports call boot(9) from machine-dependent code to
reboot system. These should be changed to either:

- Sending signal to init(8) to trigger it to shutdown system cleanly, like
acpi(4) does, in cases where found problems don't prevent system from working
immediately, or

- Just doing panic(9) if the situation is severely broken.

For now, just rewrite boot() to reboot(). Actual fixes follow.

Discussed with & OK from kettenis@


# 1.226 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.225 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.224 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.223 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.222 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.221 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.220 08-May-2014 miod

Format string fixes and removal of -Wno-format for hppa kernels.


# 1.219 08-Apr-2014 mpi

Less <uvm/uvm.h>


# 1.218 04-Apr-2014 miod

If the PDC_COPROC call fails, and we are running on a PA 1.1 system, assume
the usual 1.1 coprocessor mask, instead of using zero and having every
userland process dying with signal 4.

The circumstances under which this call fails are unclear and could be
tied to specific PROM version (I have tried overzealous stack alignment and
other tricks, to no avail). Interestingly enough, the 715/75 system which
hits this problem, only triggers it when booting from disk, and never when
booting from network.

This diff is an ugly bandaid until the problem is better understood. Or maybe
it is not worth investigating, seeing that Linux hardcodes the coprocessor
mask and never issues PDC_COPROC calls; I wonder what HP/UX does.

In my tree for over 18 months; "Looks like a nice hack" deraadt@
715/75 system provided by Sebastiaan Indesteege, thanks!


# 1.217 29-Mar-2014 guenther

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

ok dlg@ mpi@ deraadt@


# 1.216 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


# 1.215 22-Mar-2014 guenther

Move p_sigacts from struct proc to struct process.

testing help mpi@


# 1.214 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


Revision tags: OPENBSD_5_5_BASE
# 1.213 23-Nov-2013 uebayasi

Run doshutdownhooks() and config_suspend() even when boot() is called while
cold != 0. Indent and make hppa/hppa64 boot() closer to others.

OK kettenis@


# 1.212 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


Revision tags: OPENBSD_5_4_BASE
# 1.211 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


Revision tags: OPENBSD_5_3_BASE
# 1.210 02-Dec-2012 guenther

Determine whether we're currently on the alternative signal stack
dynamically, by comparing the stack pointer against the altstack
base and size, so that you get the correct answer if you longjmp
out of the signal handler, as tested by regress/sys/kern/stackjmp/.
Also, fix alt stack handling on vax, where it was completely broken.

Testing and corrections by miod@, krw@, tobiasu@, pirofti@


# 1.209 26-Oct-2012 kettenis

Properly clear trap frame in setregs() to avoid leaking registers across exec.

ok jsing@


# 1.208 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.207 07-Oct-2012 kettenis

Align the stack on a 64-byte boundary as required by "The 32-bit PA-RISC
Run-time Architecture Document". GCC relies on this to properly align
stack variables.

ok guenther@, beck@


Revision tags: OPENBSD_5_2_BASE
# 1.206 21-Jun-2012 guenther

__tfork() needs to set the stack address of the new thread in the kernel,
so that it can't get a signal while still running on the parent thread's
stack. Also, pass in sizeof(struct __tfork) to provide forward compat
when more members are added. This is an ABI change, so switch syscall
numbers and bump lib majors this time.

ok deraadt@ matthew@


Revision tags: OPENBSD_5_1_BASE
# 1.205 20-Sep-2011 miod

Clear RB_POWERDOWN early in boot() on systems which can not powerdown and
which firmware does not send spin up commands to the disks, in case the
operator changes his mind and reboots instead of manually powering down
after the system has halted.
ok kettenis@


Revision tags: OPENBSD_5_0_BASE
# 1.204 05-Jul-2011 guenther

Recommit the reverted sigacts change now that the NFS use-after-free
problem has been tracked down. This fixes the sharing of the signal
handling state: shared bits go in sigacts, per-rthread bits goes in
struct proc.

ok deraadt@


# 1.203 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.202 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.201 18-Apr-2011 guenther

Revert the sigacts diff: NFS can apparently retain pointers to processes
until they're zombies and then send them signals (for intr mounts). Until
that is untangled, the sigacts change is unsafe. sthen@ was the victim
for this one


# 1.200 15-Apr-2011 guenther

Correct the sharing of the signal handling state: stuff that should
be shared (p_sigignore, p_sigcatch, P_NOCLDSTOP, P_NOCLDWAIT) moves
to struct sigacts, wihle stuff that should be per rthread (ps_oldmask,
SAS_OLDMASK, ps_sigstk) moves to struct proc. Treat the coredumping
state bits (ps_sig, ps_code, ps_type, ps_sigval) as per-rthread
until our locking around coredumping is better.

Oh, and remove the old SunOS-compat ps_usertramp member.

"I like the sound of this" tedu@


Revision tags: OPENBSD_4_9_BASE
# 1.199 14-Jan-2011 jsing

Halt secondary CPUs when shutting down or rebooting. This should prevent
occasional hangs during reboot.

ok kettenis@


# 1.198 04-Jan-2011 jasper

- de-register. no binary change.

ok jsing@


# 1.197 01-Jan-2011 jasper

Move setting cpu_hzticks to the clock initialization function, like
other ports (e.g. hppa64) do.

ok jsing@ kettenis@


# 1.196 01-Jan-2011 jasper

- ansify

ok jsing@ kettenis@


# 1.195 30-Dec-2010 jsing

Turn signotify() into a function that also calls cpu_unidle().

ok kettenis@


# 1.194 20-Nov-2010 miod

This is a first step towards getting rid of avail_start and avail_end in the
kernel, currently limited to low-hanging fruit: these variables were used
by bus_dma to specify the range in which to allocate memory, back when
uvm_pglistalloc() was stupid and would not walk the vm_physseg[].

Nowadays, except on some platforms for early initialization, these variables
are not used, or do not need to be global variables. Therefore:
- remove `extern' declarations of avail_start and avail_end (or close cousins,
such as arm physical_start and physical_end) from files which no longer need
to use them.
- make them local variables whenever possible.
- remove them when they are assigned to but no longer used.


Revision tags: OPENBSD_4_8_BASE
# 1.193 01-Jul-2010 jsing

Create a struct to store FP state and include a pointer to the CPU that
currently holds the FPU context for this process. This will be soon used
to implement FPU shootdowns on multiprocessor kernels.

ok kettenis@


# 1.192 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.191 29-Jun-2010 jsing

Factor out code used to save and flushe process FPU context.

ok kettenis@


# 1.190 29-Jun-2010 jsing

Store pointer to process FPU state in struct cpu_info.

ok kettenis@


# 1.189 27-Jun-2010 thib

uvm constraints. Add two mandatory MD symbols, uvm_md_constraints
which contains the constraints for DMA/memory allocation for each
architecture, and dma_constraints which contains the range of addresses
that are dma accessable by the system.

This is based on ariane@'s physcontig diff, with lots of bugfixes and
additions the following additions by my self:

Introduce a new function pool_set_constraints() which sets the address
range for which we allocate pages for the pool from, this is now used
for the mbuf/mbuf cluster pools to keep them dma accessible.

The !direct archs no longer stuff pages into the kernel object in
uvm_km_getpage_pla but rather do a pmap_extract() in uvm_km_putpages.

Tested heavily by my self on i386, amd64 and sparc64. Some tests on
alpha and SGI.

"commit it" beck, art, oga, deraadt
"i like the diff" deraadt


# 1.188 27-Jun-2010 jsing

Use a mutex to make atomic operations atomic on multiprocessor kernels.

ok kettenis@


# 1.187 10-Jun-2010 deraadt

Declare safepri at the MD level on each platform, so that the kern_synch.c
does not have to deal with it as a common. Some platforms may be missed
by this commit... if you spot one, fix it the same way.
ok miod


# 1.186 09-Jun-2010 miod

Move declaration of cn_tab from dev/cons.c to dev/cninit.c, or appropriate
md files for ports which do not use dev/cninit.c. This gets rid of a common
at kernel link time.
feedback drahn@ ok deraadt@


# 1.185 24-May-2010 deraadt

Add missing prototypes
ok jsing kettenis


# 1.184 09-May-2010 kettenis

Prevent "taken branch" exceptions from kernel space by clearing the PSL_T
bit before we enter a signal handler.

"if you say so" miod@, "seems to make sense" jsing@


# 1.183 02-May-2010 kettenis

Properly initialize the members of `struct mdproc' that deal with
single-stepping when we fork and reset them upon exec.

ok miod@


# 1.182 27-Apr-2010 kettenis

Avoid null-pointer dereference by giving proc0 a place to store its
floating-point registers. Pointed out by Nick Hudson.

ok miod@, jsing@


# 1.181 19-Apr-2010 jsing

Make the Processor Status Word (PSW) a per-CPU value.

ok kettenis@


# 1.180 01-Apr-2010 jsing

Allow for multiple CPUs by moving to an array of cpu_info.

ok kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.179 31-Dec-2009 jsing

Make cpl and cpu_inintr per CPU variables. For locore.S, cpl becomes an
offset within cpu_primary_info - this will need to be revisited shortly.

ok kettenis@


# 1.178 11-Aug-2009 miod

Do not bother initializing bufpages in the md code if the computation is
exactly the same the mi could will use if bufinit() is invoked with
bufpages == 0.


# 1.177 11-Aug-2009 miod

With the SysV memory allocation changes, allocsys() doesn't do anything
anymore. Get rid of it completely.


# 1.176 09-Aug-2009 blambert

Rototill system V message queues.

No longer allocate a static amount of memory for messages in MD
boot path; message queues, message metadata, and message data now
all use dynamic memory, which means that runtime sysctls should now
be trivial to implement.

Since I'm going to be around all week to fix any breakage, this should
probably just go in now.


# 1.175 02-Aug-2009 beck

Dynamic buffer cache support - a re-commit of what was backed out
after c2k9

allows buffer cache to be extended and grow/shrink dynamically

tested by many, ok oga@, "why not just commit it" deraadt@


# 1.174 29-Jul-2009 kettenis

Get rid of non-equivalent aliases of the pcb by moving the fpu state out
of the pcb and using the p_addr member of 'struct proc' to calculate the
address of the kernel stack when switching to virtual mode after taking a trap.
Remove the now unecessary cache flushes; they're actually harmful since they
create non-equivalent aliases. This seems to fix the memory corruption we
have been observing from time to time.

This diff does not rename fpu_curpcb, which is now somewhat incorrectly named.
I hope to change things back again as soon as we are able to map the pcb 1:1.


Revision tags: OPENBSD_4_6_BASE
# 1.173 15-Jun-2009 beck

Back out all the buffer cache changes I committed during c2k9. This reverts three
commits:

1) The sysctl allowing bufcachepercent to be changed at boot time.
2) The change moving the buffer cache hash chains to a red-black tree
3) The dynamic buffer cache (Which depended on the earlier too).

ok on the backout from marco and todd


# 1.172 03-Jun-2009 beck

add kern.bufcachepercent sysctl to allow adjusting the buffer cache
size on a running system.
ok art@, oga@


Revision tags: OPENBSD_4_5_BASE
# 1.171 14-Feb-2009 kettenis

Limit the amount of physical memory to 2GB. Using more causes memory
corruption on PA-RISC 2.0 systems (and there are very few PA-RISC 1.1
systems that support more than 2GB).

ok miod@


# 1.170 04-Feb-2009 miod

On systems with split BTLB, do not bother trying to insert DBTLB entries,
as PDC will lie to us pretending it did while it didn't.

ok kettenis@


# 1.169 04-Feb-2009 miod

Unify memory size reports a bit more: always report size in MB, and report
reserved memory on alpha and hppa on its own line (as done on sgi).


Revision tags: OPENBSD_4_4_BASE
# 1.168 14-Jul-2008 miod

Be sure to propagate PSL_O in psw on PCXU* processors to userland processes
and signal handlers.
ok kettenis@


# 1.167 27-Jun-2008 miod

Clear swap encryption keys before dumping a kernel image.


# 1.166 09-Apr-2008 deraadt

Add new stub uvm_shutdown() and call it from the right place in MD boot()


Revision tags: OPENBSD_4_3_BASE
# 1.165 22-Sep-2007 martin

replace even more ctob and btoc with ptoa and atop respectively plus
uvm_extern.h where needed


Revision tags: OPENBSD_4_2_BASE
# 1.164 22-Jul-2007 kettenis

Move hppa to __HAVE_TIMECOUNTERS.


# 1.163 20-Jul-2007 kettenis

Give hppa the blink_led API from sparc64, and the associated machdep.led_blink
sysctl.


# 1.162 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.161 14-Jul-2007 kettenis

Make sigreturn(2) set the proper space ID for the instruction queue. Fixes
a few more pthreads regression tests.

ok miod@


# 1.160 10-Jul-2007 kettenis

Don't trust the privilige level in the sigcontext passed to sigreturn(2).

ok miod@


# 1.159 24-Jun-2007 kettenis

Crank initial storage for extents a bit. We really should allocate extents
using malloc once vm is initialised, but this will do for now.

ok deraadt@


# 1.158 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.157 27-May-2007 miod

Make sure the minaddr hint for uvm_km_suballoc() calls is always initialized.
ok pedro@


# 1.156 26-May-2007 pedro

Dynamic buffer cache. Initial diff from mickey@, okay art@ beck@ toby@
deraadt@ dlg@.


# 1.155 21-May-2007 kettenis

Add support for 8700/pcxw2 cpu.


# 1.154 21-May-2007 kettenis

Ask firmware for reset before trying ourselves; needed for four-digit b/c/j
workstations.

tested by otto@, krw@; ok deraadt@


# 1.153 17-May-2007 art

Limit hppa buffer cache to 30%. It used to be 70% because stack garbage
that was used for minaddr instead of the proper vm_map_min(kernel_map)
(fixed in this diff).

From mickey. art@ ok


# 1.152 14-May-2007 martin

move hppa to __HAVE_CPUINFO

input from miod@, ok kettenis@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.151 28-May-2006 martin

minor nit, use CPU ID instead of FPU ID for BTLB parameters after passing
all kludges


# 1.150 15-Apr-2006 martin

make warning about missing HPT support DEBUG for now

ok mickey@


Revision tags: OPENBSD_3_9_BASE
# 1.149 26-Oct-2005 martin

no more hppa_round_page() and hppa_trunc_page() macros

ok mickey@


Revision tags: OPENBSD_3_8_BASE
# 1.148 06-Aug-2005 miod

We do not need a char machine_arch[] constant.
ok deraadt@


# 1.147 11-Jul-2005 mickey

align some stupid comments


# 1.146 10-May-2005 mickey

set pcsq in case we get signal delivery once interrupted from the gateway page; from chs


# 1.145 18-Apr-2005 mickey

do not do some of the initmsgbuf()s job


# 1.144 07-Apr-2005 mickey

on some machines it's possible to limit the amount of physmem initialised dring post so having msgbuf at the end of memory shall work


# 1.143 07-Apr-2005 mickey

64bit-friendly pdc.h and iomod.h and correspondent changes elsewhere


# 1.142 26-Mar-2005 mickey

md parts for hpux_compa code; some problems w/ signals delivery still exist


Revision tags: OPENBSD_3_7_BASE
# 1.141 24-Feb-2005 mickey

do not even ask for btlb on 8k cpus as pdc pretends there is some but then it does not work; found w/ Moritz Kiese <mbk@mytum.de> on c180; add a debug print and fix pcxu entry


# 1.140 17-Nov-2004 mickey

print real/avail/bufcache sizes as unsigned


# 1.139 26-Oct-2004 mickey

disable sid hashing on pcxu and above


# 1.138 14-Oct-2004 mickey

a bit larger delays during boot() to let msgs appear


# 1.137 19-Sep-2004 mickey

turn totalphysmem into physmem and name old physmem into smth it really is


# 1.136 18-Sep-2004 mickey

oops


# 1.135 15-Sep-2004 mickey

add pcxu tlb handlers and cpu probing
add u2/uturn ioa driver in dumb mode now
enable pcxu/pcxw support


# 1.134 14-Sep-2004 mickey

store fpu version for later use. make sure to proper store/clear fpu state in fork/exec/exit/sendsig


# 1.133 14-Sep-2004 mickey

error out from btlb_insert() if there is none


Revision tags: OPENBSD_3_6_BASE
# 1.132 01-Jul-2004 mickey

have separate insn and data cache all-flushers


# 1.131 30-Jun-2004 mickey

allow forced fpu emulation through a sysctl


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.130 13-May-2004 mickey

8ks do not have hvt


# 1.129 05-May-2004 mickey

much easier tlb handler branch patching


# 1.128 05-May-2004 mickey

do not engage HPT on PCXT' (yet)


# 1.127 08-Apr-2004 mickey

repair pcxs/t confoosion


# 1.126 07-Apr-2004 mickey

update copyright; miod@ is fine w/ files where he holds it too


Revision tags: OPENBSD_3_5_BASE
# 1.125 10-Mar-2004 tom

Ensure that we obey a user's ddb> boot reboot command even if the system
is cold (during startup).

This adds RB_USERREQ to sys/reboot.h, uses it in the ddb commands, and
ensures that */*/machdep.c:boot() won't set RB_HALT when cold if this
flag is set.

ok deraadt@


# 1.124 14-Feb-2004 grange

Simplify hw.{cpuspeed,setperf} api moving all the sysctl stuff
from the underlying callbacks.

Testing hppa mickey@, ppc drahn@
Ok markus@ tedu@


# 1.123 05-Jan-2004 mickey

kill debugging code that is not needed anymore


# 1.122 23-Dec-2003 mickey

provide cpuspeed fluff


# 1.121 20-Dec-2003 miod

Don't let microtime() return a struct timeval with exactly 1000000 microseconds.


# 1.120 18-Dec-2003 mickey

spls do not protect cpu_itmr and thus time might jump back sometimes due to cpu_itmr modified to a higher value than a read itmr; found and testing by miod@


# 1.119 17-Dec-2003 mickey

in the real mem print do not include reserved for prom into used by openbsd


# 1.118 10-Dec-2003 mickey

for unaligned btlb mapping attempts -- just fail


# 1.117 24-Nov-2003 mickey

experimental support for HVT as a 2nd level tlb


# 1.116 15-Oct-2003 mickey

less global name space pollution


# 1.115 05-Oct-2003 mickey

reload the itmr as soon as we get the intr to avoid lagging on slower machines


# 1.114 25-Sep-2003 mickey

some pcxl2 do not report fpus -- assume it's there


Revision tags: OPENBSD_3_4_BASE
# 1.113 04-Sep-2003 mickey

a better cpu identification; testing by miod


# 1.112 31-Aug-2003 miod

pdc_model needs to be visible from cpu.c


# 1.111 20-Aug-2003 mickey

missing nl in debugging prontf


# 1.110 07-Aug-2003 mickey

dead proto


# 1.109 07-Aug-2003 mickey

first allocate space on stack then copyout signal shits. add a DEBUG check for a whacky user pc (as impossible due to the recent trap.c change)


# 1.108 03-Aug-2003 mickey

clear branch and nullify bits in psw on sending a signal


# 1.107 30-Jul-2003 mickey

deduce the leds address from the model number and thus make some more use of that lichtenblinkenschmutz on some more machinens


# 1.106 22-May-2003 mickey

imprecision in delay_init()


# 1.105 18-May-2003 mickey

save the fpu state for the signal handler. this is essential
as the fpu regs can be used by the gcc even for non-fpu
means and data copying.
rearrange the sigcontext a bit to include only the general
registers that are needed restoring upon return and thus
less waste of space and make up some space for the fpu regs.

ALL software that used the signal context on the stack
needs at least rebuilding now. a new snap has bin built as well.


Revision tags: UBC_SYNC_A
# 1.104 11-May-2003 deraadt

string cleaning; krw ok


# 1.103 07-Apr-2003 mickey

s/HP9000/HP 9000/; from weissmanndude


Revision tags: OPENBSD_3_3_BASE
# 1.102 18-Feb-2003 deraadt

knf; mickey ok


# 1.101 12-Feb-2003 jason

How uncommon... hppa only has one common: msgbufmapped (decl'd in /sys/kern)


# 1.100 12-Feb-2003 mickey

only align the first stack frame onto the minimal required alignment


# 1.99 10-Feb-2003 mickey

fix pcs and pcxt recognition. from weissmanndude


# 1.98 22-Jan-2003 mickey

consistantly use uvm_prot_* vs vm_prot_* evewrhere


# 1.97 14-Jan-2003 mickey

fix cutnpaste in the cpu table for the itlbna field; from herr weissmanndude


# 1.96 14-Jan-2003 mickey

need pdc_hwtlb always; pt out by herr weissmanndude


# 1.95 13-Jan-2003 mickey

fix the logic in hvt probing


# 1.94 09-Jan-2003 miod

Remove fetch(9) and store(9) functions from the kernel, and replace the few
remaining instances of them with appropriate copy(9) usage.

ok art@, tested on all arches unless my memory is non-ECC


# 1.93 19-Dec-2002 mickey

setregs: put the whole frame setup into one place


# 1.92 19-Dec-2002 mickey

level 0x16 is really an l2


# 1.91 17-Dec-2002 millert

Make SysV-style shared memory and semaphore limits sysctl'able.
Instead of allocating a static amount of memory for the data
structures via valloc() in allocsys(), allocate things dynamically
using pool(9) when possible and malloc(9) when not. The various
members of struct seminfo and struct shminfo are in kern.seminfo
and kern.shminfo respectively (not all members of kern.seminfo are
changable).

The data structures used still leave something to be desired but
things are not made worse in that respect by this commit.


# 1.90 27-Nov-2002 mickey

no wrapper arounf hardclock(), use CPU_CLOCKUPDATE, real microtime; miod ok


# 1.89 08-Nov-2002 mickey

Don't uvm_useracc the user sigcontext in sys_sigreturn and then access
the user addresses directly from the kernel. copyin is faster and can
correctly deal properly with mappings that uvm_useracc thinks are
correct but will fault anyway (to figure out how to generate such
mappings is left as en excercise for the reader).


# 1.88 01-Nov-2002 mickey

add a missing delay after printf on halt[-p], proper arg for a cold hook


Revision tags: UBC_SYNC_B
# 1.87 22-Oct-2002 mickey

do not force single-user; pt out by fries@


# 1.86 15-Oct-2002 mickey

missing initmsgbuf(), noticed by miod@


# 1.85 13-Oct-2002 mickey

track the end of physmem for use in dmmem_alloc


# 1.84 07-Oct-2002 mickey

s/PSW_/PSL_/ to match other archs


# 1.83 07-Oct-2002 mickey

proper terminate the user stack on signal


# 1.82 07-Oct-2002 mickey

on implementations w/ fpu included unimplemented instructions
are signaled through the exception trap w/ invalid opcode marked
instruction in the exception registers, not through the emulation
trap (as long as the fpu is enabled, of course).
parse emulation from the exception trap as well as the emulation
trap and fix the dispatcher into usable condition.
parse invalid op exception on trap and signal the user appropriately.
reset the exception on exec and for child on fork.
the later is appropriate since exceptions are delayed until next
fpu instruction, which was in the parent indeed, let him get it.
save parent's fpu context on fork before cipying it, if the
parent owned the fpu.


Revision tags: OPENBSD_3_2_BASE
# 1.81 23-Sep-2002 mickey

parisc level 0x10 is just an overclocked 0xe


# 1.80 17-Sep-2002 mickey

handle fpu exceptions properly, might use a regress, i guess


# 1.79 11-Sep-2002 mickey

provide a convinient reset label


# 1.78 11-Sep-2002 mickey

stack grows the other way, but the frame is the other way to that. hehe


# 1.77 09-Sep-2002 mickey

set up the frame flags and a user frame better on exec


# 1.76 03-Aug-2002 mickey

rework boot() w/o a goto


# 1.75 25-Jul-2002 mickey

missing arg in the call to the pdc_call since some old times


# 1.74 25-Jul-2002 mickey

kcopy is a space-to-space copy from kernel space, to guess where, -- to the same kernel space, just error on fault


# 1.73 20-Jul-2002 art

Instead of copying out the signal trampoline on top of the stack, create
an uvm aobj, copy out the signal trampoline into it and share that page
among all processes for the same emulation.

This also requires us to actually be able to tell signal code where the
trampoline is located, so introduce a new field in struct proc - p_sigcode
that is a pointer to sigcode. This allows us to remove all the ugly
calculations of the signal trampoline address done in every sendsig
function in the tree (that's why so many files are changed).

Tested by various people. ok deraadt@


# 1.72 14-May-2002 mickey

disable sid hashing while still in real mode, alos print the parisc arch once and not per each cpu since they are not intermixable architecture-wise


# 1.71 13-May-2002 mickey

ldi-ldo whatever was in the table, be that much clever


# 1.70 08-May-2002 mickey

print parisc level w/ the the parisc version, not for each cpu


# 1.69 08-May-2002 mickey

kill debugging printfski


# 1.68 22-Apr-2002 mickey

no longer batc the data, only the code.
this removes a constraint and an ld.script dependancy
for the .data and the dynamically allocated kernel
structures existed w/ batcing. also makes pmap_steal_memory
obsolete and replaced w/ the pmap_virtual_space.
implement batching for pmap_remove to avoid
zeroing out the pte entries if pde will be removed anyway.


# 1.67 21-Apr-2002 mickey

better buf's mapping and less magic constants in checking for io space cachability


Revision tags: OPENBSD_3_1_BASE
# 1.66 26-Mar-2002 mickey

if cannot guess cpu model default to the lowest supported one


# 1.65 25-Mar-2002 deraadt

spelling


# 1.64 23-Mar-2002 espie

Add variables for config(8) -e time tweak of systemV shared memory
parameters.

Ok millert@, miod@, maja@


# 1.63 19-Mar-2002 mickey

mtcpu seq requires a pre-sync, implement hpt init for pcxl


# 1.62 15-Mar-2002 mickey

rewrite a pmap to use multilevel page tables.
lower 12 bits contain the perms, no unused bits left,
but a couple for off-tlb use (as the ref implemented now).
do not use the hvt, which might get some use later
if proven to speed thigs up, tlb handlers would po
another dozen of insns though, but if that's worth its...
move on the data seg and map kernel text rdonly (idea form fredette),
since all of the page0 mods done before that we are all fine
except for some viper fluff, but later w/ that.
this also picks up a bit more of ddb magic for bpt and ss.
tlb handlers can use a little bit more of attention,
but things, visually, seem to be much faster already, --
sorry, no benchmarks for now.

* effort sponsored in part by the `henry st. old ale house'
* and mr.pete and mr.lee in particular in thier generous entrirety.
* the proj took a little more that 72man*h as it was expected,
* but within murhy's law estimations.


# 1.61 14-Mar-2002 millert

First round of __P removal in sys


# 1.60 20-Feb-2002 mickey

setup power failure handler (for sw-controlled power button), move toc handler


# 1.59 17-Feb-2002 maja

Patch from Daniel Lucq <daniel@lucq.org>

The patch allows you to change the value of NMBCLUSTERS, BUFCACHEPERCENT
and NKMEMPAGES using the config command, instead of recompiling the kernel.

This is the kernel part of the patch. I have compiled it on i386, sparc64,
alpha and macppc. -moj ok art@ maja@


# 1.58 12-Feb-2002 mickey

support 712's programmable power switch, no interrupt yet


# 1.57 12-Feb-2002 mickey

small repairs to hpmc and toc handlers


# 1.56 11-Feb-2002 mickey

disable fpu on csw, print fpu version on cpu line, if present


# 1.55 07-Feb-2002 mickey

fix sigdebug cases; init sigcontext before it's used (;


# 1.54 06-Feb-2002 mickey

implement signal delivery; based on fredette@'s work


# 1.53 03-Feb-2002 mickey

restore hpt size computation, does not break things as i thought


# 1.52 02-Feb-2002 mickey

fix 'physmem' usage


# 1.51 02-Feb-2002 mickey

implement the rest of /dev/mem devices; from netbsd


# 1.50 23-Jan-2002 art

move mb_map allocation to mbinit()


# 1.49 23-Jan-2002 art

move definition of mb_map from zillions of machdep.c to uipc_mbuf.c


# 1.48 16-Jan-2002 miod

Don't include <sys/map.h> when you don't need what's in it.


Revision tags: UBC_BASE
# 1.47 02-Dec-2001 mickey

branches: 1.47.2;
increase fixed extent storage


# 1.46 28-Nov-2001 art

zap some typedefs.
vm_map_t -> struct vm_map *
vm_map_entry_t -> struct vm_map_entry *
simple_lock_data_t -> struct simplelock

(uvm not done yet, coming in the next commit)


# 1.45 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.44 24-Nov-2001 miod

Harmonize boot() logic across arches:
- ensure RB_DUMP | RB_HALT will cause a dump
- or RB_HALT if (cold)
While there, honor RB_TIMEBAD on sparc64.


# 1.43 09-Nov-2001 art

nswbuf hasn't been used for ages. gc.


# 1.42 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.41 06-Nov-2001 miod

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


Revision tags: OPENBSD_3_0_BASE
# 1.40 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.39 12-Sep-2001 art

mbutl no more


# 1.38 23-Aug-2001 art

We can now move timeout_init into main().


# 1.37 23-Aug-2001 art

Remove even more old timeout tentacles.


# 1.36 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.35 05-Jul-2001 art

Get rid of REAL_CLISTS. It was never implemented and the tentacles are
everywhhere.


# 1.34 17-May-2001 provos

convert mbuf and cluster allocation to pool, mostly from NetBSD
okay art@ miod@


# 1.33 05-May-2001 art

Rename configure() to cpu_configure().
Move it from cpu_startup() to main().


# 1.32 05-May-2001 art

Get rid of CLSIZE and all related stuff.
CLSIZE -> 1
CLBYTES -> PAGE_SIZE
OLOFSET -> PAGE_MASK
etc.
At the same time some archs needed some cleaning in vmparam.h so that
goes in at the same time.


Revision tags: OPENBSD_2_9_BASE
# 1.31 29-Mar-2001 mickey

cpudev_data.h here needed not


# 1.30 22-Mar-2001 mickey

shuffle the tlb handlers a little,
make a new one for na data fault,
since those w/ hpt need it.


Revision tags: OPENBSD_2_8_BASE
# 1.29 15-Aug-2000 mickey

two btlb routines (i & d) for pcxs


# 1.28 15-Aug-2000 mickey

expand per-cpu control routines switch


# 1.27 08-Aug-2000 mickey

print btlb params w/ BTLBDEBUG; from Havard.Eidnes@runit.sintef.no


# 1.26 02-Jul-2000 mickey

no bays for stinger


Revision tags: OPENBSD_2_7_BASE
# 1.25 23-Mar-2000 mickey

new cpu type switch code.
initializes tlb miss handlers correspondent to probed cpu features.
also btlb load routine.
versions written are for pcxl and others.
cpu-dep btlb loaders are missing, only generic for now.


# 1.24 23-Mar-2000 art

New API for timeouts. Replaces the old timeout()/untimeout() API and
makes it the callers responsibility to allocate resources for the
timeouts.

This is a KISS implementation and does _not_ solve the problems of slow
handling of a large number of pending timeouts (this will be solved in
future work) (although hardclock is now guarateed to take constant time
for handling of timeouts).

Old timeout() and untimeout() are implemented as wrappers around the new
API and kept for compatibility. They will be removed as soon as all
subsystems are converted to use the new API.


# 1.23 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


# 1.22 22-Feb-2000 mickey

blah, blah, blah, msgbuf


Revision tags: SMP_BASE
# 1.21 09-Feb-2000 mickey

branches: 1.21.2;
heartbeat -- yeah we have a patch for that


# 1.20 25-Jan-2000 mickey

better copy and zero inlines in locore;
proper setregs() in machedep;
start of hpmc handler;
some cleanup here and there;


# 1.19 17-Jan-2000 mickey

remove unneeded stuff from setregs; force single-user for now, enable signal debug


# 1.18 11-Jan-2000 mickey

s/fpu_curproc/fpu_curpcb/ which also points into physical.
move it's definition into locore (where it's used the most).
adjust fpu context switch and save on swapout accordingly.
fix context save (in switch).
add accounting for fpu context switches (since it differes
from proc switching, we might get provided w/ some usefull
numbers as to how effective this lazy switch technique is).
enable handling fpu/sfu exceptions.


# 1.17 31-Dec-1999 mickey

don't bother about pidr3 and pidr4


# 1.16 17-Dec-1999 mickey

fix the panic message for sti memory mapping


Revision tags: kame_19991208
# 1.15 25-Nov-1999 mickey

bus stuff is in mainbus now, the rest is rewritten many ways


Revision tags: OPENBSD_2_6_BASE
# 1.14 20-Sep-1999 mickey

fix uvm_pagealloc() call


# 1.13 03-Sep-1999 art

Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.12 14-Aug-1999 mickey

proper debugging ifdefs


# 1.11 21-Jul-1999 mickey

rewrite the tlb miss handler and tlb dirty handler.
optimize for HVT usage (when compiled for proper cpu type).
drop hpt_* global variables, use info from control registers instead.
there are still ways to improve the tlb handlers tho.
machdep also prints cache and tlb coherence states (not related to the above).
You eat greenish muffin. --More-- You write real code.


# 1.10 12-Jul-1999 mickey

allocate 5% bufcache if <=16M memory installed


# 1.9 12-Jun-1999 mickey

hppa_init() now takes an argument from locore,
meaning the start of available memory.
cleanup machdep somewhat.
fix vm_map.pmap vs vm_pmap isue; 10x art@


# 1.8 23-May-1999 mickey

new swap stuff


# 1.7 21-May-1999 mickey

group all theMD f;ags together, add interrupt recursion one


# 1.6 21-May-1999 mickey

define fpu_curproc


# 1.5 20-Apr-1999 mickey

do lazy blok mapping of io space in bus_*
add copy{in,out}*, kcopy, etc
boot routines
cpu-id-hpux-compat stuff
rest of scheduler and such
uvm


Revision tags: OPENBSD_2_5_BASE
# 1.4 17-Feb-1999 mickey

print pa-risc here as well, since, finally, cpu will have to print processor type


# 1.3 04-Jan-1999 mickey

better cache handling in bus_space_barrier(), seem to work now


# 1.2 03-Jan-1999 mickey

implement bus_space_{un,}map w/ extents


# 1.1 30-Dec-1998 mickey

machdep; more work needed


# 1.259 31-May-2020 dlg

introduce "cpu_rnd_messybits" for use instead of nanotime in dev/rnd.c.

rnd.c uses nanotime to get access to some bits that change quickly
between events that it can mix into the entropy pool. it doesn't
use nanotime to get a monotonically increasing set or ordered and
accurate timestamps, it just wants something with bits that change.

there's been discussions for years about letting rnd use a clock
that's super fast to read, but not necessarily accurate, but it
wasn't until recently that i figured out it wasn't interested in
time at all, so things like keeping a fast clock coherent between
cpu cores or correct according to ntp is unecessary. this means we
can just let rnd read the cycle counters on cpus and things will
be fine. cpus with cycle counters that vary in their speed and
arent kept consistent between cores may even be desirable in this
context.

so this is the first step in converting rnd.c to reading cycle
counter. it copies the nanotime backend to each arch, and they can
replace it with something MD as a second step later on.

djm@ suggested rnd_messybytes, but we landed on cpu_rnd_messybits.
thanks to visa for his eyes.
ok deraadt@ visa@
deraadt@ says he will help handle any MD fallout that occurs.


# 1.258 16-May-2020 kettenis

Make inittodr() and resettodr() MI.

ok deraadt@, mpi@, visa@
ok cheloha@ as well (would have preferred in new file for this code)


# 1.257 11-May-2020 kettenis

Initialize the timeval passed to todr_gettime() with the base time from
the file system such that implementations can use it to guess the right
century.

ok mpi@


Revision tags: OPENBSD_6_7_BASE
# 1.256 01-May-2020 kettenis

Use the same inittodr()/resettodr() implementation as on
amd64/arm64/armv7/i386/sparc64 and move it to the end of machdep.c. Rework the
actual implementation for the MC14818 compatible RTC into something that can
be used as a todr_handle just like on amd64.

ok mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.255 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


Revision tags: OPENBSD_6_4_BASE
# 1.254 20-Jul-2018 guenther

Missed a 'ksi' -> '*ksip' change in previous commit


# 1.253 10-Jul-2018 guenther

Move from sendsig() to its callers the initsiginfo() calls and
instead of passing sendsig() the code+type+val, pass a siginfo_t*
to copy from. Eliminate the indirection through struct emul for
sendsig(); we no longer have a SunOS4-compat version of sendsig()

ok deraadt@


# 1.252 22-May-2018 guenther

Delete antique sigdebug definitions

ok kettenis@


# 1.251 12-Apr-2018 deraadt

Implement MAP_STACK option for mmap(). Synchronous faults (pagefault and
syscall) confirm the stack register points at MAP_STACK memory, otherwise
SIGSEGV is delivered. sigaltstack() and pthread_attr_setstack() are modified
to create a MAP_STACK sub-region which satisfies alignment requirements.
Observe that MAP_STACK can only be set/cleared by mmap(), which zeroes the
contents of the region -- there is no mprotect() equivalent operation, so
there is no MAP_STACK-adding gadget.
This opportunistic software-emulation of a stack protection bit makes
stack-pivot operations during ROPchain fragile (kind of like removing a
tool from the toolbox).
original discussion with tedu, uvm work by stefan, testing by mortimer
ok kettenis


Revision tags: OPENBSD_6_3_BASE
# 1.250 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.249 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


Revision tags: OPENBSD_6_2_BASE
# 1.248 18-May-2017 kettenis

Implement copyin32(9).

"your chicken scratches look fine to me" deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.247 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

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


# 1.246 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.245 21-May-2016 deraadt

hand-massage sendsig() and sys_sigreturn() to be much more similar.
ok guenther kettenis


# 1.244 10-May-2016 deraadt

SROP mitigation. sendsig() stores a (per-process ^ &sigcontext) cookie
inside the sigcontext. sigreturn(2) checks syscall entry was from the
exact PC addr in the (per-process ASLR) sigtramp, verifies the cookie,
and clears it to prevent sigcontext reuse.
not yet tested on landisk, sparc, *88k, socppc.
ok kettenis


# 1.243 20-Apr-2016 dlg

pool_setipl for floating point context things

ok kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.242 21-Oct-2015 mpi

Do not call uvm_swap_finicrypt_all() a second time in dumpsys().

ok tedu@, deraadt@, miod@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.241 20-Jan-2015 kettenis

Move ps_strings "after" the random stackgap. This makes its location a
per-process value, and therefpore turns the VM_PSSTRINGS sysctl into a
per-process one as well. This gets rid of a pointer to the bottom of the
stack at a fixed location. Also clears the road for unmapping the stackgap.

ok deraadt@


# 1.240 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.239 25-Oct-2014 kettenis

Remove vmmap; it isn't used.

ok jsing@


# 1.238 23-Oct-2014 miod

Correctly set up the HPMC trap entry: according to the PA-RISC Firmware
Architecture Reference Specification, the sum of the 8 trap entry words
*and* of the payload which address and length are to be set at well-known
positions in the aforementioned trap entry, needs to be zero; the existing
code was only enforcing that the sum of the trap entry words is zero.

This matches what Linux and NetBSD do.

ok kettenis@


# 1.237 23-Oct-2014 miod

Revert limiting physmem to 2GB; the culprit was likely in uvm and uvm has
changed a lot in the last 5 years; verified to work on a 3GB system, in
snapshots for a few weeks already.


# 1.236 22-Sep-2014 dlg

implement atomic_{cas,swap}_{uint,ulong,ptr} and
atomic_{add,sub}_{int,long}_nv. sys/atomic.h turns these into the
rest of the atomic api.

on uniprocessor hppa systems "atomic" operations are implemented
as a non-interruptable sequence by disabling all interrupts on the
cpu, doing the operation, and then restoring the interrupt mask.

this isnt enough on MP systems, so we added a global atomic memory
mutex that is taken inside the interrupt disabling above to coordinate
operations between cpus.

this is a lot of overhead though cos mutexes dance around with ipls,
which is unecessary in our case because of the interrupt disabling
that is already done. also, hppa spinlocks are implemented with
ldcw which requires the word it operates on to be 16 byte aligned.
mutexes arent guaranteed to have this alignment so they compensate
by having lots of words inside themselves so they can hit the
appropriate one to use for the ldcw op.

with this in mind, this change pulls __cpu_simple_locks, which are
simply ldcw spinlocks with a 16 byte aligned word, out of
src/sys/arch/hppa/include/lock.h into src/sys/arch/hppa/include/atomic.h
so atomic.h can use them. lock.h includes atomic.h, so it still
gets and provides the same functionality as before.

finally, this also pulls the rwlock cas implementation apart. cas
ops now share the same serialising lock on MP systems as the other
memory operations, and rw_cas is defined as a wrapper around
atomic_cas_uint.

ok kettenis@


# 1.235 19-Sep-2014 kettenis

Use config_suspend_all(9).


# 1.234 18-Aug-2014 dlg

dont rely on mbuf.h to provide pool.h.

ok miod@, who has offerred to help with any MD fallout
ok guenther@


Revision tags: OPENBSD_5_6_BASE
# 1.233 22-Jul-2014 uebayasi

boot(9): Reduce diffs between hppa & hppa64 (& others)


# 1.232 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.231 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.230 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.229 13-Jul-2014 miod

These still need <sys/reboot.h> for the RB_ constants.


# 1.228 12-Jul-2014 uebayasi

reboot(9), panic(9): Call panic(9) for unrecoverable MD H/W errors (NMIs)

Some architectures have ability to detect hardware sanity and notify system
(NMI, firmware callback, etc.). Handle these hardware severe errors, same
as software errors, with panic(9).

According to miod@, SGI IP27 NMI is triggered by pushing some "hidden" button,
which "usual" users/admins don't know. Pushing such a button is "RB_USERREQ"
(human-triggered) in that the button is pushed by a human, but not "RB_USERREQ"
in that no user intervention in system (== no command input) is done. miod@
agreed that changing these from RB_USERREQ to !RB_USERREQ (== panic(9)) is
not a big problem.

OK miod@ kettenis@


# 1.227 12-Jul-2014 uebayasi

boot(9), reboot(9): Migrate MD callers of boot(9) to reboot(9)

I have found that some ports call boot(9) from machine-dependent code to
reboot system. These should be changed to either:

- Sending signal to init(8) to trigger it to shutdown system cleanly, like
acpi(4) does, in cases where found problems don't prevent system from working
immediately, or

- Just doing panic(9) if the situation is severely broken.

For now, just rewrite boot() to reboot(). Actual fixes follow.

Discussed with & OK from kettenis@


# 1.226 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.225 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.224 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.223 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.222 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.221 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.220 08-May-2014 miod

Format string fixes and removal of -Wno-format for hppa kernels.


# 1.219 08-Apr-2014 mpi

Less <uvm/uvm.h>


# 1.218 04-Apr-2014 miod

If the PDC_COPROC call fails, and we are running on a PA 1.1 system, assume
the usual 1.1 coprocessor mask, instead of using zero and having every
userland process dying with signal 4.

The circumstances under which this call fails are unclear and could be
tied to specific PROM version (I have tried overzealous stack alignment and
other tricks, to no avail). Interestingly enough, the 715/75 system which
hits this problem, only triggers it when booting from disk, and never when
booting from network.

This diff is an ugly bandaid until the problem is better understood. Or maybe
it is not worth investigating, seeing that Linux hardcodes the coprocessor
mask and never issues PDC_COPROC calls; I wonder what HP/UX does.

In my tree for over 18 months; "Looks like a nice hack" deraadt@
715/75 system provided by Sebastiaan Indesteege, thanks!


# 1.217 29-Mar-2014 guenther

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

ok dlg@ mpi@ deraadt@


# 1.216 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


# 1.215 22-Mar-2014 guenther

Move p_sigacts from struct proc to struct process.

testing help mpi@


# 1.214 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


Revision tags: OPENBSD_5_5_BASE
# 1.213 23-Nov-2013 uebayasi

Run doshutdownhooks() and config_suspend() even when boot() is called while
cold != 0. Indent and make hppa/hppa64 boot() closer to others.

OK kettenis@


# 1.212 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


Revision tags: OPENBSD_5_4_BASE
# 1.211 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


Revision tags: OPENBSD_5_3_BASE
# 1.210 02-Dec-2012 guenther

Determine whether we're currently on the alternative signal stack
dynamically, by comparing the stack pointer against the altstack
base and size, so that you get the correct answer if you longjmp
out of the signal handler, as tested by regress/sys/kern/stackjmp/.
Also, fix alt stack handling on vax, where it was completely broken.

Testing and corrections by miod@, krw@, tobiasu@, pirofti@


# 1.209 26-Oct-2012 kettenis

Properly clear trap frame in setregs() to avoid leaking registers across exec.

ok jsing@


# 1.208 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.207 07-Oct-2012 kettenis

Align the stack on a 64-byte boundary as required by "The 32-bit PA-RISC
Run-time Architecture Document". GCC relies on this to properly align
stack variables.

ok guenther@, beck@


Revision tags: OPENBSD_5_2_BASE
# 1.206 21-Jun-2012 guenther

__tfork() needs to set the stack address of the new thread in the kernel,
so that it can't get a signal while still running on the parent thread's
stack. Also, pass in sizeof(struct __tfork) to provide forward compat
when more members are added. This is an ABI change, so switch syscall
numbers and bump lib majors this time.

ok deraadt@ matthew@


Revision tags: OPENBSD_5_1_BASE
# 1.205 20-Sep-2011 miod

Clear RB_POWERDOWN early in boot() on systems which can not powerdown and
which firmware does not send spin up commands to the disks, in case the
operator changes his mind and reboots instead of manually powering down
after the system has halted.
ok kettenis@


Revision tags: OPENBSD_5_0_BASE
# 1.204 05-Jul-2011 guenther

Recommit the reverted sigacts change now that the NFS use-after-free
problem has been tracked down. This fixes the sharing of the signal
handling state: shared bits go in sigacts, per-rthread bits goes in
struct proc.

ok deraadt@


# 1.203 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.202 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.201 18-Apr-2011 guenther

Revert the sigacts diff: NFS can apparently retain pointers to processes
until they're zombies and then send them signals (for intr mounts). Until
that is untangled, the sigacts change is unsafe. sthen@ was the victim
for this one


# 1.200 15-Apr-2011 guenther

Correct the sharing of the signal handling state: stuff that should
be shared (p_sigignore, p_sigcatch, P_NOCLDSTOP, P_NOCLDWAIT) moves
to struct sigacts, wihle stuff that should be per rthread (ps_oldmask,
SAS_OLDMASK, ps_sigstk) moves to struct proc. Treat the coredumping
state bits (ps_sig, ps_code, ps_type, ps_sigval) as per-rthread
until our locking around coredumping is better.

Oh, and remove the old SunOS-compat ps_usertramp member.

"I like the sound of this" tedu@


Revision tags: OPENBSD_4_9_BASE
# 1.199 14-Jan-2011 jsing

Halt secondary CPUs when shutting down or rebooting. This should prevent
occasional hangs during reboot.

ok kettenis@


# 1.198 04-Jan-2011 jasper

- de-register. no binary change.

ok jsing@


# 1.197 01-Jan-2011 jasper

Move setting cpu_hzticks to the clock initialization function, like
other ports (e.g. hppa64) do.

ok jsing@ kettenis@


# 1.196 01-Jan-2011 jasper

- ansify

ok jsing@ kettenis@


# 1.195 30-Dec-2010 jsing

Turn signotify() into a function that also calls cpu_unidle().

ok kettenis@


# 1.194 20-Nov-2010 miod

This is a first step towards getting rid of avail_start and avail_end in the
kernel, currently limited to low-hanging fruit: these variables were used
by bus_dma to specify the range in which to allocate memory, back when
uvm_pglistalloc() was stupid and would not walk the vm_physseg[].

Nowadays, except on some platforms for early initialization, these variables
are not used, or do not need to be global variables. Therefore:
- remove `extern' declarations of avail_start and avail_end (or close cousins,
such as arm physical_start and physical_end) from files which no longer need
to use them.
- make them local variables whenever possible.
- remove them when they are assigned to but no longer used.


Revision tags: OPENBSD_4_8_BASE
# 1.193 01-Jul-2010 jsing

Create a struct to store FP state and include a pointer to the CPU that
currently holds the FPU context for this process. This will be soon used
to implement FPU shootdowns on multiprocessor kernels.

ok kettenis@


# 1.192 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.191 29-Jun-2010 jsing

Factor out code used to save and flushe process FPU context.

ok kettenis@


# 1.190 29-Jun-2010 jsing

Store pointer to process FPU state in struct cpu_info.

ok kettenis@


# 1.189 27-Jun-2010 thib

uvm constraints. Add two mandatory MD symbols, uvm_md_constraints
which contains the constraints for DMA/memory allocation for each
architecture, and dma_constraints which contains the range of addresses
that are dma accessable by the system.

This is based on ariane@'s physcontig diff, with lots of bugfixes and
additions the following additions by my self:

Introduce a new function pool_set_constraints() which sets the address
range for which we allocate pages for the pool from, this is now used
for the mbuf/mbuf cluster pools to keep them dma accessible.

The !direct archs no longer stuff pages into the kernel object in
uvm_km_getpage_pla but rather do a pmap_extract() in uvm_km_putpages.

Tested heavily by my self on i386, amd64 and sparc64. Some tests on
alpha and SGI.

"commit it" beck, art, oga, deraadt
"i like the diff" deraadt


# 1.188 27-Jun-2010 jsing

Use a mutex to make atomic operations atomic on multiprocessor kernels.

ok kettenis@


# 1.187 10-Jun-2010 deraadt

Declare safepri at the MD level on each platform, so that the kern_synch.c
does not have to deal with it as a common. Some platforms may be missed
by this commit... if you spot one, fix it the same way.
ok miod


# 1.186 09-Jun-2010 miod

Move declaration of cn_tab from dev/cons.c to dev/cninit.c, or appropriate
md files for ports which do not use dev/cninit.c. This gets rid of a common
at kernel link time.
feedback drahn@ ok deraadt@


# 1.185 24-May-2010 deraadt

Add missing prototypes
ok jsing kettenis


# 1.184 09-May-2010 kettenis

Prevent "taken branch" exceptions from kernel space by clearing the PSL_T
bit before we enter a signal handler.

"if you say so" miod@, "seems to make sense" jsing@


# 1.183 02-May-2010 kettenis

Properly initialize the members of `struct mdproc' that deal with
single-stepping when we fork and reset them upon exec.

ok miod@


# 1.182 27-Apr-2010 kettenis

Avoid null-pointer dereference by giving proc0 a place to store its
floating-point registers. Pointed out by Nick Hudson.

ok miod@, jsing@


# 1.181 19-Apr-2010 jsing

Make the Processor Status Word (PSW) a per-CPU value.

ok kettenis@


# 1.180 01-Apr-2010 jsing

Allow for multiple CPUs by moving to an array of cpu_info.

ok kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.179 31-Dec-2009 jsing

Make cpl and cpu_inintr per CPU variables. For locore.S, cpl becomes an
offset within cpu_primary_info - this will need to be revisited shortly.

ok kettenis@


# 1.178 11-Aug-2009 miod

Do not bother initializing bufpages in the md code if the computation is
exactly the same the mi could will use if bufinit() is invoked with
bufpages == 0.


# 1.177 11-Aug-2009 miod

With the SysV memory allocation changes, allocsys() doesn't do anything
anymore. Get rid of it completely.


# 1.176 09-Aug-2009 blambert

Rototill system V message queues.

No longer allocate a static amount of memory for messages in MD
boot path; message queues, message metadata, and message data now
all use dynamic memory, which means that runtime sysctls should now
be trivial to implement.

Since I'm going to be around all week to fix any breakage, this should
probably just go in now.


# 1.175 02-Aug-2009 beck

Dynamic buffer cache support - a re-commit of what was backed out
after c2k9

allows buffer cache to be extended and grow/shrink dynamically

tested by many, ok oga@, "why not just commit it" deraadt@


# 1.174 29-Jul-2009 kettenis

Get rid of non-equivalent aliases of the pcb by moving the fpu state out
of the pcb and using the p_addr member of 'struct proc' to calculate the
address of the kernel stack when switching to virtual mode after taking a trap.
Remove the now unecessary cache flushes; they're actually harmful since they
create non-equivalent aliases. This seems to fix the memory corruption we
have been observing from time to time.

This diff does not rename fpu_curpcb, which is now somewhat incorrectly named.
I hope to change things back again as soon as we are able to map the pcb 1:1.


Revision tags: OPENBSD_4_6_BASE
# 1.173 15-Jun-2009 beck

Back out all the buffer cache changes I committed during c2k9. This reverts three
commits:

1) The sysctl allowing bufcachepercent to be changed at boot time.
2) The change moving the buffer cache hash chains to a red-black tree
3) The dynamic buffer cache (Which depended on the earlier too).

ok on the backout from marco and todd


# 1.172 03-Jun-2009 beck

add kern.bufcachepercent sysctl to allow adjusting the buffer cache
size on a running system.
ok art@, oga@


Revision tags: OPENBSD_4_5_BASE
# 1.171 14-Feb-2009 kettenis

Limit the amount of physical memory to 2GB. Using more causes memory
corruption on PA-RISC 2.0 systems (and there are very few PA-RISC 1.1
systems that support more than 2GB).

ok miod@


# 1.170 04-Feb-2009 miod

On systems with split BTLB, do not bother trying to insert DBTLB entries,
as PDC will lie to us pretending it did while it didn't.

ok kettenis@


# 1.169 04-Feb-2009 miod

Unify memory size reports a bit more: always report size in MB, and report
reserved memory on alpha and hppa on its own line (as done on sgi).


Revision tags: OPENBSD_4_4_BASE
# 1.168 14-Jul-2008 miod

Be sure to propagate PSL_O in psw on PCXU* processors to userland processes
and signal handlers.
ok kettenis@


# 1.167 27-Jun-2008 miod

Clear swap encryption keys before dumping a kernel image.


# 1.166 09-Apr-2008 deraadt

Add new stub uvm_shutdown() and call it from the right place in MD boot()


Revision tags: OPENBSD_4_3_BASE
# 1.165 22-Sep-2007 martin

replace even more ctob and btoc with ptoa and atop respectively plus
uvm_extern.h where needed


Revision tags: OPENBSD_4_2_BASE
# 1.164 22-Jul-2007 kettenis

Move hppa to __HAVE_TIMECOUNTERS.


# 1.163 20-Jul-2007 kettenis

Give hppa the blink_led API from sparc64, and the associated machdep.led_blink
sysctl.


# 1.162 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.161 14-Jul-2007 kettenis

Make sigreturn(2) set the proper space ID for the instruction queue. Fixes
a few more pthreads regression tests.

ok miod@


# 1.160 10-Jul-2007 kettenis

Don't trust the privilige level in the sigcontext passed to sigreturn(2).

ok miod@


# 1.159 24-Jun-2007 kettenis

Crank initial storage for extents a bit. We really should allocate extents
using malloc once vm is initialised, but this will do for now.

ok deraadt@


# 1.158 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.157 27-May-2007 miod

Make sure the minaddr hint for uvm_km_suballoc() calls is always initialized.
ok pedro@


# 1.156 26-May-2007 pedro

Dynamic buffer cache. Initial diff from mickey@, okay art@ beck@ toby@
deraadt@ dlg@.


# 1.155 21-May-2007 kettenis

Add support for 8700/pcxw2 cpu.


# 1.154 21-May-2007 kettenis

Ask firmware for reset before trying ourselves; needed for four-digit b/c/j
workstations.

tested by otto@, krw@; ok deraadt@


# 1.153 17-May-2007 art

Limit hppa buffer cache to 30%. It used to be 70% because stack garbage
that was used for minaddr instead of the proper vm_map_min(kernel_map)
(fixed in this diff).

From mickey. art@ ok


# 1.152 14-May-2007 martin

move hppa to __HAVE_CPUINFO

input from miod@, ok kettenis@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.151 28-May-2006 martin

minor nit, use CPU ID instead of FPU ID for BTLB parameters after passing
all kludges


# 1.150 15-Apr-2006 martin

make warning about missing HPT support DEBUG for now

ok mickey@


Revision tags: OPENBSD_3_9_BASE
# 1.149 26-Oct-2005 martin

no more hppa_round_page() and hppa_trunc_page() macros

ok mickey@


Revision tags: OPENBSD_3_8_BASE
# 1.148 06-Aug-2005 miod

We do not need a char machine_arch[] constant.
ok deraadt@


# 1.147 11-Jul-2005 mickey

align some stupid comments


# 1.146 10-May-2005 mickey

set pcsq in case we get signal delivery once interrupted from the gateway page; from chs


# 1.145 18-Apr-2005 mickey

do not do some of the initmsgbuf()s job


# 1.144 07-Apr-2005 mickey

on some machines it's possible to limit the amount of physmem initialised dring post so having msgbuf at the end of memory shall work


# 1.143 07-Apr-2005 mickey

64bit-friendly pdc.h and iomod.h and correspondent changes elsewhere


# 1.142 26-Mar-2005 mickey

md parts for hpux_compa code; some problems w/ signals delivery still exist


Revision tags: OPENBSD_3_7_BASE
# 1.141 24-Feb-2005 mickey

do not even ask for btlb on 8k cpus as pdc pretends there is some but then it does not work; found w/ Moritz Kiese <mbk@mytum.de> on c180; add a debug print and fix pcxu entry


# 1.140 17-Nov-2004 mickey

print real/avail/bufcache sizes as unsigned


# 1.139 26-Oct-2004 mickey

disable sid hashing on pcxu and above


# 1.138 14-Oct-2004 mickey

a bit larger delays during boot() to let msgs appear


# 1.137 19-Sep-2004 mickey

turn totalphysmem into physmem and name old physmem into smth it really is


# 1.136 18-Sep-2004 mickey

oops


# 1.135 15-Sep-2004 mickey

add pcxu tlb handlers and cpu probing
add u2/uturn ioa driver in dumb mode now
enable pcxu/pcxw support


# 1.134 14-Sep-2004 mickey

store fpu version for later use. make sure to proper store/clear fpu state in fork/exec/exit/sendsig


# 1.133 14-Sep-2004 mickey

error out from btlb_insert() if there is none


Revision tags: OPENBSD_3_6_BASE
# 1.132 01-Jul-2004 mickey

have separate insn and data cache all-flushers


# 1.131 30-Jun-2004 mickey

allow forced fpu emulation through a sysctl


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.130 13-May-2004 mickey

8ks do not have hvt


# 1.129 05-May-2004 mickey

much easier tlb handler branch patching


# 1.128 05-May-2004 mickey

do not engage HPT on PCXT' (yet)


# 1.127 08-Apr-2004 mickey

repair pcxs/t confoosion


# 1.126 07-Apr-2004 mickey

update copyright; miod@ is fine w/ files where he holds it too


Revision tags: OPENBSD_3_5_BASE
# 1.125 10-Mar-2004 tom

Ensure that we obey a user's ddb> boot reboot command even if the system
is cold (during startup).

This adds RB_USERREQ to sys/reboot.h, uses it in the ddb commands, and
ensures that */*/machdep.c:boot() won't set RB_HALT when cold if this
flag is set.

ok deraadt@


# 1.124 14-Feb-2004 grange

Simplify hw.{cpuspeed,setperf} api moving all the sysctl stuff
from the underlying callbacks.

Testing hppa mickey@, ppc drahn@
Ok markus@ tedu@


# 1.123 05-Jan-2004 mickey

kill debugging code that is not needed anymore


# 1.122 23-Dec-2003 mickey

provide cpuspeed fluff


# 1.121 20-Dec-2003 miod

Don't let microtime() return a struct timeval with exactly 1000000 microseconds.


# 1.120 18-Dec-2003 mickey

spls do not protect cpu_itmr and thus time might jump back sometimes due to cpu_itmr modified to a higher value than a read itmr; found and testing by miod@


# 1.119 17-Dec-2003 mickey

in the real mem print do not include reserved for prom into used by openbsd


# 1.118 10-Dec-2003 mickey

for unaligned btlb mapping attempts -- just fail


# 1.117 24-Nov-2003 mickey

experimental support for HVT as a 2nd level tlb


# 1.116 15-Oct-2003 mickey

less global name space pollution


# 1.115 05-Oct-2003 mickey

reload the itmr as soon as we get the intr to avoid lagging on slower machines


# 1.114 25-Sep-2003 mickey

some pcxl2 do not report fpus -- assume it's there


Revision tags: OPENBSD_3_4_BASE
# 1.113 04-Sep-2003 mickey

a better cpu identification; testing by miod


# 1.112 31-Aug-2003 miod

pdc_model needs to be visible from cpu.c


# 1.111 20-Aug-2003 mickey

missing nl in debugging prontf


# 1.110 07-Aug-2003 mickey

dead proto


# 1.109 07-Aug-2003 mickey

first allocate space on stack then copyout signal shits. add a DEBUG check for a whacky user pc (as impossible due to the recent trap.c change)


# 1.108 03-Aug-2003 mickey

clear branch and nullify bits in psw on sending a signal


# 1.107 30-Jul-2003 mickey

deduce the leds address from the model number and thus make some more use of that lichtenblinkenschmutz on some more machinens


# 1.106 22-May-2003 mickey

imprecision in delay_init()


# 1.105 18-May-2003 mickey

save the fpu state for the signal handler. this is essential
as the fpu regs can be used by the gcc even for non-fpu
means and data copying.
rearrange the sigcontext a bit to include only the general
registers that are needed restoring upon return and thus
less waste of space and make up some space for the fpu regs.

ALL software that used the signal context on the stack
needs at least rebuilding now. a new snap has bin built as well.


Revision tags: UBC_SYNC_A
# 1.104 11-May-2003 deraadt

string cleaning; krw ok


# 1.103 07-Apr-2003 mickey

s/HP9000/HP 9000/; from weissmanndude


Revision tags: OPENBSD_3_3_BASE
# 1.102 18-Feb-2003 deraadt

knf; mickey ok


# 1.101 12-Feb-2003 jason

How uncommon... hppa only has one common: msgbufmapped (decl'd in /sys/kern)


# 1.100 12-Feb-2003 mickey

only align the first stack frame onto the minimal required alignment


# 1.99 10-Feb-2003 mickey

fix pcs and pcxt recognition. from weissmanndude


# 1.98 22-Jan-2003 mickey

consistantly use uvm_prot_* vs vm_prot_* evewrhere


# 1.97 14-Jan-2003 mickey

fix cutnpaste in the cpu table for the itlbna field; from herr weissmanndude


# 1.96 14-Jan-2003 mickey

need pdc_hwtlb always; pt out by herr weissmanndude


# 1.95 13-Jan-2003 mickey

fix the logic in hvt probing


# 1.94 09-Jan-2003 miod

Remove fetch(9) and store(9) functions from the kernel, and replace the few
remaining instances of them with appropriate copy(9) usage.

ok art@, tested on all arches unless my memory is non-ECC


# 1.93 19-Dec-2002 mickey

setregs: put the whole frame setup into one place


# 1.92 19-Dec-2002 mickey

level 0x16 is really an l2


# 1.91 17-Dec-2002 millert

Make SysV-style shared memory and semaphore limits sysctl'able.
Instead of allocating a static amount of memory for the data
structures via valloc() in allocsys(), allocate things dynamically
using pool(9) when possible and malloc(9) when not. The various
members of struct seminfo and struct shminfo are in kern.seminfo
and kern.shminfo respectively (not all members of kern.seminfo are
changable).

The data structures used still leave something to be desired but
things are not made worse in that respect by this commit.


# 1.90 27-Nov-2002 mickey

no wrapper arounf hardclock(), use CPU_CLOCKUPDATE, real microtime; miod ok


# 1.89 08-Nov-2002 mickey

Don't uvm_useracc the user sigcontext in sys_sigreturn and then access
the user addresses directly from the kernel. copyin is faster and can
correctly deal properly with mappings that uvm_useracc thinks are
correct but will fault anyway (to figure out how to generate such
mappings is left as en excercise for the reader).


# 1.88 01-Nov-2002 mickey

add a missing delay after printf on halt[-p], proper arg for a cold hook


Revision tags: UBC_SYNC_B
# 1.87 22-Oct-2002 mickey

do not force single-user; pt out by fries@


# 1.86 15-Oct-2002 mickey

missing initmsgbuf(), noticed by miod@


# 1.85 13-Oct-2002 mickey

track the end of physmem for use in dmmem_alloc


# 1.84 07-Oct-2002 mickey

s/PSW_/PSL_/ to match other archs


# 1.83 07-Oct-2002 mickey

proper terminate the user stack on signal


# 1.82 07-Oct-2002 mickey

on implementations w/ fpu included unimplemented instructions
are signaled through the exception trap w/ invalid opcode marked
instruction in the exception registers, not through the emulation
trap (as long as the fpu is enabled, of course).
parse emulation from the exception trap as well as the emulation
trap and fix the dispatcher into usable condition.
parse invalid op exception on trap and signal the user appropriately.
reset the exception on exec and for child on fork.
the later is appropriate since exceptions are delayed until next
fpu instruction, which was in the parent indeed, let him get it.
save parent's fpu context on fork before cipying it, if the
parent owned the fpu.


Revision tags: OPENBSD_3_2_BASE
# 1.81 23-Sep-2002 mickey

parisc level 0x10 is just an overclocked 0xe


# 1.80 17-Sep-2002 mickey

handle fpu exceptions properly, might use a regress, i guess


# 1.79 11-Sep-2002 mickey

provide a convinient reset label


# 1.78 11-Sep-2002 mickey

stack grows the other way, but the frame is the other way to that. hehe


# 1.77 09-Sep-2002 mickey

set up the frame flags and a user frame better on exec


# 1.76 03-Aug-2002 mickey

rework boot() w/o a goto


# 1.75 25-Jul-2002 mickey

missing arg in the call to the pdc_call since some old times


# 1.74 25-Jul-2002 mickey

kcopy is a space-to-space copy from kernel space, to guess where, -- to the same kernel space, just error on fault


# 1.73 20-Jul-2002 art

Instead of copying out the signal trampoline on top of the stack, create
an uvm aobj, copy out the signal trampoline into it and share that page
among all processes for the same emulation.

This also requires us to actually be able to tell signal code where the
trampoline is located, so introduce a new field in struct proc - p_sigcode
that is a pointer to sigcode. This allows us to remove all the ugly
calculations of the signal trampoline address done in every sendsig
function in the tree (that's why so many files are changed).

Tested by various people. ok deraadt@


# 1.72 14-May-2002 mickey

disable sid hashing while still in real mode, alos print the parisc arch once and not per each cpu since they are not intermixable architecture-wise


# 1.71 13-May-2002 mickey

ldi-ldo whatever was in the table, be that much clever


# 1.70 08-May-2002 mickey

print parisc level w/ the the parisc version, not for each cpu


# 1.69 08-May-2002 mickey

kill debugging printfski


# 1.68 22-Apr-2002 mickey

no longer batc the data, only the code.
this removes a constraint and an ld.script dependancy
for the .data and the dynamically allocated kernel
structures existed w/ batcing. also makes pmap_steal_memory
obsolete and replaced w/ the pmap_virtual_space.
implement batching for pmap_remove to avoid
zeroing out the pte entries if pde will be removed anyway.


# 1.67 21-Apr-2002 mickey

better buf's mapping and less magic constants in checking for io space cachability


Revision tags: OPENBSD_3_1_BASE
# 1.66 26-Mar-2002 mickey

if cannot guess cpu model default to the lowest supported one


# 1.65 25-Mar-2002 deraadt

spelling


# 1.64 23-Mar-2002 espie

Add variables for config(8) -e time tweak of systemV shared memory
parameters.

Ok millert@, miod@, maja@


# 1.63 19-Mar-2002 mickey

mtcpu seq requires a pre-sync, implement hpt init for pcxl


# 1.62 15-Mar-2002 mickey

rewrite a pmap to use multilevel page tables.
lower 12 bits contain the perms, no unused bits left,
but a couple for off-tlb use (as the ref implemented now).
do not use the hvt, which might get some use later
if proven to speed thigs up, tlb handlers would po
another dozen of insns though, but if that's worth its...
move on the data seg and map kernel text rdonly (idea form fredette),
since all of the page0 mods done before that we are all fine
except for some viper fluff, but later w/ that.
this also picks up a bit more of ddb magic for bpt and ss.
tlb handlers can use a little bit more of attention,
but things, visually, seem to be much faster already, --
sorry, no benchmarks for now.

* effort sponsored in part by the `henry st. old ale house'
* and mr.pete and mr.lee in particular in thier generous entrirety.
* the proj took a little more that 72man*h as it was expected,
* but within murhy's law estimations.


# 1.61 14-Mar-2002 millert

First round of __P removal in sys


# 1.60 20-Feb-2002 mickey

setup power failure handler (for sw-controlled power button), move toc handler


# 1.59 17-Feb-2002 maja

Patch from Daniel Lucq <daniel@lucq.org>

The patch allows you to change the value of NMBCLUSTERS, BUFCACHEPERCENT
and NKMEMPAGES using the config command, instead of recompiling the kernel.

This is the kernel part of the patch. I have compiled it on i386, sparc64,
alpha and macppc. -moj ok art@ maja@


# 1.58 12-Feb-2002 mickey

support 712's programmable power switch, no interrupt yet


# 1.57 12-Feb-2002 mickey

small repairs to hpmc and toc handlers


# 1.56 11-Feb-2002 mickey

disable fpu on csw, print fpu version on cpu line, if present


# 1.55 07-Feb-2002 mickey

fix sigdebug cases; init sigcontext before it's used (;


# 1.54 06-Feb-2002 mickey

implement signal delivery; based on fredette@'s work


# 1.53 03-Feb-2002 mickey

restore hpt size computation, does not break things as i thought


# 1.52 02-Feb-2002 mickey

fix 'physmem' usage


# 1.51 02-Feb-2002 mickey

implement the rest of /dev/mem devices; from netbsd


# 1.50 23-Jan-2002 art

move mb_map allocation to mbinit()


# 1.49 23-Jan-2002 art

move definition of mb_map from zillions of machdep.c to uipc_mbuf.c


# 1.48 16-Jan-2002 miod

Don't include <sys/map.h> when you don't need what's in it.


Revision tags: UBC_BASE
# 1.47 02-Dec-2001 mickey

branches: 1.47.2;
increase fixed extent storage


# 1.46 28-Nov-2001 art

zap some typedefs.
vm_map_t -> struct vm_map *
vm_map_entry_t -> struct vm_map_entry *
simple_lock_data_t -> struct simplelock

(uvm not done yet, coming in the next commit)


# 1.45 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.44 24-Nov-2001 miod

Harmonize boot() logic across arches:
- ensure RB_DUMP | RB_HALT will cause a dump
- or RB_HALT if (cold)
While there, honor RB_TIMEBAD on sparc64.


# 1.43 09-Nov-2001 art

nswbuf hasn't been used for ages. gc.


# 1.42 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.41 06-Nov-2001 miod

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


Revision tags: OPENBSD_3_0_BASE
# 1.40 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.39 12-Sep-2001 art

mbutl no more


# 1.38 23-Aug-2001 art

We can now move timeout_init into main().


# 1.37 23-Aug-2001 art

Remove even more old timeout tentacles.


# 1.36 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.35 05-Jul-2001 art

Get rid of REAL_CLISTS. It was never implemented and the tentacles are
everywhhere.


# 1.34 17-May-2001 provos

convert mbuf and cluster allocation to pool, mostly from NetBSD
okay art@ miod@


# 1.33 05-May-2001 art

Rename configure() to cpu_configure().
Move it from cpu_startup() to main().


# 1.32 05-May-2001 art

Get rid of CLSIZE and all related stuff.
CLSIZE -> 1
CLBYTES -> PAGE_SIZE
OLOFSET -> PAGE_MASK
etc.
At the same time some archs needed some cleaning in vmparam.h so that
goes in at the same time.


Revision tags: OPENBSD_2_9_BASE
# 1.31 29-Mar-2001 mickey

cpudev_data.h here needed not


# 1.30 22-Mar-2001 mickey

shuffle the tlb handlers a little,
make a new one for na data fault,
since those w/ hpt need it.


Revision tags: OPENBSD_2_8_BASE
# 1.29 15-Aug-2000 mickey

two btlb routines (i & d) for pcxs


# 1.28 15-Aug-2000 mickey

expand per-cpu control routines switch


# 1.27 08-Aug-2000 mickey

print btlb params w/ BTLBDEBUG; from Havard.Eidnes@runit.sintef.no


# 1.26 02-Jul-2000 mickey

no bays for stinger


Revision tags: OPENBSD_2_7_BASE
# 1.25 23-Mar-2000 mickey

new cpu type switch code.
initializes tlb miss handlers correspondent to probed cpu features.
also btlb load routine.
versions written are for pcxl and others.
cpu-dep btlb loaders are missing, only generic for now.


# 1.24 23-Mar-2000 art

New API for timeouts. Replaces the old timeout()/untimeout() API and
makes it the callers responsibility to allocate resources for the
timeouts.

This is a KISS implementation and does _not_ solve the problems of slow
handling of a large number of pending timeouts (this will be solved in
future work) (although hardclock is now guarateed to take constant time
for handling of timeouts).

Old timeout() and untimeout() are implemented as wrappers around the new
API and kept for compatibility. They will be removed as soon as all
subsystems are converted to use the new API.


# 1.23 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


# 1.22 22-Feb-2000 mickey

blah, blah, blah, msgbuf


Revision tags: SMP_BASE
# 1.21 09-Feb-2000 mickey

branches: 1.21.2;
heartbeat -- yeah we have a patch for that


# 1.20 25-Jan-2000 mickey

better copy and zero inlines in locore;
proper setregs() in machedep;
start of hpmc handler;
some cleanup here and there;


# 1.19 17-Jan-2000 mickey

remove unneeded stuff from setregs; force single-user for now, enable signal debug


# 1.18 11-Jan-2000 mickey

s/fpu_curproc/fpu_curpcb/ which also points into physical.
move it's definition into locore (where it's used the most).
adjust fpu context switch and save on swapout accordingly.
fix context save (in switch).
add accounting for fpu context switches (since it differes
from proc switching, we might get provided w/ some usefull
numbers as to how effective this lazy switch technique is).
enable handling fpu/sfu exceptions.


# 1.17 31-Dec-1999 mickey

don't bother about pidr3 and pidr4


# 1.16 17-Dec-1999 mickey

fix the panic message for sti memory mapping


Revision tags: kame_19991208
# 1.15 25-Nov-1999 mickey

bus stuff is in mainbus now, the rest is rewritten many ways


Revision tags: OPENBSD_2_6_BASE
# 1.14 20-Sep-1999 mickey

fix uvm_pagealloc() call


# 1.13 03-Sep-1999 art

Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.12 14-Aug-1999 mickey

proper debugging ifdefs


# 1.11 21-Jul-1999 mickey

rewrite the tlb miss handler and tlb dirty handler.
optimize for HVT usage (when compiled for proper cpu type).
drop hpt_* global variables, use info from control registers instead.
there are still ways to improve the tlb handlers tho.
machdep also prints cache and tlb coherence states (not related to the above).
You eat greenish muffin. --More-- You write real code.


# 1.10 12-Jul-1999 mickey

allocate 5% bufcache if <=16M memory installed


# 1.9 12-Jun-1999 mickey

hppa_init() now takes an argument from locore,
meaning the start of available memory.
cleanup machdep somewhat.
fix vm_map.pmap vs vm_pmap isue; 10x art@


# 1.8 23-May-1999 mickey

new swap stuff


# 1.7 21-May-1999 mickey

group all theMD f;ags together, add interrupt recursion one


# 1.6 21-May-1999 mickey

define fpu_curproc


# 1.5 20-Apr-1999 mickey

do lazy blok mapping of io space in bus_*
add copy{in,out}*, kcopy, etc
boot routines
cpu-id-hpux-compat stuff
rest of scheduler and such
uvm


Revision tags: OPENBSD_2_5_BASE
# 1.4 17-Feb-1999 mickey

print pa-risc here as well, since, finally, cpu will have to print processor type


# 1.3 04-Jan-1999 mickey

better cache handling in bus_space_barrier(), seem to work now


# 1.2 03-Jan-1999 mickey

implement bus_space_{un,}map w/ extents


# 1.1 30-Dec-1998 mickey

machdep; more work needed


# 1.258 16-May-2020 kettenis

Make inittodr() and resettodr() MI.

ok deraadt@, mpi@, visa@
ok cheloha@ as well (would have preferred in new file for this code)


# 1.257 11-May-2020 kettenis

Initialize the timeval passed to todr_gettime() with the base time from
the file system such that implementations can use it to guess the right
century.

ok mpi@


Revision tags: OPENBSD_6_7_BASE
# 1.256 01-May-2020 kettenis

Use the same inittodr()/resettodr() implementation as on
amd64/arm64/armv7/i386/sparc64 and move it to the end of machdep.c. Rework the
actual implementation for the MC14818 compatible RTC into something that can
be used as a todr_handle just like on amd64.

ok mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.255 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


Revision tags: OPENBSD_6_4_BASE
# 1.254 20-Jul-2018 guenther

Missed a 'ksi' -> '*ksip' change in previous commit


# 1.253 10-Jul-2018 guenther

Move from sendsig() to its callers the initsiginfo() calls and
instead of passing sendsig() the code+type+val, pass a siginfo_t*
to copy from. Eliminate the indirection through struct emul for
sendsig(); we no longer have a SunOS4-compat version of sendsig()

ok deraadt@


# 1.252 22-May-2018 guenther

Delete antique sigdebug definitions

ok kettenis@


# 1.251 12-Apr-2018 deraadt

Implement MAP_STACK option for mmap(). Synchronous faults (pagefault and
syscall) confirm the stack register points at MAP_STACK memory, otherwise
SIGSEGV is delivered. sigaltstack() and pthread_attr_setstack() are modified
to create a MAP_STACK sub-region which satisfies alignment requirements.
Observe that MAP_STACK can only be set/cleared by mmap(), which zeroes the
contents of the region -- there is no mprotect() equivalent operation, so
there is no MAP_STACK-adding gadget.
This opportunistic software-emulation of a stack protection bit makes
stack-pivot operations during ROPchain fragile (kind of like removing a
tool from the toolbox).
original discussion with tedu, uvm work by stefan, testing by mortimer
ok kettenis


Revision tags: OPENBSD_6_3_BASE
# 1.250 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.249 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


Revision tags: OPENBSD_6_2_BASE
# 1.248 18-May-2017 kettenis

Implement copyin32(9).

"your chicken scratches look fine to me" deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.247 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

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


# 1.246 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.245 21-May-2016 deraadt

hand-massage sendsig() and sys_sigreturn() to be much more similar.
ok guenther kettenis


# 1.244 10-May-2016 deraadt

SROP mitigation. sendsig() stores a (per-process ^ &sigcontext) cookie
inside the sigcontext. sigreturn(2) checks syscall entry was from the
exact PC addr in the (per-process ASLR) sigtramp, verifies the cookie,
and clears it to prevent sigcontext reuse.
not yet tested on landisk, sparc, *88k, socppc.
ok kettenis


# 1.243 20-Apr-2016 dlg

pool_setipl for floating point context things

ok kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.242 21-Oct-2015 mpi

Do not call uvm_swap_finicrypt_all() a second time in dumpsys().

ok tedu@, deraadt@, miod@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.241 20-Jan-2015 kettenis

Move ps_strings "after" the random stackgap. This makes its location a
per-process value, and therefpore turns the VM_PSSTRINGS sysctl into a
per-process one as well. This gets rid of a pointer to the bottom of the
stack at a fixed location. Also clears the road for unmapping the stackgap.

ok deraadt@


# 1.240 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.239 25-Oct-2014 kettenis

Remove vmmap; it isn't used.

ok jsing@


# 1.238 23-Oct-2014 miod

Correctly set up the HPMC trap entry: according to the PA-RISC Firmware
Architecture Reference Specification, the sum of the 8 trap entry words
*and* of the payload which address and length are to be set at well-known
positions in the aforementioned trap entry, needs to be zero; the existing
code was only enforcing that the sum of the trap entry words is zero.

This matches what Linux and NetBSD do.

ok kettenis@


# 1.237 23-Oct-2014 miod

Revert limiting physmem to 2GB; the culprit was likely in uvm and uvm has
changed a lot in the last 5 years; verified to work on a 3GB system, in
snapshots for a few weeks already.


# 1.236 22-Sep-2014 dlg

implement atomic_{cas,swap}_{uint,ulong,ptr} and
atomic_{add,sub}_{int,long}_nv. sys/atomic.h turns these into the
rest of the atomic api.

on uniprocessor hppa systems "atomic" operations are implemented
as a non-interruptable sequence by disabling all interrupts on the
cpu, doing the operation, and then restoring the interrupt mask.

this isnt enough on MP systems, so we added a global atomic memory
mutex that is taken inside the interrupt disabling above to coordinate
operations between cpus.

this is a lot of overhead though cos mutexes dance around with ipls,
which is unecessary in our case because of the interrupt disabling
that is already done. also, hppa spinlocks are implemented with
ldcw which requires the word it operates on to be 16 byte aligned.
mutexes arent guaranteed to have this alignment so they compensate
by having lots of words inside themselves so they can hit the
appropriate one to use for the ldcw op.

with this in mind, this change pulls __cpu_simple_locks, which are
simply ldcw spinlocks with a 16 byte aligned word, out of
src/sys/arch/hppa/include/lock.h into src/sys/arch/hppa/include/atomic.h
so atomic.h can use them. lock.h includes atomic.h, so it still
gets and provides the same functionality as before.

finally, this also pulls the rwlock cas implementation apart. cas
ops now share the same serialising lock on MP systems as the other
memory operations, and rw_cas is defined as a wrapper around
atomic_cas_uint.

ok kettenis@


# 1.235 19-Sep-2014 kettenis

Use config_suspend_all(9).


# 1.234 18-Aug-2014 dlg

dont rely on mbuf.h to provide pool.h.

ok miod@, who has offerred to help with any MD fallout
ok guenther@


Revision tags: OPENBSD_5_6_BASE
# 1.233 22-Jul-2014 uebayasi

boot(9): Reduce diffs between hppa & hppa64 (& others)


# 1.232 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.231 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.230 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.229 13-Jul-2014 miod

These still need <sys/reboot.h> for the RB_ constants.


# 1.228 12-Jul-2014 uebayasi

reboot(9), panic(9): Call panic(9) for unrecoverable MD H/W errors (NMIs)

Some architectures have ability to detect hardware sanity and notify system
(NMI, firmware callback, etc.). Handle these hardware severe errors, same
as software errors, with panic(9).

According to miod@, SGI IP27 NMI is triggered by pushing some "hidden" button,
which "usual" users/admins don't know. Pushing such a button is "RB_USERREQ"
(human-triggered) in that the button is pushed by a human, but not "RB_USERREQ"
in that no user intervention in system (== no command input) is done. miod@
agreed that changing these from RB_USERREQ to !RB_USERREQ (== panic(9)) is
not a big problem.

OK miod@ kettenis@


# 1.227 12-Jul-2014 uebayasi

boot(9), reboot(9): Migrate MD callers of boot(9) to reboot(9)

I have found that some ports call boot(9) from machine-dependent code to
reboot system. These should be changed to either:

- Sending signal to init(8) to trigger it to shutdown system cleanly, like
acpi(4) does, in cases where found problems don't prevent system from working
immediately, or

- Just doing panic(9) if the situation is severely broken.

For now, just rewrite boot() to reboot(). Actual fixes follow.

Discussed with & OK from kettenis@


# 1.226 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.225 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.224 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.223 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.222 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.221 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.220 08-May-2014 miod

Format string fixes and removal of -Wno-format for hppa kernels.


# 1.219 08-Apr-2014 mpi

Less <uvm/uvm.h>


# 1.218 04-Apr-2014 miod

If the PDC_COPROC call fails, and we are running on a PA 1.1 system, assume
the usual 1.1 coprocessor mask, instead of using zero and having every
userland process dying with signal 4.

The circumstances under which this call fails are unclear and could be
tied to specific PROM version (I have tried overzealous stack alignment and
other tricks, to no avail). Interestingly enough, the 715/75 system which
hits this problem, only triggers it when booting from disk, and never when
booting from network.

This diff is an ugly bandaid until the problem is better understood. Or maybe
it is not worth investigating, seeing that Linux hardcodes the coprocessor
mask and never issues PDC_COPROC calls; I wonder what HP/UX does.

In my tree for over 18 months; "Looks like a nice hack" deraadt@
715/75 system provided by Sebastiaan Indesteege, thanks!


# 1.217 29-Mar-2014 guenther

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

ok dlg@ mpi@ deraadt@


# 1.216 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


# 1.215 22-Mar-2014 guenther

Move p_sigacts from struct proc to struct process.

testing help mpi@


# 1.214 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


Revision tags: OPENBSD_5_5_BASE
# 1.213 23-Nov-2013 uebayasi

Run doshutdownhooks() and config_suspend() even when boot() is called while
cold != 0. Indent and make hppa/hppa64 boot() closer to others.

OK kettenis@


# 1.212 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


Revision tags: OPENBSD_5_4_BASE
# 1.211 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


Revision tags: OPENBSD_5_3_BASE
# 1.210 02-Dec-2012 guenther

Determine whether we're currently on the alternative signal stack
dynamically, by comparing the stack pointer against the altstack
base and size, so that you get the correct answer if you longjmp
out of the signal handler, as tested by regress/sys/kern/stackjmp/.
Also, fix alt stack handling on vax, where it was completely broken.

Testing and corrections by miod@, krw@, tobiasu@, pirofti@


# 1.209 26-Oct-2012 kettenis

Properly clear trap frame in setregs() to avoid leaking registers across exec.

ok jsing@


# 1.208 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.207 07-Oct-2012 kettenis

Align the stack on a 64-byte boundary as required by "The 32-bit PA-RISC
Run-time Architecture Document". GCC relies on this to properly align
stack variables.

ok guenther@, beck@


Revision tags: OPENBSD_5_2_BASE
# 1.206 21-Jun-2012 guenther

__tfork() needs to set the stack address of the new thread in the kernel,
so that it can't get a signal while still running on the parent thread's
stack. Also, pass in sizeof(struct __tfork) to provide forward compat
when more members are added. This is an ABI change, so switch syscall
numbers and bump lib majors this time.

ok deraadt@ matthew@


Revision tags: OPENBSD_5_1_BASE
# 1.205 20-Sep-2011 miod

Clear RB_POWERDOWN early in boot() on systems which can not powerdown and
which firmware does not send spin up commands to the disks, in case the
operator changes his mind and reboots instead of manually powering down
after the system has halted.
ok kettenis@


Revision tags: OPENBSD_5_0_BASE
# 1.204 05-Jul-2011 guenther

Recommit the reverted sigacts change now that the NFS use-after-free
problem has been tracked down. This fixes the sharing of the signal
handling state: shared bits go in sigacts, per-rthread bits goes in
struct proc.

ok deraadt@


# 1.203 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.202 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.201 18-Apr-2011 guenther

Revert the sigacts diff: NFS can apparently retain pointers to processes
until they're zombies and then send them signals (for intr mounts). Until
that is untangled, the sigacts change is unsafe. sthen@ was the victim
for this one


# 1.200 15-Apr-2011 guenther

Correct the sharing of the signal handling state: stuff that should
be shared (p_sigignore, p_sigcatch, P_NOCLDSTOP, P_NOCLDWAIT) moves
to struct sigacts, wihle stuff that should be per rthread (ps_oldmask,
SAS_OLDMASK, ps_sigstk) moves to struct proc. Treat the coredumping
state bits (ps_sig, ps_code, ps_type, ps_sigval) as per-rthread
until our locking around coredumping is better.

Oh, and remove the old SunOS-compat ps_usertramp member.

"I like the sound of this" tedu@


Revision tags: OPENBSD_4_9_BASE
# 1.199 14-Jan-2011 jsing

Halt secondary CPUs when shutting down or rebooting. This should prevent
occasional hangs during reboot.

ok kettenis@


# 1.198 04-Jan-2011 jasper

- de-register. no binary change.

ok jsing@


# 1.197 01-Jan-2011 jasper

Move setting cpu_hzticks to the clock initialization function, like
other ports (e.g. hppa64) do.

ok jsing@ kettenis@


# 1.196 01-Jan-2011 jasper

- ansify

ok jsing@ kettenis@


# 1.195 30-Dec-2010 jsing

Turn signotify() into a function that also calls cpu_unidle().

ok kettenis@


# 1.194 20-Nov-2010 miod

This is a first step towards getting rid of avail_start and avail_end in the
kernel, currently limited to low-hanging fruit: these variables were used
by bus_dma to specify the range in which to allocate memory, back when
uvm_pglistalloc() was stupid and would not walk the vm_physseg[].

Nowadays, except on some platforms for early initialization, these variables
are not used, or do not need to be global variables. Therefore:
- remove `extern' declarations of avail_start and avail_end (or close cousins,
such as arm physical_start and physical_end) from files which no longer need
to use them.
- make them local variables whenever possible.
- remove them when they are assigned to but no longer used.


Revision tags: OPENBSD_4_8_BASE
# 1.193 01-Jul-2010 jsing

Create a struct to store FP state and include a pointer to the CPU that
currently holds the FPU context for this process. This will be soon used
to implement FPU shootdowns on multiprocessor kernels.

ok kettenis@


# 1.192 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.191 29-Jun-2010 jsing

Factor out code used to save and flushe process FPU context.

ok kettenis@


# 1.190 29-Jun-2010 jsing

Store pointer to process FPU state in struct cpu_info.

ok kettenis@


# 1.189 27-Jun-2010 thib

uvm constraints. Add two mandatory MD symbols, uvm_md_constraints
which contains the constraints for DMA/memory allocation for each
architecture, and dma_constraints which contains the range of addresses
that are dma accessable by the system.

This is based on ariane@'s physcontig diff, with lots of bugfixes and
additions the following additions by my self:

Introduce a new function pool_set_constraints() which sets the address
range for which we allocate pages for the pool from, this is now used
for the mbuf/mbuf cluster pools to keep them dma accessible.

The !direct archs no longer stuff pages into the kernel object in
uvm_km_getpage_pla but rather do a pmap_extract() in uvm_km_putpages.

Tested heavily by my self on i386, amd64 and sparc64. Some tests on
alpha and SGI.

"commit it" beck, art, oga, deraadt
"i like the diff" deraadt


# 1.188 27-Jun-2010 jsing

Use a mutex to make atomic operations atomic on multiprocessor kernels.

ok kettenis@


# 1.187 10-Jun-2010 deraadt

Declare safepri at the MD level on each platform, so that the kern_synch.c
does not have to deal with it as a common. Some platforms may be missed
by this commit... if you spot one, fix it the same way.
ok miod


# 1.186 09-Jun-2010 miod

Move declaration of cn_tab from dev/cons.c to dev/cninit.c, or appropriate
md files for ports which do not use dev/cninit.c. This gets rid of a common
at kernel link time.
feedback drahn@ ok deraadt@


# 1.185 24-May-2010 deraadt

Add missing prototypes
ok jsing kettenis


# 1.184 09-May-2010 kettenis

Prevent "taken branch" exceptions from kernel space by clearing the PSL_T
bit before we enter a signal handler.

"if you say so" miod@, "seems to make sense" jsing@


# 1.183 02-May-2010 kettenis

Properly initialize the members of `struct mdproc' that deal with
single-stepping when we fork and reset them upon exec.

ok miod@


# 1.182 27-Apr-2010 kettenis

Avoid null-pointer dereference by giving proc0 a place to store its
floating-point registers. Pointed out by Nick Hudson.

ok miod@, jsing@


# 1.181 19-Apr-2010 jsing

Make the Processor Status Word (PSW) a per-CPU value.

ok kettenis@


# 1.180 01-Apr-2010 jsing

Allow for multiple CPUs by moving to an array of cpu_info.

ok kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.179 31-Dec-2009 jsing

Make cpl and cpu_inintr per CPU variables. For locore.S, cpl becomes an
offset within cpu_primary_info - this will need to be revisited shortly.

ok kettenis@


# 1.178 11-Aug-2009 miod

Do not bother initializing bufpages in the md code if the computation is
exactly the same the mi could will use if bufinit() is invoked with
bufpages == 0.


# 1.177 11-Aug-2009 miod

With the SysV memory allocation changes, allocsys() doesn't do anything
anymore. Get rid of it completely.


# 1.176 09-Aug-2009 blambert

Rototill system V message queues.

No longer allocate a static amount of memory for messages in MD
boot path; message queues, message metadata, and message data now
all use dynamic memory, which means that runtime sysctls should now
be trivial to implement.

Since I'm going to be around all week to fix any breakage, this should
probably just go in now.


# 1.175 02-Aug-2009 beck

Dynamic buffer cache support - a re-commit of what was backed out
after c2k9

allows buffer cache to be extended and grow/shrink dynamically

tested by many, ok oga@, "why not just commit it" deraadt@


# 1.174 29-Jul-2009 kettenis

Get rid of non-equivalent aliases of the pcb by moving the fpu state out
of the pcb and using the p_addr member of 'struct proc' to calculate the
address of the kernel stack when switching to virtual mode after taking a trap.
Remove the now unecessary cache flushes; they're actually harmful since they
create non-equivalent aliases. This seems to fix the memory corruption we
have been observing from time to time.

This diff does not rename fpu_curpcb, which is now somewhat incorrectly named.
I hope to change things back again as soon as we are able to map the pcb 1:1.


Revision tags: OPENBSD_4_6_BASE
# 1.173 15-Jun-2009 beck

Back out all the buffer cache changes I committed during c2k9. This reverts three
commits:

1) The sysctl allowing bufcachepercent to be changed at boot time.
2) The change moving the buffer cache hash chains to a red-black tree
3) The dynamic buffer cache (Which depended on the earlier too).

ok on the backout from marco and todd


# 1.172 03-Jun-2009 beck

add kern.bufcachepercent sysctl to allow adjusting the buffer cache
size on a running system.
ok art@, oga@


Revision tags: OPENBSD_4_5_BASE
# 1.171 14-Feb-2009 kettenis

Limit the amount of physical memory to 2GB. Using more causes memory
corruption on PA-RISC 2.0 systems (and there are very few PA-RISC 1.1
systems that support more than 2GB).

ok miod@


# 1.170 04-Feb-2009 miod

On systems with split BTLB, do not bother trying to insert DBTLB entries,
as PDC will lie to us pretending it did while it didn't.

ok kettenis@


# 1.169 04-Feb-2009 miod

Unify memory size reports a bit more: always report size in MB, and report
reserved memory on alpha and hppa on its own line (as done on sgi).


Revision tags: OPENBSD_4_4_BASE
# 1.168 14-Jul-2008 miod

Be sure to propagate PSL_O in psw on PCXU* processors to userland processes
and signal handlers.
ok kettenis@


# 1.167 27-Jun-2008 miod

Clear swap encryption keys before dumping a kernel image.


# 1.166 09-Apr-2008 deraadt

Add new stub uvm_shutdown() and call it from the right place in MD boot()


Revision tags: OPENBSD_4_3_BASE
# 1.165 22-Sep-2007 martin

replace even more ctob and btoc with ptoa and atop respectively plus
uvm_extern.h where needed


Revision tags: OPENBSD_4_2_BASE
# 1.164 22-Jul-2007 kettenis

Move hppa to __HAVE_TIMECOUNTERS.


# 1.163 20-Jul-2007 kettenis

Give hppa the blink_led API from sparc64, and the associated machdep.led_blink
sysctl.


# 1.162 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.161 14-Jul-2007 kettenis

Make sigreturn(2) set the proper space ID for the instruction queue. Fixes
a few more pthreads regression tests.

ok miod@


# 1.160 10-Jul-2007 kettenis

Don't trust the privilige level in the sigcontext passed to sigreturn(2).

ok miod@


# 1.159 24-Jun-2007 kettenis

Crank initial storage for extents a bit. We really should allocate extents
using malloc once vm is initialised, but this will do for now.

ok deraadt@


# 1.158 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.157 27-May-2007 miod

Make sure the minaddr hint for uvm_km_suballoc() calls is always initialized.
ok pedro@


# 1.156 26-May-2007 pedro

Dynamic buffer cache. Initial diff from mickey@, okay art@ beck@ toby@
deraadt@ dlg@.


# 1.155 21-May-2007 kettenis

Add support for 8700/pcxw2 cpu.


# 1.154 21-May-2007 kettenis

Ask firmware for reset before trying ourselves; needed for four-digit b/c/j
workstations.

tested by otto@, krw@; ok deraadt@


# 1.153 17-May-2007 art

Limit hppa buffer cache to 30%. It used to be 70% because stack garbage
that was used for minaddr instead of the proper vm_map_min(kernel_map)
(fixed in this diff).

From mickey. art@ ok


# 1.152 14-May-2007 martin

move hppa to __HAVE_CPUINFO

input from miod@, ok kettenis@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.151 28-May-2006 martin

minor nit, use CPU ID instead of FPU ID for BTLB parameters after passing
all kludges


# 1.150 15-Apr-2006 martin

make warning about missing HPT support DEBUG for now

ok mickey@


Revision tags: OPENBSD_3_9_BASE
# 1.149 26-Oct-2005 martin

no more hppa_round_page() and hppa_trunc_page() macros

ok mickey@


Revision tags: OPENBSD_3_8_BASE
# 1.148 06-Aug-2005 miod

We do not need a char machine_arch[] constant.
ok deraadt@


# 1.147 11-Jul-2005 mickey

align some stupid comments


# 1.146 10-May-2005 mickey

set pcsq in case we get signal delivery once interrupted from the gateway page; from chs


# 1.145 18-Apr-2005 mickey

do not do some of the initmsgbuf()s job


# 1.144 07-Apr-2005 mickey

on some machines it's possible to limit the amount of physmem initialised dring post so having msgbuf at the end of memory shall work


# 1.143 07-Apr-2005 mickey

64bit-friendly pdc.h and iomod.h and correspondent changes elsewhere


# 1.142 26-Mar-2005 mickey

md parts for hpux_compa code; some problems w/ signals delivery still exist


Revision tags: OPENBSD_3_7_BASE
# 1.141 24-Feb-2005 mickey

do not even ask for btlb on 8k cpus as pdc pretends there is some but then it does not work; found w/ Moritz Kiese <mbk@mytum.de> on c180; add a debug print and fix pcxu entry


# 1.140 17-Nov-2004 mickey

print real/avail/bufcache sizes as unsigned


# 1.139 26-Oct-2004 mickey

disable sid hashing on pcxu and above


# 1.138 14-Oct-2004 mickey

a bit larger delays during boot() to let msgs appear


# 1.137 19-Sep-2004 mickey

turn totalphysmem into physmem and name old physmem into smth it really is


# 1.136 18-Sep-2004 mickey

oops


# 1.135 15-Sep-2004 mickey

add pcxu tlb handlers and cpu probing
add u2/uturn ioa driver in dumb mode now
enable pcxu/pcxw support


# 1.134 14-Sep-2004 mickey

store fpu version for later use. make sure to proper store/clear fpu state in fork/exec/exit/sendsig


# 1.133 14-Sep-2004 mickey

error out from btlb_insert() if there is none


Revision tags: OPENBSD_3_6_BASE
# 1.132 01-Jul-2004 mickey

have separate insn and data cache all-flushers


# 1.131 30-Jun-2004 mickey

allow forced fpu emulation through a sysctl


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.130 13-May-2004 mickey

8ks do not have hvt


# 1.129 05-May-2004 mickey

much easier tlb handler branch patching


# 1.128 05-May-2004 mickey

do not engage HPT on PCXT' (yet)


# 1.127 08-Apr-2004 mickey

repair pcxs/t confoosion


# 1.126 07-Apr-2004 mickey

update copyright; miod@ is fine w/ files where he holds it too


Revision tags: OPENBSD_3_5_BASE
# 1.125 10-Mar-2004 tom

Ensure that we obey a user's ddb> boot reboot command even if the system
is cold (during startup).

This adds RB_USERREQ to sys/reboot.h, uses it in the ddb commands, and
ensures that */*/machdep.c:boot() won't set RB_HALT when cold if this
flag is set.

ok deraadt@


# 1.124 14-Feb-2004 grange

Simplify hw.{cpuspeed,setperf} api moving all the sysctl stuff
from the underlying callbacks.

Testing hppa mickey@, ppc drahn@
Ok markus@ tedu@


# 1.123 05-Jan-2004 mickey

kill debugging code that is not needed anymore


# 1.122 23-Dec-2003 mickey

provide cpuspeed fluff


# 1.121 20-Dec-2003 miod

Don't let microtime() return a struct timeval with exactly 1000000 microseconds.


# 1.120 18-Dec-2003 mickey

spls do not protect cpu_itmr and thus time might jump back sometimes due to cpu_itmr modified to a higher value than a read itmr; found and testing by miod@


# 1.119 17-Dec-2003 mickey

in the real mem print do not include reserved for prom into used by openbsd


# 1.118 10-Dec-2003 mickey

for unaligned btlb mapping attempts -- just fail


# 1.117 24-Nov-2003 mickey

experimental support for HVT as a 2nd level tlb


# 1.116 15-Oct-2003 mickey

less global name space pollution


# 1.115 05-Oct-2003 mickey

reload the itmr as soon as we get the intr to avoid lagging on slower machines


# 1.114 25-Sep-2003 mickey

some pcxl2 do not report fpus -- assume it's there


Revision tags: OPENBSD_3_4_BASE
# 1.113 04-Sep-2003 mickey

a better cpu identification; testing by miod


# 1.112 31-Aug-2003 miod

pdc_model needs to be visible from cpu.c


# 1.111 20-Aug-2003 mickey

missing nl in debugging prontf


# 1.110 07-Aug-2003 mickey

dead proto


# 1.109 07-Aug-2003 mickey

first allocate space on stack then copyout signal shits. add a DEBUG check for a whacky user pc (as impossible due to the recent trap.c change)


# 1.108 03-Aug-2003 mickey

clear branch and nullify bits in psw on sending a signal


# 1.107 30-Jul-2003 mickey

deduce the leds address from the model number and thus make some more use of that lichtenblinkenschmutz on some more machinens


# 1.106 22-May-2003 mickey

imprecision in delay_init()


# 1.105 18-May-2003 mickey

save the fpu state for the signal handler. this is essential
as the fpu regs can be used by the gcc even for non-fpu
means and data copying.
rearrange the sigcontext a bit to include only the general
registers that are needed restoring upon return and thus
less waste of space and make up some space for the fpu regs.

ALL software that used the signal context on the stack
needs at least rebuilding now. a new snap has bin built as well.


Revision tags: UBC_SYNC_A
# 1.104 11-May-2003 deraadt

string cleaning; krw ok


# 1.103 07-Apr-2003 mickey

s/HP9000/HP 9000/; from weissmanndude


Revision tags: OPENBSD_3_3_BASE
# 1.102 18-Feb-2003 deraadt

knf; mickey ok


# 1.101 12-Feb-2003 jason

How uncommon... hppa only has one common: msgbufmapped (decl'd in /sys/kern)


# 1.100 12-Feb-2003 mickey

only align the first stack frame onto the minimal required alignment


# 1.99 10-Feb-2003 mickey

fix pcs and pcxt recognition. from weissmanndude


# 1.98 22-Jan-2003 mickey

consistantly use uvm_prot_* vs vm_prot_* evewrhere


# 1.97 14-Jan-2003 mickey

fix cutnpaste in the cpu table for the itlbna field; from herr weissmanndude


# 1.96 14-Jan-2003 mickey

need pdc_hwtlb always; pt out by herr weissmanndude


# 1.95 13-Jan-2003 mickey

fix the logic in hvt probing


# 1.94 09-Jan-2003 miod

Remove fetch(9) and store(9) functions from the kernel, and replace the few
remaining instances of them with appropriate copy(9) usage.

ok art@, tested on all arches unless my memory is non-ECC


# 1.93 19-Dec-2002 mickey

setregs: put the whole frame setup into one place


# 1.92 19-Dec-2002 mickey

level 0x16 is really an l2


# 1.91 17-Dec-2002 millert

Make SysV-style shared memory and semaphore limits sysctl'able.
Instead of allocating a static amount of memory for the data
structures via valloc() in allocsys(), allocate things dynamically
using pool(9) when possible and malloc(9) when not. The various
members of struct seminfo and struct shminfo are in kern.seminfo
and kern.shminfo respectively (not all members of kern.seminfo are
changable).

The data structures used still leave something to be desired but
things are not made worse in that respect by this commit.


# 1.90 27-Nov-2002 mickey

no wrapper arounf hardclock(), use CPU_CLOCKUPDATE, real microtime; miod ok


# 1.89 08-Nov-2002 mickey

Don't uvm_useracc the user sigcontext in sys_sigreturn and then access
the user addresses directly from the kernel. copyin is faster and can
correctly deal properly with mappings that uvm_useracc thinks are
correct but will fault anyway (to figure out how to generate such
mappings is left as en excercise for the reader).


# 1.88 01-Nov-2002 mickey

add a missing delay after printf on halt[-p], proper arg for a cold hook


Revision tags: UBC_SYNC_B
# 1.87 22-Oct-2002 mickey

do not force single-user; pt out by fries@


# 1.86 15-Oct-2002 mickey

missing initmsgbuf(), noticed by miod@


# 1.85 13-Oct-2002 mickey

track the end of physmem for use in dmmem_alloc


# 1.84 07-Oct-2002 mickey

s/PSW_/PSL_/ to match other archs


# 1.83 07-Oct-2002 mickey

proper terminate the user stack on signal


# 1.82 07-Oct-2002 mickey

on implementations w/ fpu included unimplemented instructions
are signaled through the exception trap w/ invalid opcode marked
instruction in the exception registers, not through the emulation
trap (as long as the fpu is enabled, of course).
parse emulation from the exception trap as well as the emulation
trap and fix the dispatcher into usable condition.
parse invalid op exception on trap and signal the user appropriately.
reset the exception on exec and for child on fork.
the later is appropriate since exceptions are delayed until next
fpu instruction, which was in the parent indeed, let him get it.
save parent's fpu context on fork before cipying it, if the
parent owned the fpu.


Revision tags: OPENBSD_3_2_BASE
# 1.81 23-Sep-2002 mickey

parisc level 0x10 is just an overclocked 0xe


# 1.80 17-Sep-2002 mickey

handle fpu exceptions properly, might use a regress, i guess


# 1.79 11-Sep-2002 mickey

provide a convinient reset label


# 1.78 11-Sep-2002 mickey

stack grows the other way, but the frame is the other way to that. hehe


# 1.77 09-Sep-2002 mickey

set up the frame flags and a user frame better on exec


# 1.76 03-Aug-2002 mickey

rework boot() w/o a goto


# 1.75 25-Jul-2002 mickey

missing arg in the call to the pdc_call since some old times


# 1.74 25-Jul-2002 mickey

kcopy is a space-to-space copy from kernel space, to guess where, -- to the same kernel space, just error on fault


# 1.73 20-Jul-2002 art

Instead of copying out the signal trampoline on top of the stack, create
an uvm aobj, copy out the signal trampoline into it and share that page
among all processes for the same emulation.

This also requires us to actually be able to tell signal code where the
trampoline is located, so introduce a new field in struct proc - p_sigcode
that is a pointer to sigcode. This allows us to remove all the ugly
calculations of the signal trampoline address done in every sendsig
function in the tree (that's why so many files are changed).

Tested by various people. ok deraadt@


# 1.72 14-May-2002 mickey

disable sid hashing while still in real mode, alos print the parisc arch once and not per each cpu since they are not intermixable architecture-wise


# 1.71 13-May-2002 mickey

ldi-ldo whatever was in the table, be that much clever


# 1.70 08-May-2002 mickey

print parisc level w/ the the parisc version, not for each cpu


# 1.69 08-May-2002 mickey

kill debugging printfski


# 1.68 22-Apr-2002 mickey

no longer batc the data, only the code.
this removes a constraint and an ld.script dependancy
for the .data and the dynamically allocated kernel
structures existed w/ batcing. also makes pmap_steal_memory
obsolete and replaced w/ the pmap_virtual_space.
implement batching for pmap_remove to avoid
zeroing out the pte entries if pde will be removed anyway.


# 1.67 21-Apr-2002 mickey

better buf's mapping and less magic constants in checking for io space cachability


Revision tags: OPENBSD_3_1_BASE
# 1.66 26-Mar-2002 mickey

if cannot guess cpu model default to the lowest supported one


# 1.65 25-Mar-2002 deraadt

spelling


# 1.64 23-Mar-2002 espie

Add variables for config(8) -e time tweak of systemV shared memory
parameters.

Ok millert@, miod@, maja@


# 1.63 19-Mar-2002 mickey

mtcpu seq requires a pre-sync, implement hpt init for pcxl


# 1.62 15-Mar-2002 mickey

rewrite a pmap to use multilevel page tables.
lower 12 bits contain the perms, no unused bits left,
but a couple for off-tlb use (as the ref implemented now).
do not use the hvt, which might get some use later
if proven to speed thigs up, tlb handlers would po
another dozen of insns though, but if that's worth its...
move on the data seg and map kernel text rdonly (idea form fredette),
since all of the page0 mods done before that we are all fine
except for some viper fluff, but later w/ that.
this also picks up a bit more of ddb magic for bpt and ss.
tlb handlers can use a little bit more of attention,
but things, visually, seem to be much faster already, --
sorry, no benchmarks for now.

* effort sponsored in part by the `henry st. old ale house'
* and mr.pete and mr.lee in particular in thier generous entrirety.
* the proj took a little more that 72man*h as it was expected,
* but within murhy's law estimations.


# 1.61 14-Mar-2002 millert

First round of __P removal in sys


# 1.60 20-Feb-2002 mickey

setup power failure handler (for sw-controlled power button), move toc handler


# 1.59 17-Feb-2002 maja

Patch from Daniel Lucq <daniel@lucq.org>

The patch allows you to change the value of NMBCLUSTERS, BUFCACHEPERCENT
and NKMEMPAGES using the config command, instead of recompiling the kernel.

This is the kernel part of the patch. I have compiled it on i386, sparc64,
alpha and macppc. -moj ok art@ maja@


# 1.58 12-Feb-2002 mickey

support 712's programmable power switch, no interrupt yet


# 1.57 12-Feb-2002 mickey

small repairs to hpmc and toc handlers


# 1.56 11-Feb-2002 mickey

disable fpu on csw, print fpu version on cpu line, if present


# 1.55 07-Feb-2002 mickey

fix sigdebug cases; init sigcontext before it's used (;


# 1.54 06-Feb-2002 mickey

implement signal delivery; based on fredette@'s work


# 1.53 03-Feb-2002 mickey

restore hpt size computation, does not break things as i thought


# 1.52 02-Feb-2002 mickey

fix 'physmem' usage


# 1.51 02-Feb-2002 mickey

implement the rest of /dev/mem devices; from netbsd


# 1.50 23-Jan-2002 art

move mb_map allocation to mbinit()


# 1.49 23-Jan-2002 art

move definition of mb_map from zillions of machdep.c to uipc_mbuf.c


# 1.48 16-Jan-2002 miod

Don't include <sys/map.h> when you don't need what's in it.


Revision tags: UBC_BASE
# 1.47 02-Dec-2001 mickey

branches: 1.47.2;
increase fixed extent storage


# 1.46 28-Nov-2001 art

zap some typedefs.
vm_map_t -> struct vm_map *
vm_map_entry_t -> struct vm_map_entry *
simple_lock_data_t -> struct simplelock

(uvm not done yet, coming in the next commit)


# 1.45 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.44 24-Nov-2001 miod

Harmonize boot() logic across arches:
- ensure RB_DUMP | RB_HALT will cause a dump
- or RB_HALT if (cold)
While there, honor RB_TIMEBAD on sparc64.


# 1.43 09-Nov-2001 art

nswbuf hasn't been used for ages. gc.


# 1.42 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.41 06-Nov-2001 miod

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


Revision tags: OPENBSD_3_0_BASE
# 1.40 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.39 12-Sep-2001 art

mbutl no more


# 1.38 23-Aug-2001 art

We can now move timeout_init into main().


# 1.37 23-Aug-2001 art

Remove even more old timeout tentacles.


# 1.36 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.35 05-Jul-2001 art

Get rid of REAL_CLISTS. It was never implemented and the tentacles are
everywhhere.


# 1.34 17-May-2001 provos

convert mbuf and cluster allocation to pool, mostly from NetBSD
okay art@ miod@


# 1.33 05-May-2001 art

Rename configure() to cpu_configure().
Move it from cpu_startup() to main().


# 1.32 05-May-2001 art

Get rid of CLSIZE and all related stuff.
CLSIZE -> 1
CLBYTES -> PAGE_SIZE
OLOFSET -> PAGE_MASK
etc.
At the same time some archs needed some cleaning in vmparam.h so that
goes in at the same time.


Revision tags: OPENBSD_2_9_BASE
# 1.31 29-Mar-2001 mickey

cpudev_data.h here needed not


# 1.30 22-Mar-2001 mickey

shuffle the tlb handlers a little,
make a new one for na data fault,
since those w/ hpt need it.


Revision tags: OPENBSD_2_8_BASE
# 1.29 15-Aug-2000 mickey

two btlb routines (i & d) for pcxs


# 1.28 15-Aug-2000 mickey

expand per-cpu control routines switch


# 1.27 08-Aug-2000 mickey

print btlb params w/ BTLBDEBUG; from Havard.Eidnes@runit.sintef.no


# 1.26 02-Jul-2000 mickey

no bays for stinger


Revision tags: OPENBSD_2_7_BASE
# 1.25 23-Mar-2000 mickey

new cpu type switch code.
initializes tlb miss handlers correspondent to probed cpu features.
also btlb load routine.
versions written are for pcxl and others.
cpu-dep btlb loaders are missing, only generic for now.


# 1.24 23-Mar-2000 art

New API for timeouts. Replaces the old timeout()/untimeout() API and
makes it the callers responsibility to allocate resources for the
timeouts.

This is a KISS implementation and does _not_ solve the problems of slow
handling of a large number of pending timeouts (this will be solved in
future work) (although hardclock is now guarateed to take constant time
for handling of timeouts).

Old timeout() and untimeout() are implemented as wrappers around the new
API and kept for compatibility. They will be removed as soon as all
subsystems are converted to use the new API.


# 1.23 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


# 1.22 22-Feb-2000 mickey

blah, blah, blah, msgbuf


Revision tags: SMP_BASE
# 1.21 09-Feb-2000 mickey

branches: 1.21.2;
heartbeat -- yeah we have a patch for that


# 1.20 25-Jan-2000 mickey

better copy and zero inlines in locore;
proper setregs() in machedep;
start of hpmc handler;
some cleanup here and there;


# 1.19 17-Jan-2000 mickey

remove unneeded stuff from setregs; force single-user for now, enable signal debug


# 1.18 11-Jan-2000 mickey

s/fpu_curproc/fpu_curpcb/ which also points into physical.
move it's definition into locore (where it's used the most).
adjust fpu context switch and save on swapout accordingly.
fix context save (in switch).
add accounting for fpu context switches (since it differes
from proc switching, we might get provided w/ some usefull
numbers as to how effective this lazy switch technique is).
enable handling fpu/sfu exceptions.


# 1.17 31-Dec-1999 mickey

don't bother about pidr3 and pidr4


# 1.16 17-Dec-1999 mickey

fix the panic message for sti memory mapping


Revision tags: kame_19991208
# 1.15 25-Nov-1999 mickey

bus stuff is in mainbus now, the rest is rewritten many ways


Revision tags: OPENBSD_2_6_BASE
# 1.14 20-Sep-1999 mickey

fix uvm_pagealloc() call


# 1.13 03-Sep-1999 art

Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.12 14-Aug-1999 mickey

proper debugging ifdefs


# 1.11 21-Jul-1999 mickey

rewrite the tlb miss handler and tlb dirty handler.
optimize for HVT usage (when compiled for proper cpu type).
drop hpt_* global variables, use info from control registers instead.
there are still ways to improve the tlb handlers tho.
machdep also prints cache and tlb coherence states (not related to the above).
You eat greenish muffin. --More-- You write real code.


# 1.10 12-Jul-1999 mickey

allocate 5% bufcache if <=16M memory installed


# 1.9 12-Jun-1999 mickey

hppa_init() now takes an argument from locore,
meaning the start of available memory.
cleanup machdep somewhat.
fix vm_map.pmap vs vm_pmap isue; 10x art@


# 1.8 23-May-1999 mickey

new swap stuff


# 1.7 21-May-1999 mickey

group all theMD f;ags together, add interrupt recursion one


# 1.6 21-May-1999 mickey

define fpu_curproc


# 1.5 20-Apr-1999 mickey

do lazy blok mapping of io space in bus_*
add copy{in,out}*, kcopy, etc
boot routines
cpu-id-hpux-compat stuff
rest of scheduler and such
uvm


Revision tags: OPENBSD_2_5_BASE
# 1.4 17-Feb-1999 mickey

print pa-risc here as well, since, finally, cpu will have to print processor type


# 1.3 04-Jan-1999 mickey

better cache handling in bus_space_barrier(), seem to work now


# 1.2 03-Jan-1999 mickey

implement bus_space_{un,}map w/ extents


# 1.1 30-Dec-1998 mickey

machdep; more work needed


# 1.257 11-May-2020 kettenis

Initialize the timeval passed to todr_gettime() with the base time from
the file system such that implementations can use it to guess the right
century.

ok mpi@


Revision tags: OPENBSD_6_7_BASE
# 1.256 01-May-2020 kettenis

Use the same inittodr()/resettodr() implementation as on
amd64/arm64/armv7/i386/sparc64 and move it to the end of machdep.c. Rework the
actual implementation for the MC14818 compatible RTC into something that can
be used as a todr_handle just like on amd64.

ok mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.255 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


Revision tags: OPENBSD_6_4_BASE
# 1.254 20-Jul-2018 guenther

Missed a 'ksi' -> '*ksip' change in previous commit


# 1.253 10-Jul-2018 guenther

Move from sendsig() to its callers the initsiginfo() calls and
instead of passing sendsig() the code+type+val, pass a siginfo_t*
to copy from. Eliminate the indirection through struct emul for
sendsig(); we no longer have a SunOS4-compat version of sendsig()

ok deraadt@


# 1.252 22-May-2018 guenther

Delete antique sigdebug definitions

ok kettenis@


# 1.251 12-Apr-2018 deraadt

Implement MAP_STACK option for mmap(). Synchronous faults (pagefault and
syscall) confirm the stack register points at MAP_STACK memory, otherwise
SIGSEGV is delivered. sigaltstack() and pthread_attr_setstack() are modified
to create a MAP_STACK sub-region which satisfies alignment requirements.
Observe that MAP_STACK can only be set/cleared by mmap(), which zeroes the
contents of the region -- there is no mprotect() equivalent operation, so
there is no MAP_STACK-adding gadget.
This opportunistic software-emulation of a stack protection bit makes
stack-pivot operations during ROPchain fragile (kind of like removing a
tool from the toolbox).
original discussion with tedu, uvm work by stefan, testing by mortimer
ok kettenis


Revision tags: OPENBSD_6_3_BASE
# 1.250 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.249 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


Revision tags: OPENBSD_6_2_BASE
# 1.248 18-May-2017 kettenis

Implement copyin32(9).

"your chicken scratches look fine to me" deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.247 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

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


# 1.246 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.245 21-May-2016 deraadt

hand-massage sendsig() and sys_sigreturn() to be much more similar.
ok guenther kettenis


# 1.244 10-May-2016 deraadt

SROP mitigation. sendsig() stores a (per-process ^ &sigcontext) cookie
inside the sigcontext. sigreturn(2) checks syscall entry was from the
exact PC addr in the (per-process ASLR) sigtramp, verifies the cookie,
and clears it to prevent sigcontext reuse.
not yet tested on landisk, sparc, *88k, socppc.
ok kettenis


# 1.243 20-Apr-2016 dlg

pool_setipl for floating point context things

ok kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.242 21-Oct-2015 mpi

Do not call uvm_swap_finicrypt_all() a second time in dumpsys().

ok tedu@, deraadt@, miod@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.241 20-Jan-2015 kettenis

Move ps_strings "after" the random stackgap. This makes its location a
per-process value, and therefpore turns the VM_PSSTRINGS sysctl into a
per-process one as well. This gets rid of a pointer to the bottom of the
stack at a fixed location. Also clears the road for unmapping the stackgap.

ok deraadt@


# 1.240 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.239 25-Oct-2014 kettenis

Remove vmmap; it isn't used.

ok jsing@


# 1.238 23-Oct-2014 miod

Correctly set up the HPMC trap entry: according to the PA-RISC Firmware
Architecture Reference Specification, the sum of the 8 trap entry words
*and* of the payload which address and length are to be set at well-known
positions in the aforementioned trap entry, needs to be zero; the existing
code was only enforcing that the sum of the trap entry words is zero.

This matches what Linux and NetBSD do.

ok kettenis@


# 1.237 23-Oct-2014 miod

Revert limiting physmem to 2GB; the culprit was likely in uvm and uvm has
changed a lot in the last 5 years; verified to work on a 3GB system, in
snapshots for a few weeks already.


# 1.236 22-Sep-2014 dlg

implement atomic_{cas,swap}_{uint,ulong,ptr} and
atomic_{add,sub}_{int,long}_nv. sys/atomic.h turns these into the
rest of the atomic api.

on uniprocessor hppa systems "atomic" operations are implemented
as a non-interruptable sequence by disabling all interrupts on the
cpu, doing the operation, and then restoring the interrupt mask.

this isnt enough on MP systems, so we added a global atomic memory
mutex that is taken inside the interrupt disabling above to coordinate
operations between cpus.

this is a lot of overhead though cos mutexes dance around with ipls,
which is unecessary in our case because of the interrupt disabling
that is already done. also, hppa spinlocks are implemented with
ldcw which requires the word it operates on to be 16 byte aligned.
mutexes arent guaranteed to have this alignment so they compensate
by having lots of words inside themselves so they can hit the
appropriate one to use for the ldcw op.

with this in mind, this change pulls __cpu_simple_locks, which are
simply ldcw spinlocks with a 16 byte aligned word, out of
src/sys/arch/hppa/include/lock.h into src/sys/arch/hppa/include/atomic.h
so atomic.h can use them. lock.h includes atomic.h, so it still
gets and provides the same functionality as before.

finally, this also pulls the rwlock cas implementation apart. cas
ops now share the same serialising lock on MP systems as the other
memory operations, and rw_cas is defined as a wrapper around
atomic_cas_uint.

ok kettenis@


# 1.235 19-Sep-2014 kettenis

Use config_suspend_all(9).


# 1.234 18-Aug-2014 dlg

dont rely on mbuf.h to provide pool.h.

ok miod@, who has offerred to help with any MD fallout
ok guenther@


Revision tags: OPENBSD_5_6_BASE
# 1.233 22-Jul-2014 uebayasi

boot(9): Reduce diffs between hppa & hppa64 (& others)


# 1.232 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.231 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.230 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.229 13-Jul-2014 miod

These still need <sys/reboot.h> for the RB_ constants.


# 1.228 12-Jul-2014 uebayasi

reboot(9), panic(9): Call panic(9) for unrecoverable MD H/W errors (NMIs)

Some architectures have ability to detect hardware sanity and notify system
(NMI, firmware callback, etc.). Handle these hardware severe errors, same
as software errors, with panic(9).

According to miod@, SGI IP27 NMI is triggered by pushing some "hidden" button,
which "usual" users/admins don't know. Pushing such a button is "RB_USERREQ"
(human-triggered) in that the button is pushed by a human, but not "RB_USERREQ"
in that no user intervention in system (== no command input) is done. miod@
agreed that changing these from RB_USERREQ to !RB_USERREQ (== panic(9)) is
not a big problem.

OK miod@ kettenis@


# 1.227 12-Jul-2014 uebayasi

boot(9), reboot(9): Migrate MD callers of boot(9) to reboot(9)

I have found that some ports call boot(9) from machine-dependent code to
reboot system. These should be changed to either:

- Sending signal to init(8) to trigger it to shutdown system cleanly, like
acpi(4) does, in cases where found problems don't prevent system from working
immediately, or

- Just doing panic(9) if the situation is severely broken.

For now, just rewrite boot() to reboot(). Actual fixes follow.

Discussed with & OK from kettenis@


# 1.226 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.225 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.224 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.223 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.222 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.221 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.220 08-May-2014 miod

Format string fixes and removal of -Wno-format for hppa kernels.


# 1.219 08-Apr-2014 mpi

Less <uvm/uvm.h>


# 1.218 04-Apr-2014 miod

If the PDC_COPROC call fails, and we are running on a PA 1.1 system, assume
the usual 1.1 coprocessor mask, instead of using zero and having every
userland process dying with signal 4.

The circumstances under which this call fails are unclear and could be
tied to specific PROM version (I have tried overzealous stack alignment and
other tricks, to no avail). Interestingly enough, the 715/75 system which
hits this problem, only triggers it when booting from disk, and never when
booting from network.

This diff is an ugly bandaid until the problem is better understood. Or maybe
it is not worth investigating, seeing that Linux hardcodes the coprocessor
mask and never issues PDC_COPROC calls; I wonder what HP/UX does.

In my tree for over 18 months; "Looks like a nice hack" deraadt@
715/75 system provided by Sebastiaan Indesteege, thanks!


# 1.217 29-Mar-2014 guenther

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

ok dlg@ mpi@ deraadt@


# 1.216 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


# 1.215 22-Mar-2014 guenther

Move p_sigacts from struct proc to struct process.

testing help mpi@


# 1.214 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


Revision tags: OPENBSD_5_5_BASE
# 1.213 23-Nov-2013 uebayasi

Run doshutdownhooks() and config_suspend() even when boot() is called while
cold != 0. Indent and make hppa/hppa64 boot() closer to others.

OK kettenis@


# 1.212 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


Revision tags: OPENBSD_5_4_BASE
# 1.211 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


Revision tags: OPENBSD_5_3_BASE
# 1.210 02-Dec-2012 guenther

Determine whether we're currently on the alternative signal stack
dynamically, by comparing the stack pointer against the altstack
base and size, so that you get the correct answer if you longjmp
out of the signal handler, as tested by regress/sys/kern/stackjmp/.
Also, fix alt stack handling on vax, where it was completely broken.

Testing and corrections by miod@, krw@, tobiasu@, pirofti@


# 1.209 26-Oct-2012 kettenis

Properly clear trap frame in setregs() to avoid leaking registers across exec.

ok jsing@


# 1.208 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.207 07-Oct-2012 kettenis

Align the stack on a 64-byte boundary as required by "The 32-bit PA-RISC
Run-time Architecture Document". GCC relies on this to properly align
stack variables.

ok guenther@, beck@


Revision tags: OPENBSD_5_2_BASE
# 1.206 21-Jun-2012 guenther

__tfork() needs to set the stack address of the new thread in the kernel,
so that it can't get a signal while still running on the parent thread's
stack. Also, pass in sizeof(struct __tfork) to provide forward compat
when more members are added. This is an ABI change, so switch syscall
numbers and bump lib majors this time.

ok deraadt@ matthew@


Revision tags: OPENBSD_5_1_BASE
# 1.205 20-Sep-2011 miod

Clear RB_POWERDOWN early in boot() on systems which can not powerdown and
which firmware does not send spin up commands to the disks, in case the
operator changes his mind and reboots instead of manually powering down
after the system has halted.
ok kettenis@


Revision tags: OPENBSD_5_0_BASE
# 1.204 05-Jul-2011 guenther

Recommit the reverted sigacts change now that the NFS use-after-free
problem has been tracked down. This fixes the sharing of the signal
handling state: shared bits go in sigacts, per-rthread bits goes in
struct proc.

ok deraadt@


# 1.203 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.202 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.201 18-Apr-2011 guenther

Revert the sigacts diff: NFS can apparently retain pointers to processes
until they're zombies and then send them signals (for intr mounts). Until
that is untangled, the sigacts change is unsafe. sthen@ was the victim
for this one


# 1.200 15-Apr-2011 guenther

Correct the sharing of the signal handling state: stuff that should
be shared (p_sigignore, p_sigcatch, P_NOCLDSTOP, P_NOCLDWAIT) moves
to struct sigacts, wihle stuff that should be per rthread (ps_oldmask,
SAS_OLDMASK, ps_sigstk) moves to struct proc. Treat the coredumping
state bits (ps_sig, ps_code, ps_type, ps_sigval) as per-rthread
until our locking around coredumping is better.

Oh, and remove the old SunOS-compat ps_usertramp member.

"I like the sound of this" tedu@


Revision tags: OPENBSD_4_9_BASE
# 1.199 14-Jan-2011 jsing

Halt secondary CPUs when shutting down or rebooting. This should prevent
occasional hangs during reboot.

ok kettenis@


# 1.198 04-Jan-2011 jasper

- de-register. no binary change.

ok jsing@


# 1.197 01-Jan-2011 jasper

Move setting cpu_hzticks to the clock initialization function, like
other ports (e.g. hppa64) do.

ok jsing@ kettenis@


# 1.196 01-Jan-2011 jasper

- ansify

ok jsing@ kettenis@


# 1.195 30-Dec-2010 jsing

Turn signotify() into a function that also calls cpu_unidle().

ok kettenis@


# 1.194 20-Nov-2010 miod

This is a first step towards getting rid of avail_start and avail_end in the
kernel, currently limited to low-hanging fruit: these variables were used
by bus_dma to specify the range in which to allocate memory, back when
uvm_pglistalloc() was stupid and would not walk the vm_physseg[].

Nowadays, except on some platforms for early initialization, these variables
are not used, or do not need to be global variables. Therefore:
- remove `extern' declarations of avail_start and avail_end (or close cousins,
such as arm physical_start and physical_end) from files which no longer need
to use them.
- make them local variables whenever possible.
- remove them when they are assigned to but no longer used.


Revision tags: OPENBSD_4_8_BASE
# 1.193 01-Jul-2010 jsing

Create a struct to store FP state and include a pointer to the CPU that
currently holds the FPU context for this process. This will be soon used
to implement FPU shootdowns on multiprocessor kernels.

ok kettenis@


# 1.192 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.191 29-Jun-2010 jsing

Factor out code used to save and flushe process FPU context.

ok kettenis@


# 1.190 29-Jun-2010 jsing

Store pointer to process FPU state in struct cpu_info.

ok kettenis@


# 1.189 27-Jun-2010 thib

uvm constraints. Add two mandatory MD symbols, uvm_md_constraints
which contains the constraints for DMA/memory allocation for each
architecture, and dma_constraints which contains the range of addresses
that are dma accessable by the system.

This is based on ariane@'s physcontig diff, with lots of bugfixes and
additions the following additions by my self:

Introduce a new function pool_set_constraints() which sets the address
range for which we allocate pages for the pool from, this is now used
for the mbuf/mbuf cluster pools to keep them dma accessible.

The !direct archs no longer stuff pages into the kernel object in
uvm_km_getpage_pla but rather do a pmap_extract() in uvm_km_putpages.

Tested heavily by my self on i386, amd64 and sparc64. Some tests on
alpha and SGI.

"commit it" beck, art, oga, deraadt
"i like the diff" deraadt


# 1.188 27-Jun-2010 jsing

Use a mutex to make atomic operations atomic on multiprocessor kernels.

ok kettenis@


# 1.187 10-Jun-2010 deraadt

Declare safepri at the MD level on each platform, so that the kern_synch.c
does not have to deal with it as a common. Some platforms may be missed
by this commit... if you spot one, fix it the same way.
ok miod


# 1.186 09-Jun-2010 miod

Move declaration of cn_tab from dev/cons.c to dev/cninit.c, or appropriate
md files for ports which do not use dev/cninit.c. This gets rid of a common
at kernel link time.
feedback drahn@ ok deraadt@


# 1.185 24-May-2010 deraadt

Add missing prototypes
ok jsing kettenis


# 1.184 09-May-2010 kettenis

Prevent "taken branch" exceptions from kernel space by clearing the PSL_T
bit before we enter a signal handler.

"if you say so" miod@, "seems to make sense" jsing@


# 1.183 02-May-2010 kettenis

Properly initialize the members of `struct mdproc' that deal with
single-stepping when we fork and reset them upon exec.

ok miod@


# 1.182 27-Apr-2010 kettenis

Avoid null-pointer dereference by giving proc0 a place to store its
floating-point registers. Pointed out by Nick Hudson.

ok miod@, jsing@


# 1.181 19-Apr-2010 jsing

Make the Processor Status Word (PSW) a per-CPU value.

ok kettenis@


# 1.180 01-Apr-2010 jsing

Allow for multiple CPUs by moving to an array of cpu_info.

ok kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.179 31-Dec-2009 jsing

Make cpl and cpu_inintr per CPU variables. For locore.S, cpl becomes an
offset within cpu_primary_info - this will need to be revisited shortly.

ok kettenis@


# 1.178 11-Aug-2009 miod

Do not bother initializing bufpages in the md code if the computation is
exactly the same the mi could will use if bufinit() is invoked with
bufpages == 0.


# 1.177 11-Aug-2009 miod

With the SysV memory allocation changes, allocsys() doesn't do anything
anymore. Get rid of it completely.


# 1.176 09-Aug-2009 blambert

Rototill system V message queues.

No longer allocate a static amount of memory for messages in MD
boot path; message queues, message metadata, and message data now
all use dynamic memory, which means that runtime sysctls should now
be trivial to implement.

Since I'm going to be around all week to fix any breakage, this should
probably just go in now.


# 1.175 02-Aug-2009 beck

Dynamic buffer cache support - a re-commit of what was backed out
after c2k9

allows buffer cache to be extended and grow/shrink dynamically

tested by many, ok oga@, "why not just commit it" deraadt@


# 1.174 29-Jul-2009 kettenis

Get rid of non-equivalent aliases of the pcb by moving the fpu state out
of the pcb and using the p_addr member of 'struct proc' to calculate the
address of the kernel stack when switching to virtual mode after taking a trap.
Remove the now unecessary cache flushes; they're actually harmful since they
create non-equivalent aliases. This seems to fix the memory corruption we
have been observing from time to time.

This diff does not rename fpu_curpcb, which is now somewhat incorrectly named.
I hope to change things back again as soon as we are able to map the pcb 1:1.


Revision tags: OPENBSD_4_6_BASE
# 1.173 15-Jun-2009 beck

Back out all the buffer cache changes I committed during c2k9. This reverts three
commits:

1) The sysctl allowing bufcachepercent to be changed at boot time.
2) The change moving the buffer cache hash chains to a red-black tree
3) The dynamic buffer cache (Which depended on the earlier too).

ok on the backout from marco and todd


# 1.172 03-Jun-2009 beck

add kern.bufcachepercent sysctl to allow adjusting the buffer cache
size on a running system.
ok art@, oga@


Revision tags: OPENBSD_4_5_BASE
# 1.171 14-Feb-2009 kettenis

Limit the amount of physical memory to 2GB. Using more causes memory
corruption on PA-RISC 2.0 systems (and there are very few PA-RISC 1.1
systems that support more than 2GB).

ok miod@


# 1.170 04-Feb-2009 miod

On systems with split BTLB, do not bother trying to insert DBTLB entries,
as PDC will lie to us pretending it did while it didn't.

ok kettenis@


# 1.169 04-Feb-2009 miod

Unify memory size reports a bit more: always report size in MB, and report
reserved memory on alpha and hppa on its own line (as done on sgi).


Revision tags: OPENBSD_4_4_BASE
# 1.168 14-Jul-2008 miod

Be sure to propagate PSL_O in psw on PCXU* processors to userland processes
and signal handlers.
ok kettenis@


# 1.167 27-Jun-2008 miod

Clear swap encryption keys before dumping a kernel image.


# 1.166 09-Apr-2008 deraadt

Add new stub uvm_shutdown() and call it from the right place in MD boot()


Revision tags: OPENBSD_4_3_BASE
# 1.165 22-Sep-2007 martin

replace even more ctob and btoc with ptoa and atop respectively plus
uvm_extern.h where needed


Revision tags: OPENBSD_4_2_BASE
# 1.164 22-Jul-2007 kettenis

Move hppa to __HAVE_TIMECOUNTERS.


# 1.163 20-Jul-2007 kettenis

Give hppa the blink_led API from sparc64, and the associated machdep.led_blink
sysctl.


# 1.162 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.161 14-Jul-2007 kettenis

Make sigreturn(2) set the proper space ID for the instruction queue. Fixes
a few more pthreads regression tests.

ok miod@


# 1.160 10-Jul-2007 kettenis

Don't trust the privilige level in the sigcontext passed to sigreturn(2).

ok miod@


# 1.159 24-Jun-2007 kettenis

Crank initial storage for extents a bit. We really should allocate extents
using malloc once vm is initialised, but this will do for now.

ok deraadt@


# 1.158 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.157 27-May-2007 miod

Make sure the minaddr hint for uvm_km_suballoc() calls is always initialized.
ok pedro@


# 1.156 26-May-2007 pedro

Dynamic buffer cache. Initial diff from mickey@, okay art@ beck@ toby@
deraadt@ dlg@.


# 1.155 21-May-2007 kettenis

Add support for 8700/pcxw2 cpu.


# 1.154 21-May-2007 kettenis

Ask firmware for reset before trying ourselves; needed for four-digit b/c/j
workstations.

tested by otto@, krw@; ok deraadt@


# 1.153 17-May-2007 art

Limit hppa buffer cache to 30%. It used to be 70% because stack garbage
that was used for minaddr instead of the proper vm_map_min(kernel_map)
(fixed in this diff).

From mickey. art@ ok


# 1.152 14-May-2007 martin

move hppa to __HAVE_CPUINFO

input from miod@, ok kettenis@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.151 28-May-2006 martin

minor nit, use CPU ID instead of FPU ID for BTLB parameters after passing
all kludges


# 1.150 15-Apr-2006 martin

make warning about missing HPT support DEBUG for now

ok mickey@


Revision tags: OPENBSD_3_9_BASE
# 1.149 26-Oct-2005 martin

no more hppa_round_page() and hppa_trunc_page() macros

ok mickey@


Revision tags: OPENBSD_3_8_BASE
# 1.148 06-Aug-2005 miod

We do not need a char machine_arch[] constant.
ok deraadt@


# 1.147 11-Jul-2005 mickey

align some stupid comments


# 1.146 10-May-2005 mickey

set pcsq in case we get signal delivery once interrupted from the gateway page; from chs


# 1.145 18-Apr-2005 mickey

do not do some of the initmsgbuf()s job


# 1.144 07-Apr-2005 mickey

on some machines it's possible to limit the amount of physmem initialised dring post so having msgbuf at the end of memory shall work


# 1.143 07-Apr-2005 mickey

64bit-friendly pdc.h and iomod.h and correspondent changes elsewhere


# 1.142 26-Mar-2005 mickey

md parts for hpux_compa code; some problems w/ signals delivery still exist


Revision tags: OPENBSD_3_7_BASE
# 1.141 24-Feb-2005 mickey

do not even ask for btlb on 8k cpus as pdc pretends there is some but then it does not work; found w/ Moritz Kiese <mbk@mytum.de> on c180; add a debug print and fix pcxu entry


# 1.140 17-Nov-2004 mickey

print real/avail/bufcache sizes as unsigned


# 1.139 26-Oct-2004 mickey

disable sid hashing on pcxu and above


# 1.138 14-Oct-2004 mickey

a bit larger delays during boot() to let msgs appear


# 1.137 19-Sep-2004 mickey

turn totalphysmem into physmem and name old physmem into smth it really is


# 1.136 18-Sep-2004 mickey

oops


# 1.135 15-Sep-2004 mickey

add pcxu tlb handlers and cpu probing
add u2/uturn ioa driver in dumb mode now
enable pcxu/pcxw support


# 1.134 14-Sep-2004 mickey

store fpu version for later use. make sure to proper store/clear fpu state in fork/exec/exit/sendsig


# 1.133 14-Sep-2004 mickey

error out from btlb_insert() if there is none


Revision tags: OPENBSD_3_6_BASE
# 1.132 01-Jul-2004 mickey

have separate insn and data cache all-flushers


# 1.131 30-Jun-2004 mickey

allow forced fpu emulation through a sysctl


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.130 13-May-2004 mickey

8ks do not have hvt


# 1.129 05-May-2004 mickey

much easier tlb handler branch patching


# 1.128 05-May-2004 mickey

do not engage HPT on PCXT' (yet)


# 1.127 08-Apr-2004 mickey

repair pcxs/t confoosion


# 1.126 07-Apr-2004 mickey

update copyright; miod@ is fine w/ files where he holds it too


Revision tags: OPENBSD_3_5_BASE
# 1.125 10-Mar-2004 tom

Ensure that we obey a user's ddb> boot reboot command even if the system
is cold (during startup).

This adds RB_USERREQ to sys/reboot.h, uses it in the ddb commands, and
ensures that */*/machdep.c:boot() won't set RB_HALT when cold if this
flag is set.

ok deraadt@


# 1.124 14-Feb-2004 grange

Simplify hw.{cpuspeed,setperf} api moving all the sysctl stuff
from the underlying callbacks.

Testing hppa mickey@, ppc drahn@
Ok markus@ tedu@


# 1.123 05-Jan-2004 mickey

kill debugging code that is not needed anymore


# 1.122 23-Dec-2003 mickey

provide cpuspeed fluff


# 1.121 20-Dec-2003 miod

Don't let microtime() return a struct timeval with exactly 1000000 microseconds.


# 1.120 18-Dec-2003 mickey

spls do not protect cpu_itmr and thus time might jump back sometimes due to cpu_itmr modified to a higher value than a read itmr; found and testing by miod@


# 1.119 17-Dec-2003 mickey

in the real mem print do not include reserved for prom into used by openbsd


# 1.118 10-Dec-2003 mickey

for unaligned btlb mapping attempts -- just fail


# 1.117 24-Nov-2003 mickey

experimental support for HVT as a 2nd level tlb


# 1.116 15-Oct-2003 mickey

less global name space pollution


# 1.115 05-Oct-2003 mickey

reload the itmr as soon as we get the intr to avoid lagging on slower machines


# 1.114 25-Sep-2003 mickey

some pcxl2 do not report fpus -- assume it's there


Revision tags: OPENBSD_3_4_BASE
# 1.113 04-Sep-2003 mickey

a better cpu identification; testing by miod


# 1.112 31-Aug-2003 miod

pdc_model needs to be visible from cpu.c


# 1.111 20-Aug-2003 mickey

missing nl in debugging prontf


# 1.110 07-Aug-2003 mickey

dead proto


# 1.109 07-Aug-2003 mickey

first allocate space on stack then copyout signal shits. add a DEBUG check for a whacky user pc (as impossible due to the recent trap.c change)


# 1.108 03-Aug-2003 mickey

clear branch and nullify bits in psw on sending a signal


# 1.107 30-Jul-2003 mickey

deduce the leds address from the model number and thus make some more use of that lichtenblinkenschmutz on some more machinens


# 1.106 22-May-2003 mickey

imprecision in delay_init()


# 1.105 18-May-2003 mickey

save the fpu state for the signal handler. this is essential
as the fpu regs can be used by the gcc even for non-fpu
means and data copying.
rearrange the sigcontext a bit to include only the general
registers that are needed restoring upon return and thus
less waste of space and make up some space for the fpu regs.

ALL software that used the signal context on the stack
needs at least rebuilding now. a new snap has bin built as well.


Revision tags: UBC_SYNC_A
# 1.104 11-May-2003 deraadt

string cleaning; krw ok


# 1.103 07-Apr-2003 mickey

s/HP9000/HP 9000/; from weissmanndude


Revision tags: OPENBSD_3_3_BASE
# 1.102 18-Feb-2003 deraadt

knf; mickey ok


# 1.101 12-Feb-2003 jason

How uncommon... hppa only has one common: msgbufmapped (decl'd in /sys/kern)


# 1.100 12-Feb-2003 mickey

only align the first stack frame onto the minimal required alignment


# 1.99 10-Feb-2003 mickey

fix pcs and pcxt recognition. from weissmanndude


# 1.98 22-Jan-2003 mickey

consistantly use uvm_prot_* vs vm_prot_* evewrhere


# 1.97 14-Jan-2003 mickey

fix cutnpaste in the cpu table for the itlbna field; from herr weissmanndude


# 1.96 14-Jan-2003 mickey

need pdc_hwtlb always; pt out by herr weissmanndude


# 1.95 13-Jan-2003 mickey

fix the logic in hvt probing


# 1.94 09-Jan-2003 miod

Remove fetch(9) and store(9) functions from the kernel, and replace the few
remaining instances of them with appropriate copy(9) usage.

ok art@, tested on all arches unless my memory is non-ECC


# 1.93 19-Dec-2002 mickey

setregs: put the whole frame setup into one place


# 1.92 19-Dec-2002 mickey

level 0x16 is really an l2


# 1.91 17-Dec-2002 millert

Make SysV-style shared memory and semaphore limits sysctl'able.
Instead of allocating a static amount of memory for the data
structures via valloc() in allocsys(), allocate things dynamically
using pool(9) when possible and malloc(9) when not. The various
members of struct seminfo and struct shminfo are in kern.seminfo
and kern.shminfo respectively (not all members of kern.seminfo are
changable).

The data structures used still leave something to be desired but
things are not made worse in that respect by this commit.


# 1.90 27-Nov-2002 mickey

no wrapper arounf hardclock(), use CPU_CLOCKUPDATE, real microtime; miod ok


# 1.89 08-Nov-2002 mickey

Don't uvm_useracc the user sigcontext in sys_sigreturn and then access
the user addresses directly from the kernel. copyin is faster and can
correctly deal properly with mappings that uvm_useracc thinks are
correct but will fault anyway (to figure out how to generate such
mappings is left as en excercise for the reader).


# 1.88 01-Nov-2002 mickey

add a missing delay after printf on halt[-p], proper arg for a cold hook


Revision tags: UBC_SYNC_B
# 1.87 22-Oct-2002 mickey

do not force single-user; pt out by fries@


# 1.86 15-Oct-2002 mickey

missing initmsgbuf(), noticed by miod@


# 1.85 13-Oct-2002 mickey

track the end of physmem for use in dmmem_alloc


# 1.84 07-Oct-2002 mickey

s/PSW_/PSL_/ to match other archs


# 1.83 07-Oct-2002 mickey

proper terminate the user stack on signal


# 1.82 07-Oct-2002 mickey

on implementations w/ fpu included unimplemented instructions
are signaled through the exception trap w/ invalid opcode marked
instruction in the exception registers, not through the emulation
trap (as long as the fpu is enabled, of course).
parse emulation from the exception trap as well as the emulation
trap and fix the dispatcher into usable condition.
parse invalid op exception on trap and signal the user appropriately.
reset the exception on exec and for child on fork.
the later is appropriate since exceptions are delayed until next
fpu instruction, which was in the parent indeed, let him get it.
save parent's fpu context on fork before cipying it, if the
parent owned the fpu.


Revision tags: OPENBSD_3_2_BASE
# 1.81 23-Sep-2002 mickey

parisc level 0x10 is just an overclocked 0xe


# 1.80 17-Sep-2002 mickey

handle fpu exceptions properly, might use a regress, i guess


# 1.79 11-Sep-2002 mickey

provide a convinient reset label


# 1.78 11-Sep-2002 mickey

stack grows the other way, but the frame is the other way to that. hehe


# 1.77 09-Sep-2002 mickey

set up the frame flags and a user frame better on exec


# 1.76 03-Aug-2002 mickey

rework boot() w/o a goto


# 1.75 25-Jul-2002 mickey

missing arg in the call to the pdc_call since some old times


# 1.74 25-Jul-2002 mickey

kcopy is a space-to-space copy from kernel space, to guess where, -- to the same kernel space, just error on fault


# 1.73 20-Jul-2002 art

Instead of copying out the signal trampoline on top of the stack, create
an uvm aobj, copy out the signal trampoline into it and share that page
among all processes for the same emulation.

This also requires us to actually be able to tell signal code where the
trampoline is located, so introduce a new field in struct proc - p_sigcode
that is a pointer to sigcode. This allows us to remove all the ugly
calculations of the signal trampoline address done in every sendsig
function in the tree (that's why so many files are changed).

Tested by various people. ok deraadt@


# 1.72 14-May-2002 mickey

disable sid hashing while still in real mode, alos print the parisc arch once and not per each cpu since they are not intermixable architecture-wise


# 1.71 13-May-2002 mickey

ldi-ldo whatever was in the table, be that much clever


# 1.70 08-May-2002 mickey

print parisc level w/ the the parisc version, not for each cpu


# 1.69 08-May-2002 mickey

kill debugging printfski


# 1.68 22-Apr-2002 mickey

no longer batc the data, only the code.
this removes a constraint and an ld.script dependancy
for the .data and the dynamically allocated kernel
structures existed w/ batcing. also makes pmap_steal_memory
obsolete and replaced w/ the pmap_virtual_space.
implement batching for pmap_remove to avoid
zeroing out the pte entries if pde will be removed anyway.


# 1.67 21-Apr-2002 mickey

better buf's mapping and less magic constants in checking for io space cachability


Revision tags: OPENBSD_3_1_BASE
# 1.66 26-Mar-2002 mickey

if cannot guess cpu model default to the lowest supported one


# 1.65 25-Mar-2002 deraadt

spelling


# 1.64 23-Mar-2002 espie

Add variables for config(8) -e time tweak of systemV shared memory
parameters.

Ok millert@, miod@, maja@


# 1.63 19-Mar-2002 mickey

mtcpu seq requires a pre-sync, implement hpt init for pcxl


# 1.62 15-Mar-2002 mickey

rewrite a pmap to use multilevel page tables.
lower 12 bits contain the perms, no unused bits left,
but a couple for off-tlb use (as the ref implemented now).
do not use the hvt, which might get some use later
if proven to speed thigs up, tlb handlers would po
another dozen of insns though, but if that's worth its...
move on the data seg and map kernel text rdonly (idea form fredette),
since all of the page0 mods done before that we are all fine
except for some viper fluff, but later w/ that.
this also picks up a bit more of ddb magic for bpt and ss.
tlb handlers can use a little bit more of attention,
but things, visually, seem to be much faster already, --
sorry, no benchmarks for now.

* effort sponsored in part by the `henry st. old ale house'
* and mr.pete and mr.lee in particular in thier generous entrirety.
* the proj took a little more that 72man*h as it was expected,
* but within murhy's law estimations.


# 1.61 14-Mar-2002 millert

First round of __P removal in sys


# 1.60 20-Feb-2002 mickey

setup power failure handler (for sw-controlled power button), move toc handler


# 1.59 17-Feb-2002 maja

Patch from Daniel Lucq <daniel@lucq.org>

The patch allows you to change the value of NMBCLUSTERS, BUFCACHEPERCENT
and NKMEMPAGES using the config command, instead of recompiling the kernel.

This is the kernel part of the patch. I have compiled it on i386, sparc64,
alpha and macppc. -moj ok art@ maja@


# 1.58 12-Feb-2002 mickey

support 712's programmable power switch, no interrupt yet


# 1.57 12-Feb-2002 mickey

small repairs to hpmc and toc handlers


# 1.56 11-Feb-2002 mickey

disable fpu on csw, print fpu version on cpu line, if present


# 1.55 07-Feb-2002 mickey

fix sigdebug cases; init sigcontext before it's used (;


# 1.54 06-Feb-2002 mickey

implement signal delivery; based on fredette@'s work


# 1.53 03-Feb-2002 mickey

restore hpt size computation, does not break things as i thought


# 1.52 02-Feb-2002 mickey

fix 'physmem' usage


# 1.51 02-Feb-2002 mickey

implement the rest of /dev/mem devices; from netbsd


# 1.50 23-Jan-2002 art

move mb_map allocation to mbinit()


# 1.49 23-Jan-2002 art

move definition of mb_map from zillions of machdep.c to uipc_mbuf.c


# 1.48 16-Jan-2002 miod

Don't include <sys/map.h> when you don't need what's in it.


Revision tags: UBC_BASE
# 1.47 02-Dec-2001 mickey

branches: 1.47.2;
increase fixed extent storage


# 1.46 28-Nov-2001 art

zap some typedefs.
vm_map_t -> struct vm_map *
vm_map_entry_t -> struct vm_map_entry *
simple_lock_data_t -> struct simplelock

(uvm not done yet, coming in the next commit)


# 1.45 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.44 24-Nov-2001 miod

Harmonize boot() logic across arches:
- ensure RB_DUMP | RB_HALT will cause a dump
- or RB_HALT if (cold)
While there, honor RB_TIMEBAD on sparc64.


# 1.43 09-Nov-2001 art

nswbuf hasn't been used for ages. gc.


# 1.42 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.41 06-Nov-2001 miod

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


Revision tags: OPENBSD_3_0_BASE
# 1.40 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.39 12-Sep-2001 art

mbutl no more


# 1.38 23-Aug-2001 art

We can now move timeout_init into main().


# 1.37 23-Aug-2001 art

Remove even more old timeout tentacles.


# 1.36 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.35 05-Jul-2001 art

Get rid of REAL_CLISTS. It was never implemented and the tentacles are
everywhhere.


# 1.34 17-May-2001 provos

convert mbuf and cluster allocation to pool, mostly from NetBSD
okay art@ miod@


# 1.33 05-May-2001 art

Rename configure() to cpu_configure().
Move it from cpu_startup() to main().


# 1.32 05-May-2001 art

Get rid of CLSIZE and all related stuff.
CLSIZE -> 1
CLBYTES -> PAGE_SIZE
OLOFSET -> PAGE_MASK
etc.
At the same time some archs needed some cleaning in vmparam.h so that
goes in at the same time.


Revision tags: OPENBSD_2_9_BASE
# 1.31 29-Mar-2001 mickey

cpudev_data.h here needed not


# 1.30 22-Mar-2001 mickey

shuffle the tlb handlers a little,
make a new one for na data fault,
since those w/ hpt need it.


Revision tags: OPENBSD_2_8_BASE
# 1.29 15-Aug-2000 mickey

two btlb routines (i & d) for pcxs


# 1.28 15-Aug-2000 mickey

expand per-cpu control routines switch


# 1.27 08-Aug-2000 mickey

print btlb params w/ BTLBDEBUG; from Havard.Eidnes@runit.sintef.no


# 1.26 02-Jul-2000 mickey

no bays for stinger


Revision tags: OPENBSD_2_7_BASE
# 1.25 23-Mar-2000 mickey

new cpu type switch code.
initializes tlb miss handlers correspondent to probed cpu features.
also btlb load routine.
versions written are for pcxl and others.
cpu-dep btlb loaders are missing, only generic for now.


# 1.24 23-Mar-2000 art

New API for timeouts. Replaces the old timeout()/untimeout() API and
makes it the callers responsibility to allocate resources for the
timeouts.

This is a KISS implementation and does _not_ solve the problems of slow
handling of a large number of pending timeouts (this will be solved in
future work) (although hardclock is now guarateed to take constant time
for handling of timeouts).

Old timeout() and untimeout() are implemented as wrappers around the new
API and kept for compatibility. They will be removed as soon as all
subsystems are converted to use the new API.


# 1.23 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


# 1.22 22-Feb-2000 mickey

blah, blah, blah, msgbuf


Revision tags: SMP_BASE
# 1.21 09-Feb-2000 mickey

branches: 1.21.2;
heartbeat -- yeah we have a patch for that


# 1.20 25-Jan-2000 mickey

better copy and zero inlines in locore;
proper setregs() in machedep;
start of hpmc handler;
some cleanup here and there;


# 1.19 17-Jan-2000 mickey

remove unneeded stuff from setregs; force single-user for now, enable signal debug


# 1.18 11-Jan-2000 mickey

s/fpu_curproc/fpu_curpcb/ which also points into physical.
move it's definition into locore (where it's used the most).
adjust fpu context switch and save on swapout accordingly.
fix context save (in switch).
add accounting for fpu context switches (since it differes
from proc switching, we might get provided w/ some usefull
numbers as to how effective this lazy switch technique is).
enable handling fpu/sfu exceptions.


# 1.17 31-Dec-1999 mickey

don't bother about pidr3 and pidr4


# 1.16 17-Dec-1999 mickey

fix the panic message for sti memory mapping


Revision tags: kame_19991208
# 1.15 25-Nov-1999 mickey

bus stuff is in mainbus now, the rest is rewritten many ways


Revision tags: OPENBSD_2_6_BASE
# 1.14 20-Sep-1999 mickey

fix uvm_pagealloc() call


# 1.13 03-Sep-1999 art

Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.12 14-Aug-1999 mickey

proper debugging ifdefs


# 1.11 21-Jul-1999 mickey

rewrite the tlb miss handler and tlb dirty handler.
optimize for HVT usage (when compiled for proper cpu type).
drop hpt_* global variables, use info from control registers instead.
there are still ways to improve the tlb handlers tho.
machdep also prints cache and tlb coherence states (not related to the above).
You eat greenish muffin. --More-- You write real code.


# 1.10 12-Jul-1999 mickey

allocate 5% bufcache if <=16M memory installed


# 1.9 12-Jun-1999 mickey

hppa_init() now takes an argument from locore,
meaning the start of available memory.
cleanup machdep somewhat.
fix vm_map.pmap vs vm_pmap isue; 10x art@


# 1.8 23-May-1999 mickey

new swap stuff


# 1.7 21-May-1999 mickey

group all theMD f;ags together, add interrupt recursion one


# 1.6 21-May-1999 mickey

define fpu_curproc


# 1.5 20-Apr-1999 mickey

do lazy blok mapping of io space in bus_*
add copy{in,out}*, kcopy, etc
boot routines
cpu-id-hpux-compat stuff
rest of scheduler and such
uvm


Revision tags: OPENBSD_2_5_BASE
# 1.4 17-Feb-1999 mickey

print pa-risc here as well, since, finally, cpu will have to print processor type


# 1.3 04-Jan-1999 mickey

better cache handling in bus_space_barrier(), seem to work now


# 1.2 03-Jan-1999 mickey

implement bus_space_{un,}map w/ extents


# 1.1 30-Dec-1998 mickey

machdep; more work needed


# 1.256 01-May-2020 kettenis

Use the same inittodr()/resettodr() implementation as on
amd64/arm64/armv7/i386/sparc64 and move it to the end of machdep.c. Rework the
actual implementation for the MC14818 compatible RTC into something that can
be used as a todr_handle just like on amd64.

ok mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.255 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


Revision tags: OPENBSD_6_4_BASE
# 1.254 20-Jul-2018 guenther

Missed a 'ksi' -> '*ksip' change in previous commit


# 1.253 10-Jul-2018 guenther

Move from sendsig() to its callers the initsiginfo() calls and
instead of passing sendsig() the code+type+val, pass a siginfo_t*
to copy from. Eliminate the indirection through struct emul for
sendsig(); we no longer have a SunOS4-compat version of sendsig()

ok deraadt@


# 1.252 22-May-2018 guenther

Delete antique sigdebug definitions

ok kettenis@


# 1.251 12-Apr-2018 deraadt

Implement MAP_STACK option for mmap(). Synchronous faults (pagefault and
syscall) confirm the stack register points at MAP_STACK memory, otherwise
SIGSEGV is delivered. sigaltstack() and pthread_attr_setstack() are modified
to create a MAP_STACK sub-region which satisfies alignment requirements.
Observe that MAP_STACK can only be set/cleared by mmap(), which zeroes the
contents of the region -- there is no mprotect() equivalent operation, so
there is no MAP_STACK-adding gadget.
This opportunistic software-emulation of a stack protection bit makes
stack-pivot operations during ROPchain fragile (kind of like removing a
tool from the toolbox).
original discussion with tedu, uvm work by stefan, testing by mortimer
ok kettenis


Revision tags: OPENBSD_6_3_BASE
# 1.250 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.249 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


Revision tags: OPENBSD_6_2_BASE
# 1.248 18-May-2017 kettenis

Implement copyin32(9).

"your chicken scratches look fine to me" deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.247 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

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


# 1.246 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.245 21-May-2016 deraadt

hand-massage sendsig() and sys_sigreturn() to be much more similar.
ok guenther kettenis


# 1.244 10-May-2016 deraadt

SROP mitigation. sendsig() stores a (per-process ^ &sigcontext) cookie
inside the sigcontext. sigreturn(2) checks syscall entry was from the
exact PC addr in the (per-process ASLR) sigtramp, verifies the cookie,
and clears it to prevent sigcontext reuse.
not yet tested on landisk, sparc, *88k, socppc.
ok kettenis


# 1.243 20-Apr-2016 dlg

pool_setipl for floating point context things

ok kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.242 21-Oct-2015 mpi

Do not call uvm_swap_finicrypt_all() a second time in dumpsys().

ok tedu@, deraadt@, miod@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.241 20-Jan-2015 kettenis

Move ps_strings "after" the random stackgap. This makes its location a
per-process value, and therefpore turns the VM_PSSTRINGS sysctl into a
per-process one as well. This gets rid of a pointer to the bottom of the
stack at a fixed location. Also clears the road for unmapping the stackgap.

ok deraadt@


# 1.240 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.239 25-Oct-2014 kettenis

Remove vmmap; it isn't used.

ok jsing@


# 1.238 23-Oct-2014 miod

Correctly set up the HPMC trap entry: according to the PA-RISC Firmware
Architecture Reference Specification, the sum of the 8 trap entry words
*and* of the payload which address and length are to be set at well-known
positions in the aforementioned trap entry, needs to be zero; the existing
code was only enforcing that the sum of the trap entry words is zero.

This matches what Linux and NetBSD do.

ok kettenis@


# 1.237 23-Oct-2014 miod

Revert limiting physmem to 2GB; the culprit was likely in uvm and uvm has
changed a lot in the last 5 years; verified to work on a 3GB system, in
snapshots for a few weeks already.


# 1.236 22-Sep-2014 dlg

implement atomic_{cas,swap}_{uint,ulong,ptr} and
atomic_{add,sub}_{int,long}_nv. sys/atomic.h turns these into the
rest of the atomic api.

on uniprocessor hppa systems "atomic" operations are implemented
as a non-interruptable sequence by disabling all interrupts on the
cpu, doing the operation, and then restoring the interrupt mask.

this isnt enough on MP systems, so we added a global atomic memory
mutex that is taken inside the interrupt disabling above to coordinate
operations between cpus.

this is a lot of overhead though cos mutexes dance around with ipls,
which is unecessary in our case because of the interrupt disabling
that is already done. also, hppa spinlocks are implemented with
ldcw which requires the word it operates on to be 16 byte aligned.
mutexes arent guaranteed to have this alignment so they compensate
by having lots of words inside themselves so they can hit the
appropriate one to use for the ldcw op.

with this in mind, this change pulls __cpu_simple_locks, which are
simply ldcw spinlocks with a 16 byte aligned word, out of
src/sys/arch/hppa/include/lock.h into src/sys/arch/hppa/include/atomic.h
so atomic.h can use them. lock.h includes atomic.h, so it still
gets and provides the same functionality as before.

finally, this also pulls the rwlock cas implementation apart. cas
ops now share the same serialising lock on MP systems as the other
memory operations, and rw_cas is defined as a wrapper around
atomic_cas_uint.

ok kettenis@


# 1.235 19-Sep-2014 kettenis

Use config_suspend_all(9).


# 1.234 18-Aug-2014 dlg

dont rely on mbuf.h to provide pool.h.

ok miod@, who has offerred to help with any MD fallout
ok guenther@


Revision tags: OPENBSD_5_6_BASE
# 1.233 22-Jul-2014 uebayasi

boot(9): Reduce diffs between hppa & hppa64 (& others)


# 1.232 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.231 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.230 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.229 13-Jul-2014 miod

These still need <sys/reboot.h> for the RB_ constants.


# 1.228 12-Jul-2014 uebayasi

reboot(9), panic(9): Call panic(9) for unrecoverable MD H/W errors (NMIs)

Some architectures have ability to detect hardware sanity and notify system
(NMI, firmware callback, etc.). Handle these hardware severe errors, same
as software errors, with panic(9).

According to miod@, SGI IP27 NMI is triggered by pushing some "hidden" button,
which "usual" users/admins don't know. Pushing such a button is "RB_USERREQ"
(human-triggered) in that the button is pushed by a human, but not "RB_USERREQ"
in that no user intervention in system (== no command input) is done. miod@
agreed that changing these from RB_USERREQ to !RB_USERREQ (== panic(9)) is
not a big problem.

OK miod@ kettenis@


# 1.227 12-Jul-2014 uebayasi

boot(9), reboot(9): Migrate MD callers of boot(9) to reboot(9)

I have found that some ports call boot(9) from machine-dependent code to
reboot system. These should be changed to either:

- Sending signal to init(8) to trigger it to shutdown system cleanly, like
acpi(4) does, in cases where found problems don't prevent system from working
immediately, or

- Just doing panic(9) if the situation is severely broken.

For now, just rewrite boot() to reboot(). Actual fixes follow.

Discussed with & OK from kettenis@


# 1.226 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.225 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.224 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.223 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.222 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.221 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.220 08-May-2014 miod

Format string fixes and removal of -Wno-format for hppa kernels.


# 1.219 08-Apr-2014 mpi

Less <uvm/uvm.h>


# 1.218 04-Apr-2014 miod

If the PDC_COPROC call fails, and we are running on a PA 1.1 system, assume
the usual 1.1 coprocessor mask, instead of using zero and having every
userland process dying with signal 4.

The circumstances under which this call fails are unclear and could be
tied to specific PROM version (I have tried overzealous stack alignment and
other tricks, to no avail). Interestingly enough, the 715/75 system which
hits this problem, only triggers it when booting from disk, and never when
booting from network.

This diff is an ugly bandaid until the problem is better understood. Or maybe
it is not worth investigating, seeing that Linux hardcodes the coprocessor
mask and never issues PDC_COPROC calls; I wonder what HP/UX does.

In my tree for over 18 months; "Looks like a nice hack" deraadt@
715/75 system provided by Sebastiaan Indesteege, thanks!


# 1.217 29-Mar-2014 guenther

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

ok dlg@ mpi@ deraadt@


# 1.216 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


# 1.215 22-Mar-2014 guenther

Move p_sigacts from struct proc to struct process.

testing help mpi@


# 1.214 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


Revision tags: OPENBSD_5_5_BASE
# 1.213 23-Nov-2013 uebayasi

Run doshutdownhooks() and config_suspend() even when boot() is called while
cold != 0. Indent and make hppa/hppa64 boot() closer to others.

OK kettenis@


# 1.212 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


Revision tags: OPENBSD_5_4_BASE
# 1.211 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


Revision tags: OPENBSD_5_3_BASE
# 1.210 02-Dec-2012 guenther

Determine whether we're currently on the alternative signal stack
dynamically, by comparing the stack pointer against the altstack
base and size, so that you get the correct answer if you longjmp
out of the signal handler, as tested by regress/sys/kern/stackjmp/.
Also, fix alt stack handling on vax, where it was completely broken.

Testing and corrections by miod@, krw@, tobiasu@, pirofti@


# 1.209 26-Oct-2012 kettenis

Properly clear trap frame in setregs() to avoid leaking registers across exec.

ok jsing@


# 1.208 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.207 07-Oct-2012 kettenis

Align the stack on a 64-byte boundary as required by "The 32-bit PA-RISC
Run-time Architecture Document". GCC relies on this to properly align
stack variables.

ok guenther@, beck@


Revision tags: OPENBSD_5_2_BASE
# 1.206 21-Jun-2012 guenther

__tfork() needs to set the stack address of the new thread in the kernel,
so that it can't get a signal while still running on the parent thread's
stack. Also, pass in sizeof(struct __tfork) to provide forward compat
when more members are added. This is an ABI change, so switch syscall
numbers and bump lib majors this time.

ok deraadt@ matthew@


Revision tags: OPENBSD_5_1_BASE
# 1.205 20-Sep-2011 miod

Clear RB_POWERDOWN early in boot() on systems which can not powerdown and
which firmware does not send spin up commands to the disks, in case the
operator changes his mind and reboots instead of manually powering down
after the system has halted.
ok kettenis@


Revision tags: OPENBSD_5_0_BASE
# 1.204 05-Jul-2011 guenther

Recommit the reverted sigacts change now that the NFS use-after-free
problem has been tracked down. This fixes the sharing of the signal
handling state: shared bits go in sigacts, per-rthread bits goes in
struct proc.

ok deraadt@


# 1.203 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.202 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.201 18-Apr-2011 guenther

Revert the sigacts diff: NFS can apparently retain pointers to processes
until they're zombies and then send them signals (for intr mounts). Until
that is untangled, the sigacts change is unsafe. sthen@ was the victim
for this one


# 1.200 15-Apr-2011 guenther

Correct the sharing of the signal handling state: stuff that should
be shared (p_sigignore, p_sigcatch, P_NOCLDSTOP, P_NOCLDWAIT) moves
to struct sigacts, wihle stuff that should be per rthread (ps_oldmask,
SAS_OLDMASK, ps_sigstk) moves to struct proc. Treat the coredumping
state bits (ps_sig, ps_code, ps_type, ps_sigval) as per-rthread
until our locking around coredumping is better.

Oh, and remove the old SunOS-compat ps_usertramp member.

"I like the sound of this" tedu@


Revision tags: OPENBSD_4_9_BASE
# 1.199 14-Jan-2011 jsing

Halt secondary CPUs when shutting down or rebooting. This should prevent
occasional hangs during reboot.

ok kettenis@


# 1.198 04-Jan-2011 jasper

- de-register. no binary change.

ok jsing@


# 1.197 01-Jan-2011 jasper

Move setting cpu_hzticks to the clock initialization function, like
other ports (e.g. hppa64) do.

ok jsing@ kettenis@


# 1.196 01-Jan-2011 jasper

- ansify

ok jsing@ kettenis@


# 1.195 30-Dec-2010 jsing

Turn signotify() into a function that also calls cpu_unidle().

ok kettenis@


# 1.194 20-Nov-2010 miod

This is a first step towards getting rid of avail_start and avail_end in the
kernel, currently limited to low-hanging fruit: these variables were used
by bus_dma to specify the range in which to allocate memory, back when
uvm_pglistalloc() was stupid and would not walk the vm_physseg[].

Nowadays, except on some platforms for early initialization, these variables
are not used, or do not need to be global variables. Therefore:
- remove `extern' declarations of avail_start and avail_end (or close cousins,
such as arm physical_start and physical_end) from files which no longer need
to use them.
- make them local variables whenever possible.
- remove them when they are assigned to but no longer used.


Revision tags: OPENBSD_4_8_BASE
# 1.193 01-Jul-2010 jsing

Create a struct to store FP state and include a pointer to the CPU that
currently holds the FPU context for this process. This will be soon used
to implement FPU shootdowns on multiprocessor kernels.

ok kettenis@


# 1.192 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.191 29-Jun-2010 jsing

Factor out code used to save and flushe process FPU context.

ok kettenis@


# 1.190 29-Jun-2010 jsing

Store pointer to process FPU state in struct cpu_info.

ok kettenis@


# 1.189 27-Jun-2010 thib

uvm constraints. Add two mandatory MD symbols, uvm_md_constraints
which contains the constraints for DMA/memory allocation for each
architecture, and dma_constraints which contains the range of addresses
that are dma accessable by the system.

This is based on ariane@'s physcontig diff, with lots of bugfixes and
additions the following additions by my self:

Introduce a new function pool_set_constraints() which sets the address
range for which we allocate pages for the pool from, this is now used
for the mbuf/mbuf cluster pools to keep them dma accessible.

The !direct archs no longer stuff pages into the kernel object in
uvm_km_getpage_pla but rather do a pmap_extract() in uvm_km_putpages.

Tested heavily by my self on i386, amd64 and sparc64. Some tests on
alpha and SGI.

"commit it" beck, art, oga, deraadt
"i like the diff" deraadt


# 1.188 27-Jun-2010 jsing

Use a mutex to make atomic operations atomic on multiprocessor kernels.

ok kettenis@


# 1.187 10-Jun-2010 deraadt

Declare safepri at the MD level on each platform, so that the kern_synch.c
does not have to deal with it as a common. Some platforms may be missed
by this commit... if you spot one, fix it the same way.
ok miod


# 1.186 09-Jun-2010 miod

Move declaration of cn_tab from dev/cons.c to dev/cninit.c, or appropriate
md files for ports which do not use dev/cninit.c. This gets rid of a common
at kernel link time.
feedback drahn@ ok deraadt@


# 1.185 24-May-2010 deraadt

Add missing prototypes
ok jsing kettenis


# 1.184 09-May-2010 kettenis

Prevent "taken branch" exceptions from kernel space by clearing the PSL_T
bit before we enter a signal handler.

"if you say so" miod@, "seems to make sense" jsing@


# 1.183 02-May-2010 kettenis

Properly initialize the members of `struct mdproc' that deal with
single-stepping when we fork and reset them upon exec.

ok miod@


# 1.182 27-Apr-2010 kettenis

Avoid null-pointer dereference by giving proc0 a place to store its
floating-point registers. Pointed out by Nick Hudson.

ok miod@, jsing@


# 1.181 19-Apr-2010 jsing

Make the Processor Status Word (PSW) a per-CPU value.

ok kettenis@


# 1.180 01-Apr-2010 jsing

Allow for multiple CPUs by moving to an array of cpu_info.

ok kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.179 31-Dec-2009 jsing

Make cpl and cpu_inintr per CPU variables. For locore.S, cpl becomes an
offset within cpu_primary_info - this will need to be revisited shortly.

ok kettenis@


# 1.178 11-Aug-2009 miod

Do not bother initializing bufpages in the md code if the computation is
exactly the same the mi could will use if bufinit() is invoked with
bufpages == 0.


# 1.177 11-Aug-2009 miod

With the SysV memory allocation changes, allocsys() doesn't do anything
anymore. Get rid of it completely.


# 1.176 09-Aug-2009 blambert

Rototill system V message queues.

No longer allocate a static amount of memory for messages in MD
boot path; message queues, message metadata, and message data now
all use dynamic memory, which means that runtime sysctls should now
be trivial to implement.

Since I'm going to be around all week to fix any breakage, this should
probably just go in now.


# 1.175 02-Aug-2009 beck

Dynamic buffer cache support - a re-commit of what was backed out
after c2k9

allows buffer cache to be extended and grow/shrink dynamically

tested by many, ok oga@, "why not just commit it" deraadt@


# 1.174 29-Jul-2009 kettenis

Get rid of non-equivalent aliases of the pcb by moving the fpu state out
of the pcb and using the p_addr member of 'struct proc' to calculate the
address of the kernel stack when switching to virtual mode after taking a trap.
Remove the now unecessary cache flushes; they're actually harmful since they
create non-equivalent aliases. This seems to fix the memory corruption we
have been observing from time to time.

This diff does not rename fpu_curpcb, which is now somewhat incorrectly named.
I hope to change things back again as soon as we are able to map the pcb 1:1.


Revision tags: OPENBSD_4_6_BASE
# 1.173 15-Jun-2009 beck

Back out all the buffer cache changes I committed during c2k9. This reverts three
commits:

1) The sysctl allowing bufcachepercent to be changed at boot time.
2) The change moving the buffer cache hash chains to a red-black tree
3) The dynamic buffer cache (Which depended on the earlier too).

ok on the backout from marco and todd


# 1.172 03-Jun-2009 beck

add kern.bufcachepercent sysctl to allow adjusting the buffer cache
size on a running system.
ok art@, oga@


Revision tags: OPENBSD_4_5_BASE
# 1.171 14-Feb-2009 kettenis

Limit the amount of physical memory to 2GB. Using more causes memory
corruption on PA-RISC 2.0 systems (and there are very few PA-RISC 1.1
systems that support more than 2GB).

ok miod@


# 1.170 04-Feb-2009 miod

On systems with split BTLB, do not bother trying to insert DBTLB entries,
as PDC will lie to us pretending it did while it didn't.

ok kettenis@


# 1.169 04-Feb-2009 miod

Unify memory size reports a bit more: always report size in MB, and report
reserved memory on alpha and hppa on its own line (as done on sgi).


Revision tags: OPENBSD_4_4_BASE
# 1.168 14-Jul-2008 miod

Be sure to propagate PSL_O in psw on PCXU* processors to userland processes
and signal handlers.
ok kettenis@


# 1.167 27-Jun-2008 miod

Clear swap encryption keys before dumping a kernel image.


# 1.166 09-Apr-2008 deraadt

Add new stub uvm_shutdown() and call it from the right place in MD boot()


Revision tags: OPENBSD_4_3_BASE
# 1.165 22-Sep-2007 martin

replace even more ctob and btoc with ptoa and atop respectively plus
uvm_extern.h where needed


Revision tags: OPENBSD_4_2_BASE
# 1.164 22-Jul-2007 kettenis

Move hppa to __HAVE_TIMECOUNTERS.


# 1.163 20-Jul-2007 kettenis

Give hppa the blink_led API from sparc64, and the associated machdep.led_blink
sysctl.


# 1.162 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.161 14-Jul-2007 kettenis

Make sigreturn(2) set the proper space ID for the instruction queue. Fixes
a few more pthreads regression tests.

ok miod@


# 1.160 10-Jul-2007 kettenis

Don't trust the privilige level in the sigcontext passed to sigreturn(2).

ok miod@


# 1.159 24-Jun-2007 kettenis

Crank initial storage for extents a bit. We really should allocate extents
using malloc once vm is initialised, but this will do for now.

ok deraadt@


# 1.158 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.157 27-May-2007 miod

Make sure the minaddr hint for uvm_km_suballoc() calls is always initialized.
ok pedro@


# 1.156 26-May-2007 pedro

Dynamic buffer cache. Initial diff from mickey@, okay art@ beck@ toby@
deraadt@ dlg@.


# 1.155 21-May-2007 kettenis

Add support for 8700/pcxw2 cpu.


# 1.154 21-May-2007 kettenis

Ask firmware for reset before trying ourselves; needed for four-digit b/c/j
workstations.

tested by otto@, krw@; ok deraadt@


# 1.153 17-May-2007 art

Limit hppa buffer cache to 30%. It used to be 70% because stack garbage
that was used for minaddr instead of the proper vm_map_min(kernel_map)
(fixed in this diff).

From mickey. art@ ok


# 1.152 14-May-2007 martin

move hppa to __HAVE_CPUINFO

input from miod@, ok kettenis@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.151 28-May-2006 martin

minor nit, use CPU ID instead of FPU ID for BTLB parameters after passing
all kludges


# 1.150 15-Apr-2006 martin

make warning about missing HPT support DEBUG for now

ok mickey@


Revision tags: OPENBSD_3_9_BASE
# 1.149 26-Oct-2005 martin

no more hppa_round_page() and hppa_trunc_page() macros

ok mickey@


Revision tags: OPENBSD_3_8_BASE
# 1.148 06-Aug-2005 miod

We do not need a char machine_arch[] constant.
ok deraadt@


# 1.147 11-Jul-2005 mickey

align some stupid comments


# 1.146 10-May-2005 mickey

set pcsq in case we get signal delivery once interrupted from the gateway page; from chs


# 1.145 18-Apr-2005 mickey

do not do some of the initmsgbuf()s job


# 1.144 07-Apr-2005 mickey

on some machines it's possible to limit the amount of physmem initialised dring post so having msgbuf at the end of memory shall work


# 1.143 07-Apr-2005 mickey

64bit-friendly pdc.h and iomod.h and correspondent changes elsewhere


# 1.142 26-Mar-2005 mickey

md parts for hpux_compa code; some problems w/ signals delivery still exist


Revision tags: OPENBSD_3_7_BASE
# 1.141 24-Feb-2005 mickey

do not even ask for btlb on 8k cpus as pdc pretends there is some but then it does not work; found w/ Moritz Kiese <mbk@mytum.de> on c180; add a debug print and fix pcxu entry


# 1.140 17-Nov-2004 mickey

print real/avail/bufcache sizes as unsigned


# 1.139 26-Oct-2004 mickey

disable sid hashing on pcxu and above


# 1.138 14-Oct-2004 mickey

a bit larger delays during boot() to let msgs appear


# 1.137 19-Sep-2004 mickey

turn totalphysmem into physmem and name old physmem into smth it really is


# 1.136 18-Sep-2004 mickey

oops


# 1.135 15-Sep-2004 mickey

add pcxu tlb handlers and cpu probing
add u2/uturn ioa driver in dumb mode now
enable pcxu/pcxw support


# 1.134 14-Sep-2004 mickey

store fpu version for later use. make sure to proper store/clear fpu state in fork/exec/exit/sendsig


# 1.133 14-Sep-2004 mickey

error out from btlb_insert() if there is none


Revision tags: OPENBSD_3_6_BASE
# 1.132 01-Jul-2004 mickey

have separate insn and data cache all-flushers


# 1.131 30-Jun-2004 mickey

allow forced fpu emulation through a sysctl


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.130 13-May-2004 mickey

8ks do not have hvt


# 1.129 05-May-2004 mickey

much easier tlb handler branch patching


# 1.128 05-May-2004 mickey

do not engage HPT on PCXT' (yet)


# 1.127 08-Apr-2004 mickey

repair pcxs/t confoosion


# 1.126 07-Apr-2004 mickey

update copyright; miod@ is fine w/ files where he holds it too


Revision tags: OPENBSD_3_5_BASE
# 1.125 10-Mar-2004 tom

Ensure that we obey a user's ddb> boot reboot command even if the system
is cold (during startup).

This adds RB_USERREQ to sys/reboot.h, uses it in the ddb commands, and
ensures that */*/machdep.c:boot() won't set RB_HALT when cold if this
flag is set.

ok deraadt@


# 1.124 14-Feb-2004 grange

Simplify hw.{cpuspeed,setperf} api moving all the sysctl stuff
from the underlying callbacks.

Testing hppa mickey@, ppc drahn@
Ok markus@ tedu@


# 1.123 05-Jan-2004 mickey

kill debugging code that is not needed anymore


# 1.122 23-Dec-2003 mickey

provide cpuspeed fluff


# 1.121 20-Dec-2003 miod

Don't let microtime() return a struct timeval with exactly 1000000 microseconds.


# 1.120 18-Dec-2003 mickey

spls do not protect cpu_itmr and thus time might jump back sometimes due to cpu_itmr modified to a higher value than a read itmr; found and testing by miod@


# 1.119 17-Dec-2003 mickey

in the real mem print do not include reserved for prom into used by openbsd


# 1.118 10-Dec-2003 mickey

for unaligned btlb mapping attempts -- just fail


# 1.117 24-Nov-2003 mickey

experimental support for HVT as a 2nd level tlb


# 1.116 15-Oct-2003 mickey

less global name space pollution


# 1.115 05-Oct-2003 mickey

reload the itmr as soon as we get the intr to avoid lagging on slower machines


# 1.114 25-Sep-2003 mickey

some pcxl2 do not report fpus -- assume it's there


Revision tags: OPENBSD_3_4_BASE
# 1.113 04-Sep-2003 mickey

a better cpu identification; testing by miod


# 1.112 31-Aug-2003 miod

pdc_model needs to be visible from cpu.c


# 1.111 20-Aug-2003 mickey

missing nl in debugging prontf


# 1.110 07-Aug-2003 mickey

dead proto


# 1.109 07-Aug-2003 mickey

first allocate space on stack then copyout signal shits. add a DEBUG check for a whacky user pc (as impossible due to the recent trap.c change)


# 1.108 03-Aug-2003 mickey

clear branch and nullify bits in psw on sending a signal


# 1.107 30-Jul-2003 mickey

deduce the leds address from the model number and thus make some more use of that lichtenblinkenschmutz on some more machinens


# 1.106 22-May-2003 mickey

imprecision in delay_init()


# 1.105 18-May-2003 mickey

save the fpu state for the signal handler. this is essential
as the fpu regs can be used by the gcc even for non-fpu
means and data copying.
rearrange the sigcontext a bit to include only the general
registers that are needed restoring upon return and thus
less waste of space and make up some space for the fpu regs.

ALL software that used the signal context on the stack
needs at least rebuilding now. a new snap has bin built as well.


Revision tags: UBC_SYNC_A
# 1.104 11-May-2003 deraadt

string cleaning; krw ok


# 1.103 07-Apr-2003 mickey

s/HP9000/HP 9000/; from weissmanndude


Revision tags: OPENBSD_3_3_BASE
# 1.102 18-Feb-2003 deraadt

knf; mickey ok


# 1.101 12-Feb-2003 jason

How uncommon... hppa only has one common: msgbufmapped (decl'd in /sys/kern)


# 1.100 12-Feb-2003 mickey

only align the first stack frame onto the minimal required alignment


# 1.99 10-Feb-2003 mickey

fix pcs and pcxt recognition. from weissmanndude


# 1.98 22-Jan-2003 mickey

consistantly use uvm_prot_* vs vm_prot_* evewrhere


# 1.97 14-Jan-2003 mickey

fix cutnpaste in the cpu table for the itlbna field; from herr weissmanndude


# 1.96 14-Jan-2003 mickey

need pdc_hwtlb always; pt out by herr weissmanndude


# 1.95 13-Jan-2003 mickey

fix the logic in hvt probing


# 1.94 09-Jan-2003 miod

Remove fetch(9) and store(9) functions from the kernel, and replace the few
remaining instances of them with appropriate copy(9) usage.

ok art@, tested on all arches unless my memory is non-ECC


# 1.93 19-Dec-2002 mickey

setregs: put the whole frame setup into one place


# 1.92 19-Dec-2002 mickey

level 0x16 is really an l2


# 1.91 17-Dec-2002 millert

Make SysV-style shared memory and semaphore limits sysctl'able.
Instead of allocating a static amount of memory for the data
structures via valloc() in allocsys(), allocate things dynamically
using pool(9) when possible and malloc(9) when not. The various
members of struct seminfo and struct shminfo are in kern.seminfo
and kern.shminfo respectively (not all members of kern.seminfo are
changable).

The data structures used still leave something to be desired but
things are not made worse in that respect by this commit.


# 1.90 27-Nov-2002 mickey

no wrapper arounf hardclock(), use CPU_CLOCKUPDATE, real microtime; miod ok


# 1.89 08-Nov-2002 mickey

Don't uvm_useracc the user sigcontext in sys_sigreturn and then access
the user addresses directly from the kernel. copyin is faster and can
correctly deal properly with mappings that uvm_useracc thinks are
correct but will fault anyway (to figure out how to generate such
mappings is left as en excercise for the reader).


# 1.88 01-Nov-2002 mickey

add a missing delay after printf on halt[-p], proper arg for a cold hook


Revision tags: UBC_SYNC_B
# 1.87 22-Oct-2002 mickey

do not force single-user; pt out by fries@


# 1.86 15-Oct-2002 mickey

missing initmsgbuf(), noticed by miod@


# 1.85 13-Oct-2002 mickey

track the end of physmem for use in dmmem_alloc


# 1.84 07-Oct-2002 mickey

s/PSW_/PSL_/ to match other archs


# 1.83 07-Oct-2002 mickey

proper terminate the user stack on signal


# 1.82 07-Oct-2002 mickey

on implementations w/ fpu included unimplemented instructions
are signaled through the exception trap w/ invalid opcode marked
instruction in the exception registers, not through the emulation
trap (as long as the fpu is enabled, of course).
parse emulation from the exception trap as well as the emulation
trap and fix the dispatcher into usable condition.
parse invalid op exception on trap and signal the user appropriately.
reset the exception on exec and for child on fork.
the later is appropriate since exceptions are delayed until next
fpu instruction, which was in the parent indeed, let him get it.
save parent's fpu context on fork before cipying it, if the
parent owned the fpu.


Revision tags: OPENBSD_3_2_BASE
# 1.81 23-Sep-2002 mickey

parisc level 0x10 is just an overclocked 0xe


# 1.80 17-Sep-2002 mickey

handle fpu exceptions properly, might use a regress, i guess


# 1.79 11-Sep-2002 mickey

provide a convinient reset label


# 1.78 11-Sep-2002 mickey

stack grows the other way, but the frame is the other way to that. hehe


# 1.77 09-Sep-2002 mickey

set up the frame flags and a user frame better on exec


# 1.76 03-Aug-2002 mickey

rework boot() w/o a goto


# 1.75 25-Jul-2002 mickey

missing arg in the call to the pdc_call since some old times


# 1.74 25-Jul-2002 mickey

kcopy is a space-to-space copy from kernel space, to guess where, -- to the same kernel space, just error on fault


# 1.73 20-Jul-2002 art

Instead of copying out the signal trampoline on top of the stack, create
an uvm aobj, copy out the signal trampoline into it and share that page
among all processes for the same emulation.

This also requires us to actually be able to tell signal code where the
trampoline is located, so introduce a new field in struct proc - p_sigcode
that is a pointer to sigcode. This allows us to remove all the ugly
calculations of the signal trampoline address done in every sendsig
function in the tree (that's why so many files are changed).

Tested by various people. ok deraadt@


# 1.72 14-May-2002 mickey

disable sid hashing while still in real mode, alos print the parisc arch once and not per each cpu since they are not intermixable architecture-wise


# 1.71 13-May-2002 mickey

ldi-ldo whatever was in the table, be that much clever


# 1.70 08-May-2002 mickey

print parisc level w/ the the parisc version, not for each cpu


# 1.69 08-May-2002 mickey

kill debugging printfski


# 1.68 22-Apr-2002 mickey

no longer batc the data, only the code.
this removes a constraint and an ld.script dependancy
for the .data and the dynamically allocated kernel
structures existed w/ batcing. also makes pmap_steal_memory
obsolete and replaced w/ the pmap_virtual_space.
implement batching for pmap_remove to avoid
zeroing out the pte entries if pde will be removed anyway.


# 1.67 21-Apr-2002 mickey

better buf's mapping and less magic constants in checking for io space cachability


Revision tags: OPENBSD_3_1_BASE
# 1.66 26-Mar-2002 mickey

if cannot guess cpu model default to the lowest supported one


# 1.65 25-Mar-2002 deraadt

spelling


# 1.64 23-Mar-2002 espie

Add variables for config(8) -e time tweak of systemV shared memory
parameters.

Ok millert@, miod@, maja@


# 1.63 19-Mar-2002 mickey

mtcpu seq requires a pre-sync, implement hpt init for pcxl


# 1.62 15-Mar-2002 mickey

rewrite a pmap to use multilevel page tables.
lower 12 bits contain the perms, no unused bits left,
but a couple for off-tlb use (as the ref implemented now).
do not use the hvt, which might get some use later
if proven to speed thigs up, tlb handlers would po
another dozen of insns though, but if that's worth its...
move on the data seg and map kernel text rdonly (idea form fredette),
since all of the page0 mods done before that we are all fine
except for some viper fluff, but later w/ that.
this also picks up a bit more of ddb magic for bpt and ss.
tlb handlers can use a little bit more of attention,
but things, visually, seem to be much faster already, --
sorry, no benchmarks for now.

* effort sponsored in part by the `henry st. old ale house'
* and mr.pete and mr.lee in particular in thier generous entrirety.
* the proj took a little more that 72man*h as it was expected,
* but within murhy's law estimations.


# 1.61 14-Mar-2002 millert

First round of __P removal in sys


# 1.60 20-Feb-2002 mickey

setup power failure handler (for sw-controlled power button), move toc handler


# 1.59 17-Feb-2002 maja

Patch from Daniel Lucq <daniel@lucq.org>

The patch allows you to change the value of NMBCLUSTERS, BUFCACHEPERCENT
and NKMEMPAGES using the config command, instead of recompiling the kernel.

This is the kernel part of the patch. I have compiled it on i386, sparc64,
alpha and macppc. -moj ok art@ maja@


# 1.58 12-Feb-2002 mickey

support 712's programmable power switch, no interrupt yet


# 1.57 12-Feb-2002 mickey

small repairs to hpmc and toc handlers


# 1.56 11-Feb-2002 mickey

disable fpu on csw, print fpu version on cpu line, if present


# 1.55 07-Feb-2002 mickey

fix sigdebug cases; init sigcontext before it's used (;


# 1.54 06-Feb-2002 mickey

implement signal delivery; based on fredette@'s work


# 1.53 03-Feb-2002 mickey

restore hpt size computation, does not break things as i thought


# 1.52 02-Feb-2002 mickey

fix 'physmem' usage


# 1.51 02-Feb-2002 mickey

implement the rest of /dev/mem devices; from netbsd


# 1.50 23-Jan-2002 art

move mb_map allocation to mbinit()


# 1.49 23-Jan-2002 art

move definition of mb_map from zillions of machdep.c to uipc_mbuf.c


# 1.48 16-Jan-2002 miod

Don't include <sys/map.h> when you don't need what's in it.


Revision tags: UBC_BASE
# 1.47 02-Dec-2001 mickey

branches: 1.47.2;
increase fixed extent storage


# 1.46 28-Nov-2001 art

zap some typedefs.
vm_map_t -> struct vm_map *
vm_map_entry_t -> struct vm_map_entry *
simple_lock_data_t -> struct simplelock

(uvm not done yet, coming in the next commit)


# 1.45 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.44 24-Nov-2001 miod

Harmonize boot() logic across arches:
- ensure RB_DUMP | RB_HALT will cause a dump
- or RB_HALT if (cold)
While there, honor RB_TIMEBAD on sparc64.


# 1.43 09-Nov-2001 art

nswbuf hasn't been used for ages. gc.


# 1.42 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.41 06-Nov-2001 miod

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


Revision tags: OPENBSD_3_0_BASE
# 1.40 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.39 12-Sep-2001 art

mbutl no more


# 1.38 23-Aug-2001 art

We can now move timeout_init into main().


# 1.37 23-Aug-2001 art

Remove even more old timeout tentacles.


# 1.36 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.35 05-Jul-2001 art

Get rid of REAL_CLISTS. It was never implemented and the tentacles are
everywhhere.


# 1.34 17-May-2001 provos

convert mbuf and cluster allocation to pool, mostly from NetBSD
okay art@ miod@


# 1.33 05-May-2001 art

Rename configure() to cpu_configure().
Move it from cpu_startup() to main().


# 1.32 05-May-2001 art

Get rid of CLSIZE and all related stuff.
CLSIZE -> 1
CLBYTES -> PAGE_SIZE
OLOFSET -> PAGE_MASK
etc.
At the same time some archs needed some cleaning in vmparam.h so that
goes in at the same time.


Revision tags: OPENBSD_2_9_BASE
# 1.31 29-Mar-2001 mickey

cpudev_data.h here needed not


# 1.30 22-Mar-2001 mickey

shuffle the tlb handlers a little,
make a new one for na data fault,
since those w/ hpt need it.


Revision tags: OPENBSD_2_8_BASE
# 1.29 15-Aug-2000 mickey

two btlb routines (i & d) for pcxs


# 1.28 15-Aug-2000 mickey

expand per-cpu control routines switch


# 1.27 08-Aug-2000 mickey

print btlb params w/ BTLBDEBUG; from Havard.Eidnes@runit.sintef.no


# 1.26 02-Jul-2000 mickey

no bays for stinger


Revision tags: OPENBSD_2_7_BASE
# 1.25 23-Mar-2000 mickey

new cpu type switch code.
initializes tlb miss handlers correspondent to probed cpu features.
also btlb load routine.
versions written are for pcxl and others.
cpu-dep btlb loaders are missing, only generic for now.


# 1.24 23-Mar-2000 art

New API for timeouts. Replaces the old timeout()/untimeout() API and
makes it the callers responsibility to allocate resources for the
timeouts.

This is a KISS implementation and does _not_ solve the problems of slow
handling of a large number of pending timeouts (this will be solved in
future work) (although hardclock is now guarateed to take constant time
for handling of timeouts).

Old timeout() and untimeout() are implemented as wrappers around the new
API and kept for compatibility. They will be removed as soon as all
subsystems are converted to use the new API.


# 1.23 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


# 1.22 22-Feb-2000 mickey

blah, blah, blah, msgbuf


Revision tags: SMP_BASE
# 1.21 09-Feb-2000 mickey

branches: 1.21.2;
heartbeat -- yeah we have a patch for that


# 1.20 25-Jan-2000 mickey

better copy and zero inlines in locore;
proper setregs() in machedep;
start of hpmc handler;
some cleanup here and there;


# 1.19 17-Jan-2000 mickey

remove unneeded stuff from setregs; force single-user for now, enable signal debug


# 1.18 11-Jan-2000 mickey

s/fpu_curproc/fpu_curpcb/ which also points into physical.
move it's definition into locore (where it's used the most).
adjust fpu context switch and save on swapout accordingly.
fix context save (in switch).
add accounting for fpu context switches (since it differes
from proc switching, we might get provided w/ some usefull
numbers as to how effective this lazy switch technique is).
enable handling fpu/sfu exceptions.


# 1.17 31-Dec-1999 mickey

don't bother about pidr3 and pidr4


# 1.16 17-Dec-1999 mickey

fix the panic message for sti memory mapping


Revision tags: kame_19991208
# 1.15 25-Nov-1999 mickey

bus stuff is in mainbus now, the rest is rewritten many ways


Revision tags: OPENBSD_2_6_BASE
# 1.14 20-Sep-1999 mickey

fix uvm_pagealloc() call


# 1.13 03-Sep-1999 art

Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.12 14-Aug-1999 mickey

proper debugging ifdefs


# 1.11 21-Jul-1999 mickey

rewrite the tlb miss handler and tlb dirty handler.
optimize for HVT usage (when compiled for proper cpu type).
drop hpt_* global variables, use info from control registers instead.
there are still ways to improve the tlb handlers tho.
machdep also prints cache and tlb coherence states (not related to the above).
You eat greenish muffin. --More-- You write real code.


# 1.10 12-Jul-1999 mickey

allocate 5% bufcache if <=16M memory installed


# 1.9 12-Jun-1999 mickey

hppa_init() now takes an argument from locore,
meaning the start of available memory.
cleanup machdep somewhat.
fix vm_map.pmap vs vm_pmap isue; 10x art@


# 1.8 23-May-1999 mickey

new swap stuff


# 1.7 21-May-1999 mickey

group all theMD f;ags together, add interrupt recursion one


# 1.6 21-May-1999 mickey

define fpu_curproc


# 1.5 20-Apr-1999 mickey

do lazy blok mapping of io space in bus_*
add copy{in,out}*, kcopy, etc
boot routines
cpu-id-hpux-compat stuff
rest of scheduler and such
uvm


Revision tags: OPENBSD_2_5_BASE
# 1.4 17-Feb-1999 mickey

print pa-risc here as well, since, finally, cpu will have to print processor type


# 1.3 04-Jan-1999 mickey

better cache handling in bus_space_barrier(), seem to work now


# 1.2 03-Jan-1999 mickey

implement bus_space_{un,}map w/ extents


# 1.1 30-Dec-1998 mickey

machdep; more work needed


Revision tags: OPENBSD_6_5_BASE
# 1.255 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


Revision tags: OPENBSD_6_4_BASE
# 1.254 20-Jul-2018 guenther

Missed a 'ksi' -> '*ksip' change in previous commit


# 1.253 10-Jul-2018 guenther

Move from sendsig() to its callers the initsiginfo() calls and
instead of passing sendsig() the code+type+val, pass a siginfo_t*
to copy from. Eliminate the indirection through struct emul for
sendsig(); we no longer have a SunOS4-compat version of sendsig()

ok deraadt@


# 1.252 22-May-2018 guenther

Delete antique sigdebug definitions

ok kettenis@


# 1.251 12-Apr-2018 deraadt

Implement MAP_STACK option for mmap(). Synchronous faults (pagefault and
syscall) confirm the stack register points at MAP_STACK memory, otherwise
SIGSEGV is delivered. sigaltstack() and pthread_attr_setstack() are modified
to create a MAP_STACK sub-region which satisfies alignment requirements.
Observe that MAP_STACK can only be set/cleared by mmap(), which zeroes the
contents of the region -- there is no mprotect() equivalent operation, so
there is no MAP_STACK-adding gadget.
This opportunistic software-emulation of a stack protection bit makes
stack-pivot operations during ROPchain fragile (kind of like removing a
tool from the toolbox).
original discussion with tedu, uvm work by stefan, testing by mortimer
ok kettenis


Revision tags: OPENBSD_6_3_BASE
# 1.250 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.249 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


Revision tags: OPENBSD_6_2_BASE
# 1.248 18-May-2017 kettenis

Implement copyin32(9).

"your chicken scratches look fine to me" deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.247 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

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


# 1.246 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.245 21-May-2016 deraadt

hand-massage sendsig() and sys_sigreturn() to be much more similar.
ok guenther kettenis


# 1.244 10-May-2016 deraadt

SROP mitigation. sendsig() stores a (per-process ^ &sigcontext) cookie
inside the sigcontext. sigreturn(2) checks syscall entry was from the
exact PC addr in the (per-process ASLR) sigtramp, verifies the cookie,
and clears it to prevent sigcontext reuse.
not yet tested on landisk, sparc, *88k, socppc.
ok kettenis


# 1.243 20-Apr-2016 dlg

pool_setipl for floating point context things

ok kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.242 21-Oct-2015 mpi

Do not call uvm_swap_finicrypt_all() a second time in dumpsys().

ok tedu@, deraadt@, miod@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.241 20-Jan-2015 kettenis

Move ps_strings "after" the random stackgap. This makes its location a
per-process value, and therefpore turns the VM_PSSTRINGS sysctl into a
per-process one as well. This gets rid of a pointer to the bottom of the
stack at a fixed location. Also clears the road for unmapping the stackgap.

ok deraadt@


# 1.240 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.239 25-Oct-2014 kettenis

Remove vmmap; it isn't used.

ok jsing@


# 1.238 23-Oct-2014 miod

Correctly set up the HPMC trap entry: according to the PA-RISC Firmware
Architecture Reference Specification, the sum of the 8 trap entry words
*and* of the payload which address and length are to be set at well-known
positions in the aforementioned trap entry, needs to be zero; the existing
code was only enforcing that the sum of the trap entry words is zero.

This matches what Linux and NetBSD do.

ok kettenis@


# 1.237 23-Oct-2014 miod

Revert limiting physmem to 2GB; the culprit was likely in uvm and uvm has
changed a lot in the last 5 years; verified to work on a 3GB system, in
snapshots for a few weeks already.


# 1.236 22-Sep-2014 dlg

implement atomic_{cas,swap}_{uint,ulong,ptr} and
atomic_{add,sub}_{int,long}_nv. sys/atomic.h turns these into the
rest of the atomic api.

on uniprocessor hppa systems "atomic" operations are implemented
as a non-interruptable sequence by disabling all interrupts on the
cpu, doing the operation, and then restoring the interrupt mask.

this isnt enough on MP systems, so we added a global atomic memory
mutex that is taken inside the interrupt disabling above to coordinate
operations between cpus.

this is a lot of overhead though cos mutexes dance around with ipls,
which is unecessary in our case because of the interrupt disabling
that is already done. also, hppa spinlocks are implemented with
ldcw which requires the word it operates on to be 16 byte aligned.
mutexes arent guaranteed to have this alignment so they compensate
by having lots of words inside themselves so they can hit the
appropriate one to use for the ldcw op.

with this in mind, this change pulls __cpu_simple_locks, which are
simply ldcw spinlocks with a 16 byte aligned word, out of
src/sys/arch/hppa/include/lock.h into src/sys/arch/hppa/include/atomic.h
so atomic.h can use them. lock.h includes atomic.h, so it still
gets and provides the same functionality as before.

finally, this also pulls the rwlock cas implementation apart. cas
ops now share the same serialising lock on MP systems as the other
memory operations, and rw_cas is defined as a wrapper around
atomic_cas_uint.

ok kettenis@


# 1.235 19-Sep-2014 kettenis

Use config_suspend_all(9).


# 1.234 18-Aug-2014 dlg

dont rely on mbuf.h to provide pool.h.

ok miod@, who has offerred to help with any MD fallout
ok guenther@


Revision tags: OPENBSD_5_6_BASE
# 1.233 22-Jul-2014 uebayasi

boot(9): Reduce diffs between hppa & hppa64 (& others)


# 1.232 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.231 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.230 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.229 13-Jul-2014 miod

These still need <sys/reboot.h> for the RB_ constants.


# 1.228 12-Jul-2014 uebayasi

reboot(9), panic(9): Call panic(9) for unrecoverable MD H/W errors (NMIs)

Some architectures have ability to detect hardware sanity and notify system
(NMI, firmware callback, etc.). Handle these hardware severe errors, same
as software errors, with panic(9).

According to miod@, SGI IP27 NMI is triggered by pushing some "hidden" button,
which "usual" users/admins don't know. Pushing such a button is "RB_USERREQ"
(human-triggered) in that the button is pushed by a human, but not "RB_USERREQ"
in that no user intervention in system (== no command input) is done. miod@
agreed that changing these from RB_USERREQ to !RB_USERREQ (== panic(9)) is
not a big problem.

OK miod@ kettenis@


# 1.227 12-Jul-2014 uebayasi

boot(9), reboot(9): Migrate MD callers of boot(9) to reboot(9)

I have found that some ports call boot(9) from machine-dependent code to
reboot system. These should be changed to either:

- Sending signal to init(8) to trigger it to shutdown system cleanly, like
acpi(4) does, in cases where found problems don't prevent system from working
immediately, or

- Just doing panic(9) if the situation is severely broken.

For now, just rewrite boot() to reboot(). Actual fixes follow.

Discussed with & OK from kettenis@


# 1.226 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.225 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.224 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.223 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.222 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.221 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.220 08-May-2014 miod

Format string fixes and removal of -Wno-format for hppa kernels.


# 1.219 08-Apr-2014 mpi

Less <uvm/uvm.h>


# 1.218 04-Apr-2014 miod

If the PDC_COPROC call fails, and we are running on a PA 1.1 system, assume
the usual 1.1 coprocessor mask, instead of using zero and having every
userland process dying with signal 4.

The circumstances under which this call fails are unclear and could be
tied to specific PROM version (I have tried overzealous stack alignment and
other tricks, to no avail). Interestingly enough, the 715/75 system which
hits this problem, only triggers it when booting from disk, and never when
booting from network.

This diff is an ugly bandaid until the problem is better understood. Or maybe
it is not worth investigating, seeing that Linux hardcodes the coprocessor
mask and never issues PDC_COPROC calls; I wonder what HP/UX does.

In my tree for over 18 months; "Looks like a nice hack" deraadt@
715/75 system provided by Sebastiaan Indesteege, thanks!


# 1.217 29-Mar-2014 guenther

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

ok dlg@ mpi@ deraadt@


# 1.216 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


# 1.215 22-Mar-2014 guenther

Move p_sigacts from struct proc to struct process.

testing help mpi@


# 1.214 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


Revision tags: OPENBSD_5_5_BASE
# 1.213 23-Nov-2013 uebayasi

Run doshutdownhooks() and config_suspend() even when boot() is called while
cold != 0. Indent and make hppa/hppa64 boot() closer to others.

OK kettenis@


# 1.212 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


Revision tags: OPENBSD_5_4_BASE
# 1.211 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


Revision tags: OPENBSD_5_3_BASE
# 1.210 02-Dec-2012 guenther

Determine whether we're currently on the alternative signal stack
dynamically, by comparing the stack pointer against the altstack
base and size, so that you get the correct answer if you longjmp
out of the signal handler, as tested by regress/sys/kern/stackjmp/.
Also, fix alt stack handling on vax, where it was completely broken.

Testing and corrections by miod@, krw@, tobiasu@, pirofti@


# 1.209 26-Oct-2012 kettenis

Properly clear trap frame in setregs() to avoid leaking registers across exec.

ok jsing@


# 1.208 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.207 07-Oct-2012 kettenis

Align the stack on a 64-byte boundary as required by "The 32-bit PA-RISC
Run-time Architecture Document". GCC relies on this to properly align
stack variables.

ok guenther@, beck@


Revision tags: OPENBSD_5_2_BASE
# 1.206 21-Jun-2012 guenther

__tfork() needs to set the stack address of the new thread in the kernel,
so that it can't get a signal while still running on the parent thread's
stack. Also, pass in sizeof(struct __tfork) to provide forward compat
when more members are added. This is an ABI change, so switch syscall
numbers and bump lib majors this time.

ok deraadt@ matthew@


Revision tags: OPENBSD_5_1_BASE
# 1.205 20-Sep-2011 miod

Clear RB_POWERDOWN early in boot() on systems which can not powerdown and
which firmware does not send spin up commands to the disks, in case the
operator changes his mind and reboots instead of manually powering down
after the system has halted.
ok kettenis@


Revision tags: OPENBSD_5_0_BASE
# 1.204 05-Jul-2011 guenther

Recommit the reverted sigacts change now that the NFS use-after-free
problem has been tracked down. This fixes the sharing of the signal
handling state: shared bits go in sigacts, per-rthread bits goes in
struct proc.

ok deraadt@


# 1.203 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.202 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.201 18-Apr-2011 guenther

Revert the sigacts diff: NFS can apparently retain pointers to processes
until they're zombies and then send them signals (for intr mounts). Until
that is untangled, the sigacts change is unsafe. sthen@ was the victim
for this one


# 1.200 15-Apr-2011 guenther

Correct the sharing of the signal handling state: stuff that should
be shared (p_sigignore, p_sigcatch, P_NOCLDSTOP, P_NOCLDWAIT) moves
to struct sigacts, wihle stuff that should be per rthread (ps_oldmask,
SAS_OLDMASK, ps_sigstk) moves to struct proc. Treat the coredumping
state bits (ps_sig, ps_code, ps_type, ps_sigval) as per-rthread
until our locking around coredumping is better.

Oh, and remove the old SunOS-compat ps_usertramp member.

"I like the sound of this" tedu@


Revision tags: OPENBSD_4_9_BASE
# 1.199 14-Jan-2011 jsing

Halt secondary CPUs when shutting down or rebooting. This should prevent
occasional hangs during reboot.

ok kettenis@


# 1.198 04-Jan-2011 jasper

- de-register. no binary change.

ok jsing@


# 1.197 01-Jan-2011 jasper

Move setting cpu_hzticks to the clock initialization function, like
other ports (e.g. hppa64) do.

ok jsing@ kettenis@


# 1.196 01-Jan-2011 jasper

- ansify

ok jsing@ kettenis@


# 1.195 30-Dec-2010 jsing

Turn signotify() into a function that also calls cpu_unidle().

ok kettenis@


# 1.194 20-Nov-2010 miod

This is a first step towards getting rid of avail_start and avail_end in the
kernel, currently limited to low-hanging fruit: these variables were used
by bus_dma to specify the range in which to allocate memory, back when
uvm_pglistalloc() was stupid and would not walk the vm_physseg[].

Nowadays, except on some platforms for early initialization, these variables
are not used, or do not need to be global variables. Therefore:
- remove `extern' declarations of avail_start and avail_end (or close cousins,
such as arm physical_start and physical_end) from files which no longer need
to use them.
- make them local variables whenever possible.
- remove them when they are assigned to but no longer used.


Revision tags: OPENBSD_4_8_BASE
# 1.193 01-Jul-2010 jsing

Create a struct to store FP state and include a pointer to the CPU that
currently holds the FPU context for this process. This will be soon used
to implement FPU shootdowns on multiprocessor kernels.

ok kettenis@


# 1.192 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.191 29-Jun-2010 jsing

Factor out code used to save and flushe process FPU context.

ok kettenis@


# 1.190 29-Jun-2010 jsing

Store pointer to process FPU state in struct cpu_info.

ok kettenis@


# 1.189 27-Jun-2010 thib

uvm constraints. Add two mandatory MD symbols, uvm_md_constraints
which contains the constraints for DMA/memory allocation for each
architecture, and dma_constraints which contains the range of addresses
that are dma accessable by the system.

This is based on ariane@'s physcontig diff, with lots of bugfixes and
additions the following additions by my self:

Introduce a new function pool_set_constraints() which sets the address
range for which we allocate pages for the pool from, this is now used
for the mbuf/mbuf cluster pools to keep them dma accessible.

The !direct archs no longer stuff pages into the kernel object in
uvm_km_getpage_pla but rather do a pmap_extract() in uvm_km_putpages.

Tested heavily by my self on i386, amd64 and sparc64. Some tests on
alpha and SGI.

"commit it" beck, art, oga, deraadt
"i like the diff" deraadt


# 1.188 27-Jun-2010 jsing

Use a mutex to make atomic operations atomic on multiprocessor kernels.

ok kettenis@


# 1.187 10-Jun-2010 deraadt

Declare safepri at the MD level on each platform, so that the kern_synch.c
does not have to deal with it as a common. Some platforms may be missed
by this commit... if you spot one, fix it the same way.
ok miod


# 1.186 09-Jun-2010 miod

Move declaration of cn_tab from dev/cons.c to dev/cninit.c, or appropriate
md files for ports which do not use dev/cninit.c. This gets rid of a common
at kernel link time.
feedback drahn@ ok deraadt@


# 1.185 24-May-2010 deraadt

Add missing prototypes
ok jsing kettenis


# 1.184 09-May-2010 kettenis

Prevent "taken branch" exceptions from kernel space by clearing the PSL_T
bit before we enter a signal handler.

"if you say so" miod@, "seems to make sense" jsing@


# 1.183 02-May-2010 kettenis

Properly initialize the members of `struct mdproc' that deal with
single-stepping when we fork and reset them upon exec.

ok miod@


# 1.182 27-Apr-2010 kettenis

Avoid null-pointer dereference by giving proc0 a place to store its
floating-point registers. Pointed out by Nick Hudson.

ok miod@, jsing@


# 1.181 19-Apr-2010 jsing

Make the Processor Status Word (PSW) a per-CPU value.

ok kettenis@


# 1.180 01-Apr-2010 jsing

Allow for multiple CPUs by moving to an array of cpu_info.

ok kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.179 31-Dec-2009 jsing

Make cpl and cpu_inintr per CPU variables. For locore.S, cpl becomes an
offset within cpu_primary_info - this will need to be revisited shortly.

ok kettenis@


# 1.178 11-Aug-2009 miod

Do not bother initializing bufpages in the md code if the computation is
exactly the same the mi could will use if bufinit() is invoked with
bufpages == 0.


# 1.177 11-Aug-2009 miod

With the SysV memory allocation changes, allocsys() doesn't do anything
anymore. Get rid of it completely.


# 1.176 09-Aug-2009 blambert

Rototill system V message queues.

No longer allocate a static amount of memory for messages in MD
boot path; message queues, message metadata, and message data now
all use dynamic memory, which means that runtime sysctls should now
be trivial to implement.

Since I'm going to be around all week to fix any breakage, this should
probably just go in now.


# 1.175 02-Aug-2009 beck

Dynamic buffer cache support - a re-commit of what was backed out
after c2k9

allows buffer cache to be extended and grow/shrink dynamically

tested by many, ok oga@, "why not just commit it" deraadt@


# 1.174 29-Jul-2009 kettenis

Get rid of non-equivalent aliases of the pcb by moving the fpu state out
of the pcb and using the p_addr member of 'struct proc' to calculate the
address of the kernel stack when switching to virtual mode after taking a trap.
Remove the now unecessary cache flushes; they're actually harmful since they
create non-equivalent aliases. This seems to fix the memory corruption we
have been observing from time to time.

This diff does not rename fpu_curpcb, which is now somewhat incorrectly named.
I hope to change things back again as soon as we are able to map the pcb 1:1.


Revision tags: OPENBSD_4_6_BASE
# 1.173 15-Jun-2009 beck

Back out all the buffer cache changes I committed during c2k9. This reverts three
commits:

1) The sysctl allowing bufcachepercent to be changed at boot time.
2) The change moving the buffer cache hash chains to a red-black tree
3) The dynamic buffer cache (Which depended on the earlier too).

ok on the backout from marco and todd


# 1.172 03-Jun-2009 beck

add kern.bufcachepercent sysctl to allow adjusting the buffer cache
size on a running system.
ok art@, oga@


Revision tags: OPENBSD_4_5_BASE
# 1.171 14-Feb-2009 kettenis

Limit the amount of physical memory to 2GB. Using more causes memory
corruption on PA-RISC 2.0 systems (and there are very few PA-RISC 1.1
systems that support more than 2GB).

ok miod@


# 1.170 04-Feb-2009 miod

On systems with split BTLB, do not bother trying to insert DBTLB entries,
as PDC will lie to us pretending it did while it didn't.

ok kettenis@


# 1.169 04-Feb-2009 miod

Unify memory size reports a bit more: always report size in MB, and report
reserved memory on alpha and hppa on its own line (as done on sgi).


Revision tags: OPENBSD_4_4_BASE
# 1.168 14-Jul-2008 miod

Be sure to propagate PSL_O in psw on PCXU* processors to userland processes
and signal handlers.
ok kettenis@


# 1.167 27-Jun-2008 miod

Clear swap encryption keys before dumping a kernel image.


# 1.166 09-Apr-2008 deraadt

Add new stub uvm_shutdown() and call it from the right place in MD boot()


Revision tags: OPENBSD_4_3_BASE
# 1.165 22-Sep-2007 martin

replace even more ctob and btoc with ptoa and atop respectively plus
uvm_extern.h where needed


Revision tags: OPENBSD_4_2_BASE
# 1.164 22-Jul-2007 kettenis

Move hppa to __HAVE_TIMECOUNTERS.


# 1.163 20-Jul-2007 kettenis

Give hppa the blink_led API from sparc64, and the associated machdep.led_blink
sysctl.


# 1.162 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.161 14-Jul-2007 kettenis

Make sigreturn(2) set the proper space ID for the instruction queue. Fixes
a few more pthreads regression tests.

ok miod@


# 1.160 10-Jul-2007 kettenis

Don't trust the privilige level in the sigcontext passed to sigreturn(2).

ok miod@


# 1.159 24-Jun-2007 kettenis

Crank initial storage for extents a bit. We really should allocate extents
using malloc once vm is initialised, but this will do for now.

ok deraadt@


# 1.158 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.157 27-May-2007 miod

Make sure the minaddr hint for uvm_km_suballoc() calls is always initialized.
ok pedro@


# 1.156 26-May-2007 pedro

Dynamic buffer cache. Initial diff from mickey@, okay art@ beck@ toby@
deraadt@ dlg@.


# 1.155 21-May-2007 kettenis

Add support for 8700/pcxw2 cpu.


# 1.154 21-May-2007 kettenis

Ask firmware for reset before trying ourselves; needed for four-digit b/c/j
workstations.

tested by otto@, krw@; ok deraadt@


# 1.153 17-May-2007 art

Limit hppa buffer cache to 30%. It used to be 70% because stack garbage
that was used for minaddr instead of the proper vm_map_min(kernel_map)
(fixed in this diff).

From mickey. art@ ok


# 1.152 14-May-2007 martin

move hppa to __HAVE_CPUINFO

input from miod@, ok kettenis@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.151 28-May-2006 martin

minor nit, use CPU ID instead of FPU ID for BTLB parameters after passing
all kludges


# 1.150 15-Apr-2006 martin

make warning about missing HPT support DEBUG for now

ok mickey@


Revision tags: OPENBSD_3_9_BASE
# 1.149 26-Oct-2005 martin

no more hppa_round_page() and hppa_trunc_page() macros

ok mickey@


Revision tags: OPENBSD_3_8_BASE
# 1.148 06-Aug-2005 miod

We do not need a char machine_arch[] constant.
ok deraadt@


# 1.147 11-Jul-2005 mickey

align some stupid comments


# 1.146 10-May-2005 mickey

set pcsq in case we get signal delivery once interrupted from the gateway page; from chs


# 1.145 18-Apr-2005 mickey

do not do some of the initmsgbuf()s job


# 1.144 07-Apr-2005 mickey

on some machines it's possible to limit the amount of physmem initialised dring post so having msgbuf at the end of memory shall work


# 1.143 07-Apr-2005 mickey

64bit-friendly pdc.h and iomod.h and correspondent changes elsewhere


# 1.142 26-Mar-2005 mickey

md parts for hpux_compa code; some problems w/ signals delivery still exist


Revision tags: OPENBSD_3_7_BASE
# 1.141 24-Feb-2005 mickey

do not even ask for btlb on 8k cpus as pdc pretends there is some but then it does not work; found w/ Moritz Kiese <mbk@mytum.de> on c180; add a debug print and fix pcxu entry


# 1.140 17-Nov-2004 mickey

print real/avail/bufcache sizes as unsigned


# 1.139 26-Oct-2004 mickey

disable sid hashing on pcxu and above


# 1.138 14-Oct-2004 mickey

a bit larger delays during boot() to let msgs appear


# 1.137 19-Sep-2004 mickey

turn totalphysmem into physmem and name old physmem into smth it really is


# 1.136 18-Sep-2004 mickey

oops


# 1.135 15-Sep-2004 mickey

add pcxu tlb handlers and cpu probing
add u2/uturn ioa driver in dumb mode now
enable pcxu/pcxw support


# 1.134 14-Sep-2004 mickey

store fpu version for later use. make sure to proper store/clear fpu state in fork/exec/exit/sendsig


# 1.133 14-Sep-2004 mickey

error out from btlb_insert() if there is none


Revision tags: OPENBSD_3_6_BASE
# 1.132 01-Jul-2004 mickey

have separate insn and data cache all-flushers


# 1.131 30-Jun-2004 mickey

allow forced fpu emulation through a sysctl


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.130 13-May-2004 mickey

8ks do not have hvt


# 1.129 05-May-2004 mickey

much easier tlb handler branch patching


# 1.128 05-May-2004 mickey

do not engage HPT on PCXT' (yet)


# 1.127 08-Apr-2004 mickey

repair pcxs/t confoosion


# 1.126 07-Apr-2004 mickey

update copyright; miod@ is fine w/ files where he holds it too


Revision tags: OPENBSD_3_5_BASE
# 1.125 10-Mar-2004 tom

Ensure that we obey a user's ddb> boot reboot command even if the system
is cold (during startup).

This adds RB_USERREQ to sys/reboot.h, uses it in the ddb commands, and
ensures that */*/machdep.c:boot() won't set RB_HALT when cold if this
flag is set.

ok deraadt@


# 1.124 14-Feb-2004 grange

Simplify hw.{cpuspeed,setperf} api moving all the sysctl stuff
from the underlying callbacks.

Testing hppa mickey@, ppc drahn@
Ok markus@ tedu@


# 1.123 05-Jan-2004 mickey

kill debugging code that is not needed anymore


# 1.122 23-Dec-2003 mickey

provide cpuspeed fluff


# 1.121 20-Dec-2003 miod

Don't let microtime() return a struct timeval with exactly 1000000 microseconds.


# 1.120 18-Dec-2003 mickey

spls do not protect cpu_itmr and thus time might jump back sometimes due to cpu_itmr modified to a higher value than a read itmr; found and testing by miod@


# 1.119 17-Dec-2003 mickey

in the real mem print do not include reserved for prom into used by openbsd


# 1.118 10-Dec-2003 mickey

for unaligned btlb mapping attempts -- just fail


# 1.117 24-Nov-2003 mickey

experimental support for HVT as a 2nd level tlb


# 1.116 15-Oct-2003 mickey

less global name space pollution


# 1.115 05-Oct-2003 mickey

reload the itmr as soon as we get the intr to avoid lagging on slower machines


# 1.114 25-Sep-2003 mickey

some pcxl2 do not report fpus -- assume it's there


Revision tags: OPENBSD_3_4_BASE
# 1.113 04-Sep-2003 mickey

a better cpu identification; testing by miod


# 1.112 31-Aug-2003 miod

pdc_model needs to be visible from cpu.c


# 1.111 20-Aug-2003 mickey

missing nl in debugging prontf


# 1.110 07-Aug-2003 mickey

dead proto


# 1.109 07-Aug-2003 mickey

first allocate space on stack then copyout signal shits. add a DEBUG check for a whacky user pc (as impossible due to the recent trap.c change)


# 1.108 03-Aug-2003 mickey

clear branch and nullify bits in psw on sending a signal


# 1.107 30-Jul-2003 mickey

deduce the leds address from the model number and thus make some more use of that lichtenblinkenschmutz on some more machinens


# 1.106 22-May-2003 mickey

imprecision in delay_init()


# 1.105 18-May-2003 mickey

save the fpu state for the signal handler. this is essential
as the fpu regs can be used by the gcc even for non-fpu
means and data copying.
rearrange the sigcontext a bit to include only the general
registers that are needed restoring upon return and thus
less waste of space and make up some space for the fpu regs.

ALL software that used the signal context on the stack
needs at least rebuilding now. a new snap has bin built as well.


Revision tags: UBC_SYNC_A
# 1.104 11-May-2003 deraadt

string cleaning; krw ok


# 1.103 07-Apr-2003 mickey

s/HP9000/HP 9000/; from weissmanndude


Revision tags: OPENBSD_3_3_BASE
# 1.102 18-Feb-2003 deraadt

knf; mickey ok


# 1.101 12-Feb-2003 jason

How uncommon... hppa only has one common: msgbufmapped (decl'd in /sys/kern)


# 1.100 12-Feb-2003 mickey

only align the first stack frame onto the minimal required alignment


# 1.99 10-Feb-2003 mickey

fix pcs and pcxt recognition. from weissmanndude


# 1.98 22-Jan-2003 mickey

consistantly use uvm_prot_* vs vm_prot_* evewrhere


# 1.97 14-Jan-2003 mickey

fix cutnpaste in the cpu table for the itlbna field; from herr weissmanndude


# 1.96 14-Jan-2003 mickey

need pdc_hwtlb always; pt out by herr weissmanndude


# 1.95 13-Jan-2003 mickey

fix the logic in hvt probing


# 1.94 09-Jan-2003 miod

Remove fetch(9) and store(9) functions from the kernel, and replace the few
remaining instances of them with appropriate copy(9) usage.

ok art@, tested on all arches unless my memory is non-ECC


# 1.93 19-Dec-2002 mickey

setregs: put the whole frame setup into one place


# 1.92 19-Dec-2002 mickey

level 0x16 is really an l2


# 1.91 17-Dec-2002 millert

Make SysV-style shared memory and semaphore limits sysctl'able.
Instead of allocating a static amount of memory for the data
structures via valloc() in allocsys(), allocate things dynamically
using pool(9) when possible and malloc(9) when not. The various
members of struct seminfo and struct shminfo are in kern.seminfo
and kern.shminfo respectively (not all members of kern.seminfo are
changable).

The data structures used still leave something to be desired but
things are not made worse in that respect by this commit.


# 1.90 27-Nov-2002 mickey

no wrapper arounf hardclock(), use CPU_CLOCKUPDATE, real microtime; miod ok


# 1.89 08-Nov-2002 mickey

Don't uvm_useracc the user sigcontext in sys_sigreturn and then access
the user addresses directly from the kernel. copyin is faster and can
correctly deal properly with mappings that uvm_useracc thinks are
correct but will fault anyway (to figure out how to generate such
mappings is left as en excercise for the reader).


# 1.88 01-Nov-2002 mickey

add a missing delay after printf on halt[-p], proper arg for a cold hook


Revision tags: UBC_SYNC_B
# 1.87 22-Oct-2002 mickey

do not force single-user; pt out by fries@


# 1.86 15-Oct-2002 mickey

missing initmsgbuf(), noticed by miod@


# 1.85 13-Oct-2002 mickey

track the end of physmem for use in dmmem_alloc


# 1.84 07-Oct-2002 mickey

s/PSW_/PSL_/ to match other archs


# 1.83 07-Oct-2002 mickey

proper terminate the user stack on signal


# 1.82 07-Oct-2002 mickey

on implementations w/ fpu included unimplemented instructions
are signaled through the exception trap w/ invalid opcode marked
instruction in the exception registers, not through the emulation
trap (as long as the fpu is enabled, of course).
parse emulation from the exception trap as well as the emulation
trap and fix the dispatcher into usable condition.
parse invalid op exception on trap and signal the user appropriately.
reset the exception on exec and for child on fork.
the later is appropriate since exceptions are delayed until next
fpu instruction, which was in the parent indeed, let him get it.
save parent's fpu context on fork before cipying it, if the
parent owned the fpu.


Revision tags: OPENBSD_3_2_BASE
# 1.81 23-Sep-2002 mickey

parisc level 0x10 is just an overclocked 0xe


# 1.80 17-Sep-2002 mickey

handle fpu exceptions properly, might use a regress, i guess


# 1.79 11-Sep-2002 mickey

provide a convinient reset label


# 1.78 11-Sep-2002 mickey

stack grows the other way, but the frame is the other way to that. hehe


# 1.77 09-Sep-2002 mickey

set up the frame flags and a user frame better on exec


# 1.76 03-Aug-2002 mickey

rework boot() w/o a goto


# 1.75 25-Jul-2002 mickey

missing arg in the call to the pdc_call since some old times


# 1.74 25-Jul-2002 mickey

kcopy is a space-to-space copy from kernel space, to guess where, -- to the same kernel space, just error on fault


# 1.73 20-Jul-2002 art

Instead of copying out the signal trampoline on top of the stack, create
an uvm aobj, copy out the signal trampoline into it and share that page
among all processes for the same emulation.

This also requires us to actually be able to tell signal code where the
trampoline is located, so introduce a new field in struct proc - p_sigcode
that is a pointer to sigcode. This allows us to remove all the ugly
calculations of the signal trampoline address done in every sendsig
function in the tree (that's why so many files are changed).

Tested by various people. ok deraadt@


# 1.72 14-May-2002 mickey

disable sid hashing while still in real mode, alos print the parisc arch once and not per each cpu since they are not intermixable architecture-wise


# 1.71 13-May-2002 mickey

ldi-ldo whatever was in the table, be that much clever


# 1.70 08-May-2002 mickey

print parisc level w/ the the parisc version, not for each cpu


# 1.69 08-May-2002 mickey

kill debugging printfski


# 1.68 22-Apr-2002 mickey

no longer batc the data, only the code.
this removes a constraint and an ld.script dependancy
for the .data and the dynamically allocated kernel
structures existed w/ batcing. also makes pmap_steal_memory
obsolete and replaced w/ the pmap_virtual_space.
implement batching for pmap_remove to avoid
zeroing out the pte entries if pde will be removed anyway.


# 1.67 21-Apr-2002 mickey

better buf's mapping and less magic constants in checking for io space cachability


Revision tags: OPENBSD_3_1_BASE
# 1.66 26-Mar-2002 mickey

if cannot guess cpu model default to the lowest supported one


# 1.65 25-Mar-2002 deraadt

spelling


# 1.64 23-Mar-2002 espie

Add variables for config(8) -e time tweak of systemV shared memory
parameters.

Ok millert@, miod@, maja@


# 1.63 19-Mar-2002 mickey

mtcpu seq requires a pre-sync, implement hpt init for pcxl


# 1.62 15-Mar-2002 mickey

rewrite a pmap to use multilevel page tables.
lower 12 bits contain the perms, no unused bits left,
but a couple for off-tlb use (as the ref implemented now).
do not use the hvt, which might get some use later
if proven to speed thigs up, tlb handlers would po
another dozen of insns though, but if that's worth its...
move on the data seg and map kernel text rdonly (idea form fredette),
since all of the page0 mods done before that we are all fine
except for some viper fluff, but later w/ that.
this also picks up a bit more of ddb magic for bpt and ss.
tlb handlers can use a little bit more of attention,
but things, visually, seem to be much faster already, --
sorry, no benchmarks for now.

* effort sponsored in part by the `henry st. old ale house'
* and mr.pete and mr.lee in particular in thier generous entrirety.
* the proj took a little more that 72man*h as it was expected,
* but within murhy's law estimations.


# 1.61 14-Mar-2002 millert

First round of __P removal in sys


# 1.60 20-Feb-2002 mickey

setup power failure handler (for sw-controlled power button), move toc handler


# 1.59 17-Feb-2002 maja

Patch from Daniel Lucq <daniel@lucq.org>

The patch allows you to change the value of NMBCLUSTERS, BUFCACHEPERCENT
and NKMEMPAGES using the config command, instead of recompiling the kernel.

This is the kernel part of the patch. I have compiled it on i386, sparc64,
alpha and macppc. -moj ok art@ maja@


# 1.58 12-Feb-2002 mickey

support 712's programmable power switch, no interrupt yet


# 1.57 12-Feb-2002 mickey

small repairs to hpmc and toc handlers


# 1.56 11-Feb-2002 mickey

disable fpu on csw, print fpu version on cpu line, if present


# 1.55 07-Feb-2002 mickey

fix sigdebug cases; init sigcontext before it's used (;


# 1.54 06-Feb-2002 mickey

implement signal delivery; based on fredette@'s work


# 1.53 03-Feb-2002 mickey

restore hpt size computation, does not break things as i thought


# 1.52 02-Feb-2002 mickey

fix 'physmem' usage


# 1.51 02-Feb-2002 mickey

implement the rest of /dev/mem devices; from netbsd


# 1.50 23-Jan-2002 art

move mb_map allocation to mbinit()


# 1.49 23-Jan-2002 art

move definition of mb_map from zillions of machdep.c to uipc_mbuf.c


# 1.48 16-Jan-2002 miod

Don't include <sys/map.h> when you don't need what's in it.


Revision tags: UBC_BASE
# 1.47 02-Dec-2001 mickey

branches: 1.47.2;
increase fixed extent storage


# 1.46 28-Nov-2001 art

zap some typedefs.
vm_map_t -> struct vm_map *
vm_map_entry_t -> struct vm_map_entry *
simple_lock_data_t -> struct simplelock

(uvm not done yet, coming in the next commit)


# 1.45 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.44 24-Nov-2001 miod

Harmonize boot() logic across arches:
- ensure RB_DUMP | RB_HALT will cause a dump
- or RB_HALT if (cold)
While there, honor RB_TIMEBAD on sparc64.


# 1.43 09-Nov-2001 art

nswbuf hasn't been used for ages. gc.


# 1.42 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.41 06-Nov-2001 miod

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


Revision tags: OPENBSD_3_0_BASE
# 1.40 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.39 12-Sep-2001 art

mbutl no more


# 1.38 23-Aug-2001 art

We can now move timeout_init into main().


# 1.37 23-Aug-2001 art

Remove even more old timeout tentacles.


# 1.36 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.35 05-Jul-2001 art

Get rid of REAL_CLISTS. It was never implemented and the tentacles are
everywhhere.


# 1.34 17-May-2001 provos

convert mbuf and cluster allocation to pool, mostly from NetBSD
okay art@ miod@


# 1.33 05-May-2001 art

Rename configure() to cpu_configure().
Move it from cpu_startup() to main().


# 1.32 05-May-2001 art

Get rid of CLSIZE and all related stuff.
CLSIZE -> 1
CLBYTES -> PAGE_SIZE
OLOFSET -> PAGE_MASK
etc.
At the same time some archs needed some cleaning in vmparam.h so that
goes in at the same time.


Revision tags: OPENBSD_2_9_BASE
# 1.31 29-Mar-2001 mickey

cpudev_data.h here needed not


# 1.30 22-Mar-2001 mickey

shuffle the tlb handlers a little,
make a new one for na data fault,
since those w/ hpt need it.


Revision tags: OPENBSD_2_8_BASE
# 1.29 15-Aug-2000 mickey

two btlb routines (i & d) for pcxs


# 1.28 15-Aug-2000 mickey

expand per-cpu control routines switch


# 1.27 08-Aug-2000 mickey

print btlb params w/ BTLBDEBUG; from Havard.Eidnes@runit.sintef.no


# 1.26 02-Jul-2000 mickey

no bays for stinger


Revision tags: OPENBSD_2_7_BASE
# 1.25 23-Mar-2000 mickey

new cpu type switch code.
initializes tlb miss handlers correspondent to probed cpu features.
also btlb load routine.
versions written are for pcxl and others.
cpu-dep btlb loaders are missing, only generic for now.


# 1.24 23-Mar-2000 art

New API for timeouts. Replaces the old timeout()/untimeout() API and
makes it the callers responsibility to allocate resources for the
timeouts.

This is a KISS implementation and does _not_ solve the problems of slow
handling of a large number of pending timeouts (this will be solved in
future work) (although hardclock is now guarateed to take constant time
for handling of timeouts).

Old timeout() and untimeout() are implemented as wrappers around the new
API and kept for compatibility. They will be removed as soon as all
subsystems are converted to use the new API.


# 1.23 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


# 1.22 22-Feb-2000 mickey

blah, blah, blah, msgbuf


Revision tags: SMP_BASE
# 1.21 09-Feb-2000 mickey

branches: 1.21.2;
heartbeat -- yeah we have a patch for that


# 1.20 25-Jan-2000 mickey

better copy and zero inlines in locore;
proper setregs() in machedep;
start of hpmc handler;
some cleanup here and there;


# 1.19 17-Jan-2000 mickey

remove unneeded stuff from setregs; force single-user for now, enable signal debug


# 1.18 11-Jan-2000 mickey

s/fpu_curproc/fpu_curpcb/ which also points into physical.
move it's definition into locore (where it's used the most).
adjust fpu context switch and save on swapout accordingly.
fix context save (in switch).
add accounting for fpu context switches (since it differes
from proc switching, we might get provided w/ some usefull
numbers as to how effective this lazy switch technique is).
enable handling fpu/sfu exceptions.


# 1.17 31-Dec-1999 mickey

don't bother about pidr3 and pidr4


# 1.16 17-Dec-1999 mickey

fix the panic message for sti memory mapping


Revision tags: kame_19991208
# 1.15 25-Nov-1999 mickey

bus stuff is in mainbus now, the rest is rewritten many ways


Revision tags: OPENBSD_2_6_BASE
# 1.14 20-Sep-1999 mickey

fix uvm_pagealloc() call


# 1.13 03-Sep-1999 art

Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.12 14-Aug-1999 mickey

proper debugging ifdefs


# 1.11 21-Jul-1999 mickey

rewrite the tlb miss handler and tlb dirty handler.
optimize for HVT usage (when compiled for proper cpu type).
drop hpt_* global variables, use info from control registers instead.
there are still ways to improve the tlb handlers tho.
machdep also prints cache and tlb coherence states (not related to the above).
You eat greenish muffin. --More-- You write real code.


# 1.10 12-Jul-1999 mickey

allocate 5% bufcache if <=16M memory installed


# 1.9 12-Jun-1999 mickey

hppa_init() now takes an argument from locore,
meaning the start of available memory.
cleanup machdep somewhat.
fix vm_map.pmap vs vm_pmap isue; 10x art@


# 1.8 23-May-1999 mickey

new swap stuff


# 1.7 21-May-1999 mickey

group all theMD f;ags together, add interrupt recursion one


# 1.6 21-May-1999 mickey

define fpu_curproc


# 1.5 20-Apr-1999 mickey

do lazy blok mapping of io space in bus_*
add copy{in,out}*, kcopy, etc
boot routines
cpu-id-hpux-compat stuff
rest of scheduler and such
uvm


Revision tags: OPENBSD_2_5_BASE
# 1.4 17-Feb-1999 mickey

print pa-risc here as well, since, finally, cpu will have to print processor type


# 1.3 04-Jan-1999 mickey

better cache handling in bus_space_barrier(), seem to work now


# 1.2 03-Jan-1999 mickey

implement bus_space_{un,}map w/ extents


# 1.1 30-Dec-1998 mickey

machdep; more work needed


# 1.254 20-Jul-2018 guenther

Missed a 'ksi' -> '*ksip' change in previous commit


# 1.253 10-Jul-2018 guenther

Move from sendsig() to its callers the initsiginfo() calls and
instead of passing sendsig() the code+type+val, pass a siginfo_t*
to copy from. Eliminate the indirection through struct emul for
sendsig(); we no longer have a SunOS4-compat version of sendsig()

ok deraadt@


# 1.252 22-May-2018 guenther

Delete antique sigdebug definitions

ok kettenis@


# 1.251 12-Apr-2018 deraadt

Implement MAP_STACK option for mmap(). Synchronous faults (pagefault and
syscall) confirm the stack register points at MAP_STACK memory, otherwise
SIGSEGV is delivered. sigaltstack() and pthread_attr_setstack() are modified
to create a MAP_STACK sub-region which satisfies alignment requirements.
Observe that MAP_STACK can only be set/cleared by mmap(), which zeroes the
contents of the region -- there is no mprotect() equivalent operation, so
there is no MAP_STACK-adding gadget.
This opportunistic software-emulation of a stack protection bit makes
stack-pivot operations during ROPchain fragile (kind of like removing a
tool from the toolbox).
original discussion with tedu, uvm work by stefan, testing by mortimer
ok kettenis


Revision tags: OPENBSD_6_3_BASE
# 1.250 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.249 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


Revision tags: OPENBSD_6_2_BASE
# 1.248 18-May-2017 kettenis

Implement copyin32(9).

"your chicken scratches look fine to me" deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.247 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

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


# 1.246 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.245 21-May-2016 deraadt

hand-massage sendsig() and sys_sigreturn() to be much more similar.
ok guenther kettenis


# 1.244 10-May-2016 deraadt

SROP mitigation. sendsig() stores a (per-process ^ &sigcontext) cookie
inside the sigcontext. sigreturn(2) checks syscall entry was from the
exact PC addr in the (per-process ASLR) sigtramp, verifies the cookie,
and clears it to prevent sigcontext reuse.
not yet tested on landisk, sparc, *88k, socppc.
ok kettenis


# 1.243 20-Apr-2016 dlg

pool_setipl for floating point context things

ok kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.242 21-Oct-2015 mpi

Do not call uvm_swap_finicrypt_all() a second time in dumpsys().

ok tedu@, deraadt@, miod@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.241 20-Jan-2015 kettenis

Move ps_strings "after" the random stackgap. This makes its location a
per-process value, and therefpore turns the VM_PSSTRINGS sysctl into a
per-process one as well. This gets rid of a pointer to the bottom of the
stack at a fixed location. Also clears the road for unmapping the stackgap.

ok deraadt@


# 1.240 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.239 25-Oct-2014 kettenis

Remove vmmap; it isn't used.

ok jsing@


# 1.238 23-Oct-2014 miod

Correctly set up the HPMC trap entry: according to the PA-RISC Firmware
Architecture Reference Specification, the sum of the 8 trap entry words
*and* of the payload which address and length are to be set at well-known
positions in the aforementioned trap entry, needs to be zero; the existing
code was only enforcing that the sum of the trap entry words is zero.

This matches what Linux and NetBSD do.

ok kettenis@


# 1.237 23-Oct-2014 miod

Revert limiting physmem to 2GB; the culprit was likely in uvm and uvm has
changed a lot in the last 5 years; verified to work on a 3GB system, in
snapshots for a few weeks already.


# 1.236 22-Sep-2014 dlg

implement atomic_{cas,swap}_{uint,ulong,ptr} and
atomic_{add,sub}_{int,long}_nv. sys/atomic.h turns these into the
rest of the atomic api.

on uniprocessor hppa systems "atomic" operations are implemented
as a non-interruptable sequence by disabling all interrupts on the
cpu, doing the operation, and then restoring the interrupt mask.

this isnt enough on MP systems, so we added a global atomic memory
mutex that is taken inside the interrupt disabling above to coordinate
operations between cpus.

this is a lot of overhead though cos mutexes dance around with ipls,
which is unecessary in our case because of the interrupt disabling
that is already done. also, hppa spinlocks are implemented with
ldcw which requires the word it operates on to be 16 byte aligned.
mutexes arent guaranteed to have this alignment so they compensate
by having lots of words inside themselves so they can hit the
appropriate one to use for the ldcw op.

with this in mind, this change pulls __cpu_simple_locks, which are
simply ldcw spinlocks with a 16 byte aligned word, out of
src/sys/arch/hppa/include/lock.h into src/sys/arch/hppa/include/atomic.h
so atomic.h can use them. lock.h includes atomic.h, so it still
gets and provides the same functionality as before.

finally, this also pulls the rwlock cas implementation apart. cas
ops now share the same serialising lock on MP systems as the other
memory operations, and rw_cas is defined as a wrapper around
atomic_cas_uint.

ok kettenis@


# 1.235 19-Sep-2014 kettenis

Use config_suspend_all(9).


# 1.234 18-Aug-2014 dlg

dont rely on mbuf.h to provide pool.h.

ok miod@, who has offerred to help with any MD fallout
ok guenther@


Revision tags: OPENBSD_5_6_BASE
# 1.233 22-Jul-2014 uebayasi

boot(9): Reduce diffs between hppa & hppa64 (& others)


# 1.232 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.231 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.230 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.229 13-Jul-2014 miod

These still need <sys/reboot.h> for the RB_ constants.


# 1.228 12-Jul-2014 uebayasi

reboot(9), panic(9): Call panic(9) for unrecoverable MD H/W errors (NMIs)

Some architectures have ability to detect hardware sanity and notify system
(NMI, firmware callback, etc.). Handle these hardware severe errors, same
as software errors, with panic(9).

According to miod@, SGI IP27 NMI is triggered by pushing some "hidden" button,
which "usual" users/admins don't know. Pushing such a button is "RB_USERREQ"
(human-triggered) in that the button is pushed by a human, but not "RB_USERREQ"
in that no user intervention in system (== no command input) is done. miod@
agreed that changing these from RB_USERREQ to !RB_USERREQ (== panic(9)) is
not a big problem.

OK miod@ kettenis@


# 1.227 12-Jul-2014 uebayasi

boot(9), reboot(9): Migrate MD callers of boot(9) to reboot(9)

I have found that some ports call boot(9) from machine-dependent code to
reboot system. These should be changed to either:

- Sending signal to init(8) to trigger it to shutdown system cleanly, like
acpi(4) does, in cases where found problems don't prevent system from working
immediately, or

- Just doing panic(9) if the situation is severely broken.

For now, just rewrite boot() to reboot(). Actual fixes follow.

Discussed with & OK from kettenis@


# 1.226 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.225 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.224 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.223 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.222 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.221 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.220 08-May-2014 miod

Format string fixes and removal of -Wno-format for hppa kernels.


# 1.219 08-Apr-2014 mpi

Less <uvm/uvm.h>


# 1.218 04-Apr-2014 miod

If the PDC_COPROC call fails, and we are running on a PA 1.1 system, assume
the usual 1.1 coprocessor mask, instead of using zero and having every
userland process dying with signal 4.

The circumstances under which this call fails are unclear and could be
tied to specific PROM version (I have tried overzealous stack alignment and
other tricks, to no avail). Interestingly enough, the 715/75 system which
hits this problem, only triggers it when booting from disk, and never when
booting from network.

This diff is an ugly bandaid until the problem is better understood. Or maybe
it is not worth investigating, seeing that Linux hardcodes the coprocessor
mask and never issues PDC_COPROC calls; I wonder what HP/UX does.

In my tree for over 18 months; "Looks like a nice hack" deraadt@
715/75 system provided by Sebastiaan Indesteege, thanks!


# 1.217 29-Mar-2014 guenther

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

ok dlg@ mpi@ deraadt@


# 1.216 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


# 1.215 22-Mar-2014 guenther

Move p_sigacts from struct proc to struct process.

testing help mpi@


# 1.214 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


Revision tags: OPENBSD_5_5_BASE
# 1.213 23-Nov-2013 uebayasi

Run doshutdownhooks() and config_suspend() even when boot() is called while
cold != 0. Indent and make hppa/hppa64 boot() closer to others.

OK kettenis@


# 1.212 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


Revision tags: OPENBSD_5_4_BASE
# 1.211 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


Revision tags: OPENBSD_5_3_BASE
# 1.210 02-Dec-2012 guenther

Determine whether we're currently on the alternative signal stack
dynamically, by comparing the stack pointer against the altstack
base and size, so that you get the correct answer if you longjmp
out of the signal handler, as tested by regress/sys/kern/stackjmp/.
Also, fix alt stack handling on vax, where it was completely broken.

Testing and corrections by miod@, krw@, tobiasu@, pirofti@


# 1.209 26-Oct-2012 kettenis

Properly clear trap frame in setregs() to avoid leaking registers across exec.

ok jsing@


# 1.208 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.207 07-Oct-2012 kettenis

Align the stack on a 64-byte boundary as required by "The 32-bit PA-RISC
Run-time Architecture Document". GCC relies on this to properly align
stack variables.

ok guenther@, beck@


Revision tags: OPENBSD_5_2_BASE
# 1.206 21-Jun-2012 guenther

__tfork() needs to set the stack address of the new thread in the kernel,
so that it can't get a signal while still running on the parent thread's
stack. Also, pass in sizeof(struct __tfork) to provide forward compat
when more members are added. This is an ABI change, so switch syscall
numbers and bump lib majors this time.

ok deraadt@ matthew@


Revision tags: OPENBSD_5_1_BASE
# 1.205 20-Sep-2011 miod

Clear RB_POWERDOWN early in boot() on systems which can not powerdown and
which firmware does not send spin up commands to the disks, in case the
operator changes his mind and reboots instead of manually powering down
after the system has halted.
ok kettenis@


Revision tags: OPENBSD_5_0_BASE
# 1.204 05-Jul-2011 guenther

Recommit the reverted sigacts change now that the NFS use-after-free
problem has been tracked down. This fixes the sharing of the signal
handling state: shared bits go in sigacts, per-rthread bits goes in
struct proc.

ok deraadt@


# 1.203 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.202 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.201 18-Apr-2011 guenther

Revert the sigacts diff: NFS can apparently retain pointers to processes
until they're zombies and then send them signals (for intr mounts). Until
that is untangled, the sigacts change is unsafe. sthen@ was the victim
for this one


# 1.200 15-Apr-2011 guenther

Correct the sharing of the signal handling state: stuff that should
be shared (p_sigignore, p_sigcatch, P_NOCLDSTOP, P_NOCLDWAIT) moves
to struct sigacts, wihle stuff that should be per rthread (ps_oldmask,
SAS_OLDMASK, ps_sigstk) moves to struct proc. Treat the coredumping
state bits (ps_sig, ps_code, ps_type, ps_sigval) as per-rthread
until our locking around coredumping is better.

Oh, and remove the old SunOS-compat ps_usertramp member.

"I like the sound of this" tedu@


Revision tags: OPENBSD_4_9_BASE
# 1.199 14-Jan-2011 jsing

Halt secondary CPUs when shutting down or rebooting. This should prevent
occasional hangs during reboot.

ok kettenis@


# 1.198 04-Jan-2011 jasper

- de-register. no binary change.

ok jsing@


# 1.197 01-Jan-2011 jasper

Move setting cpu_hzticks to the clock initialization function, like
other ports (e.g. hppa64) do.

ok jsing@ kettenis@


# 1.196 01-Jan-2011 jasper

- ansify

ok jsing@ kettenis@


# 1.195 30-Dec-2010 jsing

Turn signotify() into a function that also calls cpu_unidle().

ok kettenis@


# 1.194 20-Nov-2010 miod

This is a first step towards getting rid of avail_start and avail_end in the
kernel, currently limited to low-hanging fruit: these variables were used
by bus_dma to specify the range in which to allocate memory, back when
uvm_pglistalloc() was stupid and would not walk the vm_physseg[].

Nowadays, except on some platforms for early initialization, these variables
are not used, or do not need to be global variables. Therefore:
- remove `extern' declarations of avail_start and avail_end (or close cousins,
such as arm physical_start and physical_end) from files which no longer need
to use them.
- make them local variables whenever possible.
- remove them when they are assigned to but no longer used.


Revision tags: OPENBSD_4_8_BASE
# 1.193 01-Jul-2010 jsing

Create a struct to store FP state and include a pointer to the CPU that
currently holds the FPU context for this process. This will be soon used
to implement FPU shootdowns on multiprocessor kernels.

ok kettenis@


# 1.192 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.191 29-Jun-2010 jsing

Factor out code used to save and flushe process FPU context.

ok kettenis@


# 1.190 29-Jun-2010 jsing

Store pointer to process FPU state in struct cpu_info.

ok kettenis@


# 1.189 27-Jun-2010 thib

uvm constraints. Add two mandatory MD symbols, uvm_md_constraints
which contains the constraints for DMA/memory allocation for each
architecture, and dma_constraints which contains the range of addresses
that are dma accessable by the system.

This is based on ariane@'s physcontig diff, with lots of bugfixes and
additions the following additions by my self:

Introduce a new function pool_set_constraints() which sets the address
range for which we allocate pages for the pool from, this is now used
for the mbuf/mbuf cluster pools to keep them dma accessible.

The !direct archs no longer stuff pages into the kernel object in
uvm_km_getpage_pla but rather do a pmap_extract() in uvm_km_putpages.

Tested heavily by my self on i386, amd64 and sparc64. Some tests on
alpha and SGI.

"commit it" beck, art, oga, deraadt
"i like the diff" deraadt


# 1.188 27-Jun-2010 jsing

Use a mutex to make atomic operations atomic on multiprocessor kernels.

ok kettenis@


# 1.187 10-Jun-2010 deraadt

Declare safepri at the MD level on each platform, so that the kern_synch.c
does not have to deal with it as a common. Some platforms may be missed
by this commit... if you spot one, fix it the same way.
ok miod


# 1.186 09-Jun-2010 miod

Move declaration of cn_tab from dev/cons.c to dev/cninit.c, or appropriate
md files for ports which do not use dev/cninit.c. This gets rid of a common
at kernel link time.
feedback drahn@ ok deraadt@


# 1.185 24-May-2010 deraadt

Add missing prototypes
ok jsing kettenis


# 1.184 09-May-2010 kettenis

Prevent "taken branch" exceptions from kernel space by clearing the PSL_T
bit before we enter a signal handler.

"if you say so" miod@, "seems to make sense" jsing@


# 1.183 02-May-2010 kettenis

Properly initialize the members of `struct mdproc' that deal with
single-stepping when we fork and reset them upon exec.

ok miod@


# 1.182 27-Apr-2010 kettenis

Avoid null-pointer dereference by giving proc0 a place to store its
floating-point registers. Pointed out by Nick Hudson.

ok miod@, jsing@


# 1.181 19-Apr-2010 jsing

Make the Processor Status Word (PSW) a per-CPU value.

ok kettenis@


# 1.180 01-Apr-2010 jsing

Allow for multiple CPUs by moving to an array of cpu_info.

ok kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.179 31-Dec-2009 jsing

Make cpl and cpu_inintr per CPU variables. For locore.S, cpl becomes an
offset within cpu_primary_info - this will need to be revisited shortly.

ok kettenis@


# 1.178 11-Aug-2009 miod

Do not bother initializing bufpages in the md code if the computation is
exactly the same the mi could will use if bufinit() is invoked with
bufpages == 0.


# 1.177 11-Aug-2009 miod

With the SysV memory allocation changes, allocsys() doesn't do anything
anymore. Get rid of it completely.


# 1.176 09-Aug-2009 blambert

Rototill system V message queues.

No longer allocate a static amount of memory for messages in MD
boot path; message queues, message metadata, and message data now
all use dynamic memory, which means that runtime sysctls should now
be trivial to implement.

Since I'm going to be around all week to fix any breakage, this should
probably just go in now.


# 1.175 02-Aug-2009 beck

Dynamic buffer cache support - a re-commit of what was backed out
after c2k9

allows buffer cache to be extended and grow/shrink dynamically

tested by many, ok oga@, "why not just commit it" deraadt@


# 1.174 29-Jul-2009 kettenis

Get rid of non-equivalent aliases of the pcb by moving the fpu state out
of the pcb and using the p_addr member of 'struct proc' to calculate the
address of the kernel stack when switching to virtual mode after taking a trap.
Remove the now unecessary cache flushes; they're actually harmful since they
create non-equivalent aliases. This seems to fix the memory corruption we
have been observing from time to time.

This diff does not rename fpu_curpcb, which is now somewhat incorrectly named.
I hope to change things back again as soon as we are able to map the pcb 1:1.


Revision tags: OPENBSD_4_6_BASE
# 1.173 15-Jun-2009 beck

Back out all the buffer cache changes I committed during c2k9. This reverts three
commits:

1) The sysctl allowing bufcachepercent to be changed at boot time.
2) The change moving the buffer cache hash chains to a red-black tree
3) The dynamic buffer cache (Which depended on the earlier too).

ok on the backout from marco and todd


# 1.172 03-Jun-2009 beck

add kern.bufcachepercent sysctl to allow adjusting the buffer cache
size on a running system.
ok art@, oga@


Revision tags: OPENBSD_4_5_BASE
# 1.171 14-Feb-2009 kettenis

Limit the amount of physical memory to 2GB. Using more causes memory
corruption on PA-RISC 2.0 systems (and there are very few PA-RISC 1.1
systems that support more than 2GB).

ok miod@


# 1.170 04-Feb-2009 miod

On systems with split BTLB, do not bother trying to insert DBTLB entries,
as PDC will lie to us pretending it did while it didn't.

ok kettenis@


# 1.169 04-Feb-2009 miod

Unify memory size reports a bit more: always report size in MB, and report
reserved memory on alpha and hppa on its own line (as done on sgi).


Revision tags: OPENBSD_4_4_BASE
# 1.168 14-Jul-2008 miod

Be sure to propagate PSL_O in psw on PCXU* processors to userland processes
and signal handlers.
ok kettenis@


# 1.167 27-Jun-2008 miod

Clear swap encryption keys before dumping a kernel image.


# 1.166 09-Apr-2008 deraadt

Add new stub uvm_shutdown() and call it from the right place in MD boot()


Revision tags: OPENBSD_4_3_BASE
# 1.165 22-Sep-2007 martin

replace even more ctob and btoc with ptoa and atop respectively plus
uvm_extern.h where needed


Revision tags: OPENBSD_4_2_BASE
# 1.164 22-Jul-2007 kettenis

Move hppa to __HAVE_TIMECOUNTERS.


# 1.163 20-Jul-2007 kettenis

Give hppa the blink_led API from sparc64, and the associated machdep.led_blink
sysctl.


# 1.162 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.161 14-Jul-2007 kettenis

Make sigreturn(2) set the proper space ID for the instruction queue. Fixes
a few more pthreads regression tests.

ok miod@


# 1.160 10-Jul-2007 kettenis

Don't trust the privilige level in the sigcontext passed to sigreturn(2).

ok miod@


# 1.159 24-Jun-2007 kettenis

Crank initial storage for extents a bit. We really should allocate extents
using malloc once vm is initialised, but this will do for now.

ok deraadt@


# 1.158 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.157 27-May-2007 miod

Make sure the minaddr hint for uvm_km_suballoc() calls is always initialized.
ok pedro@


# 1.156 26-May-2007 pedro

Dynamic buffer cache. Initial diff from mickey@, okay art@ beck@ toby@
deraadt@ dlg@.


# 1.155 21-May-2007 kettenis

Add support for 8700/pcxw2 cpu.


# 1.154 21-May-2007 kettenis

Ask firmware for reset before trying ourselves; needed for four-digit b/c/j
workstations.

tested by otto@, krw@; ok deraadt@


# 1.153 17-May-2007 art

Limit hppa buffer cache to 30%. It used to be 70% because stack garbage
that was used for minaddr instead of the proper vm_map_min(kernel_map)
(fixed in this diff).

From mickey. art@ ok


# 1.152 14-May-2007 martin

move hppa to __HAVE_CPUINFO

input from miod@, ok kettenis@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.151 28-May-2006 martin

minor nit, use CPU ID instead of FPU ID for BTLB parameters after passing
all kludges


# 1.150 15-Apr-2006 martin

make warning about missing HPT support DEBUG for now

ok mickey@


Revision tags: OPENBSD_3_9_BASE
# 1.149 26-Oct-2005 martin

no more hppa_round_page() and hppa_trunc_page() macros

ok mickey@


Revision tags: OPENBSD_3_8_BASE
# 1.148 06-Aug-2005 miod

We do not need a char machine_arch[] constant.
ok deraadt@


# 1.147 11-Jul-2005 mickey

align some stupid comments


# 1.146 10-May-2005 mickey

set pcsq in case we get signal delivery once interrupted from the gateway page; from chs


# 1.145 18-Apr-2005 mickey

do not do some of the initmsgbuf()s job


# 1.144 07-Apr-2005 mickey

on some machines it's possible to limit the amount of physmem initialised dring post so having msgbuf at the end of memory shall work


# 1.143 07-Apr-2005 mickey

64bit-friendly pdc.h and iomod.h and correspondent changes elsewhere


# 1.142 26-Mar-2005 mickey

md parts for hpux_compa code; some problems w/ signals delivery still exist


Revision tags: OPENBSD_3_7_BASE
# 1.141 24-Feb-2005 mickey

do not even ask for btlb on 8k cpus as pdc pretends there is some but then it does not work; found w/ Moritz Kiese <mbk@mytum.de> on c180; add a debug print and fix pcxu entry


# 1.140 17-Nov-2004 mickey

print real/avail/bufcache sizes as unsigned


# 1.139 26-Oct-2004 mickey

disable sid hashing on pcxu and above


# 1.138 14-Oct-2004 mickey

a bit larger delays during boot() to let msgs appear


# 1.137 19-Sep-2004 mickey

turn totalphysmem into physmem and name old physmem into smth it really is


# 1.136 18-Sep-2004 mickey

oops


# 1.135 15-Sep-2004 mickey

add pcxu tlb handlers and cpu probing
add u2/uturn ioa driver in dumb mode now
enable pcxu/pcxw support


# 1.134 14-Sep-2004 mickey

store fpu version for later use. make sure to proper store/clear fpu state in fork/exec/exit/sendsig


# 1.133 14-Sep-2004 mickey

error out from btlb_insert() if there is none


Revision tags: OPENBSD_3_6_BASE
# 1.132 01-Jul-2004 mickey

have separate insn and data cache all-flushers


# 1.131 30-Jun-2004 mickey

allow forced fpu emulation through a sysctl


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.130 13-May-2004 mickey

8ks do not have hvt


# 1.129 05-May-2004 mickey

much easier tlb handler branch patching


# 1.128 05-May-2004 mickey

do not engage HPT on PCXT' (yet)


# 1.127 08-Apr-2004 mickey

repair pcxs/t confoosion


# 1.126 07-Apr-2004 mickey

update copyright; miod@ is fine w/ files where he holds it too


Revision tags: OPENBSD_3_5_BASE
# 1.125 10-Mar-2004 tom

Ensure that we obey a user's ddb> boot reboot command even if the system
is cold (during startup).

This adds RB_USERREQ to sys/reboot.h, uses it in the ddb commands, and
ensures that */*/machdep.c:boot() won't set RB_HALT when cold if this
flag is set.

ok deraadt@


# 1.124 14-Feb-2004 grange

Simplify hw.{cpuspeed,setperf} api moving all the sysctl stuff
from the underlying callbacks.

Testing hppa mickey@, ppc drahn@
Ok markus@ tedu@


# 1.123 05-Jan-2004 mickey

kill debugging code that is not needed anymore


# 1.122 23-Dec-2003 mickey

provide cpuspeed fluff


# 1.121 20-Dec-2003 miod

Don't let microtime() return a struct timeval with exactly 1000000 microseconds.


# 1.120 18-Dec-2003 mickey

spls do not protect cpu_itmr and thus time might jump back sometimes due to cpu_itmr modified to a higher value than a read itmr; found and testing by miod@


# 1.119 17-Dec-2003 mickey

in the real mem print do not include reserved for prom into used by openbsd


# 1.118 10-Dec-2003 mickey

for unaligned btlb mapping attempts -- just fail


# 1.117 24-Nov-2003 mickey

experimental support for HVT as a 2nd level tlb


# 1.116 15-Oct-2003 mickey

less global name space pollution


# 1.115 05-Oct-2003 mickey

reload the itmr as soon as we get the intr to avoid lagging on slower machines


# 1.114 25-Sep-2003 mickey

some pcxl2 do not report fpus -- assume it's there


Revision tags: OPENBSD_3_4_BASE
# 1.113 04-Sep-2003 mickey

a better cpu identification; testing by miod


# 1.112 31-Aug-2003 miod

pdc_model needs to be visible from cpu.c


# 1.111 20-Aug-2003 mickey

missing nl in debugging prontf


# 1.110 07-Aug-2003 mickey

dead proto


# 1.109 07-Aug-2003 mickey

first allocate space on stack then copyout signal shits. add a DEBUG check for a whacky user pc (as impossible due to the recent trap.c change)


# 1.108 03-Aug-2003 mickey

clear branch and nullify bits in psw on sending a signal


# 1.107 30-Jul-2003 mickey

deduce the leds address from the model number and thus make some more use of that lichtenblinkenschmutz on some more machinens


# 1.106 22-May-2003 mickey

imprecision in delay_init()


# 1.105 18-May-2003 mickey

save the fpu state for the signal handler. this is essential
as the fpu regs can be used by the gcc even for non-fpu
means and data copying.
rearrange the sigcontext a bit to include only the general
registers that are needed restoring upon return and thus
less waste of space and make up some space for the fpu regs.

ALL software that used the signal context on the stack
needs at least rebuilding now. a new snap has bin built as well.


Revision tags: UBC_SYNC_A
# 1.104 11-May-2003 deraadt

string cleaning; krw ok


# 1.103 07-Apr-2003 mickey

s/HP9000/HP 9000/; from weissmanndude


Revision tags: OPENBSD_3_3_BASE
# 1.102 18-Feb-2003 deraadt

knf; mickey ok


# 1.101 12-Feb-2003 jason

How uncommon... hppa only has one common: msgbufmapped (decl'd in /sys/kern)


# 1.100 12-Feb-2003 mickey

only align the first stack frame onto the minimal required alignment


# 1.99 10-Feb-2003 mickey

fix pcs and pcxt recognition. from weissmanndude


# 1.98 22-Jan-2003 mickey

consistantly use uvm_prot_* vs vm_prot_* evewrhere


# 1.97 14-Jan-2003 mickey

fix cutnpaste in the cpu table for the itlbna field; from herr weissmanndude


# 1.96 14-Jan-2003 mickey

need pdc_hwtlb always; pt out by herr weissmanndude


# 1.95 13-Jan-2003 mickey

fix the logic in hvt probing


# 1.94 09-Jan-2003 miod

Remove fetch(9) and store(9) functions from the kernel, and replace the few
remaining instances of them with appropriate copy(9) usage.

ok art@, tested on all arches unless my memory is non-ECC


# 1.93 19-Dec-2002 mickey

setregs: put the whole frame setup into one place


# 1.92 19-Dec-2002 mickey

level 0x16 is really an l2


# 1.91 17-Dec-2002 millert

Make SysV-style shared memory and semaphore limits sysctl'able.
Instead of allocating a static amount of memory for the data
structures via valloc() in allocsys(), allocate things dynamically
using pool(9) when possible and malloc(9) when not. The various
members of struct seminfo and struct shminfo are in kern.seminfo
and kern.shminfo respectively (not all members of kern.seminfo are
changable).

The data structures used still leave something to be desired but
things are not made worse in that respect by this commit.


# 1.90 27-Nov-2002 mickey

no wrapper arounf hardclock(), use CPU_CLOCKUPDATE, real microtime; miod ok


# 1.89 08-Nov-2002 mickey

Don't uvm_useracc the user sigcontext in sys_sigreturn and then access
the user addresses directly from the kernel. copyin is faster and can
correctly deal properly with mappings that uvm_useracc thinks are
correct but will fault anyway (to figure out how to generate such
mappings is left as en excercise for the reader).


# 1.88 01-Nov-2002 mickey

add a missing delay after printf on halt[-p], proper arg for a cold hook


Revision tags: UBC_SYNC_B
# 1.87 22-Oct-2002 mickey

do not force single-user; pt out by fries@


# 1.86 15-Oct-2002 mickey

missing initmsgbuf(), noticed by miod@


# 1.85 13-Oct-2002 mickey

track the end of physmem for use in dmmem_alloc


# 1.84 07-Oct-2002 mickey

s/PSW_/PSL_/ to match other archs


# 1.83 07-Oct-2002 mickey

proper terminate the user stack on signal


# 1.82 07-Oct-2002 mickey

on implementations w/ fpu included unimplemented instructions
are signaled through the exception trap w/ invalid opcode marked
instruction in the exception registers, not through the emulation
trap (as long as the fpu is enabled, of course).
parse emulation from the exception trap as well as the emulation
trap and fix the dispatcher into usable condition.
parse invalid op exception on trap and signal the user appropriately.
reset the exception on exec and for child on fork.
the later is appropriate since exceptions are delayed until next
fpu instruction, which was in the parent indeed, let him get it.
save parent's fpu context on fork before cipying it, if the
parent owned the fpu.


Revision tags: OPENBSD_3_2_BASE
# 1.81 23-Sep-2002 mickey

parisc level 0x10 is just an overclocked 0xe


# 1.80 17-Sep-2002 mickey

handle fpu exceptions properly, might use a regress, i guess


# 1.79 11-Sep-2002 mickey

provide a convinient reset label


# 1.78 11-Sep-2002 mickey

stack grows the other way, but the frame is the other way to that. hehe


# 1.77 09-Sep-2002 mickey

set up the frame flags and a user frame better on exec


# 1.76 03-Aug-2002 mickey

rework boot() w/o a goto


# 1.75 25-Jul-2002 mickey

missing arg in the call to the pdc_call since some old times


# 1.74 25-Jul-2002 mickey

kcopy is a space-to-space copy from kernel space, to guess where, -- to the same kernel space, just error on fault


# 1.73 20-Jul-2002 art

Instead of copying out the signal trampoline on top of the stack, create
an uvm aobj, copy out the signal trampoline into it and share that page
among all processes for the same emulation.

This also requires us to actually be able to tell signal code where the
trampoline is located, so introduce a new field in struct proc - p_sigcode
that is a pointer to sigcode. This allows us to remove all the ugly
calculations of the signal trampoline address done in every sendsig
function in the tree (that's why so many files are changed).

Tested by various people. ok deraadt@


# 1.72 14-May-2002 mickey

disable sid hashing while still in real mode, alos print the parisc arch once and not per each cpu since they are not intermixable architecture-wise


# 1.71 13-May-2002 mickey

ldi-ldo whatever was in the table, be that much clever


# 1.70 08-May-2002 mickey

print parisc level w/ the the parisc version, not for each cpu


# 1.69 08-May-2002 mickey

kill debugging printfski


# 1.68 22-Apr-2002 mickey

no longer batc the data, only the code.
this removes a constraint and an ld.script dependancy
for the .data and the dynamically allocated kernel
structures existed w/ batcing. also makes pmap_steal_memory
obsolete and replaced w/ the pmap_virtual_space.
implement batching for pmap_remove to avoid
zeroing out the pte entries if pde will be removed anyway.


# 1.67 21-Apr-2002 mickey

better buf's mapping and less magic constants in checking for io space cachability


Revision tags: OPENBSD_3_1_BASE
# 1.66 26-Mar-2002 mickey

if cannot guess cpu model default to the lowest supported one


# 1.65 25-Mar-2002 deraadt

spelling


# 1.64 23-Mar-2002 espie

Add variables for config(8) -e time tweak of systemV shared memory
parameters.

Ok millert@, miod@, maja@


# 1.63 19-Mar-2002 mickey

mtcpu seq requires a pre-sync, implement hpt init for pcxl


# 1.62 15-Mar-2002 mickey

rewrite a pmap to use multilevel page tables.
lower 12 bits contain the perms, no unused bits left,
but a couple for off-tlb use (as the ref implemented now).
do not use the hvt, which might get some use later
if proven to speed thigs up, tlb handlers would po
another dozen of insns though, but if that's worth its...
move on the data seg and map kernel text rdonly (idea form fredette),
since all of the page0 mods done before that we are all fine
except for some viper fluff, but later w/ that.
this also picks up a bit more of ddb magic for bpt and ss.
tlb handlers can use a little bit more of attention,
but things, visually, seem to be much faster already, --
sorry, no benchmarks for now.

* effort sponsored in part by the `henry st. old ale house'
* and mr.pete and mr.lee in particular in thier generous entrirety.
* the proj took a little more that 72man*h as it was expected,
* but within murhy's law estimations.


# 1.61 14-Mar-2002 millert

First round of __P removal in sys


# 1.60 20-Feb-2002 mickey

setup power failure handler (for sw-controlled power button), move toc handler


# 1.59 17-Feb-2002 maja

Patch from Daniel Lucq <daniel@lucq.org>

The patch allows you to change the value of NMBCLUSTERS, BUFCACHEPERCENT
and NKMEMPAGES using the config command, instead of recompiling the kernel.

This is the kernel part of the patch. I have compiled it on i386, sparc64,
alpha and macppc. -moj ok art@ maja@


# 1.58 12-Feb-2002 mickey

support 712's programmable power switch, no interrupt yet


# 1.57 12-Feb-2002 mickey

small repairs to hpmc and toc handlers


# 1.56 11-Feb-2002 mickey

disable fpu on csw, print fpu version on cpu line, if present


# 1.55 07-Feb-2002 mickey

fix sigdebug cases; init sigcontext before it's used (;


# 1.54 06-Feb-2002 mickey

implement signal delivery; based on fredette@'s work


# 1.53 03-Feb-2002 mickey

restore hpt size computation, does not break things as i thought


# 1.52 02-Feb-2002 mickey

fix 'physmem' usage


# 1.51 02-Feb-2002 mickey

implement the rest of /dev/mem devices; from netbsd


# 1.50 23-Jan-2002 art

move mb_map allocation to mbinit()


# 1.49 23-Jan-2002 art

move definition of mb_map from zillions of machdep.c to uipc_mbuf.c


# 1.48 16-Jan-2002 miod

Don't include <sys/map.h> when you don't need what's in it.


Revision tags: UBC_BASE
# 1.47 02-Dec-2001 mickey

branches: 1.47.2;
increase fixed extent storage


# 1.46 28-Nov-2001 art

zap some typedefs.
vm_map_t -> struct vm_map *
vm_map_entry_t -> struct vm_map_entry *
simple_lock_data_t -> struct simplelock

(uvm not done yet, coming in the next commit)


# 1.45 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.44 24-Nov-2001 miod

Harmonize boot() logic across arches:
- ensure RB_DUMP | RB_HALT will cause a dump
- or RB_HALT if (cold)
While there, honor RB_TIMEBAD on sparc64.


# 1.43 09-Nov-2001 art

nswbuf hasn't been used for ages. gc.


# 1.42 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.41 06-Nov-2001 miod

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


Revision tags: OPENBSD_3_0_BASE
# 1.40 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.39 12-Sep-2001 art

mbutl no more


# 1.38 23-Aug-2001 art

We can now move timeout_init into main().


# 1.37 23-Aug-2001 art

Remove even more old timeout tentacles.


# 1.36 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.35 05-Jul-2001 art

Get rid of REAL_CLISTS. It was never implemented and the tentacles are
everywhhere.


# 1.34 17-May-2001 provos

convert mbuf and cluster allocation to pool, mostly from NetBSD
okay art@ miod@


# 1.33 05-May-2001 art

Rename configure() to cpu_configure().
Move it from cpu_startup() to main().


# 1.32 05-May-2001 art

Get rid of CLSIZE and all related stuff.
CLSIZE -> 1
CLBYTES -> PAGE_SIZE
OLOFSET -> PAGE_MASK
etc.
At the same time some archs needed some cleaning in vmparam.h so that
goes in at the same time.


Revision tags: OPENBSD_2_9_BASE
# 1.31 29-Mar-2001 mickey

cpudev_data.h here needed not


# 1.30 22-Mar-2001 mickey

shuffle the tlb handlers a little,
make a new one for na data fault,
since those w/ hpt need it.


Revision tags: OPENBSD_2_8_BASE
# 1.29 15-Aug-2000 mickey

two btlb routines (i & d) for pcxs


# 1.28 15-Aug-2000 mickey

expand per-cpu control routines switch


# 1.27 08-Aug-2000 mickey

print btlb params w/ BTLBDEBUG; from Havard.Eidnes@runit.sintef.no


# 1.26 02-Jul-2000 mickey

no bays for stinger


Revision tags: OPENBSD_2_7_BASE
# 1.25 23-Mar-2000 mickey

new cpu type switch code.
initializes tlb miss handlers correspondent to probed cpu features.
also btlb load routine.
versions written are for pcxl and others.
cpu-dep btlb loaders are missing, only generic for now.


# 1.24 23-Mar-2000 art

New API for timeouts. Replaces the old timeout()/untimeout() API and
makes it the callers responsibility to allocate resources for the
timeouts.

This is a KISS implementation and does _not_ solve the problems of slow
handling of a large number of pending timeouts (this will be solved in
future work) (although hardclock is now guarateed to take constant time
for handling of timeouts).

Old timeout() and untimeout() are implemented as wrappers around the new
API and kept for compatibility. They will be removed as soon as all
subsystems are converted to use the new API.


# 1.23 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


# 1.22 22-Feb-2000 mickey

blah, blah, blah, msgbuf


Revision tags: SMP_BASE
# 1.21 09-Feb-2000 mickey

branches: 1.21.2;
heartbeat -- yeah we have a patch for that


# 1.20 25-Jan-2000 mickey

better copy and zero inlines in locore;
proper setregs() in machedep;
start of hpmc handler;
some cleanup here and there;


# 1.19 17-Jan-2000 mickey

remove unneeded stuff from setregs; force single-user for now, enable signal debug


# 1.18 11-Jan-2000 mickey

s/fpu_curproc/fpu_curpcb/ which also points into physical.
move it's definition into locore (where it's used the most).
adjust fpu context switch and save on swapout accordingly.
fix context save (in switch).
add accounting for fpu context switches (since it differes
from proc switching, we might get provided w/ some usefull
numbers as to how effective this lazy switch technique is).
enable handling fpu/sfu exceptions.


# 1.17 31-Dec-1999 mickey

don't bother about pidr3 and pidr4


# 1.16 17-Dec-1999 mickey

fix the panic message for sti memory mapping


Revision tags: kame_19991208
# 1.15 25-Nov-1999 mickey

bus stuff is in mainbus now, the rest is rewritten many ways


Revision tags: OPENBSD_2_6_BASE
# 1.14 20-Sep-1999 mickey

fix uvm_pagealloc() call


# 1.13 03-Sep-1999 art

Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.12 14-Aug-1999 mickey

proper debugging ifdefs


# 1.11 21-Jul-1999 mickey

rewrite the tlb miss handler and tlb dirty handler.
optimize for HVT usage (when compiled for proper cpu type).
drop hpt_* global variables, use info from control registers instead.
there are still ways to improve the tlb handlers tho.
machdep also prints cache and tlb coherence states (not related to the above).
You eat greenish muffin. --More-- You write real code.


# 1.10 12-Jul-1999 mickey

allocate 5% bufcache if <=16M memory installed


# 1.9 12-Jun-1999 mickey

hppa_init() now takes an argument from locore,
meaning the start of available memory.
cleanup machdep somewhat.
fix vm_map.pmap vs vm_pmap isue; 10x art@


# 1.8 23-May-1999 mickey

new swap stuff


# 1.7 21-May-1999 mickey

group all theMD f;ags together, add interrupt recursion one


# 1.6 21-May-1999 mickey

define fpu_curproc


# 1.5 20-Apr-1999 mickey

do lazy blok mapping of io space in bus_*
add copy{in,out}*, kcopy, etc
boot routines
cpu-id-hpux-compat stuff
rest of scheduler and such
uvm


Revision tags: OPENBSD_2_5_BASE
# 1.4 17-Feb-1999 mickey

print pa-risc here as well, since, finally, cpu will have to print processor type


# 1.3 04-Jan-1999 mickey

better cache handling in bus_space_barrier(), seem to work now


# 1.2 03-Jan-1999 mickey

implement bus_space_{un,}map w/ extents


# 1.1 30-Dec-1998 mickey

machdep; more work needed


# 1.253 10-Jul-2018 guenther

Move from sendsig() to its callers the initsiginfo() calls and
instead of passing sendsig() the code+type+val, pass a siginfo_t*
to copy from. Eliminate the indirection through struct emul for
sendsig(); we no longer have a SunOS4-compat version of sendsig()

ok deraadt@


# 1.252 22-May-2018 guenther

Delete antique sigdebug definitions

ok kettenis@


# 1.251 12-Apr-2018 deraadt

Implement MAP_STACK option for mmap(). Synchronous faults (pagefault and
syscall) confirm the stack register points at MAP_STACK memory, otherwise
SIGSEGV is delivered. sigaltstack() and pthread_attr_setstack() are modified
to create a MAP_STACK sub-region which satisfies alignment requirements.
Observe that MAP_STACK can only be set/cleared by mmap(), which zeroes the
contents of the region -- there is no mprotect() equivalent operation, so
there is no MAP_STACK-adding gadget.
This opportunistic software-emulation of a stack protection bit makes
stack-pivot operations during ROPchain fragile (kind of like removing a
tool from the toolbox).
original discussion with tedu, uvm work by stefan, testing by mortimer
ok kettenis


Revision tags: OPENBSD_6_3_BASE
# 1.250 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.249 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


Revision tags: OPENBSD_6_2_BASE
# 1.248 18-May-2017 kettenis

Implement copyin32(9).

"your chicken scratches look fine to me" deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.247 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

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


# 1.246 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.245 21-May-2016 deraadt

hand-massage sendsig() and sys_sigreturn() to be much more similar.
ok guenther kettenis


# 1.244 10-May-2016 deraadt

SROP mitigation. sendsig() stores a (per-process ^ &sigcontext) cookie
inside the sigcontext. sigreturn(2) checks syscall entry was from the
exact PC addr in the (per-process ASLR) sigtramp, verifies the cookie,
and clears it to prevent sigcontext reuse.
not yet tested on landisk, sparc, *88k, socppc.
ok kettenis


# 1.243 20-Apr-2016 dlg

pool_setipl for floating point context things

ok kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.242 21-Oct-2015 mpi

Do not call uvm_swap_finicrypt_all() a second time in dumpsys().

ok tedu@, deraadt@, miod@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.241 20-Jan-2015 kettenis

Move ps_strings "after" the random stackgap. This makes its location a
per-process value, and therefpore turns the VM_PSSTRINGS sysctl into a
per-process one as well. This gets rid of a pointer to the bottom of the
stack at a fixed location. Also clears the road for unmapping the stackgap.

ok deraadt@


# 1.240 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.239 25-Oct-2014 kettenis

Remove vmmap; it isn't used.

ok jsing@


# 1.238 23-Oct-2014 miod

Correctly set up the HPMC trap entry: according to the PA-RISC Firmware
Architecture Reference Specification, the sum of the 8 trap entry words
*and* of the payload which address and length are to be set at well-known
positions in the aforementioned trap entry, needs to be zero; the existing
code was only enforcing that the sum of the trap entry words is zero.

This matches what Linux and NetBSD do.

ok kettenis@


# 1.237 23-Oct-2014 miod

Revert limiting physmem to 2GB; the culprit was likely in uvm and uvm has
changed a lot in the last 5 years; verified to work on a 3GB system, in
snapshots for a few weeks already.


# 1.236 22-Sep-2014 dlg

implement atomic_{cas,swap}_{uint,ulong,ptr} and
atomic_{add,sub}_{int,long}_nv. sys/atomic.h turns these into the
rest of the atomic api.

on uniprocessor hppa systems "atomic" operations are implemented
as a non-interruptable sequence by disabling all interrupts on the
cpu, doing the operation, and then restoring the interrupt mask.

this isnt enough on MP systems, so we added a global atomic memory
mutex that is taken inside the interrupt disabling above to coordinate
operations between cpus.

this is a lot of overhead though cos mutexes dance around with ipls,
which is unecessary in our case because of the interrupt disabling
that is already done. also, hppa spinlocks are implemented with
ldcw which requires the word it operates on to be 16 byte aligned.
mutexes arent guaranteed to have this alignment so they compensate
by having lots of words inside themselves so they can hit the
appropriate one to use for the ldcw op.

with this in mind, this change pulls __cpu_simple_locks, which are
simply ldcw spinlocks with a 16 byte aligned word, out of
src/sys/arch/hppa/include/lock.h into src/sys/arch/hppa/include/atomic.h
so atomic.h can use them. lock.h includes atomic.h, so it still
gets and provides the same functionality as before.

finally, this also pulls the rwlock cas implementation apart. cas
ops now share the same serialising lock on MP systems as the other
memory operations, and rw_cas is defined as a wrapper around
atomic_cas_uint.

ok kettenis@


# 1.235 19-Sep-2014 kettenis

Use config_suspend_all(9).


# 1.234 18-Aug-2014 dlg

dont rely on mbuf.h to provide pool.h.

ok miod@, who has offerred to help with any MD fallout
ok guenther@


Revision tags: OPENBSD_5_6_BASE
# 1.233 22-Jul-2014 uebayasi

boot(9): Reduce diffs between hppa & hppa64 (& others)


# 1.232 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.231 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.230 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.229 13-Jul-2014 miod

These still need <sys/reboot.h> for the RB_ constants.


# 1.228 12-Jul-2014 uebayasi

reboot(9), panic(9): Call panic(9) for unrecoverable MD H/W errors (NMIs)

Some architectures have ability to detect hardware sanity and notify system
(NMI, firmware callback, etc.). Handle these hardware severe errors, same
as software errors, with panic(9).

According to miod@, SGI IP27 NMI is triggered by pushing some "hidden" button,
which "usual" users/admins don't know. Pushing such a button is "RB_USERREQ"
(human-triggered) in that the button is pushed by a human, but not "RB_USERREQ"
in that no user intervention in system (== no command input) is done. miod@
agreed that changing these from RB_USERREQ to !RB_USERREQ (== panic(9)) is
not a big problem.

OK miod@ kettenis@


# 1.227 12-Jul-2014 uebayasi

boot(9), reboot(9): Migrate MD callers of boot(9) to reboot(9)

I have found that some ports call boot(9) from machine-dependent code to
reboot system. These should be changed to either:

- Sending signal to init(8) to trigger it to shutdown system cleanly, like
acpi(4) does, in cases where found problems don't prevent system from working
immediately, or

- Just doing panic(9) if the situation is severely broken.

For now, just rewrite boot() to reboot(). Actual fixes follow.

Discussed with & OK from kettenis@


# 1.226 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.225 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.224 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.223 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.222 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.221 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.220 08-May-2014 miod

Format string fixes and removal of -Wno-format for hppa kernels.


# 1.219 08-Apr-2014 mpi

Less <uvm/uvm.h>


# 1.218 04-Apr-2014 miod

If the PDC_COPROC call fails, and we are running on a PA 1.1 system, assume
the usual 1.1 coprocessor mask, instead of using zero and having every
userland process dying with signal 4.

The circumstances under which this call fails are unclear and could be
tied to specific PROM version (I have tried overzealous stack alignment and
other tricks, to no avail). Interestingly enough, the 715/75 system which
hits this problem, only triggers it when booting from disk, and never when
booting from network.

This diff is an ugly bandaid until the problem is better understood. Or maybe
it is not worth investigating, seeing that Linux hardcodes the coprocessor
mask and never issues PDC_COPROC calls; I wonder what HP/UX does.

In my tree for over 18 months; "Looks like a nice hack" deraadt@
715/75 system provided by Sebastiaan Indesteege, thanks!


# 1.217 29-Mar-2014 guenther

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

ok dlg@ mpi@ deraadt@


# 1.216 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


# 1.215 22-Mar-2014 guenther

Move p_sigacts from struct proc to struct process.

testing help mpi@


# 1.214 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


Revision tags: OPENBSD_5_5_BASE
# 1.213 23-Nov-2013 uebayasi

Run doshutdownhooks() and config_suspend() even when boot() is called while
cold != 0. Indent and make hppa/hppa64 boot() closer to others.

OK kettenis@


# 1.212 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


Revision tags: OPENBSD_5_4_BASE
# 1.211 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


Revision tags: OPENBSD_5_3_BASE
# 1.210 02-Dec-2012 guenther

Determine whether we're currently on the alternative signal stack
dynamically, by comparing the stack pointer against the altstack
base and size, so that you get the correct answer if you longjmp
out of the signal handler, as tested by regress/sys/kern/stackjmp/.
Also, fix alt stack handling on vax, where it was completely broken.

Testing and corrections by miod@, krw@, tobiasu@, pirofti@


# 1.209 26-Oct-2012 kettenis

Properly clear trap frame in setregs() to avoid leaking registers across exec.

ok jsing@


# 1.208 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.207 07-Oct-2012 kettenis

Align the stack on a 64-byte boundary as required by "The 32-bit PA-RISC
Run-time Architecture Document". GCC relies on this to properly align
stack variables.

ok guenther@, beck@


Revision tags: OPENBSD_5_2_BASE
# 1.206 21-Jun-2012 guenther

__tfork() needs to set the stack address of the new thread in the kernel,
so that it can't get a signal while still running on the parent thread's
stack. Also, pass in sizeof(struct __tfork) to provide forward compat
when more members are added. This is an ABI change, so switch syscall
numbers and bump lib majors this time.

ok deraadt@ matthew@


Revision tags: OPENBSD_5_1_BASE
# 1.205 20-Sep-2011 miod

Clear RB_POWERDOWN early in boot() on systems which can not powerdown and
which firmware does not send spin up commands to the disks, in case the
operator changes his mind and reboots instead of manually powering down
after the system has halted.
ok kettenis@


Revision tags: OPENBSD_5_0_BASE
# 1.204 05-Jul-2011 guenther

Recommit the reverted sigacts change now that the NFS use-after-free
problem has been tracked down. This fixes the sharing of the signal
handling state: shared bits go in sigacts, per-rthread bits goes in
struct proc.

ok deraadt@


# 1.203 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.202 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.201 18-Apr-2011 guenther

Revert the sigacts diff: NFS can apparently retain pointers to processes
until they're zombies and then send them signals (for intr mounts). Until
that is untangled, the sigacts change is unsafe. sthen@ was the victim
for this one


# 1.200 15-Apr-2011 guenther

Correct the sharing of the signal handling state: stuff that should
be shared (p_sigignore, p_sigcatch, P_NOCLDSTOP, P_NOCLDWAIT) moves
to struct sigacts, wihle stuff that should be per rthread (ps_oldmask,
SAS_OLDMASK, ps_sigstk) moves to struct proc. Treat the coredumping
state bits (ps_sig, ps_code, ps_type, ps_sigval) as per-rthread
until our locking around coredumping is better.

Oh, and remove the old SunOS-compat ps_usertramp member.

"I like the sound of this" tedu@


Revision tags: OPENBSD_4_9_BASE
# 1.199 14-Jan-2011 jsing

Halt secondary CPUs when shutting down or rebooting. This should prevent
occasional hangs during reboot.

ok kettenis@


# 1.198 04-Jan-2011 jasper

- de-register. no binary change.

ok jsing@


# 1.197 01-Jan-2011 jasper

Move setting cpu_hzticks to the clock initialization function, like
other ports (e.g. hppa64) do.

ok jsing@ kettenis@


# 1.196 01-Jan-2011 jasper

- ansify

ok jsing@ kettenis@


# 1.195 30-Dec-2010 jsing

Turn signotify() into a function that also calls cpu_unidle().

ok kettenis@


# 1.194 20-Nov-2010 miod

This is a first step towards getting rid of avail_start and avail_end in the
kernel, currently limited to low-hanging fruit: these variables were used
by bus_dma to specify the range in which to allocate memory, back when
uvm_pglistalloc() was stupid and would not walk the vm_physseg[].

Nowadays, except on some platforms for early initialization, these variables
are not used, or do not need to be global variables. Therefore:
- remove `extern' declarations of avail_start and avail_end (or close cousins,
such as arm physical_start and physical_end) from files which no longer need
to use them.
- make them local variables whenever possible.
- remove them when they are assigned to but no longer used.


Revision tags: OPENBSD_4_8_BASE
# 1.193 01-Jul-2010 jsing

Create a struct to store FP state and include a pointer to the CPU that
currently holds the FPU context for this process. This will be soon used
to implement FPU shootdowns on multiprocessor kernels.

ok kettenis@


# 1.192 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.191 29-Jun-2010 jsing

Factor out code used to save and flushe process FPU context.

ok kettenis@


# 1.190 29-Jun-2010 jsing

Store pointer to process FPU state in struct cpu_info.

ok kettenis@


# 1.189 27-Jun-2010 thib

uvm constraints. Add two mandatory MD symbols, uvm_md_constraints
which contains the constraints for DMA/memory allocation for each
architecture, and dma_constraints which contains the range of addresses
that are dma accessable by the system.

This is based on ariane@'s physcontig diff, with lots of bugfixes and
additions the following additions by my self:

Introduce a new function pool_set_constraints() which sets the address
range for which we allocate pages for the pool from, this is now used
for the mbuf/mbuf cluster pools to keep them dma accessible.

The !direct archs no longer stuff pages into the kernel object in
uvm_km_getpage_pla but rather do a pmap_extract() in uvm_km_putpages.

Tested heavily by my self on i386, amd64 and sparc64. Some tests on
alpha and SGI.

"commit it" beck, art, oga, deraadt
"i like the diff" deraadt


# 1.188 27-Jun-2010 jsing

Use a mutex to make atomic operations atomic on multiprocessor kernels.

ok kettenis@


# 1.187 10-Jun-2010 deraadt

Declare safepri at the MD level on each platform, so that the kern_synch.c
does not have to deal with it as a common. Some platforms may be missed
by this commit... if you spot one, fix it the same way.
ok miod


# 1.186 09-Jun-2010 miod

Move declaration of cn_tab from dev/cons.c to dev/cninit.c, or appropriate
md files for ports which do not use dev/cninit.c. This gets rid of a common
at kernel link time.
feedback drahn@ ok deraadt@


# 1.185 24-May-2010 deraadt

Add missing prototypes
ok jsing kettenis


# 1.184 09-May-2010 kettenis

Prevent "taken branch" exceptions from kernel space by clearing the PSL_T
bit before we enter a signal handler.

"if you say so" miod@, "seems to make sense" jsing@


# 1.183 02-May-2010 kettenis

Properly initialize the members of `struct mdproc' that deal with
single-stepping when we fork and reset them upon exec.

ok miod@


# 1.182 27-Apr-2010 kettenis

Avoid null-pointer dereference by giving proc0 a place to store its
floating-point registers. Pointed out by Nick Hudson.

ok miod@, jsing@


# 1.181 19-Apr-2010 jsing

Make the Processor Status Word (PSW) a per-CPU value.

ok kettenis@


# 1.180 01-Apr-2010 jsing

Allow for multiple CPUs by moving to an array of cpu_info.

ok kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.179 31-Dec-2009 jsing

Make cpl and cpu_inintr per CPU variables. For locore.S, cpl becomes an
offset within cpu_primary_info - this will need to be revisited shortly.

ok kettenis@


# 1.178 11-Aug-2009 miod

Do not bother initializing bufpages in the md code if the computation is
exactly the same the mi could will use if bufinit() is invoked with
bufpages == 0.


# 1.177 11-Aug-2009 miod

With the SysV memory allocation changes, allocsys() doesn't do anything
anymore. Get rid of it completely.


# 1.176 09-Aug-2009 blambert

Rototill system V message queues.

No longer allocate a static amount of memory for messages in MD
boot path; message queues, message metadata, and message data now
all use dynamic memory, which means that runtime sysctls should now
be trivial to implement.

Since I'm going to be around all week to fix any breakage, this should
probably just go in now.


# 1.175 02-Aug-2009 beck

Dynamic buffer cache support - a re-commit of what was backed out
after c2k9

allows buffer cache to be extended and grow/shrink dynamically

tested by many, ok oga@, "why not just commit it" deraadt@


# 1.174 29-Jul-2009 kettenis

Get rid of non-equivalent aliases of the pcb by moving the fpu state out
of the pcb and using the p_addr member of 'struct proc' to calculate the
address of the kernel stack when switching to virtual mode after taking a trap.
Remove the now unecessary cache flushes; they're actually harmful since they
create non-equivalent aliases. This seems to fix the memory corruption we
have been observing from time to time.

This diff does not rename fpu_curpcb, which is now somewhat incorrectly named.
I hope to change things back again as soon as we are able to map the pcb 1:1.


Revision tags: OPENBSD_4_6_BASE
# 1.173 15-Jun-2009 beck

Back out all the buffer cache changes I committed during c2k9. This reverts three
commits:

1) The sysctl allowing bufcachepercent to be changed at boot time.
2) The change moving the buffer cache hash chains to a red-black tree
3) The dynamic buffer cache (Which depended on the earlier too).

ok on the backout from marco and todd


# 1.172 03-Jun-2009 beck

add kern.bufcachepercent sysctl to allow adjusting the buffer cache
size on a running system.
ok art@, oga@


Revision tags: OPENBSD_4_5_BASE
# 1.171 14-Feb-2009 kettenis

Limit the amount of physical memory to 2GB. Using more causes memory
corruption on PA-RISC 2.0 systems (and there are very few PA-RISC 1.1
systems that support more than 2GB).

ok miod@


# 1.170 04-Feb-2009 miod

On systems with split BTLB, do not bother trying to insert DBTLB entries,
as PDC will lie to us pretending it did while it didn't.

ok kettenis@


# 1.169 04-Feb-2009 miod

Unify memory size reports a bit more: always report size in MB, and report
reserved memory on alpha and hppa on its own line (as done on sgi).


Revision tags: OPENBSD_4_4_BASE
# 1.168 14-Jul-2008 miod

Be sure to propagate PSL_O in psw on PCXU* processors to userland processes
and signal handlers.
ok kettenis@


# 1.167 27-Jun-2008 miod

Clear swap encryption keys before dumping a kernel image.


# 1.166 09-Apr-2008 deraadt

Add new stub uvm_shutdown() and call it from the right place in MD boot()


Revision tags: OPENBSD_4_3_BASE
# 1.165 22-Sep-2007 martin

replace even more ctob and btoc with ptoa and atop respectively plus
uvm_extern.h where needed


Revision tags: OPENBSD_4_2_BASE
# 1.164 22-Jul-2007 kettenis

Move hppa to __HAVE_TIMECOUNTERS.


# 1.163 20-Jul-2007 kettenis

Give hppa the blink_led API from sparc64, and the associated machdep.led_blink
sysctl.


# 1.162 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.161 14-Jul-2007 kettenis

Make sigreturn(2) set the proper space ID for the instruction queue. Fixes
a few more pthreads regression tests.

ok miod@


# 1.160 10-Jul-2007 kettenis

Don't trust the privilige level in the sigcontext passed to sigreturn(2).

ok miod@


# 1.159 24-Jun-2007 kettenis

Crank initial storage for extents a bit. We really should allocate extents
using malloc once vm is initialised, but this will do for now.

ok deraadt@


# 1.158 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.157 27-May-2007 miod

Make sure the minaddr hint for uvm_km_suballoc() calls is always initialized.
ok pedro@


# 1.156 26-May-2007 pedro

Dynamic buffer cache. Initial diff from mickey@, okay art@ beck@ toby@
deraadt@ dlg@.


# 1.155 21-May-2007 kettenis

Add support for 8700/pcxw2 cpu.


# 1.154 21-May-2007 kettenis

Ask firmware for reset before trying ourselves; needed for four-digit b/c/j
workstations.

tested by otto@, krw@; ok deraadt@


# 1.153 17-May-2007 art

Limit hppa buffer cache to 30%. It used to be 70% because stack garbage
that was used for minaddr instead of the proper vm_map_min(kernel_map)
(fixed in this diff).

From mickey. art@ ok


# 1.152 14-May-2007 martin

move hppa to __HAVE_CPUINFO

input from miod@, ok kettenis@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.151 28-May-2006 martin

minor nit, use CPU ID instead of FPU ID for BTLB parameters after passing
all kludges


# 1.150 15-Apr-2006 martin

make warning about missing HPT support DEBUG for now

ok mickey@


Revision tags: OPENBSD_3_9_BASE
# 1.149 26-Oct-2005 martin

no more hppa_round_page() and hppa_trunc_page() macros

ok mickey@


Revision tags: OPENBSD_3_8_BASE
# 1.148 06-Aug-2005 miod

We do not need a char machine_arch[] constant.
ok deraadt@


# 1.147 11-Jul-2005 mickey

align some stupid comments


# 1.146 10-May-2005 mickey

set pcsq in case we get signal delivery once interrupted from the gateway page; from chs


# 1.145 18-Apr-2005 mickey

do not do some of the initmsgbuf()s job


# 1.144 07-Apr-2005 mickey

on some machines it's possible to limit the amount of physmem initialised dring post so having msgbuf at the end of memory shall work


# 1.143 07-Apr-2005 mickey

64bit-friendly pdc.h and iomod.h and correspondent changes elsewhere


# 1.142 26-Mar-2005 mickey

md parts for hpux_compa code; some problems w/ signals delivery still exist


Revision tags: OPENBSD_3_7_BASE
# 1.141 24-Feb-2005 mickey

do not even ask for btlb on 8k cpus as pdc pretends there is some but then it does not work; found w/ Moritz Kiese <mbk@mytum.de> on c180; add a debug print and fix pcxu entry


# 1.140 17-Nov-2004 mickey

print real/avail/bufcache sizes as unsigned


# 1.139 26-Oct-2004 mickey

disable sid hashing on pcxu and above


# 1.138 14-Oct-2004 mickey

a bit larger delays during boot() to let msgs appear


# 1.137 19-Sep-2004 mickey

turn totalphysmem into physmem and name old physmem into smth it really is


# 1.136 18-Sep-2004 mickey

oops


# 1.135 15-Sep-2004 mickey

add pcxu tlb handlers and cpu probing
add u2/uturn ioa driver in dumb mode now
enable pcxu/pcxw support


# 1.134 14-Sep-2004 mickey

store fpu version for later use. make sure to proper store/clear fpu state in fork/exec/exit/sendsig


# 1.133 14-Sep-2004 mickey

error out from btlb_insert() if there is none


Revision tags: OPENBSD_3_6_BASE
# 1.132 01-Jul-2004 mickey

have separate insn and data cache all-flushers


# 1.131 30-Jun-2004 mickey

allow forced fpu emulation through a sysctl


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.130 13-May-2004 mickey

8ks do not have hvt


# 1.129 05-May-2004 mickey

much easier tlb handler branch patching


# 1.128 05-May-2004 mickey

do not engage HPT on PCXT' (yet)


# 1.127 08-Apr-2004 mickey

repair pcxs/t confoosion


# 1.126 07-Apr-2004 mickey

update copyright; miod@ is fine w/ files where he holds it too


Revision tags: OPENBSD_3_5_BASE
# 1.125 10-Mar-2004 tom

Ensure that we obey a user's ddb> boot reboot command even if the system
is cold (during startup).

This adds RB_USERREQ to sys/reboot.h, uses it in the ddb commands, and
ensures that */*/machdep.c:boot() won't set RB_HALT when cold if this
flag is set.

ok deraadt@


# 1.124 14-Feb-2004 grange

Simplify hw.{cpuspeed,setperf} api moving all the sysctl stuff
from the underlying callbacks.

Testing hppa mickey@, ppc drahn@
Ok markus@ tedu@


# 1.123 05-Jan-2004 mickey

kill debugging code that is not needed anymore


# 1.122 23-Dec-2003 mickey

provide cpuspeed fluff


# 1.121 20-Dec-2003 miod

Don't let microtime() return a struct timeval with exactly 1000000 microseconds.


# 1.120 18-Dec-2003 mickey

spls do not protect cpu_itmr and thus time might jump back sometimes due to cpu_itmr modified to a higher value than a read itmr; found and testing by miod@


# 1.119 17-Dec-2003 mickey

in the real mem print do not include reserved for prom into used by openbsd


# 1.118 10-Dec-2003 mickey

for unaligned btlb mapping attempts -- just fail


# 1.117 24-Nov-2003 mickey

experimental support for HVT as a 2nd level tlb


# 1.116 15-Oct-2003 mickey

less global name space pollution


# 1.115 05-Oct-2003 mickey

reload the itmr as soon as we get the intr to avoid lagging on slower machines


# 1.114 25-Sep-2003 mickey

some pcxl2 do not report fpus -- assume it's there


Revision tags: OPENBSD_3_4_BASE
# 1.113 04-Sep-2003 mickey

a better cpu identification; testing by miod


# 1.112 31-Aug-2003 miod

pdc_model needs to be visible from cpu.c


# 1.111 20-Aug-2003 mickey

missing nl in debugging prontf


# 1.110 07-Aug-2003 mickey

dead proto


# 1.109 07-Aug-2003 mickey

first allocate space on stack then copyout signal shits. add a DEBUG check for a whacky user pc (as impossible due to the recent trap.c change)


# 1.108 03-Aug-2003 mickey

clear branch and nullify bits in psw on sending a signal


# 1.107 30-Jul-2003 mickey

deduce the leds address from the model number and thus make some more use of that lichtenblinkenschmutz on some more machinens


# 1.106 22-May-2003 mickey

imprecision in delay_init()


# 1.105 18-May-2003 mickey

save the fpu state for the signal handler. this is essential
as the fpu regs can be used by the gcc even for non-fpu
means and data copying.
rearrange the sigcontext a bit to include only the general
registers that are needed restoring upon return and thus
less waste of space and make up some space for the fpu regs.

ALL software that used the signal context on the stack
needs at least rebuilding now. a new snap has bin built as well.


Revision tags: UBC_SYNC_A
# 1.104 11-May-2003 deraadt

string cleaning; krw ok


# 1.103 07-Apr-2003 mickey

s/HP9000/HP 9000/; from weissmanndude


Revision tags: OPENBSD_3_3_BASE
# 1.102 18-Feb-2003 deraadt

knf; mickey ok


# 1.101 12-Feb-2003 jason

How uncommon... hppa only has one common: msgbufmapped (decl'd in /sys/kern)


# 1.100 12-Feb-2003 mickey

only align the first stack frame onto the minimal required alignment


# 1.99 10-Feb-2003 mickey

fix pcs and pcxt recognition. from weissmanndude


# 1.98 22-Jan-2003 mickey

consistantly use uvm_prot_* vs vm_prot_* evewrhere


# 1.97 14-Jan-2003 mickey

fix cutnpaste in the cpu table for the itlbna field; from herr weissmanndude


# 1.96 14-Jan-2003 mickey

need pdc_hwtlb always; pt out by herr weissmanndude


# 1.95 13-Jan-2003 mickey

fix the logic in hvt probing


# 1.94 09-Jan-2003 miod

Remove fetch(9) and store(9) functions from the kernel, and replace the few
remaining instances of them with appropriate copy(9) usage.

ok art@, tested on all arches unless my memory is non-ECC


# 1.93 19-Dec-2002 mickey

setregs: put the whole frame setup into one place


# 1.92 19-Dec-2002 mickey

level 0x16 is really an l2


# 1.91 17-Dec-2002 millert

Make SysV-style shared memory and semaphore limits sysctl'able.
Instead of allocating a static amount of memory for the data
structures via valloc() in allocsys(), allocate things dynamically
using pool(9) when possible and malloc(9) when not. The various
members of struct seminfo and struct shminfo are in kern.seminfo
and kern.shminfo respectively (not all members of kern.seminfo are
changable).

The data structures used still leave something to be desired but
things are not made worse in that respect by this commit.


# 1.90 27-Nov-2002 mickey

no wrapper arounf hardclock(), use CPU_CLOCKUPDATE, real microtime; miod ok


# 1.89 08-Nov-2002 mickey

Don't uvm_useracc the user sigcontext in sys_sigreturn and then access
the user addresses directly from the kernel. copyin is faster and can
correctly deal properly with mappings that uvm_useracc thinks are
correct but will fault anyway (to figure out how to generate such
mappings is left as en excercise for the reader).


# 1.88 01-Nov-2002 mickey

add a missing delay after printf on halt[-p], proper arg for a cold hook


Revision tags: UBC_SYNC_B
# 1.87 22-Oct-2002 mickey

do not force single-user; pt out by fries@


# 1.86 15-Oct-2002 mickey

missing initmsgbuf(), noticed by miod@


# 1.85 13-Oct-2002 mickey

track the end of physmem for use in dmmem_alloc


# 1.84 07-Oct-2002 mickey

s/PSW_/PSL_/ to match other archs


# 1.83 07-Oct-2002 mickey

proper terminate the user stack on signal


# 1.82 07-Oct-2002 mickey

on implementations w/ fpu included unimplemented instructions
are signaled through the exception trap w/ invalid opcode marked
instruction in the exception registers, not through the emulation
trap (as long as the fpu is enabled, of course).
parse emulation from the exception trap as well as the emulation
trap and fix the dispatcher into usable condition.
parse invalid op exception on trap and signal the user appropriately.
reset the exception on exec and for child on fork.
the later is appropriate since exceptions are delayed until next
fpu instruction, which was in the parent indeed, let him get it.
save parent's fpu context on fork before cipying it, if the
parent owned the fpu.


Revision tags: OPENBSD_3_2_BASE
# 1.81 23-Sep-2002 mickey

parisc level 0x10 is just an overclocked 0xe


# 1.80 17-Sep-2002 mickey

handle fpu exceptions properly, might use a regress, i guess


# 1.79 11-Sep-2002 mickey

provide a convinient reset label


# 1.78 11-Sep-2002 mickey

stack grows the other way, but the frame is the other way to that. hehe


# 1.77 09-Sep-2002 mickey

set up the frame flags and a user frame better on exec


# 1.76 03-Aug-2002 mickey

rework boot() w/o a goto


# 1.75 25-Jul-2002 mickey

missing arg in the call to the pdc_call since some old times


# 1.74 25-Jul-2002 mickey

kcopy is a space-to-space copy from kernel space, to guess where, -- to the same kernel space, just error on fault


# 1.73 20-Jul-2002 art

Instead of copying out the signal trampoline on top of the stack, create
an uvm aobj, copy out the signal trampoline into it and share that page
among all processes for the same emulation.

This also requires us to actually be able to tell signal code where the
trampoline is located, so introduce a new field in struct proc - p_sigcode
that is a pointer to sigcode. This allows us to remove all the ugly
calculations of the signal trampoline address done in every sendsig
function in the tree (that's why so many files are changed).

Tested by various people. ok deraadt@


# 1.72 14-May-2002 mickey

disable sid hashing while still in real mode, alos print the parisc arch once and not per each cpu since they are not intermixable architecture-wise


# 1.71 13-May-2002 mickey

ldi-ldo whatever was in the table, be that much clever


# 1.70 08-May-2002 mickey

print parisc level w/ the the parisc version, not for each cpu


# 1.69 08-May-2002 mickey

kill debugging printfski


# 1.68 22-Apr-2002 mickey

no longer batc the data, only the code.
this removes a constraint and an ld.script dependancy
for the .data and the dynamically allocated kernel
structures existed w/ batcing. also makes pmap_steal_memory
obsolete and replaced w/ the pmap_virtual_space.
implement batching for pmap_remove to avoid
zeroing out the pte entries if pde will be removed anyway.


# 1.67 21-Apr-2002 mickey

better buf's mapping and less magic constants in checking for io space cachability


Revision tags: OPENBSD_3_1_BASE
# 1.66 26-Mar-2002 mickey

if cannot guess cpu model default to the lowest supported one


# 1.65 25-Mar-2002 deraadt

spelling


# 1.64 23-Mar-2002 espie

Add variables for config(8) -e time tweak of systemV shared memory
parameters.

Ok millert@, miod@, maja@


# 1.63 19-Mar-2002 mickey

mtcpu seq requires a pre-sync, implement hpt init for pcxl


# 1.62 15-Mar-2002 mickey

rewrite a pmap to use multilevel page tables.
lower 12 bits contain the perms, no unused bits left,
but a couple for off-tlb use (as the ref implemented now).
do not use the hvt, which might get some use later
if proven to speed thigs up, tlb handlers would po
another dozen of insns though, but if that's worth its...
move on the data seg and map kernel text rdonly (idea form fredette),
since all of the page0 mods done before that we are all fine
except for some viper fluff, but later w/ that.
this also picks up a bit more of ddb magic for bpt and ss.
tlb handlers can use a little bit more of attention,
but things, visually, seem to be much faster already, --
sorry, no benchmarks for now.

* effort sponsored in part by the `henry st. old ale house'
* and mr.pete and mr.lee in particular in thier generous entrirety.
* the proj took a little more that 72man*h as it was expected,
* but within murhy's law estimations.


# 1.61 14-Mar-2002 millert

First round of __P removal in sys


# 1.60 20-Feb-2002 mickey

setup power failure handler (for sw-controlled power button), move toc handler


# 1.59 17-Feb-2002 maja

Patch from Daniel Lucq <daniel@lucq.org>

The patch allows you to change the value of NMBCLUSTERS, BUFCACHEPERCENT
and NKMEMPAGES using the config command, instead of recompiling the kernel.

This is the kernel part of the patch. I have compiled it on i386, sparc64,
alpha and macppc. -moj ok art@ maja@


# 1.58 12-Feb-2002 mickey

support 712's programmable power switch, no interrupt yet


# 1.57 12-Feb-2002 mickey

small repairs to hpmc and toc handlers


# 1.56 11-Feb-2002 mickey

disable fpu on csw, print fpu version on cpu line, if present


# 1.55 07-Feb-2002 mickey

fix sigdebug cases; init sigcontext before it's used (;


# 1.54 06-Feb-2002 mickey

implement signal delivery; based on fredette@'s work


# 1.53 03-Feb-2002 mickey

restore hpt size computation, does not break things as i thought


# 1.52 02-Feb-2002 mickey

fix 'physmem' usage


# 1.51 02-Feb-2002 mickey

implement the rest of /dev/mem devices; from netbsd


# 1.50 23-Jan-2002 art

move mb_map allocation to mbinit()


# 1.49 23-Jan-2002 art

move definition of mb_map from zillions of machdep.c to uipc_mbuf.c


# 1.48 16-Jan-2002 miod

Don't include <sys/map.h> when you don't need what's in it.


Revision tags: UBC_BASE
# 1.47 02-Dec-2001 mickey

branches: 1.47.2;
increase fixed extent storage


# 1.46 28-Nov-2001 art

zap some typedefs.
vm_map_t -> struct vm_map *
vm_map_entry_t -> struct vm_map_entry *
simple_lock_data_t -> struct simplelock

(uvm not done yet, coming in the next commit)


# 1.45 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.44 24-Nov-2001 miod

Harmonize boot() logic across arches:
- ensure RB_DUMP | RB_HALT will cause a dump
- or RB_HALT if (cold)
While there, honor RB_TIMEBAD on sparc64.


# 1.43 09-Nov-2001 art

nswbuf hasn't been used for ages. gc.


# 1.42 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.41 06-Nov-2001 miod

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


Revision tags: OPENBSD_3_0_BASE
# 1.40 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.39 12-Sep-2001 art

mbutl no more


# 1.38 23-Aug-2001 art

We can now move timeout_init into main().


# 1.37 23-Aug-2001 art

Remove even more old timeout tentacles.


# 1.36 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.35 05-Jul-2001 art

Get rid of REAL_CLISTS. It was never implemented and the tentacles are
everywhhere.


# 1.34 17-May-2001 provos

convert mbuf and cluster allocation to pool, mostly from NetBSD
okay art@ miod@


# 1.33 05-May-2001 art

Rename configure() to cpu_configure().
Move it from cpu_startup() to main().


# 1.32 05-May-2001 art

Get rid of CLSIZE and all related stuff.
CLSIZE -> 1
CLBYTES -> PAGE_SIZE
OLOFSET -> PAGE_MASK
etc.
At the same time some archs needed some cleaning in vmparam.h so that
goes in at the same time.


Revision tags: OPENBSD_2_9_BASE
# 1.31 29-Mar-2001 mickey

cpudev_data.h here needed not


# 1.30 22-Mar-2001 mickey

shuffle the tlb handlers a little,
make a new one for na data fault,
since those w/ hpt need it.


Revision tags: OPENBSD_2_8_BASE
# 1.29 15-Aug-2000 mickey

two btlb routines (i & d) for pcxs


# 1.28 15-Aug-2000 mickey

expand per-cpu control routines switch


# 1.27 08-Aug-2000 mickey

print btlb params w/ BTLBDEBUG; from Havard.Eidnes@runit.sintef.no


# 1.26 02-Jul-2000 mickey

no bays for stinger


Revision tags: OPENBSD_2_7_BASE
# 1.25 23-Mar-2000 mickey

new cpu type switch code.
initializes tlb miss handlers correspondent to probed cpu features.
also btlb load routine.
versions written are for pcxl and others.
cpu-dep btlb loaders are missing, only generic for now.


# 1.24 23-Mar-2000 art

New API for timeouts. Replaces the old timeout()/untimeout() API and
makes it the callers responsibility to allocate resources for the
timeouts.

This is a KISS implementation and does _not_ solve the problems of slow
handling of a large number of pending timeouts (this will be solved in
future work) (although hardclock is now guarateed to take constant time
for handling of timeouts).

Old timeout() and untimeout() are implemented as wrappers around the new
API and kept for compatibility. They will be removed as soon as all
subsystems are converted to use the new API.


# 1.23 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


# 1.22 22-Feb-2000 mickey

blah, blah, blah, msgbuf


Revision tags: SMP_BASE
# 1.21 09-Feb-2000 mickey

branches: 1.21.2;
heartbeat -- yeah we have a patch for that


# 1.20 25-Jan-2000 mickey

better copy and zero inlines in locore;
proper setregs() in machedep;
start of hpmc handler;
some cleanup here and there;


# 1.19 17-Jan-2000 mickey

remove unneeded stuff from setregs; force single-user for now, enable signal debug


# 1.18 11-Jan-2000 mickey

s/fpu_curproc/fpu_curpcb/ which also points into physical.
move it's definition into locore (where it's used the most).
adjust fpu context switch and save on swapout accordingly.
fix context save (in switch).
add accounting for fpu context switches (since it differes
from proc switching, we might get provided w/ some usefull
numbers as to how effective this lazy switch technique is).
enable handling fpu/sfu exceptions.


# 1.17 31-Dec-1999 mickey

don't bother about pidr3 and pidr4


# 1.16 17-Dec-1999 mickey

fix the panic message for sti memory mapping


Revision tags: kame_19991208
# 1.15 25-Nov-1999 mickey

bus stuff is in mainbus now, the rest is rewritten many ways


Revision tags: OPENBSD_2_6_BASE
# 1.14 20-Sep-1999 mickey

fix uvm_pagealloc() call


# 1.13 03-Sep-1999 art

Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.12 14-Aug-1999 mickey

proper debugging ifdefs


# 1.11 21-Jul-1999 mickey

rewrite the tlb miss handler and tlb dirty handler.
optimize for HVT usage (when compiled for proper cpu type).
drop hpt_* global variables, use info from control registers instead.
there are still ways to improve the tlb handlers tho.
machdep also prints cache and tlb coherence states (not related to the above).
You eat greenish muffin. --More-- You write real code.


# 1.10 12-Jul-1999 mickey

allocate 5% bufcache if <=16M memory installed


# 1.9 12-Jun-1999 mickey

hppa_init() now takes an argument from locore,
meaning the start of available memory.
cleanup machdep somewhat.
fix vm_map.pmap vs vm_pmap isue; 10x art@


# 1.8 23-May-1999 mickey

new swap stuff


# 1.7 21-May-1999 mickey

group all theMD f;ags together, add interrupt recursion one


# 1.6 21-May-1999 mickey

define fpu_curproc


# 1.5 20-Apr-1999 mickey

do lazy blok mapping of io space in bus_*
add copy{in,out}*, kcopy, etc
boot routines
cpu-id-hpux-compat stuff
rest of scheduler and such
uvm


Revision tags: OPENBSD_2_5_BASE
# 1.4 17-Feb-1999 mickey

print pa-risc here as well, since, finally, cpu will have to print processor type


# 1.3 04-Jan-1999 mickey

better cache handling in bus_space_barrier(), seem to work now


# 1.2 03-Jan-1999 mickey

implement bus_space_{un,}map w/ extents


# 1.1 30-Dec-1998 mickey

machdep; more work needed


# 1.252 22-May-2018 guenther

Delete antique sigdebug definitions

ok kettenis@


# 1.251 12-Apr-2018 deraadt

Implement MAP_STACK option for mmap(). Synchronous faults (pagefault and
syscall) confirm the stack register points at MAP_STACK memory, otherwise
SIGSEGV is delivered. sigaltstack() and pthread_attr_setstack() are modified
to create a MAP_STACK sub-region which satisfies alignment requirements.
Observe that MAP_STACK can only be set/cleared by mmap(), which zeroes the
contents of the region -- there is no mprotect() equivalent operation, so
there is no MAP_STACK-adding gadget.
This opportunistic software-emulation of a stack protection bit makes
stack-pivot operations during ROPchain fragile (kind of like removing a
tool from the toolbox).
original discussion with tedu, uvm work by stefan, testing by mortimer
ok kettenis


Revision tags: OPENBSD_6_3_BASE
# 1.250 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.249 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


Revision tags: OPENBSD_6_2_BASE
# 1.248 18-May-2017 kettenis

Implement copyin32(9).

"your chicken scratches look fine to me" deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.247 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

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


# 1.246 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.245 21-May-2016 deraadt

hand-massage sendsig() and sys_sigreturn() to be much more similar.
ok guenther kettenis


# 1.244 10-May-2016 deraadt

SROP mitigation. sendsig() stores a (per-process ^ &sigcontext) cookie
inside the sigcontext. sigreturn(2) checks syscall entry was from the
exact PC addr in the (per-process ASLR) sigtramp, verifies the cookie,
and clears it to prevent sigcontext reuse.
not yet tested on landisk, sparc, *88k, socppc.
ok kettenis


# 1.243 20-Apr-2016 dlg

pool_setipl for floating point context things

ok kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.242 21-Oct-2015 mpi

Do not call uvm_swap_finicrypt_all() a second time in dumpsys().

ok tedu@, deraadt@, miod@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.241 20-Jan-2015 kettenis

Move ps_strings "after" the random stackgap. This makes its location a
per-process value, and therefpore turns the VM_PSSTRINGS sysctl into a
per-process one as well. This gets rid of a pointer to the bottom of the
stack at a fixed location. Also clears the road for unmapping the stackgap.

ok deraadt@


# 1.240 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.239 25-Oct-2014 kettenis

Remove vmmap; it isn't used.

ok jsing@


# 1.238 23-Oct-2014 miod

Correctly set up the HPMC trap entry: according to the PA-RISC Firmware
Architecture Reference Specification, the sum of the 8 trap entry words
*and* of the payload which address and length are to be set at well-known
positions in the aforementioned trap entry, needs to be zero; the existing
code was only enforcing that the sum of the trap entry words is zero.

This matches what Linux and NetBSD do.

ok kettenis@


# 1.237 23-Oct-2014 miod

Revert limiting physmem to 2GB; the culprit was likely in uvm and uvm has
changed a lot in the last 5 years; verified to work on a 3GB system, in
snapshots for a few weeks already.


# 1.236 22-Sep-2014 dlg

implement atomic_{cas,swap}_{uint,ulong,ptr} and
atomic_{add,sub}_{int,long}_nv. sys/atomic.h turns these into the
rest of the atomic api.

on uniprocessor hppa systems "atomic" operations are implemented
as a non-interruptable sequence by disabling all interrupts on the
cpu, doing the operation, and then restoring the interrupt mask.

this isnt enough on MP systems, so we added a global atomic memory
mutex that is taken inside the interrupt disabling above to coordinate
operations between cpus.

this is a lot of overhead though cos mutexes dance around with ipls,
which is unecessary in our case because of the interrupt disabling
that is already done. also, hppa spinlocks are implemented with
ldcw which requires the word it operates on to be 16 byte aligned.
mutexes arent guaranteed to have this alignment so they compensate
by having lots of words inside themselves so they can hit the
appropriate one to use for the ldcw op.

with this in mind, this change pulls __cpu_simple_locks, which are
simply ldcw spinlocks with a 16 byte aligned word, out of
src/sys/arch/hppa/include/lock.h into src/sys/arch/hppa/include/atomic.h
so atomic.h can use them. lock.h includes atomic.h, so it still
gets and provides the same functionality as before.

finally, this also pulls the rwlock cas implementation apart. cas
ops now share the same serialising lock on MP systems as the other
memory operations, and rw_cas is defined as a wrapper around
atomic_cas_uint.

ok kettenis@


# 1.235 19-Sep-2014 kettenis

Use config_suspend_all(9).


# 1.234 18-Aug-2014 dlg

dont rely on mbuf.h to provide pool.h.

ok miod@, who has offerred to help with any MD fallout
ok guenther@


Revision tags: OPENBSD_5_6_BASE
# 1.233 22-Jul-2014 uebayasi

boot(9): Reduce diffs between hppa & hppa64 (& others)


# 1.232 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.231 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.230 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.229 13-Jul-2014 miod

These still need <sys/reboot.h> for the RB_ constants.


# 1.228 12-Jul-2014 uebayasi

reboot(9), panic(9): Call panic(9) for unrecoverable MD H/W errors (NMIs)

Some architectures have ability to detect hardware sanity and notify system
(NMI, firmware callback, etc.). Handle these hardware severe errors, same
as software errors, with panic(9).

According to miod@, SGI IP27 NMI is triggered by pushing some "hidden" button,
which "usual" users/admins don't know. Pushing such a button is "RB_USERREQ"
(human-triggered) in that the button is pushed by a human, but not "RB_USERREQ"
in that no user intervention in system (== no command input) is done. miod@
agreed that changing these from RB_USERREQ to !RB_USERREQ (== panic(9)) is
not a big problem.

OK miod@ kettenis@


# 1.227 12-Jul-2014 uebayasi

boot(9), reboot(9): Migrate MD callers of boot(9) to reboot(9)

I have found that some ports call boot(9) from machine-dependent code to
reboot system. These should be changed to either:

- Sending signal to init(8) to trigger it to shutdown system cleanly, like
acpi(4) does, in cases where found problems don't prevent system from working
immediately, or

- Just doing panic(9) if the situation is severely broken.

For now, just rewrite boot() to reboot(). Actual fixes follow.

Discussed with & OK from kettenis@


# 1.226 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.225 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.224 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.223 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.222 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.221 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.220 08-May-2014 miod

Format string fixes and removal of -Wno-format for hppa kernels.


# 1.219 08-Apr-2014 mpi

Less <uvm/uvm.h>


# 1.218 04-Apr-2014 miod

If the PDC_COPROC call fails, and we are running on a PA 1.1 system, assume
the usual 1.1 coprocessor mask, instead of using zero and having every
userland process dying with signal 4.

The circumstances under which this call fails are unclear and could be
tied to specific PROM version (I have tried overzealous stack alignment and
other tricks, to no avail). Interestingly enough, the 715/75 system which
hits this problem, only triggers it when booting from disk, and never when
booting from network.

This diff is an ugly bandaid until the problem is better understood. Or maybe
it is not worth investigating, seeing that Linux hardcodes the coprocessor
mask and never issues PDC_COPROC calls; I wonder what HP/UX does.

In my tree for over 18 months; "Looks like a nice hack" deraadt@
715/75 system provided by Sebastiaan Indesteege, thanks!


# 1.217 29-Mar-2014 guenther

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

ok dlg@ mpi@ deraadt@


# 1.216 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


# 1.215 22-Mar-2014 guenther

Move p_sigacts from struct proc to struct process.

testing help mpi@


# 1.214 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


Revision tags: OPENBSD_5_5_BASE
# 1.213 23-Nov-2013 uebayasi

Run doshutdownhooks() and config_suspend() even when boot() is called while
cold != 0. Indent and make hppa/hppa64 boot() closer to others.

OK kettenis@


# 1.212 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


Revision tags: OPENBSD_5_4_BASE
# 1.211 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


Revision tags: OPENBSD_5_3_BASE
# 1.210 02-Dec-2012 guenther

Determine whether we're currently on the alternative signal stack
dynamically, by comparing the stack pointer against the altstack
base and size, so that you get the correct answer if you longjmp
out of the signal handler, as tested by regress/sys/kern/stackjmp/.
Also, fix alt stack handling on vax, where it was completely broken.

Testing and corrections by miod@, krw@, tobiasu@, pirofti@


# 1.209 26-Oct-2012 kettenis

Properly clear trap frame in setregs() to avoid leaking registers across exec.

ok jsing@


# 1.208 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.207 07-Oct-2012 kettenis

Align the stack on a 64-byte boundary as required by "The 32-bit PA-RISC
Run-time Architecture Document". GCC relies on this to properly align
stack variables.

ok guenther@, beck@


Revision tags: OPENBSD_5_2_BASE
# 1.206 21-Jun-2012 guenther

__tfork() needs to set the stack address of the new thread in the kernel,
so that it can't get a signal while still running on the parent thread's
stack. Also, pass in sizeof(struct __tfork) to provide forward compat
when more members are added. This is an ABI change, so switch syscall
numbers and bump lib majors this time.

ok deraadt@ matthew@


Revision tags: OPENBSD_5_1_BASE
# 1.205 20-Sep-2011 miod

Clear RB_POWERDOWN early in boot() on systems which can not powerdown and
which firmware does not send spin up commands to the disks, in case the
operator changes his mind and reboots instead of manually powering down
after the system has halted.
ok kettenis@


Revision tags: OPENBSD_5_0_BASE
# 1.204 05-Jul-2011 guenther

Recommit the reverted sigacts change now that the NFS use-after-free
problem has been tracked down. This fixes the sharing of the signal
handling state: shared bits go in sigacts, per-rthread bits goes in
struct proc.

ok deraadt@


# 1.203 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.202 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.201 18-Apr-2011 guenther

Revert the sigacts diff: NFS can apparently retain pointers to processes
until they're zombies and then send them signals (for intr mounts). Until
that is untangled, the sigacts change is unsafe. sthen@ was the victim
for this one


# 1.200 15-Apr-2011 guenther

Correct the sharing of the signal handling state: stuff that should
be shared (p_sigignore, p_sigcatch, P_NOCLDSTOP, P_NOCLDWAIT) moves
to struct sigacts, wihle stuff that should be per rthread (ps_oldmask,
SAS_OLDMASK, ps_sigstk) moves to struct proc. Treat the coredumping
state bits (ps_sig, ps_code, ps_type, ps_sigval) as per-rthread
until our locking around coredumping is better.

Oh, and remove the old SunOS-compat ps_usertramp member.

"I like the sound of this" tedu@


Revision tags: OPENBSD_4_9_BASE
# 1.199 14-Jan-2011 jsing

Halt secondary CPUs when shutting down or rebooting. This should prevent
occasional hangs during reboot.

ok kettenis@


# 1.198 04-Jan-2011 jasper

- de-register. no binary change.

ok jsing@


# 1.197 01-Jan-2011 jasper

Move setting cpu_hzticks to the clock initialization function, like
other ports (e.g. hppa64) do.

ok jsing@ kettenis@


# 1.196 01-Jan-2011 jasper

- ansify

ok jsing@ kettenis@


# 1.195 30-Dec-2010 jsing

Turn signotify() into a function that also calls cpu_unidle().

ok kettenis@


# 1.194 20-Nov-2010 miod

This is a first step towards getting rid of avail_start and avail_end in the
kernel, currently limited to low-hanging fruit: these variables were used
by bus_dma to specify the range in which to allocate memory, back when
uvm_pglistalloc() was stupid and would not walk the vm_physseg[].

Nowadays, except on some platforms for early initialization, these variables
are not used, or do not need to be global variables. Therefore:
- remove `extern' declarations of avail_start and avail_end (or close cousins,
such as arm physical_start and physical_end) from files which no longer need
to use them.
- make them local variables whenever possible.
- remove them when they are assigned to but no longer used.


Revision tags: OPENBSD_4_8_BASE
# 1.193 01-Jul-2010 jsing

Create a struct to store FP state and include a pointer to the CPU that
currently holds the FPU context for this process. This will be soon used
to implement FPU shootdowns on multiprocessor kernels.

ok kettenis@


# 1.192 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.191 29-Jun-2010 jsing

Factor out code used to save and flushe process FPU context.

ok kettenis@


# 1.190 29-Jun-2010 jsing

Store pointer to process FPU state in struct cpu_info.

ok kettenis@


# 1.189 27-Jun-2010 thib

uvm constraints. Add two mandatory MD symbols, uvm_md_constraints
which contains the constraints for DMA/memory allocation for each
architecture, and dma_constraints which contains the range of addresses
that are dma accessable by the system.

This is based on ariane@'s physcontig diff, with lots of bugfixes and
additions the following additions by my self:

Introduce a new function pool_set_constraints() which sets the address
range for which we allocate pages for the pool from, this is now used
for the mbuf/mbuf cluster pools to keep them dma accessible.

The !direct archs no longer stuff pages into the kernel object in
uvm_km_getpage_pla but rather do a pmap_extract() in uvm_km_putpages.

Tested heavily by my self on i386, amd64 and sparc64. Some tests on
alpha and SGI.

"commit it" beck, art, oga, deraadt
"i like the diff" deraadt


# 1.188 27-Jun-2010 jsing

Use a mutex to make atomic operations atomic on multiprocessor kernels.

ok kettenis@


# 1.187 10-Jun-2010 deraadt

Declare safepri at the MD level on each platform, so that the kern_synch.c
does not have to deal with it as a common. Some platforms may be missed
by this commit... if you spot one, fix it the same way.
ok miod


# 1.186 09-Jun-2010 miod

Move declaration of cn_tab from dev/cons.c to dev/cninit.c, or appropriate
md files for ports which do not use dev/cninit.c. This gets rid of a common
at kernel link time.
feedback drahn@ ok deraadt@


# 1.185 24-May-2010 deraadt

Add missing prototypes
ok jsing kettenis


# 1.184 09-May-2010 kettenis

Prevent "taken branch" exceptions from kernel space by clearing the PSL_T
bit before we enter a signal handler.

"if you say so" miod@, "seems to make sense" jsing@


# 1.183 02-May-2010 kettenis

Properly initialize the members of `struct mdproc' that deal with
single-stepping when we fork and reset them upon exec.

ok miod@


# 1.182 27-Apr-2010 kettenis

Avoid null-pointer dereference by giving proc0 a place to store its
floating-point registers. Pointed out by Nick Hudson.

ok miod@, jsing@


# 1.181 19-Apr-2010 jsing

Make the Processor Status Word (PSW) a per-CPU value.

ok kettenis@


# 1.180 01-Apr-2010 jsing

Allow for multiple CPUs by moving to an array of cpu_info.

ok kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.179 31-Dec-2009 jsing

Make cpl and cpu_inintr per CPU variables. For locore.S, cpl becomes an
offset within cpu_primary_info - this will need to be revisited shortly.

ok kettenis@


# 1.178 11-Aug-2009 miod

Do not bother initializing bufpages in the md code if the computation is
exactly the same the mi could will use if bufinit() is invoked with
bufpages == 0.


# 1.177 11-Aug-2009 miod

With the SysV memory allocation changes, allocsys() doesn't do anything
anymore. Get rid of it completely.


# 1.176 09-Aug-2009 blambert

Rototill system V message queues.

No longer allocate a static amount of memory for messages in MD
boot path; message queues, message metadata, and message data now
all use dynamic memory, which means that runtime sysctls should now
be trivial to implement.

Since I'm going to be around all week to fix any breakage, this should
probably just go in now.


# 1.175 02-Aug-2009 beck

Dynamic buffer cache support - a re-commit of what was backed out
after c2k9

allows buffer cache to be extended and grow/shrink dynamically

tested by many, ok oga@, "why not just commit it" deraadt@


# 1.174 29-Jul-2009 kettenis

Get rid of non-equivalent aliases of the pcb by moving the fpu state out
of the pcb and using the p_addr member of 'struct proc' to calculate the
address of the kernel stack when switching to virtual mode after taking a trap.
Remove the now unecessary cache flushes; they're actually harmful since they
create non-equivalent aliases. This seems to fix the memory corruption we
have been observing from time to time.

This diff does not rename fpu_curpcb, which is now somewhat incorrectly named.
I hope to change things back again as soon as we are able to map the pcb 1:1.


Revision tags: OPENBSD_4_6_BASE
# 1.173 15-Jun-2009 beck

Back out all the buffer cache changes I committed during c2k9. This reverts three
commits:

1) The sysctl allowing bufcachepercent to be changed at boot time.
2) The change moving the buffer cache hash chains to a red-black tree
3) The dynamic buffer cache (Which depended on the earlier too).

ok on the backout from marco and todd


# 1.172 03-Jun-2009 beck

add kern.bufcachepercent sysctl to allow adjusting the buffer cache
size on a running system.
ok art@, oga@


Revision tags: OPENBSD_4_5_BASE
# 1.171 14-Feb-2009 kettenis

Limit the amount of physical memory to 2GB. Using more causes memory
corruption on PA-RISC 2.0 systems (and there are very few PA-RISC 1.1
systems that support more than 2GB).

ok miod@


# 1.170 04-Feb-2009 miod

On systems with split BTLB, do not bother trying to insert DBTLB entries,
as PDC will lie to us pretending it did while it didn't.

ok kettenis@


# 1.169 04-Feb-2009 miod

Unify memory size reports a bit more: always report size in MB, and report
reserved memory on alpha and hppa on its own line (as done on sgi).


Revision tags: OPENBSD_4_4_BASE
# 1.168 14-Jul-2008 miod

Be sure to propagate PSL_O in psw on PCXU* processors to userland processes
and signal handlers.
ok kettenis@


# 1.167 27-Jun-2008 miod

Clear swap encryption keys before dumping a kernel image.


# 1.166 09-Apr-2008 deraadt

Add new stub uvm_shutdown() and call it from the right place in MD boot()


Revision tags: OPENBSD_4_3_BASE
# 1.165 22-Sep-2007 martin

replace even more ctob and btoc with ptoa and atop respectively plus
uvm_extern.h where needed


Revision tags: OPENBSD_4_2_BASE
# 1.164 22-Jul-2007 kettenis

Move hppa to __HAVE_TIMECOUNTERS.


# 1.163 20-Jul-2007 kettenis

Give hppa the blink_led API from sparc64, and the associated machdep.led_blink
sysctl.


# 1.162 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.161 14-Jul-2007 kettenis

Make sigreturn(2) set the proper space ID for the instruction queue. Fixes
a few more pthreads regression tests.

ok miod@


# 1.160 10-Jul-2007 kettenis

Don't trust the privilige level in the sigcontext passed to sigreturn(2).

ok miod@


# 1.159 24-Jun-2007 kettenis

Crank initial storage for extents a bit. We really should allocate extents
using malloc once vm is initialised, but this will do for now.

ok deraadt@


# 1.158 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.157 27-May-2007 miod

Make sure the minaddr hint for uvm_km_suballoc() calls is always initialized.
ok pedro@


# 1.156 26-May-2007 pedro

Dynamic buffer cache. Initial diff from mickey@, okay art@ beck@ toby@
deraadt@ dlg@.


# 1.155 21-May-2007 kettenis

Add support for 8700/pcxw2 cpu.


# 1.154 21-May-2007 kettenis

Ask firmware for reset before trying ourselves; needed for four-digit b/c/j
workstations.

tested by otto@, krw@; ok deraadt@


# 1.153 17-May-2007 art

Limit hppa buffer cache to 30%. It used to be 70% because stack garbage
that was used for minaddr instead of the proper vm_map_min(kernel_map)
(fixed in this diff).

From mickey. art@ ok


# 1.152 14-May-2007 martin

move hppa to __HAVE_CPUINFO

input from miod@, ok kettenis@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.151 28-May-2006 martin

minor nit, use CPU ID instead of FPU ID for BTLB parameters after passing
all kludges


# 1.150 15-Apr-2006 martin

make warning about missing HPT support DEBUG for now

ok mickey@


Revision tags: OPENBSD_3_9_BASE
# 1.149 26-Oct-2005 martin

no more hppa_round_page() and hppa_trunc_page() macros

ok mickey@


Revision tags: OPENBSD_3_8_BASE
# 1.148 06-Aug-2005 miod

We do not need a char machine_arch[] constant.
ok deraadt@


# 1.147 11-Jul-2005 mickey

align some stupid comments


# 1.146 10-May-2005 mickey

set pcsq in case we get signal delivery once interrupted from the gateway page; from chs


# 1.145 18-Apr-2005 mickey

do not do some of the initmsgbuf()s job


# 1.144 07-Apr-2005 mickey

on some machines it's possible to limit the amount of physmem initialised dring post so having msgbuf at the end of memory shall work


# 1.143 07-Apr-2005 mickey

64bit-friendly pdc.h and iomod.h and correspondent changes elsewhere


# 1.142 26-Mar-2005 mickey

md parts for hpux_compa code; some problems w/ signals delivery still exist


Revision tags: OPENBSD_3_7_BASE
# 1.141 24-Feb-2005 mickey

do not even ask for btlb on 8k cpus as pdc pretends there is some but then it does not work; found w/ Moritz Kiese <mbk@mytum.de> on c180; add a debug print and fix pcxu entry


# 1.140 17-Nov-2004 mickey

print real/avail/bufcache sizes as unsigned


# 1.139 26-Oct-2004 mickey

disable sid hashing on pcxu and above


# 1.138 14-Oct-2004 mickey

a bit larger delays during boot() to let msgs appear


# 1.137 19-Sep-2004 mickey

turn totalphysmem into physmem and name old physmem into smth it really is


# 1.136 18-Sep-2004 mickey

oops


# 1.135 15-Sep-2004 mickey

add pcxu tlb handlers and cpu probing
add u2/uturn ioa driver in dumb mode now
enable pcxu/pcxw support


# 1.134 14-Sep-2004 mickey

store fpu version for later use. make sure to proper store/clear fpu state in fork/exec/exit/sendsig


# 1.133 14-Sep-2004 mickey

error out from btlb_insert() if there is none


Revision tags: OPENBSD_3_6_BASE
# 1.132 01-Jul-2004 mickey

have separate insn and data cache all-flushers


# 1.131 30-Jun-2004 mickey

allow forced fpu emulation through a sysctl


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.130 13-May-2004 mickey

8ks do not have hvt


# 1.129 05-May-2004 mickey

much easier tlb handler branch patching


# 1.128 05-May-2004 mickey

do not engage HPT on PCXT' (yet)


# 1.127 08-Apr-2004 mickey

repair pcxs/t confoosion


# 1.126 07-Apr-2004 mickey

update copyright; miod@ is fine w/ files where he holds it too


Revision tags: OPENBSD_3_5_BASE
# 1.125 10-Mar-2004 tom

Ensure that we obey a user's ddb> boot reboot command even if the system
is cold (during startup).

This adds RB_USERREQ to sys/reboot.h, uses it in the ddb commands, and
ensures that */*/machdep.c:boot() won't set RB_HALT when cold if this
flag is set.

ok deraadt@


# 1.124 14-Feb-2004 grange

Simplify hw.{cpuspeed,setperf} api moving all the sysctl stuff
from the underlying callbacks.

Testing hppa mickey@, ppc drahn@
Ok markus@ tedu@


# 1.123 05-Jan-2004 mickey

kill debugging code that is not needed anymore


# 1.122 23-Dec-2003 mickey

provide cpuspeed fluff


# 1.121 20-Dec-2003 miod

Don't let microtime() return a struct timeval with exactly 1000000 microseconds.


# 1.120 18-Dec-2003 mickey

spls do not protect cpu_itmr and thus time might jump back sometimes due to cpu_itmr modified to a higher value than a read itmr; found and testing by miod@


# 1.119 17-Dec-2003 mickey

in the real mem print do not include reserved for prom into used by openbsd


# 1.118 10-Dec-2003 mickey

for unaligned btlb mapping attempts -- just fail


# 1.117 24-Nov-2003 mickey

experimental support for HVT as a 2nd level tlb


# 1.116 15-Oct-2003 mickey

less global name space pollution


# 1.115 05-Oct-2003 mickey

reload the itmr as soon as we get the intr to avoid lagging on slower machines


# 1.114 25-Sep-2003 mickey

some pcxl2 do not report fpus -- assume it's there


Revision tags: OPENBSD_3_4_BASE
# 1.113 04-Sep-2003 mickey

a better cpu identification; testing by miod


# 1.112 31-Aug-2003 miod

pdc_model needs to be visible from cpu.c


# 1.111 20-Aug-2003 mickey

missing nl in debugging prontf


# 1.110 07-Aug-2003 mickey

dead proto


# 1.109 07-Aug-2003 mickey

first allocate space on stack then copyout signal shits. add a DEBUG check for a whacky user pc (as impossible due to the recent trap.c change)


# 1.108 03-Aug-2003 mickey

clear branch and nullify bits in psw on sending a signal


# 1.107 30-Jul-2003 mickey

deduce the leds address from the model number and thus make some more use of that lichtenblinkenschmutz on some more machinens


# 1.106 22-May-2003 mickey

imprecision in delay_init()


# 1.105 18-May-2003 mickey

save the fpu state for the signal handler. this is essential
as the fpu regs can be used by the gcc even for non-fpu
means and data copying.
rearrange the sigcontext a bit to include only the general
registers that are needed restoring upon return and thus
less waste of space and make up some space for the fpu regs.

ALL software that used the signal context on the stack
needs at least rebuilding now. a new snap has bin built as well.


Revision tags: UBC_SYNC_A
# 1.104 11-May-2003 deraadt

string cleaning; krw ok


# 1.103 07-Apr-2003 mickey

s/HP9000/HP 9000/; from weissmanndude


Revision tags: OPENBSD_3_3_BASE
# 1.102 18-Feb-2003 deraadt

knf; mickey ok


# 1.101 12-Feb-2003 jason

How uncommon... hppa only has one common: msgbufmapped (decl'd in /sys/kern)


# 1.100 12-Feb-2003 mickey

only align the first stack frame onto the minimal required alignment


# 1.99 10-Feb-2003 mickey

fix pcs and pcxt recognition. from weissmanndude


# 1.98 22-Jan-2003 mickey

consistantly use uvm_prot_* vs vm_prot_* evewrhere


# 1.97 14-Jan-2003 mickey

fix cutnpaste in the cpu table for the itlbna field; from herr weissmanndude


# 1.96 14-Jan-2003 mickey

need pdc_hwtlb always; pt out by herr weissmanndude


# 1.95 13-Jan-2003 mickey

fix the logic in hvt probing


# 1.94 09-Jan-2003 miod

Remove fetch(9) and store(9) functions from the kernel, and replace the few
remaining instances of them with appropriate copy(9) usage.

ok art@, tested on all arches unless my memory is non-ECC


# 1.93 19-Dec-2002 mickey

setregs: put the whole frame setup into one place


# 1.92 19-Dec-2002 mickey

level 0x16 is really an l2


# 1.91 17-Dec-2002 millert

Make SysV-style shared memory and semaphore limits sysctl'able.
Instead of allocating a static amount of memory for the data
structures via valloc() in allocsys(), allocate things dynamically
using pool(9) when possible and malloc(9) when not. The various
members of struct seminfo and struct shminfo are in kern.seminfo
and kern.shminfo respectively (not all members of kern.seminfo are
changable).

The data structures used still leave something to be desired but
things are not made worse in that respect by this commit.


# 1.90 27-Nov-2002 mickey

no wrapper arounf hardclock(), use CPU_CLOCKUPDATE, real microtime; miod ok


# 1.89 08-Nov-2002 mickey

Don't uvm_useracc the user sigcontext in sys_sigreturn and then access
the user addresses directly from the kernel. copyin is faster and can
correctly deal properly with mappings that uvm_useracc thinks are
correct but will fault anyway (to figure out how to generate such
mappings is left as en excercise for the reader).


# 1.88 01-Nov-2002 mickey

add a missing delay after printf on halt[-p], proper arg for a cold hook


Revision tags: UBC_SYNC_B
# 1.87 22-Oct-2002 mickey

do not force single-user; pt out by fries@


# 1.86 15-Oct-2002 mickey

missing initmsgbuf(), noticed by miod@


# 1.85 13-Oct-2002 mickey

track the end of physmem for use in dmmem_alloc


# 1.84 07-Oct-2002 mickey

s/PSW_/PSL_/ to match other archs


# 1.83 07-Oct-2002 mickey

proper terminate the user stack on signal


# 1.82 07-Oct-2002 mickey

on implementations w/ fpu included unimplemented instructions
are signaled through the exception trap w/ invalid opcode marked
instruction in the exception registers, not through the emulation
trap (as long as the fpu is enabled, of course).
parse emulation from the exception trap as well as the emulation
trap and fix the dispatcher into usable condition.
parse invalid op exception on trap and signal the user appropriately.
reset the exception on exec and for child on fork.
the later is appropriate since exceptions are delayed until next
fpu instruction, which was in the parent indeed, let him get it.
save parent's fpu context on fork before cipying it, if the
parent owned the fpu.


Revision tags: OPENBSD_3_2_BASE
# 1.81 23-Sep-2002 mickey

parisc level 0x10 is just an overclocked 0xe


# 1.80 17-Sep-2002 mickey

handle fpu exceptions properly, might use a regress, i guess


# 1.79 11-Sep-2002 mickey

provide a convinient reset label


# 1.78 11-Sep-2002 mickey

stack grows the other way, but the frame is the other way to that. hehe


# 1.77 09-Sep-2002 mickey

set up the frame flags and a user frame better on exec


# 1.76 03-Aug-2002 mickey

rework boot() w/o a goto


# 1.75 25-Jul-2002 mickey

missing arg in the call to the pdc_call since some old times


# 1.74 25-Jul-2002 mickey

kcopy is a space-to-space copy from kernel space, to guess where, -- to the same kernel space, just error on fault


# 1.73 20-Jul-2002 art

Instead of copying out the signal trampoline on top of the stack, create
an uvm aobj, copy out the signal trampoline into it and share that page
among all processes for the same emulation.

This also requires us to actually be able to tell signal code where the
trampoline is located, so introduce a new field in struct proc - p_sigcode
that is a pointer to sigcode. This allows us to remove all the ugly
calculations of the signal trampoline address done in every sendsig
function in the tree (that's why so many files are changed).

Tested by various people. ok deraadt@


# 1.72 14-May-2002 mickey

disable sid hashing while still in real mode, alos print the parisc arch once and not per each cpu since they are not intermixable architecture-wise


# 1.71 13-May-2002 mickey

ldi-ldo whatever was in the table, be that much clever


# 1.70 08-May-2002 mickey

print parisc level w/ the the parisc version, not for each cpu


# 1.69 08-May-2002 mickey

kill debugging printfski


# 1.68 22-Apr-2002 mickey

no longer batc the data, only the code.
this removes a constraint and an ld.script dependancy
for the .data and the dynamically allocated kernel
structures existed w/ batcing. also makes pmap_steal_memory
obsolete and replaced w/ the pmap_virtual_space.
implement batching for pmap_remove to avoid
zeroing out the pte entries if pde will be removed anyway.


# 1.67 21-Apr-2002 mickey

better buf's mapping and less magic constants in checking for io space cachability


Revision tags: OPENBSD_3_1_BASE
# 1.66 26-Mar-2002 mickey

if cannot guess cpu model default to the lowest supported one


# 1.65 25-Mar-2002 deraadt

spelling


# 1.64 23-Mar-2002 espie

Add variables for config(8) -e time tweak of systemV shared memory
parameters.

Ok millert@, miod@, maja@


# 1.63 19-Mar-2002 mickey

mtcpu seq requires a pre-sync, implement hpt init for pcxl


# 1.62 15-Mar-2002 mickey

rewrite a pmap to use multilevel page tables.
lower 12 bits contain the perms, no unused bits left,
but a couple for off-tlb use (as the ref implemented now).
do not use the hvt, which might get some use later
if proven to speed thigs up, tlb handlers would po
another dozen of insns though, but if that's worth its...
move on the data seg and map kernel text rdonly (idea form fredette),
since all of the page0 mods done before that we are all fine
except for some viper fluff, but later w/ that.
this also picks up a bit more of ddb magic for bpt and ss.
tlb handlers can use a little bit more of attention,
but things, visually, seem to be much faster already, --
sorry, no benchmarks for now.

* effort sponsored in part by the `henry st. old ale house'
* and mr.pete and mr.lee in particular in thier generous entrirety.
* the proj took a little more that 72man*h as it was expected,
* but within murhy's law estimations.


# 1.61 14-Mar-2002 millert

First round of __P removal in sys


# 1.60 20-Feb-2002 mickey

setup power failure handler (for sw-controlled power button), move toc handler


# 1.59 17-Feb-2002 maja

Patch from Daniel Lucq <daniel@lucq.org>

The patch allows you to change the value of NMBCLUSTERS, BUFCACHEPERCENT
and NKMEMPAGES using the config command, instead of recompiling the kernel.

This is the kernel part of the patch. I have compiled it on i386, sparc64,
alpha and macppc. -moj ok art@ maja@


# 1.58 12-Feb-2002 mickey

support 712's programmable power switch, no interrupt yet


# 1.57 12-Feb-2002 mickey

small repairs to hpmc and toc handlers


# 1.56 11-Feb-2002 mickey

disable fpu on csw, print fpu version on cpu line, if present


# 1.55 07-Feb-2002 mickey

fix sigdebug cases; init sigcontext before it's used (;


# 1.54 06-Feb-2002 mickey

implement signal delivery; based on fredette@'s work


# 1.53 03-Feb-2002 mickey

restore hpt size computation, does not break things as i thought


# 1.52 02-Feb-2002 mickey

fix 'physmem' usage


# 1.51 02-Feb-2002 mickey

implement the rest of /dev/mem devices; from netbsd


# 1.50 23-Jan-2002 art

move mb_map allocation to mbinit()


# 1.49 23-Jan-2002 art

move definition of mb_map from zillions of machdep.c to uipc_mbuf.c


# 1.48 16-Jan-2002 miod

Don't include <sys/map.h> when you don't need what's in it.


Revision tags: UBC_BASE
# 1.47 02-Dec-2001 mickey

branches: 1.47.2;
increase fixed extent storage


# 1.46 28-Nov-2001 art

zap some typedefs.
vm_map_t -> struct vm_map *
vm_map_entry_t -> struct vm_map_entry *
simple_lock_data_t -> struct simplelock

(uvm not done yet, coming in the next commit)


# 1.45 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.44 24-Nov-2001 miod

Harmonize boot() logic across arches:
- ensure RB_DUMP | RB_HALT will cause a dump
- or RB_HALT if (cold)
While there, honor RB_TIMEBAD on sparc64.


# 1.43 09-Nov-2001 art

nswbuf hasn't been used for ages. gc.


# 1.42 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.41 06-Nov-2001 miod

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


Revision tags: OPENBSD_3_0_BASE
# 1.40 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.39 12-Sep-2001 art

mbutl no more


# 1.38 23-Aug-2001 art

We can now move timeout_init into main().


# 1.37 23-Aug-2001 art

Remove even more old timeout tentacles.


# 1.36 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.35 05-Jul-2001 art

Get rid of REAL_CLISTS. It was never implemented and the tentacles are
everywhhere.


# 1.34 17-May-2001 provos

convert mbuf and cluster allocation to pool, mostly from NetBSD
okay art@ miod@


# 1.33 05-May-2001 art

Rename configure() to cpu_configure().
Move it from cpu_startup() to main().


# 1.32 05-May-2001 art

Get rid of CLSIZE and all related stuff.
CLSIZE -> 1
CLBYTES -> PAGE_SIZE
OLOFSET -> PAGE_MASK
etc.
At the same time some archs needed some cleaning in vmparam.h so that
goes in at the same time.


Revision tags: OPENBSD_2_9_BASE
# 1.31 29-Mar-2001 mickey

cpudev_data.h here needed not


# 1.30 22-Mar-2001 mickey

shuffle the tlb handlers a little,
make a new one for na data fault,
since those w/ hpt need it.


Revision tags: OPENBSD_2_8_BASE
# 1.29 15-Aug-2000 mickey

two btlb routines (i & d) for pcxs


# 1.28 15-Aug-2000 mickey

expand per-cpu control routines switch


# 1.27 08-Aug-2000 mickey

print btlb params w/ BTLBDEBUG; from Havard.Eidnes@runit.sintef.no


# 1.26 02-Jul-2000 mickey

no bays for stinger


Revision tags: OPENBSD_2_7_BASE
# 1.25 23-Mar-2000 mickey

new cpu type switch code.
initializes tlb miss handlers correspondent to probed cpu features.
also btlb load routine.
versions written are for pcxl and others.
cpu-dep btlb loaders are missing, only generic for now.


# 1.24 23-Mar-2000 art

New API for timeouts. Replaces the old timeout()/untimeout() API and
makes it the callers responsibility to allocate resources for the
timeouts.

This is a KISS implementation and does _not_ solve the problems of slow
handling of a large number of pending timeouts (this will be solved in
future work) (although hardclock is now guarateed to take constant time
for handling of timeouts).

Old timeout() and untimeout() are implemented as wrappers around the new
API and kept for compatibility. They will be removed as soon as all
subsystems are converted to use the new API.


# 1.23 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


# 1.22 22-Feb-2000 mickey

blah, blah, blah, msgbuf


Revision tags: SMP_BASE
# 1.21 09-Feb-2000 mickey

branches: 1.21.2;
heartbeat -- yeah we have a patch for that


# 1.20 25-Jan-2000 mickey

better copy and zero inlines in locore;
proper setregs() in machedep;
start of hpmc handler;
some cleanup here and there;


# 1.19 17-Jan-2000 mickey

remove unneeded stuff from setregs; force single-user for now, enable signal debug


# 1.18 11-Jan-2000 mickey

s/fpu_curproc/fpu_curpcb/ which also points into physical.
move it's definition into locore (where it's used the most).
adjust fpu context switch and save on swapout accordingly.
fix context save (in switch).
add accounting for fpu context switches (since it differes
from proc switching, we might get provided w/ some usefull
numbers as to how effective this lazy switch technique is).
enable handling fpu/sfu exceptions.


# 1.17 31-Dec-1999 mickey

don't bother about pidr3 and pidr4


# 1.16 17-Dec-1999 mickey

fix the panic message for sti memory mapping


Revision tags: kame_19991208
# 1.15 25-Nov-1999 mickey

bus stuff is in mainbus now, the rest is rewritten many ways


Revision tags: OPENBSD_2_6_BASE
# 1.14 20-Sep-1999 mickey

fix uvm_pagealloc() call


# 1.13 03-Sep-1999 art

Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.12 14-Aug-1999 mickey

proper debugging ifdefs


# 1.11 21-Jul-1999 mickey

rewrite the tlb miss handler and tlb dirty handler.
optimize for HVT usage (when compiled for proper cpu type).
drop hpt_* global variables, use info from control registers instead.
there are still ways to improve the tlb handlers tho.
machdep also prints cache and tlb coherence states (not related to the above).
You eat greenish muffin. --More-- You write real code.


# 1.10 12-Jul-1999 mickey

allocate 5% bufcache if <=16M memory installed


# 1.9 12-Jun-1999 mickey

hppa_init() now takes an argument from locore,
meaning the start of available memory.
cleanup machdep somewhat.
fix vm_map.pmap vs vm_pmap isue; 10x art@


# 1.8 23-May-1999 mickey

new swap stuff


# 1.7 21-May-1999 mickey

group all theMD f;ags together, add interrupt recursion one


# 1.6 21-May-1999 mickey

define fpu_curproc


# 1.5 20-Apr-1999 mickey

do lazy blok mapping of io space in bus_*
add copy{in,out}*, kcopy, etc
boot routines
cpu-id-hpux-compat stuff
rest of scheduler and such
uvm


Revision tags: OPENBSD_2_5_BASE
# 1.4 17-Feb-1999 mickey

print pa-risc here as well, since, finally, cpu will have to print processor type


# 1.3 04-Jan-1999 mickey

better cache handling in bus_space_barrier(), seem to work now


# 1.2 03-Jan-1999 mickey

implement bus_space_{un,}map w/ extents


# 1.1 30-Dec-1998 mickey

machdep; more work needed


# 1.251 12-Apr-2018 deraadt

Implement MAP_STACK option for mmap(). Synchronous faults (pagefault and
syscall) confirm the stack register points at MAP_STACK memory, otherwise
SIGSEGV is delivered. sigaltstack() and pthread_attr_setstack() are modified
to create a MAP_STACK sub-region which satisfies alignment requirements.
Observe that MAP_STACK can only be set/cleared by mmap(), which zeroes the
contents of the region -- there is no mprotect() equivalent operation, so
there is no MAP_STACK-adding gadget.
This opportunistic software-emulation of a stack protection bit makes
stack-pivot operations during ROPchain fragile (kind of like removing a
tool from the toolbox).
original discussion with tedu, uvm work by stefan, testing by mortimer
ok kettenis


Revision tags: OPENBSD_6_3_BASE
# 1.250 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.249 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


Revision tags: OPENBSD_6_2_BASE
# 1.248 18-May-2017 kettenis

Implement copyin32(9).

"your chicken scratches look fine to me" deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.247 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

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


# 1.246 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.245 21-May-2016 deraadt

hand-massage sendsig() and sys_sigreturn() to be much more similar.
ok guenther kettenis


# 1.244 10-May-2016 deraadt

SROP mitigation. sendsig() stores a (per-process ^ &sigcontext) cookie
inside the sigcontext. sigreturn(2) checks syscall entry was from the
exact PC addr in the (per-process ASLR) sigtramp, verifies the cookie,
and clears it to prevent sigcontext reuse.
not yet tested on landisk, sparc, *88k, socppc.
ok kettenis


# 1.243 20-Apr-2016 dlg

pool_setipl for floating point context things

ok kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.242 21-Oct-2015 mpi

Do not call uvm_swap_finicrypt_all() a second time in dumpsys().

ok tedu@, deraadt@, miod@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.241 20-Jan-2015 kettenis

Move ps_strings "after" the random stackgap. This makes its location a
per-process value, and therefpore turns the VM_PSSTRINGS sysctl into a
per-process one as well. This gets rid of a pointer to the bottom of the
stack at a fixed location. Also clears the road for unmapping the stackgap.

ok deraadt@


# 1.240 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.239 25-Oct-2014 kettenis

Remove vmmap; it isn't used.

ok jsing@


# 1.238 23-Oct-2014 miod

Correctly set up the HPMC trap entry: according to the PA-RISC Firmware
Architecture Reference Specification, the sum of the 8 trap entry words
*and* of the payload which address and length are to be set at well-known
positions in the aforementioned trap entry, needs to be zero; the existing
code was only enforcing that the sum of the trap entry words is zero.

This matches what Linux and NetBSD do.

ok kettenis@


# 1.237 23-Oct-2014 miod

Revert limiting physmem to 2GB; the culprit was likely in uvm and uvm has
changed a lot in the last 5 years; verified to work on a 3GB system, in
snapshots for a few weeks already.


# 1.236 22-Sep-2014 dlg

implement atomic_{cas,swap}_{uint,ulong,ptr} and
atomic_{add,sub}_{int,long}_nv. sys/atomic.h turns these into the
rest of the atomic api.

on uniprocessor hppa systems "atomic" operations are implemented
as a non-interruptable sequence by disabling all interrupts on the
cpu, doing the operation, and then restoring the interrupt mask.

this isnt enough on MP systems, so we added a global atomic memory
mutex that is taken inside the interrupt disabling above to coordinate
operations between cpus.

this is a lot of overhead though cos mutexes dance around with ipls,
which is unecessary in our case because of the interrupt disabling
that is already done. also, hppa spinlocks are implemented with
ldcw which requires the word it operates on to be 16 byte aligned.
mutexes arent guaranteed to have this alignment so they compensate
by having lots of words inside themselves so they can hit the
appropriate one to use for the ldcw op.

with this in mind, this change pulls __cpu_simple_locks, which are
simply ldcw spinlocks with a 16 byte aligned word, out of
src/sys/arch/hppa/include/lock.h into src/sys/arch/hppa/include/atomic.h
so atomic.h can use them. lock.h includes atomic.h, so it still
gets and provides the same functionality as before.

finally, this also pulls the rwlock cas implementation apart. cas
ops now share the same serialising lock on MP systems as the other
memory operations, and rw_cas is defined as a wrapper around
atomic_cas_uint.

ok kettenis@


# 1.235 19-Sep-2014 kettenis

Use config_suspend_all(9).


# 1.234 18-Aug-2014 dlg

dont rely on mbuf.h to provide pool.h.

ok miod@, who has offerred to help with any MD fallout
ok guenther@


Revision tags: OPENBSD_5_6_BASE
# 1.233 22-Jul-2014 uebayasi

boot(9): Reduce diffs between hppa & hppa64 (& others)


# 1.232 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.231 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.230 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.229 13-Jul-2014 miod

These still need <sys/reboot.h> for the RB_ constants.


# 1.228 12-Jul-2014 uebayasi

reboot(9), panic(9): Call panic(9) for unrecoverable MD H/W errors (NMIs)

Some architectures have ability to detect hardware sanity and notify system
(NMI, firmware callback, etc.). Handle these hardware severe errors, same
as software errors, with panic(9).

According to miod@, SGI IP27 NMI is triggered by pushing some "hidden" button,
which "usual" users/admins don't know. Pushing such a button is "RB_USERREQ"
(human-triggered) in that the button is pushed by a human, but not "RB_USERREQ"
in that no user intervention in system (== no command input) is done. miod@
agreed that changing these from RB_USERREQ to !RB_USERREQ (== panic(9)) is
not a big problem.

OK miod@ kettenis@


# 1.227 12-Jul-2014 uebayasi

boot(9), reboot(9): Migrate MD callers of boot(9) to reboot(9)

I have found that some ports call boot(9) from machine-dependent code to
reboot system. These should be changed to either:

- Sending signal to init(8) to trigger it to shutdown system cleanly, like
acpi(4) does, in cases where found problems don't prevent system from working
immediately, or

- Just doing panic(9) if the situation is severely broken.

For now, just rewrite boot() to reboot(). Actual fixes follow.

Discussed with & OK from kettenis@


# 1.226 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.225 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.224 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.223 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.222 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.221 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.220 08-May-2014 miod

Format string fixes and removal of -Wno-format for hppa kernels.


# 1.219 08-Apr-2014 mpi

Less <uvm/uvm.h>


# 1.218 04-Apr-2014 miod

If the PDC_COPROC call fails, and we are running on a PA 1.1 system, assume
the usual 1.1 coprocessor mask, instead of using zero and having every
userland process dying with signal 4.

The circumstances under which this call fails are unclear and could be
tied to specific PROM version (I have tried overzealous stack alignment and
other tricks, to no avail). Interestingly enough, the 715/75 system which
hits this problem, only triggers it when booting from disk, and never when
booting from network.

This diff is an ugly bandaid until the problem is better understood. Or maybe
it is not worth investigating, seeing that Linux hardcodes the coprocessor
mask and never issues PDC_COPROC calls; I wonder what HP/UX does.

In my tree for over 18 months; "Looks like a nice hack" deraadt@
715/75 system provided by Sebastiaan Indesteege, thanks!


# 1.217 29-Mar-2014 guenther

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

ok dlg@ mpi@ deraadt@


# 1.216 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


# 1.215 22-Mar-2014 guenther

Move p_sigacts from struct proc to struct process.

testing help mpi@


# 1.214 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


Revision tags: OPENBSD_5_5_BASE
# 1.213 23-Nov-2013 uebayasi

Run doshutdownhooks() and config_suspend() even when boot() is called while
cold != 0. Indent and make hppa/hppa64 boot() closer to others.

OK kettenis@


# 1.212 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


Revision tags: OPENBSD_5_4_BASE
# 1.211 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


Revision tags: OPENBSD_5_3_BASE
# 1.210 02-Dec-2012 guenther

Determine whether we're currently on the alternative signal stack
dynamically, by comparing the stack pointer against the altstack
base and size, so that you get the correct answer if you longjmp
out of the signal handler, as tested by regress/sys/kern/stackjmp/.
Also, fix alt stack handling on vax, where it was completely broken.

Testing and corrections by miod@, krw@, tobiasu@, pirofti@


# 1.209 26-Oct-2012 kettenis

Properly clear trap frame in setregs() to avoid leaking registers across exec.

ok jsing@


# 1.208 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.207 07-Oct-2012 kettenis

Align the stack on a 64-byte boundary as required by "The 32-bit PA-RISC
Run-time Architecture Document". GCC relies on this to properly align
stack variables.

ok guenther@, beck@


Revision tags: OPENBSD_5_2_BASE
# 1.206 21-Jun-2012 guenther

__tfork() needs to set the stack address of the new thread in the kernel,
so that it can't get a signal while still running on the parent thread's
stack. Also, pass in sizeof(struct __tfork) to provide forward compat
when more members are added. This is an ABI change, so switch syscall
numbers and bump lib majors this time.

ok deraadt@ matthew@


Revision tags: OPENBSD_5_1_BASE
# 1.205 20-Sep-2011 miod

Clear RB_POWERDOWN early in boot() on systems which can not powerdown and
which firmware does not send spin up commands to the disks, in case the
operator changes his mind and reboots instead of manually powering down
after the system has halted.
ok kettenis@


Revision tags: OPENBSD_5_0_BASE
# 1.204 05-Jul-2011 guenther

Recommit the reverted sigacts change now that the NFS use-after-free
problem has been tracked down. This fixes the sharing of the signal
handling state: shared bits go in sigacts, per-rthread bits goes in
struct proc.

ok deraadt@


# 1.203 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.202 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.201 18-Apr-2011 guenther

Revert the sigacts diff: NFS can apparently retain pointers to processes
until they're zombies and then send them signals (for intr mounts). Until
that is untangled, the sigacts change is unsafe. sthen@ was the victim
for this one


# 1.200 15-Apr-2011 guenther

Correct the sharing of the signal handling state: stuff that should
be shared (p_sigignore, p_sigcatch, P_NOCLDSTOP, P_NOCLDWAIT) moves
to struct sigacts, wihle stuff that should be per rthread (ps_oldmask,
SAS_OLDMASK, ps_sigstk) moves to struct proc. Treat the coredumping
state bits (ps_sig, ps_code, ps_type, ps_sigval) as per-rthread
until our locking around coredumping is better.

Oh, and remove the old SunOS-compat ps_usertramp member.

"I like the sound of this" tedu@


Revision tags: OPENBSD_4_9_BASE
# 1.199 14-Jan-2011 jsing

Halt secondary CPUs when shutting down or rebooting. This should prevent
occasional hangs during reboot.

ok kettenis@


# 1.198 04-Jan-2011 jasper

- de-register. no binary change.

ok jsing@


# 1.197 01-Jan-2011 jasper

Move setting cpu_hzticks to the clock initialization function, like
other ports (e.g. hppa64) do.

ok jsing@ kettenis@


# 1.196 01-Jan-2011 jasper

- ansify

ok jsing@ kettenis@


# 1.195 30-Dec-2010 jsing

Turn signotify() into a function that also calls cpu_unidle().

ok kettenis@


# 1.194 20-Nov-2010 miod

This is a first step towards getting rid of avail_start and avail_end in the
kernel, currently limited to low-hanging fruit: these variables were used
by bus_dma to specify the range in which to allocate memory, back when
uvm_pglistalloc() was stupid and would not walk the vm_physseg[].

Nowadays, except on some platforms for early initialization, these variables
are not used, or do not need to be global variables. Therefore:
- remove `extern' declarations of avail_start and avail_end (or close cousins,
such as arm physical_start and physical_end) from files which no longer need
to use them.
- make them local variables whenever possible.
- remove them when they are assigned to but no longer used.


Revision tags: OPENBSD_4_8_BASE
# 1.193 01-Jul-2010 jsing

Create a struct to store FP state and include a pointer to the CPU that
currently holds the FPU context for this process. This will be soon used
to implement FPU shootdowns on multiprocessor kernels.

ok kettenis@


# 1.192 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.191 29-Jun-2010 jsing

Factor out code used to save and flushe process FPU context.

ok kettenis@


# 1.190 29-Jun-2010 jsing

Store pointer to process FPU state in struct cpu_info.

ok kettenis@


# 1.189 27-Jun-2010 thib

uvm constraints. Add two mandatory MD symbols, uvm_md_constraints
which contains the constraints for DMA/memory allocation for each
architecture, and dma_constraints which contains the range of addresses
that are dma accessable by the system.

This is based on ariane@'s physcontig diff, with lots of bugfixes and
additions the following additions by my self:

Introduce a new function pool_set_constraints() which sets the address
range for which we allocate pages for the pool from, this is now used
for the mbuf/mbuf cluster pools to keep them dma accessible.

The !direct archs no longer stuff pages into the kernel object in
uvm_km_getpage_pla but rather do a pmap_extract() in uvm_km_putpages.

Tested heavily by my self on i386, amd64 and sparc64. Some tests on
alpha and SGI.

"commit it" beck, art, oga, deraadt
"i like the diff" deraadt


# 1.188 27-Jun-2010 jsing

Use a mutex to make atomic operations atomic on multiprocessor kernels.

ok kettenis@


# 1.187 10-Jun-2010 deraadt

Declare safepri at the MD level on each platform, so that the kern_synch.c
does not have to deal with it as a common. Some platforms may be missed
by this commit... if you spot one, fix it the same way.
ok miod


# 1.186 09-Jun-2010 miod

Move declaration of cn_tab from dev/cons.c to dev/cninit.c, or appropriate
md files for ports which do not use dev/cninit.c. This gets rid of a common
at kernel link time.
feedback drahn@ ok deraadt@


# 1.185 24-May-2010 deraadt

Add missing prototypes
ok jsing kettenis


# 1.184 09-May-2010 kettenis

Prevent "taken branch" exceptions from kernel space by clearing the PSL_T
bit before we enter a signal handler.

"if you say so" miod@, "seems to make sense" jsing@


# 1.183 02-May-2010 kettenis

Properly initialize the members of `struct mdproc' that deal with
single-stepping when we fork and reset them upon exec.

ok miod@


# 1.182 27-Apr-2010 kettenis

Avoid null-pointer dereference by giving proc0 a place to store its
floating-point registers. Pointed out by Nick Hudson.

ok miod@, jsing@


# 1.181 19-Apr-2010 jsing

Make the Processor Status Word (PSW) a per-CPU value.

ok kettenis@


# 1.180 01-Apr-2010 jsing

Allow for multiple CPUs by moving to an array of cpu_info.

ok kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.179 31-Dec-2009 jsing

Make cpl and cpu_inintr per CPU variables. For locore.S, cpl becomes an
offset within cpu_primary_info - this will need to be revisited shortly.

ok kettenis@


# 1.178 11-Aug-2009 miod

Do not bother initializing bufpages in the md code if the computation is
exactly the same the mi could will use if bufinit() is invoked with
bufpages == 0.


# 1.177 11-Aug-2009 miod

With the SysV memory allocation changes, allocsys() doesn't do anything
anymore. Get rid of it completely.


# 1.176 09-Aug-2009 blambert

Rototill system V message queues.

No longer allocate a static amount of memory for messages in MD
boot path; message queues, message metadata, and message data now
all use dynamic memory, which means that runtime sysctls should now
be trivial to implement.

Since I'm going to be around all week to fix any breakage, this should
probably just go in now.


# 1.175 02-Aug-2009 beck

Dynamic buffer cache support - a re-commit of what was backed out
after c2k9

allows buffer cache to be extended and grow/shrink dynamically

tested by many, ok oga@, "why not just commit it" deraadt@


# 1.174 29-Jul-2009 kettenis

Get rid of non-equivalent aliases of the pcb by moving the fpu state out
of the pcb and using the p_addr member of 'struct proc' to calculate the
address of the kernel stack when switching to virtual mode after taking a trap.
Remove the now unecessary cache flushes; they're actually harmful since they
create non-equivalent aliases. This seems to fix the memory corruption we
have been observing from time to time.

This diff does not rename fpu_curpcb, which is now somewhat incorrectly named.
I hope to change things back again as soon as we are able to map the pcb 1:1.


Revision tags: OPENBSD_4_6_BASE
# 1.173 15-Jun-2009 beck

Back out all the buffer cache changes I committed during c2k9. This reverts three
commits:

1) The sysctl allowing bufcachepercent to be changed at boot time.
2) The change moving the buffer cache hash chains to a red-black tree
3) The dynamic buffer cache (Which depended on the earlier too).

ok on the backout from marco and todd


# 1.172 03-Jun-2009 beck

add kern.bufcachepercent sysctl to allow adjusting the buffer cache
size on a running system.
ok art@, oga@


Revision tags: OPENBSD_4_5_BASE
# 1.171 14-Feb-2009 kettenis

Limit the amount of physical memory to 2GB. Using more causes memory
corruption on PA-RISC 2.0 systems (and there are very few PA-RISC 1.1
systems that support more than 2GB).

ok miod@


# 1.170 04-Feb-2009 miod

On systems with split BTLB, do not bother trying to insert DBTLB entries,
as PDC will lie to us pretending it did while it didn't.

ok kettenis@


# 1.169 04-Feb-2009 miod

Unify memory size reports a bit more: always report size in MB, and report
reserved memory on alpha and hppa on its own line (as done on sgi).


Revision tags: OPENBSD_4_4_BASE
# 1.168 14-Jul-2008 miod

Be sure to propagate PSL_O in psw on PCXU* processors to userland processes
and signal handlers.
ok kettenis@


# 1.167 27-Jun-2008 miod

Clear swap encryption keys before dumping a kernel image.


# 1.166 09-Apr-2008 deraadt

Add new stub uvm_shutdown() and call it from the right place in MD boot()


Revision tags: OPENBSD_4_3_BASE
# 1.165 22-Sep-2007 martin

replace even more ctob and btoc with ptoa and atop respectively plus
uvm_extern.h where needed


Revision tags: OPENBSD_4_2_BASE
# 1.164 22-Jul-2007 kettenis

Move hppa to __HAVE_TIMECOUNTERS.


# 1.163 20-Jul-2007 kettenis

Give hppa the blink_led API from sparc64, and the associated machdep.led_blink
sysctl.


# 1.162 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.161 14-Jul-2007 kettenis

Make sigreturn(2) set the proper space ID for the instruction queue. Fixes
a few more pthreads regression tests.

ok miod@


# 1.160 10-Jul-2007 kettenis

Don't trust the privilige level in the sigcontext passed to sigreturn(2).

ok miod@


# 1.159 24-Jun-2007 kettenis

Crank initial storage for extents a bit. We really should allocate extents
using malloc once vm is initialised, but this will do for now.

ok deraadt@


# 1.158 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.157 27-May-2007 miod

Make sure the minaddr hint for uvm_km_suballoc() calls is always initialized.
ok pedro@


# 1.156 26-May-2007 pedro

Dynamic buffer cache. Initial diff from mickey@, okay art@ beck@ toby@
deraadt@ dlg@.


# 1.155 21-May-2007 kettenis

Add support for 8700/pcxw2 cpu.


# 1.154 21-May-2007 kettenis

Ask firmware for reset before trying ourselves; needed for four-digit b/c/j
workstations.

tested by otto@, krw@; ok deraadt@


# 1.153 17-May-2007 art

Limit hppa buffer cache to 30%. It used to be 70% because stack garbage
that was used for minaddr instead of the proper vm_map_min(kernel_map)
(fixed in this diff).

From mickey. art@ ok


# 1.152 14-May-2007 martin

move hppa to __HAVE_CPUINFO

input from miod@, ok kettenis@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.151 28-May-2006 martin

minor nit, use CPU ID instead of FPU ID for BTLB parameters after passing
all kludges


# 1.150 15-Apr-2006 martin

make warning about missing HPT support DEBUG for now

ok mickey@


Revision tags: OPENBSD_3_9_BASE
# 1.149 26-Oct-2005 martin

no more hppa_round_page() and hppa_trunc_page() macros

ok mickey@


Revision tags: OPENBSD_3_8_BASE
# 1.148 06-Aug-2005 miod

We do not need a char machine_arch[] constant.
ok deraadt@


# 1.147 11-Jul-2005 mickey

align some stupid comments


# 1.146 10-May-2005 mickey

set pcsq in case we get signal delivery once interrupted from the gateway page; from chs


# 1.145 18-Apr-2005 mickey

do not do some of the initmsgbuf()s job


# 1.144 07-Apr-2005 mickey

on some machines it's possible to limit the amount of physmem initialised dring post so having msgbuf at the end of memory shall work


# 1.143 07-Apr-2005 mickey

64bit-friendly pdc.h and iomod.h and correspondent changes elsewhere


# 1.142 26-Mar-2005 mickey

md parts for hpux_compa code; some problems w/ signals delivery still exist


Revision tags: OPENBSD_3_7_BASE
# 1.141 24-Feb-2005 mickey

do not even ask for btlb on 8k cpus as pdc pretends there is some but then it does not work; found w/ Moritz Kiese <mbk@mytum.de> on c180; add a debug print and fix pcxu entry


# 1.140 17-Nov-2004 mickey

print real/avail/bufcache sizes as unsigned


# 1.139 26-Oct-2004 mickey

disable sid hashing on pcxu and above


# 1.138 14-Oct-2004 mickey

a bit larger delays during boot() to let msgs appear


# 1.137 19-Sep-2004 mickey

turn totalphysmem into physmem and name old physmem into smth it really is


# 1.136 18-Sep-2004 mickey

oops


# 1.135 15-Sep-2004 mickey

add pcxu tlb handlers and cpu probing
add u2/uturn ioa driver in dumb mode now
enable pcxu/pcxw support


# 1.134 14-Sep-2004 mickey

store fpu version for later use. make sure to proper store/clear fpu state in fork/exec/exit/sendsig


# 1.133 14-Sep-2004 mickey

error out from btlb_insert() if there is none


Revision tags: OPENBSD_3_6_BASE
# 1.132 01-Jul-2004 mickey

have separate insn and data cache all-flushers


# 1.131 30-Jun-2004 mickey

allow forced fpu emulation through a sysctl


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.130 13-May-2004 mickey

8ks do not have hvt


# 1.129 05-May-2004 mickey

much easier tlb handler branch patching


# 1.128 05-May-2004 mickey

do not engage HPT on PCXT' (yet)


# 1.127 08-Apr-2004 mickey

repair pcxs/t confoosion


# 1.126 07-Apr-2004 mickey

update copyright; miod@ is fine w/ files where he holds it too


Revision tags: OPENBSD_3_5_BASE
# 1.125 10-Mar-2004 tom

Ensure that we obey a user's ddb> boot reboot command even if the system
is cold (during startup).

This adds RB_USERREQ to sys/reboot.h, uses it in the ddb commands, and
ensures that */*/machdep.c:boot() won't set RB_HALT when cold if this
flag is set.

ok deraadt@


# 1.124 14-Feb-2004 grange

Simplify hw.{cpuspeed,setperf} api moving all the sysctl stuff
from the underlying callbacks.

Testing hppa mickey@, ppc drahn@
Ok markus@ tedu@


# 1.123 05-Jan-2004 mickey

kill debugging code that is not needed anymore


# 1.122 23-Dec-2003 mickey

provide cpuspeed fluff


# 1.121 20-Dec-2003 miod

Don't let microtime() return a struct timeval with exactly 1000000 microseconds.


# 1.120 18-Dec-2003 mickey

spls do not protect cpu_itmr and thus time might jump back sometimes due to cpu_itmr modified to a higher value than a read itmr; found and testing by miod@


# 1.119 17-Dec-2003 mickey

in the real mem print do not include reserved for prom into used by openbsd


# 1.118 10-Dec-2003 mickey

for unaligned btlb mapping attempts -- just fail


# 1.117 24-Nov-2003 mickey

experimental support for HVT as a 2nd level tlb


# 1.116 15-Oct-2003 mickey

less global name space pollution


# 1.115 05-Oct-2003 mickey

reload the itmr as soon as we get the intr to avoid lagging on slower machines


# 1.114 25-Sep-2003 mickey

some pcxl2 do not report fpus -- assume it's there


Revision tags: OPENBSD_3_4_BASE
# 1.113 04-Sep-2003 mickey

a better cpu identification; testing by miod


# 1.112 31-Aug-2003 miod

pdc_model needs to be visible from cpu.c


# 1.111 20-Aug-2003 mickey

missing nl in debugging prontf


# 1.110 07-Aug-2003 mickey

dead proto


# 1.109 07-Aug-2003 mickey

first allocate space on stack then copyout signal shits. add a DEBUG check for a whacky user pc (as impossible due to the recent trap.c change)


# 1.108 03-Aug-2003 mickey

clear branch and nullify bits in psw on sending a signal


# 1.107 30-Jul-2003 mickey

deduce the leds address from the model number and thus make some more use of that lichtenblinkenschmutz on some more machinens


# 1.106 22-May-2003 mickey

imprecision in delay_init()


# 1.105 18-May-2003 mickey

save the fpu state for the signal handler. this is essential
as the fpu regs can be used by the gcc even for non-fpu
means and data copying.
rearrange the sigcontext a bit to include only the general
registers that are needed restoring upon return and thus
less waste of space and make up some space for the fpu regs.

ALL software that used the signal context on the stack
needs at least rebuilding now. a new snap has bin built as well.


Revision tags: UBC_SYNC_A
# 1.104 11-May-2003 deraadt

string cleaning; krw ok


# 1.103 07-Apr-2003 mickey

s/HP9000/HP 9000/; from weissmanndude


Revision tags: OPENBSD_3_3_BASE
# 1.102 18-Feb-2003 deraadt

knf; mickey ok


# 1.101 12-Feb-2003 jason

How uncommon... hppa only has one common: msgbufmapped (decl'd in /sys/kern)


# 1.100 12-Feb-2003 mickey

only align the first stack frame onto the minimal required alignment


# 1.99 10-Feb-2003 mickey

fix pcs and pcxt recognition. from weissmanndude


# 1.98 22-Jan-2003 mickey

consistantly use uvm_prot_* vs vm_prot_* evewrhere


# 1.97 14-Jan-2003 mickey

fix cutnpaste in the cpu table for the itlbna field; from herr weissmanndude


# 1.96 14-Jan-2003 mickey

need pdc_hwtlb always; pt out by herr weissmanndude


# 1.95 13-Jan-2003 mickey

fix the logic in hvt probing


# 1.94 09-Jan-2003 miod

Remove fetch(9) and store(9) functions from the kernel, and replace the few
remaining instances of them with appropriate copy(9) usage.

ok art@, tested on all arches unless my memory is non-ECC


# 1.93 19-Dec-2002 mickey

setregs: put the whole frame setup into one place


# 1.92 19-Dec-2002 mickey

level 0x16 is really an l2


# 1.91 17-Dec-2002 millert

Make SysV-style shared memory and semaphore limits sysctl'able.
Instead of allocating a static amount of memory for the data
structures via valloc() in allocsys(), allocate things dynamically
using pool(9) when possible and malloc(9) when not. The various
members of struct seminfo and struct shminfo are in kern.seminfo
and kern.shminfo respectively (not all members of kern.seminfo are
changable).

The data structures used still leave something to be desired but
things are not made worse in that respect by this commit.


# 1.90 27-Nov-2002 mickey

no wrapper arounf hardclock(), use CPU_CLOCKUPDATE, real microtime; miod ok


# 1.89 08-Nov-2002 mickey

Don't uvm_useracc the user sigcontext in sys_sigreturn and then access
the user addresses directly from the kernel. copyin is faster and can
correctly deal properly with mappings that uvm_useracc thinks are
correct but will fault anyway (to figure out how to generate such
mappings is left as en excercise for the reader).


# 1.88 01-Nov-2002 mickey

add a missing delay after printf on halt[-p], proper arg for a cold hook


Revision tags: UBC_SYNC_B
# 1.87 22-Oct-2002 mickey

do not force single-user; pt out by fries@


# 1.86 15-Oct-2002 mickey

missing initmsgbuf(), noticed by miod@


# 1.85 13-Oct-2002 mickey

track the end of physmem for use in dmmem_alloc


# 1.84 07-Oct-2002 mickey

s/PSW_/PSL_/ to match other archs


# 1.83 07-Oct-2002 mickey

proper terminate the user stack on signal


# 1.82 07-Oct-2002 mickey

on implementations w/ fpu included unimplemented instructions
are signaled through the exception trap w/ invalid opcode marked
instruction in the exception registers, not through the emulation
trap (as long as the fpu is enabled, of course).
parse emulation from the exception trap as well as the emulation
trap and fix the dispatcher into usable condition.
parse invalid op exception on trap and signal the user appropriately.
reset the exception on exec and for child on fork.
the later is appropriate since exceptions are delayed until next
fpu instruction, which was in the parent indeed, let him get it.
save parent's fpu context on fork before cipying it, if the
parent owned the fpu.


Revision tags: OPENBSD_3_2_BASE
# 1.81 23-Sep-2002 mickey

parisc level 0x10 is just an overclocked 0xe


# 1.80 17-Sep-2002 mickey

handle fpu exceptions properly, might use a regress, i guess


# 1.79 11-Sep-2002 mickey

provide a convinient reset label


# 1.78 11-Sep-2002 mickey

stack grows the other way, but the frame is the other way to that. hehe


# 1.77 09-Sep-2002 mickey

set up the frame flags and a user frame better on exec


# 1.76 03-Aug-2002 mickey

rework boot() w/o a goto


# 1.75 25-Jul-2002 mickey

missing arg in the call to the pdc_call since some old times


# 1.74 25-Jul-2002 mickey

kcopy is a space-to-space copy from kernel space, to guess where, -- to the same kernel space, just error on fault


# 1.73 20-Jul-2002 art

Instead of copying out the signal trampoline on top of the stack, create
an uvm aobj, copy out the signal trampoline into it and share that page
among all processes for the same emulation.

This also requires us to actually be able to tell signal code where the
trampoline is located, so introduce a new field in struct proc - p_sigcode
that is a pointer to sigcode. This allows us to remove all the ugly
calculations of the signal trampoline address done in every sendsig
function in the tree (that's why so many files are changed).

Tested by various people. ok deraadt@


# 1.72 14-May-2002 mickey

disable sid hashing while still in real mode, alos print the parisc arch once and not per each cpu since they are not intermixable architecture-wise


# 1.71 13-May-2002 mickey

ldi-ldo whatever was in the table, be that much clever


# 1.70 08-May-2002 mickey

print parisc level w/ the the parisc version, not for each cpu


# 1.69 08-May-2002 mickey

kill debugging printfski


# 1.68 22-Apr-2002 mickey

no longer batc the data, only the code.
this removes a constraint and an ld.script dependancy
for the .data and the dynamically allocated kernel
structures existed w/ batcing. also makes pmap_steal_memory
obsolete and replaced w/ the pmap_virtual_space.
implement batching for pmap_remove to avoid
zeroing out the pte entries if pde will be removed anyway.


# 1.67 21-Apr-2002 mickey

better buf's mapping and less magic constants in checking for io space cachability


Revision tags: OPENBSD_3_1_BASE
# 1.66 26-Mar-2002 mickey

if cannot guess cpu model default to the lowest supported one


# 1.65 25-Mar-2002 deraadt

spelling


# 1.64 23-Mar-2002 espie

Add variables for config(8) -e time tweak of systemV shared memory
parameters.

Ok millert@, miod@, maja@


# 1.63 19-Mar-2002 mickey

mtcpu seq requires a pre-sync, implement hpt init for pcxl


# 1.62 15-Mar-2002 mickey

rewrite a pmap to use multilevel page tables.
lower 12 bits contain the perms, no unused bits left,
but a couple for off-tlb use (as the ref implemented now).
do not use the hvt, which might get some use later
if proven to speed thigs up, tlb handlers would po
another dozen of insns though, but if that's worth its...
move on the data seg and map kernel text rdonly (idea form fredette),
since all of the page0 mods done before that we are all fine
except for some viper fluff, but later w/ that.
this also picks up a bit more of ddb magic for bpt and ss.
tlb handlers can use a little bit more of attention,
but things, visually, seem to be much faster already, --
sorry, no benchmarks for now.

* effort sponsored in part by the `henry st. old ale house'
* and mr.pete and mr.lee in particular in thier generous entrirety.
* the proj took a little more that 72man*h as it was expected,
* but within murhy's law estimations.


# 1.61 14-Mar-2002 millert

First round of __P removal in sys


# 1.60 20-Feb-2002 mickey

setup power failure handler (for sw-controlled power button), move toc handler


# 1.59 17-Feb-2002 maja

Patch from Daniel Lucq <daniel@lucq.org>

The patch allows you to change the value of NMBCLUSTERS, BUFCACHEPERCENT
and NKMEMPAGES using the config command, instead of recompiling the kernel.

This is the kernel part of the patch. I have compiled it on i386, sparc64,
alpha and macppc. -moj ok art@ maja@


# 1.58 12-Feb-2002 mickey

support 712's programmable power switch, no interrupt yet


# 1.57 12-Feb-2002 mickey

small repairs to hpmc and toc handlers


# 1.56 11-Feb-2002 mickey

disable fpu on csw, print fpu version on cpu line, if present


# 1.55 07-Feb-2002 mickey

fix sigdebug cases; init sigcontext before it's used (;


# 1.54 06-Feb-2002 mickey

implement signal delivery; based on fredette@'s work


# 1.53 03-Feb-2002 mickey

restore hpt size computation, does not break things as i thought


# 1.52 02-Feb-2002 mickey

fix 'physmem' usage


# 1.51 02-Feb-2002 mickey

implement the rest of /dev/mem devices; from netbsd


# 1.50 23-Jan-2002 art

move mb_map allocation to mbinit()


# 1.49 23-Jan-2002 art

move definition of mb_map from zillions of machdep.c to uipc_mbuf.c


# 1.48 16-Jan-2002 miod

Don't include <sys/map.h> when you don't need what's in it.


Revision tags: UBC_BASE
# 1.47 02-Dec-2001 mickey

branches: 1.47.2;
increase fixed extent storage


# 1.46 28-Nov-2001 art

zap some typedefs.
vm_map_t -> struct vm_map *
vm_map_entry_t -> struct vm_map_entry *
simple_lock_data_t -> struct simplelock

(uvm not done yet, coming in the next commit)


# 1.45 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.44 24-Nov-2001 miod

Harmonize boot() logic across arches:
- ensure RB_DUMP | RB_HALT will cause a dump
- or RB_HALT if (cold)
While there, honor RB_TIMEBAD on sparc64.


# 1.43 09-Nov-2001 art

nswbuf hasn't been used for ages. gc.


# 1.42 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.41 06-Nov-2001 miod

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


Revision tags: OPENBSD_3_0_BASE
# 1.40 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.39 12-Sep-2001 art

mbutl no more


# 1.38 23-Aug-2001 art

We can now move timeout_init into main().


# 1.37 23-Aug-2001 art

Remove even more old timeout tentacles.


# 1.36 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.35 05-Jul-2001 art

Get rid of REAL_CLISTS. It was never implemented and the tentacles are
everywhhere.


# 1.34 17-May-2001 provos

convert mbuf and cluster allocation to pool, mostly from NetBSD
okay art@ miod@


# 1.33 05-May-2001 art

Rename configure() to cpu_configure().
Move it from cpu_startup() to main().


# 1.32 05-May-2001 art

Get rid of CLSIZE and all related stuff.
CLSIZE -> 1
CLBYTES -> PAGE_SIZE
OLOFSET -> PAGE_MASK
etc.
At the same time some archs needed some cleaning in vmparam.h so that
goes in at the same time.


Revision tags: OPENBSD_2_9_BASE
# 1.31 29-Mar-2001 mickey

cpudev_data.h here needed not


# 1.30 22-Mar-2001 mickey

shuffle the tlb handlers a little,
make a new one for na data fault,
since those w/ hpt need it.


Revision tags: OPENBSD_2_8_BASE
# 1.29 15-Aug-2000 mickey

two btlb routines (i & d) for pcxs


# 1.28 15-Aug-2000 mickey

expand per-cpu control routines switch


# 1.27 08-Aug-2000 mickey

print btlb params w/ BTLBDEBUG; from Havard.Eidnes@runit.sintef.no


# 1.26 02-Jul-2000 mickey

no bays for stinger


Revision tags: OPENBSD_2_7_BASE
# 1.25 23-Mar-2000 mickey

new cpu type switch code.
initializes tlb miss handlers correspondent to probed cpu features.
also btlb load routine.
versions written are for pcxl and others.
cpu-dep btlb loaders are missing, only generic for now.


# 1.24 23-Mar-2000 art

New API for timeouts. Replaces the old timeout()/untimeout() API and
makes it the callers responsibility to allocate resources for the
timeouts.

This is a KISS implementation and does _not_ solve the problems of slow
handling of a large number of pending timeouts (this will be solved in
future work) (although hardclock is now guarateed to take constant time
for handling of timeouts).

Old timeout() and untimeout() are implemented as wrappers around the new
API and kept for compatibility. They will be removed as soon as all
subsystems are converted to use the new API.


# 1.23 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


# 1.22 22-Feb-2000 mickey

blah, blah, blah, msgbuf


Revision tags: SMP_BASE
# 1.21 09-Feb-2000 mickey

branches: 1.21.2;
heartbeat -- yeah we have a patch for that


# 1.20 25-Jan-2000 mickey

better copy and zero inlines in locore;
proper setregs() in machedep;
start of hpmc handler;
some cleanup here and there;


# 1.19 17-Jan-2000 mickey

remove unneeded stuff from setregs; force single-user for now, enable signal debug


# 1.18 11-Jan-2000 mickey

s/fpu_curproc/fpu_curpcb/ which also points into physical.
move it's definition into locore (where it's used the most).
adjust fpu context switch and save on swapout accordingly.
fix context save (in switch).
add accounting for fpu context switches (since it differes
from proc switching, we might get provided w/ some usefull
numbers as to how effective this lazy switch technique is).
enable handling fpu/sfu exceptions.


# 1.17 31-Dec-1999 mickey

don't bother about pidr3 and pidr4


# 1.16 17-Dec-1999 mickey

fix the panic message for sti memory mapping


Revision tags: kame_19991208
# 1.15 25-Nov-1999 mickey

bus stuff is in mainbus now, the rest is rewritten many ways


Revision tags: OPENBSD_2_6_BASE
# 1.14 20-Sep-1999 mickey

fix uvm_pagealloc() call


# 1.13 03-Sep-1999 art

Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.12 14-Aug-1999 mickey

proper debugging ifdefs


# 1.11 21-Jul-1999 mickey

rewrite the tlb miss handler and tlb dirty handler.
optimize for HVT usage (when compiled for proper cpu type).
drop hpt_* global variables, use info from control registers instead.
there are still ways to improve the tlb handlers tho.
machdep also prints cache and tlb coherence states (not related to the above).
You eat greenish muffin. --More-- You write real code.


# 1.10 12-Jul-1999 mickey

allocate 5% bufcache if <=16M memory installed


# 1.9 12-Jun-1999 mickey

hppa_init() now takes an argument from locore,
meaning the start of available memory.
cleanup machdep somewhat.
fix vm_map.pmap vs vm_pmap isue; 10x art@


# 1.8 23-May-1999 mickey

new swap stuff


# 1.7 21-May-1999 mickey

group all theMD f;ags together, add interrupt recursion one


# 1.6 21-May-1999 mickey

define fpu_curproc


# 1.5 20-Apr-1999 mickey

do lazy blok mapping of io space in bus_*
add copy{in,out}*, kcopy, etc
boot routines
cpu-id-hpux-compat stuff
rest of scheduler and such
uvm


Revision tags: OPENBSD_2_5_BASE
# 1.4 17-Feb-1999 mickey

print pa-risc here as well, since, finally, cpu will have to print processor type


# 1.3 04-Jan-1999 mickey

better cache handling in bus_space_barrier(), seem to work now


# 1.2 03-Jan-1999 mickey

implement bus_space_{un,}map w/ extents


# 1.1 30-Dec-1998 mickey

machdep; more work needed


# 1.250 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.249 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


Revision tags: OPENBSD_6_2_BASE
# 1.248 18-May-2017 kettenis

Implement copyin32(9).

"your chicken scratches look fine to me" deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.247 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

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


# 1.246 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.245 21-May-2016 deraadt

hand-massage sendsig() and sys_sigreturn() to be much more similar.
ok guenther kettenis


# 1.244 10-May-2016 deraadt

SROP mitigation. sendsig() stores a (per-process ^ &sigcontext) cookie
inside the sigcontext. sigreturn(2) checks syscall entry was from the
exact PC addr in the (per-process ASLR) sigtramp, verifies the cookie,
and clears it to prevent sigcontext reuse.
not yet tested on landisk, sparc, *88k, socppc.
ok kettenis


# 1.243 20-Apr-2016 dlg

pool_setipl for floating point context things

ok kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.242 21-Oct-2015 mpi

Do not call uvm_swap_finicrypt_all() a second time in dumpsys().

ok tedu@, deraadt@, miod@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.241 20-Jan-2015 kettenis

Move ps_strings "after" the random stackgap. This makes its location a
per-process value, and therefpore turns the VM_PSSTRINGS sysctl into a
per-process one as well. This gets rid of a pointer to the bottom of the
stack at a fixed location. Also clears the road for unmapping the stackgap.

ok deraadt@


# 1.240 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.239 25-Oct-2014 kettenis

Remove vmmap; it isn't used.

ok jsing@


# 1.238 23-Oct-2014 miod

Correctly set up the HPMC trap entry: according to the PA-RISC Firmware
Architecture Reference Specification, the sum of the 8 trap entry words
*and* of the payload which address and length are to be set at well-known
positions in the aforementioned trap entry, needs to be zero; the existing
code was only enforcing that the sum of the trap entry words is zero.

This matches what Linux and NetBSD do.

ok kettenis@


# 1.237 23-Oct-2014 miod

Revert limiting physmem to 2GB; the culprit was likely in uvm and uvm has
changed a lot in the last 5 years; verified to work on a 3GB system, in
snapshots for a few weeks already.


# 1.236 22-Sep-2014 dlg

implement atomic_{cas,swap}_{uint,ulong,ptr} and
atomic_{add,sub}_{int,long}_nv. sys/atomic.h turns these into the
rest of the atomic api.

on uniprocessor hppa systems "atomic" operations are implemented
as a non-interruptable sequence by disabling all interrupts on the
cpu, doing the operation, and then restoring the interrupt mask.

this isnt enough on MP systems, so we added a global atomic memory
mutex that is taken inside the interrupt disabling above to coordinate
operations between cpus.

this is a lot of overhead though cos mutexes dance around with ipls,
which is unecessary in our case because of the interrupt disabling
that is already done. also, hppa spinlocks are implemented with
ldcw which requires the word it operates on to be 16 byte aligned.
mutexes arent guaranteed to have this alignment so they compensate
by having lots of words inside themselves so they can hit the
appropriate one to use for the ldcw op.

with this in mind, this change pulls __cpu_simple_locks, which are
simply ldcw spinlocks with a 16 byte aligned word, out of
src/sys/arch/hppa/include/lock.h into src/sys/arch/hppa/include/atomic.h
so atomic.h can use them. lock.h includes atomic.h, so it still
gets and provides the same functionality as before.

finally, this also pulls the rwlock cas implementation apart. cas
ops now share the same serialising lock on MP systems as the other
memory operations, and rw_cas is defined as a wrapper around
atomic_cas_uint.

ok kettenis@


# 1.235 19-Sep-2014 kettenis

Use config_suspend_all(9).


# 1.234 18-Aug-2014 dlg

dont rely on mbuf.h to provide pool.h.

ok miod@, who has offerred to help with any MD fallout
ok guenther@


Revision tags: OPENBSD_5_6_BASE
# 1.233 22-Jul-2014 uebayasi

boot(9): Reduce diffs between hppa & hppa64 (& others)


# 1.232 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.231 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.230 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.229 13-Jul-2014 miod

These still need <sys/reboot.h> for the RB_ constants.


# 1.228 12-Jul-2014 uebayasi

reboot(9), panic(9): Call panic(9) for unrecoverable MD H/W errors (NMIs)

Some architectures have ability to detect hardware sanity and notify system
(NMI, firmware callback, etc.). Handle these hardware severe errors, same
as software errors, with panic(9).

According to miod@, SGI IP27 NMI is triggered by pushing some "hidden" button,
which "usual" users/admins don't know. Pushing such a button is "RB_USERREQ"
(human-triggered) in that the button is pushed by a human, but not "RB_USERREQ"
in that no user intervention in system (== no command input) is done. miod@
agreed that changing these from RB_USERREQ to !RB_USERREQ (== panic(9)) is
not a big problem.

OK miod@ kettenis@


# 1.227 12-Jul-2014 uebayasi

boot(9), reboot(9): Migrate MD callers of boot(9) to reboot(9)

I have found that some ports call boot(9) from machine-dependent code to
reboot system. These should be changed to either:

- Sending signal to init(8) to trigger it to shutdown system cleanly, like
acpi(4) does, in cases where found problems don't prevent system from working
immediately, or

- Just doing panic(9) if the situation is severely broken.

For now, just rewrite boot() to reboot(). Actual fixes follow.

Discussed with & OK from kettenis@


# 1.226 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.225 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.224 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.223 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.222 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.221 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.220 08-May-2014 miod

Format string fixes and removal of -Wno-format for hppa kernels.


# 1.219 08-Apr-2014 mpi

Less <uvm/uvm.h>


# 1.218 04-Apr-2014 miod

If the PDC_COPROC call fails, and we are running on a PA 1.1 system, assume
the usual 1.1 coprocessor mask, instead of using zero and having every
userland process dying with signal 4.

The circumstances under which this call fails are unclear and could be
tied to specific PROM version (I have tried overzealous stack alignment and
other tricks, to no avail). Interestingly enough, the 715/75 system which
hits this problem, only triggers it when booting from disk, and never when
booting from network.

This diff is an ugly bandaid until the problem is better understood. Or maybe
it is not worth investigating, seeing that Linux hardcodes the coprocessor
mask and never issues PDC_COPROC calls; I wonder what HP/UX does.

In my tree for over 18 months; "Looks like a nice hack" deraadt@
715/75 system provided by Sebastiaan Indesteege, thanks!


# 1.217 29-Mar-2014 guenther

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

ok dlg@ mpi@ deraadt@


# 1.216 26-Mar-2014 guenther

Move p_emul and p_sigcode from proc to process.
Tweak the handling of ktrace EMUL when changing ktracing: only
generate one per process (not one per thread) and pass the correct
proc pointer down to the VFS layer. Permit generating of NAMI and
CSW records inside ktrace(2) itself.

ok deraadt@ millert@


# 1.215 22-Mar-2014 guenther

Move p_sigacts from struct proc to struct process.

testing help mpi@


# 1.214 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


Revision tags: OPENBSD_5_5_BASE
# 1.213 23-Nov-2013 uebayasi

Run doshutdownhooks() and config_suspend() even when boot() is called while
cold != 0. Indent and make hppa/hppa64 boot() closer to others.

OK kettenis@


# 1.212 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


Revision tags: OPENBSD_5_4_BASE
# 1.211 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


Revision tags: OPENBSD_5_3_BASE
# 1.210 02-Dec-2012 guenther

Determine whether we're currently on the alternative signal stack
dynamically, by comparing the stack pointer against the altstack
base and size, so that you get the correct answer if you longjmp
out of the signal handler, as tested by regress/sys/kern/stackjmp/.
Also, fix alt stack handling on vax, where it was completely broken.

Testing and corrections by miod@, krw@, tobiasu@, pirofti@


# 1.209 26-Oct-2012 kettenis

Properly clear trap frame in setregs() to avoid leaking registers across exec.

ok jsing@


# 1.208 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.207 07-Oct-2012 kettenis

Align the stack on a 64-byte boundary as required by "The 32-bit PA-RISC
Run-time Architecture Document". GCC relies on this to properly align
stack variables.

ok guenther@, beck@


Revision tags: OPENBSD_5_2_BASE
# 1.206 21-Jun-2012 guenther

__tfork() needs to set the stack address of the new thread in the kernel,
so that it can't get a signal while still running on the parent thread's
stack. Also, pass in sizeof(struct __tfork) to provide forward compat
when more members are added. This is an ABI change, so switch syscall
numbers and bump lib majors this time.

ok deraadt@ matthew@


Revision tags: OPENBSD_5_1_BASE
# 1.205 20-Sep-2011 miod

Clear RB_POWERDOWN early in boot() on systems which can not powerdown and
which firmware does not send spin up commands to the disks, in case the
operator changes his mind and reboots instead of manually powering down
after the system has halted.
ok kettenis@


Revision tags: OPENBSD_5_0_BASE
# 1.204 05-Jul-2011 guenther

Recommit the reverted sigacts change now that the NFS use-after-free
problem has been tracked down. This fixes the sharing of the signal
handling state: shared bits go in sigacts, per-rthread bits goes in
struct proc.

ok deraadt@


# 1.203 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.202 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.201 18-Apr-2011 guenther

Revert the sigacts diff: NFS can apparently retain pointers to processes
until they're zombies and then send them signals (for intr mounts). Until
that is untangled, the sigacts change is unsafe. sthen@ was the victim
for this one


# 1.200 15-Apr-2011 guenther

Correct the sharing of the signal handling state: stuff that should
be shared (p_sigignore, p_sigcatch, P_NOCLDSTOP, P_NOCLDWAIT) moves
to struct sigacts, wihle stuff that should be per rthread (ps_oldmask,
SAS_OLDMASK, ps_sigstk) moves to struct proc. Treat the coredumping
state bits (ps_sig, ps_code, ps_type, ps_sigval) as per-rthread
until our locking around coredumping is better.

Oh, and remove the old SunOS-compat ps_usertramp member.

"I like the sound of this" tedu@


Revision tags: OPENBSD_4_9_BASE
# 1.199 14-Jan-2011 jsing

Halt secondary CPUs when shutting down or rebooting. This should prevent
occasional hangs during reboot.

ok kettenis@


# 1.198 04-Jan-2011 jasper

- de-register. no binary change.

ok jsing@


# 1.197 01-Jan-2011 jasper

Move setting cpu_hzticks to the clock initialization function, like
other ports (e.g. hppa64) do.

ok jsing@ kettenis@


# 1.196 01-Jan-2011 jasper

- ansify

ok jsing@ kettenis@


# 1.195 30-Dec-2010 jsing

Turn signotify() into a function that also calls cpu_unidle().

ok kettenis@


# 1.194 20-Nov-2010 miod

This is a first step towards getting rid of avail_start and avail_end in the
kernel, currently limited to low-hanging fruit: these variables were used
by bus_dma to specify the range in which to allocate memory, back when
uvm_pglistalloc() was stupid and would not walk the vm_physseg[].

Nowadays, except on some platforms for early initialization, these variables
are not used, or do not need to be global variables. Therefore:
- remove `extern' declarations of avail_start and avail_end (or close cousins,
such as arm physical_start and physical_end) from files which no longer need
to use them.
- make them local variables whenever possible.
- remove them when they are assigned to but no longer used.


Revision tags: OPENBSD_4_8_BASE
# 1.193 01-Jul-2010 jsing

Create a struct to store FP state and include a pointer to the CPU that
currently holds the FPU context for this process. This will be soon used
to implement FPU shootdowns on multiprocessor kernels.

ok kettenis@


# 1.192 29-Jun-2010 guenther

Remove COMPAT_HPUX. No one wanted to support it and its fewmets were
blocking other cleanups
ok miod@


# 1.191 29-Jun-2010 jsing

Factor out code used to save and flushe process FPU context.

ok kettenis@


# 1.190 29-Jun-2010 jsing

Store pointer to process FPU state in struct cpu_info.

ok kettenis@


# 1.189 27-Jun-2010 thib

uvm constraints. Add two mandatory MD symbols, uvm_md_constraints
which contains the constraints for DMA/memory allocation for each
architecture, and dma_constraints which contains the range of addresses
that are dma accessable by the system.

This is based on ariane@'s physcontig diff, with lots of bugfixes and
additions the following additions by my self:

Introduce a new function pool_set_constraints() which sets the address
range for which we allocate pages for the pool from, this is now used
for the mbuf/mbuf cluster pools to keep them dma accessible.

The !direct archs no longer stuff pages into the kernel object in
uvm_km_getpage_pla but rather do a pmap_extract() in uvm_km_putpages.

Tested heavily by my self on i386, amd64 and sparc64. Some tests on
alpha and SGI.

"commit it" beck, art, oga, deraadt
"i like the diff" deraadt


# 1.188 27-Jun-2010 jsing

Use a mutex to make atomic operations atomic on multiprocessor kernels.

ok kettenis@


# 1.187 10-Jun-2010 deraadt

Declare safepri at the MD level on each platform, so that the kern_synch.c
does not have to deal with it as a common. Some platforms may be missed
by this commit... if you spot one, fix it the same way.
ok miod


# 1.186 09-Jun-2010 miod

Move declaration of cn_tab from dev/cons.c to dev/cninit.c, or appropriate
md files for ports which do not use dev/cninit.c. This gets rid of a common
at kernel link time.
feedback drahn@ ok deraadt@


# 1.185 24-May-2010 deraadt

Add missing prototypes
ok jsing kettenis


# 1.184 09-May-2010 kettenis

Prevent "taken branch" exceptions from kernel space by clearing the PSL_T
bit before we enter a signal handler.

"if you say so" miod@, "seems to make sense" jsing@


# 1.183 02-May-2010 kettenis

Properly initialize the members of `struct mdproc' that deal with
single-stepping when we fork and reset them upon exec.

ok miod@


# 1.182 27-Apr-2010 kettenis

Avoid null-pointer dereference by giving proc0 a place to store its
floating-point registers. Pointed out by Nick Hudson.

ok miod@, jsing@


# 1.181 19-Apr-2010 jsing

Make the Processor Status Word (PSW) a per-CPU value.

ok kettenis@


# 1.180 01-Apr-2010 jsing

Allow for multiple CPUs by moving to an array of cpu_info.

ok kettenis@


Revision tags: OPENBSD_4_7_BASE
# 1.179 31-Dec-2009 jsing

Make cpl and cpu_inintr per CPU variables. For locore.S, cpl becomes an
offset within cpu_primary_info - this will need to be revisited shortly.

ok kettenis@


# 1.178 11-Aug-2009 miod

Do not bother initializing bufpages in the md code if the computation is
exactly the same the mi could will use if bufinit() is invoked with
bufpages == 0.


# 1.177 11-Aug-2009 miod

With the SysV memory allocation changes, allocsys() doesn't do anything
anymore. Get rid of it completely.


# 1.176 09-Aug-2009 blambert

Rototill system V message queues.

No longer allocate a static amount of memory for messages in MD
boot path; message queues, message metadata, and message data now
all use dynamic memory, which means that runtime sysctls should now
be trivial to implement.

Since I'm going to be around all week to fix any breakage, this should
probably just go in now.


# 1.175 02-Aug-2009 beck

Dynamic buffer cache support - a re-commit of what was backed out
after c2k9

allows buffer cache to be extended and grow/shrink dynamically

tested by many, ok oga@, "why not just commit it" deraadt@


# 1.174 29-Jul-2009 kettenis

Get rid of non-equivalent aliases of the pcb by moving the fpu state out
of the pcb and using the p_addr member of 'struct proc' to calculate the
address of the kernel stack when switching to virtual mode after taking a trap.
Remove the now unecessary cache flushes; they're actually harmful since they
create non-equivalent aliases. This seems to fix the memory corruption we
have been observing from time to time.

This diff does not rename fpu_curpcb, which is now somewhat incorrectly named.
I hope to change things back again as soon as we are able to map the pcb 1:1.


Revision tags: OPENBSD_4_6_BASE
# 1.173 15-Jun-2009 beck

Back out all the buffer cache changes I committed during c2k9. This reverts three
commits:

1) The sysctl allowing bufcachepercent to be changed at boot time.
2) The change moving the buffer cache hash chains to a red-black tree
3) The dynamic buffer cache (Which depended on the earlier too).

ok on the backout from marco and todd


# 1.172 03-Jun-2009 beck

add kern.bufcachepercent sysctl to allow adjusting the buffer cache
size on a running system.
ok art@, oga@


Revision tags: OPENBSD_4_5_BASE
# 1.171 14-Feb-2009 kettenis

Limit the amount of physical memory to 2GB. Using more causes memory
corruption on PA-RISC 2.0 systems (and there are very few PA-RISC 1.1
systems that support more than 2GB).

ok miod@


# 1.170 04-Feb-2009 miod

On systems with split BTLB, do not bother trying to insert DBTLB entries,
as PDC will lie to us pretending it did while it didn't.

ok kettenis@


# 1.169 04-Feb-2009 miod

Unify memory size reports a bit more: always report size in MB, and report
reserved memory on alpha and hppa on its own line (as done on sgi).


Revision tags: OPENBSD_4_4_BASE
# 1.168 14-Jul-2008 miod

Be sure to propagate PSL_O in psw on PCXU* processors to userland processes
and signal handlers.
ok kettenis@


# 1.167 27-Jun-2008 miod

Clear swap encryption keys before dumping a kernel image.


# 1.166 09-Apr-2008 deraadt

Add new stub uvm_shutdown() and call it from the right place in MD boot()


Revision tags: OPENBSD_4_3_BASE
# 1.165 22-Sep-2007 martin

replace even more ctob and btoc with ptoa and atop respectively plus
uvm_extern.h where needed


Revision tags: OPENBSD_4_2_BASE
# 1.164 22-Jul-2007 kettenis

Move hppa to __HAVE_TIMECOUNTERS.


# 1.163 20-Jul-2007 kettenis

Give hppa the blink_led API from sparc64, and the associated machdep.led_blink
sysctl.


# 1.162 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.161 14-Jul-2007 kettenis

Make sigreturn(2) set the proper space ID for the instruction queue. Fixes
a few more pthreads regression tests.

ok miod@


# 1.160 10-Jul-2007 kettenis

Don't trust the privilige level in the sigcontext passed to sigreturn(2).

ok miod@


# 1.159 24-Jun-2007 kettenis

Crank initial storage for extents a bit. We really should allocate extents
using malloc once vm is initialised, but this will do for now.

ok deraadt@


# 1.158 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.157 27-May-2007 miod

Make sure the minaddr hint for uvm_km_suballoc() calls is always initialized.
ok pedro@


# 1.156 26-May-2007 pedro

Dynamic buffer cache. Initial diff from mickey@, okay art@ beck@ toby@
deraadt@ dlg@.


# 1.155 21-May-2007 kettenis

Add support for 8700/pcxw2 cpu.


# 1.154 21-May-2007 kettenis

Ask firmware for reset before trying ourselves; needed for four-digit b/c/j
workstations.

tested by otto@, krw@; ok deraadt@


# 1.153 17-May-2007 art

Limit hppa buffer cache to 30%. It used to be 70% because stack garbage
that was used for minaddr instead of the proper vm_map_min(kernel_map)
(fixed in this diff).

From mickey. art@ ok


# 1.152 14-May-2007 martin

move hppa to __HAVE_CPUINFO

input from miod@, ok kettenis@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.151 28-May-2006 martin

minor nit, use CPU ID instead of FPU ID for BTLB parameters after passing
all kludges


# 1.150 15-Apr-2006 martin

make warning about missing HPT support DEBUG for now

ok mickey@


Revision tags: OPENBSD_3_9_BASE
# 1.149 26-Oct-2005 martin

no more hppa_round_page() and hppa_trunc_page() macros

ok mickey@


Revision tags: OPENBSD_3_8_BASE
# 1.148 06-Aug-2005 miod

We do not need a char machine_arch[] constant.
ok deraadt@


# 1.147 11-Jul-2005 mickey

align some stupid comments


# 1.146 10-May-2005 mickey

set pcsq in case we get signal delivery once interrupted from the gateway page; from chs


# 1.145 18-Apr-2005 mickey

do not do some of the initmsgbuf()s job


# 1.144 07-Apr-2005 mickey

on some machines it's possible to limit the amount of physmem initialised dring post so having msgbuf at the end of memory shall work


# 1.143 07-Apr-2005 mickey

64bit-friendly pdc.h and iomod.h and correspondent changes elsewhere


# 1.142 26-Mar-2005 mickey

md parts for hpux_compa code; some problems w/ signals delivery still exist


Revision tags: OPENBSD_3_7_BASE
# 1.141 24-Feb-2005 mickey

do not even ask for btlb on 8k cpus as pdc pretends there is some but then it does not work; found w/ Moritz Kiese <mbk@mytum.de> on c180; add a debug print and fix pcxu entry


# 1.140 17-Nov-2004 mickey

print real/avail/bufcache sizes as unsigned


# 1.139 26-Oct-2004 mickey

disable sid hashing on pcxu and above


# 1.138 14-Oct-2004 mickey

a bit larger delays during boot() to let msgs appear


# 1.137 19-Sep-2004 mickey

turn totalphysmem into physmem and name old physmem into smth it really is


# 1.136 18-Sep-2004 mickey

oops


# 1.135 15-Sep-2004 mickey

add pcxu tlb handlers and cpu probing
add u2/uturn ioa driver in dumb mode now
enable pcxu/pcxw support


# 1.134 14-Sep-2004 mickey

store fpu version for later use. make sure to proper store/clear fpu state in fork/exec/exit/sendsig


# 1.133 14-Sep-2004 mickey

error out from btlb_insert() if there is none


Revision tags: OPENBSD_3_6_BASE
# 1.132 01-Jul-2004 mickey

have separate insn and data cache all-flushers


# 1.131 30-Jun-2004 mickey

allow forced fpu emulation through a sysctl


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.130 13-May-2004 mickey

8ks do not have hvt


# 1.129 05-May-2004 mickey

much easier tlb handler branch patching


# 1.128 05-May-2004 mickey

do not engage HPT on PCXT' (yet)


# 1.127 08-Apr-2004 mickey

repair pcxs/t confoosion


# 1.126 07-Apr-2004 mickey

update copyright; miod@ is fine w/ files where he holds it too


Revision tags: OPENBSD_3_5_BASE
# 1.125 10-Mar-2004 tom

Ensure that we obey a user's ddb> boot reboot command even if the system
is cold (during startup).

This adds RB_USERREQ to sys/reboot.h, uses it in the ddb commands, and
ensures that */*/machdep.c:boot() won't set RB_HALT when cold if this
flag is set.

ok deraadt@


# 1.124 14-Feb-2004 grange

Simplify hw.{cpuspeed,setperf} api moving all the sysctl stuff
from the underlying callbacks.

Testing hppa mickey@, ppc drahn@
Ok markus@ tedu@


# 1.123 05-Jan-2004 mickey

kill debugging code that is not needed anymore


# 1.122 23-Dec-2003 mickey

provide cpuspeed fluff


# 1.121 20-Dec-2003 miod

Don't let microtime() return a struct timeval with exactly 1000000 microseconds.


# 1.120 18-Dec-2003 mickey

spls do not protect cpu_itmr and thus time might jump back sometimes due to cpu_itmr modified to a higher value than a read itmr; found and testing by miod@


# 1.119 17-Dec-2003 mickey

in the real mem print do not include reserved for prom into used by openbsd


# 1.118 10-Dec-2003 mickey

for unaligned btlb mapping attempts -- just fail


# 1.117 24-Nov-2003 mickey

experimental support for HVT as a 2nd level tlb


# 1.116 15-Oct-2003 mickey

less global name space pollution


# 1.115 05-Oct-2003 mickey

reload the itmr as soon as we get the intr to avoid lagging on slower machines


# 1.114 25-Sep-2003 mickey

some pcxl2 do not report fpus -- assume it's there


Revision tags: OPENBSD_3_4_BASE
# 1.113 04-Sep-2003 mickey

a better cpu identification; testing by miod


# 1.112 31-Aug-2003 miod

pdc_model needs to be visible from cpu.c


# 1.111 20-Aug-2003 mickey

missing nl in debugging prontf


# 1.110 07-Aug-2003 mickey

dead proto


# 1.109 07-Aug-2003 mickey

first allocate space on stack then copyout signal shits. add a DEBUG check for a whacky user pc (as impossible due to the recent trap.c change)


# 1.108 03-Aug-2003 mickey

clear branch and nullify bits in psw on sending a signal


# 1.107 30-Jul-2003 mickey

deduce the leds address from the model number and thus make some more use of that lichtenblinkenschmutz on some more machinens


# 1.106 22-May-2003 mickey

imprecision in delay_init()


# 1.105 18-May-2003 mickey

save the fpu state for the signal handler. this is essential
as the fpu regs can be used by the gcc even for non-fpu
means and data copying.
rearrange the sigcontext a bit to include only the general
registers that are needed restoring upon return and thus
less waste of space and make up some space for the fpu regs.

ALL software that used the signal context on the stack
needs at least rebuilding now. a new snap has bin built as well.


Revision tags: UBC_SYNC_A
# 1.104 11-May-2003 deraadt

string cleaning; krw ok


# 1.103 07-Apr-2003 mickey

s/HP9000/HP 9000/; from weissmanndude


Revision tags: OPENBSD_3_3_BASE
# 1.102 18-Feb-2003 deraadt

knf; mickey ok


# 1.101 12-Feb-2003 jason

How uncommon... hppa only has one common: msgbufmapped (decl'd in /sys/kern)


# 1.100 12-Feb-2003 mickey

only align the first stack frame onto the minimal required alignment


# 1.99 10-Feb-2003 mickey

fix pcs and pcxt recognition. from weissmanndude


# 1.98 22-Jan-2003 mickey

consistantly use uvm_prot_* vs vm_prot_* evewrhere


# 1.97 14-Jan-2003 mickey

fix cutnpaste in the cpu table for the itlbna field; from herr weissmanndude


# 1.96 14-Jan-2003 mickey

need pdc_hwtlb always; pt out by herr weissmanndude


# 1.95 13-Jan-2003 mickey

fix the logic in hvt probing


# 1.94 09-Jan-2003 miod

Remove fetch(9) and store(9) functions from the kernel, and replace the few
remaining instances of them with appropriate copy(9) usage.

ok art@, tested on all arches unless my memory is non-ECC


# 1.93 19-Dec-2002 mickey

setregs: put the whole frame setup into one place


# 1.92 19-Dec-2002 mickey

level 0x16 is really an l2


# 1.91 17-Dec-2002 millert

Make SysV-style shared memory and semaphore limits sysctl'able.
Instead of allocating a static amount of memory for the data
structures via valloc() in allocsys(), allocate things dynamically
using pool(9) when possible and malloc(9) when not. The various
members of struct seminfo and struct shminfo are in kern.seminfo
and kern.shminfo respectively (not all members of kern.seminfo are
changable).

The data structures used still leave something to be desired but
things are not made worse in that respect by this commit.


# 1.90 27-Nov-2002 mickey

no wrapper arounf hardclock(), use CPU_CLOCKUPDATE, real microtime; miod ok


# 1.89 08-Nov-2002 mickey

Don't uvm_useracc the user sigcontext in sys_sigreturn and then access
the user addresses directly from the kernel. copyin is faster and can
correctly deal properly with mappings that uvm_useracc thinks are
correct but will fault anyway (to figure out how to generate such
mappings is left as en excercise for the reader).


# 1.88 01-Nov-2002 mickey

add a missing delay after printf on halt[-p], proper arg for a cold hook


Revision tags: UBC_SYNC_B
# 1.87 22-Oct-2002 mickey

do not force single-user; pt out by fries@


# 1.86 15-Oct-2002 mickey

missing initmsgbuf(), noticed by miod@


# 1.85 13-Oct-2002 mickey

track the end of physmem for use in dmmem_alloc


# 1.84 07-Oct-2002 mickey

s/PSW_/PSL_/ to match other archs


# 1.83 07-Oct-2002 mickey

proper terminate the user stack on signal


# 1.82 07-Oct-2002 mickey

on implementations w/ fpu included unimplemented instructions
are signaled through the exception trap w/ invalid opcode marked
instruction in the exception registers, not through the emulation
trap (as long as the fpu is enabled, of course).
parse emulation from the exception trap as well as the emulation
trap and fix the dispatcher into usable condition.
parse invalid op exception on trap and signal the user appropriately.
reset the exception on exec and for child on fork.
the later is appropriate since exceptions are delayed until next
fpu instruction, which was in the parent indeed, let him get it.
save parent's fpu context on fork before cipying it, if the
parent owned the fpu.


Revision tags: OPENBSD_3_2_BASE
# 1.81 23-Sep-2002 mickey

parisc level 0x10 is just an overclocked 0xe


# 1.80 17-Sep-2002 mickey

handle fpu exceptions properly, might use a regress, i guess


# 1.79 11-Sep-2002 mickey

provide a convinient reset label


# 1.78 11-Sep-2002 mickey

stack grows the other way, but the frame is the other way to that. hehe


# 1.77 09-Sep-2002 mickey

set up the frame flags and a user frame better on exec


# 1.76 03-Aug-2002 mickey

rework boot() w/o a goto


# 1.75 25-Jul-2002 mickey

missing arg in the call to the pdc_call since some old times


# 1.74 25-Jul-2002 mickey

kcopy is a space-to-space copy from kernel space, to guess where, -- to the same kernel space, just error on fault


# 1.73 20-Jul-2002 art

Instead of copying out the signal trampoline on top of the stack, create
an uvm aobj, copy out the signal trampoline into it and share that page
among all processes for the same emulation.

This also requires us to actually be able to tell signal code where the
trampoline is located, so introduce a new field in struct proc - p_sigcode
that is a pointer to sigcode. This allows us to remove all the ugly
calculations of the signal trampoline address done in every sendsig
function in the tree (that's why so many files are changed).

Tested by various people. ok deraadt@


# 1.72 14-May-2002 mickey

disable sid hashing while still in real mode, alos print the parisc arch once and not per each cpu since they are not intermixable architecture-wise


# 1.71 13-May-2002 mickey

ldi-ldo whatever was in the table, be that much clever


# 1.70 08-May-2002 mickey

print parisc level w/ the the parisc version, not for each cpu


# 1.69 08-May-2002 mickey

kill debugging printfski


# 1.68 22-Apr-2002 mickey

no longer batc the data, only the code.
this removes a constraint and an ld.script dependancy
for the .data and the dynamically allocated kernel
structures existed w/ batcing. also makes pmap_steal_memory
obsolete and replaced w/ the pmap_virtual_space.
implement batching for pmap_remove to avoid
zeroing out the pte entries if pde will be removed anyway.


# 1.67 21-Apr-2002 mickey

better buf's mapping and less magic constants in checking for io space cachability


Revision tags: OPENBSD_3_1_BASE
# 1.66 26-Mar-2002 mickey

if cannot guess cpu model default to the lowest supported one


# 1.65 25-Mar-2002 deraadt

spelling


# 1.64 23-Mar-2002 espie

Add variables for config(8) -e time tweak of systemV shared memory
parameters.

Ok millert@, miod@, maja@


# 1.63 19-Mar-2002 mickey

mtcpu seq requires a pre-sync, implement hpt init for pcxl


# 1.62 15-Mar-2002 mickey

rewrite a pmap to use multilevel page tables.
lower 12 bits contain the perms, no unused bits left,
but a couple for off-tlb use (as the ref implemented now).
do not use the hvt, which might get some use later
if proven to speed thigs up, tlb handlers would po
another dozen of insns though, but if that's worth its...
move on the data seg and map kernel text rdonly (idea form fredette),
since all of the page0 mods done before that we are all fine
except for some viper fluff, but later w/ that.
this also picks up a bit more of ddb magic for bpt and ss.
tlb handlers can use a little bit more of attention,
but things, visually, seem to be much faster already, --
sorry, no benchmarks for now.

* effort sponsored in part by the `henry st. old ale house'
* and mr.pete and mr.lee in particular in thier generous entrirety.
* the proj took a little more that 72man*h as it was expected,
* but within murhy's law estimations.


# 1.61 14-Mar-2002 millert

First round of __P removal in sys


# 1.60 20-Feb-2002 mickey

setup power failure handler (for sw-controlled power button), move toc handler


# 1.59 17-Feb-2002 maja

Patch from Daniel Lucq <daniel@lucq.org>

The patch allows you to change the value of NMBCLUSTERS, BUFCACHEPERCENT
and NKMEMPAGES using the config command, instead of recompiling the kernel.

This is the kernel part of the patch. I have compiled it on i386, sparc64,
alpha and macppc. -moj ok art@ maja@


# 1.58 12-Feb-2002 mickey

support 712's programmable power switch, no interrupt yet


# 1.57 12-Feb-2002 mickey

small repairs to hpmc and toc handlers


# 1.56 11-Feb-2002 mickey

disable fpu on csw, print fpu version on cpu line, if present


# 1.55 07-Feb-2002 mickey

fix sigdebug cases; init sigcontext before it's used (;


# 1.54 06-Feb-2002 mickey

implement signal delivery; based on fredette@'s work


# 1.53 03-Feb-2002 mickey

restore hpt size computation, does not break things as i thought


# 1.52 02-Feb-2002 mickey

fix 'physmem' usage


# 1.51 02-Feb-2002 mickey

implement the rest of /dev/mem devices; from netbsd


# 1.50 23-Jan-2002 art

move mb_map allocation to mbinit()


# 1.49 23-Jan-2002 art

move definition of mb_map from zillions of machdep.c to uipc_mbuf.c


# 1.48 16-Jan-2002 miod

Don't include <sys/map.h> when you don't need what's in it.


Revision tags: UBC_BASE
# 1.47 02-Dec-2001 mickey

branches: 1.47.2;
increase fixed extent storage


# 1.46 28-Nov-2001 art

zap some typedefs.
vm_map_t -> struct vm_map *
vm_map_entry_t -> struct vm_map_entry *
simple_lock_data_t -> struct simplelock

(uvm not done yet, coming in the next commit)


# 1.45 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.44 24-Nov-2001 miod

Harmonize boot() logic across arches:
- ensure RB_DUMP | RB_HALT will cause a dump
- or RB_HALT if (cold)
While there, honor RB_TIMEBAD on sparc64.


# 1.43 09-Nov-2001 art

nswbuf hasn't been used for ages. gc.


# 1.42 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.41 06-Nov-2001 miod

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


Revision tags: OPENBSD_3_0_BASE
# 1.40 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.39 12-Sep-2001 art

mbutl no more


# 1.38 23-Aug-2001 art

We can now move timeout_init into main().


# 1.37 23-Aug-2001 art

Remove even more old timeout tentacles.


# 1.36 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.35 05-Jul-2001 art

Get rid of REAL_CLISTS. It was never implemented and the tentacles are
everywhhere.


# 1.34 17-May-2001 provos

convert mbuf and cluster allocation to pool, mostly from NetBSD
okay art@ miod@


# 1.33 05-May-2001 art

Rename configure() to cpu_configure().
Move it from cpu_startup() to main().


# 1.32 05-May-2001 art

Get rid of CLSIZE and all related stuff.
CLSIZE -> 1
CLBYTES -> PAGE_SIZE
OLOFSET -> PAGE_MASK
etc.
At the same time some archs needed some cleaning in vmparam.h so that
goes in at the same time.


Revision tags: OPENBSD_2_9_BASE
# 1.31 29-Mar-2001 mickey

cpudev_data.h here needed not


# 1.30 22-Mar-2001 mickey

shuffle the tlb handlers a little,
make a new one for na data fault,
since those w/ hpt need it.


Revision tags: OPENBSD_2_8_BASE
# 1.29 15-Aug-2000 mickey

two btlb routines (i & d) for pcxs


# 1.28 15-Aug-2000 mickey

expand per-cpu control routines switch


# 1.27 08-Aug-2000 mickey

print btlb params w/ BTLBDEBUG; from Havard.Eidnes@runit.sintef.no


# 1.26 02-Jul-2000 mickey

no bays for stinger


Revision tags: OPENBSD_2_7_BASE
# 1.25 23-Mar-2000 mickey

new cpu type switch code.
initializes tlb miss handlers correspondent to probed cpu features.
also btlb load routine.
versions written are for pcxl and others.
cpu-dep btlb loaders are missing, only generic for now.


# 1.24 23-Mar-2000 art

New API for timeouts. Replaces the old timeout()/untimeout() API and
makes it the callers responsibility to allocate resources for the
timeouts.

This is a KISS implementation and does _not_ solve the problems of slow
handling of a large number of pending timeouts (this will be solved in
future work) (although hardclock is now guarateed to take constant time
for handling of timeouts).

Old timeout() and untimeout() are implemented as wrappers around the new
API and kept for compatibility. They will be removed as soon as all
subsystems are converted to use the new API.


# 1.23 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


# 1.22 22-Feb-2000 mickey

blah, blah, blah, msgbuf


Revision tags: SMP_BASE
# 1.21 09-Feb-2000 mickey

branches: 1.21.2;
heartbeat -- yeah we have a patch for that


# 1.20 25-Jan-2000 mickey

better copy and zero inlines in locore;
proper setregs() in machedep;
start of hpmc handler;
some cleanup here and there;


# 1.19 17-Jan-2000 mickey

remove unneeded stuff from setregs; force single-user for now, enable signal debug


# 1.18 11-Jan-2000 mickey

s/fpu_curproc/fpu_curpcb/ which also points into physical.
move it's definition into locore (where it's used the most).
adjust fpu context switch and save on swapout accordingly.
fix context save (in switch).
add accounting for fpu context switches (since it differes
from proc switching, we might get provided w/ some usefull
numbers as to how effective this lazy switch technique is).
enable handling fpu/sfu exceptions.


# 1.17 31-Dec-1999 mickey

don't bother about pidr3 and pidr4


# 1.16 17-Dec-1999 mickey

fix the panic message for sti memory mapping


Revision tags: kame_19991208
# 1.15 25-Nov-1999 mickey

bus stuff is in mainbus now, the rest is rewritten many ways


Revision tags: OPENBSD_2_6_BASE
# 1.14 20-Sep-1999 mickey

fix uvm_pagealloc() call


# 1.13 03-Sep-1999 art

Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.12 14-Aug-1999 mickey

proper debugging ifdefs


# 1.11 21-Jul-1999 mickey

rewrite the tlb miss handler and tlb dirty handler.
optimize for HVT usage (when compiled for proper cpu type).
drop hpt_* global variables, use info from control registers instead.
there are still ways to improve the tlb handlers tho.
machdep also prints cache and tlb coherence states (not related to the above).
You eat greenish muffin. --More-- You write real code.


# 1.10 12-Jul-1999 mickey

allocate 5% bufcache if <=16M memory installed


# 1.9 12-Jun-1999 mickey

hppa_init() now takes an argument from locore,
meaning the start of available memory.
cleanup machdep somewhat.
fix vm_map.pmap vs vm_pmap isue; 10x art@


# 1.8 23-May-1999 mickey

new swap stuff


# 1.7 21-May-1999 mickey

group all theMD f;ags together, add interrupt recursion one


# 1.6 21-May-1999 mickey

define fpu_curproc


# 1.5 20-Apr-1999 mickey

do lazy blok mapping of io space in bus_*
add copy{in,out}*, kcopy, etc
boot routines
cpu-id-hpux-compat stuff
rest of scheduler and such
uvm


Revision tags: OPENBSD_2_5_BASE
# 1.4 17-Feb-1999 mickey

print pa-risc here as well, since, finally, cpu will have to print processor type


# 1.3 04-Jan-1999 mickey

better cache handling in bus_space_barrier(), seem to work now


# 1.2 03-Jan-1999 mickey

implement bus_space_{un,}map w/ extents


# 1.1 30-Dec-1998 mickey

machdep; more work needed