History log of /netbsd-current/sys/arch/sparc64/sparc64/locore.s
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.434 17-Feb-2024 palle

Ensure that the size of the stack is properly specified (2*USPACE) so it matches the allocation of stack pages done in pmap_bootstrap(). If this is not properly in sync, then the stack pointer may end up in the redzone right before the stack causing mmu faults. This issue has been observed on a T2000 (sun4v) system while probing the devices (pci/ebus/com) during bootstrap


Revision tags: thorpej-ifq-base thorpej-altq-separation-base
# 1.433 01-Mar-2023 riastradh

sparc64: Optimization: Omit needless membar when triggering softint.

When we are triggering a softint, it can't already hold any mutexes.
So any path to mutex_exit(mtx) must go via mutex_enter(mtx), which is
always done with atomic r/m/w, and we need not issue any explicit
barrier between ci->ci_curlwp = softlwp and a potential load of
mtx->mtx_owner in mutex_exit.

PR kern/57240

XXX pullup-8
XXX pullup-9
XXX pullup-10


# 1.432 23-Feb-2023 riastradh

sparc64: Add missing barriers in cpu_switchto.

Details in comments.

PR kern/57240

XXX pullup-8
XXX pullup-9
XXX pullup-10


Revision tags: netbsd-10-base bouyer-sunxi-drm-base
# 1.431 05-Jul-2022 andvar

branches: 1.431.4;
fix various typos in comments.


# 1.430 27-Jun-2022 andvar

fix various typos in comments.


# 1.429 22-May-2022 andvar

fix various small typos, mainly in comments.


# 1.428 16-May-2022 mrg

try to handle ultrasparc III* "fast ecc error" traps.

i had a sunblade 2500 reset with this trap recently, and the
manual says it should have been recoverable. in particular,
the US IIIv2 manual says in section 12.4.4.2 that the i-cache
won't see this data ever (so nothing needed there), and that
the d-cache needs to be disabled, and all the entries flushed,
and then re-enabled.

tested with a "trap 0x70" from kernel space, that trap.c
converted the "0x170" back to "0x70" (with an ADVANCE). this
code not commited.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 1.427 03-Apr-2021 palle

Improve cpu_idle() by allowing a platform specific implementaion (same logic as the sparc implementation) - currently only used by sun4v


# 1.426 30-Mar-2021 palle

sun4v: handle spill trap properly when trap level is 1 and otherwin is non-zero - ensure that all windows are spilled to the pcb like the sun4u winfixsave code path


# 1.425 22-Feb-2021 palle

branches: 1.425.2;
sun4v: handle spill normal user traps properly when current trap level is 1 - registers are spilled to the PA of the stack to avoid further mmu-related traps, since sun4v only has 2 trap levels


# 1.424 20-Dec-2020 palle

sun4v: add comment in sun4v_tl1_ptbl_miss code path - no functional change


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1
# 1.423 08-Jan-2020 skrll

branches: 1.423.6;
oldlwp is always non-NULL in cpu_switchto so remove the test for NULL.


# 1.422 08-Jan-2020 ad

Hopefully fix some problems seen with MP support on non-x86, in particular
where curcpu() is defined as curlwp->l_cpu:

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

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

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

- Remove some KERNEL_LOCK handling which hasn't been needed for years.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 ad-namecache-base netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.421 18-Jul-2019 palle

branches: 1.421.2; 1.421.4;
sun4v: added some missing comments to the code in pcbspill


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 1.420 07-Apr-2019 mrg

make trap 0x70 a TRAP() not UTRAP(). we should be able to handle
fast ECC error as a normal trap, and i saw this once a few years
ago but it never repeated so i haven't been able to test this.


# 1.419 08-Feb-2019 palle

sun4v: Improve comment for next_stick_init() - no functional changes


# 1.418 08-Feb-2019 palle

sun4v: initialize %stickcmpr properly when establishing interrupt - fixes issue seen on newer sun4v/SPARC-T5 system where the interrupt never fires.


# 1.417 08-Feb-2019 palle

sun4v: introduce macros for handling spill traps from userlevevel @ traplevel 1 (from OpenBSD) - spill traps at level 1 from userspace now works better


# 1.416 08-Feb-2019 palle

sun4v: add comment documenting the contents of the %g2 register - no functional changes


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126
# 1.415 04-Nov-2018 palle

Ensure that the 64-bit condition codes are used instead of the 32-bit condition codes. ok martin@


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.414 26-May-2018 palle

branches: 1.414.2;
next_stick() - fix typy in comment: tick->stick


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.413 11-Apr-2018 palle

sun4v: handle MMU-related traps properly when they occur at trap level 1. This fixes issues when user-level LWPs access the user-level stack


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 1.412 26-Aug-2017 palle

branches: 1.412.2;
sun4v: Avoid touching the %tick_cmpr register which is not present on never systems (Oracle SPARC Architecture 2011 and beyond). Based on code from OpenBSD locore.s revision 1.177. Tested on both sun4u (qemu and USIII) and sun4v (qemu and T5-2). ok martin@


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2
# 1.411 06-May-2017 palle

branches: 1.411.2;
sun4v: The %ver register is not available on sun4v - use GET_MAXCWP introduced in rev. 1.361. Verified using qemu (sun4u and sun4v) and on real sun4v hw (t2000)


Revision tags: prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.410 18-Apr-2017 palle

branches: 1.410.2;
sun4v: Add handling of trap 0x06c @ trap level 1 - based on code from OpenBSD, but slightly adapted to NetBSD. verified using qemu


Revision tags: jdolecek-ncq-base pgoyette-localcount-20170320
# 1.409 19-Feb-2017 palle

sun4v: rft_user needs special handling (a manual fill) since the restore instruction may cause the number of trap levels to exceed the maximum for sun4v - inspired by code from the the openbsd rft_user code path - verified using qemu for both sun4u and sun4v


# 1.408 10-Feb-2017 palle

sun4v: Added handling of trap type 0x034 (address alignment error) + fixed typo mmfsa -> mmufsa. Verified for both sun4u and sun4v using qemu.


Revision tags: nick-nhusb-base-20170204
# 1.407 30-Jan-2017 palle

sun4v: Hook up syscall handling to the trap table. Verified using qemu for both sun4u and sun4v.


# 1.406 27-Jan-2017 palle

sun4v: implement missing handling of itsb traps 0x008 and 0x009. Based on code from OpenBSD. Tested using qemu.


Revision tags: bouyer-socketcan-base
# 1.405 07-Jan-2017 palle

branches: 1.405.2;
sun4v: slowtrap() now selects normal globals properly on both sun4u and sun4v platforms. Verified using qemu for both sun4u and sun4v systems


Revision tags: pgoyette-localcount-20170107
# 1.404 05-Jan-2017 palle

sun4v: TRAP_SETUP() updated to set mmu context id properly for both sun4v and sun4u platforms. Verified using qemu for both sun4u and sun4v systems


# 1.403 04-Jan-2017 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x00-0x23 and 0x28-0x30


# 1.402 29-Dec-2016 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x32-0x7f


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.401 20-Sep-2016 nakayama

Fix RAS for 32-bit kernels. trapframe is always 64-bit.


Revision tags: localcount-20160914
# 1.400 23-Aug-2016 palle

sun4v: rework sun4v_datatrap so it works properly when running on a T2-based system like T5120 - for some reason %tl is 0 when entering sun4v_datatrap causing a crash (sir instruction), so ignore the %tl value for now upon entry to sun4v_datatrap - with this fix both T1 and T2 based systems reach the same point - hangs in rft_user after the init process is started


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726
# 1.399 18-Jul-2016 palle

sun4v: handle device interrupts properly - both legacy (sysino) and cookies


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 1.398 04-Jun-2016 palle

branches: 1.398.2;
sun4v: rtf_user now uses macros GET_MMU_CONTEXTID and SET_MMU_CONTEXTID. Tested on sun4u (QEMU) and sun4v (T2000). Parts from OpenBSD.


Revision tags: nick-nhusb-base-20160529
# 1.397 18-May-2016 nakayama

Decrement %tl in trap handler not to make it zero unconditionally
for the nested trap, and remove useless mov.


# 1.396 17-May-2016 palle

sun4v: Implement missng MMU protection trap handling - mostly from OpenBSD


# 1.395 16-May-2016 palle

Avoid assembler-specific defines by using the export keyword in genassym.cf instead


# 1.394 15-May-2016 nakayama

%g1 is not preserved across function call, so load it before
return_from_trap.


# 1.393 13-May-2016 palle

sun4v: add missing implementation of sun4v_datatrap_tl0 so data_access_fault() is called - mostly from OpenBSD


# 1.392 13-May-2016 nakayama

- ci_paddr is always 64-bit.
- intrlev is array of pointer.
- ih_ack is pointer.


# 1.391 10-May-2016 palle

sun4v: make device interrupts work. Introduce a new intrhand_alloc() function for allocation of interrupt handlers and adapt to this. Parts from OpenBSD. ok martin@


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.390 09-Mar-2016 nakayama

32-bit kernels use 32-bit stack.


# 1.389 03-Mar-2016 palle

sun4v: rft_kernel should pay attention to the number of register windows that can be restored. We cannot rely on fill traps to occur, since sun4v only has two trap levels available in privileged mode. Based on code from OpenBSD. ok martin@


# 1.388 14-Feb-2016 palle

sun4v: add breakpoint trap entry to the sun4v trap table


# 1.387 03-Feb-2016 palle

sun4v: extend dmmu_set_secondary_context() to handle both sun4u and sun4v. ok martin@


Revision tags: nick-nhusb-base-20151226
# 1.386 06-Nov-2015 martin

Basically revert r1.246 of locore.s and r1.73 of vm_machdep.c:

Remove special case handling for userland lwps from cpu_lwp_fork,
instead do it in lwp_trampoline when we first return to userland.

which was a stupid idea - since we did now set all fork child's %tstate
(and thus %pstate when back in userland) to the current kernel's userland
default. This meant we lost the address mask bit for 32bit processes and
all memory model details for 64bit ones.

Move it back to cpu_lwp_fork and fix the condition to only do it once when
forking init.


# 1.385 05-Nov-2015 martin

Most of the time return_from_trap already got called with tf->tf_tstate
loaded in register %g1 - make it so for two more callers and remove
the reload of that value.


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606 nick-nhusb-base-20150406
# 1.384 05-Apr-2015 palle

sun4v: Ensure that the TTEs CP and CV bits are the same (both set) for the primary cpu and secondary cpus INTSTACK mappings


# 1.383 01-Apr-2015 palle

sun4v: Implement handling of cpu_mondo trap - from OpenBSD - tested using the Legion simulator


# 1.382 04-Mar-2015 palle

sun4v: revert some of the logic introduced in revision 1.378 - flushw is not necessary on sun4v (OpenBSD patches the flushw instruction to a nop instruction) - with these changes the kernel reaches cpu_boot_secondary_processors() when running in the Legion simulator (crashes due to missing handling of cpu_mondo_trap)


# 1.381 02-Mar-2015 nakayama

prom_printf converts "\n" to "\r\n" internally, so omit "\r".


# 1.380 02-Mar-2015 nakayama

PANICSTACK is a pointer itself, not a pointer to pointer.


# 1.379 02-Mar-2015 nakayama

Use panic stack temporarily for calling prom_printf in a trap
handler.

It seems that openfirmware cannot handle over 4GB pointers, and
stack pointers may point to over 4GB since VA layout was rearranged
by rev 1.33 of vmparam.h. Therefore, use panic stack to avoid
panicking in OF_write used by prom_printf.


# 1.378 23-Feb-2015 palle

sun4v: sparc_interupt - ensure that the trap level and globals level are the same when the flushw instruction is issued - othwise warnings occur when using the sun4v Legion simulator.


Revision tags: nick-nhusb-base
# 1.377 26-Oct-2014 palle

branches: 1.377.2;
sun4v: Create CLEANWIN0 and CLEANWIN1 macros for handling clean window traps on both sun4u and sun4u (based on the original code inlined in the sun4u trap table). Update trap tables accordingly for both sun4u and sun4v. Ok martin@


# 1.376 24-Oct-2014 nakayama

Fix typo in comment.


# 1.375 18-Oct-2014 snj

src is too big these days to tolerate superfluous apostrophes. It's
"its", people!


# 1.374 15-Oct-2014 palle

sun4v: fixed bug causing the real address to be incorrectly calculated as zero


# 1.373 24-Sep-2014 palle

sun4v: add code to enable startup of secondary cpus on both sun4u and sun4v systems - ok martin@


# 1.372 04-Sep-2014 palle

sun4v: All cpus must be setup with a TSB descriptor, so pmap_setup_tsb_sun4v() must take a pointer to the TSB descriptor


# 1.371 31-Aug-2014 palle

sun4v: Split the NORMAL_GLOBALS and ALTERNATE_GLOBALS macros to _SUN4U and _SUN4V variants. Rework the return_from_trap logic to use the new variants so it is possible to use a global register as scratch register.


# 1.370 14-Aug-2014 nakayama

Add missing delay slot in DEBUG kernel.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.369 30-Jul-2014 palle

branches: 1.369.2;
Fix ALTERNATE_GLOBALS so it at least works on sun4u - using a scratch register is not a good idea...


# 1.368 27-Jul-2014 palle

sun4v: Introduce a new macro ALTERNATE_GLOBALS (matching NORMAL_GLOBALS). Two new helper macros ENABLE_INTERRUPTS and DISABLE_INTERRUPTS are also created. With these changes the GENERIC.UP kernel will reach rootmount on sun4v systems - ok martin@


# 1.367 26-Jul-2014 palle

Improved the NORMAL_GLOBALS macro in the sun4u case, so only the relevant bit (AG) in %pstate is affected - ok martin@


# 1.366 24-Jul-2014 palle

sun4v: add missing spill/fill handling for trap level 1 + cosmetic changes to comments for trap level 0 entries


# 1.365 19-Jul-2014 palle

sun4v: Introduce a NORMAL_GLOBALS macro - first used in sparc_interrupt - other relevant uses will be handled as the sun4v work is progressesing - ok martin@


# 1.364 16-Jul-2014 palle

sun4v: Introduce SET_MMU_CONTEXTID macro for setting the mmu context id on both sun4u and sun4v


# 1.363 13-Jul-2014 palle

sun4v: add interrupt handling to sun4v trap table


# 1.362 13-Jul-2014 palle

Bugfix: add missing cmp instruction to GET_MAXCWP macro


# 1.361 30-Jun-2014 palle

sun4v: The maximum number of register windows is a constant and thus not available via the %ver register (sun4u only). Introduce a macro GET_MAXCWP that handles this, so cpu_switchto() works properly on sun4v. Other relevant reference to %ver can be adapted to use GET_MAXCWP as the sun4v port progresses. OK martin@


# 1.360 31-May-2014 palle

sun4v: added missing dtsb miss handling for trap level 1 - with this update the kernel now reaches configure() on sun4v systems


# 1.359 30-May-2014 palle

Remove debugging code introduced by accident in locore.s revision 1.357


Revision tags: yamt-pagecache-base9 rmind-smpnet-nbase rmind-smpnet-base
# 1.358 05-May-2014 palle

sun4v: the trap base address should be assigned to %l1 so %tba is properly setup later in the code - now the kernel gets as far as printing the copyright disclaimer, kernel version and total and available memory before crashing


# 1.357 21-Apr-2014 palle

sun4v: Update comment: modified -> access


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.356 21-Feb-2014 palle

branches: 1.356.2;
sun4v: Rename TLB_ defines to SUN4U_TLB_ so entries created using TSB_DATA() are properly setup for sun4u and sun4v. Relocate the cputyp variable from autoconf.c to locore.s and make it const in param.h so optimized code can be generated. Parts from OpenBSD. Optimization suggested by nakayama@. OK martin@, mrg@, nakayama@


# 1.355 31-Jan-2014 tsutsui

defined(LKM) -> defined(MODULAR)


# 1.354 26-Jan-2014 palle

sun4v: Add handling of spill/fill and dtsb miss traps (with a XXX to be handled later)


# 1.353 07-Jan-2014 palle

sun4v: trap table setup - currently populated with dummy entries which will be properly implemented later - parts from OpenBSD - OK martin@


# 1.352 29-Dec-2013 nakayama

Make buildable w/o options SUN4V.


# 1.351 27-Dec-2013 palle

a) make the hunt through the cpus list more generic b) sun4v: ensure that the interrupt stack is mapped permanently and the TSB is setup properly - parts from OpenBSD. OK martin@


# 1.350 06-Dec-2013 nakayama

Increase an interrupt depth only in the case of hardware interrupts,
and remove the ci_idepth trick in softint_fastintr.

Fixes the following diagnostic panic reported in port-sparc64.

panic: kernel diagnostic assertion "!cpu_intr_p()" failed: file
"../../../../kern/subr_xcall.c", line 351


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 1.349 24-May-2013 nakayama

branches: 1.349.2;
Disable interrupts after calling data_access_error as with
data_access_fault.


# 1.348 28-Apr-2013 nakayama

Use macros in machine/asm.h instead of locally defined, and
introduce CASPTRA for casxa/casa.


Revision tags: agc-symver-base
# 1.347 23-Jan-2013 martin

Fix sparc64_ipi_ccall by adding proper trap setup.
Fixes xcall(9) problems, as exposed by pserialize(9). Noticed by
J. Hannken-Illjes, cause pointed out by Takeshi Nakayama.


# 1.346 23-Jan-2013 martin

Sligthly clean up the (by default unused) #ifdef TRAPS_USE_IG


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.345 10-Nov-2012 nakayama

Revise comment.


# 1.344 10-Nov-2012 nakayama

Use macro instead of magic number.


# 1.343 09-Nov-2012 nakayama

Make setstick() and getstick() to inline functions.


# 1.342 08-Nov-2012 macallan

use system tick timer instead of %tick on UltraSPARC-III-ish CPUs
review & fixes by Takeshi Nakayama


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.341 17-Mar-2012 mrg

branches: 1.341.2;
port the corrected ECC error handling code from freebsd. i noticed my U10
took one of these and then hang. it shouldn't hang, there's a 'sir' here that
doesn't seem to reset properly. oh well.

tested by simulated a trap via 'ta 0x10' and considering that the same, but
it hasn't been tested against a real ECC error yet.


Revision tags: jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base4
# 1.340 03-Mar-2012 nakayama

Fix the root cause of the hack "disable optimizations for uvm_bio.c
on 32 bit kernels".

gcc converts a division in the calculation of UBC_UMAP_ADDR macro
to multiplication (smul or combination of add/sll), and the
register of its result contains a garbage in upper 32 bits (the
upper 32 bits of smul/add/sll's result isn't zero cleared).

Then it passes to pseg_get{,_real} through pmap_extract without the
zero clear of upper 32 bits in the optimization case. So the
result of pseg_get and pmap_extact sometimes gets screwed up.


Revision tags: jmcneill-usbmp-base5 jmcneill-usbmp-base3
# 1.339 19-Feb-2012 rmind

Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.


Revision tags: jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.338 04-Sep-2011 nakayama

branches: 1.338.2; 1.338.6; 1.338.8;
ih_pil is an interrupt level, not an interrupt mask.


# 1.337 27-Jul-2011 nakayama

ivec is assigned to hardware, so count its event counter up in
interrupt_vector, not in softint, and do some optimization.


# 1.336 20-Jul-2011 macallan

add per ivec event counters


# 1.335 12-Jul-2011 mrg

rename sparc64 BLOCK_SIZE and BLOCK_ALIGN to have SPARC64_ prefixes.
for the assembler files, define the old names to the new names
since using the new names cause ugliness due to longer identifer
names, and reduces churn.

fixes build issues in dtv and vaguely makes <machine/psl.h> slightly
less name-space invasive.


# 1.334 18-Jun-2011 nakayama

Add fast softint(9) support for sparc64.

Reviewed on port-sparc64.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 1.333 12-May-2011 mrg

branches: 1.333.2;
first steps towards fujitsu SPARC64 support:

- SPARC64 systems have interrupts with upto 14 bits set, but we only look
at the first 11 bits. trim non IPI interrupts to 11 bits


Revision tags: uebayasi-xip-base7 bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 jym-xensuspend-nbase jym-xensuspend-base
# 1.332 20-Dec-2010 matt

branches: 1.332.2;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.


Revision tags: uebayasi-xip-base6 uebayasi-xip-base5 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 1.331 10-Jul-2010 nakayama

Clear the upper word explicitly before combining two 32-bit values to 64-bit
on 32-bit kernels.


# 1.330 23-May-2010 martin

Split copy related functions out of locore.s into copy.S, move functions
only needed on multiprocessors into mp_subr.S.


# 1.329 17-May-2010 martin

Simplify primary CPU startup slightly by using the fact that our cpuinfo's
curpcb pointer points to the uarea/pcb of lwp0 and by remembering the pointer
to this cpuinfo, thus avoiding a few CPUINFO_VA references.


Revision tags: uebayasi-xip-base1
# 1.328 20-Mar-2010 chs

fix copy{in,out}{,str}() to return the error returned by uvm_fault().
fixes PR 41813.


Revision tags: yamt-nfs-mp-base9
# 1.327 10-Mar-2010 mrg

branches: 1.327.2;
XXX: workaround we'd like to remove when pmap / uvm locking is cleaned up:

- rename pseg_get() and pseg_set() to pseg_get_real() and pseg_set_real().
- if USE_LOCKSAFE_PSEG_GETSET is defined, which it current is by default,
define pseg_[gs]et() in terms of functions that take a new pseg_lock
mutex at IPL_VM while calling into the real functions.

this seems to avoid the pseg_set() crashes we've seen:
1 - spare needed, when pseg_get() just worked for this pmap
2 - the 2rd ldxa via ASI_PHYS_CACHED in pseg_set() loads garbage
into %o4, and causes the 3rd ldxa to fault


# 1.326 08-Mar-2010 mrg

blast_dcache() SMP friendly:

- blast_dcache() becomes sp_blast_dcache(dcache_size, dcache_line_size)
- new smp_blast_dcache(sparc64_cpuset_t) that blasts the D$ on this cpuset
- sparc64_ipi_blast_dcache() to support the above
- in pmap_remove_all(), when freeing mmu contexts for this pmap, mark
the set of cpus to blast the d$ on as well and convert the
blast_dcache() call into smp_blast_dcache() on the cpus who ran this
pmap, or, sp_blast_dcache(dcache_size, dcache_line_size)
- convert the remaining blast_dcache() in machdep.c to sp_blast_dcache()
- in pmap_destroy()/pmap_remove_all() take the pmap_lock() always since
we assert it is held always.

with these changes, NFS builds on the U60 seem to be stable now, and
the USIII machines also can often complete a single build.sh run now,
diskful or diskless.


reviewed by mlelstv and partially by martin, tested by martin and myself,
with some ideas from chuq as well.


# 1.325 07-Mar-2010 mrg

need _ALIGN in locore.h as well, for DEBUG kernels.


# 1.324 07-Mar-2010 mrg

gas has supported SPARC ".empty" for a long while; get rid of an
ancient workaround.


# 1.323 06-Mar-2010 mrg

move the memcpy/memset implementations out into their own file, with the
block copy versions as well. move some of the definitions in locore.s
into a new locore.h.

locore.s is almost 2000 lines shorter with this change.


# 1.322 04-Mar-2010 mrg

- in _bus_dmamap_unload(), pmap_page_protect() and pmap_clear_reference()
switch the dcache_flush_page() into a dcache_flush_page_all()
- in both pmap_kremove()/pmap_remove(), remove the blast_dcache() call
and replace it with dcache_flush_page_all()
- in pmap_get_page() [used to allocate PTP's], always call pmap_zero_page(pa)
- flush the dcache of the dst page in pmap_{copy,zero}_page() by redirecting
throught a C function that calls the (renamed) asm. the old asm code had a
comment about needing to do this...
- add a couple of membar #Sync's that the USIII manual recommends


based on discussions with chuq@, skrll@ and martin@.


these help my SB2000 / SB2500 with both disk / nfs builds and other tasks,
sometimes lasting for several hours before failing or asserting.


# 1.321 24-Feb-2010 mrg

when handing back page table pages to UVM, flush them from the dcache
on all CPUs.

idea from skrll@, and makes my disk-based SB2000 stable.

tested on U60, SB2000 and SB2500.


# 1.320 24-Feb-2010 mrg

- re-introduce sp_tlb_flush_pte() and sp_tlb_flush_all() that call
the right USI/USIII version.
- define tlb_flush_pte() in terms of sp_tlb_flush_pte() for the
!MULTIPROCESSOR case

this centralises some CPU_IS_USIII_UP() tests.


# 1.319 22-Feb-2010 mrg

move {dump,print}_[id]tlb() into a separate file.


# 1.318 22-Feb-2010 mrg

- store the maximum [id]cache size / line size for each cpu

- remove patch_kernel() since it isn't necessary and has been patching
the wrong thing in general.

- implement USIII versions of blast_icache(), dcache_flush_page() and
cache_flush_phys(). use the newly recorded cache size/line sizes.

- in winfixsave, flush the D$ with the right size index and ops. this
kills one of the wrong tag->inval patches.

- for blast_dcache(), use the newly recorded dcache_size/line_size.

- for blast_icache(), use the newly recorded cache size/line sizes.
for the USIII verison, disable the I$ while writing to ASI_ICACHE_TAG.


these changes removed several hard coded cache sizes values, some very
wrong kernel patching, and seem to make the current failure modes for
USIII less common, but not gone.


# 1.317 15-Feb-2010 mrg

- don't flush 32-bit entries for 64-bit code, it does not seem to be
necessary. #define TLB_FLUSH_LOWVA to turn it back on.
- remove the #if 0'd code in sparc64_ipi_flush_pte_usiii(), i have
verified that it is not required.
- add a missing membar #Sync to sp_tlb_flush_pte_usiii().


# 1.316 15-Feb-2010 nakayama

Fix linker error of GENERIC32 kernel.


# 1.315 15-Feb-2010 mrg

use TLB_SIZE_SPITFIRE in a couple of places, and note that the
{print,dump}_[id]tlb() versions are currently spitfire specific.


# 1.314 15-Feb-2010 mrg

introduce a new patch_kernel() and call it from the end of bootstrap().
use it to patch up TLB flush instructions that don't match for USI/II
and later. we can also hopefully use this to make GENERIC.MP minimally
expensive on single CPU machines as well.

this is the last piece needed to get GENERIC/GENERIC.MP to boot on the
USIII* machines.

idea and some initial code from openbsd.


# 1.313 13-Feb-2010 mrg

remove KTR support. it's never been a working part of netbsd src tree.


# 1.312 09-Feb-2010 wiz

Fix typo in comment.


Revision tags: uebayasi-xip-base
# 1.311 06-Feb-2010 mrg

branches: 1.311.2;
- properly map the schizo interrupt registers, so we can use the normal
virtual mappings to access them.
- with the above fxied, kill SCHIZO_BUS_SPACE_BROKEN, and introduce
an options CHEETAH for now, that disables the SPITFIRE code in locore.
- merge schizo_init() into schizo_attach() and clean up the softc a bit.


with this we are only one more step away from GENERIC booting on USIII
machines.


# 1.310 02-Feb-2010 mrg

- split sp_tlb_flush_pte() and switchtoctx() into sp_tlb_flush_pte_us()/
sp_tlb_flush_pte_usiii() and switchtoctx_us()/switchtoctx_usiii() and
implement the latter while i'm here. it works ... sometimes i think,
but also sometimes panics/hangs.
- fix a comment in sparc64_ipi_flush_pte_usiii()


# 1.309 02-Feb-2010 mrg

for now, reduce a few #ifdef SPITFIRE cases by introducing a new
ASI_DCACHE_TAG_OR_INV that is either ASI_DCACHE_{TAG,_INVALIDATE}.

increase the common code in cache_flush_phys().


# 1.308 01-Feb-2010 mrg

- sp_tlb_flush_all() becomes sp_tlb_flush_all_us() and sp_tlb_flush_all_usiii()
- sparc64_ipi_flush_pte() becomes sparc64_ipi_flush_pte_us() and
sparc64_ipi_flush_pte_usiii()
- add some commented out code to disable interrupts and raise the traplevel
in sparc64_ipi_flush_pte_usiii()
- cache_flush_phys() was missing a little of code in the cheetah case


# 1.307 01-Feb-2010 mrg

for USIII, use the new "tlb demap all" operation in sp_tlb_flush_all()


# 1.306 01-Feb-2010 mrg

remove unused icache_flush_page() implementation.


# 1.305 23-Jan-2010 mrg

remove the final uses of DATA_START.

now we can remove the 16KB space reserved at the start of the data segment,
and i now understand why i wrote this now removed comment 3.5 years ago:
"this shouldn't be needed... but kernel usually hangs without it"


# 1.304 23-Jan-2010 mrg

remove most of the code that writes debugging info DATA_START + offset.


# 1.303 23-Jan-2010 mrg

remove CHKPT() macro and uses. it's likely wrong in SMP land and probably should
be replaced with KTR-style uses if necessary.


# 1.302 23-Jan-2010 mrg

fix a comment.


Revision tags: matt-premerge-20091211
# 1.301 10-Dec-2009 rmind

Rename L_ADDR to L_PCB and amend some comments accordingly.


# 1.300 05-Dec-2009 mrg

- adjust the PA mask to the 43 bits supported by USIII.
- rework the spitfire/cheetah cache_flush_phys() to avoid several #ifdefs
- add a membar #Sync after sparc64_ipi_drop_fpstate (probably unnecessary)


# 1.299 30-Nov-2009 nakayama

sp_tlb_flush_pte for cheetah:
- restore interrupts properly in case of %tl > 0.


# 1.298 30-Nov-2009 mrg

stablize UP USIII support by blocking interrupts around sp_tlb_flush_pte()
i was seeing stack corruption while taking an interrupt in this function.

get USIII SMP mostly working by implementing the cheetah version of
sparc64_ipi_flush_pte().


SMP support is still not entirely stable. i can reproducably get a:

panic: fpusave_lwp ipi didn't

while running build.sh, when an awk process is exiting. other simple
heavy work loads do not crash for me right now.


# 1.297 30-Nov-2009 mrg

delete some no longer used code:
- smp_tlb_flush_ctx()
- smp_tlb_flush_all()
- sparc64_ipi_flush_ctx()
- sparc64_ipi_flush_all()
- sp_tlb_flush_ctx()


# 1.296 29-Nov-2009 nakayama

- calculate end PA correctly.
- wrap more spitfire specific (flushing I$) code.
- fix inverted #if condition for flushing I$ (and restore ASI_ICACHE_TAG).


# 1.295 28-Nov-2009 mrg

implement enough code to get SB2000/SB2500 booting to multiuser. does
not last long if you use it, but an idle machine has stayed up 10 hours.

- for the !SPITFIRE case, use ASI_DCACHE_INVALIDATE instead of
ASI_DCACHE_TAG when clearing tlb entries. from openbsd.

- convert some comment "! Not yet" into "WRITEME", so that attempting
to build a USIII MULTIPROCESSOR kernel fails to build until the code
is written.

- add some more WRITEME's for the above.

- implement a !SPITFIRE version of sp_tlb_flush_all(). since there are
no spare regs, for now just always increase %tl around this call. (we
could maybe store a token in %o3 along with the saved %pstate info.)


# 1.294 26-Nov-2009 matt

Kill proc0paddr. Use lwp0.l_addr instead.


# 1.293 25-Nov-2009 mrg

s/L_ADDR/L_PCB/, requested by rmind.


# 1.292 17-Oct-2009 nakayama

Wrap unused code with #if 0 which is called from #if 0'ed code.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5
# 1.291 30-May-2009 martin

cpu_setfunc() can not use lwp_trampoline, as that has additional lwp startup
semantics. Use a simpler setfunc_trampoline instead.


# 1.290 18-May-2009 nakayama

Remove random() from locore.s since it is in libkern.


# 1.289 16-May-2009 nakayama

Remove clear %tick in locore.s since it is cleared at cpu_initclocks() in
clock.c.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 nick-hppapmap-base mjf-devfs2-base
# 1.288 15-Dec-2008 mrg

restore some old "intrdebug" code, but leave it under NOT_DEBUG. most
of it works, but one that prints func/arg for each handler is not very
stable...

for now, while schizo bus space pointer accesses aren't working, add
a SCHIZO_BUS_SPACE_BROKEN option so you can build a kernel with schizo.

with this, and the prior schizo interrupt fix, you can now fail to run
/sbin/init!


Revision tags: haad-dm-base2 haad-nbase2 haad-dm-base
# 1.287 09-Dec-2008 martin

Get rid of get_maxctx() - it doesn't work on newer cpus and we will have
to find a better way for (some) sun4v machines - all sun4u use 13 bit
contexts anyway.


Revision tags: netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 ad-audiomp2-base netbsd-5-base
# 1.286 30-Oct-2008 nakayama

branches: 1.286.2; 1.286.6;
Wrap more code specific to USE_BLOCK_STORE_LOAD.


Revision tags: matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4
# 1.285 05-Oct-2008 nakayama

branches: 1.285.2;
- in flushing cache, use 32 as increment/decrement value to match the
cache line size.
- remove useless restore of %asi.
- remove nop in delay slot if we can.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 1.284 10-Jul-2008 nakayama

Use proper CCR.


# 1.283 10-Jul-2008 nakayama

sparc64_ipi_save_fpstate:
- use primary MMU context for consistency with other trap/interrupt handlers.

sparc64_ipi_save_fpstate, savefpstate:
- avoid storing fp registers as we can.

sparc64_ipi_save_fpstate, savefpstate, loadfpstate:
- remove unaligned case since buffers allocated with pool_cache are ensured
64-byte aligned.

Ok by martin@.


# 1.282 02-Jul-2008 nakayama

branches: 1.282.2;
UltraSPARCs don't have floating point queue, and reading %fq regsiter
will cause illegal instruction trap. So remove the code handling them.


# 1.281 29-Jun-2008 nakayama

Wrap IPI calls with #ifdef MULTIPROCESSOR.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.280 14-Jun-2008 nakayama

Close unterminated comment.
Fix unexpected behavior in case of loadfpstate from unaligned buffer.


Revision tags: yamt-pf42-base3
# 1.279 31-May-2008 nakayama

branches: 1.279.2;
openfirmware_exit:
- disable interrupts with %pstate.
- prepare 64-bit stack and enable 64-bit addresses for 32-bit SMP kernels.


Revision tags: hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 yamt-nfs-mp-base yamt-pf42-base
# 1.278 16-Apr-2008 nakayama

branches: 1.278.2; 1.278.4; 1.278.6;
Disable TRAPSTATS which was accidentally enabled when yamt-idlelwp branch
was merged.

Ok by martin@.


# 1.277 14-Apr-2008 nakayama

Remove sparc64_ipi_sync_tick.

Since we can use counter-timer as timecounter instead of %tick on SMP kernel,
it is not necessary to sync all CPUs %tick registers.


# 1.276 14-Apr-2008 nakayama

Add workaround for BB_ERRATA_1 on writing to TICK_CMPR register in
next_tick(). If writing to TICK_CMPR fails, we lose hardclock interrupt
on secondary CPUs.

About BB_ERRATA_1 from comment in OpenSolaris:

/*
* Writes to the TICK_COMPARE register sometimes fail on blackbird modules.
* The failure occurs only when the following instruction decodes to wr or
* wrpr. The workaround is to immediately follow writes to TICK_COMPARE
* with a read, thus stalling the pipe and keeping following instructions
* from causing data corruption. Aligning to a quadword will ensure these
* two instructions are not split due to i$ misses.
*/


# 1.275 28-Mar-2008 nakayama

Don't read fplwp content in delay slot for considering the case fplwp was
modifiled.

Reported by Chris Ross on port-sparc64.


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.274 20-Mar-2008 nakayama

- remove disabling interrupt in IPI.
- unused VA bits in MMU demap is 13 bits, not 12 bits.


# 1.273 18-Mar-2008 nakayama

Fix a race when increment an interrupt level event counter.


# 1.272 17-Mar-2008 nakayama

Fix a race condition in IPI handlers of save/drop fpstate, from OpenBSD.
Reported and tested by martin@.


# 1.271 17-Mar-2008 nakayama

Make schedintr interrupt handler per-CPU.
While there rename tickintr interrupt handler and share initialization
code with schedintr.


# 1.270 14-Mar-2008 nakayama

Improve IPI handling:
- make IPI takes two arguments.
- add IPI event counters per-CPU.
- implement IPI functions which were missing or broken.
- insert DELAY while halting primary CPU in IPI handler.


# 1.269 02-Mar-2008 nakayama

- make interrupt pending list per-CPU.
- make tickintr() MP-safe.
- remove unused port-sparc derived interrupt code.

Ok by martin@.


# 1.268 02-Mar-2008 nakayama

Don't get IPI handler argument (from bogus address), and ack IRQ twice.


# 1.267 28-Feb-2008 martin

Make TSBs and MMU contexts per-cpu.


Revision tags: nick-net80211-sync-base mjf-devfs-base hpcarm-cleanup-base
# 1.266 26-Jan-2008 nakayama

branches: 1.266.2; 1.266.6;
Fix for 32-bit kernels.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.265 15-Jan-2008 skrll

Store a sensbile PCB_PC value in snapshot - the return point.

This helps gdb somewhat.

OK'd by martin.


# 1.264 14-Jan-2008 martin

Fix register name typo/copy&pasto - %g6 is not %o6/%sp.
From OpenBSD.


Revision tags: matt-armv6-base
# 1.263 06-Jan-2008 martin

Load the next cpu_info pointer with LDPTR instead of ld.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2
# 1.262 09-Dec-2007 martin

branches: 1.262.2;
Provide cpu_intr_p(), at least for non-MULTIPROCESSOR kernels.
Based on suggestions by Andrew Doran.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.261 22-Oct-2007 martin

branches: 1.261.2; 1.261.4; 1.261.6;
Remove an unused .globl declaration


Revision tags: yamt-x86pmap-base4
# 1.260 17-Oct-2007 garbled

Merge the ppcoea-renovation branch to HEAD.

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

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

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base ppcoea-renovation-base vmlocking-base
# 1.259 09-Sep-2007 martin

branches: 1.259.4;
Make cpufrequency and friends per cpu values.
Prepare a hz tick interrupt on secondary CPUs via %tick, but do not
enable it yet, as it breaks ddb.


# 1.258 09-Sep-2007 martin

Do not ACK IPIs before we finished loading all arguments.


# 1.257 06-Sep-2007 martin

Remove the (now unused) second 64k page mapped per CPU.
From matthew green, with small changes by me. All bugs are mine.


# 1.256 25-Aug-2007 martin

branches: 1.256.2;
Remove INITSTACK completely - at the time we used to switch to it, we
already have access to all of lwp0 and it's uarea - so we can switch
to the correct lwp0 stack easily before calling main.


# 1.255 25-Aug-2007 martin

When exiting to OF, use the interrupt stack instead of INITSTACK


# 1.254 25-Aug-2007 martin

Rework cpu_mp_startup slightly:
- temporarily use the cpu's interrupt stack untill we are ready
to access non-OF-based mappings, then directly switch to the cpu's
idlelwp's uarea stack
- disable interrupts untill we are ready to call C code


# 1.253 13-Aug-2007 macallan

remove two restore without matching save


Revision tags: nick-csl-alignment-base matt-mips64-base mjf-ufs-trans-base
# 1.252 06-Jul-2007 martin

branches: 1.252.4; 1.252.8;
A few nits for 32bit SMP kernels, noticed by mrg.
While there, simplify the fpstate IPIs a bit.


# 1.251 05-Jul-2007 martin

sparc64_ipi_save_fpstate is not a leaf function - create a full grown
stack frame.


# 1.250 28-May-2007 mrg

clean up cpu_switchto() a little - no need to flushw or membar
excessively. optimise an rdpr. tested by tnn.


# 1.249 23-May-2007 martin

Fix a stupid bug in the save_fpstate ipi, which caused overwriting of
struct lwp of the lwp owning the fpu. Fix clearing the fplwp - %o0 will
not survive the call to savefpstate - duh!


# 1.248 20-May-2007 martin

Simplify tf_tstate setting when leaving for userland initially - I seem
to have confused the if with the else case of the previous C code.
Funny that it worked at all.


# 1.247 20-May-2007 martin

cpu_switchto() has to return it's first arg, always. This differs from
my reading of the documentation, but helps in the real world and seems
to be what other ports do.


# 1.246 20-May-2007 martin

Remove special case handling for userland lwps from cpu_lwp_fork, instead
do it in lwp_trampoline when we first return to userland.


# 1.245 19-May-2007 martin

cpu_idle is a leaf function, so we better "return from leaf".
Use return value from cpu_switchto for previous lwp in lwp_trampoline.
Also shamelessly steal a comment from uwe written for sparc that explains
all this.
Thanks to tnn, mrg, and uwe for helping to debug this.


# 1.244 17-May-2007 yamt

merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base ad-audiomp-base
# 1.243 22-Feb-2007 martin

branches: 1.243.4; 1.243.6; 1.243.12;
uvm.page_idle_zero now is a bool, not a 32bit value any more.


# 1.242 21-Feb-2007 mrg

shave 9 insns off the tsb setup in cpu_initialize & cpu_mp_startup.


# 1.241 21-Feb-2007 martin

Get rid of unused (thus always zero) "curlwp" variable hidden in assembler
code (C code always uses a cpuinfo based macro).


# 1.240 18-Feb-2007 martin

Make use of another call delay slot, pointed out by uwe.


# 1.239 18-Feb-2007 martin

Make use of a call delay slot and avoid a bogus EMPTY.
Spotted by Juergen Hannken-Illjes, with input from Andrew Doran and
Valeriy E. Ushakov.


# 1.238 18-Feb-2007 martin

Whitespace cosmetics


# 1.237 18-Feb-2007 martin

Backout previous: EMPTY was misused


# 1.236 18-Feb-2007 martin

Make EMPTY expand to nop with gas, as it is used to mark empty branch
delay slots.


# 1.235 15-Feb-2007 martin

branches: 1.235.2;
Fix obvious copy&pasto in SCHED_DEBUG register usage.


Revision tags: post-newlock2-merge
# 1.234 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.233 25-Dec-2006 wiz

Spell "relevant" correctly. From Zafer Aydogan.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.232 25-Oct-2006 mrg

branches: 1.232.2; 1.232.4;
- note that __idle_u should go away but doing so breaks things
- fix several comments to reality
- clean up the #ifdef NO_VCACHE code slightly
- use call instead of set/jmpl
- remove a couple of unnecessary stores to curlwp


Revision tags: yamt-splraiseipl-base2
# 1.231 18-Oct-2006 rjs

Clean up some comments. Cosmetic change to use correct structure
offset names.

Optimize out two instructions from sparc64_ipi_save_fpstate and
sparc64_ipi_drop_fpstate.


# 1.230 17-Oct-2006 mrg

allocate 128KB (as opposed to 64KB) per-cpu, and place the interrupt
stack, cpu_info structure, panicstack, idle uarea and normal kernel
stack in here. the idle uarea and kernel stack are in the 2nd 64KB
page. the interrupt stack and cpu_info structure are as the same
place in the 1st 64KB page, and the panicstack grows down from the
top of this page. update comments in param.h to suit (XXX: a lot
of these constants should move to a header file that will not pollute
the name space so much.) map these pages identically between
cpu_initialise() and cpu_mp_startup(), and deal with the two 64KB
pages in pmap_extract(). keep an unmapped 64KB page between them.

don't initialise the unused "ci_eintstack" member of the cpu_info
structure

use constants to initialise many addresses in the cpu_info structure,
consolidating these assignments from cpu0 and cpu>0

delete u0/estack0/panicstack from locore.s

clean up some wrong comments in locore.s

fix a 32bit-only bug in cpu_mp_startup().

delete 'u0' entirely.


this fixes recent random lossage seen on port-sparc64: processes
stuck in RUN state, data faults, and hangs.


# 1.229 04-Oct-2006 mrg

use call instead of set/jmpl. add an entry point for idle that expects
sched_lock to be unlocked, and use this for non-boot cpu's. complete a
comment describing how registers in idle_switch are expected to be set.


# 1.228 03-Oct-2006 mrg

use the same SAVE_LOCALS_INS definition for 32 bit and 64 bit kernels.
refactor TRAP_SETUP() a little between these two versions to be more alike.


# 1.227 03-Oct-2006 mrg

use the correct size/type for MP variables (pointers and longs).

a 32 bit MULTIPROCESSOR kernel now builds (and crashes quickly.)


# 1.226 03-Oct-2006 mrg

in the 64bit version of SAVE_LOCAL_INS, s/BIAS/STKB/ to allow future
sharing of the 32 and 64 bit versions of the {TRAP,INTR}_SETUP macros.


# 1.225 19-Sep-2006 mrg

- remove some way old FP setup/teardown code
- put the block memcpy/memset inside #ifdef USE_BLOCK_STORE_LOAD which
is (now) defined.

no functional change, same .o is generated.


# 1.224 19-Sep-2006 mrg

re-order the changes in rev 1.217 to give registers a little bit of
time to settle between usage, like it was before hand.


# 1.223 19-Sep-2006 mrg

- remove a wrong comment.
- add a new entry point for idle called idle_switch that is called by
cpu_switch() in the MP case when sched_whichqs is zero, properly
setting up the idle stack. from petrov@ via martin@.


# 1.222 19-Sep-2006 mrg

rework interrupt_vector() slightly:
- for the IPI case, avoid loading the address of intrlev into %g3
- remove some NOT_DEBUG code
- load the interrupt argument #2 in the delay slot

this removes 2 nops during interrupt processing for the normal
case, and an additional 2 ALU instructions for IPIs


# 1.221 18-Sep-2006 mrg

- sparc64_ipi_halt(): we shouldn't return from sparc64_ipi_halt_thiscpu()
so replace a branch with a 'sir'
- in #if 0 code, in sparc64_ipi_flush_pte() and sparc64_ipi_flush_ctx()
save/restore the out registers that the sp_tlb_flush_xxx() versions
around calling them
- in sp_tlb_flush_pte() and sp_tlb_flush_ctx(), replace global register
usage with out registers so that we don't clobber the (alternate)
global registers when these are called from IPI context


# 1.220 18-Sep-2006 mrg

- remove an extra 'sir' that followed one in a macro
- add some named labels to some spill/fill handlers
- remove 2 unused strings


Revision tags: yamt-splraiseipl-base
# 1.219 18-Sep-2006 martin

branches: 1.219.2;
Lazy FPU handling for the MULTIPROCESSOR case


# 1.218 16-Sep-2006 nakayama

From OpenBSD:
- reload %fprs for checking it again.
- use symbolic names for checking in %fprs.

revision 1.51
date: 2005/07/18 14:50:11; author: deraadt; state: Exp; lines: +2 -1
cache a copy of the fprs so we know what fp restore we should do after

revision 1.50
date: 2005/07/14 01:46:13; author: deraadt; state: Exp; lines: +4 -4
use symbolic names for checking in %fprs, as above


# 1.217 16-Sep-2006 nakayama

Fix a couple of %y register save/restore errors, inspired from OpenBSD.

revision 1.44
date: 2004/04/23 04:18:17; author: marc; state: Exp; lines: +5 -4

fix a couple of %y register save/restore errors
1) don't save %y in a register that is later used before restoring %y
2) always restore %y after calling a signal handler
tested by drahn@, OK pval


# 1.216 15-Sep-2006 martin

Do not bother to save fpu state when we are about to get rid of it.


Revision tags: yamt-pdpolicy-base9
# 1.215 13-Sep-2006 mrg

SMP cleanup. provide support for multiple CPUs in DDB. (SMP itself
is still not working.)

cpu.h:
- add a pointer for DDB regs in SMP environment to struct cpu_info
- remove the #defines for mp_pause_cpus() and mp_resume_cpus()
cpuset.h:
- remove CPUSET_ALL() and rename CPUSET_ALL_BUT() to CPUSET_EXCEPT()
from petrov.
db_machdep.h:
- rename the members of db_regs_t to be the same as sparc
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- redo DDB_REGS to no longer be a pointer to a fixed data structure
but to one allocated per-cpu when ddb is entered
- move a bunch of prototypes in here
intr.h:
- remove SPARC64_IPI_* macros, no longer used
db_interface.c:
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- make "nil" a 64 bit entity
- change the ddb register access methods to work in multiprocessor
environment, it is now very much like sparc does it
- in kdb_trap() avoid accessing ddb_regp when it is NULL
- update several messages to include the cpu number
- unpause other cpus much later when resuming from ddb
- rename db_lock() to db_lock_cmd(), as the sparc-like code has
db_lock as a simple lock
- remove "mach cpus" command, and replace it with "mach cpu" (which
does the same) and also implement "mach cpu N" to switch to
another cpus saved trapframe
db_trace.c:
- update for the ddb_regs -> ddb_regp change
genassym.cf:
- add TF_KSTACK as offsetof(struct trapframe64, tf_kstack)
ipifuncs.c:
- overhaul extensively
- remove all normal interrupt handlers as IPI's, we now handle
them all specially in locore.s:interrupt_vector
- add a simplelock around all ipi functions - it's not safe for
multiple cpus to be sending IPI's to each other right now
- rename sparc64_ipi_pause() to sparc64_ipi_pause_thiscpu() and,
if DDB is configured, enable it to save the passed-in trapframe
to a db_regs_t for this cpu's saved DDB registers.
- remove the "ipimask" system (SPARC64_IPI_* macros) and instead
pass functions directly
- in sparc64_send_ipi() always set the interrupt arguments to 0,
the address and argument of the to be called function. (the
argument right now is the address of ipi_tlb_args variable, and
part of the reason why only one CPU can send IPI's at a time.)
don't wait forever for an IPI to complete. some of this is
from petrov.
- rename sparc64_ipi_{halt,pause,resume}_cpus() to
mp_{halt,pause,resume}_cpus()
- new function mp_cpu_is_paused() used to avoid access missing
saved DDB registers
- actually broadcast the flush in smp_tlb_flush_pte(),
smp_tlb_flush_ctx() and smp_tlb_flush_all(). the other end may
not do anything yet in the pte/ctx cases yet...
kgdb_machdep.c:
- rework for changed member names in db_regs_t.
locore.s:
- shave an instruction from syscall_setup() (set + ld -> sethi + ld)
- remove some old dead debug code
- add new sparc64_ipi_halt IPI entry point, it just calls the C
vector to shutdown.
- add new sparc64_ipi_pause IPI entry point, which just traps into
the debugger using the normal breakpoint trap. these cpus usually
lose the race in db_interface.c:db_suspend_others() and end up
calling the C vector sparc64_ipi_pause_thiscpu().
- add #if 0'ed code to sparc64_ipi_flush_{pte,ctx}() IPI entry
points to call the sp_ version of these functions.
- in rft_kernel (return from trap, kernel), check to see if the
%tpc is at the sparc64_ipi_pause_trap_point and if so, call
"done" not "retry"
- rework cpu_switch slightly: save the passed-in lwp instead of
using the one in curlwp
- in cpu_loadproc(), save the new lwp not the old lwp, to curlwp
- in cpu_initialize(), set %tl to zero as well. from petrov.
- in cpu_exit(), fix a load register confusion. from petrov.
- change some "set" in delay branch to "mov".
machdep.c:
- deal with function renames
pmap.c:
- remove a spurious space
trap.c:
- remove unused "trapstats" variable
- add cpu number to a couple of messages


# 1.214 09-Sep-2006 mrg

significant clean up effort, largely from petrov@ via martin@.

- fix a bunch of comments for proc->lwp
- remove old TRAPTRACE, NOT_DEBUG, etc. code that has bit-rotted
- put some older DEBUG code under NOT_DEBUG
- add a bunch of new debugging/tracing code ("KTR") that depends on
other changes not yet present.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base yamt-pdpolicy-base5 chap-midi-base simonb-timecounters-base rpaulo-netinet-merge-pcb-base
# 1.213 14-May-2006 elad

branches: 1.213.6; 1.213.8;
integrate kauth.


# 1.212 12-May-2006 skrll

Fix some comments.


Revision tags: elad-kernelauth-base
# 1.211 09-May-2006 rjs

Load CPCB in cpu_mp_startup.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.210 11-Feb-2006 cdi

branches: 1.210.2; 1.210.4; 1.210.6;
ANSIfication: u_intN_t -> uintN_t, use ANSI function declarations/definitions
instead of K&R ones.


# 1.209 27-Jan-2006 cdi

branches: 1.209.2; 1.209.4;
Alter sparc64 bootstrap, catch up to ofwboot v1.9:

- Accept bootinfo structure passed down from ofwboot v1.9
- Drop kernel re-mapping code
- Use permanent 4MB mappings provided by the loader instead
- Change kernel entry address to point directly at the code instead of pointing
at the trap table's first slot. This allows the bootloader to detect
those kernels which are aware of the new boot scheme
- Due to the changes in kernel mapping code, alter secondary CPU bootstrap
code to use trampoline just like FreeBSD does (some FreeBSD code is used
here as well)


# 1.208 12-Jan-2006 cdi

Fix a typo: %g0 should be used instead of %o0 when initializing FPU in dostart:
and cpu_mp_startup:, %o0 is not even initialized at this point.


# 1.207 11-Dec-2005 christos

branches: 1.207.2;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 1.206 10-Jul-2005 christos

Re-factor syscall, and make it use syscall_{plain,fancy}.


# 1.205 31-May-2005 chs

branches: 1.205.2;
remove vestigal {,e}intr{names,cnt} symbols now that vmstat doesn't need them.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.204 12-Feb-2005 chs

branches: 1.204.4; 1.204.6; 1.204.8;
in sparc_interrupt(), wait to enable interrupts until just before calling
the handler and disable them again right after the handler returns.
we don't want another hardware interrupt coming in while we're mucking
with the list pointers. also, clear the intrhand's ih_pending pointer
before calling the handler rather than after, so that if another interrupt
comes in while the handler is running, we can put the intrhand back on
the list so it will be called again.

in send_softint(), disable interrupts via %pstate instead of %pil, so that
hardware interrupts at higher levels are blocked while we manipulate the
intrpending list. also, if the intrhand already has ih_pending set,
don't bother poking the SET_SOFTINT register again, since being on the list
implies that there is already a softint pending in the hardware.

these appear to fix PR 21750 (the "sleep forever" problem).

while I'm here, remove more vestiges of the !INTRLIST softint stuff
(code and comments). and in sparc64_ipi_flush_all(), interrupts are
already disabled so we don't need to fiddle with %pstate.


Revision tags: yamt-km-base2
# 1.203 30-Jan-2005 martin

Remove the no long usefull variants selected by undefining INTRLIST and
INTR_INTERLOCK to improve readability. Same object code generated as before.


Revision tags: yamt-km-base
# 1.202 16-Jan-2005 chs

branches: 1.202.2;
use ENTRY_NOPROFILE() for various entry points,
stack traces work better that way.


Revision tags: kent-audio1-beforemerge kent-audio1-base
# 1.201 03-Dec-2004 chs

branches: 1.201.4;
remove cache_flush_virt() and PADDRT, they're no longer used.
allocate a stack frame for blast_dcache() when profiling so it shows up.
in dcache_flush_page(), use a stride of 32 instead of 16 to match the
cache line size. correct various comments.


# 1.200 08-Nov-2004 petrov

Don't compile sparc64_ipi functions when UP.


# 1.199 25-Oct-2004 martin

No need to clear %o1 when returning a 64 bit integer from pseg_get if we
are compiling for a 64 bit kernel.


# 1.198 24-Jul-2004 nakayama

Change interrupt pending list end value to -1, to avoid linking an
interrupt handler twice.

It may fix "sleep forever" bug.


# 1.197 09-Apr-2004 petrov

Clean-up unused defines and variables.


Revision tags: netbsd-2-0-base
# 1.196 26-Mar-2004 petrov

branches: 1.196.2;
Use want_resched from cpu_info area.


# 1.195 23-Mar-2004 martin

Replace intrcnts by evcnts. XXX - needs slight tweaking for MULTIPROCESSOR.


# 1.194 14-Mar-2004 chs

checkpoint of MP work from dennis and myself. includes cross-processor
interrupt framework, a sledgehammer TLB invalidation and misc MP fixes.
doesn't work at all yet.


# 1.193 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.192 19-Jan-2004 martin

Rename switchexit to cpu_exit and g/c the old C implementation of cpu_exit.


# 1.191 18-Jan-2004 martin

Support RAS for 32bit kernels too.


# 1.190 16-Jan-2004 martin

In proc_trampoline don't bother to clear condition codes in the trap
frame, since we no longer rely on this.
While there fix a few comments.


# 1.189 08-Jan-2004 martin

Minor cleanup


# 1.188 06-Jan-2004 martin

Implement restartable atomic sequences (RAS) for sparc64.


# 1.187 06-Jan-2004 petrov

Spinup secondary cpus. Based on codes sent to me by Dennis Chernoivanov
and Chuck Silvers.


# 1.186 04-Jan-2004 jdolecek

update to recent changes - exit2() doesn't exist anymore and the
exit path always calls lwp_exit2()
pointed out Martin Husemann


# 1.185 02-Dec-2003 martin

Minor cleanup: remove unused code, sync a comment with current reality.


# 1.184 25-Nov-2003 cdi

Use per-cpu pcb, curlwp and fplwp rather than global ones. This brings
GENERIC.MP configuration to a usable state.

Approved by petrov@.


# 1.183 24-Nov-2003 cdi

Call 'proc_trampoline_mp' from 'proc_trampoline' in a multiprocessor
configuration. Fix process locking. Approved by petrov@.


# 1.182 20-Nov-2003 petrov

Remove nwindows calculation, it's not used. Set l_cpu in cpu_switch.


# 1.181 09-Nov-2003 martin

Get rid of bcopy/bzero.


# 1.180 26-Oct-2003 christos

Initial siginfo support for sparc64 (untested). COMPAT_16 sigcontext signal
delivery tested.


# 1.179 24-Aug-2003 chs

add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default. the changes
fall into two basic catagories:

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

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

originally from openbsd, adapted for netbsd by me.


# 1.178 08-Jul-2003 cdi

traceit: don't use %g7 as it is to become curcpu() register. Add comments.


# 1.177 18-May-2003 martin

branches: 1.177.2;
Make kernels with options KGDB at least compile.
Still needs some work to make it working.


# 1.176 29-Apr-2003 nakayama

Use BLOCK_ALIGN rather than BLOCK_SIZE for aligning a pointer.


# 1.175 27-Apr-2003 ragge

Preserve the symbol table in the LKM || KSYMS cases also.


# 1.174 04-Apr-2003 petrov

use branch slot in pmap_copy_page.


# 1.173 24-Mar-2003 nakayama

Divide `set' instruction in delay slot (from OpenBSD change to rev 1.30).


# 1.172 10-Feb-2003 martin

Remove some #if 0 code and a few XXX marked membars w/o proper
justification for their existence.


# 1.171 09-Feb-2003 martin

Remove left over pieces from reusing the signal trampoline for upcalls.
This should fix signal delivery for 32bit kernels.


# 1.170 05-Feb-2003 nakayama

Switch to use cycle counter (%tick) based microtime().

This is derived from alpha/microtime.c and i386/tsc_microtime.c,
and will share with both ports.

This should fix PR port-sparc64/18452.
(approved by martin)


# 1.169 04-Feb-2003 martin

Fix return value of pseg_set, which I accidently broke in rev. 1.164.

Fix register names in comment and shave off another register (hint
from uwe).


# 1.168 01-Feb-2003 martin

Rearrange register usage in pseg_set a bit and shave off %g4.


# 1.167 01-Feb-2003 martin

Remove a few #ifdef _LP64 by using STPTR/LDPTR macros.
Thanks to Matthew Green for the pointer.


# 1.166 31-Jan-2003 martin

Apply leaf procedure optimization to pseg_set (again).


# 1.165 31-Jan-2003 martin

Make the pmap count resident/wired mappings on the fly instead of
walking the page tables whenever this information is needed.

Add an option PMAP_COUNT_DEBUG to assert the new counts and the
page table walk agree.

The old solution had very bad performance impact, for example
by the high CPU load when running top(1).

Thanks to Simon Burge for pointing at the cause of the problem and
to Valeriy E. Ushakov for optimizing my simple minded assembler code.


# 1.164 27-Jan-2003 martin

Remove unused function pseg_find (which looked quite similar to
pseg_get anyway).


# 1.163 18-Jan-2003 thorpej

Merge the nathanw_sa branch.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.162 16-Jan-2003 petrov

Move dump_dtlb back under DDB.


# 1.161 15-Jan-2003 chs

fix two bugs in my last pmap rework:
- in tlb_flush_all(), don't skip TLB entries with the high bit on,
I was confused about which MMU register it was using. it's also fine
to use the last hardware context.
- in pmap_create(), don't allocate a hardware context for the new pmap.
it's unnecessary, and when this would cause us to recycle all the contexts,
it would result in the current process's context being set to 0
(ie. the kernel's context). the current process could then return to
userspace without going through the context-switch code (and thus without
having a hardware context reallocated). this would lead to user mappings
being entered in the kernel's context later, causing all sorts of trouble.
add some assertions to catch this kind of thing.


Revision tags: fvdl_fs64_base
# 1.160 25-Dec-2002 petrov

new function dump_itlb.


Revision tags: gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.159 22-Sep-2002 chs

many improvements:
- use struct vm_page_md for attaching pv entries to struct vm_page
- change pseg_set()'s return value to indicate whether the spare page
was used as an L2 or L3 PTP.
- use a pool for pv entries instead of malloc().
- put PTPs on a list attached to the pmap so we can free them
more efficiently (by just walking the list) in pmap_destroy().
- use the new pmap_remove_all() interface to avoid flushing the cache and TLB
for each pmap_remove() that's done as we are tearing down an address space.
- in pmap_enter(), handle replacing an existing mapping more efficiently
than just calling pmap_remove() on it. also, skip flushing the
TSB and TLB if there was no previous mapping, since there can't be
anything we need to flush. also, preload the TSB if we're pre-setting
the mod/ref bits.
- allocate hardware contexts like the MIPS pmap:
allocate them all sequentially without reuse, then once we run out
just invalidate all user TLB entries and flush the entire L1 dcache.
- fix pmap_extract() for the case where the va is not page-aligned and
nothing is mapped there.
- fix calculation of TSB size. it was comparing physmem (which is
in units of pages) to constants that only make sense if they are
in units of bytes.
- avoid sleeping in pmap_enter(), instead let the caller do it.
- use pmap_kenter_pa() instead of pmap_enter() where appropriate.
- remove code to handle impossible cases in various functions.
- tweak asm code to pipeline a little better.
- remove many unnecessary spls and membars.
- lots of code cleanup.
- no doubt other stuff that I've forgotten.

the result of all this is that a fork+exit microbenchmark is 34% faster
and a fork+exec+exit microbenchmark is 28% faster.


Revision tags: gehenna-devsw-base
# 1.158 18-Jul-2002 wiz

Spell 'should' correctly.


# 1.157 07-Jun-2002 eeh

Shave 10% off the time needed to flush the D$ through a bit of instruction
reordering.


# 1.156 05-Jun-2002 eeh

Handle improperly aligned stack pointers more cleanly.


# 1.155 04-Jun-2002 eeh

Fix the fork trampoline to properly use the supplied tstate.


# 1.154 31-May-2002 thorpej

Make this work with an ISO C preprocessor.


Revision tags: netbsd-1-6-base
# 1.153 14-May-2002 eeh

branches: 1.153.2; 1.153.4;
Only save locals and ins in trapframes for DEBUG kernels.


# 1.152 04-May-2002 kleink

Add some comments to the CPP conditionals controlling the trap macro
definitions, to ease navigation somewhat.


# 1.151 16-Apr-2002 eeh

Make lots of routines profile-friendly and get rid of some cruft.


Revision tags: eeh-devprop-base
# 1.150 21-Mar-2002 petrov

Not needed debug stuff deleted.


# 1.149 16-Mar-2002 mrg

tell newer binutils that our use of %g2 and %g3 is OK here.


# 1.148 15-Mar-2002 eeh

Cleanup MMU initialization to prevent hangs.


Revision tags: newlock-base ifpoll-base
# 1.147 09-Feb-2002 eeh

branches: 1.147.4;
Fix microsecond calculation in microtime.


# 1.146 07-Feb-2002 eeh

Fix register allocation in microtime().


# 1.145 29-Jan-2002 eeh

Shift the UPAID in the correct direction.


# 1.144 17-Jan-2002 eeh

Be more tolerant of unaligned stack pointers.


# 1.143 17-Jan-2002 eeh

Enable block insns in bcopy and bzero.


# 1.142 16-Jan-2002 eeh

In bcopy use 32-bit comparisons in 32-bit kernels.


# 1.141 16-Jan-2002 eeh

Use correct calculation for the trapframe in softtrap for ILP32.


# 1.140 20-Nov-2001 lukem

- pull in opt_kgdb.h where necessary
- replace opt_kgdb_machdep.h with opt_kgdb.h
- defparam opt_kgdb.h:
KGDB_DEV KGDB_DEVNAME KGDB_DEVADDR KGDB_DEVRATE KGDB_DEVMODE
- move from opt_ddbparam.h to opt_ddb.h:
DDB_FROMCONSOLE DDB_ONPANIC DDB_HISTORY_SIZE DDB_BREAK_CHAR SYMTAB_SPACE
- replace KGDBDEV with KGDB_DEV
- replace KGDBADDR with KGDB_DEVADDR
- replace KGDBMODE with KGDB_DEVMODE
- replace KGDBRATE with KGDB_DEVRATE
- use `9600' instead of `0x2580' for 9600 baud rate
- use correct quotes for options KGDB_DEVNAME="\"com\""
- use correct quotes for options KGDB_DEV="17*256+0"
- remove unnecessary dependancy on Makefile for kgdb_stub.o
- minor whitespace cleanup


Revision tags: thorpej-mips-cache-base thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf
# 1.139 14-Sep-2001 thorpej

branches: 1.139.4;
Don't declare intrhand[] here -- that's taken care of in intr.c.


Revision tags: thorpej-devvp-base
# 1.138 30-Aug-2001 eeh

branches: 1.138.2;
Preliminary UltraSPARC III suport (not enabled yet).


# 1.137 13-Aug-2001 jdolecek

g/c _remque()/_insque(); use the C version in libkern


# 1.136 09-Aug-2001 eeh

Fix context masking lossage caused by last version.


# 1.135 08-Aug-2001 eeh

Clean up the trap code to handle the changes cause by supporting non-faulting
accesses. Also change the parameter order so trap frames are easy to find.


# 1.134 07-Aug-2001 eeh

Make sure C code always has ASI_PRIMARY_NOFAULT in the %asi register so
the compiler will be happy if it ever starts generating speculative loads.


# 1.133 05-Aug-2001 eeh

Add support for non-faulting loads and optimize MMU miss handling paths.


# 1.132 02-Aug-2001 eeh

Fix bcopy.


# 1.131 02-Aug-2001 eeh

Sync bzero w/libc version.


# 1.130 01-Aug-2001 eeh

Integrate fixes from userland memset.


# 1.129 31-Jul-2001 eeh

Code cleanup and optimization.


# 1.128 23-Jul-2001 eeh

Get rid of some debug code that really isn't all that useful any more.


# 1.127 19-Jul-2001 eeh

Do ignore unregistered interrupts instead of faulting.


# 1.126 16-Jul-2001 eeh

Make bcopy a 32-bit friendly.


# 1.125 11-Jul-2001 eeh

Fix problems booting 32-bit kernels and dispatching level-15 interrupts.


# 1.124 08-Jul-2001 eeh

branches: 1.124.2;
Code cleanup. Add block_disable to let you turn on block set/copy routines.


# 1.123 05-Jul-2001 eeh

New block bzero and bcopy.


# 1.122 04-Jul-2001 eeh

Replace old bcopy with a much faster version.


# 1.121 01-Jul-2001 martin

Disable axidently enabled debug code to make -current compile again.


# 1.120 30-Jun-2001 eeh

Use a newer version (still disabled) of block bcopy.


# 1.119 30-Jun-2001 eeh

Fixup fpu save restore, get rid of some unused copy functions, and add
a new bcopy.


# 1.118 21-Jun-2001 eeh

Allow multiple 4MB pages for both kernel text and kernel data.

Note: DEBUG checks will not allow accesses to the hole between
text and data segments, so you may need to update programs that
use libkvm before relocating the start of kernel data.


# 1.117 06-Jun-2001 mrg

extract the netbsd32, sunos, 32 bit svr4 and 64 bit svr4 sigcode out into
separate files, so that compat lkms can link with them as well.


# 1.116 30-May-2001 lukem

add missing #include "opt_kgdb.h"


Revision tags: thorpej_scsipi_beforemerge
# 1.115 25-Apr-2001 simonb

Spell occurred correctly.


Revision tags: thorpej_scsipi_nbase thorpej_scsipi_base
# 1.114 09-Apr-2001 eeh

Interrupt latency fix from sparc port. (Hm. One insn instead of 5).


# 1.113 07-Mar-2001 eeh

Fix inverted preprocessor logic. (Spotted by Charles.)


# 1.112 21-Feb-2001 eeh

branches: 1.112.2;
Add support for 64-bit SVR4 (Solaris 8) binaries.


# 1.111 10-Feb-2001 pk

Fix conditional for svr4 compat inclusion.


# 1.110 05-Feb-2001 eeh

Add signal trampoline for 64-bit svr4 emulations.


# 1.109 31-Dec-2000 eeh

Make INCR() atomic.


# 1.108 29-Dec-2000 eeh

pseg_get tells us whether it really needed that spare page after all.


# 1.107 07-Dec-2000 eeh

Fixup calculating where fpstate should be saved in the signal trampoline
code so it doesn't overwrite something important like the registers.


# 1.106 09-Nov-2000 eeh

Fix ILP32 bug in probe_get().


# 1.105 22-Oct-2000 pk

Restore revision 1.102.

I hope it sticks this time..


# 1.104 20-Oct-2000 eeh

Fix hang in 32-bit kernels caused by relocation of KERNBASE.


# 1.103 04-Oct-2000 eeh

Fix interrupt lossage problem and some cosmetic changes.


# 1.102 01-Oct-2000 pk

cpu_initialize: global registers aren't preserved across calls to
prom_printf(), so replace %g3 with %l7 (which isn't used despite
the `usage' comment).

Also, clean up white-space turds.


# 1.101 29-Sep-2000 eeh

This seems to fix the interrupt lossage of non-debug kernels.


# 1.100 28-Sep-2000 eeh

Fix INTR_SETUP() to properly distinguish kernel and user addresses.

Make microtime() return the correct time on %tick machines.

Re-enable debug stuff in dostart for now to detect kernel mapping issues.


# 1.99 25-Sep-2000 pk

Missing `#if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)'


# 1.98 17-Sep-2000 eeh

Make the improved %tick changes work with machines that use the counter-timer
for the clock.


# 1.97 12-Sep-2000 eeh

Fix new version of microtime.


# 1.96 11-Sep-2000 eeh

(Hopefully) fix clock skew on machines that us %tick for the clock (UIIi).


# 1.95 31-Aug-2000 eeh

Use casx instead of stx to change entries in the page table trees.


# 1.94 23-Aug-2000 eeh

Update the scheduler to the new locking scheme.


# 1.93 10-Aug-2000 eeh

Fix signal delivery.


# 1.92 02-Aug-2000 eeh

Get kernel profiling to work. Now if only gprof worked....


# 1.91 01-Aug-2000 eeh

Overhaul cache flush code and coredump code.


# 1.90 25-Jul-2000 pk

Re-instate a couple of delay slot NOPs marked `XXX spitfire bug?'


# 1.89 24-Jul-2000 mycroft

Optimization to pmap_zero_page(): we only need to use the first 16 FP regs,
as in bzero().


# 1.88 24-Jul-2000 mycroft

Fix a whitespace glitch.


# 1.87 24-Jul-2000 mycroft

Pull in the bzero() changes from libc for real, with a couple of kernel-
specific hacks:
* Make the bias handling depend on STKB, so it switches correctly for 32-bit
kernels.
* Use the 32-bit stw/ld for 32-bit kernels.
* Add a few `-STKB's that were missed in the previous change.


# 1.86 24-Jul-2000 pk

Cosmetic & readability:
- local label cleanup in interrupt handling code;
- in debugging sections when testing `intrdebug': use a unique
local label (97) to enhanced clarity;
- comment-out unused code;
- kill a bug as the satisfying result of doing all of the above.


# 1.85 24-Jul-2000 eeh

Fix stack issues in bzero.


# 1.84 24-Jul-2000 mycroft

Revert the previous change for now. I don't have time to debug it tonight.


# 1.83 23-Jul-2000 mycroft

Copy bzero change from libc.


# 1.82 20-Jul-2000 pk

Since `intrcnt' points to an array of long ints, reserve the appropriate
amount of space depending on _LP64. Provide macros to load/store signed
and unsigned long ints.

Also, make the `intrcnt' and `intrpending' arrays 16 entries long, as on
sparc/v9 interrupt #15 is just a regular interrupt.


# 1.81 19-Jul-2000 eeh

Fix merge problem.


# 1.80 19-Jul-2000 eeh

Disable interrupt interlock using ih->ih_pending field. Seems to cause
more problems than it solves.


# 1.79 19-Jul-2000 eeh

Miscellaneous cleanup.


# 1.78 18-Jul-2000 pk

Correct args usage comment in probeget.
Whitespace cleanup.


# 1.77 18-Jul-2000 pk

probeget: 9 -> 0x9


# 1.76 18-Jul-2000 pk

If `ih_pending' is set simply return from the trap, don't schedule another
soft interrupt.


Revision tags: mrg-merge-1-5-top
# 1.75 18-Jul-2000 pk

openfirmware: don't lower %pil


# 1.74 17-Jul-2000 pk

Kill typos in interrupt code.


# 1.73 17-Jul-2000 pk

probeget: do the same song and dance as ld*a() macros in ctlreg.h do.


# 1.72 14-Jul-2000 eeh

Move some macro definitions out of genassym and into locore.s


# 1.71 08-Jul-2000 mrg

backout part of previous: turn off intrdebug, and another debug message


# 1.70 07-Jul-2000 pk

Changes for readability:
- #define LP64 dependent STACKFRAME macro once
- use a LOAD_ASCIZ macro for setting up the format string
for debug messages.


# 1.69 07-Jul-2000 eeh

Temporary fix to prevent the clock from stopping on UIIi machines.


# 1.68 03-Jul-2000 eeh

Prevent interrupts from being posted if they are active and deprecate polled
interrupts. This seems to eliminate the spurious interrupts.


# 1.67 02-Jul-2000 eeh

Clean up interrupt handling some more.


# 1.66 30-Jun-2000 eeh

Fix interrupt delivery on UltraSPARC IIi machines.


# 1.65 24-Jun-2000 eeh

With these changes the kernel seems almost stable again.


# 1.64 24-Jun-2000 eeh

More VM cleanup:

Move the cpu_info structure above the interrupt stack so it won't
get corrupted if the stack overflows.

Flush the D$ before and after all MMU bypass accesses since the
D$ latches all of those.


# 1.63 23-Jun-2000 eeh

Make probeget() and probeset() really work for a change.


Revision tags: netbsd-1-5-base
# 1.62 19-Jun-2000 eeh

branches: 1.62.2;
Have separate data and text segments, make text read-only.


# 1.61 12-Jun-2000 eeh

Start reorganizing the kernel for MULTIPROCESSOR support.


# 1.60 31-May-2000 thorpej

Add a comment about needing to initialize p_cpu when multiple
processors are supported.


Revision tags: minoura-xpg4dl-base
# 1.59 26-May-2000 thorpej

branches: 1.59.2;
First sweep at scheduler state cleanup. Collect MI scheduler
state into global and per-CPU scheduler state:

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

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

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

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

Tested on i386 and Alpha. Changes are mostly mechanical, but apologies
in advance if it doesn't compile on a particular platform.


# 1.58 26-May-2000 thorpej

Don't set `runtime' here; it's done at the end of mi_switch().
cvS: ----------------------------------------------------------------------


# 1.57 26-May-2000 thorpej

Introduce a new process state distinct from SRUN called SONPROC
which indicates that the process is actually running on a
processor. Test against SONPROC as appropriate rather than
combinations of SRUN and curproc. Update all context switch code
to properly set SONPROC when the process becomes the current
process on the CPU.


# 1.56 22-Apr-2000 eeh

If we trap due to a bad kernel stack, try to switch to the interrupt strack
before breaking into the debugger.


# 1.55 18-Apr-2000 eeh

Prevent the system from getting watchdog reset by returning directly to user
mode if restoring the user window traps. Also reduce the time we run with
%tl>0.


# 1.54 13-Apr-2000 eeh

Apparently gas 2.9.5 (don't ask) does not like to add values to %lo()
directives so move the additions inside %lo() to make it happy.
Hopefully this won't break older versions.


# 1.53 10-Apr-2000 mrg

- fix a speeling error
- rename some numbered labels to be a bit less confusing.
- remove dead code
- fix a debug error message (argh!)


# 1.52 10-Apr-2000 pk

Get a kernel without DDB to build.


# 1.51 16-Mar-2000 eeh

Revamp interrupts again:

Fix a bug causing interrmittent panics in interrupt dispatch.
Use interrupt vectors for softints.
Add a new send_softint interface.
Improved D$ flushing.
Improve traptrace and other debugging enhancements.


Revision tags: chs-ubc2-newbase
# 1.50 16-Jan-2000 eeh

Interrupt handlers return zero if they didn't handle the interrupt.


# 1.49 10-Jan-2000 eeh

Add debugger single-stepping and fix interrupt dispatch bugs.


# 1.48 30-Dec-1999 eeh

Lots of changes:

remove ffs()
add bzero that uses block store insns
save %gsr to fpstate
revert to physical accesses for pmap_zero_page so we don't
have conflicting page mappings
general cleanup.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base fvdl-softdep-base
# 1.47 06-Nov-1999 eeh

Handle zero length properly in copyinstr() copyoutstr() and copystr().


Revision tags: comdex-fall-1999-base
# 1.46 11-Oct-1999 eeh

branches: 1.46.2; 1.46.4;
Update to post 1.4.


# 1.45 05-Oct-1999 eeh

branches: 1.45.2;
Make broken versions of gas happy by using sethi/or instead of set for
(negative) addresses.


# 1.44 17-Sep-1999 thorpej

Centralize the declaration and clearing of `cold'.


Revision tags: chs-ubc2-base
# 1.43 18-Jul-1999 eeh

More fun with pmap.


# 1.42 21-Jun-1999 eeh

Improve TRAPTRACE. Add FLTRACE that only tracks MMU faults.


# 1.41 05-Jun-1999 eeh

Make pbrobeget() and probeset() work for 64-bit values as well. To do this
the arguments are changed so the address is first and the ASI second so we
can have the address in %o0:%o1 and not worry about unused registers.

Also a bit of copyright cleanup.


# 1.40 05-Jun-1999 mrg

update a commit slightly.


# 1.39 30-May-1999 eeh

Add code to support using %tick as the system clock if no "counter-timer" node
is found.


# 1.38 09-May-1999 eeh

Fixup non-DEBUG kernels.


# 1.37 29-Apr-1999 christos

Add sunos_sigcode (32 bit only)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.36 26-Mar-1999 eeh

branches: 1.36.4;
COMPAT_SPARC32 -> COMPAT_NETBSD32


# 1.35 25-Mar-1999 mrg

clean and up make compile


# 1.34 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.33 22-Mar-1999 eeh

Need to set up the pointers properly for partial FPU register stores.


# 1.32 22-Mar-1999 eeh

Flush D$ on bypass accesses.


# 1.31 28-Feb-1999 eeh

Use block load/store in pmap_zero_page()/pmap_copy_page().


# 1.30 17-Feb-1999 eeh

Let's test out vectored interrupts.


# 1.29 15-Feb-1999 hubertf

RCS ID police


# 1.28 11-Feb-1999 mrg

fix a comment pasto.


# 1.27 11-Jan-1999 eeh

Finally fixed 64-bit signal trampoline.


# 1.26 10-Jan-1999 eeh

Handle the symbol table properly in a 32-bit kernel that was booted from a
64-bit bootloader.


# 1.25 09-Jan-1999 eeh

More signal fixup.


Revision tags: kenh-if-detach-base
# 1.24 26-Nov-1998 mycroft

Sync kcopy() with 32-bit SPARC version.


# 1.23 16-Nov-1998 eeh

Fixup the last broken bits of the signal handling code.


Revision tags: chs-ubc-base
# 1.22 08-Oct-1998 eeh

Fix more syscall32 and signal breakage.


# 1.21 22-Sep-1998 eeh

More fixup in the signal area.

64-bit syscall cleanup.

Add emulation for some new FPU insns: conversion to 64-bit long int and
conditional moves.


# 1.20 17-Sep-1998 thorpej

SYS_sigreturn -> SYS___sigreturn14.


# 1.19 13-Sep-1998 eeh

Fixup signal changes (hopefully). However SUN_COMPAT is likely broken by
this and I don't know how to fix it.

We can now exec a 64-bit init through a really ugly hack (don't ask.)


# 1.18 11-Sep-1998 eeh

Add labels for the compat_sparc32 signal trampoline and break -- er -- fix
suword and fuword.


# 1.17 09-Sep-1998 eeh

Don't use %tick for microtime on 32-bit kernels -- breaks gettimeofday.


# 1.16 09-Sep-1998 thorpej

Adjust for the new "reaper" kernel thread: do not free the vmspace and
u-area in machine-dependent code. Instead, call exit2() to schedule
the reaper to free them for us, once it is safe to do so (i.e. we are
no longer running on the dead proc's vmspace and stack).


# 1.15 07-Sep-1998 eeh

Fix data corruption problem caused by broken debug code.


# 1.14 07-Sep-1998 eeh

Add new 64-bit trap vectors.


# 1.13 06-Sep-1998 eeh

32-bit fixup.


# 1.12 06-Sep-1998 eeh

Disable some debug stuff.


# 1.11 05-Sep-1998 eeh

It slices. It dices. It does everything except exec a sparc32_compat init.


# 1.10 02-Sep-1998 eeh

Periodic update: now starts probing devices.


# 1.9 30-Aug-1998 eeh

Some more 64-bit cleanup. Now everything compiles.


# 1.8 29-Aug-1998 eeh

Some more 64-bit-ification.


# 1.7 27-Aug-1998 eeh

Add 64-bit pmap support:

Moved from a two level 512/1024 entry setup mapping 32 (9/10/13) bits
respectively to a three level 1024/1024/1024 entry setup mapping 43
(10/10/10/13) bits. In 32-bit mode we waste about 1/12 pages mapping the high
11 bits. We also only manage 43 of the possible 44 bits of virtual address
space, wasting half of it. Oh well, maybe we'll do better next revision.


Revision tags: PMAP32
# 1.6 26-Aug-1998 mrg

panicstack: is needed outside of DEBUG. use _C_LABEL, and printf not db_printf (incase no ddb!)


# 1.5 13-Aug-1998 eeh

Merge paddr_t changes into the main branch.


Revision tags: eeh-paddr_t-base
# 1.4 07-Jul-1998 eeh

branches: 1.4.2;
General update:

Added genassym.cf
Removed lderr which should never have gotten in
Removed lots of dead code from locore.s
Added some softint stuff to intr.c
Added support for halt -p
esp and le both use bus_dmamap_*() functions now
instead of kdvma_mapin()
groundwork for PCI (but we still have no drivers for
any sun4u PCI devices)


# 1.3 04-Jul-1998 jonathan

defopt DDB.


# 1.2 26-Jun-1998 thorpej

defopt COMPAT_SVR4


# 1.1 20-Jun-1998 eeh

branches: 1.1.1;
Initial revision


# 1.433 01-Mar-2023 riastradh

sparc64: Optimization: Omit needless membar when triggering softint.

When we are triggering a softint, it can't already hold any mutexes.
So any path to mutex_exit(mtx) must go via mutex_enter(mtx), which is
always done with atomic r/m/w, and we need not issue any explicit
barrier between ci->ci_curlwp = softlwp and a potential load of
mtx->mtx_owner in mutex_exit.

PR kern/57240

XXX pullup-8
XXX pullup-9
XXX pullup-10


# 1.432 23-Feb-2023 riastradh

sparc64: Add missing barriers in cpu_switchto.

Details in comments.

PR kern/57240

XXX pullup-8
XXX pullup-9
XXX pullup-10


Revision tags: netbsd-10-base bouyer-sunxi-drm-base
# 1.431 05-Jul-2022 andvar

fix various typos in comments.


# 1.430 27-Jun-2022 andvar

fix various typos in comments.


# 1.429 22-May-2022 andvar

fix various small typos, mainly in comments.


# 1.428 16-May-2022 mrg

try to handle ultrasparc III* "fast ecc error" traps.

i had a sunblade 2500 reset with this trap recently, and the
manual says it should have been recoverable. in particular,
the US IIIv2 manual says in section 12.4.4.2 that the i-cache
won't see this data ever (so nothing needed there), and that
the d-cache needs to be disabled, and all the entries flushed,
and then re-enabled.

tested with a "trap 0x70" from kernel space, that trap.c
converted the "0x170" back to "0x70" (with an ADVANCE). this
code not commited.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 1.427 03-Apr-2021 palle

Improve cpu_idle() by allowing a platform specific implementaion (same logic as the sparc implementation) - currently only used by sun4v


# 1.426 30-Mar-2021 palle

sun4v: handle spill trap properly when trap level is 1 and otherwin is non-zero - ensure that all windows are spilled to the pcb like the sun4u winfixsave code path


# 1.425 22-Feb-2021 palle

branches: 1.425.2;
sun4v: handle spill normal user traps properly when current trap level is 1 - registers are spilled to the PA of the stack to avoid further mmu-related traps, since sun4v only has 2 trap levels


# 1.424 20-Dec-2020 palle

sun4v: add comment in sun4v_tl1_ptbl_miss code path - no functional change


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1
# 1.423 08-Jan-2020 skrll

branches: 1.423.6;
oldlwp is always non-NULL in cpu_switchto so remove the test for NULL.


# 1.422 08-Jan-2020 ad

Hopefully fix some problems seen with MP support on non-x86, in particular
where curcpu() is defined as curlwp->l_cpu:

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

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

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

- Remove some KERNEL_LOCK handling which hasn't been needed for years.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 ad-namecache-base netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.421 18-Jul-2019 palle

branches: 1.421.4;
sun4v: added some missing comments to the code in pcbspill


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 1.420 07-Apr-2019 mrg

make trap 0x70 a TRAP() not UTRAP(). we should be able to handle
fast ECC error as a normal trap, and i saw this once a few years
ago but it never repeated so i haven't been able to test this.


# 1.419 08-Feb-2019 palle

sun4v: Improve comment for next_stick_init() - no functional changes


# 1.418 08-Feb-2019 palle

sun4v: initialize %stickcmpr properly when establishing interrupt - fixes issue seen on newer sun4v/SPARC-T5 system where the interrupt never fires.


# 1.417 08-Feb-2019 palle

sun4v: introduce macros for handling spill traps from userlevevel @ traplevel 1 (from OpenBSD) - spill traps at level 1 from userspace now works better


# 1.416 08-Feb-2019 palle

sun4v: add comment documenting the contents of the %g2 register - no functional changes


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126
# 1.415 04-Nov-2018 palle

Ensure that the 64-bit condition codes are used instead of the 32-bit condition codes. ok martin@


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.414 26-May-2018 palle

branches: 1.414.2;
next_stick() - fix typy in comment: tick->stick


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.413 11-Apr-2018 palle

sun4v: handle MMU-related traps properly when they occur at trap level 1. This fixes issues when user-level LWPs access the user-level stack


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 1.412 26-Aug-2017 palle

branches: 1.412.2;
sun4v: Avoid touching the %tick_cmpr register which is not present on never systems (Oracle SPARC Architecture 2011 and beyond). Based on code from OpenBSD locore.s revision 1.177. Tested on both sun4u (qemu and USIII) and sun4v (qemu and T5-2). ok martin@


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2
# 1.411 06-May-2017 palle

sun4v: The %ver register is not available on sun4v - use GET_MAXCWP introduced in rev. 1.361. Verified using qemu (sun4u and sun4v) and on real sun4v hw (t2000)


Revision tags: prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.410 18-Apr-2017 palle

branches: 1.410.2;
sun4v: Add handling of trap 0x06c @ trap level 1 - based on code from OpenBSD, but slightly adapted to NetBSD. verified using qemu


Revision tags: jdolecek-ncq-base pgoyette-localcount-20170320
# 1.409 19-Feb-2017 palle

sun4v: rft_user needs special handling (a manual fill) since the restore instruction may cause the number of trap levels to exceed the maximum for sun4v - inspired by code from the the openbsd rft_user code path - verified using qemu for both sun4u and sun4v


# 1.408 10-Feb-2017 palle

sun4v: Added handling of trap type 0x034 (address alignment error) + fixed typo mmfsa -> mmufsa. Verified for both sun4u and sun4v using qemu.


Revision tags: nick-nhusb-base-20170204
# 1.407 30-Jan-2017 palle

sun4v: Hook up syscall handling to the trap table. Verified using qemu for both sun4u and sun4v.


# 1.406 27-Jan-2017 palle

sun4v: implement missing handling of itsb traps 0x008 and 0x009. Based on code from OpenBSD. Tested using qemu.


Revision tags: bouyer-socketcan-base
# 1.405 07-Jan-2017 palle

branches: 1.405.2;
sun4v: slowtrap() now selects normal globals properly on both sun4u and sun4v platforms. Verified using qemu for both sun4u and sun4v systems


Revision tags: pgoyette-localcount-20170107
# 1.404 05-Jan-2017 palle

sun4v: TRAP_SETUP() updated to set mmu context id properly for both sun4v and sun4u platforms. Verified using qemu for both sun4u and sun4v systems


# 1.403 04-Jan-2017 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x00-0x23 and 0x28-0x30


# 1.402 29-Dec-2016 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x32-0x7f


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.401 20-Sep-2016 nakayama

Fix RAS for 32-bit kernels. trapframe is always 64-bit.


Revision tags: localcount-20160914
# 1.400 23-Aug-2016 palle

sun4v: rework sun4v_datatrap so it works properly when running on a T2-based system like T5120 - for some reason %tl is 0 when entering sun4v_datatrap causing a crash (sir instruction), so ignore the %tl value for now upon entry to sun4v_datatrap - with this fix both T1 and T2 based systems reach the same point - hangs in rft_user after the init process is started


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726
# 1.399 18-Jul-2016 palle

sun4v: handle device interrupts properly - both legacy (sysino) and cookies


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 1.398 04-Jun-2016 palle

branches: 1.398.2;
sun4v: rtf_user now uses macros GET_MMU_CONTEXTID and SET_MMU_CONTEXTID. Tested on sun4u (QEMU) and sun4v (T2000). Parts from OpenBSD.


Revision tags: nick-nhusb-base-20160529
# 1.397 18-May-2016 nakayama

Decrement %tl in trap handler not to make it zero unconditionally
for the nested trap, and remove useless mov.


# 1.396 17-May-2016 palle

sun4v: Implement missng MMU protection trap handling - mostly from OpenBSD


# 1.395 16-May-2016 palle

Avoid assembler-specific defines by using the export keyword in genassym.cf instead


# 1.394 15-May-2016 nakayama

%g1 is not preserved across function call, so load it before
return_from_trap.


# 1.393 13-May-2016 palle

sun4v: add missing implementation of sun4v_datatrap_tl0 so data_access_fault() is called - mostly from OpenBSD


# 1.392 13-May-2016 nakayama

- ci_paddr is always 64-bit.
- intrlev is array of pointer.
- ih_ack is pointer.


# 1.391 10-May-2016 palle

sun4v: make device interrupts work. Introduce a new intrhand_alloc() function for allocation of interrupt handlers and adapt to this. Parts from OpenBSD. ok martin@


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.390 09-Mar-2016 nakayama

32-bit kernels use 32-bit stack.


# 1.389 03-Mar-2016 palle

sun4v: rft_kernel should pay attention to the number of register windows that can be restored. We cannot rely on fill traps to occur, since sun4v only has two trap levels available in privileged mode. Based on code from OpenBSD. ok martin@


# 1.388 14-Feb-2016 palle

sun4v: add breakpoint trap entry to the sun4v trap table


# 1.387 03-Feb-2016 palle

sun4v: extend dmmu_set_secondary_context() to handle both sun4u and sun4v. ok martin@


Revision tags: nick-nhusb-base-20151226
# 1.386 06-Nov-2015 martin

Basically revert r1.246 of locore.s and r1.73 of vm_machdep.c:

Remove special case handling for userland lwps from cpu_lwp_fork,
instead do it in lwp_trampoline when we first return to userland.

which was a stupid idea - since we did now set all fork child's %tstate
(and thus %pstate when back in userland) to the current kernel's userland
default. This meant we lost the address mask bit for 32bit processes and
all memory model details for 64bit ones.

Move it back to cpu_lwp_fork and fix the condition to only do it once when
forking init.


# 1.385 05-Nov-2015 martin

Most of the time return_from_trap already got called with tf->tf_tstate
loaded in register %g1 - make it so for two more callers and remove
the reload of that value.


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606 nick-nhusb-base-20150406
# 1.384 05-Apr-2015 palle

sun4v: Ensure that the TTEs CP and CV bits are the same (both set) for the primary cpu and secondary cpus INTSTACK mappings


# 1.383 01-Apr-2015 palle

sun4v: Implement handling of cpu_mondo trap - from OpenBSD - tested using the Legion simulator


# 1.382 04-Mar-2015 palle

sun4v: revert some of the logic introduced in revision 1.378 - flushw is not necessary on sun4v (OpenBSD patches the flushw instruction to a nop instruction) - with these changes the kernel reaches cpu_boot_secondary_processors() when running in the Legion simulator (crashes due to missing handling of cpu_mondo_trap)


# 1.381 02-Mar-2015 nakayama

prom_printf converts "\n" to "\r\n" internally, so omit "\r".


# 1.380 02-Mar-2015 nakayama

PANICSTACK is a pointer itself, not a pointer to pointer.


# 1.379 02-Mar-2015 nakayama

Use panic stack temporarily for calling prom_printf in a trap
handler.

It seems that openfirmware cannot handle over 4GB pointers, and
stack pointers may point to over 4GB since VA layout was rearranged
by rev 1.33 of vmparam.h. Therefore, use panic stack to avoid
panicking in OF_write used by prom_printf.


# 1.378 23-Feb-2015 palle

sun4v: sparc_interupt - ensure that the trap level and globals level are the same when the flushw instruction is issued - othwise warnings occur when using the sun4v Legion simulator.


Revision tags: nick-nhusb-base
# 1.377 26-Oct-2014 palle

branches: 1.377.2;
sun4v: Create CLEANWIN0 and CLEANWIN1 macros for handling clean window traps on both sun4u and sun4u (based on the original code inlined in the sun4u trap table). Update trap tables accordingly for both sun4u and sun4v. Ok martin@


# 1.376 24-Oct-2014 nakayama

Fix typo in comment.


# 1.375 18-Oct-2014 snj

src is too big these days to tolerate superfluous apostrophes. It's
"its", people!


# 1.374 15-Oct-2014 palle

sun4v: fixed bug causing the real address to be incorrectly calculated as zero


# 1.373 24-Sep-2014 palle

sun4v: add code to enable startup of secondary cpus on both sun4u and sun4v systems - ok martin@


# 1.372 04-Sep-2014 palle

sun4v: All cpus must be setup with a TSB descriptor, so pmap_setup_tsb_sun4v() must take a pointer to the TSB descriptor


# 1.371 31-Aug-2014 palle

sun4v: Split the NORMAL_GLOBALS and ALTERNATE_GLOBALS macros to _SUN4U and _SUN4V variants. Rework the return_from_trap logic to use the new variants so it is possible to use a global register as scratch register.


# 1.370 14-Aug-2014 nakayama

Add missing delay slot in DEBUG kernel.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.369 30-Jul-2014 palle

branches: 1.369.2;
Fix ALTERNATE_GLOBALS so it at least works on sun4u - using a scratch register is not a good idea...


# 1.368 27-Jul-2014 palle

sun4v: Introduce a new macro ALTERNATE_GLOBALS (matching NORMAL_GLOBALS). Two new helper macros ENABLE_INTERRUPTS and DISABLE_INTERRUPTS are also created. With these changes the GENERIC.UP kernel will reach rootmount on sun4v systems - ok martin@


# 1.367 26-Jul-2014 palle

Improved the NORMAL_GLOBALS macro in the sun4u case, so only the relevant bit (AG) in %pstate is affected - ok martin@


# 1.366 24-Jul-2014 palle

sun4v: add missing spill/fill handling for trap level 1 + cosmetic changes to comments for trap level 0 entries


# 1.365 19-Jul-2014 palle

sun4v: Introduce a NORMAL_GLOBALS macro - first used in sparc_interrupt - other relevant uses will be handled as the sun4v work is progressesing - ok martin@


# 1.364 16-Jul-2014 palle

sun4v: Introduce SET_MMU_CONTEXTID macro for setting the mmu context id on both sun4u and sun4v


# 1.363 13-Jul-2014 palle

sun4v: add interrupt handling to sun4v trap table


# 1.362 13-Jul-2014 palle

Bugfix: add missing cmp instruction to GET_MAXCWP macro


# 1.361 30-Jun-2014 palle

sun4v: The maximum number of register windows is a constant and thus not available via the %ver register (sun4u only). Introduce a macro GET_MAXCWP that handles this, so cpu_switchto() works properly on sun4v. Other relevant reference to %ver can be adapted to use GET_MAXCWP as the sun4v port progresses. OK martin@


# 1.360 31-May-2014 palle

sun4v: added missing dtsb miss handling for trap level 1 - with this update the kernel now reaches configure() on sun4v systems


# 1.359 30-May-2014 palle

Remove debugging code introduced by accident in locore.s revision 1.357


Revision tags: yamt-pagecache-base9 rmind-smpnet-nbase rmind-smpnet-base
# 1.358 05-May-2014 palle

sun4v: the trap base address should be assigned to %l1 so %tba is properly setup later in the code - now the kernel gets as far as printing the copyright disclaimer, kernel version and total and available memory before crashing


# 1.357 21-Apr-2014 palle

sun4v: Update comment: modified -> access


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.356 21-Feb-2014 palle

branches: 1.356.2;
sun4v: Rename TLB_ defines to SUN4U_TLB_ so entries created using TSB_DATA() are properly setup for sun4u and sun4v. Relocate the cputyp variable from autoconf.c to locore.s and make it const in param.h so optimized code can be generated. Parts from OpenBSD. Optimization suggested by nakayama@. OK martin@, mrg@, nakayama@


# 1.355 31-Jan-2014 tsutsui

defined(LKM) -> defined(MODULAR)


# 1.354 26-Jan-2014 palle

sun4v: Add handling of spill/fill and dtsb miss traps (with a XXX to be handled later)


# 1.353 07-Jan-2014 palle

sun4v: trap table setup - currently populated with dummy entries which will be properly implemented later - parts from OpenBSD - OK martin@


# 1.352 29-Dec-2013 nakayama

Make buildable w/o options SUN4V.


# 1.351 27-Dec-2013 palle

a) make the hunt through the cpus list more generic b) sun4v: ensure that the interrupt stack is mapped permanently and the TSB is setup properly - parts from OpenBSD. OK martin@


# 1.350 06-Dec-2013 nakayama

Increase an interrupt depth only in the case of hardware interrupts,
and remove the ci_idepth trick in softint_fastintr.

Fixes the following diagnostic panic reported in port-sparc64.

panic: kernel diagnostic assertion "!cpu_intr_p()" failed: file
"../../../../kern/subr_xcall.c", line 351


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 1.349 24-May-2013 nakayama

branches: 1.349.2;
Disable interrupts after calling data_access_error as with
data_access_fault.


# 1.348 28-Apr-2013 nakayama

Use macros in machine/asm.h instead of locally defined, and
introduce CASPTRA for casxa/casa.


Revision tags: agc-symver-base
# 1.347 23-Jan-2013 martin

Fix sparc64_ipi_ccall by adding proper trap setup.
Fixes xcall(9) problems, as exposed by pserialize(9). Noticed by
J. Hannken-Illjes, cause pointed out by Takeshi Nakayama.


# 1.346 23-Jan-2013 martin

Sligthly clean up the (by default unused) #ifdef TRAPS_USE_IG


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.345 10-Nov-2012 nakayama

Revise comment.


# 1.344 10-Nov-2012 nakayama

Use macro instead of magic number.


# 1.343 09-Nov-2012 nakayama

Make setstick() and getstick() to inline functions.


# 1.342 08-Nov-2012 macallan

use system tick timer instead of %tick on UltraSPARC-III-ish CPUs
review & fixes by Takeshi Nakayama


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.341 17-Mar-2012 mrg

branches: 1.341.2;
port the corrected ECC error handling code from freebsd. i noticed my U10
took one of these and then hang. it shouldn't hang, there's a 'sir' here that
doesn't seem to reset properly. oh well.

tested by simulated a trap via 'ta 0x10' and considering that the same, but
it hasn't been tested against a real ECC error yet.


Revision tags: jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base4
# 1.340 03-Mar-2012 nakayama

Fix the root cause of the hack "disable optimizations for uvm_bio.c
on 32 bit kernels".

gcc converts a division in the calculation of UBC_UMAP_ADDR macro
to multiplication (smul or combination of add/sll), and the
register of its result contains a garbage in upper 32 bits (the
upper 32 bits of smul/add/sll's result isn't zero cleared).

Then it passes to pseg_get{,_real} through pmap_extract without the
zero clear of upper 32 bits in the optimization case. So the
result of pseg_get and pmap_extact sometimes gets screwed up.


Revision tags: jmcneill-usbmp-base5 jmcneill-usbmp-base3
# 1.339 19-Feb-2012 rmind

Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.


Revision tags: jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.338 04-Sep-2011 nakayama

branches: 1.338.2; 1.338.6; 1.338.8;
ih_pil is an interrupt level, not an interrupt mask.


# 1.337 27-Jul-2011 nakayama

ivec is assigned to hardware, so count its event counter up in
interrupt_vector, not in softint, and do some optimization.


# 1.336 20-Jul-2011 macallan

add per ivec event counters


# 1.335 12-Jul-2011 mrg

rename sparc64 BLOCK_SIZE and BLOCK_ALIGN to have SPARC64_ prefixes.
for the assembler files, define the old names to the new names
since using the new names cause ugliness due to longer identifer
names, and reduces churn.

fixes build issues in dtv and vaguely makes <machine/psl.h> slightly
less name-space invasive.


# 1.334 18-Jun-2011 nakayama

Add fast softint(9) support for sparc64.

Reviewed on port-sparc64.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 1.333 12-May-2011 mrg

branches: 1.333.2;
first steps towards fujitsu SPARC64 support:

- SPARC64 systems have interrupts with upto 14 bits set, but we only look
at the first 11 bits. trim non IPI interrupts to 11 bits


Revision tags: uebayasi-xip-base7 bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 jym-xensuspend-nbase jym-xensuspend-base
# 1.332 20-Dec-2010 matt

branches: 1.332.2;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.


Revision tags: uebayasi-xip-base6 uebayasi-xip-base5 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 1.331 10-Jul-2010 nakayama

Clear the upper word explicitly before combining two 32-bit values to 64-bit
on 32-bit kernels.


# 1.330 23-May-2010 martin

Split copy related functions out of locore.s into copy.S, move functions
only needed on multiprocessors into mp_subr.S.


# 1.329 17-May-2010 martin

Simplify primary CPU startup slightly by using the fact that our cpuinfo's
curpcb pointer points to the uarea/pcb of lwp0 and by remembering the pointer
to this cpuinfo, thus avoiding a few CPUINFO_VA references.


Revision tags: uebayasi-xip-base1
# 1.328 20-Mar-2010 chs

fix copy{in,out}{,str}() to return the error returned by uvm_fault().
fixes PR 41813.


Revision tags: yamt-nfs-mp-base9
# 1.327 10-Mar-2010 mrg

branches: 1.327.2;
XXX: workaround we'd like to remove when pmap / uvm locking is cleaned up:

- rename pseg_get() and pseg_set() to pseg_get_real() and pseg_set_real().
- if USE_LOCKSAFE_PSEG_GETSET is defined, which it current is by default,
define pseg_[gs]et() in terms of functions that take a new pseg_lock
mutex at IPL_VM while calling into the real functions.

this seems to avoid the pseg_set() crashes we've seen:
1 - spare needed, when pseg_get() just worked for this pmap
2 - the 2rd ldxa via ASI_PHYS_CACHED in pseg_set() loads garbage
into %o4, and causes the 3rd ldxa to fault


# 1.326 08-Mar-2010 mrg

blast_dcache() SMP friendly:

- blast_dcache() becomes sp_blast_dcache(dcache_size, dcache_line_size)
- new smp_blast_dcache(sparc64_cpuset_t) that blasts the D$ on this cpuset
- sparc64_ipi_blast_dcache() to support the above
- in pmap_remove_all(), when freeing mmu contexts for this pmap, mark
the set of cpus to blast the d$ on as well and convert the
blast_dcache() call into smp_blast_dcache() on the cpus who ran this
pmap, or, sp_blast_dcache(dcache_size, dcache_line_size)
- convert the remaining blast_dcache() in machdep.c to sp_blast_dcache()
- in pmap_destroy()/pmap_remove_all() take the pmap_lock() always since
we assert it is held always.

with these changes, NFS builds on the U60 seem to be stable now, and
the USIII machines also can often complete a single build.sh run now,
diskful or diskless.


reviewed by mlelstv and partially by martin, tested by martin and myself,
with some ideas from chuq as well.


# 1.325 07-Mar-2010 mrg

need _ALIGN in locore.h as well, for DEBUG kernels.


# 1.324 07-Mar-2010 mrg

gas has supported SPARC ".empty" for a long while; get rid of an
ancient workaround.


# 1.323 06-Mar-2010 mrg

move the memcpy/memset implementations out into their own file, with the
block copy versions as well. move some of the definitions in locore.s
into a new locore.h.

locore.s is almost 2000 lines shorter with this change.


# 1.322 04-Mar-2010 mrg

- in _bus_dmamap_unload(), pmap_page_protect() and pmap_clear_reference()
switch the dcache_flush_page() into a dcache_flush_page_all()
- in both pmap_kremove()/pmap_remove(), remove the blast_dcache() call
and replace it with dcache_flush_page_all()
- in pmap_get_page() [used to allocate PTP's], always call pmap_zero_page(pa)
- flush the dcache of the dst page in pmap_{copy,zero}_page() by redirecting
throught a C function that calls the (renamed) asm. the old asm code had a
comment about needing to do this...
- add a couple of membar #Sync's that the USIII manual recommends


based on discussions with chuq@, skrll@ and martin@.


these help my SB2000 / SB2500 with both disk / nfs builds and other tasks,
sometimes lasting for several hours before failing or asserting.


# 1.321 24-Feb-2010 mrg

when handing back page table pages to UVM, flush them from the dcache
on all CPUs.

idea from skrll@, and makes my disk-based SB2000 stable.

tested on U60, SB2000 and SB2500.


# 1.320 24-Feb-2010 mrg

- re-introduce sp_tlb_flush_pte() and sp_tlb_flush_all() that call
the right USI/USIII version.
- define tlb_flush_pte() in terms of sp_tlb_flush_pte() for the
!MULTIPROCESSOR case

this centralises some CPU_IS_USIII_UP() tests.


# 1.319 22-Feb-2010 mrg

move {dump,print}_[id]tlb() into a separate file.


# 1.318 22-Feb-2010 mrg

- store the maximum [id]cache size / line size for each cpu

- remove patch_kernel() since it isn't necessary and has been patching
the wrong thing in general.

- implement USIII versions of blast_icache(), dcache_flush_page() and
cache_flush_phys(). use the newly recorded cache size/line sizes.

- in winfixsave, flush the D$ with the right size index and ops. this
kills one of the wrong tag->inval patches.

- for blast_dcache(), use the newly recorded dcache_size/line_size.

- for blast_icache(), use the newly recorded cache size/line sizes.
for the USIII verison, disable the I$ while writing to ASI_ICACHE_TAG.


these changes removed several hard coded cache sizes values, some very
wrong kernel patching, and seem to make the current failure modes for
USIII less common, but not gone.


# 1.317 15-Feb-2010 mrg

- don't flush 32-bit entries for 64-bit code, it does not seem to be
necessary. #define TLB_FLUSH_LOWVA to turn it back on.
- remove the #if 0'd code in sparc64_ipi_flush_pte_usiii(), i have
verified that it is not required.
- add a missing membar #Sync to sp_tlb_flush_pte_usiii().


# 1.316 15-Feb-2010 nakayama

Fix linker error of GENERIC32 kernel.


# 1.315 15-Feb-2010 mrg

use TLB_SIZE_SPITFIRE in a couple of places, and note that the
{print,dump}_[id]tlb() versions are currently spitfire specific.


# 1.314 15-Feb-2010 mrg

introduce a new patch_kernel() and call it from the end of bootstrap().
use it to patch up TLB flush instructions that don't match for USI/II
and later. we can also hopefully use this to make GENERIC.MP minimally
expensive on single CPU machines as well.

this is the last piece needed to get GENERIC/GENERIC.MP to boot on the
USIII* machines.

idea and some initial code from openbsd.


# 1.313 13-Feb-2010 mrg

remove KTR support. it's never been a working part of netbsd src tree.


# 1.312 09-Feb-2010 wiz

Fix typo in comment.


Revision tags: uebayasi-xip-base
# 1.311 06-Feb-2010 mrg

branches: 1.311.2;
- properly map the schizo interrupt registers, so we can use the normal
virtual mappings to access them.
- with the above fxied, kill SCHIZO_BUS_SPACE_BROKEN, and introduce
an options CHEETAH for now, that disables the SPITFIRE code in locore.
- merge schizo_init() into schizo_attach() and clean up the softc a bit.


with this we are only one more step away from GENERIC booting on USIII
machines.


# 1.310 02-Feb-2010 mrg

- split sp_tlb_flush_pte() and switchtoctx() into sp_tlb_flush_pte_us()/
sp_tlb_flush_pte_usiii() and switchtoctx_us()/switchtoctx_usiii() and
implement the latter while i'm here. it works ... sometimes i think,
but also sometimes panics/hangs.
- fix a comment in sparc64_ipi_flush_pte_usiii()


# 1.309 02-Feb-2010 mrg

for now, reduce a few #ifdef SPITFIRE cases by introducing a new
ASI_DCACHE_TAG_OR_INV that is either ASI_DCACHE_{TAG,_INVALIDATE}.

increase the common code in cache_flush_phys().


# 1.308 01-Feb-2010 mrg

- sp_tlb_flush_all() becomes sp_tlb_flush_all_us() and sp_tlb_flush_all_usiii()
- sparc64_ipi_flush_pte() becomes sparc64_ipi_flush_pte_us() and
sparc64_ipi_flush_pte_usiii()
- add some commented out code to disable interrupts and raise the traplevel
in sparc64_ipi_flush_pte_usiii()
- cache_flush_phys() was missing a little of code in the cheetah case


# 1.307 01-Feb-2010 mrg

for USIII, use the new "tlb demap all" operation in sp_tlb_flush_all()


# 1.306 01-Feb-2010 mrg

remove unused icache_flush_page() implementation.


# 1.305 23-Jan-2010 mrg

remove the final uses of DATA_START.

now we can remove the 16KB space reserved at the start of the data segment,
and i now understand why i wrote this now removed comment 3.5 years ago:
"this shouldn't be needed... but kernel usually hangs without it"


# 1.304 23-Jan-2010 mrg

remove most of the code that writes debugging info DATA_START + offset.


# 1.303 23-Jan-2010 mrg

remove CHKPT() macro and uses. it's likely wrong in SMP land and probably should
be replaced with KTR-style uses if necessary.


# 1.302 23-Jan-2010 mrg

fix a comment.


Revision tags: matt-premerge-20091211
# 1.301 10-Dec-2009 rmind

Rename L_ADDR to L_PCB and amend some comments accordingly.


# 1.300 05-Dec-2009 mrg

- adjust the PA mask to the 43 bits supported by USIII.
- rework the spitfire/cheetah cache_flush_phys() to avoid several #ifdefs
- add a membar #Sync after sparc64_ipi_drop_fpstate (probably unnecessary)


# 1.299 30-Nov-2009 nakayama

sp_tlb_flush_pte for cheetah:
- restore interrupts properly in case of %tl > 0.


# 1.298 30-Nov-2009 mrg

stablize UP USIII support by blocking interrupts around sp_tlb_flush_pte()
i was seeing stack corruption while taking an interrupt in this function.

get USIII SMP mostly working by implementing the cheetah version of
sparc64_ipi_flush_pte().


SMP support is still not entirely stable. i can reproducably get a:

panic: fpusave_lwp ipi didn't

while running build.sh, when an awk process is exiting. other simple
heavy work loads do not crash for me right now.


# 1.297 30-Nov-2009 mrg

delete some no longer used code:
- smp_tlb_flush_ctx()
- smp_tlb_flush_all()
- sparc64_ipi_flush_ctx()
- sparc64_ipi_flush_all()
- sp_tlb_flush_ctx()


# 1.296 29-Nov-2009 nakayama

- calculate end PA correctly.
- wrap more spitfire specific (flushing I$) code.
- fix inverted #if condition for flushing I$ (and restore ASI_ICACHE_TAG).


# 1.295 28-Nov-2009 mrg

implement enough code to get SB2000/SB2500 booting to multiuser. does
not last long if you use it, but an idle machine has stayed up 10 hours.

- for the !SPITFIRE case, use ASI_DCACHE_INVALIDATE instead of
ASI_DCACHE_TAG when clearing tlb entries. from openbsd.

- convert some comment "! Not yet" into "WRITEME", so that attempting
to build a USIII MULTIPROCESSOR kernel fails to build until the code
is written.

- add some more WRITEME's for the above.

- implement a !SPITFIRE version of sp_tlb_flush_all(). since there are
no spare regs, for now just always increase %tl around this call. (we
could maybe store a token in %o3 along with the saved %pstate info.)


# 1.294 26-Nov-2009 matt

Kill proc0paddr. Use lwp0.l_addr instead.


# 1.293 25-Nov-2009 mrg

s/L_ADDR/L_PCB/, requested by rmind.


# 1.292 17-Oct-2009 nakayama

Wrap unused code with #if 0 which is called from #if 0'ed code.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5
# 1.291 30-May-2009 martin

cpu_setfunc() can not use lwp_trampoline, as that has additional lwp startup
semantics. Use a simpler setfunc_trampoline instead.


# 1.290 18-May-2009 nakayama

Remove random() from locore.s since it is in libkern.


# 1.289 16-May-2009 nakayama

Remove clear %tick in locore.s since it is cleared at cpu_initclocks() in
clock.c.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 nick-hppapmap-base mjf-devfs2-base
# 1.288 15-Dec-2008 mrg

restore some old "intrdebug" code, but leave it under NOT_DEBUG. most
of it works, but one that prints func/arg for each handler is not very
stable...

for now, while schizo bus space pointer accesses aren't working, add
a SCHIZO_BUS_SPACE_BROKEN option so you can build a kernel with schizo.

with this, and the prior schizo interrupt fix, you can now fail to run
/sbin/init!


Revision tags: haad-dm-base2 haad-nbase2 haad-dm-base
# 1.287 09-Dec-2008 martin

Get rid of get_maxctx() - it doesn't work on newer cpus and we will have
to find a better way for (some) sun4v machines - all sun4u use 13 bit
contexts anyway.


Revision tags: netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 ad-audiomp2-base netbsd-5-base
# 1.286 30-Oct-2008 nakayama

branches: 1.286.2; 1.286.6;
Wrap more code specific to USE_BLOCK_STORE_LOAD.


Revision tags: matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4
# 1.285 05-Oct-2008 nakayama

branches: 1.285.2;
- in flushing cache, use 32 as increment/decrement value to match the
cache line size.
- remove useless restore of %asi.
- remove nop in delay slot if we can.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 1.284 10-Jul-2008 nakayama

Use proper CCR.


# 1.283 10-Jul-2008 nakayama

sparc64_ipi_save_fpstate:
- use primary MMU context for consistency with other trap/interrupt handlers.

sparc64_ipi_save_fpstate, savefpstate:
- avoid storing fp registers as we can.

sparc64_ipi_save_fpstate, savefpstate, loadfpstate:
- remove unaligned case since buffers allocated with pool_cache are ensured
64-byte aligned.

Ok by martin@.


# 1.282 02-Jul-2008 nakayama

branches: 1.282.2;
UltraSPARCs don't have floating point queue, and reading %fq regsiter
will cause illegal instruction trap. So remove the code handling them.


# 1.281 29-Jun-2008 nakayama

Wrap IPI calls with #ifdef MULTIPROCESSOR.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.280 14-Jun-2008 nakayama

Close unterminated comment.
Fix unexpected behavior in case of loadfpstate from unaligned buffer.


Revision tags: yamt-pf42-base3
# 1.279 31-May-2008 nakayama

branches: 1.279.2;
openfirmware_exit:
- disable interrupts with %pstate.
- prepare 64-bit stack and enable 64-bit addresses for 32-bit SMP kernels.


Revision tags: hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 yamt-nfs-mp-base yamt-pf42-base
# 1.278 16-Apr-2008 nakayama

branches: 1.278.2; 1.278.4; 1.278.6;
Disable TRAPSTATS which was accidentally enabled when yamt-idlelwp branch
was merged.

Ok by martin@.


# 1.277 14-Apr-2008 nakayama

Remove sparc64_ipi_sync_tick.

Since we can use counter-timer as timecounter instead of %tick on SMP kernel,
it is not necessary to sync all CPUs %tick registers.


# 1.276 14-Apr-2008 nakayama

Add workaround for BB_ERRATA_1 on writing to TICK_CMPR register in
next_tick(). If writing to TICK_CMPR fails, we lose hardclock interrupt
on secondary CPUs.

About BB_ERRATA_1 from comment in OpenSolaris:

/*
* Writes to the TICK_COMPARE register sometimes fail on blackbird modules.
* The failure occurs only when the following instruction decodes to wr or
* wrpr. The workaround is to immediately follow writes to TICK_COMPARE
* with a read, thus stalling the pipe and keeping following instructions
* from causing data corruption. Aligning to a quadword will ensure these
* two instructions are not split due to i$ misses.
*/


# 1.275 28-Mar-2008 nakayama

Don't read fplwp content in delay slot for considering the case fplwp was
modifiled.

Reported by Chris Ross on port-sparc64.


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.274 20-Mar-2008 nakayama

- remove disabling interrupt in IPI.
- unused VA bits in MMU demap is 13 bits, not 12 bits.


# 1.273 18-Mar-2008 nakayama

Fix a race when increment an interrupt level event counter.


# 1.272 17-Mar-2008 nakayama

Fix a race condition in IPI handlers of save/drop fpstate, from OpenBSD.
Reported and tested by martin@.


# 1.271 17-Mar-2008 nakayama

Make schedintr interrupt handler per-CPU.
While there rename tickintr interrupt handler and share initialization
code with schedintr.


# 1.270 14-Mar-2008 nakayama

Improve IPI handling:
- make IPI takes two arguments.
- add IPI event counters per-CPU.
- implement IPI functions which were missing or broken.
- insert DELAY while halting primary CPU in IPI handler.


# 1.269 02-Mar-2008 nakayama

- make interrupt pending list per-CPU.
- make tickintr() MP-safe.
- remove unused port-sparc derived interrupt code.

Ok by martin@.


# 1.268 02-Mar-2008 nakayama

Don't get IPI handler argument (from bogus address), and ack IRQ twice.


# 1.267 28-Feb-2008 martin

Make TSBs and MMU contexts per-cpu.


Revision tags: nick-net80211-sync-base mjf-devfs-base hpcarm-cleanup-base
# 1.266 26-Jan-2008 nakayama

branches: 1.266.2; 1.266.6;
Fix for 32-bit kernels.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.265 15-Jan-2008 skrll

Store a sensbile PCB_PC value in snapshot - the return point.

This helps gdb somewhat.

OK'd by martin.


# 1.264 14-Jan-2008 martin

Fix register name typo/copy&pasto - %g6 is not %o6/%sp.
From OpenBSD.


Revision tags: matt-armv6-base
# 1.263 06-Jan-2008 martin

Load the next cpu_info pointer with LDPTR instead of ld.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2
# 1.262 09-Dec-2007 martin

branches: 1.262.2;
Provide cpu_intr_p(), at least for non-MULTIPROCESSOR kernels.
Based on suggestions by Andrew Doran.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.261 22-Oct-2007 martin

branches: 1.261.2; 1.261.4; 1.261.6;
Remove an unused .globl declaration


Revision tags: yamt-x86pmap-base4
# 1.260 17-Oct-2007 garbled

Merge the ppcoea-renovation branch to HEAD.

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

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

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base ppcoea-renovation-base vmlocking-base
# 1.259 09-Sep-2007 martin

branches: 1.259.4;
Make cpufrequency and friends per cpu values.
Prepare a hz tick interrupt on secondary CPUs via %tick, but do not
enable it yet, as it breaks ddb.


# 1.258 09-Sep-2007 martin

Do not ACK IPIs before we finished loading all arguments.


# 1.257 06-Sep-2007 martin

Remove the (now unused) second 64k page mapped per CPU.
From matthew green, with small changes by me. All bugs are mine.


# 1.256 25-Aug-2007 martin

branches: 1.256.2;
Remove INITSTACK completely - at the time we used to switch to it, we
already have access to all of lwp0 and it's uarea - so we can switch
to the correct lwp0 stack easily before calling main.


# 1.255 25-Aug-2007 martin

When exiting to OF, use the interrupt stack instead of INITSTACK


# 1.254 25-Aug-2007 martin

Rework cpu_mp_startup slightly:
- temporarily use the cpu's interrupt stack untill we are ready
to access non-OF-based mappings, then directly switch to the cpu's
idlelwp's uarea stack
- disable interrupts untill we are ready to call C code


# 1.253 13-Aug-2007 macallan

remove two restore without matching save


Revision tags: nick-csl-alignment-base matt-mips64-base mjf-ufs-trans-base
# 1.252 06-Jul-2007 martin

branches: 1.252.4; 1.252.8;
A few nits for 32bit SMP kernels, noticed by mrg.
While there, simplify the fpstate IPIs a bit.


# 1.251 05-Jul-2007 martin

sparc64_ipi_save_fpstate is not a leaf function - create a full grown
stack frame.


# 1.250 28-May-2007 mrg

clean up cpu_switchto() a little - no need to flushw or membar
excessively. optimise an rdpr. tested by tnn.


# 1.249 23-May-2007 martin

Fix a stupid bug in the save_fpstate ipi, which caused overwriting of
struct lwp of the lwp owning the fpu. Fix clearing the fplwp - %o0 will
not survive the call to savefpstate - duh!


# 1.248 20-May-2007 martin

Simplify tf_tstate setting when leaving for userland initially - I seem
to have confused the if with the else case of the previous C code.
Funny that it worked at all.


# 1.247 20-May-2007 martin

cpu_switchto() has to return it's first arg, always. This differs from
my reading of the documentation, but helps in the real world and seems
to be what other ports do.


# 1.246 20-May-2007 martin

Remove special case handling for userland lwps from cpu_lwp_fork, instead
do it in lwp_trampoline when we first return to userland.


# 1.245 19-May-2007 martin

cpu_idle is a leaf function, so we better "return from leaf".
Use return value from cpu_switchto for previous lwp in lwp_trampoline.
Also shamelessly steal a comment from uwe written for sparc that explains
all this.
Thanks to tnn, mrg, and uwe for helping to debug this.


# 1.244 17-May-2007 yamt

merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base ad-audiomp-base
# 1.243 22-Feb-2007 martin

branches: 1.243.4; 1.243.6; 1.243.12;
uvm.page_idle_zero now is a bool, not a 32bit value any more.


# 1.242 21-Feb-2007 mrg

shave 9 insns off the tsb setup in cpu_initialize & cpu_mp_startup.


# 1.241 21-Feb-2007 martin

Get rid of unused (thus always zero) "curlwp" variable hidden in assembler
code (C code always uses a cpuinfo based macro).


# 1.240 18-Feb-2007 martin

Make use of another call delay slot, pointed out by uwe.


# 1.239 18-Feb-2007 martin

Make use of a call delay slot and avoid a bogus EMPTY.
Spotted by Juergen Hannken-Illjes, with input from Andrew Doran and
Valeriy E. Ushakov.


# 1.238 18-Feb-2007 martin

Whitespace cosmetics


# 1.237 18-Feb-2007 martin

Backout previous: EMPTY was misused


# 1.236 18-Feb-2007 martin

Make EMPTY expand to nop with gas, as it is used to mark empty branch
delay slots.


# 1.235 15-Feb-2007 martin

branches: 1.235.2;
Fix obvious copy&pasto in SCHED_DEBUG register usage.


Revision tags: post-newlock2-merge
# 1.234 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.233 25-Dec-2006 wiz

Spell "relevant" correctly. From Zafer Aydogan.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.232 25-Oct-2006 mrg

branches: 1.232.2; 1.232.4;
- note that __idle_u should go away but doing so breaks things
- fix several comments to reality
- clean up the #ifdef NO_VCACHE code slightly
- use call instead of set/jmpl
- remove a couple of unnecessary stores to curlwp


Revision tags: yamt-splraiseipl-base2
# 1.231 18-Oct-2006 rjs

Clean up some comments. Cosmetic change to use correct structure
offset names.

Optimize out two instructions from sparc64_ipi_save_fpstate and
sparc64_ipi_drop_fpstate.


# 1.230 17-Oct-2006 mrg

allocate 128KB (as opposed to 64KB) per-cpu, and place the interrupt
stack, cpu_info structure, panicstack, idle uarea and normal kernel
stack in here. the idle uarea and kernel stack are in the 2nd 64KB
page. the interrupt stack and cpu_info structure are as the same
place in the 1st 64KB page, and the panicstack grows down from the
top of this page. update comments in param.h to suit (XXX: a lot
of these constants should move to a header file that will not pollute
the name space so much.) map these pages identically between
cpu_initialise() and cpu_mp_startup(), and deal with the two 64KB
pages in pmap_extract(). keep an unmapped 64KB page between them.

don't initialise the unused "ci_eintstack" member of the cpu_info
structure

use constants to initialise many addresses in the cpu_info structure,
consolidating these assignments from cpu0 and cpu>0

delete u0/estack0/panicstack from locore.s

clean up some wrong comments in locore.s

fix a 32bit-only bug in cpu_mp_startup().

delete 'u0' entirely.


this fixes recent random lossage seen on port-sparc64: processes
stuck in RUN state, data faults, and hangs.


# 1.229 04-Oct-2006 mrg

use call instead of set/jmpl. add an entry point for idle that expects
sched_lock to be unlocked, and use this for non-boot cpu's. complete a
comment describing how registers in idle_switch are expected to be set.


# 1.228 03-Oct-2006 mrg

use the same SAVE_LOCALS_INS definition for 32 bit and 64 bit kernels.
refactor TRAP_SETUP() a little between these two versions to be more alike.


# 1.227 03-Oct-2006 mrg

use the correct size/type for MP variables (pointers and longs).

a 32 bit MULTIPROCESSOR kernel now builds (and crashes quickly.)


# 1.226 03-Oct-2006 mrg

in the 64bit version of SAVE_LOCAL_INS, s/BIAS/STKB/ to allow future
sharing of the 32 and 64 bit versions of the {TRAP,INTR}_SETUP macros.


# 1.225 19-Sep-2006 mrg

- remove some way old FP setup/teardown code
- put the block memcpy/memset inside #ifdef USE_BLOCK_STORE_LOAD which
is (now) defined.

no functional change, same .o is generated.


# 1.224 19-Sep-2006 mrg

re-order the changes in rev 1.217 to give registers a little bit of
time to settle between usage, like it was before hand.


# 1.223 19-Sep-2006 mrg

- remove a wrong comment.
- add a new entry point for idle called idle_switch that is called by
cpu_switch() in the MP case when sched_whichqs is zero, properly
setting up the idle stack. from petrov@ via martin@.


# 1.222 19-Sep-2006 mrg

rework interrupt_vector() slightly:
- for the IPI case, avoid loading the address of intrlev into %g3
- remove some NOT_DEBUG code
- load the interrupt argument #2 in the delay slot

this removes 2 nops during interrupt processing for the normal
case, and an additional 2 ALU instructions for IPIs


# 1.221 18-Sep-2006 mrg

- sparc64_ipi_halt(): we shouldn't return from sparc64_ipi_halt_thiscpu()
so replace a branch with a 'sir'
- in #if 0 code, in sparc64_ipi_flush_pte() and sparc64_ipi_flush_ctx()
save/restore the out registers that the sp_tlb_flush_xxx() versions
around calling them
- in sp_tlb_flush_pte() and sp_tlb_flush_ctx(), replace global register
usage with out registers so that we don't clobber the (alternate)
global registers when these are called from IPI context


# 1.220 18-Sep-2006 mrg

- remove an extra 'sir' that followed one in a macro
- add some named labels to some spill/fill handlers
- remove 2 unused strings


Revision tags: yamt-splraiseipl-base
# 1.219 18-Sep-2006 martin

branches: 1.219.2;
Lazy FPU handling for the MULTIPROCESSOR case


# 1.218 16-Sep-2006 nakayama

From OpenBSD:
- reload %fprs for checking it again.
- use symbolic names for checking in %fprs.

revision 1.51
date: 2005/07/18 14:50:11; author: deraadt; state: Exp; lines: +2 -1
cache a copy of the fprs so we know what fp restore we should do after

revision 1.50
date: 2005/07/14 01:46:13; author: deraadt; state: Exp; lines: +4 -4
use symbolic names for checking in %fprs, as above


# 1.217 16-Sep-2006 nakayama

Fix a couple of %y register save/restore errors, inspired from OpenBSD.

revision 1.44
date: 2004/04/23 04:18:17; author: marc; state: Exp; lines: +5 -4

fix a couple of %y register save/restore errors
1) don't save %y in a register that is later used before restoring %y
2) always restore %y after calling a signal handler
tested by drahn@, OK pval


# 1.216 15-Sep-2006 martin

Do not bother to save fpu state when we are about to get rid of it.


Revision tags: yamt-pdpolicy-base9
# 1.215 13-Sep-2006 mrg

SMP cleanup. provide support for multiple CPUs in DDB. (SMP itself
is still not working.)

cpu.h:
- add a pointer for DDB regs in SMP environment to struct cpu_info
- remove the #defines for mp_pause_cpus() and mp_resume_cpus()
cpuset.h:
- remove CPUSET_ALL() and rename CPUSET_ALL_BUT() to CPUSET_EXCEPT()
from petrov.
db_machdep.h:
- rename the members of db_regs_t to be the same as sparc
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- redo DDB_REGS to no longer be a pointer to a fixed data structure
but to one allocated per-cpu when ddb is entered
- move a bunch of prototypes in here
intr.h:
- remove SPARC64_IPI_* macros, no longer used
db_interface.c:
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- make "nil" a 64 bit entity
- change the ddb register access methods to work in multiprocessor
environment, it is now very much like sparc does it
- in kdb_trap() avoid accessing ddb_regp when it is NULL
- update several messages to include the cpu number
- unpause other cpus much later when resuming from ddb
- rename db_lock() to db_lock_cmd(), as the sparc-like code has
db_lock as a simple lock
- remove "mach cpus" command, and replace it with "mach cpu" (which
does the same) and also implement "mach cpu N" to switch to
another cpus saved trapframe
db_trace.c:
- update for the ddb_regs -> ddb_regp change
genassym.cf:
- add TF_KSTACK as offsetof(struct trapframe64, tf_kstack)
ipifuncs.c:
- overhaul extensively
- remove all normal interrupt handlers as IPI's, we now handle
them all specially in locore.s:interrupt_vector
- add a simplelock around all ipi functions - it's not safe for
multiple cpus to be sending IPI's to each other right now
- rename sparc64_ipi_pause() to sparc64_ipi_pause_thiscpu() and,
if DDB is configured, enable it to save the passed-in trapframe
to a db_regs_t for this cpu's saved DDB registers.
- remove the "ipimask" system (SPARC64_IPI_* macros) and instead
pass functions directly
- in sparc64_send_ipi() always set the interrupt arguments to 0,
the address and argument of the to be called function. (the
argument right now is the address of ipi_tlb_args variable, and
part of the reason why only one CPU can send IPI's at a time.)
don't wait forever for an IPI to complete. some of this is
from petrov.
- rename sparc64_ipi_{halt,pause,resume}_cpus() to
mp_{halt,pause,resume}_cpus()
- new function mp_cpu_is_paused() used to avoid access missing
saved DDB registers
- actually broadcast the flush in smp_tlb_flush_pte(),
smp_tlb_flush_ctx() and smp_tlb_flush_all(). the other end may
not do anything yet in the pte/ctx cases yet...
kgdb_machdep.c:
- rework for changed member names in db_regs_t.
locore.s:
- shave an instruction from syscall_setup() (set + ld -> sethi + ld)
- remove some old dead debug code
- add new sparc64_ipi_halt IPI entry point, it just calls the C
vector to shutdown.
- add new sparc64_ipi_pause IPI entry point, which just traps into
the debugger using the normal breakpoint trap. these cpus usually
lose the race in db_interface.c:db_suspend_others() and end up
calling the C vector sparc64_ipi_pause_thiscpu().
- add #if 0'ed code to sparc64_ipi_flush_{pte,ctx}() IPI entry
points to call the sp_ version of these functions.
- in rft_kernel (return from trap, kernel), check to see if the
%tpc is at the sparc64_ipi_pause_trap_point and if so, call
"done" not "retry"
- rework cpu_switch slightly: save the passed-in lwp instead of
using the one in curlwp
- in cpu_loadproc(), save the new lwp not the old lwp, to curlwp
- in cpu_initialize(), set %tl to zero as well. from petrov.
- in cpu_exit(), fix a load register confusion. from petrov.
- change some "set" in delay branch to "mov".
machdep.c:
- deal with function renames
pmap.c:
- remove a spurious space
trap.c:
- remove unused "trapstats" variable
- add cpu number to a couple of messages


# 1.214 09-Sep-2006 mrg

significant clean up effort, largely from petrov@ via martin@.

- fix a bunch of comments for proc->lwp
- remove old TRAPTRACE, NOT_DEBUG, etc. code that has bit-rotted
- put some older DEBUG code under NOT_DEBUG
- add a bunch of new debugging/tracing code ("KTR") that depends on
other changes not yet present.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base yamt-pdpolicy-base5 chap-midi-base simonb-timecounters-base rpaulo-netinet-merge-pcb-base
# 1.213 14-May-2006 elad

branches: 1.213.6; 1.213.8;
integrate kauth.


# 1.212 12-May-2006 skrll

Fix some comments.


Revision tags: elad-kernelauth-base
# 1.211 09-May-2006 rjs

Load CPCB in cpu_mp_startup.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.210 11-Feb-2006 cdi

branches: 1.210.2; 1.210.4; 1.210.6;
ANSIfication: u_intN_t -> uintN_t, use ANSI function declarations/definitions
instead of K&R ones.


# 1.209 27-Jan-2006 cdi

branches: 1.209.2; 1.209.4;
Alter sparc64 bootstrap, catch up to ofwboot v1.9:

- Accept bootinfo structure passed down from ofwboot v1.9
- Drop kernel re-mapping code
- Use permanent 4MB mappings provided by the loader instead
- Change kernel entry address to point directly at the code instead of pointing
at the trap table's first slot. This allows the bootloader to detect
those kernels which are aware of the new boot scheme
- Due to the changes in kernel mapping code, alter secondary CPU bootstrap
code to use trampoline just like FreeBSD does (some FreeBSD code is used
here as well)


# 1.208 12-Jan-2006 cdi

Fix a typo: %g0 should be used instead of %o0 when initializing FPU in dostart:
and cpu_mp_startup:, %o0 is not even initialized at this point.


# 1.207 11-Dec-2005 christos

branches: 1.207.2;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 1.206 10-Jul-2005 christos

Re-factor syscall, and make it use syscall_{plain,fancy}.


# 1.205 31-May-2005 chs

branches: 1.205.2;
remove vestigal {,e}intr{names,cnt} symbols now that vmstat doesn't need them.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.204 12-Feb-2005 chs

branches: 1.204.4; 1.204.6; 1.204.8;
in sparc_interrupt(), wait to enable interrupts until just before calling
the handler and disable them again right after the handler returns.
we don't want another hardware interrupt coming in while we're mucking
with the list pointers. also, clear the intrhand's ih_pending pointer
before calling the handler rather than after, so that if another interrupt
comes in while the handler is running, we can put the intrhand back on
the list so it will be called again.

in send_softint(), disable interrupts via %pstate instead of %pil, so that
hardware interrupts at higher levels are blocked while we manipulate the
intrpending list. also, if the intrhand already has ih_pending set,
don't bother poking the SET_SOFTINT register again, since being on the list
implies that there is already a softint pending in the hardware.

these appear to fix PR 21750 (the "sleep forever" problem).

while I'm here, remove more vestiges of the !INTRLIST softint stuff
(code and comments). and in sparc64_ipi_flush_all(), interrupts are
already disabled so we don't need to fiddle with %pstate.


Revision tags: yamt-km-base2
# 1.203 30-Jan-2005 martin

Remove the no long usefull variants selected by undefining INTRLIST and
INTR_INTERLOCK to improve readability. Same object code generated as before.


Revision tags: yamt-km-base
# 1.202 16-Jan-2005 chs

branches: 1.202.2;
use ENTRY_NOPROFILE() for various entry points,
stack traces work better that way.


Revision tags: kent-audio1-beforemerge kent-audio1-base
# 1.201 03-Dec-2004 chs

branches: 1.201.4;
remove cache_flush_virt() and PADDRT, they're no longer used.
allocate a stack frame for blast_dcache() when profiling so it shows up.
in dcache_flush_page(), use a stride of 32 instead of 16 to match the
cache line size. correct various comments.


# 1.200 08-Nov-2004 petrov

Don't compile sparc64_ipi functions when UP.


# 1.199 25-Oct-2004 martin

No need to clear %o1 when returning a 64 bit integer from pseg_get if we
are compiling for a 64 bit kernel.


# 1.198 24-Jul-2004 nakayama

Change interrupt pending list end value to -1, to avoid linking an
interrupt handler twice.

It may fix "sleep forever" bug.


# 1.197 09-Apr-2004 petrov

Clean-up unused defines and variables.


Revision tags: netbsd-2-0-base
# 1.196 26-Mar-2004 petrov

branches: 1.196.2;
Use want_resched from cpu_info area.


# 1.195 23-Mar-2004 martin

Replace intrcnts by evcnts. XXX - needs slight tweaking for MULTIPROCESSOR.


# 1.194 14-Mar-2004 chs

checkpoint of MP work from dennis and myself. includes cross-processor
interrupt framework, a sledgehammer TLB invalidation and misc MP fixes.
doesn't work at all yet.


# 1.193 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.192 19-Jan-2004 martin

Rename switchexit to cpu_exit and g/c the old C implementation of cpu_exit.


# 1.191 18-Jan-2004 martin

Support RAS for 32bit kernels too.


# 1.190 16-Jan-2004 martin

In proc_trampoline don't bother to clear condition codes in the trap
frame, since we no longer rely on this.
While there fix a few comments.


# 1.189 08-Jan-2004 martin

Minor cleanup


# 1.188 06-Jan-2004 martin

Implement restartable atomic sequences (RAS) for sparc64.


# 1.187 06-Jan-2004 petrov

Spinup secondary cpus. Based on codes sent to me by Dennis Chernoivanov
and Chuck Silvers.


# 1.186 04-Jan-2004 jdolecek

update to recent changes - exit2() doesn't exist anymore and the
exit path always calls lwp_exit2()
pointed out Martin Husemann


# 1.185 02-Dec-2003 martin

Minor cleanup: remove unused code, sync a comment with current reality.


# 1.184 25-Nov-2003 cdi

Use per-cpu pcb, curlwp and fplwp rather than global ones. This brings
GENERIC.MP configuration to a usable state.

Approved by petrov@.


# 1.183 24-Nov-2003 cdi

Call 'proc_trampoline_mp' from 'proc_trampoline' in a multiprocessor
configuration. Fix process locking. Approved by petrov@.


# 1.182 20-Nov-2003 petrov

Remove nwindows calculation, it's not used. Set l_cpu in cpu_switch.


# 1.181 09-Nov-2003 martin

Get rid of bcopy/bzero.


# 1.180 26-Oct-2003 christos

Initial siginfo support for sparc64 (untested). COMPAT_16 sigcontext signal
delivery tested.


# 1.179 24-Aug-2003 chs

add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default. the changes
fall into two basic catagories:

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

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

originally from openbsd, adapted for netbsd by me.


# 1.178 08-Jul-2003 cdi

traceit: don't use %g7 as it is to become curcpu() register. Add comments.


# 1.177 18-May-2003 martin

branches: 1.177.2;
Make kernels with options KGDB at least compile.
Still needs some work to make it working.


# 1.176 29-Apr-2003 nakayama

Use BLOCK_ALIGN rather than BLOCK_SIZE for aligning a pointer.


# 1.175 27-Apr-2003 ragge

Preserve the symbol table in the LKM || KSYMS cases also.


# 1.174 04-Apr-2003 petrov

use branch slot in pmap_copy_page.


# 1.173 24-Mar-2003 nakayama

Divide `set' instruction in delay slot (from OpenBSD change to rev 1.30).


# 1.172 10-Feb-2003 martin

Remove some #if 0 code and a few XXX marked membars w/o proper
justification for their existence.


# 1.171 09-Feb-2003 martin

Remove left over pieces from reusing the signal trampoline for upcalls.
This should fix signal delivery for 32bit kernels.


# 1.170 05-Feb-2003 nakayama

Switch to use cycle counter (%tick) based microtime().

This is derived from alpha/microtime.c and i386/tsc_microtime.c,
and will share with both ports.

This should fix PR port-sparc64/18452.
(approved by martin)


# 1.169 04-Feb-2003 martin

Fix return value of pseg_set, which I accidently broke in rev. 1.164.

Fix register names in comment and shave off another register (hint
from uwe).


# 1.168 01-Feb-2003 martin

Rearrange register usage in pseg_set a bit and shave off %g4.


# 1.167 01-Feb-2003 martin

Remove a few #ifdef _LP64 by using STPTR/LDPTR macros.
Thanks to Matthew Green for the pointer.


# 1.166 31-Jan-2003 martin

Apply leaf procedure optimization to pseg_set (again).


# 1.165 31-Jan-2003 martin

Make the pmap count resident/wired mappings on the fly instead of
walking the page tables whenever this information is needed.

Add an option PMAP_COUNT_DEBUG to assert the new counts and the
page table walk agree.

The old solution had very bad performance impact, for example
by the high CPU load when running top(1).

Thanks to Simon Burge for pointing at the cause of the problem and
to Valeriy E. Ushakov for optimizing my simple minded assembler code.


# 1.164 27-Jan-2003 martin

Remove unused function pseg_find (which looked quite similar to
pseg_get anyway).


# 1.163 18-Jan-2003 thorpej

Merge the nathanw_sa branch.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.162 16-Jan-2003 petrov

Move dump_dtlb back under DDB.


# 1.161 15-Jan-2003 chs

fix two bugs in my last pmap rework:
- in tlb_flush_all(), don't skip TLB entries with the high bit on,
I was confused about which MMU register it was using. it's also fine
to use the last hardware context.
- in pmap_create(), don't allocate a hardware context for the new pmap.
it's unnecessary, and when this would cause us to recycle all the contexts,
it would result in the current process's context being set to 0
(ie. the kernel's context). the current process could then return to
userspace without going through the context-switch code (and thus without
having a hardware context reallocated). this would lead to user mappings
being entered in the kernel's context later, causing all sorts of trouble.
add some assertions to catch this kind of thing.


Revision tags: fvdl_fs64_base
# 1.160 25-Dec-2002 petrov

new function dump_itlb.


Revision tags: gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.159 22-Sep-2002 chs

many improvements:
- use struct vm_page_md for attaching pv entries to struct vm_page
- change pseg_set()'s return value to indicate whether the spare page
was used as an L2 or L3 PTP.
- use a pool for pv entries instead of malloc().
- put PTPs on a list attached to the pmap so we can free them
more efficiently (by just walking the list) in pmap_destroy().
- use the new pmap_remove_all() interface to avoid flushing the cache and TLB
for each pmap_remove() that's done as we are tearing down an address space.
- in pmap_enter(), handle replacing an existing mapping more efficiently
than just calling pmap_remove() on it. also, skip flushing the
TSB and TLB if there was no previous mapping, since there can't be
anything we need to flush. also, preload the TSB if we're pre-setting
the mod/ref bits.
- allocate hardware contexts like the MIPS pmap:
allocate them all sequentially without reuse, then once we run out
just invalidate all user TLB entries and flush the entire L1 dcache.
- fix pmap_extract() for the case where the va is not page-aligned and
nothing is mapped there.
- fix calculation of TSB size. it was comparing physmem (which is
in units of pages) to constants that only make sense if they are
in units of bytes.
- avoid sleeping in pmap_enter(), instead let the caller do it.
- use pmap_kenter_pa() instead of pmap_enter() where appropriate.
- remove code to handle impossible cases in various functions.
- tweak asm code to pipeline a little better.
- remove many unnecessary spls and membars.
- lots of code cleanup.
- no doubt other stuff that I've forgotten.

the result of all this is that a fork+exit microbenchmark is 34% faster
and a fork+exec+exit microbenchmark is 28% faster.


Revision tags: gehenna-devsw-base
# 1.158 18-Jul-2002 wiz

Spell 'should' correctly.


# 1.157 07-Jun-2002 eeh

Shave 10% off the time needed to flush the D$ through a bit of instruction
reordering.


# 1.156 05-Jun-2002 eeh

Handle improperly aligned stack pointers more cleanly.


# 1.155 04-Jun-2002 eeh

Fix the fork trampoline to properly use the supplied tstate.


# 1.154 31-May-2002 thorpej

Make this work with an ISO C preprocessor.


Revision tags: netbsd-1-6-base
# 1.153 14-May-2002 eeh

branches: 1.153.2; 1.153.4;
Only save locals and ins in trapframes for DEBUG kernels.


# 1.152 04-May-2002 kleink

Add some comments to the CPP conditionals controlling the trap macro
definitions, to ease navigation somewhat.


# 1.151 16-Apr-2002 eeh

Make lots of routines profile-friendly and get rid of some cruft.


Revision tags: eeh-devprop-base
# 1.150 21-Mar-2002 petrov

Not needed debug stuff deleted.


# 1.149 16-Mar-2002 mrg

tell newer binutils that our use of %g2 and %g3 is OK here.


# 1.148 15-Mar-2002 eeh

Cleanup MMU initialization to prevent hangs.


Revision tags: newlock-base ifpoll-base
# 1.147 09-Feb-2002 eeh

branches: 1.147.4;
Fix microsecond calculation in microtime.


# 1.146 07-Feb-2002 eeh

Fix register allocation in microtime().


# 1.145 29-Jan-2002 eeh

Shift the UPAID in the correct direction.


# 1.144 17-Jan-2002 eeh

Be more tolerant of unaligned stack pointers.


# 1.143 17-Jan-2002 eeh

Enable block insns in bcopy and bzero.


# 1.142 16-Jan-2002 eeh

In bcopy use 32-bit comparisons in 32-bit kernels.


# 1.141 16-Jan-2002 eeh

Use correct calculation for the trapframe in softtrap for ILP32.


# 1.140 20-Nov-2001 lukem

- pull in opt_kgdb.h where necessary
- replace opt_kgdb_machdep.h with opt_kgdb.h
- defparam opt_kgdb.h:
KGDB_DEV KGDB_DEVNAME KGDB_DEVADDR KGDB_DEVRATE KGDB_DEVMODE
- move from opt_ddbparam.h to opt_ddb.h:
DDB_FROMCONSOLE DDB_ONPANIC DDB_HISTORY_SIZE DDB_BREAK_CHAR SYMTAB_SPACE
- replace KGDBDEV with KGDB_DEV
- replace KGDBADDR with KGDB_DEVADDR
- replace KGDBMODE with KGDB_DEVMODE
- replace KGDBRATE with KGDB_DEVRATE
- use `9600' instead of `0x2580' for 9600 baud rate
- use correct quotes for options KGDB_DEVNAME="\"com\""
- use correct quotes for options KGDB_DEV="17*256+0"
- remove unnecessary dependancy on Makefile for kgdb_stub.o
- minor whitespace cleanup


Revision tags: thorpej-mips-cache-base thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf
# 1.139 14-Sep-2001 thorpej

branches: 1.139.4;
Don't declare intrhand[] here -- that's taken care of in intr.c.


Revision tags: thorpej-devvp-base
# 1.138 30-Aug-2001 eeh

branches: 1.138.2;
Preliminary UltraSPARC III suport (not enabled yet).


# 1.137 13-Aug-2001 jdolecek

g/c _remque()/_insque(); use the C version in libkern


# 1.136 09-Aug-2001 eeh

Fix context masking lossage caused by last version.


# 1.135 08-Aug-2001 eeh

Clean up the trap code to handle the changes cause by supporting non-faulting
accesses. Also change the parameter order so trap frames are easy to find.


# 1.134 07-Aug-2001 eeh

Make sure C code always has ASI_PRIMARY_NOFAULT in the %asi register so
the compiler will be happy if it ever starts generating speculative loads.


# 1.133 05-Aug-2001 eeh

Add support for non-faulting loads and optimize MMU miss handling paths.


# 1.132 02-Aug-2001 eeh

Fix bcopy.


# 1.131 02-Aug-2001 eeh

Sync bzero w/libc version.


# 1.130 01-Aug-2001 eeh

Integrate fixes from userland memset.


# 1.129 31-Jul-2001 eeh

Code cleanup and optimization.


# 1.128 23-Jul-2001 eeh

Get rid of some debug code that really isn't all that useful any more.


# 1.127 19-Jul-2001 eeh

Do ignore unregistered interrupts instead of faulting.


# 1.126 16-Jul-2001 eeh

Make bcopy a 32-bit friendly.


# 1.125 11-Jul-2001 eeh

Fix problems booting 32-bit kernels and dispatching level-15 interrupts.


# 1.124 08-Jul-2001 eeh

branches: 1.124.2;
Code cleanup. Add block_disable to let you turn on block set/copy routines.


# 1.123 05-Jul-2001 eeh

New block bzero and bcopy.


# 1.122 04-Jul-2001 eeh

Replace old bcopy with a much faster version.


# 1.121 01-Jul-2001 martin

Disable axidently enabled debug code to make -current compile again.


# 1.120 30-Jun-2001 eeh

Use a newer version (still disabled) of block bcopy.


# 1.119 30-Jun-2001 eeh

Fixup fpu save restore, get rid of some unused copy functions, and add
a new bcopy.


# 1.118 21-Jun-2001 eeh

Allow multiple 4MB pages for both kernel text and kernel data.

Note: DEBUG checks will not allow accesses to the hole between
text and data segments, so you may need to update programs that
use libkvm before relocating the start of kernel data.


# 1.117 06-Jun-2001 mrg

extract the netbsd32, sunos, 32 bit svr4 and 64 bit svr4 sigcode out into
separate files, so that compat lkms can link with them as well.


# 1.116 30-May-2001 lukem

add missing #include "opt_kgdb.h"


Revision tags: thorpej_scsipi_beforemerge
# 1.115 25-Apr-2001 simonb

Spell occurred correctly.


Revision tags: thorpej_scsipi_nbase thorpej_scsipi_base
# 1.114 09-Apr-2001 eeh

Interrupt latency fix from sparc port. (Hm. One insn instead of 5).


# 1.113 07-Mar-2001 eeh

Fix inverted preprocessor logic. (Spotted by Charles.)


# 1.112 21-Feb-2001 eeh

branches: 1.112.2;
Add support for 64-bit SVR4 (Solaris 8) binaries.


# 1.111 10-Feb-2001 pk

Fix conditional for svr4 compat inclusion.


# 1.110 05-Feb-2001 eeh

Add signal trampoline for 64-bit svr4 emulations.


# 1.109 31-Dec-2000 eeh

Make INCR() atomic.


# 1.108 29-Dec-2000 eeh

pseg_get tells us whether it really needed that spare page after all.


# 1.107 07-Dec-2000 eeh

Fixup calculating where fpstate should be saved in the signal trampoline
code so it doesn't overwrite something important like the registers.


# 1.106 09-Nov-2000 eeh

Fix ILP32 bug in probe_get().


# 1.105 22-Oct-2000 pk

Restore revision 1.102.

I hope it sticks this time..


# 1.104 20-Oct-2000 eeh

Fix hang in 32-bit kernels caused by relocation of KERNBASE.


# 1.103 04-Oct-2000 eeh

Fix interrupt lossage problem and some cosmetic changes.


# 1.102 01-Oct-2000 pk

cpu_initialize: global registers aren't preserved across calls to
prom_printf(), so replace %g3 with %l7 (which isn't used despite
the `usage' comment).

Also, clean up white-space turds.


# 1.101 29-Sep-2000 eeh

This seems to fix the interrupt lossage of non-debug kernels.


# 1.100 28-Sep-2000 eeh

Fix INTR_SETUP() to properly distinguish kernel and user addresses.

Make microtime() return the correct time on %tick machines.

Re-enable debug stuff in dostart for now to detect kernel mapping issues.


# 1.99 25-Sep-2000 pk

Missing `#if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)'


# 1.98 17-Sep-2000 eeh

Make the improved %tick changes work with machines that use the counter-timer
for the clock.


# 1.97 12-Sep-2000 eeh

Fix new version of microtime.


# 1.96 11-Sep-2000 eeh

(Hopefully) fix clock skew on machines that us %tick for the clock (UIIi).


# 1.95 31-Aug-2000 eeh

Use casx instead of stx to change entries in the page table trees.


# 1.94 23-Aug-2000 eeh

Update the scheduler to the new locking scheme.


# 1.93 10-Aug-2000 eeh

Fix signal delivery.


# 1.92 02-Aug-2000 eeh

Get kernel profiling to work. Now if only gprof worked....


# 1.91 01-Aug-2000 eeh

Overhaul cache flush code and coredump code.


# 1.90 25-Jul-2000 pk

Re-instate a couple of delay slot NOPs marked `XXX spitfire bug?'


# 1.89 24-Jul-2000 mycroft

Optimization to pmap_zero_page(): we only need to use the first 16 FP regs,
as in bzero().


# 1.88 24-Jul-2000 mycroft

Fix a whitespace glitch.


# 1.87 24-Jul-2000 mycroft

Pull in the bzero() changes from libc for real, with a couple of kernel-
specific hacks:
* Make the bias handling depend on STKB, so it switches correctly for 32-bit
kernels.
* Use the 32-bit stw/ld for 32-bit kernels.
* Add a few `-STKB's that were missed in the previous change.


# 1.86 24-Jul-2000 pk

Cosmetic & readability:
- local label cleanup in interrupt handling code;
- in debugging sections when testing `intrdebug': use a unique
local label (97) to enhanced clarity;
- comment-out unused code;
- kill a bug as the satisfying result of doing all of the above.


# 1.85 24-Jul-2000 eeh

Fix stack issues in bzero.


# 1.84 24-Jul-2000 mycroft

Revert the previous change for now. I don't have time to debug it tonight.


# 1.83 23-Jul-2000 mycroft

Copy bzero change from libc.


# 1.82 20-Jul-2000 pk

Since `intrcnt' points to an array of long ints, reserve the appropriate
amount of space depending on _LP64. Provide macros to load/store signed
and unsigned long ints.

Also, make the `intrcnt' and `intrpending' arrays 16 entries long, as on
sparc/v9 interrupt #15 is just a regular interrupt.


# 1.81 19-Jul-2000 eeh

Fix merge problem.


# 1.80 19-Jul-2000 eeh

Disable interrupt interlock using ih->ih_pending field. Seems to cause
more problems than it solves.


# 1.79 19-Jul-2000 eeh

Miscellaneous cleanup.


# 1.78 18-Jul-2000 pk

Correct args usage comment in probeget.
Whitespace cleanup.


# 1.77 18-Jul-2000 pk

probeget: 9 -> 0x9


# 1.76 18-Jul-2000 pk

If `ih_pending' is set simply return from the trap, don't schedule another
soft interrupt.


Revision tags: mrg-merge-1-5-top
# 1.75 18-Jul-2000 pk

openfirmware: don't lower %pil


# 1.74 17-Jul-2000 pk

Kill typos in interrupt code.


# 1.73 17-Jul-2000 pk

probeget: do the same song and dance as ld*a() macros in ctlreg.h do.


# 1.72 14-Jul-2000 eeh

Move some macro definitions out of genassym and into locore.s


# 1.71 08-Jul-2000 mrg

backout part of previous: turn off intrdebug, and another debug message


# 1.70 07-Jul-2000 pk

Changes for readability:
- #define LP64 dependent STACKFRAME macro once
- use a LOAD_ASCIZ macro for setting up the format string
for debug messages.


# 1.69 07-Jul-2000 eeh

Temporary fix to prevent the clock from stopping on UIIi machines.


# 1.68 03-Jul-2000 eeh

Prevent interrupts from being posted if they are active and deprecate polled
interrupts. This seems to eliminate the spurious interrupts.


# 1.67 02-Jul-2000 eeh

Clean up interrupt handling some more.


# 1.66 30-Jun-2000 eeh

Fix interrupt delivery on UltraSPARC IIi machines.


# 1.65 24-Jun-2000 eeh

With these changes the kernel seems almost stable again.


# 1.64 24-Jun-2000 eeh

More VM cleanup:

Move the cpu_info structure above the interrupt stack so it won't
get corrupted if the stack overflows.

Flush the D$ before and after all MMU bypass accesses since the
D$ latches all of those.


# 1.63 23-Jun-2000 eeh

Make probeget() and probeset() really work for a change.


Revision tags: netbsd-1-5-base
# 1.62 19-Jun-2000 eeh

branches: 1.62.2;
Have separate data and text segments, make text read-only.


# 1.61 12-Jun-2000 eeh

Start reorganizing the kernel for MULTIPROCESSOR support.


# 1.60 31-May-2000 thorpej

Add a comment about needing to initialize p_cpu when multiple
processors are supported.


Revision tags: minoura-xpg4dl-base
# 1.59 26-May-2000 thorpej

branches: 1.59.2;
First sweep at scheduler state cleanup. Collect MI scheduler
state into global and per-CPU scheduler state:

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

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

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

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

Tested on i386 and Alpha. Changes are mostly mechanical, but apologies
in advance if it doesn't compile on a particular platform.


# 1.58 26-May-2000 thorpej

Don't set `runtime' here; it's done at the end of mi_switch().
cvS: ----------------------------------------------------------------------


# 1.57 26-May-2000 thorpej

Introduce a new process state distinct from SRUN called SONPROC
which indicates that the process is actually running on a
processor. Test against SONPROC as appropriate rather than
combinations of SRUN and curproc. Update all context switch code
to properly set SONPROC when the process becomes the current
process on the CPU.


# 1.56 22-Apr-2000 eeh

If we trap due to a bad kernel stack, try to switch to the interrupt strack
before breaking into the debugger.


# 1.55 18-Apr-2000 eeh

Prevent the system from getting watchdog reset by returning directly to user
mode if restoring the user window traps. Also reduce the time we run with
%tl>0.


# 1.54 13-Apr-2000 eeh

Apparently gas 2.9.5 (don't ask) does not like to add values to %lo()
directives so move the additions inside %lo() to make it happy.
Hopefully this won't break older versions.


# 1.53 10-Apr-2000 mrg

- fix a speeling error
- rename some numbered labels to be a bit less confusing.
- remove dead code
- fix a debug error message (argh!)


# 1.52 10-Apr-2000 pk

Get a kernel without DDB to build.


# 1.51 16-Mar-2000 eeh

Revamp interrupts again:

Fix a bug causing interrmittent panics in interrupt dispatch.
Use interrupt vectors for softints.
Add a new send_softint interface.
Improved D$ flushing.
Improve traptrace and other debugging enhancements.


Revision tags: chs-ubc2-newbase
# 1.50 16-Jan-2000 eeh

Interrupt handlers return zero if they didn't handle the interrupt.


# 1.49 10-Jan-2000 eeh

Add debugger single-stepping and fix interrupt dispatch bugs.


# 1.48 30-Dec-1999 eeh

Lots of changes:

remove ffs()
add bzero that uses block store insns
save %gsr to fpstate
revert to physical accesses for pmap_zero_page so we don't
have conflicting page mappings
general cleanup.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base fvdl-softdep-base
# 1.47 06-Nov-1999 eeh

Handle zero length properly in copyinstr() copyoutstr() and copystr().


Revision tags: comdex-fall-1999-base
# 1.46 11-Oct-1999 eeh

branches: 1.46.2; 1.46.4;
Update to post 1.4.


# 1.45 05-Oct-1999 eeh

branches: 1.45.2;
Make broken versions of gas happy by using sethi/or instead of set for
(negative) addresses.


# 1.44 17-Sep-1999 thorpej

Centralize the declaration and clearing of `cold'.


Revision tags: chs-ubc2-base
# 1.43 18-Jul-1999 eeh

More fun with pmap.


# 1.42 21-Jun-1999 eeh

Improve TRAPTRACE. Add FLTRACE that only tracks MMU faults.


# 1.41 05-Jun-1999 eeh

Make pbrobeget() and probeset() work for 64-bit values as well. To do this
the arguments are changed so the address is first and the ASI second so we
can have the address in %o0:%o1 and not worry about unused registers.

Also a bit of copyright cleanup.


# 1.40 05-Jun-1999 mrg

update a commit slightly.


# 1.39 30-May-1999 eeh

Add code to support using %tick as the system clock if no "counter-timer" node
is found.


# 1.38 09-May-1999 eeh

Fixup non-DEBUG kernels.


# 1.37 29-Apr-1999 christos

Add sunos_sigcode (32 bit only)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.36 26-Mar-1999 eeh

branches: 1.36.4;
COMPAT_SPARC32 -> COMPAT_NETBSD32


# 1.35 25-Mar-1999 mrg

clean and up make compile


# 1.34 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.33 22-Mar-1999 eeh

Need to set up the pointers properly for partial FPU register stores.


# 1.32 22-Mar-1999 eeh

Flush D$ on bypass accesses.


# 1.31 28-Feb-1999 eeh

Use block load/store in pmap_zero_page()/pmap_copy_page().


# 1.30 17-Feb-1999 eeh

Let's test out vectored interrupts.


# 1.29 15-Feb-1999 hubertf

RCS ID police


# 1.28 11-Feb-1999 mrg

fix a comment pasto.


# 1.27 11-Jan-1999 eeh

Finally fixed 64-bit signal trampoline.


# 1.26 10-Jan-1999 eeh

Handle the symbol table properly in a 32-bit kernel that was booted from a
64-bit bootloader.


# 1.25 09-Jan-1999 eeh

More signal fixup.


Revision tags: kenh-if-detach-base
# 1.24 26-Nov-1998 mycroft

Sync kcopy() with 32-bit SPARC version.


# 1.23 16-Nov-1998 eeh

Fixup the last broken bits of the signal handling code.


Revision tags: chs-ubc-base
# 1.22 08-Oct-1998 eeh

Fix more syscall32 and signal breakage.


# 1.21 22-Sep-1998 eeh

More fixup in the signal area.

64-bit syscall cleanup.

Add emulation for some new FPU insns: conversion to 64-bit long int and
conditional moves.


# 1.20 17-Sep-1998 thorpej

SYS_sigreturn -> SYS___sigreturn14.


# 1.19 13-Sep-1998 eeh

Fixup signal changes (hopefully). However SUN_COMPAT is likely broken by
this and I don't know how to fix it.

We can now exec a 64-bit init through a really ugly hack (don't ask.)


# 1.18 11-Sep-1998 eeh

Add labels for the compat_sparc32 signal trampoline and break -- er -- fix
suword and fuword.


# 1.17 09-Sep-1998 eeh

Don't use %tick for microtime on 32-bit kernels -- breaks gettimeofday.


# 1.16 09-Sep-1998 thorpej

Adjust for the new "reaper" kernel thread: do not free the vmspace and
u-area in machine-dependent code. Instead, call exit2() to schedule
the reaper to free them for us, once it is safe to do so (i.e. we are
no longer running on the dead proc's vmspace and stack).


# 1.15 07-Sep-1998 eeh

Fix data corruption problem caused by broken debug code.


# 1.14 07-Sep-1998 eeh

Add new 64-bit trap vectors.


# 1.13 06-Sep-1998 eeh

32-bit fixup.


# 1.12 06-Sep-1998 eeh

Disable some debug stuff.


# 1.11 05-Sep-1998 eeh

It slices. It dices. It does everything except exec a sparc32_compat init.


# 1.10 02-Sep-1998 eeh

Periodic update: now starts probing devices.


# 1.9 30-Aug-1998 eeh

Some more 64-bit cleanup. Now everything compiles.


# 1.8 29-Aug-1998 eeh

Some more 64-bit-ification.


# 1.7 27-Aug-1998 eeh

Add 64-bit pmap support:

Moved from a two level 512/1024 entry setup mapping 32 (9/10/13) bits
respectively to a three level 1024/1024/1024 entry setup mapping 43
(10/10/10/13) bits. In 32-bit mode we waste about 1/12 pages mapping the high
11 bits. We also only manage 43 of the possible 44 bits of virtual address
space, wasting half of it. Oh well, maybe we'll do better next revision.


Revision tags: PMAP32
# 1.6 26-Aug-1998 mrg

panicstack: is needed outside of DEBUG. use _C_LABEL, and printf not db_printf (incase no ddb!)


# 1.5 13-Aug-1998 eeh

Merge paddr_t changes into the main branch.


Revision tags: eeh-paddr_t-base
# 1.4 07-Jul-1998 eeh

branches: 1.4.2;
General update:

Added genassym.cf
Removed lderr which should never have gotten in
Removed lots of dead code from locore.s
Added some softint stuff to intr.c
Added support for halt -p
esp and le both use bus_dmamap_*() functions now
instead of kdvma_mapin()
groundwork for PCI (but we still have no drivers for
any sun4u PCI devices)


# 1.3 04-Jul-1998 jonathan

defopt DDB.


# 1.2 26-Jun-1998 thorpej

defopt COMPAT_SVR4


# 1.1 20-Jun-1998 eeh

branches: 1.1.1;
Initial revision


# 1.432 23-Feb-2023 riastradh

sparc64: Add missing barriers in cpu_switchto.

Details in comments.

PR kern/57240

XXX pullup-8
XXX pullup-9
XXX pullup-10


Revision tags: netbsd-10-base bouyer-sunxi-drm-base
# 1.431 05-Jul-2022 andvar

fix various typos in comments.


# 1.430 27-Jun-2022 andvar

fix various typos in comments.


# 1.429 22-May-2022 andvar

fix various small typos, mainly in comments.


# 1.428 16-May-2022 mrg

try to handle ultrasparc III* "fast ecc error" traps.

i had a sunblade 2500 reset with this trap recently, and the
manual says it should have been recoverable. in particular,
the US IIIv2 manual says in section 12.4.4.2 that the i-cache
won't see this data ever (so nothing needed there), and that
the d-cache needs to be disabled, and all the entries flushed,
and then re-enabled.

tested with a "trap 0x70" from kernel space, that trap.c
converted the "0x170" back to "0x70" (with an ADVANCE). this
code not commited.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 1.427 03-Apr-2021 palle

Improve cpu_idle() by allowing a platform specific implementaion (same logic as the sparc implementation) - currently only used by sun4v


# 1.426 30-Mar-2021 palle

sun4v: handle spill trap properly when trap level is 1 and otherwin is non-zero - ensure that all windows are spilled to the pcb like the sun4u winfixsave code path


# 1.425 22-Feb-2021 palle

branches: 1.425.2;
sun4v: handle spill normal user traps properly when current trap level is 1 - registers are spilled to the PA of the stack to avoid further mmu-related traps, since sun4v only has 2 trap levels


# 1.424 20-Dec-2020 palle

sun4v: add comment in sun4v_tl1_ptbl_miss code path - no functional change


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1
# 1.423 08-Jan-2020 skrll

branches: 1.423.6;
oldlwp is always non-NULL in cpu_switchto so remove the test for NULL.


# 1.422 08-Jan-2020 ad

Hopefully fix some problems seen with MP support on non-x86, in particular
where curcpu() is defined as curlwp->l_cpu:

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

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

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

- Remove some KERNEL_LOCK handling which hasn't been needed for years.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 ad-namecache-base netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.421 18-Jul-2019 palle

branches: 1.421.4;
sun4v: added some missing comments to the code in pcbspill


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 1.420 07-Apr-2019 mrg

make trap 0x70 a TRAP() not UTRAP(). we should be able to handle
fast ECC error as a normal trap, and i saw this once a few years
ago but it never repeated so i haven't been able to test this.


# 1.419 08-Feb-2019 palle

sun4v: Improve comment for next_stick_init() - no functional changes


# 1.418 08-Feb-2019 palle

sun4v: initialize %stickcmpr properly when establishing interrupt - fixes issue seen on newer sun4v/SPARC-T5 system where the interrupt never fires.


# 1.417 08-Feb-2019 palle

sun4v: introduce macros for handling spill traps from userlevevel @ traplevel 1 (from OpenBSD) - spill traps at level 1 from userspace now works better


# 1.416 08-Feb-2019 palle

sun4v: add comment documenting the contents of the %g2 register - no functional changes


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126
# 1.415 04-Nov-2018 palle

Ensure that the 64-bit condition codes are used instead of the 32-bit condition codes. ok martin@


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.414 26-May-2018 palle

branches: 1.414.2;
next_stick() - fix typy in comment: tick->stick


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.413 11-Apr-2018 palle

sun4v: handle MMU-related traps properly when they occur at trap level 1. This fixes issues when user-level LWPs access the user-level stack


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 1.412 26-Aug-2017 palle

branches: 1.412.2;
sun4v: Avoid touching the %tick_cmpr register which is not present on never systems (Oracle SPARC Architecture 2011 and beyond). Based on code from OpenBSD locore.s revision 1.177. Tested on both sun4u (qemu and USIII) and sun4v (qemu and T5-2). ok martin@


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2
# 1.411 06-May-2017 palle

sun4v: The %ver register is not available on sun4v - use GET_MAXCWP introduced in rev. 1.361. Verified using qemu (sun4u and sun4v) and on real sun4v hw (t2000)


Revision tags: prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.410 18-Apr-2017 palle

branches: 1.410.2;
sun4v: Add handling of trap 0x06c @ trap level 1 - based on code from OpenBSD, but slightly adapted to NetBSD. verified using qemu


Revision tags: jdolecek-ncq-base pgoyette-localcount-20170320
# 1.409 19-Feb-2017 palle

sun4v: rft_user needs special handling (a manual fill) since the restore instruction may cause the number of trap levels to exceed the maximum for sun4v - inspired by code from the the openbsd rft_user code path - verified using qemu for both sun4u and sun4v


# 1.408 10-Feb-2017 palle

sun4v: Added handling of trap type 0x034 (address alignment error) + fixed typo mmfsa -> mmufsa. Verified for both sun4u and sun4v using qemu.


Revision tags: nick-nhusb-base-20170204
# 1.407 30-Jan-2017 palle

sun4v: Hook up syscall handling to the trap table. Verified using qemu for both sun4u and sun4v.


# 1.406 27-Jan-2017 palle

sun4v: implement missing handling of itsb traps 0x008 and 0x009. Based on code from OpenBSD. Tested using qemu.


Revision tags: bouyer-socketcan-base
# 1.405 07-Jan-2017 palle

branches: 1.405.2;
sun4v: slowtrap() now selects normal globals properly on both sun4u and sun4v platforms. Verified using qemu for both sun4u and sun4v systems


Revision tags: pgoyette-localcount-20170107
# 1.404 05-Jan-2017 palle

sun4v: TRAP_SETUP() updated to set mmu context id properly for both sun4v and sun4u platforms. Verified using qemu for both sun4u and sun4v systems


# 1.403 04-Jan-2017 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x00-0x23 and 0x28-0x30


# 1.402 29-Dec-2016 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x32-0x7f


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.401 20-Sep-2016 nakayama

Fix RAS for 32-bit kernels. trapframe is always 64-bit.


Revision tags: localcount-20160914
# 1.400 23-Aug-2016 palle

sun4v: rework sun4v_datatrap so it works properly when running on a T2-based system like T5120 - for some reason %tl is 0 when entering sun4v_datatrap causing a crash (sir instruction), so ignore the %tl value for now upon entry to sun4v_datatrap - with this fix both T1 and T2 based systems reach the same point - hangs in rft_user after the init process is started


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726
# 1.399 18-Jul-2016 palle

sun4v: handle device interrupts properly - both legacy (sysino) and cookies


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 1.398 04-Jun-2016 palle

branches: 1.398.2;
sun4v: rtf_user now uses macros GET_MMU_CONTEXTID and SET_MMU_CONTEXTID. Tested on sun4u (QEMU) and sun4v (T2000). Parts from OpenBSD.


Revision tags: nick-nhusb-base-20160529
# 1.397 18-May-2016 nakayama

Decrement %tl in trap handler not to make it zero unconditionally
for the nested trap, and remove useless mov.


# 1.396 17-May-2016 palle

sun4v: Implement missng MMU protection trap handling - mostly from OpenBSD


# 1.395 16-May-2016 palle

Avoid assembler-specific defines by using the export keyword in genassym.cf instead


# 1.394 15-May-2016 nakayama

%g1 is not preserved across function call, so load it before
return_from_trap.


# 1.393 13-May-2016 palle

sun4v: add missing implementation of sun4v_datatrap_tl0 so data_access_fault() is called - mostly from OpenBSD


# 1.392 13-May-2016 nakayama

- ci_paddr is always 64-bit.
- intrlev is array of pointer.
- ih_ack is pointer.


# 1.391 10-May-2016 palle

sun4v: make device interrupts work. Introduce a new intrhand_alloc() function for allocation of interrupt handlers and adapt to this. Parts from OpenBSD. ok martin@


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.390 09-Mar-2016 nakayama

32-bit kernels use 32-bit stack.


# 1.389 03-Mar-2016 palle

sun4v: rft_kernel should pay attention to the number of register windows that can be restored. We cannot rely on fill traps to occur, since sun4v only has two trap levels available in privileged mode. Based on code from OpenBSD. ok martin@


# 1.388 14-Feb-2016 palle

sun4v: add breakpoint trap entry to the sun4v trap table


# 1.387 03-Feb-2016 palle

sun4v: extend dmmu_set_secondary_context() to handle both sun4u and sun4v. ok martin@


Revision tags: nick-nhusb-base-20151226
# 1.386 06-Nov-2015 martin

Basically revert r1.246 of locore.s and r1.73 of vm_machdep.c:

Remove special case handling for userland lwps from cpu_lwp_fork,
instead do it in lwp_trampoline when we first return to userland.

which was a stupid idea - since we did now set all fork child's %tstate
(and thus %pstate when back in userland) to the current kernel's userland
default. This meant we lost the address mask bit for 32bit processes and
all memory model details for 64bit ones.

Move it back to cpu_lwp_fork and fix the condition to only do it once when
forking init.


# 1.385 05-Nov-2015 martin

Most of the time return_from_trap already got called with tf->tf_tstate
loaded in register %g1 - make it so for two more callers and remove
the reload of that value.


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606 nick-nhusb-base-20150406
# 1.384 05-Apr-2015 palle

sun4v: Ensure that the TTEs CP and CV bits are the same (both set) for the primary cpu and secondary cpus INTSTACK mappings


# 1.383 01-Apr-2015 palle

sun4v: Implement handling of cpu_mondo trap - from OpenBSD - tested using the Legion simulator


# 1.382 04-Mar-2015 palle

sun4v: revert some of the logic introduced in revision 1.378 - flushw is not necessary on sun4v (OpenBSD patches the flushw instruction to a nop instruction) - with these changes the kernel reaches cpu_boot_secondary_processors() when running in the Legion simulator (crashes due to missing handling of cpu_mondo_trap)


# 1.381 02-Mar-2015 nakayama

prom_printf converts "\n" to "\r\n" internally, so omit "\r".


# 1.380 02-Mar-2015 nakayama

PANICSTACK is a pointer itself, not a pointer to pointer.


# 1.379 02-Mar-2015 nakayama

Use panic stack temporarily for calling prom_printf in a trap
handler.

It seems that openfirmware cannot handle over 4GB pointers, and
stack pointers may point to over 4GB since VA layout was rearranged
by rev 1.33 of vmparam.h. Therefore, use panic stack to avoid
panicking in OF_write used by prom_printf.


# 1.378 23-Feb-2015 palle

sun4v: sparc_interupt - ensure that the trap level and globals level are the same when the flushw instruction is issued - othwise warnings occur when using the sun4v Legion simulator.


Revision tags: nick-nhusb-base
# 1.377 26-Oct-2014 palle

branches: 1.377.2;
sun4v: Create CLEANWIN0 and CLEANWIN1 macros for handling clean window traps on both sun4u and sun4u (based on the original code inlined in the sun4u trap table). Update trap tables accordingly for both sun4u and sun4v. Ok martin@


# 1.376 24-Oct-2014 nakayama

Fix typo in comment.


# 1.375 18-Oct-2014 snj

src is too big these days to tolerate superfluous apostrophes. It's
"its", people!


# 1.374 15-Oct-2014 palle

sun4v: fixed bug causing the real address to be incorrectly calculated as zero


# 1.373 24-Sep-2014 palle

sun4v: add code to enable startup of secondary cpus on both sun4u and sun4v systems - ok martin@


# 1.372 04-Sep-2014 palle

sun4v: All cpus must be setup with a TSB descriptor, so pmap_setup_tsb_sun4v() must take a pointer to the TSB descriptor


# 1.371 31-Aug-2014 palle

sun4v: Split the NORMAL_GLOBALS and ALTERNATE_GLOBALS macros to _SUN4U and _SUN4V variants. Rework the return_from_trap logic to use the new variants so it is possible to use a global register as scratch register.


# 1.370 14-Aug-2014 nakayama

Add missing delay slot in DEBUG kernel.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.369 30-Jul-2014 palle

branches: 1.369.2;
Fix ALTERNATE_GLOBALS so it at least works on sun4u - using a scratch register is not a good idea...


# 1.368 27-Jul-2014 palle

sun4v: Introduce a new macro ALTERNATE_GLOBALS (matching NORMAL_GLOBALS). Two new helper macros ENABLE_INTERRUPTS and DISABLE_INTERRUPTS are also created. With these changes the GENERIC.UP kernel will reach rootmount on sun4v systems - ok martin@


# 1.367 26-Jul-2014 palle

Improved the NORMAL_GLOBALS macro in the sun4u case, so only the relevant bit (AG) in %pstate is affected - ok martin@


# 1.366 24-Jul-2014 palle

sun4v: add missing spill/fill handling for trap level 1 + cosmetic changes to comments for trap level 0 entries


# 1.365 19-Jul-2014 palle

sun4v: Introduce a NORMAL_GLOBALS macro - first used in sparc_interrupt - other relevant uses will be handled as the sun4v work is progressesing - ok martin@


# 1.364 16-Jul-2014 palle

sun4v: Introduce SET_MMU_CONTEXTID macro for setting the mmu context id on both sun4u and sun4v


# 1.363 13-Jul-2014 palle

sun4v: add interrupt handling to sun4v trap table


# 1.362 13-Jul-2014 palle

Bugfix: add missing cmp instruction to GET_MAXCWP macro


# 1.361 30-Jun-2014 palle

sun4v: The maximum number of register windows is a constant and thus not available via the %ver register (sun4u only). Introduce a macro GET_MAXCWP that handles this, so cpu_switchto() works properly on sun4v. Other relevant reference to %ver can be adapted to use GET_MAXCWP as the sun4v port progresses. OK martin@


# 1.360 31-May-2014 palle

sun4v: added missing dtsb miss handling for trap level 1 - with this update the kernel now reaches configure() on sun4v systems


# 1.359 30-May-2014 palle

Remove debugging code introduced by accident in locore.s revision 1.357


Revision tags: yamt-pagecache-base9 rmind-smpnet-nbase rmind-smpnet-base
# 1.358 05-May-2014 palle

sun4v: the trap base address should be assigned to %l1 so %tba is properly setup later in the code - now the kernel gets as far as printing the copyright disclaimer, kernel version and total and available memory before crashing


# 1.357 21-Apr-2014 palle

sun4v: Update comment: modified -> access


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.356 21-Feb-2014 palle

branches: 1.356.2;
sun4v: Rename TLB_ defines to SUN4U_TLB_ so entries created using TSB_DATA() are properly setup for sun4u and sun4v. Relocate the cputyp variable from autoconf.c to locore.s and make it const in param.h so optimized code can be generated. Parts from OpenBSD. Optimization suggested by nakayama@. OK martin@, mrg@, nakayama@


# 1.355 31-Jan-2014 tsutsui

defined(LKM) -> defined(MODULAR)


# 1.354 26-Jan-2014 palle

sun4v: Add handling of spill/fill and dtsb miss traps (with a XXX to be handled later)


# 1.353 07-Jan-2014 palle

sun4v: trap table setup - currently populated with dummy entries which will be properly implemented later - parts from OpenBSD - OK martin@


# 1.352 29-Dec-2013 nakayama

Make buildable w/o options SUN4V.


# 1.351 27-Dec-2013 palle

a) make the hunt through the cpus list more generic b) sun4v: ensure that the interrupt stack is mapped permanently and the TSB is setup properly - parts from OpenBSD. OK martin@


# 1.350 06-Dec-2013 nakayama

Increase an interrupt depth only in the case of hardware interrupts,
and remove the ci_idepth trick in softint_fastintr.

Fixes the following diagnostic panic reported in port-sparc64.

panic: kernel diagnostic assertion "!cpu_intr_p()" failed: file
"../../../../kern/subr_xcall.c", line 351


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 1.349 24-May-2013 nakayama

branches: 1.349.2;
Disable interrupts after calling data_access_error as with
data_access_fault.


# 1.348 28-Apr-2013 nakayama

Use macros in machine/asm.h instead of locally defined, and
introduce CASPTRA for casxa/casa.


Revision tags: agc-symver-base
# 1.347 23-Jan-2013 martin

Fix sparc64_ipi_ccall by adding proper trap setup.
Fixes xcall(9) problems, as exposed by pserialize(9). Noticed by
J. Hannken-Illjes, cause pointed out by Takeshi Nakayama.


# 1.346 23-Jan-2013 martin

Sligthly clean up the (by default unused) #ifdef TRAPS_USE_IG


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.345 10-Nov-2012 nakayama

Revise comment.


# 1.344 10-Nov-2012 nakayama

Use macro instead of magic number.


# 1.343 09-Nov-2012 nakayama

Make setstick() and getstick() to inline functions.


# 1.342 08-Nov-2012 macallan

use system tick timer instead of %tick on UltraSPARC-III-ish CPUs
review & fixes by Takeshi Nakayama


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.341 17-Mar-2012 mrg

branches: 1.341.2;
port the corrected ECC error handling code from freebsd. i noticed my U10
took one of these and then hang. it shouldn't hang, there's a 'sir' here that
doesn't seem to reset properly. oh well.

tested by simulated a trap via 'ta 0x10' and considering that the same, but
it hasn't been tested against a real ECC error yet.


Revision tags: jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base4
# 1.340 03-Mar-2012 nakayama

Fix the root cause of the hack "disable optimizations for uvm_bio.c
on 32 bit kernels".

gcc converts a division in the calculation of UBC_UMAP_ADDR macro
to multiplication (smul or combination of add/sll), and the
register of its result contains a garbage in upper 32 bits (the
upper 32 bits of smul/add/sll's result isn't zero cleared).

Then it passes to pseg_get{,_real} through pmap_extract without the
zero clear of upper 32 bits in the optimization case. So the
result of pseg_get and pmap_extact sometimes gets screwed up.


Revision tags: jmcneill-usbmp-base5 jmcneill-usbmp-base3
# 1.339 19-Feb-2012 rmind

Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.


Revision tags: jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.338 04-Sep-2011 nakayama

branches: 1.338.2; 1.338.6; 1.338.8;
ih_pil is an interrupt level, not an interrupt mask.


# 1.337 27-Jul-2011 nakayama

ivec is assigned to hardware, so count its event counter up in
interrupt_vector, not in softint, and do some optimization.


# 1.336 20-Jul-2011 macallan

add per ivec event counters


# 1.335 12-Jul-2011 mrg

rename sparc64 BLOCK_SIZE and BLOCK_ALIGN to have SPARC64_ prefixes.
for the assembler files, define the old names to the new names
since using the new names cause ugliness due to longer identifer
names, and reduces churn.

fixes build issues in dtv and vaguely makes <machine/psl.h> slightly
less name-space invasive.


# 1.334 18-Jun-2011 nakayama

Add fast softint(9) support for sparc64.

Reviewed on port-sparc64.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 1.333 12-May-2011 mrg

branches: 1.333.2;
first steps towards fujitsu SPARC64 support:

- SPARC64 systems have interrupts with upto 14 bits set, but we only look
at the first 11 bits. trim non IPI interrupts to 11 bits


Revision tags: uebayasi-xip-base7 bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 jym-xensuspend-nbase jym-xensuspend-base
# 1.332 20-Dec-2010 matt

branches: 1.332.2;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.


Revision tags: uebayasi-xip-base6 uebayasi-xip-base5 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 1.331 10-Jul-2010 nakayama

Clear the upper word explicitly before combining two 32-bit values to 64-bit
on 32-bit kernels.


# 1.330 23-May-2010 martin

Split copy related functions out of locore.s into copy.S, move functions
only needed on multiprocessors into mp_subr.S.


# 1.329 17-May-2010 martin

Simplify primary CPU startup slightly by using the fact that our cpuinfo's
curpcb pointer points to the uarea/pcb of lwp0 and by remembering the pointer
to this cpuinfo, thus avoiding a few CPUINFO_VA references.


Revision tags: uebayasi-xip-base1
# 1.328 20-Mar-2010 chs

fix copy{in,out}{,str}() to return the error returned by uvm_fault().
fixes PR 41813.


Revision tags: yamt-nfs-mp-base9
# 1.327 10-Mar-2010 mrg

branches: 1.327.2;
XXX: workaround we'd like to remove when pmap / uvm locking is cleaned up:

- rename pseg_get() and pseg_set() to pseg_get_real() and pseg_set_real().
- if USE_LOCKSAFE_PSEG_GETSET is defined, which it current is by default,
define pseg_[gs]et() in terms of functions that take a new pseg_lock
mutex at IPL_VM while calling into the real functions.

this seems to avoid the pseg_set() crashes we've seen:
1 - spare needed, when pseg_get() just worked for this pmap
2 - the 2rd ldxa via ASI_PHYS_CACHED in pseg_set() loads garbage
into %o4, and causes the 3rd ldxa to fault


# 1.326 08-Mar-2010 mrg

blast_dcache() SMP friendly:

- blast_dcache() becomes sp_blast_dcache(dcache_size, dcache_line_size)
- new smp_blast_dcache(sparc64_cpuset_t) that blasts the D$ on this cpuset
- sparc64_ipi_blast_dcache() to support the above
- in pmap_remove_all(), when freeing mmu contexts for this pmap, mark
the set of cpus to blast the d$ on as well and convert the
blast_dcache() call into smp_blast_dcache() on the cpus who ran this
pmap, or, sp_blast_dcache(dcache_size, dcache_line_size)
- convert the remaining blast_dcache() in machdep.c to sp_blast_dcache()
- in pmap_destroy()/pmap_remove_all() take the pmap_lock() always since
we assert it is held always.

with these changes, NFS builds on the U60 seem to be stable now, and
the USIII machines also can often complete a single build.sh run now,
diskful or diskless.


reviewed by mlelstv and partially by martin, tested by martin and myself,
with some ideas from chuq as well.


# 1.325 07-Mar-2010 mrg

need _ALIGN in locore.h as well, for DEBUG kernels.


# 1.324 07-Mar-2010 mrg

gas has supported SPARC ".empty" for a long while; get rid of an
ancient workaround.


# 1.323 06-Mar-2010 mrg

move the memcpy/memset implementations out into their own file, with the
block copy versions as well. move some of the definitions in locore.s
into a new locore.h.

locore.s is almost 2000 lines shorter with this change.


# 1.322 04-Mar-2010 mrg

- in _bus_dmamap_unload(), pmap_page_protect() and pmap_clear_reference()
switch the dcache_flush_page() into a dcache_flush_page_all()
- in both pmap_kremove()/pmap_remove(), remove the blast_dcache() call
and replace it with dcache_flush_page_all()
- in pmap_get_page() [used to allocate PTP's], always call pmap_zero_page(pa)
- flush the dcache of the dst page in pmap_{copy,zero}_page() by redirecting
throught a C function that calls the (renamed) asm. the old asm code had a
comment about needing to do this...
- add a couple of membar #Sync's that the USIII manual recommends


based on discussions with chuq@, skrll@ and martin@.


these help my SB2000 / SB2500 with both disk / nfs builds and other tasks,
sometimes lasting for several hours before failing or asserting.


# 1.321 24-Feb-2010 mrg

when handing back page table pages to UVM, flush them from the dcache
on all CPUs.

idea from skrll@, and makes my disk-based SB2000 stable.

tested on U60, SB2000 and SB2500.


# 1.320 24-Feb-2010 mrg

- re-introduce sp_tlb_flush_pte() and sp_tlb_flush_all() that call
the right USI/USIII version.
- define tlb_flush_pte() in terms of sp_tlb_flush_pte() for the
!MULTIPROCESSOR case

this centralises some CPU_IS_USIII_UP() tests.


# 1.319 22-Feb-2010 mrg

move {dump,print}_[id]tlb() into a separate file.


# 1.318 22-Feb-2010 mrg

- store the maximum [id]cache size / line size for each cpu

- remove patch_kernel() since it isn't necessary and has been patching
the wrong thing in general.

- implement USIII versions of blast_icache(), dcache_flush_page() and
cache_flush_phys(). use the newly recorded cache size/line sizes.

- in winfixsave, flush the D$ with the right size index and ops. this
kills one of the wrong tag->inval patches.

- for blast_dcache(), use the newly recorded dcache_size/line_size.

- for blast_icache(), use the newly recorded cache size/line sizes.
for the USIII verison, disable the I$ while writing to ASI_ICACHE_TAG.


these changes removed several hard coded cache sizes values, some very
wrong kernel patching, and seem to make the current failure modes for
USIII less common, but not gone.


# 1.317 15-Feb-2010 mrg

- don't flush 32-bit entries for 64-bit code, it does not seem to be
necessary. #define TLB_FLUSH_LOWVA to turn it back on.
- remove the #if 0'd code in sparc64_ipi_flush_pte_usiii(), i have
verified that it is not required.
- add a missing membar #Sync to sp_tlb_flush_pte_usiii().


# 1.316 15-Feb-2010 nakayama

Fix linker error of GENERIC32 kernel.


# 1.315 15-Feb-2010 mrg

use TLB_SIZE_SPITFIRE in a couple of places, and note that the
{print,dump}_[id]tlb() versions are currently spitfire specific.


# 1.314 15-Feb-2010 mrg

introduce a new patch_kernel() and call it from the end of bootstrap().
use it to patch up TLB flush instructions that don't match for USI/II
and later. we can also hopefully use this to make GENERIC.MP minimally
expensive on single CPU machines as well.

this is the last piece needed to get GENERIC/GENERIC.MP to boot on the
USIII* machines.

idea and some initial code from openbsd.


# 1.313 13-Feb-2010 mrg

remove KTR support. it's never been a working part of netbsd src tree.


# 1.312 09-Feb-2010 wiz

Fix typo in comment.


Revision tags: uebayasi-xip-base
# 1.311 06-Feb-2010 mrg

branches: 1.311.2;
- properly map the schizo interrupt registers, so we can use the normal
virtual mappings to access them.
- with the above fxied, kill SCHIZO_BUS_SPACE_BROKEN, and introduce
an options CHEETAH for now, that disables the SPITFIRE code in locore.
- merge schizo_init() into schizo_attach() and clean up the softc a bit.


with this we are only one more step away from GENERIC booting on USIII
machines.


# 1.310 02-Feb-2010 mrg

- split sp_tlb_flush_pte() and switchtoctx() into sp_tlb_flush_pte_us()/
sp_tlb_flush_pte_usiii() and switchtoctx_us()/switchtoctx_usiii() and
implement the latter while i'm here. it works ... sometimes i think,
but also sometimes panics/hangs.
- fix a comment in sparc64_ipi_flush_pte_usiii()


# 1.309 02-Feb-2010 mrg

for now, reduce a few #ifdef SPITFIRE cases by introducing a new
ASI_DCACHE_TAG_OR_INV that is either ASI_DCACHE_{TAG,_INVALIDATE}.

increase the common code in cache_flush_phys().


# 1.308 01-Feb-2010 mrg

- sp_tlb_flush_all() becomes sp_tlb_flush_all_us() and sp_tlb_flush_all_usiii()
- sparc64_ipi_flush_pte() becomes sparc64_ipi_flush_pte_us() and
sparc64_ipi_flush_pte_usiii()
- add some commented out code to disable interrupts and raise the traplevel
in sparc64_ipi_flush_pte_usiii()
- cache_flush_phys() was missing a little of code in the cheetah case


# 1.307 01-Feb-2010 mrg

for USIII, use the new "tlb demap all" operation in sp_tlb_flush_all()


# 1.306 01-Feb-2010 mrg

remove unused icache_flush_page() implementation.


# 1.305 23-Jan-2010 mrg

remove the final uses of DATA_START.

now we can remove the 16KB space reserved at the start of the data segment,
and i now understand why i wrote this now removed comment 3.5 years ago:
"this shouldn't be needed... but kernel usually hangs without it"


# 1.304 23-Jan-2010 mrg

remove most of the code that writes debugging info DATA_START + offset.


# 1.303 23-Jan-2010 mrg

remove CHKPT() macro and uses. it's likely wrong in SMP land and probably should
be replaced with KTR-style uses if necessary.


# 1.302 23-Jan-2010 mrg

fix a comment.


Revision tags: matt-premerge-20091211
# 1.301 10-Dec-2009 rmind

Rename L_ADDR to L_PCB and amend some comments accordingly.


# 1.300 05-Dec-2009 mrg

- adjust the PA mask to the 43 bits supported by USIII.
- rework the spitfire/cheetah cache_flush_phys() to avoid several #ifdefs
- add a membar #Sync after sparc64_ipi_drop_fpstate (probably unnecessary)


# 1.299 30-Nov-2009 nakayama

sp_tlb_flush_pte for cheetah:
- restore interrupts properly in case of %tl > 0.


# 1.298 30-Nov-2009 mrg

stablize UP USIII support by blocking interrupts around sp_tlb_flush_pte()
i was seeing stack corruption while taking an interrupt in this function.

get USIII SMP mostly working by implementing the cheetah version of
sparc64_ipi_flush_pte().


SMP support is still not entirely stable. i can reproducably get a:

panic: fpusave_lwp ipi didn't

while running build.sh, when an awk process is exiting. other simple
heavy work loads do not crash for me right now.


# 1.297 30-Nov-2009 mrg

delete some no longer used code:
- smp_tlb_flush_ctx()
- smp_tlb_flush_all()
- sparc64_ipi_flush_ctx()
- sparc64_ipi_flush_all()
- sp_tlb_flush_ctx()


# 1.296 29-Nov-2009 nakayama

- calculate end PA correctly.
- wrap more spitfire specific (flushing I$) code.
- fix inverted #if condition for flushing I$ (and restore ASI_ICACHE_TAG).


# 1.295 28-Nov-2009 mrg

implement enough code to get SB2000/SB2500 booting to multiuser. does
not last long if you use it, but an idle machine has stayed up 10 hours.

- for the !SPITFIRE case, use ASI_DCACHE_INVALIDATE instead of
ASI_DCACHE_TAG when clearing tlb entries. from openbsd.

- convert some comment "! Not yet" into "WRITEME", so that attempting
to build a USIII MULTIPROCESSOR kernel fails to build until the code
is written.

- add some more WRITEME's for the above.

- implement a !SPITFIRE version of sp_tlb_flush_all(). since there are
no spare regs, for now just always increase %tl around this call. (we
could maybe store a token in %o3 along with the saved %pstate info.)


# 1.294 26-Nov-2009 matt

Kill proc0paddr. Use lwp0.l_addr instead.


# 1.293 25-Nov-2009 mrg

s/L_ADDR/L_PCB/, requested by rmind.


# 1.292 17-Oct-2009 nakayama

Wrap unused code with #if 0 which is called from #if 0'ed code.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5
# 1.291 30-May-2009 martin

cpu_setfunc() can not use lwp_trampoline, as that has additional lwp startup
semantics. Use a simpler setfunc_trampoline instead.


# 1.290 18-May-2009 nakayama

Remove random() from locore.s since it is in libkern.


# 1.289 16-May-2009 nakayama

Remove clear %tick in locore.s since it is cleared at cpu_initclocks() in
clock.c.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 nick-hppapmap-base mjf-devfs2-base
# 1.288 15-Dec-2008 mrg

restore some old "intrdebug" code, but leave it under NOT_DEBUG. most
of it works, but one that prints func/arg for each handler is not very
stable...

for now, while schizo bus space pointer accesses aren't working, add
a SCHIZO_BUS_SPACE_BROKEN option so you can build a kernel with schizo.

with this, and the prior schizo interrupt fix, you can now fail to run
/sbin/init!


Revision tags: haad-dm-base2 haad-nbase2 haad-dm-base
# 1.287 09-Dec-2008 martin

Get rid of get_maxctx() - it doesn't work on newer cpus and we will have
to find a better way for (some) sun4v machines - all sun4u use 13 bit
contexts anyway.


Revision tags: netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 ad-audiomp2-base netbsd-5-base
# 1.286 30-Oct-2008 nakayama

branches: 1.286.2; 1.286.6;
Wrap more code specific to USE_BLOCK_STORE_LOAD.


Revision tags: matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4
# 1.285 05-Oct-2008 nakayama

branches: 1.285.2;
- in flushing cache, use 32 as increment/decrement value to match the
cache line size.
- remove useless restore of %asi.
- remove nop in delay slot if we can.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 1.284 10-Jul-2008 nakayama

Use proper CCR.


# 1.283 10-Jul-2008 nakayama

sparc64_ipi_save_fpstate:
- use primary MMU context for consistency with other trap/interrupt handlers.

sparc64_ipi_save_fpstate, savefpstate:
- avoid storing fp registers as we can.

sparc64_ipi_save_fpstate, savefpstate, loadfpstate:
- remove unaligned case since buffers allocated with pool_cache are ensured
64-byte aligned.

Ok by martin@.


# 1.282 02-Jul-2008 nakayama

branches: 1.282.2;
UltraSPARCs don't have floating point queue, and reading %fq regsiter
will cause illegal instruction trap. So remove the code handling them.


# 1.281 29-Jun-2008 nakayama

Wrap IPI calls with #ifdef MULTIPROCESSOR.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.280 14-Jun-2008 nakayama

Close unterminated comment.
Fix unexpected behavior in case of loadfpstate from unaligned buffer.


Revision tags: yamt-pf42-base3
# 1.279 31-May-2008 nakayama

branches: 1.279.2;
openfirmware_exit:
- disable interrupts with %pstate.
- prepare 64-bit stack and enable 64-bit addresses for 32-bit SMP kernels.


Revision tags: hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 yamt-nfs-mp-base yamt-pf42-base
# 1.278 16-Apr-2008 nakayama

branches: 1.278.2; 1.278.4; 1.278.6;
Disable TRAPSTATS which was accidentally enabled when yamt-idlelwp branch
was merged.

Ok by martin@.


# 1.277 14-Apr-2008 nakayama

Remove sparc64_ipi_sync_tick.

Since we can use counter-timer as timecounter instead of %tick on SMP kernel,
it is not necessary to sync all CPUs %tick registers.


# 1.276 14-Apr-2008 nakayama

Add workaround for BB_ERRATA_1 on writing to TICK_CMPR register in
next_tick(). If writing to TICK_CMPR fails, we lose hardclock interrupt
on secondary CPUs.

About BB_ERRATA_1 from comment in OpenSolaris:

/*
* Writes to the TICK_COMPARE register sometimes fail on blackbird modules.
* The failure occurs only when the following instruction decodes to wr or
* wrpr. The workaround is to immediately follow writes to TICK_COMPARE
* with a read, thus stalling the pipe and keeping following instructions
* from causing data corruption. Aligning to a quadword will ensure these
* two instructions are not split due to i$ misses.
*/


# 1.275 28-Mar-2008 nakayama

Don't read fplwp content in delay slot for considering the case fplwp was
modifiled.

Reported by Chris Ross on port-sparc64.


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.274 20-Mar-2008 nakayama

- remove disabling interrupt in IPI.
- unused VA bits in MMU demap is 13 bits, not 12 bits.


# 1.273 18-Mar-2008 nakayama

Fix a race when increment an interrupt level event counter.


# 1.272 17-Mar-2008 nakayama

Fix a race condition in IPI handlers of save/drop fpstate, from OpenBSD.
Reported and tested by martin@.


# 1.271 17-Mar-2008 nakayama

Make schedintr interrupt handler per-CPU.
While there rename tickintr interrupt handler and share initialization
code with schedintr.


# 1.270 14-Mar-2008 nakayama

Improve IPI handling:
- make IPI takes two arguments.
- add IPI event counters per-CPU.
- implement IPI functions which were missing or broken.
- insert DELAY while halting primary CPU in IPI handler.


# 1.269 02-Mar-2008 nakayama

- make interrupt pending list per-CPU.
- make tickintr() MP-safe.
- remove unused port-sparc derived interrupt code.

Ok by martin@.


# 1.268 02-Mar-2008 nakayama

Don't get IPI handler argument (from bogus address), and ack IRQ twice.


# 1.267 28-Feb-2008 martin

Make TSBs and MMU contexts per-cpu.


Revision tags: nick-net80211-sync-base mjf-devfs-base hpcarm-cleanup-base
# 1.266 26-Jan-2008 nakayama

branches: 1.266.2; 1.266.6;
Fix for 32-bit kernels.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.265 15-Jan-2008 skrll

Store a sensbile PCB_PC value in snapshot - the return point.

This helps gdb somewhat.

OK'd by martin.


# 1.264 14-Jan-2008 martin

Fix register name typo/copy&pasto - %g6 is not %o6/%sp.
From OpenBSD.


Revision tags: matt-armv6-base
# 1.263 06-Jan-2008 martin

Load the next cpu_info pointer with LDPTR instead of ld.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2
# 1.262 09-Dec-2007 martin

branches: 1.262.2;
Provide cpu_intr_p(), at least for non-MULTIPROCESSOR kernels.
Based on suggestions by Andrew Doran.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.261 22-Oct-2007 martin

branches: 1.261.2; 1.261.4; 1.261.6;
Remove an unused .globl declaration


Revision tags: yamt-x86pmap-base4
# 1.260 17-Oct-2007 garbled

Merge the ppcoea-renovation branch to HEAD.

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

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

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base ppcoea-renovation-base vmlocking-base
# 1.259 09-Sep-2007 martin

branches: 1.259.4;
Make cpufrequency and friends per cpu values.
Prepare a hz tick interrupt on secondary CPUs via %tick, but do not
enable it yet, as it breaks ddb.


# 1.258 09-Sep-2007 martin

Do not ACK IPIs before we finished loading all arguments.


# 1.257 06-Sep-2007 martin

Remove the (now unused) second 64k page mapped per CPU.
From matthew green, with small changes by me. All bugs are mine.


# 1.256 25-Aug-2007 martin

branches: 1.256.2;
Remove INITSTACK completely - at the time we used to switch to it, we
already have access to all of lwp0 and it's uarea - so we can switch
to the correct lwp0 stack easily before calling main.


# 1.255 25-Aug-2007 martin

When exiting to OF, use the interrupt stack instead of INITSTACK


# 1.254 25-Aug-2007 martin

Rework cpu_mp_startup slightly:
- temporarily use the cpu's interrupt stack untill we are ready
to access non-OF-based mappings, then directly switch to the cpu's
idlelwp's uarea stack
- disable interrupts untill we are ready to call C code


# 1.253 13-Aug-2007 macallan

remove two restore without matching save


Revision tags: nick-csl-alignment-base matt-mips64-base mjf-ufs-trans-base
# 1.252 06-Jul-2007 martin

branches: 1.252.4; 1.252.8;
A few nits for 32bit SMP kernels, noticed by mrg.
While there, simplify the fpstate IPIs a bit.


# 1.251 05-Jul-2007 martin

sparc64_ipi_save_fpstate is not a leaf function - create a full grown
stack frame.


# 1.250 28-May-2007 mrg

clean up cpu_switchto() a little - no need to flushw or membar
excessively. optimise an rdpr. tested by tnn.


# 1.249 23-May-2007 martin

Fix a stupid bug in the save_fpstate ipi, which caused overwriting of
struct lwp of the lwp owning the fpu. Fix clearing the fplwp - %o0 will
not survive the call to savefpstate - duh!


# 1.248 20-May-2007 martin

Simplify tf_tstate setting when leaving for userland initially - I seem
to have confused the if with the else case of the previous C code.
Funny that it worked at all.


# 1.247 20-May-2007 martin

cpu_switchto() has to return it's first arg, always. This differs from
my reading of the documentation, but helps in the real world and seems
to be what other ports do.


# 1.246 20-May-2007 martin

Remove special case handling for userland lwps from cpu_lwp_fork, instead
do it in lwp_trampoline when we first return to userland.


# 1.245 19-May-2007 martin

cpu_idle is a leaf function, so we better "return from leaf".
Use return value from cpu_switchto for previous lwp in lwp_trampoline.
Also shamelessly steal a comment from uwe written for sparc that explains
all this.
Thanks to tnn, mrg, and uwe for helping to debug this.


# 1.244 17-May-2007 yamt

merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base ad-audiomp-base
# 1.243 22-Feb-2007 martin

branches: 1.243.4; 1.243.6; 1.243.12;
uvm.page_idle_zero now is a bool, not a 32bit value any more.


# 1.242 21-Feb-2007 mrg

shave 9 insns off the tsb setup in cpu_initialize & cpu_mp_startup.


# 1.241 21-Feb-2007 martin

Get rid of unused (thus always zero) "curlwp" variable hidden in assembler
code (C code always uses a cpuinfo based macro).


# 1.240 18-Feb-2007 martin

Make use of another call delay slot, pointed out by uwe.


# 1.239 18-Feb-2007 martin

Make use of a call delay slot and avoid a bogus EMPTY.
Spotted by Juergen Hannken-Illjes, with input from Andrew Doran and
Valeriy E. Ushakov.


# 1.238 18-Feb-2007 martin

Whitespace cosmetics


# 1.237 18-Feb-2007 martin

Backout previous: EMPTY was misused


# 1.236 18-Feb-2007 martin

Make EMPTY expand to nop with gas, as it is used to mark empty branch
delay slots.


# 1.235 15-Feb-2007 martin

branches: 1.235.2;
Fix obvious copy&pasto in SCHED_DEBUG register usage.


Revision tags: post-newlock2-merge
# 1.234 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.233 25-Dec-2006 wiz

Spell "relevant" correctly. From Zafer Aydogan.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.232 25-Oct-2006 mrg

branches: 1.232.2; 1.232.4;
- note that __idle_u should go away but doing so breaks things
- fix several comments to reality
- clean up the #ifdef NO_VCACHE code slightly
- use call instead of set/jmpl
- remove a couple of unnecessary stores to curlwp


Revision tags: yamt-splraiseipl-base2
# 1.231 18-Oct-2006 rjs

Clean up some comments. Cosmetic change to use correct structure
offset names.

Optimize out two instructions from sparc64_ipi_save_fpstate and
sparc64_ipi_drop_fpstate.


# 1.230 17-Oct-2006 mrg

allocate 128KB (as opposed to 64KB) per-cpu, and place the interrupt
stack, cpu_info structure, panicstack, idle uarea and normal kernel
stack in here. the idle uarea and kernel stack are in the 2nd 64KB
page. the interrupt stack and cpu_info structure are as the same
place in the 1st 64KB page, and the panicstack grows down from the
top of this page. update comments in param.h to suit (XXX: a lot
of these constants should move to a header file that will not pollute
the name space so much.) map these pages identically between
cpu_initialise() and cpu_mp_startup(), and deal with the two 64KB
pages in pmap_extract(). keep an unmapped 64KB page between them.

don't initialise the unused "ci_eintstack" member of the cpu_info
structure

use constants to initialise many addresses in the cpu_info structure,
consolidating these assignments from cpu0 and cpu>0

delete u0/estack0/panicstack from locore.s

clean up some wrong comments in locore.s

fix a 32bit-only bug in cpu_mp_startup().

delete 'u0' entirely.


this fixes recent random lossage seen on port-sparc64: processes
stuck in RUN state, data faults, and hangs.


# 1.229 04-Oct-2006 mrg

use call instead of set/jmpl. add an entry point for idle that expects
sched_lock to be unlocked, and use this for non-boot cpu's. complete a
comment describing how registers in idle_switch are expected to be set.


# 1.228 03-Oct-2006 mrg

use the same SAVE_LOCALS_INS definition for 32 bit and 64 bit kernels.
refactor TRAP_SETUP() a little between these two versions to be more alike.


# 1.227 03-Oct-2006 mrg

use the correct size/type for MP variables (pointers and longs).

a 32 bit MULTIPROCESSOR kernel now builds (and crashes quickly.)


# 1.226 03-Oct-2006 mrg

in the 64bit version of SAVE_LOCAL_INS, s/BIAS/STKB/ to allow future
sharing of the 32 and 64 bit versions of the {TRAP,INTR}_SETUP macros.


# 1.225 19-Sep-2006 mrg

- remove some way old FP setup/teardown code
- put the block memcpy/memset inside #ifdef USE_BLOCK_STORE_LOAD which
is (now) defined.

no functional change, same .o is generated.


# 1.224 19-Sep-2006 mrg

re-order the changes in rev 1.217 to give registers a little bit of
time to settle between usage, like it was before hand.


# 1.223 19-Sep-2006 mrg

- remove a wrong comment.
- add a new entry point for idle called idle_switch that is called by
cpu_switch() in the MP case when sched_whichqs is zero, properly
setting up the idle stack. from petrov@ via martin@.


# 1.222 19-Sep-2006 mrg

rework interrupt_vector() slightly:
- for the IPI case, avoid loading the address of intrlev into %g3
- remove some NOT_DEBUG code
- load the interrupt argument #2 in the delay slot

this removes 2 nops during interrupt processing for the normal
case, and an additional 2 ALU instructions for IPIs


# 1.221 18-Sep-2006 mrg

- sparc64_ipi_halt(): we shouldn't return from sparc64_ipi_halt_thiscpu()
so replace a branch with a 'sir'
- in #if 0 code, in sparc64_ipi_flush_pte() and sparc64_ipi_flush_ctx()
save/restore the out registers that the sp_tlb_flush_xxx() versions
around calling them
- in sp_tlb_flush_pte() and sp_tlb_flush_ctx(), replace global register
usage with out registers so that we don't clobber the (alternate)
global registers when these are called from IPI context


# 1.220 18-Sep-2006 mrg

- remove an extra 'sir' that followed one in a macro
- add some named labels to some spill/fill handlers
- remove 2 unused strings


Revision tags: yamt-splraiseipl-base
# 1.219 18-Sep-2006 martin

branches: 1.219.2;
Lazy FPU handling for the MULTIPROCESSOR case


# 1.218 16-Sep-2006 nakayama

From OpenBSD:
- reload %fprs for checking it again.
- use symbolic names for checking in %fprs.

revision 1.51
date: 2005/07/18 14:50:11; author: deraadt; state: Exp; lines: +2 -1
cache a copy of the fprs so we know what fp restore we should do after

revision 1.50
date: 2005/07/14 01:46:13; author: deraadt; state: Exp; lines: +4 -4
use symbolic names for checking in %fprs, as above


# 1.217 16-Sep-2006 nakayama

Fix a couple of %y register save/restore errors, inspired from OpenBSD.

revision 1.44
date: 2004/04/23 04:18:17; author: marc; state: Exp; lines: +5 -4

fix a couple of %y register save/restore errors
1) don't save %y in a register that is later used before restoring %y
2) always restore %y after calling a signal handler
tested by drahn@, OK pval


# 1.216 15-Sep-2006 martin

Do not bother to save fpu state when we are about to get rid of it.


Revision tags: yamt-pdpolicy-base9
# 1.215 13-Sep-2006 mrg

SMP cleanup. provide support for multiple CPUs in DDB. (SMP itself
is still not working.)

cpu.h:
- add a pointer for DDB regs in SMP environment to struct cpu_info
- remove the #defines for mp_pause_cpus() and mp_resume_cpus()
cpuset.h:
- remove CPUSET_ALL() and rename CPUSET_ALL_BUT() to CPUSET_EXCEPT()
from petrov.
db_machdep.h:
- rename the members of db_regs_t to be the same as sparc
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- redo DDB_REGS to no longer be a pointer to a fixed data structure
but to one allocated per-cpu when ddb is entered
- move a bunch of prototypes in here
intr.h:
- remove SPARC64_IPI_* macros, no longer used
db_interface.c:
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- make "nil" a 64 bit entity
- change the ddb register access methods to work in multiprocessor
environment, it is now very much like sparc does it
- in kdb_trap() avoid accessing ddb_regp when it is NULL
- update several messages to include the cpu number
- unpause other cpus much later when resuming from ddb
- rename db_lock() to db_lock_cmd(), as the sparc-like code has
db_lock as a simple lock
- remove "mach cpus" command, and replace it with "mach cpu" (which
does the same) and also implement "mach cpu N" to switch to
another cpus saved trapframe
db_trace.c:
- update for the ddb_regs -> ddb_regp change
genassym.cf:
- add TF_KSTACK as offsetof(struct trapframe64, tf_kstack)
ipifuncs.c:
- overhaul extensively
- remove all normal interrupt handlers as IPI's, we now handle
them all specially in locore.s:interrupt_vector
- add a simplelock around all ipi functions - it's not safe for
multiple cpus to be sending IPI's to each other right now
- rename sparc64_ipi_pause() to sparc64_ipi_pause_thiscpu() and,
if DDB is configured, enable it to save the passed-in trapframe
to a db_regs_t for this cpu's saved DDB registers.
- remove the "ipimask" system (SPARC64_IPI_* macros) and instead
pass functions directly
- in sparc64_send_ipi() always set the interrupt arguments to 0,
the address and argument of the to be called function. (the
argument right now is the address of ipi_tlb_args variable, and
part of the reason why only one CPU can send IPI's at a time.)
don't wait forever for an IPI to complete. some of this is
from petrov.
- rename sparc64_ipi_{halt,pause,resume}_cpus() to
mp_{halt,pause,resume}_cpus()
- new function mp_cpu_is_paused() used to avoid access missing
saved DDB registers
- actually broadcast the flush in smp_tlb_flush_pte(),
smp_tlb_flush_ctx() and smp_tlb_flush_all(). the other end may
not do anything yet in the pte/ctx cases yet...
kgdb_machdep.c:
- rework for changed member names in db_regs_t.
locore.s:
- shave an instruction from syscall_setup() (set + ld -> sethi + ld)
- remove some old dead debug code
- add new sparc64_ipi_halt IPI entry point, it just calls the C
vector to shutdown.
- add new sparc64_ipi_pause IPI entry point, which just traps into
the debugger using the normal breakpoint trap. these cpus usually
lose the race in db_interface.c:db_suspend_others() and end up
calling the C vector sparc64_ipi_pause_thiscpu().
- add #if 0'ed code to sparc64_ipi_flush_{pte,ctx}() IPI entry
points to call the sp_ version of these functions.
- in rft_kernel (return from trap, kernel), check to see if the
%tpc is at the sparc64_ipi_pause_trap_point and if so, call
"done" not "retry"
- rework cpu_switch slightly: save the passed-in lwp instead of
using the one in curlwp
- in cpu_loadproc(), save the new lwp not the old lwp, to curlwp
- in cpu_initialize(), set %tl to zero as well. from petrov.
- in cpu_exit(), fix a load register confusion. from petrov.
- change some "set" in delay branch to "mov".
machdep.c:
- deal with function renames
pmap.c:
- remove a spurious space
trap.c:
- remove unused "trapstats" variable
- add cpu number to a couple of messages


# 1.214 09-Sep-2006 mrg

significant clean up effort, largely from petrov@ via martin@.

- fix a bunch of comments for proc->lwp
- remove old TRAPTRACE, NOT_DEBUG, etc. code that has bit-rotted
- put some older DEBUG code under NOT_DEBUG
- add a bunch of new debugging/tracing code ("KTR") that depends on
other changes not yet present.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base yamt-pdpolicy-base5 chap-midi-base simonb-timecounters-base rpaulo-netinet-merge-pcb-base
# 1.213 14-May-2006 elad

branches: 1.213.6; 1.213.8;
integrate kauth.


# 1.212 12-May-2006 skrll

Fix some comments.


Revision tags: elad-kernelauth-base
# 1.211 09-May-2006 rjs

Load CPCB in cpu_mp_startup.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.210 11-Feb-2006 cdi

branches: 1.210.2; 1.210.4; 1.210.6;
ANSIfication: u_intN_t -> uintN_t, use ANSI function declarations/definitions
instead of K&R ones.


# 1.209 27-Jan-2006 cdi

branches: 1.209.2; 1.209.4;
Alter sparc64 bootstrap, catch up to ofwboot v1.9:

- Accept bootinfo structure passed down from ofwboot v1.9
- Drop kernel re-mapping code
- Use permanent 4MB mappings provided by the loader instead
- Change kernel entry address to point directly at the code instead of pointing
at the trap table's first slot. This allows the bootloader to detect
those kernels which are aware of the new boot scheme
- Due to the changes in kernel mapping code, alter secondary CPU bootstrap
code to use trampoline just like FreeBSD does (some FreeBSD code is used
here as well)


# 1.208 12-Jan-2006 cdi

Fix a typo: %g0 should be used instead of %o0 when initializing FPU in dostart:
and cpu_mp_startup:, %o0 is not even initialized at this point.


# 1.207 11-Dec-2005 christos

branches: 1.207.2;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 1.206 10-Jul-2005 christos

Re-factor syscall, and make it use syscall_{plain,fancy}.


# 1.205 31-May-2005 chs

branches: 1.205.2;
remove vestigal {,e}intr{names,cnt} symbols now that vmstat doesn't need them.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.204 12-Feb-2005 chs

branches: 1.204.4; 1.204.6; 1.204.8;
in sparc_interrupt(), wait to enable interrupts until just before calling
the handler and disable them again right after the handler returns.
we don't want another hardware interrupt coming in while we're mucking
with the list pointers. also, clear the intrhand's ih_pending pointer
before calling the handler rather than after, so that if another interrupt
comes in while the handler is running, we can put the intrhand back on
the list so it will be called again.

in send_softint(), disable interrupts via %pstate instead of %pil, so that
hardware interrupts at higher levels are blocked while we manipulate the
intrpending list. also, if the intrhand already has ih_pending set,
don't bother poking the SET_SOFTINT register again, since being on the list
implies that there is already a softint pending in the hardware.

these appear to fix PR 21750 (the "sleep forever" problem).

while I'm here, remove more vestiges of the !INTRLIST softint stuff
(code and comments). and in sparc64_ipi_flush_all(), interrupts are
already disabled so we don't need to fiddle with %pstate.


Revision tags: yamt-km-base2
# 1.203 30-Jan-2005 martin

Remove the no long usefull variants selected by undefining INTRLIST and
INTR_INTERLOCK to improve readability. Same object code generated as before.


Revision tags: yamt-km-base
# 1.202 16-Jan-2005 chs

branches: 1.202.2;
use ENTRY_NOPROFILE() for various entry points,
stack traces work better that way.


Revision tags: kent-audio1-beforemerge kent-audio1-base
# 1.201 03-Dec-2004 chs

branches: 1.201.4;
remove cache_flush_virt() and PADDRT, they're no longer used.
allocate a stack frame for blast_dcache() when profiling so it shows up.
in dcache_flush_page(), use a stride of 32 instead of 16 to match the
cache line size. correct various comments.


# 1.200 08-Nov-2004 petrov

Don't compile sparc64_ipi functions when UP.


# 1.199 25-Oct-2004 martin

No need to clear %o1 when returning a 64 bit integer from pseg_get if we
are compiling for a 64 bit kernel.


# 1.198 24-Jul-2004 nakayama

Change interrupt pending list end value to -1, to avoid linking an
interrupt handler twice.

It may fix "sleep forever" bug.


# 1.197 09-Apr-2004 petrov

Clean-up unused defines and variables.


Revision tags: netbsd-2-0-base
# 1.196 26-Mar-2004 petrov

branches: 1.196.2;
Use want_resched from cpu_info area.


# 1.195 23-Mar-2004 martin

Replace intrcnts by evcnts. XXX - needs slight tweaking for MULTIPROCESSOR.


# 1.194 14-Mar-2004 chs

checkpoint of MP work from dennis and myself. includes cross-processor
interrupt framework, a sledgehammer TLB invalidation and misc MP fixes.
doesn't work at all yet.


# 1.193 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.192 19-Jan-2004 martin

Rename switchexit to cpu_exit and g/c the old C implementation of cpu_exit.


# 1.191 18-Jan-2004 martin

Support RAS for 32bit kernels too.


# 1.190 16-Jan-2004 martin

In proc_trampoline don't bother to clear condition codes in the trap
frame, since we no longer rely on this.
While there fix a few comments.


# 1.189 08-Jan-2004 martin

Minor cleanup


# 1.188 06-Jan-2004 martin

Implement restartable atomic sequences (RAS) for sparc64.


# 1.187 06-Jan-2004 petrov

Spinup secondary cpus. Based on codes sent to me by Dennis Chernoivanov
and Chuck Silvers.


# 1.186 04-Jan-2004 jdolecek

update to recent changes - exit2() doesn't exist anymore and the
exit path always calls lwp_exit2()
pointed out Martin Husemann


# 1.185 02-Dec-2003 martin

Minor cleanup: remove unused code, sync a comment with current reality.


# 1.184 25-Nov-2003 cdi

Use per-cpu pcb, curlwp and fplwp rather than global ones. This brings
GENERIC.MP configuration to a usable state.

Approved by petrov@.


# 1.183 24-Nov-2003 cdi

Call 'proc_trampoline_mp' from 'proc_trampoline' in a multiprocessor
configuration. Fix process locking. Approved by petrov@.


# 1.182 20-Nov-2003 petrov

Remove nwindows calculation, it's not used. Set l_cpu in cpu_switch.


# 1.181 09-Nov-2003 martin

Get rid of bcopy/bzero.


# 1.180 26-Oct-2003 christos

Initial siginfo support for sparc64 (untested). COMPAT_16 sigcontext signal
delivery tested.


# 1.179 24-Aug-2003 chs

add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default. the changes
fall into two basic catagories:

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

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

originally from openbsd, adapted for netbsd by me.


# 1.178 08-Jul-2003 cdi

traceit: don't use %g7 as it is to become curcpu() register. Add comments.


# 1.177 18-May-2003 martin

branches: 1.177.2;
Make kernels with options KGDB at least compile.
Still needs some work to make it working.


# 1.176 29-Apr-2003 nakayama

Use BLOCK_ALIGN rather than BLOCK_SIZE for aligning a pointer.


# 1.175 27-Apr-2003 ragge

Preserve the symbol table in the LKM || KSYMS cases also.


# 1.174 04-Apr-2003 petrov

use branch slot in pmap_copy_page.


# 1.173 24-Mar-2003 nakayama

Divide `set' instruction in delay slot (from OpenBSD change to rev 1.30).


# 1.172 10-Feb-2003 martin

Remove some #if 0 code and a few XXX marked membars w/o proper
justification for their existence.


# 1.171 09-Feb-2003 martin

Remove left over pieces from reusing the signal trampoline for upcalls.
This should fix signal delivery for 32bit kernels.


# 1.170 05-Feb-2003 nakayama

Switch to use cycle counter (%tick) based microtime().

This is derived from alpha/microtime.c and i386/tsc_microtime.c,
and will share with both ports.

This should fix PR port-sparc64/18452.
(approved by martin)


# 1.169 04-Feb-2003 martin

Fix return value of pseg_set, which I accidently broke in rev. 1.164.

Fix register names in comment and shave off another register (hint
from uwe).


# 1.168 01-Feb-2003 martin

Rearrange register usage in pseg_set a bit and shave off %g4.


# 1.167 01-Feb-2003 martin

Remove a few #ifdef _LP64 by using STPTR/LDPTR macros.
Thanks to Matthew Green for the pointer.


# 1.166 31-Jan-2003 martin

Apply leaf procedure optimization to pseg_set (again).


# 1.165 31-Jan-2003 martin

Make the pmap count resident/wired mappings on the fly instead of
walking the page tables whenever this information is needed.

Add an option PMAP_COUNT_DEBUG to assert the new counts and the
page table walk agree.

The old solution had very bad performance impact, for example
by the high CPU load when running top(1).

Thanks to Simon Burge for pointing at the cause of the problem and
to Valeriy E. Ushakov for optimizing my simple minded assembler code.


# 1.164 27-Jan-2003 martin

Remove unused function pseg_find (which looked quite similar to
pseg_get anyway).


# 1.163 18-Jan-2003 thorpej

Merge the nathanw_sa branch.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.162 16-Jan-2003 petrov

Move dump_dtlb back under DDB.


# 1.161 15-Jan-2003 chs

fix two bugs in my last pmap rework:
- in tlb_flush_all(), don't skip TLB entries with the high bit on,
I was confused about which MMU register it was using. it's also fine
to use the last hardware context.
- in pmap_create(), don't allocate a hardware context for the new pmap.
it's unnecessary, and when this would cause us to recycle all the contexts,
it would result in the current process's context being set to 0
(ie. the kernel's context). the current process could then return to
userspace without going through the context-switch code (and thus without
having a hardware context reallocated). this would lead to user mappings
being entered in the kernel's context later, causing all sorts of trouble.
add some assertions to catch this kind of thing.


Revision tags: fvdl_fs64_base
# 1.160 25-Dec-2002 petrov

new function dump_itlb.


Revision tags: gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.159 22-Sep-2002 chs

many improvements:
- use struct vm_page_md for attaching pv entries to struct vm_page
- change pseg_set()'s return value to indicate whether the spare page
was used as an L2 or L3 PTP.
- use a pool for pv entries instead of malloc().
- put PTPs on a list attached to the pmap so we can free them
more efficiently (by just walking the list) in pmap_destroy().
- use the new pmap_remove_all() interface to avoid flushing the cache and TLB
for each pmap_remove() that's done as we are tearing down an address space.
- in pmap_enter(), handle replacing an existing mapping more efficiently
than just calling pmap_remove() on it. also, skip flushing the
TSB and TLB if there was no previous mapping, since there can't be
anything we need to flush. also, preload the TSB if we're pre-setting
the mod/ref bits.
- allocate hardware contexts like the MIPS pmap:
allocate them all sequentially without reuse, then once we run out
just invalidate all user TLB entries and flush the entire L1 dcache.
- fix pmap_extract() for the case where the va is not page-aligned and
nothing is mapped there.
- fix calculation of TSB size. it was comparing physmem (which is
in units of pages) to constants that only make sense if they are
in units of bytes.
- avoid sleeping in pmap_enter(), instead let the caller do it.
- use pmap_kenter_pa() instead of pmap_enter() where appropriate.
- remove code to handle impossible cases in various functions.
- tweak asm code to pipeline a little better.
- remove many unnecessary spls and membars.
- lots of code cleanup.
- no doubt other stuff that I've forgotten.

the result of all this is that a fork+exit microbenchmark is 34% faster
and a fork+exec+exit microbenchmark is 28% faster.


Revision tags: gehenna-devsw-base
# 1.158 18-Jul-2002 wiz

Spell 'should' correctly.


# 1.157 07-Jun-2002 eeh

Shave 10% off the time needed to flush the D$ through a bit of instruction
reordering.


# 1.156 05-Jun-2002 eeh

Handle improperly aligned stack pointers more cleanly.


# 1.155 04-Jun-2002 eeh

Fix the fork trampoline to properly use the supplied tstate.


# 1.154 31-May-2002 thorpej

Make this work with an ISO C preprocessor.


Revision tags: netbsd-1-6-base
# 1.153 14-May-2002 eeh

branches: 1.153.2; 1.153.4;
Only save locals and ins in trapframes for DEBUG kernels.


# 1.152 04-May-2002 kleink

Add some comments to the CPP conditionals controlling the trap macro
definitions, to ease navigation somewhat.


# 1.151 16-Apr-2002 eeh

Make lots of routines profile-friendly and get rid of some cruft.


Revision tags: eeh-devprop-base
# 1.150 21-Mar-2002 petrov

Not needed debug stuff deleted.


# 1.149 16-Mar-2002 mrg

tell newer binutils that our use of %g2 and %g3 is OK here.


# 1.148 15-Mar-2002 eeh

Cleanup MMU initialization to prevent hangs.


Revision tags: newlock-base ifpoll-base
# 1.147 09-Feb-2002 eeh

branches: 1.147.4;
Fix microsecond calculation in microtime.


# 1.146 07-Feb-2002 eeh

Fix register allocation in microtime().


# 1.145 29-Jan-2002 eeh

Shift the UPAID in the correct direction.


# 1.144 17-Jan-2002 eeh

Be more tolerant of unaligned stack pointers.


# 1.143 17-Jan-2002 eeh

Enable block insns in bcopy and bzero.


# 1.142 16-Jan-2002 eeh

In bcopy use 32-bit comparisons in 32-bit kernels.


# 1.141 16-Jan-2002 eeh

Use correct calculation for the trapframe in softtrap for ILP32.


# 1.140 20-Nov-2001 lukem

- pull in opt_kgdb.h where necessary
- replace opt_kgdb_machdep.h with opt_kgdb.h
- defparam opt_kgdb.h:
KGDB_DEV KGDB_DEVNAME KGDB_DEVADDR KGDB_DEVRATE KGDB_DEVMODE
- move from opt_ddbparam.h to opt_ddb.h:
DDB_FROMCONSOLE DDB_ONPANIC DDB_HISTORY_SIZE DDB_BREAK_CHAR SYMTAB_SPACE
- replace KGDBDEV with KGDB_DEV
- replace KGDBADDR with KGDB_DEVADDR
- replace KGDBMODE with KGDB_DEVMODE
- replace KGDBRATE with KGDB_DEVRATE
- use `9600' instead of `0x2580' for 9600 baud rate
- use correct quotes for options KGDB_DEVNAME="\"com\""
- use correct quotes for options KGDB_DEV="17*256+0"
- remove unnecessary dependancy on Makefile for kgdb_stub.o
- minor whitespace cleanup


Revision tags: thorpej-mips-cache-base thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf
# 1.139 14-Sep-2001 thorpej

branches: 1.139.4;
Don't declare intrhand[] here -- that's taken care of in intr.c.


Revision tags: thorpej-devvp-base
# 1.138 30-Aug-2001 eeh

branches: 1.138.2;
Preliminary UltraSPARC III suport (not enabled yet).


# 1.137 13-Aug-2001 jdolecek

g/c _remque()/_insque(); use the C version in libkern


# 1.136 09-Aug-2001 eeh

Fix context masking lossage caused by last version.


# 1.135 08-Aug-2001 eeh

Clean up the trap code to handle the changes cause by supporting non-faulting
accesses. Also change the parameter order so trap frames are easy to find.


# 1.134 07-Aug-2001 eeh

Make sure C code always has ASI_PRIMARY_NOFAULT in the %asi register so
the compiler will be happy if it ever starts generating speculative loads.


# 1.133 05-Aug-2001 eeh

Add support for non-faulting loads and optimize MMU miss handling paths.


# 1.132 02-Aug-2001 eeh

Fix bcopy.


# 1.131 02-Aug-2001 eeh

Sync bzero w/libc version.


# 1.130 01-Aug-2001 eeh

Integrate fixes from userland memset.


# 1.129 31-Jul-2001 eeh

Code cleanup and optimization.


# 1.128 23-Jul-2001 eeh

Get rid of some debug code that really isn't all that useful any more.


# 1.127 19-Jul-2001 eeh

Do ignore unregistered interrupts instead of faulting.


# 1.126 16-Jul-2001 eeh

Make bcopy a 32-bit friendly.


# 1.125 11-Jul-2001 eeh

Fix problems booting 32-bit kernels and dispatching level-15 interrupts.


# 1.124 08-Jul-2001 eeh

branches: 1.124.2;
Code cleanup. Add block_disable to let you turn on block set/copy routines.


# 1.123 05-Jul-2001 eeh

New block bzero and bcopy.


# 1.122 04-Jul-2001 eeh

Replace old bcopy with a much faster version.


# 1.121 01-Jul-2001 martin

Disable axidently enabled debug code to make -current compile again.


# 1.120 30-Jun-2001 eeh

Use a newer version (still disabled) of block bcopy.


# 1.119 30-Jun-2001 eeh

Fixup fpu save restore, get rid of some unused copy functions, and add
a new bcopy.


# 1.118 21-Jun-2001 eeh

Allow multiple 4MB pages for both kernel text and kernel data.

Note: DEBUG checks will not allow accesses to the hole between
text and data segments, so you may need to update programs that
use libkvm before relocating the start of kernel data.


# 1.117 06-Jun-2001 mrg

extract the netbsd32, sunos, 32 bit svr4 and 64 bit svr4 sigcode out into
separate files, so that compat lkms can link with them as well.


# 1.116 30-May-2001 lukem

add missing #include "opt_kgdb.h"


Revision tags: thorpej_scsipi_beforemerge
# 1.115 25-Apr-2001 simonb

Spell occurred correctly.


Revision tags: thorpej_scsipi_nbase thorpej_scsipi_base
# 1.114 09-Apr-2001 eeh

Interrupt latency fix from sparc port. (Hm. One insn instead of 5).


# 1.113 07-Mar-2001 eeh

Fix inverted preprocessor logic. (Spotted by Charles.)


# 1.112 21-Feb-2001 eeh

branches: 1.112.2;
Add support for 64-bit SVR4 (Solaris 8) binaries.


# 1.111 10-Feb-2001 pk

Fix conditional for svr4 compat inclusion.


# 1.110 05-Feb-2001 eeh

Add signal trampoline for 64-bit svr4 emulations.


# 1.109 31-Dec-2000 eeh

Make INCR() atomic.


# 1.108 29-Dec-2000 eeh

pseg_get tells us whether it really needed that spare page after all.


# 1.107 07-Dec-2000 eeh

Fixup calculating where fpstate should be saved in the signal trampoline
code so it doesn't overwrite something important like the registers.


# 1.106 09-Nov-2000 eeh

Fix ILP32 bug in probe_get().


# 1.105 22-Oct-2000 pk

Restore revision 1.102.

I hope it sticks this time..


# 1.104 20-Oct-2000 eeh

Fix hang in 32-bit kernels caused by relocation of KERNBASE.


# 1.103 04-Oct-2000 eeh

Fix interrupt lossage problem and some cosmetic changes.


# 1.102 01-Oct-2000 pk

cpu_initialize: global registers aren't preserved across calls to
prom_printf(), so replace %g3 with %l7 (which isn't used despite
the `usage' comment).

Also, clean up white-space turds.


# 1.101 29-Sep-2000 eeh

This seems to fix the interrupt lossage of non-debug kernels.


# 1.100 28-Sep-2000 eeh

Fix INTR_SETUP() to properly distinguish kernel and user addresses.

Make microtime() return the correct time on %tick machines.

Re-enable debug stuff in dostart for now to detect kernel mapping issues.


# 1.99 25-Sep-2000 pk

Missing `#if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)'


# 1.98 17-Sep-2000 eeh

Make the improved %tick changes work with machines that use the counter-timer
for the clock.


# 1.97 12-Sep-2000 eeh

Fix new version of microtime.


# 1.96 11-Sep-2000 eeh

(Hopefully) fix clock skew on machines that us %tick for the clock (UIIi).


# 1.95 31-Aug-2000 eeh

Use casx instead of stx to change entries in the page table trees.


# 1.94 23-Aug-2000 eeh

Update the scheduler to the new locking scheme.


# 1.93 10-Aug-2000 eeh

Fix signal delivery.


# 1.92 02-Aug-2000 eeh

Get kernel profiling to work. Now if only gprof worked....


# 1.91 01-Aug-2000 eeh

Overhaul cache flush code and coredump code.


# 1.90 25-Jul-2000 pk

Re-instate a couple of delay slot NOPs marked `XXX spitfire bug?'


# 1.89 24-Jul-2000 mycroft

Optimization to pmap_zero_page(): we only need to use the first 16 FP regs,
as in bzero().


# 1.88 24-Jul-2000 mycroft

Fix a whitespace glitch.


# 1.87 24-Jul-2000 mycroft

Pull in the bzero() changes from libc for real, with a couple of kernel-
specific hacks:
* Make the bias handling depend on STKB, so it switches correctly for 32-bit
kernels.
* Use the 32-bit stw/ld for 32-bit kernels.
* Add a few `-STKB's that were missed in the previous change.


# 1.86 24-Jul-2000 pk

Cosmetic & readability:
- local label cleanup in interrupt handling code;
- in debugging sections when testing `intrdebug': use a unique
local label (97) to enhanced clarity;
- comment-out unused code;
- kill a bug as the satisfying result of doing all of the above.


# 1.85 24-Jul-2000 eeh

Fix stack issues in bzero.


# 1.84 24-Jul-2000 mycroft

Revert the previous change for now. I don't have time to debug it tonight.


# 1.83 23-Jul-2000 mycroft

Copy bzero change from libc.


# 1.82 20-Jul-2000 pk

Since `intrcnt' points to an array of long ints, reserve the appropriate
amount of space depending on _LP64. Provide macros to load/store signed
and unsigned long ints.

Also, make the `intrcnt' and `intrpending' arrays 16 entries long, as on
sparc/v9 interrupt #15 is just a regular interrupt.


# 1.81 19-Jul-2000 eeh

Fix merge problem.


# 1.80 19-Jul-2000 eeh

Disable interrupt interlock using ih->ih_pending field. Seems to cause
more problems than it solves.


# 1.79 19-Jul-2000 eeh

Miscellaneous cleanup.


# 1.78 18-Jul-2000 pk

Correct args usage comment in probeget.
Whitespace cleanup.


# 1.77 18-Jul-2000 pk

probeget: 9 -> 0x9


# 1.76 18-Jul-2000 pk

If `ih_pending' is set simply return from the trap, don't schedule another
soft interrupt.


Revision tags: mrg-merge-1-5-top
# 1.75 18-Jul-2000 pk

openfirmware: don't lower %pil


# 1.74 17-Jul-2000 pk

Kill typos in interrupt code.


# 1.73 17-Jul-2000 pk

probeget: do the same song and dance as ld*a() macros in ctlreg.h do.


# 1.72 14-Jul-2000 eeh

Move some macro definitions out of genassym and into locore.s


# 1.71 08-Jul-2000 mrg

backout part of previous: turn off intrdebug, and another debug message


# 1.70 07-Jul-2000 pk

Changes for readability:
- #define LP64 dependent STACKFRAME macro once
- use a LOAD_ASCIZ macro for setting up the format string
for debug messages.


# 1.69 07-Jul-2000 eeh

Temporary fix to prevent the clock from stopping on UIIi machines.


# 1.68 03-Jul-2000 eeh

Prevent interrupts from being posted if they are active and deprecate polled
interrupts. This seems to eliminate the spurious interrupts.


# 1.67 02-Jul-2000 eeh

Clean up interrupt handling some more.


# 1.66 30-Jun-2000 eeh

Fix interrupt delivery on UltraSPARC IIi machines.


# 1.65 24-Jun-2000 eeh

With these changes the kernel seems almost stable again.


# 1.64 24-Jun-2000 eeh

More VM cleanup:

Move the cpu_info structure above the interrupt stack so it won't
get corrupted if the stack overflows.

Flush the D$ before and after all MMU bypass accesses since the
D$ latches all of those.


# 1.63 23-Jun-2000 eeh

Make probeget() and probeset() really work for a change.


Revision tags: netbsd-1-5-base
# 1.62 19-Jun-2000 eeh

branches: 1.62.2;
Have separate data and text segments, make text read-only.


# 1.61 12-Jun-2000 eeh

Start reorganizing the kernel for MULTIPROCESSOR support.


# 1.60 31-May-2000 thorpej

Add a comment about needing to initialize p_cpu when multiple
processors are supported.


Revision tags: minoura-xpg4dl-base
# 1.59 26-May-2000 thorpej

branches: 1.59.2;
First sweep at scheduler state cleanup. Collect MI scheduler
state into global and per-CPU scheduler state:

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

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

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

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

Tested on i386 and Alpha. Changes are mostly mechanical, but apologies
in advance if it doesn't compile on a particular platform.


# 1.58 26-May-2000 thorpej

Don't set `runtime' here; it's done at the end of mi_switch().
cvS: ----------------------------------------------------------------------


# 1.57 26-May-2000 thorpej

Introduce a new process state distinct from SRUN called SONPROC
which indicates that the process is actually running on a
processor. Test against SONPROC as appropriate rather than
combinations of SRUN and curproc. Update all context switch code
to properly set SONPROC when the process becomes the current
process on the CPU.


# 1.56 22-Apr-2000 eeh

If we trap due to a bad kernel stack, try to switch to the interrupt strack
before breaking into the debugger.


# 1.55 18-Apr-2000 eeh

Prevent the system from getting watchdog reset by returning directly to user
mode if restoring the user window traps. Also reduce the time we run with
%tl>0.


# 1.54 13-Apr-2000 eeh

Apparently gas 2.9.5 (don't ask) does not like to add values to %lo()
directives so move the additions inside %lo() to make it happy.
Hopefully this won't break older versions.


# 1.53 10-Apr-2000 mrg

- fix a speeling error
- rename some numbered labels to be a bit less confusing.
- remove dead code
- fix a debug error message (argh!)


# 1.52 10-Apr-2000 pk

Get a kernel without DDB to build.


# 1.51 16-Mar-2000 eeh

Revamp interrupts again:

Fix a bug causing interrmittent panics in interrupt dispatch.
Use interrupt vectors for softints.
Add a new send_softint interface.
Improved D$ flushing.
Improve traptrace and other debugging enhancements.


Revision tags: chs-ubc2-newbase
# 1.50 16-Jan-2000 eeh

Interrupt handlers return zero if they didn't handle the interrupt.


# 1.49 10-Jan-2000 eeh

Add debugger single-stepping and fix interrupt dispatch bugs.


# 1.48 30-Dec-1999 eeh

Lots of changes:

remove ffs()
add bzero that uses block store insns
save %gsr to fpstate
revert to physical accesses for pmap_zero_page so we don't
have conflicting page mappings
general cleanup.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base fvdl-softdep-base
# 1.47 06-Nov-1999 eeh

Handle zero length properly in copyinstr() copyoutstr() and copystr().


Revision tags: comdex-fall-1999-base
# 1.46 11-Oct-1999 eeh

branches: 1.46.2; 1.46.4;
Update to post 1.4.


# 1.45 05-Oct-1999 eeh

branches: 1.45.2;
Make broken versions of gas happy by using sethi/or instead of set for
(negative) addresses.


# 1.44 17-Sep-1999 thorpej

Centralize the declaration and clearing of `cold'.


Revision tags: chs-ubc2-base
# 1.43 18-Jul-1999 eeh

More fun with pmap.


# 1.42 21-Jun-1999 eeh

Improve TRAPTRACE. Add FLTRACE that only tracks MMU faults.


# 1.41 05-Jun-1999 eeh

Make pbrobeget() and probeset() work for 64-bit values as well. To do this
the arguments are changed so the address is first and the ASI second so we
can have the address in %o0:%o1 and not worry about unused registers.

Also a bit of copyright cleanup.


# 1.40 05-Jun-1999 mrg

update a commit slightly.


# 1.39 30-May-1999 eeh

Add code to support using %tick as the system clock if no "counter-timer" node
is found.


# 1.38 09-May-1999 eeh

Fixup non-DEBUG kernels.


# 1.37 29-Apr-1999 christos

Add sunos_sigcode (32 bit only)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.36 26-Mar-1999 eeh

branches: 1.36.4;
COMPAT_SPARC32 -> COMPAT_NETBSD32


# 1.35 25-Mar-1999 mrg

clean and up make compile


# 1.34 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.33 22-Mar-1999 eeh

Need to set up the pointers properly for partial FPU register stores.


# 1.32 22-Mar-1999 eeh

Flush D$ on bypass accesses.


# 1.31 28-Feb-1999 eeh

Use block load/store in pmap_zero_page()/pmap_copy_page().


# 1.30 17-Feb-1999 eeh

Let's test out vectored interrupts.


# 1.29 15-Feb-1999 hubertf

RCS ID police


# 1.28 11-Feb-1999 mrg

fix a comment pasto.


# 1.27 11-Jan-1999 eeh

Finally fixed 64-bit signal trampoline.


# 1.26 10-Jan-1999 eeh

Handle the symbol table properly in a 32-bit kernel that was booted from a
64-bit bootloader.


# 1.25 09-Jan-1999 eeh

More signal fixup.


Revision tags: kenh-if-detach-base
# 1.24 26-Nov-1998 mycroft

Sync kcopy() with 32-bit SPARC version.


# 1.23 16-Nov-1998 eeh

Fixup the last broken bits of the signal handling code.


Revision tags: chs-ubc-base
# 1.22 08-Oct-1998 eeh

Fix more syscall32 and signal breakage.


# 1.21 22-Sep-1998 eeh

More fixup in the signal area.

64-bit syscall cleanup.

Add emulation for some new FPU insns: conversion to 64-bit long int and
conditional moves.


# 1.20 17-Sep-1998 thorpej

SYS_sigreturn -> SYS___sigreturn14.


# 1.19 13-Sep-1998 eeh

Fixup signal changes (hopefully). However SUN_COMPAT is likely broken by
this and I don't know how to fix it.

We can now exec a 64-bit init through a really ugly hack (don't ask.)


# 1.18 11-Sep-1998 eeh

Add labels for the compat_sparc32 signal trampoline and break -- er -- fix
suword and fuword.


# 1.17 09-Sep-1998 eeh

Don't use %tick for microtime on 32-bit kernels -- breaks gettimeofday.


# 1.16 09-Sep-1998 thorpej

Adjust for the new "reaper" kernel thread: do not free the vmspace and
u-area in machine-dependent code. Instead, call exit2() to schedule
the reaper to free them for us, once it is safe to do so (i.e. we are
no longer running on the dead proc's vmspace and stack).


# 1.15 07-Sep-1998 eeh

Fix data corruption problem caused by broken debug code.


# 1.14 07-Sep-1998 eeh

Add new 64-bit trap vectors.


# 1.13 06-Sep-1998 eeh

32-bit fixup.


# 1.12 06-Sep-1998 eeh

Disable some debug stuff.


# 1.11 05-Sep-1998 eeh

It slices. It dices. It does everything except exec a sparc32_compat init.


# 1.10 02-Sep-1998 eeh

Periodic update: now starts probing devices.


# 1.9 30-Aug-1998 eeh

Some more 64-bit cleanup. Now everything compiles.


# 1.8 29-Aug-1998 eeh

Some more 64-bit-ification.


# 1.7 27-Aug-1998 eeh

Add 64-bit pmap support:

Moved from a two level 512/1024 entry setup mapping 32 (9/10/13) bits
respectively to a three level 1024/1024/1024 entry setup mapping 43
(10/10/10/13) bits. In 32-bit mode we waste about 1/12 pages mapping the high
11 bits. We also only manage 43 of the possible 44 bits of virtual address
space, wasting half of it. Oh well, maybe we'll do better next revision.


Revision tags: PMAP32
# 1.6 26-Aug-1998 mrg

panicstack: is needed outside of DEBUG. use _C_LABEL, and printf not db_printf (incase no ddb!)


# 1.5 13-Aug-1998 eeh

Merge paddr_t changes into the main branch.


Revision tags: eeh-paddr_t-base
# 1.4 07-Jul-1998 eeh

branches: 1.4.2;
General update:

Added genassym.cf
Removed lderr which should never have gotten in
Removed lots of dead code from locore.s
Added some softint stuff to intr.c
Added support for halt -p
esp and le both use bus_dmamap_*() functions now
instead of kdvma_mapin()
groundwork for PCI (but we still have no drivers for
any sun4u PCI devices)


# 1.3 04-Jul-1998 jonathan

defopt DDB.


# 1.2 26-Jun-1998 thorpej

defopt COMPAT_SVR4


# 1.1 20-Jun-1998 eeh

branches: 1.1.1;
Initial revision


# 1.431 05-Jul-2022 andvar

fix various typos in comments.


# 1.430 27-Jun-2022 andvar

fix various typos in comments.


# 1.429 22-May-2022 andvar

fix various small typos, mainly in comments.


# 1.428 16-May-2022 mrg

try to handle ultrasparc III* "fast ecc error" traps.

i had a sunblade 2500 reset with this trap recently, and the
manual says it should have been recoverable. in particular,
the US IIIv2 manual says in section 12.4.4.2 that the i-cache
won't see this data ever (so nothing needed there), and that
the d-cache needs to be disabled, and all the entries flushed,
and then re-enabled.

tested with a "trap 0x70" from kernel space, that trap.c
converted the "0x170" back to "0x70" (with an ADVANCE). this
code not commited.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 1.427 03-Apr-2021 palle

Improve cpu_idle() by allowing a platform specific implementaion (same logic as the sparc implementation) - currently only used by sun4v


# 1.426 30-Mar-2021 palle

sun4v: handle spill trap properly when trap level is 1 and otherwin is non-zero - ensure that all windows are spilled to the pcb like the sun4u winfixsave code path


# 1.425 22-Feb-2021 palle

branches: 1.425.2;
sun4v: handle spill normal user traps properly when current trap level is 1 - registers are spilled to the PA of the stack to avoid further mmu-related traps, since sun4v only has 2 trap levels


# 1.424 20-Dec-2020 palle

sun4v: add comment in sun4v_tl1_ptbl_miss code path - no functional change


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1
# 1.423 08-Jan-2020 skrll

branches: 1.423.6;
oldlwp is always non-NULL in cpu_switchto so remove the test for NULL.


# 1.422 08-Jan-2020 ad

Hopefully fix some problems seen with MP support on non-x86, in particular
where curcpu() is defined as curlwp->l_cpu:

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

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

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

- Remove some KERNEL_LOCK handling which hasn't been needed for years.


Revision tags: netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 ad-namecache-base netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.421 18-Jul-2019 palle

branches: 1.421.4;
sun4v: added some missing comments to the code in pcbspill


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 1.420 07-Apr-2019 mrg

make trap 0x70 a TRAP() not UTRAP(). we should be able to handle
fast ECC error as a normal trap, and i saw this once a few years
ago but it never repeated so i haven't been able to test this.


# 1.419 08-Feb-2019 palle

sun4v: Improve comment for next_stick_init() - no functional changes


# 1.418 08-Feb-2019 palle

sun4v: initialize %stickcmpr properly when establishing interrupt - fixes issue seen on newer sun4v/SPARC-T5 system where the interrupt never fires.


# 1.417 08-Feb-2019 palle

sun4v: introduce macros for handling spill traps from userlevevel @ traplevel 1 (from OpenBSD) - spill traps at level 1 from userspace now works better


# 1.416 08-Feb-2019 palle

sun4v: add comment documenting the contents of the %g2 register - no functional changes


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126
# 1.415 04-Nov-2018 palle

Ensure that the 64-bit condition codes are used instead of the 32-bit condition codes. ok martin@


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.414 26-May-2018 palle

branches: 1.414.2;
next_stick() - fix typy in comment: tick->stick


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.413 11-Apr-2018 palle

sun4v: handle MMU-related traps properly when they occur at trap level 1. This fixes issues when user-level LWPs access the user-level stack


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 1.412 26-Aug-2017 palle

branches: 1.412.2;
sun4v: Avoid touching the %tick_cmpr register which is not present on never systems (Oracle SPARC Architecture 2011 and beyond). Based on code from OpenBSD locore.s revision 1.177. Tested on both sun4u (qemu and USIII) and sun4v (qemu and T5-2). ok martin@


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2
# 1.411 06-May-2017 palle

sun4v: The %ver register is not available on sun4v - use GET_MAXCWP introduced in rev. 1.361. Verified using qemu (sun4u and sun4v) and on real sun4v hw (t2000)


Revision tags: prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.410 18-Apr-2017 palle

branches: 1.410.2;
sun4v: Add handling of trap 0x06c @ trap level 1 - based on code from OpenBSD, but slightly adapted to NetBSD. verified using qemu


Revision tags: jdolecek-ncq-base pgoyette-localcount-20170320
# 1.409 19-Feb-2017 palle

sun4v: rft_user needs special handling (a manual fill) since the restore instruction may cause the number of trap levels to exceed the maximum for sun4v - inspired by code from the the openbsd rft_user code path - verified using qemu for both sun4u and sun4v


# 1.408 10-Feb-2017 palle

sun4v: Added handling of trap type 0x034 (address alignment error) + fixed typo mmfsa -> mmufsa. Verified for both sun4u and sun4v using qemu.


Revision tags: nick-nhusb-base-20170204
# 1.407 30-Jan-2017 palle

sun4v: Hook up syscall handling to the trap table. Verified using qemu for both sun4u and sun4v.


# 1.406 27-Jan-2017 palle

sun4v: implement missing handling of itsb traps 0x008 and 0x009. Based on code from OpenBSD. Tested using qemu.


Revision tags: bouyer-socketcan-base
# 1.405 07-Jan-2017 palle

branches: 1.405.2;
sun4v: slowtrap() now selects normal globals properly on both sun4u and sun4v platforms. Verified using qemu for both sun4u and sun4v systems


Revision tags: pgoyette-localcount-20170107
# 1.404 05-Jan-2017 palle

sun4v: TRAP_SETUP() updated to set mmu context id properly for both sun4v and sun4u platforms. Verified using qemu for both sun4u and sun4v systems


# 1.403 04-Jan-2017 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x00-0x23 and 0x28-0x30


# 1.402 29-Dec-2016 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x32-0x7f


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.401 20-Sep-2016 nakayama

Fix RAS for 32-bit kernels. trapframe is always 64-bit.


Revision tags: localcount-20160914
# 1.400 23-Aug-2016 palle

sun4v: rework sun4v_datatrap so it works properly when running on a T2-based system like T5120 - for some reason %tl is 0 when entering sun4v_datatrap causing a crash (sir instruction), so ignore the %tl value for now upon entry to sun4v_datatrap - with this fix both T1 and T2 based systems reach the same point - hangs in rft_user after the init process is started


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726
# 1.399 18-Jul-2016 palle

sun4v: handle device interrupts properly - both legacy (sysino) and cookies


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 1.398 04-Jun-2016 palle

branches: 1.398.2;
sun4v: rtf_user now uses macros GET_MMU_CONTEXTID and SET_MMU_CONTEXTID. Tested on sun4u (QEMU) and sun4v (T2000). Parts from OpenBSD.


Revision tags: nick-nhusb-base-20160529
# 1.397 18-May-2016 nakayama

Decrement %tl in trap handler not to make it zero unconditionally
for the nested trap, and remove useless mov.


# 1.396 17-May-2016 palle

sun4v: Implement missng MMU protection trap handling - mostly from OpenBSD


# 1.395 16-May-2016 palle

Avoid assembler-specific defines by using the export keyword in genassym.cf instead


# 1.394 15-May-2016 nakayama

%g1 is not preserved across function call, so load it before
return_from_trap.


# 1.393 13-May-2016 palle

sun4v: add missing implementation of sun4v_datatrap_tl0 so data_access_fault() is called - mostly from OpenBSD


# 1.392 13-May-2016 nakayama

- ci_paddr is always 64-bit.
- intrlev is array of pointer.
- ih_ack is pointer.


# 1.391 10-May-2016 palle

sun4v: make device interrupts work. Introduce a new intrhand_alloc() function for allocation of interrupt handlers and adapt to this. Parts from OpenBSD. ok martin@


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.390 09-Mar-2016 nakayama

32-bit kernels use 32-bit stack.


# 1.389 03-Mar-2016 palle

sun4v: rft_kernel should pay attention to the number of register windows that can be restored. We cannot rely on fill traps to occur, since sun4v only has two trap levels available in privileged mode. Based on code from OpenBSD. ok martin@


# 1.388 14-Feb-2016 palle

sun4v: add breakpoint trap entry to the sun4v trap table


# 1.387 03-Feb-2016 palle

sun4v: extend dmmu_set_secondary_context() to handle both sun4u and sun4v. ok martin@


Revision tags: nick-nhusb-base-20151226
# 1.386 06-Nov-2015 martin

Basically revert r1.246 of locore.s and r1.73 of vm_machdep.c:

Remove special case handling for userland lwps from cpu_lwp_fork,
instead do it in lwp_trampoline when we first return to userland.

which was a stupid idea - since we did now set all fork child's %tstate
(and thus %pstate when back in userland) to the current kernel's userland
default. This meant we lost the address mask bit for 32bit processes and
all memory model details for 64bit ones.

Move it back to cpu_lwp_fork and fix the condition to only do it once when
forking init.


# 1.385 05-Nov-2015 martin

Most of the time return_from_trap already got called with tf->tf_tstate
loaded in register %g1 - make it so for two more callers and remove
the reload of that value.


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606 nick-nhusb-base-20150406
# 1.384 05-Apr-2015 palle

sun4v: Ensure that the TTEs CP and CV bits are the same (both set) for the primary cpu and secondary cpus INTSTACK mappings


# 1.383 01-Apr-2015 palle

sun4v: Implement handling of cpu_mondo trap - from OpenBSD - tested using the Legion simulator


# 1.382 04-Mar-2015 palle

sun4v: revert some of the logic introduced in revision 1.378 - flushw is not necessary on sun4v (OpenBSD patches the flushw instruction to a nop instruction) - with these changes the kernel reaches cpu_boot_secondary_processors() when running in the Legion simulator (crashes due to missing handling of cpu_mondo_trap)


# 1.381 02-Mar-2015 nakayama

prom_printf converts "\n" to "\r\n" internally, so omit "\r".


# 1.380 02-Mar-2015 nakayama

PANICSTACK is a pointer itself, not a pointer to pointer.


# 1.379 02-Mar-2015 nakayama

Use panic stack temporarily for calling prom_printf in a trap
handler.

It seems that openfirmware cannot handle over 4GB pointers, and
stack pointers may point to over 4GB since VA layout was rearranged
by rev 1.33 of vmparam.h. Therefore, use panic stack to avoid
panicking in OF_write used by prom_printf.


# 1.378 23-Feb-2015 palle

sun4v: sparc_interupt - ensure that the trap level and globals level are the same when the flushw instruction is issued - othwise warnings occur when using the sun4v Legion simulator.


Revision tags: nick-nhusb-base
# 1.377 26-Oct-2014 palle

branches: 1.377.2;
sun4v: Create CLEANWIN0 and CLEANWIN1 macros for handling clean window traps on both sun4u and sun4u (based on the original code inlined in the sun4u trap table). Update trap tables accordingly for both sun4u and sun4v. Ok martin@


# 1.376 24-Oct-2014 nakayama

Fix typo in comment.


# 1.375 18-Oct-2014 snj

src is too big these days to tolerate superfluous apostrophes. It's
"its", people!


# 1.374 15-Oct-2014 palle

sun4v: fixed bug causing the real address to be incorrectly calculated as zero


# 1.373 24-Sep-2014 palle

sun4v: add code to enable startup of secondary cpus on both sun4u and sun4v systems - ok martin@


# 1.372 04-Sep-2014 palle

sun4v: All cpus must be setup with a TSB descriptor, so pmap_setup_tsb_sun4v() must take a pointer to the TSB descriptor


# 1.371 31-Aug-2014 palle

sun4v: Split the NORMAL_GLOBALS and ALTERNATE_GLOBALS macros to _SUN4U and _SUN4V variants. Rework the return_from_trap logic to use the new variants so it is possible to use a global register as scratch register.


# 1.370 14-Aug-2014 nakayama

Add missing delay slot in DEBUG kernel.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.369 30-Jul-2014 palle

branches: 1.369.2;
Fix ALTERNATE_GLOBALS so it at least works on sun4u - using a scratch register is not a good idea...


# 1.368 27-Jul-2014 palle

sun4v: Introduce a new macro ALTERNATE_GLOBALS (matching NORMAL_GLOBALS). Two new helper macros ENABLE_INTERRUPTS and DISABLE_INTERRUPTS are also created. With these changes the GENERIC.UP kernel will reach rootmount on sun4v systems - ok martin@


# 1.367 26-Jul-2014 palle

Improved the NORMAL_GLOBALS macro in the sun4u case, so only the relevant bit (AG) in %pstate is affected - ok martin@


# 1.366 24-Jul-2014 palle

sun4v: add missing spill/fill handling for trap level 1 + cosmetic changes to comments for trap level 0 entries


# 1.365 19-Jul-2014 palle

sun4v: Introduce a NORMAL_GLOBALS macro - first used in sparc_interrupt - other relevant uses will be handled as the sun4v work is progressesing - ok martin@


# 1.364 16-Jul-2014 palle

sun4v: Introduce SET_MMU_CONTEXTID macro for setting the mmu context id on both sun4u and sun4v


# 1.363 13-Jul-2014 palle

sun4v: add interrupt handling to sun4v trap table


# 1.362 13-Jul-2014 palle

Bugfix: add missing cmp instruction to GET_MAXCWP macro


# 1.361 30-Jun-2014 palle

sun4v: The maximum number of register windows is a constant and thus not available via the %ver register (sun4u only). Introduce a macro GET_MAXCWP that handles this, so cpu_switchto() works properly on sun4v. Other relevant reference to %ver can be adapted to use GET_MAXCWP as the sun4v port progresses. OK martin@


# 1.360 31-May-2014 palle

sun4v: added missing dtsb miss handling for trap level 1 - with this update the kernel now reaches configure() on sun4v systems


# 1.359 30-May-2014 palle

Remove debugging code introduced by accident in locore.s revision 1.357


Revision tags: yamt-pagecache-base9 rmind-smpnet-nbase rmind-smpnet-base
# 1.358 05-May-2014 palle

sun4v: the trap base address should be assigned to %l1 so %tba is properly setup later in the code - now the kernel gets as far as printing the copyright disclaimer, kernel version and total and available memory before crashing


# 1.357 21-Apr-2014 palle

sun4v: Update comment: modified -> access


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.356 21-Feb-2014 palle

branches: 1.356.2;
sun4v: Rename TLB_ defines to SUN4U_TLB_ so entries created using TSB_DATA() are properly setup for sun4u and sun4v. Relocate the cputyp variable from autoconf.c to locore.s and make it const in param.h so optimized code can be generated. Parts from OpenBSD. Optimization suggested by nakayama@. OK martin@, mrg@, nakayama@


# 1.355 31-Jan-2014 tsutsui

defined(LKM) -> defined(MODULAR)


# 1.354 26-Jan-2014 palle

sun4v: Add handling of spill/fill and dtsb miss traps (with a XXX to be handled later)


# 1.353 07-Jan-2014 palle

sun4v: trap table setup - currently populated with dummy entries which will be properly implemented later - parts from OpenBSD - OK martin@


# 1.352 29-Dec-2013 nakayama

Make buildable w/o options SUN4V.


# 1.351 27-Dec-2013 palle

a) make the hunt through the cpus list more generic b) sun4v: ensure that the interrupt stack is mapped permanently and the TSB is setup properly - parts from OpenBSD. OK martin@


# 1.350 06-Dec-2013 nakayama

Increase an interrupt depth only in the case of hardware interrupts,
and remove the ci_idepth trick in softint_fastintr.

Fixes the following diagnostic panic reported in port-sparc64.

panic: kernel diagnostic assertion "!cpu_intr_p()" failed: file
"../../../../kern/subr_xcall.c", line 351


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 1.349 24-May-2013 nakayama

branches: 1.349.2;
Disable interrupts after calling data_access_error as with
data_access_fault.


# 1.348 28-Apr-2013 nakayama

Use macros in machine/asm.h instead of locally defined, and
introduce CASPTRA for casxa/casa.


Revision tags: agc-symver-base
# 1.347 23-Jan-2013 martin

Fix sparc64_ipi_ccall by adding proper trap setup.
Fixes xcall(9) problems, as exposed by pserialize(9). Noticed by
J. Hannken-Illjes, cause pointed out by Takeshi Nakayama.


# 1.346 23-Jan-2013 martin

Sligthly clean up the (by default unused) #ifdef TRAPS_USE_IG


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.345 10-Nov-2012 nakayama

Revise comment.


# 1.344 10-Nov-2012 nakayama

Use macro instead of magic number.


# 1.343 09-Nov-2012 nakayama

Make setstick() and getstick() to inline functions.


# 1.342 08-Nov-2012 macallan

use system tick timer instead of %tick on UltraSPARC-III-ish CPUs
review & fixes by Takeshi Nakayama


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.341 17-Mar-2012 mrg

branches: 1.341.2;
port the corrected ECC error handling code from freebsd. i noticed my U10
took one of these and then hang. it shouldn't hang, there's a 'sir' here that
doesn't seem to reset properly. oh well.

tested by simulated a trap via 'ta 0x10' and considering that the same, but
it hasn't been tested against a real ECC error yet.


Revision tags: jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base4
# 1.340 03-Mar-2012 nakayama

Fix the root cause of the hack "disable optimizations for uvm_bio.c
on 32 bit kernels".

gcc converts a division in the calculation of UBC_UMAP_ADDR macro
to multiplication (smul or combination of add/sll), and the
register of its result contains a garbage in upper 32 bits (the
upper 32 bits of smul/add/sll's result isn't zero cleared).

Then it passes to pseg_get{,_real} through pmap_extract without the
zero clear of upper 32 bits in the optimization case. So the
result of pseg_get and pmap_extact sometimes gets screwed up.


Revision tags: jmcneill-usbmp-base5 jmcneill-usbmp-base3
# 1.339 19-Feb-2012 rmind

Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.


Revision tags: jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.338 04-Sep-2011 nakayama

branches: 1.338.2; 1.338.6; 1.338.8;
ih_pil is an interrupt level, not an interrupt mask.


# 1.337 27-Jul-2011 nakayama

ivec is assigned to hardware, so count its event counter up in
interrupt_vector, not in softint, and do some optimization.


# 1.336 20-Jul-2011 macallan

add per ivec event counters


# 1.335 12-Jul-2011 mrg

rename sparc64 BLOCK_SIZE and BLOCK_ALIGN to have SPARC64_ prefixes.
for the assembler files, define the old names to the new names
since using the new names cause ugliness due to longer identifer
names, and reduces churn.

fixes build issues in dtv and vaguely makes <machine/psl.h> slightly
less name-space invasive.


# 1.334 18-Jun-2011 nakayama

Add fast softint(9) support for sparc64.

Reviewed on port-sparc64.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 1.333 12-May-2011 mrg

branches: 1.333.2;
first steps towards fujitsu SPARC64 support:

- SPARC64 systems have interrupts with upto 14 bits set, but we only look
at the first 11 bits. trim non IPI interrupts to 11 bits


Revision tags: uebayasi-xip-base7 bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 jym-xensuspend-nbase jym-xensuspend-base
# 1.332 20-Dec-2010 matt

branches: 1.332.2;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.


Revision tags: uebayasi-xip-base6 uebayasi-xip-base5 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 1.331 10-Jul-2010 nakayama

Clear the upper word explicitly before combining two 32-bit values to 64-bit
on 32-bit kernels.


# 1.330 23-May-2010 martin

Split copy related functions out of locore.s into copy.S, move functions
only needed on multiprocessors into mp_subr.S.


# 1.329 17-May-2010 martin

Simplify primary CPU startup slightly by using the fact that our cpuinfo's
curpcb pointer points to the uarea/pcb of lwp0 and by remembering the pointer
to this cpuinfo, thus avoiding a few CPUINFO_VA references.


Revision tags: uebayasi-xip-base1
# 1.328 20-Mar-2010 chs

fix copy{in,out}{,str}() to return the error returned by uvm_fault().
fixes PR 41813.


Revision tags: yamt-nfs-mp-base9
# 1.327 10-Mar-2010 mrg

branches: 1.327.2;
XXX: workaround we'd like to remove when pmap / uvm locking is cleaned up:

- rename pseg_get() and pseg_set() to pseg_get_real() and pseg_set_real().
- if USE_LOCKSAFE_PSEG_GETSET is defined, which it current is by default,
define pseg_[gs]et() in terms of functions that take a new pseg_lock
mutex at IPL_VM while calling into the real functions.

this seems to avoid the pseg_set() crashes we've seen:
1 - spare needed, when pseg_get() just worked for this pmap
2 - the 2rd ldxa via ASI_PHYS_CACHED in pseg_set() loads garbage
into %o4, and causes the 3rd ldxa to fault


# 1.326 08-Mar-2010 mrg

blast_dcache() SMP friendly:

- blast_dcache() becomes sp_blast_dcache(dcache_size, dcache_line_size)
- new smp_blast_dcache(sparc64_cpuset_t) that blasts the D$ on this cpuset
- sparc64_ipi_blast_dcache() to support the above
- in pmap_remove_all(), when freeing mmu contexts for this pmap, mark
the set of cpus to blast the d$ on as well and convert the
blast_dcache() call into smp_blast_dcache() on the cpus who ran this
pmap, or, sp_blast_dcache(dcache_size, dcache_line_size)
- convert the remaining blast_dcache() in machdep.c to sp_blast_dcache()
- in pmap_destroy()/pmap_remove_all() take the pmap_lock() always since
we assert it is held always.

with these changes, NFS builds on the U60 seem to be stable now, and
the USIII machines also can often complete a single build.sh run now,
diskful or diskless.


reviewed by mlelstv and partially by martin, tested by martin and myself,
with some ideas from chuq as well.


# 1.325 07-Mar-2010 mrg

need _ALIGN in locore.h as well, for DEBUG kernels.


# 1.324 07-Mar-2010 mrg

gas has supported SPARC ".empty" for a long while; get rid of an
ancient workaround.


# 1.323 06-Mar-2010 mrg

move the memcpy/memset implementations out into their own file, with the
block copy versions as well. move some of the definitions in locore.s
into a new locore.h.

locore.s is almost 2000 lines shorter with this change.


# 1.322 04-Mar-2010 mrg

- in _bus_dmamap_unload(), pmap_page_protect() and pmap_clear_reference()
switch the dcache_flush_page() into a dcache_flush_page_all()
- in both pmap_kremove()/pmap_remove(), remove the blast_dcache() call
and replace it with dcache_flush_page_all()
- in pmap_get_page() [used to allocate PTP's], always call pmap_zero_page(pa)
- flush the dcache of the dst page in pmap_{copy,zero}_page() by redirecting
throught a C function that calls the (renamed) asm. the old asm code had a
comment about needing to do this...
- add a couple of membar #Sync's that the USIII manual recommends


based on discussions with chuq@, skrll@ and martin@.


these help my SB2000 / SB2500 with both disk / nfs builds and other tasks,
sometimes lasting for several hours before failing or asserting.


# 1.321 24-Feb-2010 mrg

when handing back page table pages to UVM, flush them from the dcache
on all CPUs.

idea from skrll@, and makes my disk-based SB2000 stable.

tested on U60, SB2000 and SB2500.


# 1.320 24-Feb-2010 mrg

- re-introduce sp_tlb_flush_pte() and sp_tlb_flush_all() that call
the right USI/USIII version.
- define tlb_flush_pte() in terms of sp_tlb_flush_pte() for the
!MULTIPROCESSOR case

this centralises some CPU_IS_USIII_UP() tests.


# 1.319 22-Feb-2010 mrg

move {dump,print}_[id]tlb() into a separate file.


# 1.318 22-Feb-2010 mrg

- store the maximum [id]cache size / line size for each cpu

- remove patch_kernel() since it isn't necessary and has been patching
the wrong thing in general.

- implement USIII versions of blast_icache(), dcache_flush_page() and
cache_flush_phys(). use the newly recorded cache size/line sizes.

- in winfixsave, flush the D$ with the right size index and ops. this
kills one of the wrong tag->inval patches.

- for blast_dcache(), use the newly recorded dcache_size/line_size.

- for blast_icache(), use the newly recorded cache size/line sizes.
for the USIII verison, disable the I$ while writing to ASI_ICACHE_TAG.


these changes removed several hard coded cache sizes values, some very
wrong kernel patching, and seem to make the current failure modes for
USIII less common, but not gone.


# 1.317 15-Feb-2010 mrg

- don't flush 32-bit entries for 64-bit code, it does not seem to be
necessary. #define TLB_FLUSH_LOWVA to turn it back on.
- remove the #if 0'd code in sparc64_ipi_flush_pte_usiii(), i have
verified that it is not required.
- add a missing membar #Sync to sp_tlb_flush_pte_usiii().


# 1.316 15-Feb-2010 nakayama

Fix linker error of GENERIC32 kernel.


# 1.315 15-Feb-2010 mrg

use TLB_SIZE_SPITFIRE in a couple of places, and note that the
{print,dump}_[id]tlb() versions are currently spitfire specific.


# 1.314 15-Feb-2010 mrg

introduce a new patch_kernel() and call it from the end of bootstrap().
use it to patch up TLB flush instructions that don't match for USI/II
and later. we can also hopefully use this to make GENERIC.MP minimally
expensive on single CPU machines as well.

this is the last piece needed to get GENERIC/GENERIC.MP to boot on the
USIII* machines.

idea and some initial code from openbsd.


# 1.313 13-Feb-2010 mrg

remove KTR support. it's never been a working part of netbsd src tree.


# 1.312 09-Feb-2010 wiz

Fix typo in comment.


Revision tags: uebayasi-xip-base
# 1.311 06-Feb-2010 mrg

branches: 1.311.2;
- properly map the schizo interrupt registers, so we can use the normal
virtual mappings to access them.
- with the above fxied, kill SCHIZO_BUS_SPACE_BROKEN, and introduce
an options CHEETAH for now, that disables the SPITFIRE code in locore.
- merge schizo_init() into schizo_attach() and clean up the softc a bit.


with this we are only one more step away from GENERIC booting on USIII
machines.


# 1.310 02-Feb-2010 mrg

- split sp_tlb_flush_pte() and switchtoctx() into sp_tlb_flush_pte_us()/
sp_tlb_flush_pte_usiii() and switchtoctx_us()/switchtoctx_usiii() and
implement the latter while i'm here. it works ... sometimes i think,
but also sometimes panics/hangs.
- fix a comment in sparc64_ipi_flush_pte_usiii()


# 1.309 02-Feb-2010 mrg

for now, reduce a few #ifdef SPITFIRE cases by introducing a new
ASI_DCACHE_TAG_OR_INV that is either ASI_DCACHE_{TAG,_INVALIDATE}.

increase the common code in cache_flush_phys().


# 1.308 01-Feb-2010 mrg

- sp_tlb_flush_all() becomes sp_tlb_flush_all_us() and sp_tlb_flush_all_usiii()
- sparc64_ipi_flush_pte() becomes sparc64_ipi_flush_pte_us() and
sparc64_ipi_flush_pte_usiii()
- add some commented out code to disable interrupts and raise the traplevel
in sparc64_ipi_flush_pte_usiii()
- cache_flush_phys() was missing a little of code in the cheetah case


# 1.307 01-Feb-2010 mrg

for USIII, use the new "tlb demap all" operation in sp_tlb_flush_all()


# 1.306 01-Feb-2010 mrg

remove unused icache_flush_page() implementation.


# 1.305 23-Jan-2010 mrg

remove the final uses of DATA_START.

now we can remove the 16KB space reserved at the start of the data segment,
and i now understand why i wrote this now removed comment 3.5 years ago:
"this shouldn't be needed... but kernel usually hangs without it"


# 1.304 23-Jan-2010 mrg

remove most of the code that writes debugging info DATA_START + offset.


# 1.303 23-Jan-2010 mrg

remove CHKPT() macro and uses. it's likely wrong in SMP land and probably should
be replaced with KTR-style uses if necessary.


# 1.302 23-Jan-2010 mrg

fix a comment.


Revision tags: matt-premerge-20091211
# 1.301 10-Dec-2009 rmind

Rename L_ADDR to L_PCB and amend some comments accordingly.


# 1.300 05-Dec-2009 mrg

- adjust the PA mask to the 43 bits supported by USIII.
- rework the spitfire/cheetah cache_flush_phys() to avoid several #ifdefs
- add a membar #Sync after sparc64_ipi_drop_fpstate (probably unnecessary)


# 1.299 30-Nov-2009 nakayama

sp_tlb_flush_pte for cheetah:
- restore interrupts properly in case of %tl > 0.


# 1.298 30-Nov-2009 mrg

stablize UP USIII support by blocking interrupts around sp_tlb_flush_pte()
i was seeing stack corruption while taking an interrupt in this function.

get USIII SMP mostly working by implementing the cheetah version of
sparc64_ipi_flush_pte().


SMP support is still not entirely stable. i can reproducably get a:

panic: fpusave_lwp ipi didn't

while running build.sh, when an awk process is exiting. other simple
heavy work loads do not crash for me right now.


# 1.297 30-Nov-2009 mrg

delete some no longer used code:
- smp_tlb_flush_ctx()
- smp_tlb_flush_all()
- sparc64_ipi_flush_ctx()
- sparc64_ipi_flush_all()
- sp_tlb_flush_ctx()


# 1.296 29-Nov-2009 nakayama

- calculate end PA correctly.
- wrap more spitfire specific (flushing I$) code.
- fix inverted #if condition for flushing I$ (and restore ASI_ICACHE_TAG).


# 1.295 28-Nov-2009 mrg

implement enough code to get SB2000/SB2500 booting to multiuser. does
not last long if you use it, but an idle machine has stayed up 10 hours.

- for the !SPITFIRE case, use ASI_DCACHE_INVALIDATE instead of
ASI_DCACHE_TAG when clearing tlb entries. from openbsd.

- convert some comment "! Not yet" into "WRITEME", so that attempting
to build a USIII MULTIPROCESSOR kernel fails to build until the code
is written.

- add some more WRITEME's for the above.

- implement a !SPITFIRE version of sp_tlb_flush_all(). since there are
no spare regs, for now just always increase %tl around this call. (we
could maybe store a token in %o3 along with the saved %pstate info.)


# 1.294 26-Nov-2009 matt

Kill proc0paddr. Use lwp0.l_addr instead.


# 1.293 25-Nov-2009 mrg

s/L_ADDR/L_PCB/, requested by rmind.


# 1.292 17-Oct-2009 nakayama

Wrap unused code with #if 0 which is called from #if 0'ed code.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5
# 1.291 30-May-2009 martin

cpu_setfunc() can not use lwp_trampoline, as that has additional lwp startup
semantics. Use a simpler setfunc_trampoline instead.


# 1.290 18-May-2009 nakayama

Remove random() from locore.s since it is in libkern.


# 1.289 16-May-2009 nakayama

Remove clear %tick in locore.s since it is cleared at cpu_initclocks() in
clock.c.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 nick-hppapmap-base mjf-devfs2-base
# 1.288 15-Dec-2008 mrg

restore some old "intrdebug" code, but leave it under NOT_DEBUG. most
of it works, but one that prints func/arg for each handler is not very
stable...

for now, while schizo bus space pointer accesses aren't working, add
a SCHIZO_BUS_SPACE_BROKEN option so you can build a kernel with schizo.

with this, and the prior schizo interrupt fix, you can now fail to run
/sbin/init!


Revision tags: haad-dm-base2 haad-nbase2 haad-dm-base
# 1.287 09-Dec-2008 martin

Get rid of get_maxctx() - it doesn't work on newer cpus and we will have
to find a better way for (some) sun4v machines - all sun4u use 13 bit
contexts anyway.


Revision tags: netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 ad-audiomp2-base netbsd-5-base
# 1.286 30-Oct-2008 nakayama

branches: 1.286.2; 1.286.6;
Wrap more code specific to USE_BLOCK_STORE_LOAD.


Revision tags: matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4
# 1.285 05-Oct-2008 nakayama

branches: 1.285.2;
- in flushing cache, use 32 as increment/decrement value to match the
cache line size.
- remove useless restore of %asi.
- remove nop in delay slot if we can.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 1.284 10-Jul-2008 nakayama

Use proper CCR.


# 1.283 10-Jul-2008 nakayama

sparc64_ipi_save_fpstate:
- use primary MMU context for consistency with other trap/interrupt handlers.

sparc64_ipi_save_fpstate, savefpstate:
- avoid storing fp registers as we can.

sparc64_ipi_save_fpstate, savefpstate, loadfpstate:
- remove unaligned case since buffers allocated with pool_cache are ensured
64-byte aligned.

Ok by martin@.


# 1.282 02-Jul-2008 nakayama

branches: 1.282.2;
UltraSPARCs don't have floating point queue, and reading %fq regsiter
will cause illegal instruction trap. So remove the code handling them.


# 1.281 29-Jun-2008 nakayama

Wrap IPI calls with #ifdef MULTIPROCESSOR.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.280 14-Jun-2008 nakayama

Close unterminated comment.
Fix unexpected behavior in case of loadfpstate from unaligned buffer.


Revision tags: yamt-pf42-base3
# 1.279 31-May-2008 nakayama

branches: 1.279.2;
openfirmware_exit:
- disable interrupts with %pstate.
- prepare 64-bit stack and enable 64-bit addresses for 32-bit SMP kernels.


Revision tags: hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 yamt-nfs-mp-base yamt-pf42-base
# 1.278 16-Apr-2008 nakayama

branches: 1.278.2; 1.278.4; 1.278.6;
Disable TRAPSTATS which was accidentally enabled when yamt-idlelwp branch
was merged.

Ok by martin@.


# 1.277 14-Apr-2008 nakayama

Remove sparc64_ipi_sync_tick.

Since we can use counter-timer as timecounter instead of %tick on SMP kernel,
it is not necessary to sync all CPUs %tick registers.


# 1.276 14-Apr-2008 nakayama

Add workaround for BB_ERRATA_1 on writing to TICK_CMPR register in
next_tick(). If writing to TICK_CMPR fails, we lose hardclock interrupt
on secondary CPUs.

About BB_ERRATA_1 from comment in OpenSolaris:

/*
* Writes to the TICK_COMPARE register sometimes fail on blackbird modules.
* The failure occurs only when the following instruction decodes to wr or
* wrpr. The workaround is to immediately follow writes to TICK_COMPARE
* with a read, thus stalling the pipe and keeping following instructions
* from causing data corruption. Aligning to a quadword will ensure these
* two instructions are not split due to i$ misses.
*/


# 1.275 28-Mar-2008 nakayama

Don't read fplwp content in delay slot for considering the case fplwp was
modifiled.

Reported by Chris Ross on port-sparc64.


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.274 20-Mar-2008 nakayama

- remove disabling interrupt in IPI.
- unused VA bits in MMU demap is 13 bits, not 12 bits.


# 1.273 18-Mar-2008 nakayama

Fix a race when increment an interrupt level event counter.


# 1.272 17-Mar-2008 nakayama

Fix a race condition in IPI handlers of save/drop fpstate, from OpenBSD.
Reported and tested by martin@.


# 1.271 17-Mar-2008 nakayama

Make schedintr interrupt handler per-CPU.
While there rename tickintr interrupt handler and share initialization
code with schedintr.


# 1.270 14-Mar-2008 nakayama

Improve IPI handling:
- make IPI takes two arguments.
- add IPI event counters per-CPU.
- implement IPI functions which were missing or broken.
- insert DELAY while halting primary CPU in IPI handler.


# 1.269 02-Mar-2008 nakayama

- make interrupt pending list per-CPU.
- make tickintr() MP-safe.
- remove unused port-sparc derived interrupt code.

Ok by martin@.


# 1.268 02-Mar-2008 nakayama

Don't get IPI handler argument (from bogus address), and ack IRQ twice.


# 1.267 28-Feb-2008 martin

Make TSBs and MMU contexts per-cpu.


Revision tags: nick-net80211-sync-base mjf-devfs-base hpcarm-cleanup-base
# 1.266 26-Jan-2008 nakayama

branches: 1.266.2; 1.266.6;
Fix for 32-bit kernels.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.265 15-Jan-2008 skrll

Store a sensbile PCB_PC value in snapshot - the return point.

This helps gdb somewhat.

OK'd by martin.


# 1.264 14-Jan-2008 martin

Fix register name typo/copy&pasto - %g6 is not %o6/%sp.
From OpenBSD.


Revision tags: matt-armv6-base
# 1.263 06-Jan-2008 martin

Load the next cpu_info pointer with LDPTR instead of ld.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2
# 1.262 09-Dec-2007 martin

branches: 1.262.2;
Provide cpu_intr_p(), at least for non-MULTIPROCESSOR kernels.
Based on suggestions by Andrew Doran.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.261 22-Oct-2007 martin

branches: 1.261.2; 1.261.4; 1.261.6;
Remove an unused .globl declaration


Revision tags: yamt-x86pmap-base4
# 1.260 17-Oct-2007 garbled

Merge the ppcoea-renovation branch to HEAD.

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

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

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base ppcoea-renovation-base vmlocking-base
# 1.259 09-Sep-2007 martin

branches: 1.259.4;
Make cpufrequency and friends per cpu values.
Prepare a hz tick interrupt on secondary CPUs via %tick, but do not
enable it yet, as it breaks ddb.


# 1.258 09-Sep-2007 martin

Do not ACK IPIs before we finished loading all arguments.


# 1.257 06-Sep-2007 martin

Remove the (now unused) second 64k page mapped per CPU.
From matthew green, with small changes by me. All bugs are mine.


# 1.256 25-Aug-2007 martin

branches: 1.256.2;
Remove INITSTACK completely - at the time we used to switch to it, we
already have access to all of lwp0 and it's uarea - so we can switch
to the correct lwp0 stack easily before calling main.


# 1.255 25-Aug-2007 martin

When exiting to OF, use the interrupt stack instead of INITSTACK


# 1.254 25-Aug-2007 martin

Rework cpu_mp_startup slightly:
- temporarily use the cpu's interrupt stack untill we are ready
to access non-OF-based mappings, then directly switch to the cpu's
idlelwp's uarea stack
- disable interrupts untill we are ready to call C code


# 1.253 13-Aug-2007 macallan

remove two restore without matching save


Revision tags: nick-csl-alignment-base matt-mips64-base mjf-ufs-trans-base
# 1.252 06-Jul-2007 martin

branches: 1.252.4; 1.252.8;
A few nits for 32bit SMP kernels, noticed by mrg.
While there, simplify the fpstate IPIs a bit.


# 1.251 05-Jul-2007 martin

sparc64_ipi_save_fpstate is not a leaf function - create a full grown
stack frame.


# 1.250 28-May-2007 mrg

clean up cpu_switchto() a little - no need to flushw or membar
excessively. optimise an rdpr. tested by tnn.


# 1.249 23-May-2007 martin

Fix a stupid bug in the save_fpstate ipi, which caused overwriting of
struct lwp of the lwp owning the fpu. Fix clearing the fplwp - %o0 will
not survive the call to savefpstate - duh!


# 1.248 20-May-2007 martin

Simplify tf_tstate setting when leaving for userland initially - I seem
to have confused the if with the else case of the previous C code.
Funny that it worked at all.


# 1.247 20-May-2007 martin

cpu_switchto() has to return it's first arg, always. This differs from
my reading of the documentation, but helps in the real world and seems
to be what other ports do.


# 1.246 20-May-2007 martin

Remove special case handling for userland lwps from cpu_lwp_fork, instead
do it in lwp_trampoline when we first return to userland.


# 1.245 19-May-2007 martin

cpu_idle is a leaf function, so we better "return from leaf".
Use return value from cpu_switchto for previous lwp in lwp_trampoline.
Also shamelessly steal a comment from uwe written for sparc that explains
all this.
Thanks to tnn, mrg, and uwe for helping to debug this.


# 1.244 17-May-2007 yamt

merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base ad-audiomp-base
# 1.243 22-Feb-2007 martin

branches: 1.243.4; 1.243.6; 1.243.12;
uvm.page_idle_zero now is a bool, not a 32bit value any more.


# 1.242 21-Feb-2007 mrg

shave 9 insns off the tsb setup in cpu_initialize & cpu_mp_startup.


# 1.241 21-Feb-2007 martin

Get rid of unused (thus always zero) "curlwp" variable hidden in assembler
code (C code always uses a cpuinfo based macro).


# 1.240 18-Feb-2007 martin

Make use of another call delay slot, pointed out by uwe.


# 1.239 18-Feb-2007 martin

Make use of a call delay slot and avoid a bogus EMPTY.
Spotted by Juergen Hannken-Illjes, with input from Andrew Doran and
Valeriy E. Ushakov.


# 1.238 18-Feb-2007 martin

Whitespace cosmetics


# 1.237 18-Feb-2007 martin

Backout previous: EMPTY was misused


# 1.236 18-Feb-2007 martin

Make EMPTY expand to nop with gas, as it is used to mark empty branch
delay slots.


# 1.235 15-Feb-2007 martin

branches: 1.235.2;
Fix obvious copy&pasto in SCHED_DEBUG register usage.


Revision tags: post-newlock2-merge
# 1.234 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.233 25-Dec-2006 wiz

Spell "relevant" correctly. From Zafer Aydogan.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.232 25-Oct-2006 mrg

branches: 1.232.2; 1.232.4;
- note that __idle_u should go away but doing so breaks things
- fix several comments to reality
- clean up the #ifdef NO_VCACHE code slightly
- use call instead of set/jmpl
- remove a couple of unnecessary stores to curlwp


Revision tags: yamt-splraiseipl-base2
# 1.231 18-Oct-2006 rjs

Clean up some comments. Cosmetic change to use correct structure
offset names.

Optimize out two instructions from sparc64_ipi_save_fpstate and
sparc64_ipi_drop_fpstate.


# 1.230 17-Oct-2006 mrg

allocate 128KB (as opposed to 64KB) per-cpu, and place the interrupt
stack, cpu_info structure, panicstack, idle uarea and normal kernel
stack in here. the idle uarea and kernel stack are in the 2nd 64KB
page. the interrupt stack and cpu_info structure are as the same
place in the 1st 64KB page, and the panicstack grows down from the
top of this page. update comments in param.h to suit (XXX: a lot
of these constants should move to a header file that will not pollute
the name space so much.) map these pages identically between
cpu_initialise() and cpu_mp_startup(), and deal with the two 64KB
pages in pmap_extract(). keep an unmapped 64KB page between them.

don't initialise the unused "ci_eintstack" member of the cpu_info
structure

use constants to initialise many addresses in the cpu_info structure,
consolidating these assignments from cpu0 and cpu>0

delete u0/estack0/panicstack from locore.s

clean up some wrong comments in locore.s

fix a 32bit-only bug in cpu_mp_startup().

delete 'u0' entirely.


this fixes recent random lossage seen on port-sparc64: processes
stuck in RUN state, data faults, and hangs.


# 1.229 04-Oct-2006 mrg

use call instead of set/jmpl. add an entry point for idle that expects
sched_lock to be unlocked, and use this for non-boot cpu's. complete a
comment describing how registers in idle_switch are expected to be set.


# 1.228 03-Oct-2006 mrg

use the same SAVE_LOCALS_INS definition for 32 bit and 64 bit kernels.
refactor TRAP_SETUP() a little between these two versions to be more alike.


# 1.227 03-Oct-2006 mrg

use the correct size/type for MP variables (pointers and longs).

a 32 bit MULTIPROCESSOR kernel now builds (and crashes quickly.)


# 1.226 03-Oct-2006 mrg

in the 64bit version of SAVE_LOCAL_INS, s/BIAS/STKB/ to allow future
sharing of the 32 and 64 bit versions of the {TRAP,INTR}_SETUP macros.


# 1.225 19-Sep-2006 mrg

- remove some way old FP setup/teardown code
- put the block memcpy/memset inside #ifdef USE_BLOCK_STORE_LOAD which
is (now) defined.

no functional change, same .o is generated.


# 1.224 19-Sep-2006 mrg

re-order the changes in rev 1.217 to give registers a little bit of
time to settle between usage, like it was before hand.


# 1.223 19-Sep-2006 mrg

- remove a wrong comment.
- add a new entry point for idle called idle_switch that is called by
cpu_switch() in the MP case when sched_whichqs is zero, properly
setting up the idle stack. from petrov@ via martin@.


# 1.222 19-Sep-2006 mrg

rework interrupt_vector() slightly:
- for the IPI case, avoid loading the address of intrlev into %g3
- remove some NOT_DEBUG code
- load the interrupt argument #2 in the delay slot

this removes 2 nops during interrupt processing for the normal
case, and an additional 2 ALU instructions for IPIs


# 1.221 18-Sep-2006 mrg

- sparc64_ipi_halt(): we shouldn't return from sparc64_ipi_halt_thiscpu()
so replace a branch with a 'sir'
- in #if 0 code, in sparc64_ipi_flush_pte() and sparc64_ipi_flush_ctx()
save/restore the out registers that the sp_tlb_flush_xxx() versions
around calling them
- in sp_tlb_flush_pte() and sp_tlb_flush_ctx(), replace global register
usage with out registers so that we don't clobber the (alternate)
global registers when these are called from IPI context


# 1.220 18-Sep-2006 mrg

- remove an extra 'sir' that followed one in a macro
- add some named labels to some spill/fill handlers
- remove 2 unused strings


Revision tags: yamt-splraiseipl-base
# 1.219 18-Sep-2006 martin

branches: 1.219.2;
Lazy FPU handling for the MULTIPROCESSOR case


# 1.218 16-Sep-2006 nakayama

From OpenBSD:
- reload %fprs for checking it again.
- use symbolic names for checking in %fprs.

revision 1.51
date: 2005/07/18 14:50:11; author: deraadt; state: Exp; lines: +2 -1
cache a copy of the fprs so we know what fp restore we should do after

revision 1.50
date: 2005/07/14 01:46:13; author: deraadt; state: Exp; lines: +4 -4
use symbolic names for checking in %fprs, as above


# 1.217 16-Sep-2006 nakayama

Fix a couple of %y register save/restore errors, inspired from OpenBSD.

revision 1.44
date: 2004/04/23 04:18:17; author: marc; state: Exp; lines: +5 -4

fix a couple of %y register save/restore errors
1) don't save %y in a register that is later used before restoring %y
2) always restore %y after calling a signal handler
tested by drahn@, OK pval


# 1.216 15-Sep-2006 martin

Do not bother to save fpu state when we are about to get rid of it.


Revision tags: yamt-pdpolicy-base9
# 1.215 13-Sep-2006 mrg

SMP cleanup. provide support for multiple CPUs in DDB. (SMP itself
is still not working.)

cpu.h:
- add a pointer for DDB regs in SMP environment to struct cpu_info
- remove the #defines for mp_pause_cpus() and mp_resume_cpus()
cpuset.h:
- remove CPUSET_ALL() and rename CPUSET_ALL_BUT() to CPUSET_EXCEPT()
from petrov.
db_machdep.h:
- rename the members of db_regs_t to be the same as sparc
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- redo DDB_REGS to no longer be a pointer to a fixed data structure
but to one allocated per-cpu when ddb is entered
- move a bunch of prototypes in here
intr.h:
- remove SPARC64_IPI_* macros, no longer used
db_interface.c:
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- make "nil" a 64 bit entity
- change the ddb register access methods to work in multiprocessor
environment, it is now very much like sparc does it
- in kdb_trap() avoid accessing ddb_regp when it is NULL
- update several messages to include the cpu number
- unpause other cpus much later when resuming from ddb
- rename db_lock() to db_lock_cmd(), as the sparc-like code has
db_lock as a simple lock
- remove "mach cpus" command, and replace it with "mach cpu" (which
does the same) and also implement "mach cpu N" to switch to
another cpus saved trapframe
db_trace.c:
- update for the ddb_regs -> ddb_regp change
genassym.cf:
- add TF_KSTACK as offsetof(struct trapframe64, tf_kstack)
ipifuncs.c:
- overhaul extensively
- remove all normal interrupt handlers as IPI's, we now handle
them all specially in locore.s:interrupt_vector
- add a simplelock around all ipi functions - it's not safe for
multiple cpus to be sending IPI's to each other right now
- rename sparc64_ipi_pause() to sparc64_ipi_pause_thiscpu() and,
if DDB is configured, enable it to save the passed-in trapframe
to a db_regs_t for this cpu's saved DDB registers.
- remove the "ipimask" system (SPARC64_IPI_* macros) and instead
pass functions directly
- in sparc64_send_ipi() always set the interrupt arguments to 0,
the address and argument of the to be called function. (the
argument right now is the address of ipi_tlb_args variable, and
part of the reason why only one CPU can send IPI's at a time.)
don't wait forever for an IPI to complete. some of this is
from petrov.
- rename sparc64_ipi_{halt,pause,resume}_cpus() to
mp_{halt,pause,resume}_cpus()
- new function mp_cpu_is_paused() used to avoid access missing
saved DDB registers
- actually broadcast the flush in smp_tlb_flush_pte(),
smp_tlb_flush_ctx() and smp_tlb_flush_all(). the other end may
not do anything yet in the pte/ctx cases yet...
kgdb_machdep.c:
- rework for changed member names in db_regs_t.
locore.s:
- shave an instruction from syscall_setup() (set + ld -> sethi + ld)
- remove some old dead debug code
- add new sparc64_ipi_halt IPI entry point, it just calls the C
vector to shutdown.
- add new sparc64_ipi_pause IPI entry point, which just traps into
the debugger using the normal breakpoint trap. these cpus usually
lose the race in db_interface.c:db_suspend_others() and end up
calling the C vector sparc64_ipi_pause_thiscpu().
- add #if 0'ed code to sparc64_ipi_flush_{pte,ctx}() IPI entry
points to call the sp_ version of these functions.
- in rft_kernel (return from trap, kernel), check to see if the
%tpc is at the sparc64_ipi_pause_trap_point and if so, call
"done" not "retry"
- rework cpu_switch slightly: save the passed-in lwp instead of
using the one in curlwp
- in cpu_loadproc(), save the new lwp not the old lwp, to curlwp
- in cpu_initialize(), set %tl to zero as well. from petrov.
- in cpu_exit(), fix a load register confusion. from petrov.
- change some "set" in delay branch to "mov".
machdep.c:
- deal with function renames
pmap.c:
- remove a spurious space
trap.c:
- remove unused "trapstats" variable
- add cpu number to a couple of messages


# 1.214 09-Sep-2006 mrg

significant clean up effort, largely from petrov@ via martin@.

- fix a bunch of comments for proc->lwp
- remove old TRAPTRACE, NOT_DEBUG, etc. code that has bit-rotted
- put some older DEBUG code under NOT_DEBUG
- add a bunch of new debugging/tracing code ("KTR") that depends on
other changes not yet present.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base yamt-pdpolicy-base5 chap-midi-base simonb-timecounters-base rpaulo-netinet-merge-pcb-base
# 1.213 14-May-2006 elad

branches: 1.213.6; 1.213.8;
integrate kauth.


# 1.212 12-May-2006 skrll

Fix some comments.


Revision tags: elad-kernelauth-base
# 1.211 09-May-2006 rjs

Load CPCB in cpu_mp_startup.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.210 11-Feb-2006 cdi

branches: 1.210.2; 1.210.4; 1.210.6;
ANSIfication: u_intN_t -> uintN_t, use ANSI function declarations/definitions
instead of K&R ones.


# 1.209 27-Jan-2006 cdi

branches: 1.209.2; 1.209.4;
Alter sparc64 bootstrap, catch up to ofwboot v1.9:

- Accept bootinfo structure passed down from ofwboot v1.9
- Drop kernel re-mapping code
- Use permanent 4MB mappings provided by the loader instead
- Change kernel entry address to point directly at the code instead of pointing
at the trap table's first slot. This allows the bootloader to detect
those kernels which are aware of the new boot scheme
- Due to the changes in kernel mapping code, alter secondary CPU bootstrap
code to use trampoline just like FreeBSD does (some FreeBSD code is used
here as well)


# 1.208 12-Jan-2006 cdi

Fix a typo: %g0 should be used instead of %o0 when initializing FPU in dostart:
and cpu_mp_startup:, %o0 is not even initialized at this point.


# 1.207 11-Dec-2005 christos

branches: 1.207.2;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 1.206 10-Jul-2005 christos

Re-factor syscall, and make it use syscall_{plain,fancy}.


# 1.205 31-May-2005 chs

branches: 1.205.2;
remove vestigal {,e}intr{names,cnt} symbols now that vmstat doesn't need them.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.204 12-Feb-2005 chs

branches: 1.204.4; 1.204.6; 1.204.8;
in sparc_interrupt(), wait to enable interrupts until just before calling
the handler and disable them again right after the handler returns.
we don't want another hardware interrupt coming in while we're mucking
with the list pointers. also, clear the intrhand's ih_pending pointer
before calling the handler rather than after, so that if another interrupt
comes in while the handler is running, we can put the intrhand back on
the list so it will be called again.

in send_softint(), disable interrupts via %pstate instead of %pil, so that
hardware interrupts at higher levels are blocked while we manipulate the
intrpending list. also, if the intrhand already has ih_pending set,
don't bother poking the SET_SOFTINT register again, since being on the list
implies that there is already a softint pending in the hardware.

these appear to fix PR 21750 (the "sleep forever" problem).

while I'm here, remove more vestiges of the !INTRLIST softint stuff
(code and comments). and in sparc64_ipi_flush_all(), interrupts are
already disabled so we don't need to fiddle with %pstate.


Revision tags: yamt-km-base2
# 1.203 30-Jan-2005 martin

Remove the no long usefull variants selected by undefining INTRLIST and
INTR_INTERLOCK to improve readability. Same object code generated as before.


Revision tags: yamt-km-base
# 1.202 16-Jan-2005 chs

branches: 1.202.2;
use ENTRY_NOPROFILE() for various entry points,
stack traces work better that way.


Revision tags: kent-audio1-beforemerge kent-audio1-base
# 1.201 03-Dec-2004 chs

branches: 1.201.4;
remove cache_flush_virt() and PADDRT, they're no longer used.
allocate a stack frame for blast_dcache() when profiling so it shows up.
in dcache_flush_page(), use a stride of 32 instead of 16 to match the
cache line size. correct various comments.


# 1.200 08-Nov-2004 petrov

Don't compile sparc64_ipi functions when UP.


# 1.199 25-Oct-2004 martin

No need to clear %o1 when returning a 64 bit integer from pseg_get if we
are compiling for a 64 bit kernel.


# 1.198 24-Jul-2004 nakayama

Change interrupt pending list end value to -1, to avoid linking an
interrupt handler twice.

It may fix "sleep forever" bug.


# 1.197 09-Apr-2004 petrov

Clean-up unused defines and variables.


Revision tags: netbsd-2-0-base
# 1.196 26-Mar-2004 petrov

branches: 1.196.2;
Use want_resched from cpu_info area.


# 1.195 23-Mar-2004 martin

Replace intrcnts by evcnts. XXX - needs slight tweaking for MULTIPROCESSOR.


# 1.194 14-Mar-2004 chs

checkpoint of MP work from dennis and myself. includes cross-processor
interrupt framework, a sledgehammer TLB invalidation and misc MP fixes.
doesn't work at all yet.


# 1.193 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.192 19-Jan-2004 martin

Rename switchexit to cpu_exit and g/c the old C implementation of cpu_exit.


# 1.191 18-Jan-2004 martin

Support RAS for 32bit kernels too.


# 1.190 16-Jan-2004 martin

In proc_trampoline don't bother to clear condition codes in the trap
frame, since we no longer rely on this.
While there fix a few comments.


# 1.189 08-Jan-2004 martin

Minor cleanup


# 1.188 06-Jan-2004 martin

Implement restartable atomic sequences (RAS) for sparc64.


# 1.187 06-Jan-2004 petrov

Spinup secondary cpus. Based on codes sent to me by Dennis Chernoivanov
and Chuck Silvers.


# 1.186 04-Jan-2004 jdolecek

update to recent changes - exit2() doesn't exist anymore and the
exit path always calls lwp_exit2()
pointed out Martin Husemann


# 1.185 02-Dec-2003 martin

Minor cleanup: remove unused code, sync a comment with current reality.


# 1.184 25-Nov-2003 cdi

Use per-cpu pcb, curlwp and fplwp rather than global ones. This brings
GENERIC.MP configuration to a usable state.

Approved by petrov@.


# 1.183 24-Nov-2003 cdi

Call 'proc_trampoline_mp' from 'proc_trampoline' in a multiprocessor
configuration. Fix process locking. Approved by petrov@.


# 1.182 20-Nov-2003 petrov

Remove nwindows calculation, it's not used. Set l_cpu in cpu_switch.


# 1.181 09-Nov-2003 martin

Get rid of bcopy/bzero.


# 1.180 26-Oct-2003 christos

Initial siginfo support for sparc64 (untested). COMPAT_16 sigcontext signal
delivery tested.


# 1.179 24-Aug-2003 chs

add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default. the changes
fall into two basic catagories:

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

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

originally from openbsd, adapted for netbsd by me.


# 1.178 08-Jul-2003 cdi

traceit: don't use %g7 as it is to become curcpu() register. Add comments.


# 1.177 18-May-2003 martin

branches: 1.177.2;
Make kernels with options KGDB at least compile.
Still needs some work to make it working.


# 1.176 29-Apr-2003 nakayama

Use BLOCK_ALIGN rather than BLOCK_SIZE for aligning a pointer.


# 1.175 27-Apr-2003 ragge

Preserve the symbol table in the LKM || KSYMS cases also.


# 1.174 04-Apr-2003 petrov

use branch slot in pmap_copy_page.


# 1.173 24-Mar-2003 nakayama

Divide `set' instruction in delay slot (from OpenBSD change to rev 1.30).


# 1.172 10-Feb-2003 martin

Remove some #if 0 code and a few XXX marked membars w/o proper
justification for their existence.


# 1.171 09-Feb-2003 martin

Remove left over pieces from reusing the signal trampoline for upcalls.
This should fix signal delivery for 32bit kernels.


# 1.170 05-Feb-2003 nakayama

Switch to use cycle counter (%tick) based microtime().

This is derived from alpha/microtime.c and i386/tsc_microtime.c,
and will share with both ports.

This should fix PR port-sparc64/18452.
(approved by martin)


# 1.169 04-Feb-2003 martin

Fix return value of pseg_set, which I accidently broke in rev. 1.164.

Fix register names in comment and shave off another register (hint
from uwe).


# 1.168 01-Feb-2003 martin

Rearrange register usage in pseg_set a bit and shave off %g4.


# 1.167 01-Feb-2003 martin

Remove a few #ifdef _LP64 by using STPTR/LDPTR macros.
Thanks to Matthew Green for the pointer.


# 1.166 31-Jan-2003 martin

Apply leaf procedure optimization to pseg_set (again).


# 1.165 31-Jan-2003 martin

Make the pmap count resident/wired mappings on the fly instead of
walking the page tables whenever this information is needed.

Add an option PMAP_COUNT_DEBUG to assert the new counts and the
page table walk agree.

The old solution had very bad performance impact, for example
by the high CPU load when running top(1).

Thanks to Simon Burge for pointing at the cause of the problem and
to Valeriy E. Ushakov for optimizing my simple minded assembler code.


# 1.164 27-Jan-2003 martin

Remove unused function pseg_find (which looked quite similar to
pseg_get anyway).


# 1.163 18-Jan-2003 thorpej

Merge the nathanw_sa branch.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.162 16-Jan-2003 petrov

Move dump_dtlb back under DDB.


# 1.161 15-Jan-2003 chs

fix two bugs in my last pmap rework:
- in tlb_flush_all(), don't skip TLB entries with the high bit on,
I was confused about which MMU register it was using. it's also fine
to use the last hardware context.
- in pmap_create(), don't allocate a hardware context for the new pmap.
it's unnecessary, and when this would cause us to recycle all the contexts,
it would result in the current process's context being set to 0
(ie. the kernel's context). the current process could then return to
userspace without going through the context-switch code (and thus without
having a hardware context reallocated). this would lead to user mappings
being entered in the kernel's context later, causing all sorts of trouble.
add some assertions to catch this kind of thing.


Revision tags: fvdl_fs64_base
# 1.160 25-Dec-2002 petrov

new function dump_itlb.


Revision tags: gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.159 22-Sep-2002 chs

many improvements:
- use struct vm_page_md for attaching pv entries to struct vm_page
- change pseg_set()'s return value to indicate whether the spare page
was used as an L2 or L3 PTP.
- use a pool for pv entries instead of malloc().
- put PTPs on a list attached to the pmap so we can free them
more efficiently (by just walking the list) in pmap_destroy().
- use the new pmap_remove_all() interface to avoid flushing the cache and TLB
for each pmap_remove() that's done as we are tearing down an address space.
- in pmap_enter(), handle replacing an existing mapping more efficiently
than just calling pmap_remove() on it. also, skip flushing the
TSB and TLB if there was no previous mapping, since there can't be
anything we need to flush. also, preload the TSB if we're pre-setting
the mod/ref bits.
- allocate hardware contexts like the MIPS pmap:
allocate them all sequentially without reuse, then once we run out
just invalidate all user TLB entries and flush the entire L1 dcache.
- fix pmap_extract() for the case where the va is not page-aligned and
nothing is mapped there.
- fix calculation of TSB size. it was comparing physmem (which is
in units of pages) to constants that only make sense if they are
in units of bytes.
- avoid sleeping in pmap_enter(), instead let the caller do it.
- use pmap_kenter_pa() instead of pmap_enter() where appropriate.
- remove code to handle impossible cases in various functions.
- tweak asm code to pipeline a little better.
- remove many unnecessary spls and membars.
- lots of code cleanup.
- no doubt other stuff that I've forgotten.

the result of all this is that a fork+exit microbenchmark is 34% faster
and a fork+exec+exit microbenchmark is 28% faster.


Revision tags: gehenna-devsw-base
# 1.158 18-Jul-2002 wiz

Spell 'should' correctly.


# 1.157 07-Jun-2002 eeh

Shave 10% off the time needed to flush the D$ through a bit of instruction
reordering.


# 1.156 05-Jun-2002 eeh

Handle improperly aligned stack pointers more cleanly.


# 1.155 04-Jun-2002 eeh

Fix the fork trampoline to properly use the supplied tstate.


# 1.154 31-May-2002 thorpej

Make this work with an ISO C preprocessor.


Revision tags: netbsd-1-6-base
# 1.153 14-May-2002 eeh

branches: 1.153.2; 1.153.4;
Only save locals and ins in trapframes for DEBUG kernels.


# 1.152 04-May-2002 kleink

Add some comments to the CPP conditionals controlling the trap macro
definitions, to ease navigation somewhat.


# 1.151 16-Apr-2002 eeh

Make lots of routines profile-friendly and get rid of some cruft.


Revision tags: eeh-devprop-base
# 1.150 21-Mar-2002 petrov

Not needed debug stuff deleted.


# 1.149 16-Mar-2002 mrg

tell newer binutils that our use of %g2 and %g3 is OK here.


# 1.148 15-Mar-2002 eeh

Cleanup MMU initialization to prevent hangs.


Revision tags: newlock-base ifpoll-base
# 1.147 09-Feb-2002 eeh

branches: 1.147.4;
Fix microsecond calculation in microtime.


# 1.146 07-Feb-2002 eeh

Fix register allocation in microtime().


# 1.145 29-Jan-2002 eeh

Shift the UPAID in the correct direction.


# 1.144 17-Jan-2002 eeh

Be more tolerant of unaligned stack pointers.


# 1.143 17-Jan-2002 eeh

Enable block insns in bcopy and bzero.


# 1.142 16-Jan-2002 eeh

In bcopy use 32-bit comparisons in 32-bit kernels.


# 1.141 16-Jan-2002 eeh

Use correct calculation for the trapframe in softtrap for ILP32.


# 1.140 20-Nov-2001 lukem

- pull in opt_kgdb.h where necessary
- replace opt_kgdb_machdep.h with opt_kgdb.h
- defparam opt_kgdb.h:
KGDB_DEV KGDB_DEVNAME KGDB_DEVADDR KGDB_DEVRATE KGDB_DEVMODE
- move from opt_ddbparam.h to opt_ddb.h:
DDB_FROMCONSOLE DDB_ONPANIC DDB_HISTORY_SIZE DDB_BREAK_CHAR SYMTAB_SPACE
- replace KGDBDEV with KGDB_DEV
- replace KGDBADDR with KGDB_DEVADDR
- replace KGDBMODE with KGDB_DEVMODE
- replace KGDBRATE with KGDB_DEVRATE
- use `9600' instead of `0x2580' for 9600 baud rate
- use correct quotes for options KGDB_DEVNAME="\"com\""
- use correct quotes for options KGDB_DEV="17*256+0"
- remove unnecessary dependancy on Makefile for kgdb_stub.o
- minor whitespace cleanup


Revision tags: thorpej-mips-cache-base thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf
# 1.139 14-Sep-2001 thorpej

branches: 1.139.4;
Don't declare intrhand[] here -- that's taken care of in intr.c.


Revision tags: thorpej-devvp-base
# 1.138 30-Aug-2001 eeh

branches: 1.138.2;
Preliminary UltraSPARC III suport (not enabled yet).


# 1.137 13-Aug-2001 jdolecek

g/c _remque()/_insque(); use the C version in libkern


# 1.136 09-Aug-2001 eeh

Fix context masking lossage caused by last version.


# 1.135 08-Aug-2001 eeh

Clean up the trap code to handle the changes cause by supporting non-faulting
accesses. Also change the parameter order so trap frames are easy to find.


# 1.134 07-Aug-2001 eeh

Make sure C code always has ASI_PRIMARY_NOFAULT in the %asi register so
the compiler will be happy if it ever starts generating speculative loads.


# 1.133 05-Aug-2001 eeh

Add support for non-faulting loads and optimize MMU miss handling paths.


# 1.132 02-Aug-2001 eeh

Fix bcopy.


# 1.131 02-Aug-2001 eeh

Sync bzero w/libc version.


# 1.130 01-Aug-2001 eeh

Integrate fixes from userland memset.


# 1.129 31-Jul-2001 eeh

Code cleanup and optimization.


# 1.128 23-Jul-2001 eeh

Get rid of some debug code that really isn't all that useful any more.


# 1.127 19-Jul-2001 eeh

Do ignore unregistered interrupts instead of faulting.


# 1.126 16-Jul-2001 eeh

Make bcopy a 32-bit friendly.


# 1.125 11-Jul-2001 eeh

Fix problems booting 32-bit kernels and dispatching level-15 interrupts.


# 1.124 08-Jul-2001 eeh

branches: 1.124.2;
Code cleanup. Add block_disable to let you turn on block set/copy routines.


# 1.123 05-Jul-2001 eeh

New block bzero and bcopy.


# 1.122 04-Jul-2001 eeh

Replace old bcopy with a much faster version.


# 1.121 01-Jul-2001 martin

Disable axidently enabled debug code to make -current compile again.


# 1.120 30-Jun-2001 eeh

Use a newer version (still disabled) of block bcopy.


# 1.119 30-Jun-2001 eeh

Fixup fpu save restore, get rid of some unused copy functions, and add
a new bcopy.


# 1.118 21-Jun-2001 eeh

Allow multiple 4MB pages for both kernel text and kernel data.

Note: DEBUG checks will not allow accesses to the hole between
text and data segments, so you may need to update programs that
use libkvm before relocating the start of kernel data.


# 1.117 06-Jun-2001 mrg

extract the netbsd32, sunos, 32 bit svr4 and 64 bit svr4 sigcode out into
separate files, so that compat lkms can link with them as well.


# 1.116 30-May-2001 lukem

add missing #include "opt_kgdb.h"


Revision tags: thorpej_scsipi_beforemerge
# 1.115 25-Apr-2001 simonb

Spell occurred correctly.


Revision tags: thorpej_scsipi_nbase thorpej_scsipi_base
# 1.114 09-Apr-2001 eeh

Interrupt latency fix from sparc port. (Hm. One insn instead of 5).


# 1.113 07-Mar-2001 eeh

Fix inverted preprocessor logic. (Spotted by Charles.)


# 1.112 21-Feb-2001 eeh

branches: 1.112.2;
Add support for 64-bit SVR4 (Solaris 8) binaries.


# 1.111 10-Feb-2001 pk

Fix conditional for svr4 compat inclusion.


# 1.110 05-Feb-2001 eeh

Add signal trampoline for 64-bit svr4 emulations.


# 1.109 31-Dec-2000 eeh

Make INCR() atomic.


# 1.108 29-Dec-2000 eeh

pseg_get tells us whether it really needed that spare page after all.


# 1.107 07-Dec-2000 eeh

Fixup calculating where fpstate should be saved in the signal trampoline
code so it doesn't overwrite something important like the registers.


# 1.106 09-Nov-2000 eeh

Fix ILP32 bug in probe_get().


# 1.105 22-Oct-2000 pk

Restore revision 1.102.

I hope it sticks this time..


# 1.104 20-Oct-2000 eeh

Fix hang in 32-bit kernels caused by relocation of KERNBASE.


# 1.103 04-Oct-2000 eeh

Fix interrupt lossage problem and some cosmetic changes.


# 1.102 01-Oct-2000 pk

cpu_initialize: global registers aren't preserved across calls to
prom_printf(), so replace %g3 with %l7 (which isn't used despite
the `usage' comment).

Also, clean up white-space turds.


# 1.101 29-Sep-2000 eeh

This seems to fix the interrupt lossage of non-debug kernels.


# 1.100 28-Sep-2000 eeh

Fix INTR_SETUP() to properly distinguish kernel and user addresses.

Make microtime() return the correct time on %tick machines.

Re-enable debug stuff in dostart for now to detect kernel mapping issues.


# 1.99 25-Sep-2000 pk

Missing `#if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)'


# 1.98 17-Sep-2000 eeh

Make the improved %tick changes work with machines that use the counter-timer
for the clock.


# 1.97 12-Sep-2000 eeh

Fix new version of microtime.


# 1.96 11-Sep-2000 eeh

(Hopefully) fix clock skew on machines that us %tick for the clock (UIIi).


# 1.95 31-Aug-2000 eeh

Use casx instead of stx to change entries in the page table trees.


# 1.94 23-Aug-2000 eeh

Update the scheduler to the new locking scheme.


# 1.93 10-Aug-2000 eeh

Fix signal delivery.


# 1.92 02-Aug-2000 eeh

Get kernel profiling to work. Now if only gprof worked....


# 1.91 01-Aug-2000 eeh

Overhaul cache flush code and coredump code.


# 1.90 25-Jul-2000 pk

Re-instate a couple of delay slot NOPs marked `XXX spitfire bug?'


# 1.89 24-Jul-2000 mycroft

Optimization to pmap_zero_page(): we only need to use the first 16 FP regs,
as in bzero().


# 1.88 24-Jul-2000 mycroft

Fix a whitespace glitch.


# 1.87 24-Jul-2000 mycroft

Pull in the bzero() changes from libc for real, with a couple of kernel-
specific hacks:
* Make the bias handling depend on STKB, so it switches correctly for 32-bit
kernels.
* Use the 32-bit stw/ld for 32-bit kernels.
* Add a few `-STKB's that were missed in the previous change.


# 1.86 24-Jul-2000 pk

Cosmetic & readability:
- local label cleanup in interrupt handling code;
- in debugging sections when testing `intrdebug': use a unique
local label (97) to enhanced clarity;
- comment-out unused code;
- kill a bug as the satisfying result of doing all of the above.


# 1.85 24-Jul-2000 eeh

Fix stack issues in bzero.


# 1.84 24-Jul-2000 mycroft

Revert the previous change for now. I don't have time to debug it tonight.


# 1.83 23-Jul-2000 mycroft

Copy bzero change from libc.


# 1.82 20-Jul-2000 pk

Since `intrcnt' points to an array of long ints, reserve the appropriate
amount of space depending on _LP64. Provide macros to load/store signed
and unsigned long ints.

Also, make the `intrcnt' and `intrpending' arrays 16 entries long, as on
sparc/v9 interrupt #15 is just a regular interrupt.


# 1.81 19-Jul-2000 eeh

Fix merge problem.


# 1.80 19-Jul-2000 eeh

Disable interrupt interlock using ih->ih_pending field. Seems to cause
more problems than it solves.


# 1.79 19-Jul-2000 eeh

Miscellaneous cleanup.


# 1.78 18-Jul-2000 pk

Correct args usage comment in probeget.
Whitespace cleanup.


# 1.77 18-Jul-2000 pk

probeget: 9 -> 0x9


# 1.76 18-Jul-2000 pk

If `ih_pending' is set simply return from the trap, don't schedule another
soft interrupt.


Revision tags: mrg-merge-1-5-top
# 1.75 18-Jul-2000 pk

openfirmware: don't lower %pil


# 1.74 17-Jul-2000 pk

Kill typos in interrupt code.


# 1.73 17-Jul-2000 pk

probeget: do the same song and dance as ld*a() macros in ctlreg.h do.


# 1.72 14-Jul-2000 eeh

Move some macro definitions out of genassym and into locore.s


# 1.71 08-Jul-2000 mrg

backout part of previous: turn off intrdebug, and another debug message


# 1.70 07-Jul-2000 pk

Changes for readability:
- #define LP64 dependent STACKFRAME macro once
- use a LOAD_ASCIZ macro for setting up the format string
for debug messages.


# 1.69 07-Jul-2000 eeh

Temporary fix to prevent the clock from stopping on UIIi machines.


# 1.68 03-Jul-2000 eeh

Prevent interrupts from being posted if they are active and deprecate polled
interrupts. This seems to eliminate the spurious interrupts.


# 1.67 02-Jul-2000 eeh

Clean up interrupt handling some more.


# 1.66 30-Jun-2000 eeh

Fix interrupt delivery on UltraSPARC IIi machines.


# 1.65 24-Jun-2000 eeh

With these changes the kernel seems almost stable again.


# 1.64 24-Jun-2000 eeh

More VM cleanup:

Move the cpu_info structure above the interrupt stack so it won't
get corrupted if the stack overflows.

Flush the D$ before and after all MMU bypass accesses since the
D$ latches all of those.


# 1.63 23-Jun-2000 eeh

Make probeget() and probeset() really work for a change.


Revision tags: netbsd-1-5-base
# 1.62 19-Jun-2000 eeh

branches: 1.62.2;
Have separate data and text segments, make text read-only.


# 1.61 12-Jun-2000 eeh

Start reorganizing the kernel for MULTIPROCESSOR support.


# 1.60 31-May-2000 thorpej

Add a comment about needing to initialize p_cpu when multiple
processors are supported.


Revision tags: minoura-xpg4dl-base
# 1.59 26-May-2000 thorpej

branches: 1.59.2;
First sweep at scheduler state cleanup. Collect MI scheduler
state into global and per-CPU scheduler state:

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

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

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

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

Tested on i386 and Alpha. Changes are mostly mechanical, but apologies
in advance if it doesn't compile on a particular platform.


# 1.58 26-May-2000 thorpej

Don't set `runtime' here; it's done at the end of mi_switch().
cvS: ----------------------------------------------------------------------


# 1.57 26-May-2000 thorpej

Introduce a new process state distinct from SRUN called SONPROC
which indicates that the process is actually running on a
processor. Test against SONPROC as appropriate rather than
combinations of SRUN and curproc. Update all context switch code
to properly set SONPROC when the process becomes the current
process on the CPU.


# 1.56 22-Apr-2000 eeh

If we trap due to a bad kernel stack, try to switch to the interrupt strack
before breaking into the debugger.


# 1.55 18-Apr-2000 eeh

Prevent the system from getting watchdog reset by returning directly to user
mode if restoring the user window traps. Also reduce the time we run with
%tl>0.


# 1.54 13-Apr-2000 eeh

Apparently gas 2.9.5 (don't ask) does not like to add values to %lo()
directives so move the additions inside %lo() to make it happy.
Hopefully this won't break older versions.


# 1.53 10-Apr-2000 mrg

- fix a speeling error
- rename some numbered labels to be a bit less confusing.
- remove dead code
- fix a debug error message (argh!)


# 1.52 10-Apr-2000 pk

Get a kernel without DDB to build.


# 1.51 16-Mar-2000 eeh

Revamp interrupts again:

Fix a bug causing interrmittent panics in interrupt dispatch.
Use interrupt vectors for softints.
Add a new send_softint interface.
Improved D$ flushing.
Improve traptrace and other debugging enhancements.


Revision tags: chs-ubc2-newbase
# 1.50 16-Jan-2000 eeh

Interrupt handlers return zero if they didn't handle the interrupt.


# 1.49 10-Jan-2000 eeh

Add debugger single-stepping and fix interrupt dispatch bugs.


# 1.48 30-Dec-1999 eeh

Lots of changes:

remove ffs()
add bzero that uses block store insns
save %gsr to fpstate
revert to physical accesses for pmap_zero_page so we don't
have conflicting page mappings
general cleanup.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base fvdl-softdep-base
# 1.47 06-Nov-1999 eeh

Handle zero length properly in copyinstr() copyoutstr() and copystr().


Revision tags: comdex-fall-1999-base
# 1.46 11-Oct-1999 eeh

branches: 1.46.2; 1.46.4;
Update to post 1.4.


# 1.45 05-Oct-1999 eeh

branches: 1.45.2;
Make broken versions of gas happy by using sethi/or instead of set for
(negative) addresses.


# 1.44 17-Sep-1999 thorpej

Centralize the declaration and clearing of `cold'.


Revision tags: chs-ubc2-base
# 1.43 18-Jul-1999 eeh

More fun with pmap.


# 1.42 21-Jun-1999 eeh

Improve TRAPTRACE. Add FLTRACE that only tracks MMU faults.


# 1.41 05-Jun-1999 eeh

Make pbrobeget() and probeset() work for 64-bit values as well. To do this
the arguments are changed so the address is first and the ASI second so we
can have the address in %o0:%o1 and not worry about unused registers.

Also a bit of copyright cleanup.


# 1.40 05-Jun-1999 mrg

update a commit slightly.


# 1.39 30-May-1999 eeh

Add code to support using %tick as the system clock if no "counter-timer" node
is found.


# 1.38 09-May-1999 eeh

Fixup non-DEBUG kernels.


# 1.37 29-Apr-1999 christos

Add sunos_sigcode (32 bit only)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.36 26-Mar-1999 eeh

branches: 1.36.4;
COMPAT_SPARC32 -> COMPAT_NETBSD32


# 1.35 25-Mar-1999 mrg

clean and up make compile


# 1.34 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.33 22-Mar-1999 eeh

Need to set up the pointers properly for partial FPU register stores.


# 1.32 22-Mar-1999 eeh

Flush D$ on bypass accesses.


# 1.31 28-Feb-1999 eeh

Use block load/store in pmap_zero_page()/pmap_copy_page().


# 1.30 17-Feb-1999 eeh

Let's test out vectored interrupts.


# 1.29 15-Feb-1999 hubertf

RCS ID police


# 1.28 11-Feb-1999 mrg

fix a comment pasto.


# 1.27 11-Jan-1999 eeh

Finally fixed 64-bit signal trampoline.


# 1.26 10-Jan-1999 eeh

Handle the symbol table properly in a 32-bit kernel that was booted from a
64-bit bootloader.


# 1.25 09-Jan-1999 eeh

More signal fixup.


Revision tags: kenh-if-detach-base
# 1.24 26-Nov-1998 mycroft

Sync kcopy() with 32-bit SPARC version.


# 1.23 16-Nov-1998 eeh

Fixup the last broken bits of the signal handling code.


Revision tags: chs-ubc-base
# 1.22 08-Oct-1998 eeh

Fix more syscall32 and signal breakage.


# 1.21 22-Sep-1998 eeh

More fixup in the signal area.

64-bit syscall cleanup.

Add emulation for some new FPU insns: conversion to 64-bit long int and
conditional moves.


# 1.20 17-Sep-1998 thorpej

SYS_sigreturn -> SYS___sigreturn14.


# 1.19 13-Sep-1998 eeh

Fixup signal changes (hopefully). However SUN_COMPAT is likely broken by
this and I don't know how to fix it.

We can now exec a 64-bit init through a really ugly hack (don't ask.)


# 1.18 11-Sep-1998 eeh

Add labels for the compat_sparc32 signal trampoline and break -- er -- fix
suword and fuword.


# 1.17 09-Sep-1998 eeh

Don't use %tick for microtime on 32-bit kernels -- breaks gettimeofday.


# 1.16 09-Sep-1998 thorpej

Adjust for the new "reaper" kernel thread: do not free the vmspace and
u-area in machine-dependent code. Instead, call exit2() to schedule
the reaper to free them for us, once it is safe to do so (i.e. we are
no longer running on the dead proc's vmspace and stack).


# 1.15 07-Sep-1998 eeh

Fix data corruption problem caused by broken debug code.


# 1.14 07-Sep-1998 eeh

Add new 64-bit trap vectors.


# 1.13 06-Sep-1998 eeh

32-bit fixup.


# 1.12 06-Sep-1998 eeh

Disable some debug stuff.


# 1.11 05-Sep-1998 eeh

It slices. It dices. It does everything except exec a sparc32_compat init.


# 1.10 02-Sep-1998 eeh

Periodic update: now starts probing devices.


# 1.9 30-Aug-1998 eeh

Some more 64-bit cleanup. Now everything compiles.


# 1.8 29-Aug-1998 eeh

Some more 64-bit-ification.


# 1.7 27-Aug-1998 eeh

Add 64-bit pmap support:

Moved from a two level 512/1024 entry setup mapping 32 (9/10/13) bits
respectively to a three level 1024/1024/1024 entry setup mapping 43
(10/10/10/13) bits. In 32-bit mode we waste about 1/12 pages mapping the high
11 bits. We also only manage 43 of the possible 44 bits of virtual address
space, wasting half of it. Oh well, maybe we'll do better next revision.


Revision tags: PMAP32
# 1.6 26-Aug-1998 mrg

panicstack: is needed outside of DEBUG. use _C_LABEL, and printf not db_printf (incase no ddb!)


# 1.5 13-Aug-1998 eeh

Merge paddr_t changes into the main branch.


Revision tags: eeh-paddr_t-base
# 1.4 07-Jul-1998 eeh

branches: 1.4.2;
General update:

Added genassym.cf
Removed lderr which should never have gotten in
Removed lots of dead code from locore.s
Added some softint stuff to intr.c
Added support for halt -p
esp and le both use bus_dmamap_*() functions now
instead of kdvma_mapin()
groundwork for PCI (but we still have no drivers for
any sun4u PCI devices)


# 1.3 04-Jul-1998 jonathan

defopt DDB.


# 1.2 26-Jun-1998 thorpej

defopt COMPAT_SVR4


# 1.1 20-Jun-1998 eeh

branches: 1.1.1;
Initial revision


# 1.430 27-Jun-2022 andvar

fix various typos in comments.


# 1.429 22-May-2022 andvar

fix various small typos, mainly in comments.


# 1.428 16-May-2022 mrg

try to handle ultrasparc III* "fast ecc error" traps.

i had a sunblade 2500 reset with this trap recently, and the
manual says it should have been recoverable. in particular,
the US IIIv2 manual says in section 12.4.4.2 that the i-cache
won't see this data ever (so nothing needed there), and that
the d-cache needs to be disabled, and all the entries flushed,
and then re-enabled.

tested with a "trap 0x70" from kernel space, that trap.c
converted the "0x170" back to "0x70" (with an ADVANCE). this
code not commited.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 1.427 03-Apr-2021 palle

Improve cpu_idle() by allowing a platform specific implementaion (same logic as the sparc implementation) - currently only used by sun4v


# 1.426 30-Mar-2021 palle

sun4v: handle spill trap properly when trap level is 1 and otherwin is non-zero - ensure that all windows are spilled to the pcb like the sun4u winfixsave code path


# 1.425 22-Feb-2021 palle

branches: 1.425.2;
sun4v: handle spill normal user traps properly when current trap level is 1 - registers are spilled to the PA of the stack to avoid further mmu-related traps, since sun4v only has 2 trap levels


# 1.424 20-Dec-2020 palle

sun4v: add comment in sun4v_tl1_ptbl_miss code path - no functional change


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1
# 1.423 08-Jan-2020 skrll

branches: 1.423.6;
oldlwp is always non-NULL in cpu_switchto so remove the test for NULL.


# 1.422 08-Jan-2020 ad

Hopefully fix some problems seen with MP support on non-x86, in particular
where curcpu() is defined as curlwp->l_cpu:

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

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

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

- Remove some KERNEL_LOCK handling which hasn't been needed for years.


Revision tags: netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 ad-namecache-base netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.421 18-Jul-2019 palle

branches: 1.421.4;
sun4v: added some missing comments to the code in pcbspill


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 1.420 07-Apr-2019 mrg

make trap 0x70 a TRAP() not UTRAP(). we should be able to handle
fast ECC error as a normal trap, and i saw this once a few years
ago but it never repeated so i haven't been able to test this.


# 1.419 08-Feb-2019 palle

sun4v: Improve comment for next_stick_init() - no functional changes


# 1.418 08-Feb-2019 palle

sun4v: initialize %stickcmpr properly when establishing interrupt - fixes issue seen on newer sun4v/SPARC-T5 system where the interrupt never fires.


# 1.417 08-Feb-2019 palle

sun4v: introduce macros for handling spill traps from userlevevel @ traplevel 1 (from OpenBSD) - spill traps at level 1 from userspace now works better


# 1.416 08-Feb-2019 palle

sun4v: add comment documenting the contents of the %g2 register - no functional changes


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126
# 1.415 04-Nov-2018 palle

Ensure that the 64-bit condition codes are used instead of the 32-bit condition codes. ok martin@


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.414 26-May-2018 palle

branches: 1.414.2;
next_stick() - fix typy in comment: tick->stick


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.413 11-Apr-2018 palle

sun4v: handle MMU-related traps properly when they occur at trap level 1. This fixes issues when user-level LWPs access the user-level stack


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 1.412 26-Aug-2017 palle

branches: 1.412.2;
sun4v: Avoid touching the %tick_cmpr register which is not present on never systems (Oracle SPARC Architecture 2011 and beyond). Based on code from OpenBSD locore.s revision 1.177. Tested on both sun4u (qemu and USIII) and sun4v (qemu and T5-2). ok martin@


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2
# 1.411 06-May-2017 palle

sun4v: The %ver register is not available on sun4v - use GET_MAXCWP introduced in rev. 1.361. Verified using qemu (sun4u and sun4v) and on real sun4v hw (t2000)


Revision tags: prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.410 18-Apr-2017 palle

branches: 1.410.2;
sun4v: Add handling of trap 0x06c @ trap level 1 - based on code from OpenBSD, but slightly adapted to NetBSD. verified using qemu


Revision tags: jdolecek-ncq-base pgoyette-localcount-20170320
# 1.409 19-Feb-2017 palle

sun4v: rft_user needs special handling (a manual fill) since the restore instruction may cause the number of trap levels to exceed the maximum for sun4v - inspired by code from the the openbsd rft_user code path - verified using qemu for both sun4u and sun4v


# 1.408 10-Feb-2017 palle

sun4v: Added handling of trap type 0x034 (address alignment error) + fixed typo mmfsa -> mmufsa. Verified for both sun4u and sun4v using qemu.


Revision tags: nick-nhusb-base-20170204
# 1.407 30-Jan-2017 palle

sun4v: Hook up syscall handling to the trap table. Verified using qemu for both sun4u and sun4v.


# 1.406 27-Jan-2017 palle

sun4v: implement missing handling of itsb traps 0x008 and 0x009. Based on code from OpenBSD. Tested using qemu.


Revision tags: bouyer-socketcan-base
# 1.405 07-Jan-2017 palle

branches: 1.405.2;
sun4v: slowtrap() now selects normal globals properly on both sun4u and sun4v platforms. Verified using qemu for both sun4u and sun4v systems


Revision tags: pgoyette-localcount-20170107
# 1.404 05-Jan-2017 palle

sun4v: TRAP_SETUP() updated to set mmu context id properly for both sun4v and sun4u platforms. Verified using qemu for both sun4u and sun4v systems


# 1.403 04-Jan-2017 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x00-0x23 and 0x28-0x30


# 1.402 29-Dec-2016 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x32-0x7f


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.401 20-Sep-2016 nakayama

Fix RAS for 32-bit kernels. trapframe is always 64-bit.


Revision tags: localcount-20160914
# 1.400 23-Aug-2016 palle

sun4v: rework sun4v_datatrap so it works properly when running on a T2-based system like T5120 - for some reason %tl is 0 when entering sun4v_datatrap causing a crash (sir instruction), so ignore the %tl value for now upon entry to sun4v_datatrap - with this fix both T1 and T2 based systems reach the same point - hangs in rft_user after the init process is started


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726
# 1.399 18-Jul-2016 palle

sun4v: handle device interrupts properly - both legacy (sysino) and cookies


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 1.398 04-Jun-2016 palle

branches: 1.398.2;
sun4v: rtf_user now uses macros GET_MMU_CONTEXTID and SET_MMU_CONTEXTID. Tested on sun4u (QEMU) and sun4v (T2000). Parts from OpenBSD.


Revision tags: nick-nhusb-base-20160529
# 1.397 18-May-2016 nakayama

Decrement %tl in trap handler not to make it zero unconditionally
for the nested trap, and remove useless mov.


# 1.396 17-May-2016 palle

sun4v: Implement missng MMU protection trap handling - mostly from OpenBSD


# 1.395 16-May-2016 palle

Avoid assembler-specific defines by using the export keyword in genassym.cf instead


# 1.394 15-May-2016 nakayama

%g1 is not preserved across function call, so load it before
return_from_trap.


# 1.393 13-May-2016 palle

sun4v: add missing implementation of sun4v_datatrap_tl0 so data_access_fault() is called - mostly from OpenBSD


# 1.392 13-May-2016 nakayama

- ci_paddr is always 64-bit.
- intrlev is array of pointer.
- ih_ack is pointer.


# 1.391 10-May-2016 palle

sun4v: make device interrupts work. Introduce a new intrhand_alloc() function for allocation of interrupt handlers and adapt to this. Parts from OpenBSD. ok martin@


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.390 09-Mar-2016 nakayama

32-bit kernels use 32-bit stack.


# 1.389 03-Mar-2016 palle

sun4v: rft_kernel should pay attention to the number of register windows that can be restored. We cannot rely on fill traps to occur, since sun4v only has two trap levels available in privileged mode. Based on code from OpenBSD. ok martin@


# 1.388 14-Feb-2016 palle

sun4v: add breakpoint trap entry to the sun4v trap table


# 1.387 03-Feb-2016 palle

sun4v: extend dmmu_set_secondary_context() to handle both sun4u and sun4v. ok martin@


Revision tags: nick-nhusb-base-20151226
# 1.386 06-Nov-2015 martin

Basically revert r1.246 of locore.s and r1.73 of vm_machdep.c:

Remove special case handling for userland lwps from cpu_lwp_fork,
instead do it in lwp_trampoline when we first return to userland.

which was a stupid idea - since we did now set all fork child's %tstate
(and thus %pstate when back in userland) to the current kernel's userland
default. This meant we lost the address mask bit for 32bit processes and
all memory model details for 64bit ones.

Move it back to cpu_lwp_fork and fix the condition to only do it once when
forking init.


# 1.385 05-Nov-2015 martin

Most of the time return_from_trap already got called with tf->tf_tstate
loaded in register %g1 - make it so for two more callers and remove
the reload of that value.


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606 nick-nhusb-base-20150406
# 1.384 05-Apr-2015 palle

sun4v: Ensure that the TTEs CP and CV bits are the same (both set) for the primary cpu and secondary cpus INTSTACK mappings


# 1.383 01-Apr-2015 palle

sun4v: Implement handling of cpu_mondo trap - from OpenBSD - tested using the Legion simulator


# 1.382 04-Mar-2015 palle

sun4v: revert some of the logic introduced in revision 1.378 - flushw is not necessary on sun4v (OpenBSD patches the flushw instruction to a nop instruction) - with these changes the kernel reaches cpu_boot_secondary_processors() when running in the Legion simulator (crashes due to missing handling of cpu_mondo_trap)


# 1.381 02-Mar-2015 nakayama

prom_printf converts "\n" to "\r\n" internally, so omit "\r".


# 1.380 02-Mar-2015 nakayama

PANICSTACK is a pointer itself, not a pointer to pointer.


# 1.379 02-Mar-2015 nakayama

Use panic stack temporarily for calling prom_printf in a trap
handler.

It seems that openfirmware cannot handle over 4GB pointers, and
stack pointers may point to over 4GB since VA layout was rearranged
by rev 1.33 of vmparam.h. Therefore, use panic stack to avoid
panicking in OF_write used by prom_printf.


# 1.378 23-Feb-2015 palle

sun4v: sparc_interupt - ensure that the trap level and globals level are the same when the flushw instruction is issued - othwise warnings occur when using the sun4v Legion simulator.


Revision tags: nick-nhusb-base
# 1.377 26-Oct-2014 palle

branches: 1.377.2;
sun4v: Create CLEANWIN0 and CLEANWIN1 macros for handling clean window traps on both sun4u and sun4u (based on the original code inlined in the sun4u trap table). Update trap tables accordingly for both sun4u and sun4v. Ok martin@


# 1.376 24-Oct-2014 nakayama

Fix typo in comment.


# 1.375 18-Oct-2014 snj

src is too big these days to tolerate superfluous apostrophes. It's
"its", people!


# 1.374 15-Oct-2014 palle

sun4v: fixed bug causing the real address to be incorrectly calculated as zero


# 1.373 24-Sep-2014 palle

sun4v: add code to enable startup of secondary cpus on both sun4u and sun4v systems - ok martin@


# 1.372 04-Sep-2014 palle

sun4v: All cpus must be setup with a TSB descriptor, so pmap_setup_tsb_sun4v() must take a pointer to the TSB descriptor


# 1.371 31-Aug-2014 palle

sun4v: Split the NORMAL_GLOBALS and ALTERNATE_GLOBALS macros to _SUN4U and _SUN4V variants. Rework the return_from_trap logic to use the new variants so it is possible to use a global register as scratch register.


# 1.370 14-Aug-2014 nakayama

Add missing delay slot in DEBUG kernel.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.369 30-Jul-2014 palle

branches: 1.369.2;
Fix ALTERNATE_GLOBALS so it at least works on sun4u - using a scratch register is not a good idea...


# 1.368 27-Jul-2014 palle

sun4v: Introduce a new macro ALTERNATE_GLOBALS (matching NORMAL_GLOBALS). Two new helper macros ENABLE_INTERRUPTS and DISABLE_INTERRUPTS are also created. With these changes the GENERIC.UP kernel will reach rootmount on sun4v systems - ok martin@


# 1.367 26-Jul-2014 palle

Improved the NORMAL_GLOBALS macro in the sun4u case, so only the relevant bit (AG) in %pstate is affected - ok martin@


# 1.366 24-Jul-2014 palle

sun4v: add missing spill/fill handling for trap level 1 + cosmetic changes to comments for trap level 0 entries


# 1.365 19-Jul-2014 palle

sun4v: Introduce a NORMAL_GLOBALS macro - first used in sparc_interrupt - other relevant uses will be handled as the sun4v work is progressesing - ok martin@


# 1.364 16-Jul-2014 palle

sun4v: Introduce SET_MMU_CONTEXTID macro for setting the mmu context id on both sun4u and sun4v


# 1.363 13-Jul-2014 palle

sun4v: add interrupt handling to sun4v trap table


# 1.362 13-Jul-2014 palle

Bugfix: add missing cmp instruction to GET_MAXCWP macro


# 1.361 30-Jun-2014 palle

sun4v: The maximum number of register windows is a constant and thus not available via the %ver register (sun4u only). Introduce a macro GET_MAXCWP that handles this, so cpu_switchto() works properly on sun4v. Other relevant reference to %ver can be adapted to use GET_MAXCWP as the sun4v port progresses. OK martin@


# 1.360 31-May-2014 palle

sun4v: added missing dtsb miss handling for trap level 1 - with this update the kernel now reaches configure() on sun4v systems


# 1.359 30-May-2014 palle

Remove debugging code introduced by accident in locore.s revision 1.357


Revision tags: yamt-pagecache-base9 rmind-smpnet-nbase rmind-smpnet-base
# 1.358 05-May-2014 palle

sun4v: the trap base address should be assigned to %l1 so %tba is properly setup later in the code - now the kernel gets as far as printing the copyright disclaimer, kernel version and total and available memory before crashing


# 1.357 21-Apr-2014 palle

sun4v: Update comment: modified -> access


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.356 21-Feb-2014 palle

branches: 1.356.2;
sun4v: Rename TLB_ defines to SUN4U_TLB_ so entries created using TSB_DATA() are properly setup for sun4u and sun4v. Relocate the cputyp variable from autoconf.c to locore.s and make it const in param.h so optimized code can be generated. Parts from OpenBSD. Optimization suggested by nakayama@. OK martin@, mrg@, nakayama@


# 1.355 31-Jan-2014 tsutsui

defined(LKM) -> defined(MODULAR)


# 1.354 26-Jan-2014 palle

sun4v: Add handling of spill/fill and dtsb miss traps (with a XXX to be handled later)


# 1.353 07-Jan-2014 palle

sun4v: trap table setup - currently populated with dummy entries which will be properly implemented later - parts from OpenBSD - OK martin@


# 1.352 29-Dec-2013 nakayama

Make buildable w/o options SUN4V.


# 1.351 27-Dec-2013 palle

a) make the hunt through the cpus list more generic b) sun4v: ensure that the interrupt stack is mapped permanently and the TSB is setup properly - parts from OpenBSD. OK martin@


# 1.350 06-Dec-2013 nakayama

Increase an interrupt depth only in the case of hardware interrupts,
and remove the ci_idepth trick in softint_fastintr.

Fixes the following diagnostic panic reported in port-sparc64.

panic: kernel diagnostic assertion "!cpu_intr_p()" failed: file
"../../../../kern/subr_xcall.c", line 351


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 1.349 24-May-2013 nakayama

branches: 1.349.2;
Disable interrupts after calling data_access_error as with
data_access_fault.


# 1.348 28-Apr-2013 nakayama

Use macros in machine/asm.h instead of locally defined, and
introduce CASPTRA for casxa/casa.


Revision tags: agc-symver-base
# 1.347 23-Jan-2013 martin

Fix sparc64_ipi_ccall by adding proper trap setup.
Fixes xcall(9) problems, as exposed by pserialize(9). Noticed by
J. Hannken-Illjes, cause pointed out by Takeshi Nakayama.


# 1.346 23-Jan-2013 martin

Sligthly clean up the (by default unused) #ifdef TRAPS_USE_IG


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.345 10-Nov-2012 nakayama

Revise comment.


# 1.344 10-Nov-2012 nakayama

Use macro instead of magic number.


# 1.343 09-Nov-2012 nakayama

Make setstick() and getstick() to inline functions.


# 1.342 08-Nov-2012 macallan

use system tick timer instead of %tick on UltraSPARC-III-ish CPUs
review & fixes by Takeshi Nakayama


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.341 17-Mar-2012 mrg

branches: 1.341.2;
port the corrected ECC error handling code from freebsd. i noticed my U10
took one of these and then hang. it shouldn't hang, there's a 'sir' here that
doesn't seem to reset properly. oh well.

tested by simulated a trap via 'ta 0x10' and considering that the same, but
it hasn't been tested against a real ECC error yet.


Revision tags: jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base4
# 1.340 03-Mar-2012 nakayama

Fix the root cause of the hack "disable optimizations for uvm_bio.c
on 32 bit kernels".

gcc converts a division in the calculation of UBC_UMAP_ADDR macro
to multiplication (smul or combination of add/sll), and the
register of its result contains a garbage in upper 32 bits (the
upper 32 bits of smul/add/sll's result isn't zero cleared).

Then it passes to pseg_get{,_real} through pmap_extract without the
zero clear of upper 32 bits in the optimization case. So the
result of pseg_get and pmap_extact sometimes gets screwed up.


Revision tags: jmcneill-usbmp-base5 jmcneill-usbmp-base3
# 1.339 19-Feb-2012 rmind

Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.


Revision tags: jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.338 04-Sep-2011 nakayama

branches: 1.338.2; 1.338.6; 1.338.8;
ih_pil is an interrupt level, not an interrupt mask.


# 1.337 27-Jul-2011 nakayama

ivec is assigned to hardware, so count its event counter up in
interrupt_vector, not in softint, and do some optimization.


# 1.336 20-Jul-2011 macallan

add per ivec event counters


# 1.335 12-Jul-2011 mrg

rename sparc64 BLOCK_SIZE and BLOCK_ALIGN to have SPARC64_ prefixes.
for the assembler files, define the old names to the new names
since using the new names cause ugliness due to longer identifer
names, and reduces churn.

fixes build issues in dtv and vaguely makes <machine/psl.h> slightly
less name-space invasive.


# 1.334 18-Jun-2011 nakayama

Add fast softint(9) support for sparc64.

Reviewed on port-sparc64.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 1.333 12-May-2011 mrg

branches: 1.333.2;
first steps towards fujitsu SPARC64 support:

- SPARC64 systems have interrupts with upto 14 bits set, but we only look
at the first 11 bits. trim non IPI interrupts to 11 bits


Revision tags: uebayasi-xip-base7 bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 jym-xensuspend-nbase jym-xensuspend-base
# 1.332 20-Dec-2010 matt

branches: 1.332.2;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.


Revision tags: uebayasi-xip-base6 uebayasi-xip-base5 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 1.331 10-Jul-2010 nakayama

Clear the upper word explicitly before combining two 32-bit values to 64-bit
on 32-bit kernels.


# 1.330 23-May-2010 martin

Split copy related functions out of locore.s into copy.S, move functions
only needed on multiprocessors into mp_subr.S.


# 1.329 17-May-2010 martin

Simplify primary CPU startup slightly by using the fact that our cpuinfo's
curpcb pointer points to the uarea/pcb of lwp0 and by remembering the pointer
to this cpuinfo, thus avoiding a few CPUINFO_VA references.


Revision tags: uebayasi-xip-base1
# 1.328 20-Mar-2010 chs

fix copy{in,out}{,str}() to return the error returned by uvm_fault().
fixes PR 41813.


Revision tags: yamt-nfs-mp-base9
# 1.327 10-Mar-2010 mrg

branches: 1.327.2;
XXX: workaround we'd like to remove when pmap / uvm locking is cleaned up:

- rename pseg_get() and pseg_set() to pseg_get_real() and pseg_set_real().
- if USE_LOCKSAFE_PSEG_GETSET is defined, which it current is by default,
define pseg_[gs]et() in terms of functions that take a new pseg_lock
mutex at IPL_VM while calling into the real functions.

this seems to avoid the pseg_set() crashes we've seen:
1 - spare needed, when pseg_get() just worked for this pmap
2 - the 2rd ldxa via ASI_PHYS_CACHED in pseg_set() loads garbage
into %o4, and causes the 3rd ldxa to fault


# 1.326 08-Mar-2010 mrg

blast_dcache() SMP friendly:

- blast_dcache() becomes sp_blast_dcache(dcache_size, dcache_line_size)
- new smp_blast_dcache(sparc64_cpuset_t) that blasts the D$ on this cpuset
- sparc64_ipi_blast_dcache() to support the above
- in pmap_remove_all(), when freeing mmu contexts for this pmap, mark
the set of cpus to blast the d$ on as well and convert the
blast_dcache() call into smp_blast_dcache() on the cpus who ran this
pmap, or, sp_blast_dcache(dcache_size, dcache_line_size)
- convert the remaining blast_dcache() in machdep.c to sp_blast_dcache()
- in pmap_destroy()/pmap_remove_all() take the pmap_lock() always since
we assert it is held always.

with these changes, NFS builds on the U60 seem to be stable now, and
the USIII machines also can often complete a single build.sh run now,
diskful or diskless.


reviewed by mlelstv and partially by martin, tested by martin and myself,
with some ideas from chuq as well.


# 1.325 07-Mar-2010 mrg

need _ALIGN in locore.h as well, for DEBUG kernels.


# 1.324 07-Mar-2010 mrg

gas has supported SPARC ".empty" for a long while; get rid of an
ancient workaround.


# 1.323 06-Mar-2010 mrg

move the memcpy/memset implementations out into their own file, with the
block copy versions as well. move some of the definitions in locore.s
into a new locore.h.

locore.s is almost 2000 lines shorter with this change.


# 1.322 04-Mar-2010 mrg

- in _bus_dmamap_unload(), pmap_page_protect() and pmap_clear_reference()
switch the dcache_flush_page() into a dcache_flush_page_all()
- in both pmap_kremove()/pmap_remove(), remove the blast_dcache() call
and replace it with dcache_flush_page_all()
- in pmap_get_page() [used to allocate PTP's], always call pmap_zero_page(pa)
- flush the dcache of the dst page in pmap_{copy,zero}_page() by redirecting
throught a C function that calls the (renamed) asm. the old asm code had a
comment about needing to do this...
- add a couple of membar #Sync's that the USIII manual recommends


based on discussions with chuq@, skrll@ and martin@.


these help my SB2000 / SB2500 with both disk / nfs builds and other tasks,
sometimes lasting for several hours before failing or asserting.


# 1.321 24-Feb-2010 mrg

when handing back page table pages to UVM, flush them from the dcache
on all CPUs.

idea from skrll@, and makes my disk-based SB2000 stable.

tested on U60, SB2000 and SB2500.


# 1.320 24-Feb-2010 mrg

- re-introduce sp_tlb_flush_pte() and sp_tlb_flush_all() that call
the right USI/USIII version.
- define tlb_flush_pte() in terms of sp_tlb_flush_pte() for the
!MULTIPROCESSOR case

this centralises some CPU_IS_USIII_UP() tests.


# 1.319 22-Feb-2010 mrg

move {dump,print}_[id]tlb() into a separate file.


# 1.318 22-Feb-2010 mrg

- store the maximum [id]cache size / line size for each cpu

- remove patch_kernel() since it isn't necessary and has been patching
the wrong thing in general.

- implement USIII versions of blast_icache(), dcache_flush_page() and
cache_flush_phys(). use the newly recorded cache size/line sizes.

- in winfixsave, flush the D$ with the right size index and ops. this
kills one of the wrong tag->inval patches.

- for blast_dcache(), use the newly recorded dcache_size/line_size.

- for blast_icache(), use the newly recorded cache size/line sizes.
for the USIII verison, disable the I$ while writing to ASI_ICACHE_TAG.


these changes removed several hard coded cache sizes values, some very
wrong kernel patching, and seem to make the current failure modes for
USIII less common, but not gone.


# 1.317 15-Feb-2010 mrg

- don't flush 32-bit entries for 64-bit code, it does not seem to be
necessary. #define TLB_FLUSH_LOWVA to turn it back on.
- remove the #if 0'd code in sparc64_ipi_flush_pte_usiii(), i have
verified that it is not required.
- add a missing membar #Sync to sp_tlb_flush_pte_usiii().


# 1.316 15-Feb-2010 nakayama

Fix linker error of GENERIC32 kernel.


# 1.315 15-Feb-2010 mrg

use TLB_SIZE_SPITFIRE in a couple of places, and note that the
{print,dump}_[id]tlb() versions are currently spitfire specific.


# 1.314 15-Feb-2010 mrg

introduce a new patch_kernel() and call it from the end of bootstrap().
use it to patch up TLB flush instructions that don't match for USI/II
and later. we can also hopefully use this to make GENERIC.MP minimally
expensive on single CPU machines as well.

this is the last piece needed to get GENERIC/GENERIC.MP to boot on the
USIII* machines.

idea and some initial code from openbsd.


# 1.313 13-Feb-2010 mrg

remove KTR support. it's never been a working part of netbsd src tree.


# 1.312 09-Feb-2010 wiz

Fix typo in comment.


Revision tags: uebayasi-xip-base
# 1.311 06-Feb-2010 mrg

branches: 1.311.2;
- properly map the schizo interrupt registers, so we can use the normal
virtual mappings to access them.
- with the above fxied, kill SCHIZO_BUS_SPACE_BROKEN, and introduce
an options CHEETAH for now, that disables the SPITFIRE code in locore.
- merge schizo_init() into schizo_attach() and clean up the softc a bit.


with this we are only one more step away from GENERIC booting on USIII
machines.


# 1.310 02-Feb-2010 mrg

- split sp_tlb_flush_pte() and switchtoctx() into sp_tlb_flush_pte_us()/
sp_tlb_flush_pte_usiii() and switchtoctx_us()/switchtoctx_usiii() and
implement the latter while i'm here. it works ... sometimes i think,
but also sometimes panics/hangs.
- fix a comment in sparc64_ipi_flush_pte_usiii()


# 1.309 02-Feb-2010 mrg

for now, reduce a few #ifdef SPITFIRE cases by introducing a new
ASI_DCACHE_TAG_OR_INV that is either ASI_DCACHE_{TAG,_INVALIDATE}.

increase the common code in cache_flush_phys().


# 1.308 01-Feb-2010 mrg

- sp_tlb_flush_all() becomes sp_tlb_flush_all_us() and sp_tlb_flush_all_usiii()
- sparc64_ipi_flush_pte() becomes sparc64_ipi_flush_pte_us() and
sparc64_ipi_flush_pte_usiii()
- add some commented out code to disable interrupts and raise the traplevel
in sparc64_ipi_flush_pte_usiii()
- cache_flush_phys() was missing a little of code in the cheetah case


# 1.307 01-Feb-2010 mrg

for USIII, use the new "tlb demap all" operation in sp_tlb_flush_all()


# 1.306 01-Feb-2010 mrg

remove unused icache_flush_page() implementation.


# 1.305 23-Jan-2010 mrg

remove the final uses of DATA_START.

now we can remove the 16KB space reserved at the start of the data segment,
and i now understand why i wrote this now removed comment 3.5 years ago:
"this shouldn't be needed... but kernel usually hangs without it"


# 1.304 23-Jan-2010 mrg

remove most of the code that writes debugging info DATA_START + offset.


# 1.303 23-Jan-2010 mrg

remove CHKPT() macro and uses. it's likely wrong in SMP land and probably should
be replaced with KTR-style uses if necessary.


# 1.302 23-Jan-2010 mrg

fix a comment.


Revision tags: matt-premerge-20091211
# 1.301 10-Dec-2009 rmind

Rename L_ADDR to L_PCB and amend some comments accordingly.


# 1.300 05-Dec-2009 mrg

- adjust the PA mask to the 43 bits supported by USIII.
- rework the spitfire/cheetah cache_flush_phys() to avoid several #ifdefs
- add a membar #Sync after sparc64_ipi_drop_fpstate (probably unnecessary)


# 1.299 30-Nov-2009 nakayama

sp_tlb_flush_pte for cheetah:
- restore interrupts properly in case of %tl > 0.


# 1.298 30-Nov-2009 mrg

stablize UP USIII support by blocking interrupts around sp_tlb_flush_pte()
i was seeing stack corruption while taking an interrupt in this function.

get USIII SMP mostly working by implementing the cheetah version of
sparc64_ipi_flush_pte().


SMP support is still not entirely stable. i can reproducably get a:

panic: fpusave_lwp ipi didn't

while running build.sh, when an awk process is exiting. other simple
heavy work loads do not crash for me right now.


# 1.297 30-Nov-2009 mrg

delete some no longer used code:
- smp_tlb_flush_ctx()
- smp_tlb_flush_all()
- sparc64_ipi_flush_ctx()
- sparc64_ipi_flush_all()
- sp_tlb_flush_ctx()


# 1.296 29-Nov-2009 nakayama

- calculate end PA correctly.
- wrap more spitfire specific (flushing I$) code.
- fix inverted #if condition for flushing I$ (and restore ASI_ICACHE_TAG).


# 1.295 28-Nov-2009 mrg

implement enough code to get SB2000/SB2500 booting to multiuser. does
not last long if you use it, but an idle machine has stayed up 10 hours.

- for the !SPITFIRE case, use ASI_DCACHE_INVALIDATE instead of
ASI_DCACHE_TAG when clearing tlb entries. from openbsd.

- convert some comment "! Not yet" into "WRITEME", so that attempting
to build a USIII MULTIPROCESSOR kernel fails to build until the code
is written.

- add some more WRITEME's for the above.

- implement a !SPITFIRE version of sp_tlb_flush_all(). since there are
no spare regs, for now just always increase %tl around this call. (we
could maybe store a token in %o3 along with the saved %pstate info.)


# 1.294 26-Nov-2009 matt

Kill proc0paddr. Use lwp0.l_addr instead.


# 1.293 25-Nov-2009 mrg

s/L_ADDR/L_PCB/, requested by rmind.


# 1.292 17-Oct-2009 nakayama

Wrap unused code with #if 0 which is called from #if 0'ed code.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5
# 1.291 30-May-2009 martin

cpu_setfunc() can not use lwp_trampoline, as that has additional lwp startup
semantics. Use a simpler setfunc_trampoline instead.


# 1.290 18-May-2009 nakayama

Remove random() from locore.s since it is in libkern.


# 1.289 16-May-2009 nakayama

Remove clear %tick in locore.s since it is cleared at cpu_initclocks() in
clock.c.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 nick-hppapmap-base mjf-devfs2-base
# 1.288 15-Dec-2008 mrg

restore some old "intrdebug" code, but leave it under NOT_DEBUG. most
of it works, but one that prints func/arg for each handler is not very
stable...

for now, while schizo bus space pointer accesses aren't working, add
a SCHIZO_BUS_SPACE_BROKEN option so you can build a kernel with schizo.

with this, and the prior schizo interrupt fix, you can now fail to run
/sbin/init!


Revision tags: haad-dm-base2 haad-nbase2 haad-dm-base
# 1.287 09-Dec-2008 martin

Get rid of get_maxctx() - it doesn't work on newer cpus and we will have
to find a better way for (some) sun4v machines - all sun4u use 13 bit
contexts anyway.


Revision tags: netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 ad-audiomp2-base netbsd-5-base
# 1.286 30-Oct-2008 nakayama

branches: 1.286.2; 1.286.6;
Wrap more code specific to USE_BLOCK_STORE_LOAD.


Revision tags: matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4
# 1.285 05-Oct-2008 nakayama

branches: 1.285.2;
- in flushing cache, use 32 as increment/decrement value to match the
cache line size.
- remove useless restore of %asi.
- remove nop in delay slot if we can.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 1.284 10-Jul-2008 nakayama

Use proper CCR.


# 1.283 10-Jul-2008 nakayama

sparc64_ipi_save_fpstate:
- use primary MMU context for consistency with other trap/interrupt handlers.

sparc64_ipi_save_fpstate, savefpstate:
- avoid storing fp registers as we can.

sparc64_ipi_save_fpstate, savefpstate, loadfpstate:
- remove unaligned case since buffers allocated with pool_cache are ensured
64-byte aligned.

Ok by martin@.


# 1.282 02-Jul-2008 nakayama

branches: 1.282.2;
UltraSPARCs don't have floating point queue, and reading %fq regsiter
will cause illegal instruction trap. So remove the code handling them.


# 1.281 29-Jun-2008 nakayama

Wrap IPI calls with #ifdef MULTIPROCESSOR.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.280 14-Jun-2008 nakayama

Close unterminated comment.
Fix unexpected behavior in case of loadfpstate from unaligned buffer.


Revision tags: yamt-pf42-base3
# 1.279 31-May-2008 nakayama

branches: 1.279.2;
openfirmware_exit:
- disable interrupts with %pstate.
- prepare 64-bit stack and enable 64-bit addresses for 32-bit SMP kernels.


Revision tags: hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 yamt-nfs-mp-base yamt-pf42-base
# 1.278 16-Apr-2008 nakayama

branches: 1.278.2; 1.278.4; 1.278.6;
Disable TRAPSTATS which was accidentally enabled when yamt-idlelwp branch
was merged.

Ok by martin@.


# 1.277 14-Apr-2008 nakayama

Remove sparc64_ipi_sync_tick.

Since we can use counter-timer as timecounter instead of %tick on SMP kernel,
it is not necessary to sync all CPUs %tick registers.


# 1.276 14-Apr-2008 nakayama

Add workaround for BB_ERRATA_1 on writing to TICK_CMPR register in
next_tick(). If writing to TICK_CMPR fails, we lose hardclock interrupt
on secondary CPUs.

About BB_ERRATA_1 from comment in OpenSolaris:

/*
* Writes to the TICK_COMPARE register sometimes fail on blackbird modules.
* The failure occurs only when the following instruction decodes to wr or
* wrpr. The workaround is to immediately follow writes to TICK_COMPARE
* with a read, thus stalling the pipe and keeping following instructions
* from causing data corruption. Aligning to a quadword will ensure these
* two instructions are not split due to i$ misses.
*/


# 1.275 28-Mar-2008 nakayama

Don't read fplwp content in delay slot for considering the case fplwp was
modifiled.

Reported by Chris Ross on port-sparc64.


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.274 20-Mar-2008 nakayama

- remove disabling interrupt in IPI.
- unused VA bits in MMU demap is 13 bits, not 12 bits.


# 1.273 18-Mar-2008 nakayama

Fix a race when increment an interrupt level event counter.


# 1.272 17-Mar-2008 nakayama

Fix a race condition in IPI handlers of save/drop fpstate, from OpenBSD.
Reported and tested by martin@.


# 1.271 17-Mar-2008 nakayama

Make schedintr interrupt handler per-CPU.
While there rename tickintr interrupt handler and share initialization
code with schedintr.


# 1.270 14-Mar-2008 nakayama

Improve IPI handling:
- make IPI takes two arguments.
- add IPI event counters per-CPU.
- implement IPI functions which were missing or broken.
- insert DELAY while halting primary CPU in IPI handler.


# 1.269 02-Mar-2008 nakayama

- make interrupt pending list per-CPU.
- make tickintr() MP-safe.
- remove unused port-sparc derived interrupt code.

Ok by martin@.


# 1.268 02-Mar-2008 nakayama

Don't get IPI handler argument (from bogus address), and ack IRQ twice.


# 1.267 28-Feb-2008 martin

Make TSBs and MMU contexts per-cpu.


Revision tags: nick-net80211-sync-base mjf-devfs-base hpcarm-cleanup-base
# 1.266 26-Jan-2008 nakayama

branches: 1.266.2; 1.266.6;
Fix for 32-bit kernels.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.265 15-Jan-2008 skrll

Store a sensbile PCB_PC value in snapshot - the return point.

This helps gdb somewhat.

OK'd by martin.


# 1.264 14-Jan-2008 martin

Fix register name typo/copy&pasto - %g6 is not %o6/%sp.
From OpenBSD.


Revision tags: matt-armv6-base
# 1.263 06-Jan-2008 martin

Load the next cpu_info pointer with LDPTR instead of ld.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2
# 1.262 09-Dec-2007 martin

branches: 1.262.2;
Provide cpu_intr_p(), at least for non-MULTIPROCESSOR kernels.
Based on suggestions by Andrew Doran.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.261 22-Oct-2007 martin

branches: 1.261.2; 1.261.4; 1.261.6;
Remove an unused .globl declaration


Revision tags: yamt-x86pmap-base4
# 1.260 17-Oct-2007 garbled

Merge the ppcoea-renovation branch to HEAD.

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

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

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base ppcoea-renovation-base vmlocking-base
# 1.259 09-Sep-2007 martin

branches: 1.259.4;
Make cpufrequency and friends per cpu values.
Prepare a hz tick interrupt on secondary CPUs via %tick, but do not
enable it yet, as it breaks ddb.


# 1.258 09-Sep-2007 martin

Do not ACK IPIs before we finished loading all arguments.


# 1.257 06-Sep-2007 martin

Remove the (now unused) second 64k page mapped per CPU.
From matthew green, with small changes by me. All bugs are mine.


# 1.256 25-Aug-2007 martin

branches: 1.256.2;
Remove INITSTACK completely - at the time we used to switch to it, we
already have access to all of lwp0 and it's uarea - so we can switch
to the correct lwp0 stack easily before calling main.


# 1.255 25-Aug-2007 martin

When exiting to OF, use the interrupt stack instead of INITSTACK


# 1.254 25-Aug-2007 martin

Rework cpu_mp_startup slightly:
- temporarily use the cpu's interrupt stack untill we are ready
to access non-OF-based mappings, then directly switch to the cpu's
idlelwp's uarea stack
- disable interrupts untill we are ready to call C code


# 1.253 13-Aug-2007 macallan

remove two restore without matching save


Revision tags: nick-csl-alignment-base matt-mips64-base mjf-ufs-trans-base
# 1.252 06-Jul-2007 martin

branches: 1.252.4; 1.252.8;
A few nits for 32bit SMP kernels, noticed by mrg.
While there, simplify the fpstate IPIs a bit.


# 1.251 05-Jul-2007 martin

sparc64_ipi_save_fpstate is not a leaf function - create a full grown
stack frame.


# 1.250 28-May-2007 mrg

clean up cpu_switchto() a little - no need to flushw or membar
excessively. optimise an rdpr. tested by tnn.


# 1.249 23-May-2007 martin

Fix a stupid bug in the save_fpstate ipi, which caused overwriting of
struct lwp of the lwp owning the fpu. Fix clearing the fplwp - %o0 will
not survive the call to savefpstate - duh!


# 1.248 20-May-2007 martin

Simplify tf_tstate setting when leaving for userland initially - I seem
to have confused the if with the else case of the previous C code.
Funny that it worked at all.


# 1.247 20-May-2007 martin

cpu_switchto() has to return it's first arg, always. This differs from
my reading of the documentation, but helps in the real world and seems
to be what other ports do.


# 1.246 20-May-2007 martin

Remove special case handling for userland lwps from cpu_lwp_fork, instead
do it in lwp_trampoline when we first return to userland.


# 1.245 19-May-2007 martin

cpu_idle is a leaf function, so we better "return from leaf".
Use return value from cpu_switchto for previous lwp in lwp_trampoline.
Also shamelessly steal a comment from uwe written for sparc that explains
all this.
Thanks to tnn, mrg, and uwe for helping to debug this.


# 1.244 17-May-2007 yamt

merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base ad-audiomp-base
# 1.243 22-Feb-2007 martin

branches: 1.243.4; 1.243.6; 1.243.12;
uvm.page_idle_zero now is a bool, not a 32bit value any more.


# 1.242 21-Feb-2007 mrg

shave 9 insns off the tsb setup in cpu_initialize & cpu_mp_startup.


# 1.241 21-Feb-2007 martin

Get rid of unused (thus always zero) "curlwp" variable hidden in assembler
code (C code always uses a cpuinfo based macro).


# 1.240 18-Feb-2007 martin

Make use of another call delay slot, pointed out by uwe.


# 1.239 18-Feb-2007 martin

Make use of a call delay slot and avoid a bogus EMPTY.
Spotted by Juergen Hannken-Illjes, with input from Andrew Doran and
Valeriy E. Ushakov.


# 1.238 18-Feb-2007 martin

Whitespace cosmetics


# 1.237 18-Feb-2007 martin

Backout previous: EMPTY was misused


# 1.236 18-Feb-2007 martin

Make EMPTY expand to nop with gas, as it is used to mark empty branch
delay slots.


# 1.235 15-Feb-2007 martin

branches: 1.235.2;
Fix obvious copy&pasto in SCHED_DEBUG register usage.


Revision tags: post-newlock2-merge
# 1.234 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.233 25-Dec-2006 wiz

Spell "relevant" correctly. From Zafer Aydogan.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.232 25-Oct-2006 mrg

branches: 1.232.2; 1.232.4;
- note that __idle_u should go away but doing so breaks things
- fix several comments to reality
- clean up the #ifdef NO_VCACHE code slightly
- use call instead of set/jmpl
- remove a couple of unnecessary stores to curlwp


Revision tags: yamt-splraiseipl-base2
# 1.231 18-Oct-2006 rjs

Clean up some comments. Cosmetic change to use correct structure
offset names.

Optimize out two instructions from sparc64_ipi_save_fpstate and
sparc64_ipi_drop_fpstate.


# 1.230 17-Oct-2006 mrg

allocate 128KB (as opposed to 64KB) per-cpu, and place the interrupt
stack, cpu_info structure, panicstack, idle uarea and normal kernel
stack in here. the idle uarea and kernel stack are in the 2nd 64KB
page. the interrupt stack and cpu_info structure are as the same
place in the 1st 64KB page, and the panicstack grows down from the
top of this page. update comments in param.h to suit (XXX: a lot
of these constants should move to a header file that will not pollute
the name space so much.) map these pages identically between
cpu_initialise() and cpu_mp_startup(), and deal with the two 64KB
pages in pmap_extract(). keep an unmapped 64KB page between them.

don't initialise the unused "ci_eintstack" member of the cpu_info
structure

use constants to initialise many addresses in the cpu_info structure,
consolidating these assignments from cpu0 and cpu>0

delete u0/estack0/panicstack from locore.s

clean up some wrong comments in locore.s

fix a 32bit-only bug in cpu_mp_startup().

delete 'u0' entirely.


this fixes recent random lossage seen on port-sparc64: processes
stuck in RUN state, data faults, and hangs.


# 1.229 04-Oct-2006 mrg

use call instead of set/jmpl. add an entry point for idle that expects
sched_lock to be unlocked, and use this for non-boot cpu's. complete a
comment describing how registers in idle_switch are expected to be set.


# 1.228 03-Oct-2006 mrg

use the same SAVE_LOCALS_INS definition for 32 bit and 64 bit kernels.
refactor TRAP_SETUP() a little between these two versions to be more alike.


# 1.227 03-Oct-2006 mrg

use the correct size/type for MP variables (pointers and longs).

a 32 bit MULTIPROCESSOR kernel now builds (and crashes quickly.)


# 1.226 03-Oct-2006 mrg

in the 64bit version of SAVE_LOCAL_INS, s/BIAS/STKB/ to allow future
sharing of the 32 and 64 bit versions of the {TRAP,INTR}_SETUP macros.


# 1.225 19-Sep-2006 mrg

- remove some way old FP setup/teardown code
- put the block memcpy/memset inside #ifdef USE_BLOCK_STORE_LOAD which
is (now) defined.

no functional change, same .o is generated.


# 1.224 19-Sep-2006 mrg

re-order the changes in rev 1.217 to give registers a little bit of
time to settle between usage, like it was before hand.


# 1.223 19-Sep-2006 mrg

- remove a wrong comment.
- add a new entry point for idle called idle_switch that is called by
cpu_switch() in the MP case when sched_whichqs is zero, properly
setting up the idle stack. from petrov@ via martin@.


# 1.222 19-Sep-2006 mrg

rework interrupt_vector() slightly:
- for the IPI case, avoid loading the address of intrlev into %g3
- remove some NOT_DEBUG code
- load the interrupt argument #2 in the delay slot

this removes 2 nops during interrupt processing for the normal
case, and an additional 2 ALU instructions for IPIs


# 1.221 18-Sep-2006 mrg

- sparc64_ipi_halt(): we shouldn't return from sparc64_ipi_halt_thiscpu()
so replace a branch with a 'sir'
- in #if 0 code, in sparc64_ipi_flush_pte() and sparc64_ipi_flush_ctx()
save/restore the out registers that the sp_tlb_flush_xxx() versions
around calling them
- in sp_tlb_flush_pte() and sp_tlb_flush_ctx(), replace global register
usage with out registers so that we don't clobber the (alternate)
global registers when these are called from IPI context


# 1.220 18-Sep-2006 mrg

- remove an extra 'sir' that followed one in a macro
- add some named labels to some spill/fill handlers
- remove 2 unused strings


Revision tags: yamt-splraiseipl-base
# 1.219 18-Sep-2006 martin

branches: 1.219.2;
Lazy FPU handling for the MULTIPROCESSOR case


# 1.218 16-Sep-2006 nakayama

From OpenBSD:
- reload %fprs for checking it again.
- use symbolic names for checking in %fprs.

revision 1.51
date: 2005/07/18 14:50:11; author: deraadt; state: Exp; lines: +2 -1
cache a copy of the fprs so we know what fp restore we should do after

revision 1.50
date: 2005/07/14 01:46:13; author: deraadt; state: Exp; lines: +4 -4
use symbolic names for checking in %fprs, as above


# 1.217 16-Sep-2006 nakayama

Fix a couple of %y register save/restore errors, inspired from OpenBSD.

revision 1.44
date: 2004/04/23 04:18:17; author: marc; state: Exp; lines: +5 -4

fix a couple of %y register save/restore errors
1) don't save %y in a register that is later used before restoring %y
2) always restore %y after calling a signal handler
tested by drahn@, OK pval


# 1.216 15-Sep-2006 martin

Do not bother to save fpu state when we are about to get rid of it.


Revision tags: yamt-pdpolicy-base9
# 1.215 13-Sep-2006 mrg

SMP cleanup. provide support for multiple CPUs in DDB. (SMP itself
is still not working.)

cpu.h:
- add a pointer for DDB regs in SMP environment to struct cpu_info
- remove the #defines for mp_pause_cpus() and mp_resume_cpus()
cpuset.h:
- remove CPUSET_ALL() and rename CPUSET_ALL_BUT() to CPUSET_EXCEPT()
from petrov.
db_machdep.h:
- rename the members of db_regs_t to be the same as sparc
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- redo DDB_REGS to no longer be a pointer to a fixed data structure
but to one allocated per-cpu when ddb is entered
- move a bunch of prototypes in here
intr.h:
- remove SPARC64_IPI_* macros, no longer used
db_interface.c:
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- make "nil" a 64 bit entity
- change the ddb register access methods to work in multiprocessor
environment, it is now very much like sparc does it
- in kdb_trap() avoid accessing ddb_regp when it is NULL
- update several messages to include the cpu number
- unpause other cpus much later when resuming from ddb
- rename db_lock() to db_lock_cmd(), as the sparc-like code has
db_lock as a simple lock
- remove "mach cpus" command, and replace it with "mach cpu" (which
does the same) and also implement "mach cpu N" to switch to
another cpus saved trapframe
db_trace.c:
- update for the ddb_regs -> ddb_regp change
genassym.cf:
- add TF_KSTACK as offsetof(struct trapframe64, tf_kstack)
ipifuncs.c:
- overhaul extensively
- remove all normal interrupt handlers as IPI's, we now handle
them all specially in locore.s:interrupt_vector
- add a simplelock around all ipi functions - it's not safe for
multiple cpus to be sending IPI's to each other right now
- rename sparc64_ipi_pause() to sparc64_ipi_pause_thiscpu() and,
if DDB is configured, enable it to save the passed-in trapframe
to a db_regs_t for this cpu's saved DDB registers.
- remove the "ipimask" system (SPARC64_IPI_* macros) and instead
pass functions directly
- in sparc64_send_ipi() always set the interrupt arguments to 0,
the address and argument of the to be called function. (the
argument right now is the address of ipi_tlb_args variable, and
part of the reason why only one CPU can send IPI's at a time.)
don't wait forever for an IPI to complete. some of this is
from petrov.
- rename sparc64_ipi_{halt,pause,resume}_cpus() to
mp_{halt,pause,resume}_cpus()
- new function mp_cpu_is_paused() used to avoid access missing
saved DDB registers
- actually broadcast the flush in smp_tlb_flush_pte(),
smp_tlb_flush_ctx() and smp_tlb_flush_all(). the other end may
not do anything yet in the pte/ctx cases yet...
kgdb_machdep.c:
- rework for changed member names in db_regs_t.
locore.s:
- shave an instruction from syscall_setup() (set + ld -> sethi + ld)
- remove some old dead debug code
- add new sparc64_ipi_halt IPI entry point, it just calls the C
vector to shutdown.
- add new sparc64_ipi_pause IPI entry point, which just traps into
the debugger using the normal breakpoint trap. these cpus usually
lose the race in db_interface.c:db_suspend_others() and end up
calling the C vector sparc64_ipi_pause_thiscpu().
- add #if 0'ed code to sparc64_ipi_flush_{pte,ctx}() IPI entry
points to call the sp_ version of these functions.
- in rft_kernel (return from trap, kernel), check to see if the
%tpc is at the sparc64_ipi_pause_trap_point and if so, call
"done" not "retry"
- rework cpu_switch slightly: save the passed-in lwp instead of
using the one in curlwp
- in cpu_loadproc(), save the new lwp not the old lwp, to curlwp
- in cpu_initialize(), set %tl to zero as well. from petrov.
- in cpu_exit(), fix a load register confusion. from petrov.
- change some "set" in delay branch to "mov".
machdep.c:
- deal with function renames
pmap.c:
- remove a spurious space
trap.c:
- remove unused "trapstats" variable
- add cpu number to a couple of messages


# 1.214 09-Sep-2006 mrg

significant clean up effort, largely from petrov@ via martin@.

- fix a bunch of comments for proc->lwp
- remove old TRAPTRACE, NOT_DEBUG, etc. code that has bit-rotted
- put some older DEBUG code under NOT_DEBUG
- add a bunch of new debugging/tracing code ("KTR") that depends on
other changes not yet present.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base yamt-pdpolicy-base5 chap-midi-base simonb-timecounters-base rpaulo-netinet-merge-pcb-base
# 1.213 14-May-2006 elad

branches: 1.213.6; 1.213.8;
integrate kauth.


# 1.212 12-May-2006 skrll

Fix some comments.


Revision tags: elad-kernelauth-base
# 1.211 09-May-2006 rjs

Load CPCB in cpu_mp_startup.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.210 11-Feb-2006 cdi

branches: 1.210.2; 1.210.4; 1.210.6;
ANSIfication: u_intN_t -> uintN_t, use ANSI function declarations/definitions
instead of K&R ones.


# 1.209 27-Jan-2006 cdi

branches: 1.209.2; 1.209.4;
Alter sparc64 bootstrap, catch up to ofwboot v1.9:

- Accept bootinfo structure passed down from ofwboot v1.9
- Drop kernel re-mapping code
- Use permanent 4MB mappings provided by the loader instead
- Change kernel entry address to point directly at the code instead of pointing
at the trap table's first slot. This allows the bootloader to detect
those kernels which are aware of the new boot scheme
- Due to the changes in kernel mapping code, alter secondary CPU bootstrap
code to use trampoline just like FreeBSD does (some FreeBSD code is used
here as well)


# 1.208 12-Jan-2006 cdi

Fix a typo: %g0 should be used instead of %o0 when initializing FPU in dostart:
and cpu_mp_startup:, %o0 is not even initialized at this point.


# 1.207 11-Dec-2005 christos

branches: 1.207.2;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 1.206 10-Jul-2005 christos

Re-factor syscall, and make it use syscall_{plain,fancy}.


# 1.205 31-May-2005 chs

branches: 1.205.2;
remove vestigal {,e}intr{names,cnt} symbols now that vmstat doesn't need them.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.204 12-Feb-2005 chs

branches: 1.204.4; 1.204.6; 1.204.8;
in sparc_interrupt(), wait to enable interrupts until just before calling
the handler and disable them again right after the handler returns.
we don't want another hardware interrupt coming in while we're mucking
with the list pointers. also, clear the intrhand's ih_pending pointer
before calling the handler rather than after, so that if another interrupt
comes in while the handler is running, we can put the intrhand back on
the list so it will be called again.

in send_softint(), disable interrupts via %pstate instead of %pil, so that
hardware interrupts at higher levels are blocked while we manipulate the
intrpending list. also, if the intrhand already has ih_pending set,
don't bother poking the SET_SOFTINT register again, since being on the list
implies that there is already a softint pending in the hardware.

these appear to fix PR 21750 (the "sleep forever" problem).

while I'm here, remove more vestiges of the !INTRLIST softint stuff
(code and comments). and in sparc64_ipi_flush_all(), interrupts are
already disabled so we don't need to fiddle with %pstate.


Revision tags: yamt-km-base2
# 1.203 30-Jan-2005 martin

Remove the no long usefull variants selected by undefining INTRLIST and
INTR_INTERLOCK to improve readability. Same object code generated as before.


Revision tags: yamt-km-base
# 1.202 16-Jan-2005 chs

branches: 1.202.2;
use ENTRY_NOPROFILE() for various entry points,
stack traces work better that way.


Revision tags: kent-audio1-beforemerge kent-audio1-base
# 1.201 03-Dec-2004 chs

branches: 1.201.4;
remove cache_flush_virt() and PADDRT, they're no longer used.
allocate a stack frame for blast_dcache() when profiling so it shows up.
in dcache_flush_page(), use a stride of 32 instead of 16 to match the
cache line size. correct various comments.


# 1.200 08-Nov-2004 petrov

Don't compile sparc64_ipi functions when UP.


# 1.199 25-Oct-2004 martin

No need to clear %o1 when returning a 64 bit integer from pseg_get if we
are compiling for a 64 bit kernel.


# 1.198 24-Jul-2004 nakayama

Change interrupt pending list end value to -1, to avoid linking an
interrupt handler twice.

It may fix "sleep forever" bug.


# 1.197 09-Apr-2004 petrov

Clean-up unused defines and variables.


Revision tags: netbsd-2-0-base
# 1.196 26-Mar-2004 petrov

branches: 1.196.2;
Use want_resched from cpu_info area.


# 1.195 23-Mar-2004 martin

Replace intrcnts by evcnts. XXX - needs slight tweaking for MULTIPROCESSOR.


# 1.194 14-Mar-2004 chs

checkpoint of MP work from dennis and myself. includes cross-processor
interrupt framework, a sledgehammer TLB invalidation and misc MP fixes.
doesn't work at all yet.


# 1.193 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.192 19-Jan-2004 martin

Rename switchexit to cpu_exit and g/c the old C implementation of cpu_exit.


# 1.191 18-Jan-2004 martin

Support RAS for 32bit kernels too.


# 1.190 16-Jan-2004 martin

In proc_trampoline don't bother to clear condition codes in the trap
frame, since we no longer rely on this.
While there fix a few comments.


# 1.189 08-Jan-2004 martin

Minor cleanup


# 1.188 06-Jan-2004 martin

Implement restartable atomic sequences (RAS) for sparc64.


# 1.187 06-Jan-2004 petrov

Spinup secondary cpus. Based on codes sent to me by Dennis Chernoivanov
and Chuck Silvers.


# 1.186 04-Jan-2004 jdolecek

update to recent changes - exit2() doesn't exist anymore and the
exit path always calls lwp_exit2()
pointed out Martin Husemann


# 1.185 02-Dec-2003 martin

Minor cleanup: remove unused code, sync a comment with current reality.


# 1.184 25-Nov-2003 cdi

Use per-cpu pcb, curlwp and fplwp rather than global ones. This brings
GENERIC.MP configuration to a usable state.

Approved by petrov@.


# 1.183 24-Nov-2003 cdi

Call 'proc_trampoline_mp' from 'proc_trampoline' in a multiprocessor
configuration. Fix process locking. Approved by petrov@.


# 1.182 20-Nov-2003 petrov

Remove nwindows calculation, it's not used. Set l_cpu in cpu_switch.


# 1.181 09-Nov-2003 martin

Get rid of bcopy/bzero.


# 1.180 26-Oct-2003 christos

Initial siginfo support for sparc64 (untested). COMPAT_16 sigcontext signal
delivery tested.


# 1.179 24-Aug-2003 chs

add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default. the changes
fall into two basic catagories:

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

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

originally from openbsd, adapted for netbsd by me.


# 1.178 08-Jul-2003 cdi

traceit: don't use %g7 as it is to become curcpu() register. Add comments.


# 1.177 18-May-2003 martin

branches: 1.177.2;
Make kernels with options KGDB at least compile.
Still needs some work to make it working.


# 1.176 29-Apr-2003 nakayama

Use BLOCK_ALIGN rather than BLOCK_SIZE for aligning a pointer.


# 1.175 27-Apr-2003 ragge

Preserve the symbol table in the LKM || KSYMS cases also.


# 1.174 04-Apr-2003 petrov

use branch slot in pmap_copy_page.


# 1.173 24-Mar-2003 nakayama

Divide `set' instruction in delay slot (from OpenBSD change to rev 1.30).


# 1.172 10-Feb-2003 martin

Remove some #if 0 code and a few XXX marked membars w/o proper
justification for their existence.


# 1.171 09-Feb-2003 martin

Remove left over pieces from reusing the signal trampoline for upcalls.
This should fix signal delivery for 32bit kernels.


# 1.170 05-Feb-2003 nakayama

Switch to use cycle counter (%tick) based microtime().

This is derived from alpha/microtime.c and i386/tsc_microtime.c,
and will share with both ports.

This should fix PR port-sparc64/18452.
(approved by martin)


# 1.169 04-Feb-2003 martin

Fix return value of pseg_set, which I accidently broke in rev. 1.164.

Fix register names in comment and shave off another register (hint
from uwe).


# 1.168 01-Feb-2003 martin

Rearrange register usage in pseg_set a bit and shave off %g4.


# 1.167 01-Feb-2003 martin

Remove a few #ifdef _LP64 by using STPTR/LDPTR macros.
Thanks to Matthew Green for the pointer.


# 1.166 31-Jan-2003 martin

Apply leaf procedure optimization to pseg_set (again).


# 1.165 31-Jan-2003 martin

Make the pmap count resident/wired mappings on the fly instead of
walking the page tables whenever this information is needed.

Add an option PMAP_COUNT_DEBUG to assert the new counts and the
page table walk agree.

The old solution had very bad performance impact, for example
by the high CPU load when running top(1).

Thanks to Simon Burge for pointing at the cause of the problem and
to Valeriy E. Ushakov for optimizing my simple minded assembler code.


# 1.164 27-Jan-2003 martin

Remove unused function pseg_find (which looked quite similar to
pseg_get anyway).


# 1.163 18-Jan-2003 thorpej

Merge the nathanw_sa branch.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.162 16-Jan-2003 petrov

Move dump_dtlb back under DDB.


# 1.161 15-Jan-2003 chs

fix two bugs in my last pmap rework:
- in tlb_flush_all(), don't skip TLB entries with the high bit on,
I was confused about which MMU register it was using. it's also fine
to use the last hardware context.
- in pmap_create(), don't allocate a hardware context for the new pmap.
it's unnecessary, and when this would cause us to recycle all the contexts,
it would result in the current process's context being set to 0
(ie. the kernel's context). the current process could then return to
userspace without going through the context-switch code (and thus without
having a hardware context reallocated). this would lead to user mappings
being entered in the kernel's context later, causing all sorts of trouble.
add some assertions to catch this kind of thing.


Revision tags: fvdl_fs64_base
# 1.160 25-Dec-2002 petrov

new function dump_itlb.


Revision tags: gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.159 22-Sep-2002 chs

many improvements:
- use struct vm_page_md for attaching pv entries to struct vm_page
- change pseg_set()'s return value to indicate whether the spare page
was used as an L2 or L3 PTP.
- use a pool for pv entries instead of malloc().
- put PTPs on a list attached to the pmap so we can free them
more efficiently (by just walking the list) in pmap_destroy().
- use the new pmap_remove_all() interface to avoid flushing the cache and TLB
for each pmap_remove() that's done as we are tearing down an address space.
- in pmap_enter(), handle replacing an existing mapping more efficiently
than just calling pmap_remove() on it. also, skip flushing the
TSB and TLB if there was no previous mapping, since there can't be
anything we need to flush. also, preload the TSB if we're pre-setting
the mod/ref bits.
- allocate hardware contexts like the MIPS pmap:
allocate them all sequentially without reuse, then once we run out
just invalidate all user TLB entries and flush the entire L1 dcache.
- fix pmap_extract() for the case where the va is not page-aligned and
nothing is mapped there.
- fix calculation of TSB size. it was comparing physmem (which is
in units of pages) to constants that only make sense if they are
in units of bytes.
- avoid sleeping in pmap_enter(), instead let the caller do it.
- use pmap_kenter_pa() instead of pmap_enter() where appropriate.
- remove code to handle impossible cases in various functions.
- tweak asm code to pipeline a little better.
- remove many unnecessary spls and membars.
- lots of code cleanup.
- no doubt other stuff that I've forgotten.

the result of all this is that a fork+exit microbenchmark is 34% faster
and a fork+exec+exit microbenchmark is 28% faster.


Revision tags: gehenna-devsw-base
# 1.158 18-Jul-2002 wiz

Spell 'should' correctly.


# 1.157 07-Jun-2002 eeh

Shave 10% off the time needed to flush the D$ through a bit of instruction
reordering.


# 1.156 05-Jun-2002 eeh

Handle improperly aligned stack pointers more cleanly.


# 1.155 04-Jun-2002 eeh

Fix the fork trampoline to properly use the supplied tstate.


# 1.154 31-May-2002 thorpej

Make this work with an ISO C preprocessor.


Revision tags: netbsd-1-6-base
# 1.153 14-May-2002 eeh

branches: 1.153.2; 1.153.4;
Only save locals and ins in trapframes for DEBUG kernels.


# 1.152 04-May-2002 kleink

Add some comments to the CPP conditionals controlling the trap macro
definitions, to ease navigation somewhat.


# 1.151 16-Apr-2002 eeh

Make lots of routines profile-friendly and get rid of some cruft.


Revision tags: eeh-devprop-base
# 1.150 21-Mar-2002 petrov

Not needed debug stuff deleted.


# 1.149 16-Mar-2002 mrg

tell newer binutils that our use of %g2 and %g3 is OK here.


# 1.148 15-Mar-2002 eeh

Cleanup MMU initialization to prevent hangs.


Revision tags: newlock-base ifpoll-base
# 1.147 09-Feb-2002 eeh

branches: 1.147.4;
Fix microsecond calculation in microtime.


# 1.146 07-Feb-2002 eeh

Fix register allocation in microtime().


# 1.145 29-Jan-2002 eeh

Shift the UPAID in the correct direction.


# 1.144 17-Jan-2002 eeh

Be more tolerant of unaligned stack pointers.


# 1.143 17-Jan-2002 eeh

Enable block insns in bcopy and bzero.


# 1.142 16-Jan-2002 eeh

In bcopy use 32-bit comparisons in 32-bit kernels.


# 1.141 16-Jan-2002 eeh

Use correct calculation for the trapframe in softtrap for ILP32.


# 1.140 20-Nov-2001 lukem

- pull in opt_kgdb.h where necessary
- replace opt_kgdb_machdep.h with opt_kgdb.h
- defparam opt_kgdb.h:
KGDB_DEV KGDB_DEVNAME KGDB_DEVADDR KGDB_DEVRATE KGDB_DEVMODE
- move from opt_ddbparam.h to opt_ddb.h:
DDB_FROMCONSOLE DDB_ONPANIC DDB_HISTORY_SIZE DDB_BREAK_CHAR SYMTAB_SPACE
- replace KGDBDEV with KGDB_DEV
- replace KGDBADDR with KGDB_DEVADDR
- replace KGDBMODE with KGDB_DEVMODE
- replace KGDBRATE with KGDB_DEVRATE
- use `9600' instead of `0x2580' for 9600 baud rate
- use correct quotes for options KGDB_DEVNAME="\"com\""
- use correct quotes for options KGDB_DEV="17*256+0"
- remove unnecessary dependancy on Makefile for kgdb_stub.o
- minor whitespace cleanup


Revision tags: thorpej-mips-cache-base thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf
# 1.139 14-Sep-2001 thorpej

branches: 1.139.4;
Don't declare intrhand[] here -- that's taken care of in intr.c.


Revision tags: thorpej-devvp-base
# 1.138 30-Aug-2001 eeh

branches: 1.138.2;
Preliminary UltraSPARC III suport (not enabled yet).


# 1.137 13-Aug-2001 jdolecek

g/c _remque()/_insque(); use the C version in libkern


# 1.136 09-Aug-2001 eeh

Fix context masking lossage caused by last version.


# 1.135 08-Aug-2001 eeh

Clean up the trap code to handle the changes cause by supporting non-faulting
accesses. Also change the parameter order so trap frames are easy to find.


# 1.134 07-Aug-2001 eeh

Make sure C code always has ASI_PRIMARY_NOFAULT in the %asi register so
the compiler will be happy if it ever starts generating speculative loads.


# 1.133 05-Aug-2001 eeh

Add support for non-faulting loads and optimize MMU miss handling paths.


# 1.132 02-Aug-2001 eeh

Fix bcopy.


# 1.131 02-Aug-2001 eeh

Sync bzero w/libc version.


# 1.130 01-Aug-2001 eeh

Integrate fixes from userland memset.


# 1.129 31-Jul-2001 eeh

Code cleanup and optimization.


# 1.128 23-Jul-2001 eeh

Get rid of some debug code that really isn't all that useful any more.


# 1.127 19-Jul-2001 eeh

Do ignore unregistered interrupts instead of faulting.


# 1.126 16-Jul-2001 eeh

Make bcopy a 32-bit friendly.


# 1.125 11-Jul-2001 eeh

Fix problems booting 32-bit kernels and dispatching level-15 interrupts.


# 1.124 08-Jul-2001 eeh

branches: 1.124.2;
Code cleanup. Add block_disable to let you turn on block set/copy routines.


# 1.123 05-Jul-2001 eeh

New block bzero and bcopy.


# 1.122 04-Jul-2001 eeh

Replace old bcopy with a much faster version.


# 1.121 01-Jul-2001 martin

Disable axidently enabled debug code to make -current compile again.


# 1.120 30-Jun-2001 eeh

Use a newer version (still disabled) of block bcopy.


# 1.119 30-Jun-2001 eeh

Fixup fpu save restore, get rid of some unused copy functions, and add
a new bcopy.


# 1.118 21-Jun-2001 eeh

Allow multiple 4MB pages for both kernel text and kernel data.

Note: DEBUG checks will not allow accesses to the hole between
text and data segments, so you may need to update programs that
use libkvm before relocating the start of kernel data.


# 1.117 06-Jun-2001 mrg

extract the netbsd32, sunos, 32 bit svr4 and 64 bit svr4 sigcode out into
separate files, so that compat lkms can link with them as well.


# 1.116 30-May-2001 lukem

add missing #include "opt_kgdb.h"


Revision tags: thorpej_scsipi_beforemerge
# 1.115 25-Apr-2001 simonb

Spell occurred correctly.


Revision tags: thorpej_scsipi_nbase thorpej_scsipi_base
# 1.114 09-Apr-2001 eeh

Interrupt latency fix from sparc port. (Hm. One insn instead of 5).


# 1.113 07-Mar-2001 eeh

Fix inverted preprocessor logic. (Spotted by Charles.)


# 1.112 21-Feb-2001 eeh

branches: 1.112.2;
Add support for 64-bit SVR4 (Solaris 8) binaries.


# 1.111 10-Feb-2001 pk

Fix conditional for svr4 compat inclusion.


# 1.110 05-Feb-2001 eeh

Add signal trampoline for 64-bit svr4 emulations.


# 1.109 31-Dec-2000 eeh

Make INCR() atomic.


# 1.108 29-Dec-2000 eeh

pseg_get tells us whether it really needed that spare page after all.


# 1.107 07-Dec-2000 eeh

Fixup calculating where fpstate should be saved in the signal trampoline
code so it doesn't overwrite something important like the registers.


# 1.106 09-Nov-2000 eeh

Fix ILP32 bug in probe_get().


# 1.105 22-Oct-2000 pk

Restore revision 1.102.

I hope it sticks this time..


# 1.104 20-Oct-2000 eeh

Fix hang in 32-bit kernels caused by relocation of KERNBASE.


# 1.103 04-Oct-2000 eeh

Fix interrupt lossage problem and some cosmetic changes.


# 1.102 01-Oct-2000 pk

cpu_initialize: global registers aren't preserved across calls to
prom_printf(), so replace %g3 with %l7 (which isn't used despite
the `usage' comment).

Also, clean up white-space turds.


# 1.101 29-Sep-2000 eeh

This seems to fix the interrupt lossage of non-debug kernels.


# 1.100 28-Sep-2000 eeh

Fix INTR_SETUP() to properly distinguish kernel and user addresses.

Make microtime() return the correct time on %tick machines.

Re-enable debug stuff in dostart for now to detect kernel mapping issues.


# 1.99 25-Sep-2000 pk

Missing `#if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)'


# 1.98 17-Sep-2000 eeh

Make the improved %tick changes work with machines that use the counter-timer
for the clock.


# 1.97 12-Sep-2000 eeh

Fix new version of microtime.


# 1.96 11-Sep-2000 eeh

(Hopefully) fix clock skew on machines that us %tick for the clock (UIIi).


# 1.95 31-Aug-2000 eeh

Use casx instead of stx to change entries in the page table trees.


# 1.94 23-Aug-2000 eeh

Update the scheduler to the new locking scheme.


# 1.93 10-Aug-2000 eeh

Fix signal delivery.


# 1.92 02-Aug-2000 eeh

Get kernel profiling to work. Now if only gprof worked....


# 1.91 01-Aug-2000 eeh

Overhaul cache flush code and coredump code.


# 1.90 25-Jul-2000 pk

Re-instate a couple of delay slot NOPs marked `XXX spitfire bug?'


# 1.89 24-Jul-2000 mycroft

Optimization to pmap_zero_page(): we only need to use the first 16 FP regs,
as in bzero().


# 1.88 24-Jul-2000 mycroft

Fix a whitespace glitch.


# 1.87 24-Jul-2000 mycroft

Pull in the bzero() changes from libc for real, with a couple of kernel-
specific hacks:
* Make the bias handling depend on STKB, so it switches correctly for 32-bit
kernels.
* Use the 32-bit stw/ld for 32-bit kernels.
* Add a few `-STKB's that were missed in the previous change.


# 1.86 24-Jul-2000 pk

Cosmetic & readability:
- local label cleanup in interrupt handling code;
- in debugging sections when testing `intrdebug': use a unique
local label (97) to enhanced clarity;
- comment-out unused code;
- kill a bug as the satisfying result of doing all of the above.


# 1.85 24-Jul-2000 eeh

Fix stack issues in bzero.


# 1.84 24-Jul-2000 mycroft

Revert the previous change for now. I don't have time to debug it tonight.


# 1.83 23-Jul-2000 mycroft

Copy bzero change from libc.


# 1.82 20-Jul-2000 pk

Since `intrcnt' points to an array of long ints, reserve the appropriate
amount of space depending on _LP64. Provide macros to load/store signed
and unsigned long ints.

Also, make the `intrcnt' and `intrpending' arrays 16 entries long, as on
sparc/v9 interrupt #15 is just a regular interrupt.


# 1.81 19-Jul-2000 eeh

Fix merge problem.


# 1.80 19-Jul-2000 eeh

Disable interrupt interlock using ih->ih_pending field. Seems to cause
more problems than it solves.


# 1.79 19-Jul-2000 eeh

Miscellaneous cleanup.


# 1.78 18-Jul-2000 pk

Correct args usage comment in probeget.
Whitespace cleanup.


# 1.77 18-Jul-2000 pk

probeget: 9 -> 0x9


# 1.76 18-Jul-2000 pk

If `ih_pending' is set simply return from the trap, don't schedule another
soft interrupt.


Revision tags: mrg-merge-1-5-top
# 1.75 18-Jul-2000 pk

openfirmware: don't lower %pil


# 1.74 17-Jul-2000 pk

Kill typos in interrupt code.


# 1.73 17-Jul-2000 pk

probeget: do the same song and dance as ld*a() macros in ctlreg.h do.


# 1.72 14-Jul-2000 eeh

Move some macro definitions out of genassym and into locore.s


# 1.71 08-Jul-2000 mrg

backout part of previous: turn off intrdebug, and another debug message


# 1.70 07-Jul-2000 pk

Changes for readability:
- #define LP64 dependent STACKFRAME macro once
- use a LOAD_ASCIZ macro for setting up the format string
for debug messages.


# 1.69 07-Jul-2000 eeh

Temporary fix to prevent the clock from stopping on UIIi machines.


# 1.68 03-Jul-2000 eeh

Prevent interrupts from being posted if they are active and deprecate polled
interrupts. This seems to eliminate the spurious interrupts.


# 1.67 02-Jul-2000 eeh

Clean up interrupt handling some more.


# 1.66 30-Jun-2000 eeh

Fix interrupt delivery on UltraSPARC IIi machines.


# 1.65 24-Jun-2000 eeh

With these changes the kernel seems almost stable again.


# 1.64 24-Jun-2000 eeh

More VM cleanup:

Move the cpu_info structure above the interrupt stack so it won't
get corrupted if the stack overflows.

Flush the D$ before and after all MMU bypass accesses since the
D$ latches all of those.


# 1.63 23-Jun-2000 eeh

Make probeget() and probeset() really work for a change.


Revision tags: netbsd-1-5-base
# 1.62 19-Jun-2000 eeh

branches: 1.62.2;
Have separate data and text segments, make text read-only.


# 1.61 12-Jun-2000 eeh

Start reorganizing the kernel for MULTIPROCESSOR support.


# 1.60 31-May-2000 thorpej

Add a comment about needing to initialize p_cpu when multiple
processors are supported.


Revision tags: minoura-xpg4dl-base
# 1.59 26-May-2000 thorpej

branches: 1.59.2;
First sweep at scheduler state cleanup. Collect MI scheduler
state into global and per-CPU scheduler state:

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

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

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

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

Tested on i386 and Alpha. Changes are mostly mechanical, but apologies
in advance if it doesn't compile on a particular platform.


# 1.58 26-May-2000 thorpej

Don't set `runtime' here; it's done at the end of mi_switch().
cvS: ----------------------------------------------------------------------


# 1.57 26-May-2000 thorpej

Introduce a new process state distinct from SRUN called SONPROC
which indicates that the process is actually running on a
processor. Test against SONPROC as appropriate rather than
combinations of SRUN and curproc. Update all context switch code
to properly set SONPROC when the process becomes the current
process on the CPU.


# 1.56 22-Apr-2000 eeh

If we trap due to a bad kernel stack, try to switch to the interrupt strack
before breaking into the debugger.


# 1.55 18-Apr-2000 eeh

Prevent the system from getting watchdog reset by returning directly to user
mode if restoring the user window traps. Also reduce the time we run with
%tl>0.


# 1.54 13-Apr-2000 eeh

Apparently gas 2.9.5 (don't ask) does not like to add values to %lo()
directives so move the additions inside %lo() to make it happy.
Hopefully this won't break older versions.


# 1.53 10-Apr-2000 mrg

- fix a speeling error
- rename some numbered labels to be a bit less confusing.
- remove dead code
- fix a debug error message (argh!)


# 1.52 10-Apr-2000 pk

Get a kernel without DDB to build.


# 1.51 16-Mar-2000 eeh

Revamp interrupts again:

Fix a bug causing interrmittent panics in interrupt dispatch.
Use interrupt vectors for softints.
Add a new send_softint interface.
Improved D$ flushing.
Improve traptrace and other debugging enhancements.


Revision tags: chs-ubc2-newbase
# 1.50 16-Jan-2000 eeh

Interrupt handlers return zero if they didn't handle the interrupt.


# 1.49 10-Jan-2000 eeh

Add debugger single-stepping and fix interrupt dispatch bugs.


# 1.48 30-Dec-1999 eeh

Lots of changes:

remove ffs()
add bzero that uses block store insns
save %gsr to fpstate
revert to physical accesses for pmap_zero_page so we don't
have conflicting page mappings
general cleanup.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base fvdl-softdep-base
# 1.47 06-Nov-1999 eeh

Handle zero length properly in copyinstr() copyoutstr() and copystr().


Revision tags: comdex-fall-1999-base
# 1.46 11-Oct-1999 eeh

branches: 1.46.2; 1.46.4;
Update to post 1.4.


# 1.45 05-Oct-1999 eeh

branches: 1.45.2;
Make broken versions of gas happy by using sethi/or instead of set for
(negative) addresses.


# 1.44 17-Sep-1999 thorpej

Centralize the declaration and clearing of `cold'.


Revision tags: chs-ubc2-base
# 1.43 18-Jul-1999 eeh

More fun with pmap.


# 1.42 21-Jun-1999 eeh

Improve TRAPTRACE. Add FLTRACE that only tracks MMU faults.


# 1.41 05-Jun-1999 eeh

Make pbrobeget() and probeset() work for 64-bit values as well. To do this
the arguments are changed so the address is first and the ASI second so we
can have the address in %o0:%o1 and not worry about unused registers.

Also a bit of copyright cleanup.


# 1.40 05-Jun-1999 mrg

update a commit slightly.


# 1.39 30-May-1999 eeh

Add code to support using %tick as the system clock if no "counter-timer" node
is found.


# 1.38 09-May-1999 eeh

Fixup non-DEBUG kernels.


# 1.37 29-Apr-1999 christos

Add sunos_sigcode (32 bit only)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.36 26-Mar-1999 eeh

branches: 1.36.4;
COMPAT_SPARC32 -> COMPAT_NETBSD32


# 1.35 25-Mar-1999 mrg

clean and up make compile


# 1.34 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.33 22-Mar-1999 eeh

Need to set up the pointers properly for partial FPU register stores.


# 1.32 22-Mar-1999 eeh

Flush D$ on bypass accesses.


# 1.31 28-Feb-1999 eeh

Use block load/store in pmap_zero_page()/pmap_copy_page().


# 1.30 17-Feb-1999 eeh

Let's test out vectored interrupts.


# 1.29 15-Feb-1999 hubertf

RCS ID police


# 1.28 11-Feb-1999 mrg

fix a comment pasto.


# 1.27 11-Jan-1999 eeh

Finally fixed 64-bit signal trampoline.


# 1.26 10-Jan-1999 eeh

Handle the symbol table properly in a 32-bit kernel that was booted from a
64-bit bootloader.


# 1.25 09-Jan-1999 eeh

More signal fixup.


Revision tags: kenh-if-detach-base
# 1.24 26-Nov-1998 mycroft

Sync kcopy() with 32-bit SPARC version.


# 1.23 16-Nov-1998 eeh

Fixup the last broken bits of the signal handling code.


Revision tags: chs-ubc-base
# 1.22 08-Oct-1998 eeh

Fix more syscall32 and signal breakage.


# 1.21 22-Sep-1998 eeh

More fixup in the signal area.

64-bit syscall cleanup.

Add emulation for some new FPU insns: conversion to 64-bit long int and
conditional moves.


# 1.20 17-Sep-1998 thorpej

SYS_sigreturn -> SYS___sigreturn14.


# 1.19 13-Sep-1998 eeh

Fixup signal changes (hopefully). However SUN_COMPAT is likely broken by
this and I don't know how to fix it.

We can now exec a 64-bit init through a really ugly hack (don't ask.)


# 1.18 11-Sep-1998 eeh

Add labels for the compat_sparc32 signal trampoline and break -- er -- fix
suword and fuword.


# 1.17 09-Sep-1998 eeh

Don't use %tick for microtime on 32-bit kernels -- breaks gettimeofday.


# 1.16 09-Sep-1998 thorpej

Adjust for the new "reaper" kernel thread: do not free the vmspace and
u-area in machine-dependent code. Instead, call exit2() to schedule
the reaper to free them for us, once it is safe to do so (i.e. we are
no longer running on the dead proc's vmspace and stack).


# 1.15 07-Sep-1998 eeh

Fix data corruption problem caused by broken debug code.


# 1.14 07-Sep-1998 eeh

Add new 64-bit trap vectors.


# 1.13 06-Sep-1998 eeh

32-bit fixup.


# 1.12 06-Sep-1998 eeh

Disable some debug stuff.


# 1.11 05-Sep-1998 eeh

It slices. It dices. It does everything except exec a sparc32_compat init.


# 1.10 02-Sep-1998 eeh

Periodic update: now starts probing devices.


# 1.9 30-Aug-1998 eeh

Some more 64-bit cleanup. Now everything compiles.


# 1.8 29-Aug-1998 eeh

Some more 64-bit-ification.


# 1.7 27-Aug-1998 eeh

Add 64-bit pmap support:

Moved from a two level 512/1024 entry setup mapping 32 (9/10/13) bits
respectively to a three level 1024/1024/1024 entry setup mapping 43
(10/10/10/13) bits. In 32-bit mode we waste about 1/12 pages mapping the high
11 bits. We also only manage 43 of the possible 44 bits of virtual address
space, wasting half of it. Oh well, maybe we'll do better next revision.


Revision tags: PMAP32
# 1.6 26-Aug-1998 mrg

panicstack: is needed outside of DEBUG. use _C_LABEL, and printf not db_printf (incase no ddb!)


# 1.5 13-Aug-1998 eeh

Merge paddr_t changes into the main branch.


Revision tags: eeh-paddr_t-base
# 1.4 07-Jul-1998 eeh

branches: 1.4.2;
General update:

Added genassym.cf
Removed lderr which should never have gotten in
Removed lots of dead code from locore.s
Added some softint stuff to intr.c
Added support for halt -p
esp and le both use bus_dmamap_*() functions now
instead of kdvma_mapin()
groundwork for PCI (but we still have no drivers for
any sun4u PCI devices)


# 1.3 04-Jul-1998 jonathan

defopt DDB.


# 1.2 26-Jun-1998 thorpej

defopt COMPAT_SVR4


# 1.1 20-Jun-1998 eeh

branches: 1.1.1;
Initial revision


# 1.429 22-May-2022 andvar

fix various small typos, mainly in comments.


# 1.428 16-May-2022 mrg

try to handle ultrasparc III* "fast ecc error" traps.

i had a sunblade 2500 reset with this trap recently, and the
manual says it should have been recoverable. in particular,
the US IIIv2 manual says in section 12.4.4.2 that the i-cache
won't see this data ever (so nothing needed there), and that
the d-cache needs to be disabled, and all the entries flushed,
and then re-enabled.

tested with a "trap 0x70" from kernel space, that trap.c
converted the "0x170" back to "0x70" (with an ADVANCE). this
code not commited.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 1.427 03-Apr-2021 palle

Improve cpu_idle() by allowing a platform specific implementaion (same logic as the sparc implementation) - currently only used by sun4v


# 1.426 30-Mar-2021 palle

sun4v: handle spill trap properly when trap level is 1 and otherwin is non-zero - ensure that all windows are spilled to the pcb like the sun4u winfixsave code path


# 1.425 22-Feb-2021 palle

branches: 1.425.2;
sun4v: handle spill normal user traps properly when current trap level is 1 - registers are spilled to the PA of the stack to avoid further mmu-related traps, since sun4v only has 2 trap levels


# 1.424 20-Dec-2020 palle

sun4v: add comment in sun4v_tl1_ptbl_miss code path - no functional change


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1
# 1.423 08-Jan-2020 skrll

branches: 1.423.6;
oldlwp is always non-NULL in cpu_switchto so remove the test for NULL.


# 1.422 08-Jan-2020 ad

Hopefully fix some problems seen with MP support on non-x86, in particular
where curcpu() is defined as curlwp->l_cpu:

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

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

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

- Remove some KERNEL_LOCK handling which hasn't been needed for years.


Revision tags: netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 ad-namecache-base netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.421 18-Jul-2019 palle

branches: 1.421.4;
sun4v: added some missing comments to the code in pcbspill


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 1.420 07-Apr-2019 mrg

make trap 0x70 a TRAP() not UTRAP(). we should be able to handle
fast ECC error as a normal trap, and i saw this once a few years
ago but it never repeated so i haven't been able to test this.


# 1.419 08-Feb-2019 palle

sun4v: Improve comment for next_stick_init() - no functional changes


# 1.418 08-Feb-2019 palle

sun4v: initialize %stickcmpr properly when establishing interrupt - fixes issue seen on newer sun4v/SPARC-T5 system where the interrupt never fires.


# 1.417 08-Feb-2019 palle

sun4v: introduce macros for handling spill traps from userlevevel @ traplevel 1 (from OpenBSD) - spill traps at level 1 from userspace now works better


# 1.416 08-Feb-2019 palle

sun4v: add comment documenting the contents of the %g2 register - no functional changes


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126
# 1.415 04-Nov-2018 palle

Ensure that the 64-bit condition codes are used instead of the 32-bit condition codes. ok martin@


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.414 26-May-2018 palle

branches: 1.414.2;
next_stick() - fix typy in comment: tick->stick


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.413 11-Apr-2018 palle

sun4v: handle MMU-related traps properly when they occur at trap level 1. This fixes issues when user-level LWPs access the user-level stack


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 1.412 26-Aug-2017 palle

branches: 1.412.2;
sun4v: Avoid touching the %tick_cmpr register which is not present on never systems (Oracle SPARC Architecture 2011 and beyond). Based on code from OpenBSD locore.s revision 1.177. Tested on both sun4u (qemu and USIII) and sun4v (qemu and T5-2). ok martin@


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2
# 1.411 06-May-2017 palle

sun4v: The %ver register is not available on sun4v - use GET_MAXCWP introduced in rev. 1.361. Verified using qemu (sun4u and sun4v) and on real sun4v hw (t2000)


Revision tags: prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.410 18-Apr-2017 palle

branches: 1.410.2;
sun4v: Add handling of trap 0x06c @ trap level 1 - based on code from OpenBSD, but slightly adapted to NetBSD. verified using qemu


Revision tags: jdolecek-ncq-base pgoyette-localcount-20170320
# 1.409 19-Feb-2017 palle

sun4v: rft_user needs special handling (a manual fill) since the restore instruction may cause the number of trap levels to exceed the maximum for sun4v - inspired by code from the the openbsd rft_user code path - verified using qemu for both sun4u and sun4v


# 1.408 10-Feb-2017 palle

sun4v: Added handling of trap type 0x034 (address alignment error) + fixed typo mmfsa -> mmufsa. Verified for both sun4u and sun4v using qemu.


Revision tags: nick-nhusb-base-20170204
# 1.407 30-Jan-2017 palle

sun4v: Hook up syscall handling to the trap table. Verified using qemu for both sun4u and sun4v.


# 1.406 27-Jan-2017 palle

sun4v: implement missing handling of itsb traps 0x008 and 0x009. Based on code from OpenBSD. Tested using qemu.


Revision tags: bouyer-socketcan-base
# 1.405 07-Jan-2017 palle

branches: 1.405.2;
sun4v: slowtrap() now selects normal globals properly on both sun4u and sun4v platforms. Verified using qemu for both sun4u and sun4v systems


Revision tags: pgoyette-localcount-20170107
# 1.404 05-Jan-2017 palle

sun4v: TRAP_SETUP() updated to set mmu context id properly for both sun4v and sun4u platforms. Verified using qemu for both sun4u and sun4v systems


# 1.403 04-Jan-2017 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x00-0x23 and 0x28-0x30


# 1.402 29-Dec-2016 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x32-0x7f


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.401 20-Sep-2016 nakayama

Fix RAS for 32-bit kernels. trapframe is always 64-bit.


Revision tags: localcount-20160914
# 1.400 23-Aug-2016 palle

sun4v: rework sun4v_datatrap so it works properly when running on a T2-based system like T5120 - for some reason %tl is 0 when entering sun4v_datatrap causing a crash (sir instruction), so ignore the %tl value for now upon entry to sun4v_datatrap - with this fix both T1 and T2 based systems reach the same point - hangs in rft_user after the init process is started


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726
# 1.399 18-Jul-2016 palle

sun4v: handle device interrupts properly - both legacy (sysino) and cookies


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 1.398 04-Jun-2016 palle

branches: 1.398.2;
sun4v: rtf_user now uses macros GET_MMU_CONTEXTID and SET_MMU_CONTEXTID. Tested on sun4u (QEMU) and sun4v (T2000). Parts from OpenBSD.


Revision tags: nick-nhusb-base-20160529
# 1.397 18-May-2016 nakayama

Decrement %tl in trap handler not to make it zero unconditionally
for the nested trap, and remove useless mov.


# 1.396 17-May-2016 palle

sun4v: Implement missng MMU protection trap handling - mostly from OpenBSD


# 1.395 16-May-2016 palle

Avoid assembler-specific defines by using the export keyword in genassym.cf instead


# 1.394 15-May-2016 nakayama

%g1 is not preserved across function call, so load it before
return_from_trap.


# 1.393 13-May-2016 palle

sun4v: add missing implementation of sun4v_datatrap_tl0 so data_access_fault() is called - mostly from OpenBSD


# 1.392 13-May-2016 nakayama

- ci_paddr is always 64-bit.
- intrlev is array of pointer.
- ih_ack is pointer.


# 1.391 10-May-2016 palle

sun4v: make device interrupts work. Introduce a new intrhand_alloc() function for allocation of interrupt handlers and adapt to this. Parts from OpenBSD. ok martin@


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.390 09-Mar-2016 nakayama

32-bit kernels use 32-bit stack.


# 1.389 03-Mar-2016 palle

sun4v: rft_kernel should pay attention to the number of register windows that can be restored. We cannot rely on fill traps to occur, since sun4v only has two trap levels available in privileged mode. Based on code from OpenBSD. ok martin@


# 1.388 14-Feb-2016 palle

sun4v: add breakpoint trap entry to the sun4v trap table


# 1.387 03-Feb-2016 palle

sun4v: extend dmmu_set_secondary_context() to handle both sun4u and sun4v. ok martin@


Revision tags: nick-nhusb-base-20151226
# 1.386 06-Nov-2015 martin

Basically revert r1.246 of locore.s and r1.73 of vm_machdep.c:

Remove special case handling for userland lwps from cpu_lwp_fork,
instead do it in lwp_trampoline when we first return to userland.

which was a stupid idea - since we did now set all fork child's %tstate
(and thus %pstate when back in userland) to the current kernel's userland
default. This meant we lost the address mask bit for 32bit processes and
all memory model details for 64bit ones.

Move it back to cpu_lwp_fork and fix the condition to only do it once when
forking init.


# 1.385 05-Nov-2015 martin

Most of the time return_from_trap already got called with tf->tf_tstate
loaded in register %g1 - make it so for two more callers and remove
the reload of that value.


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606 nick-nhusb-base-20150406
# 1.384 05-Apr-2015 palle

sun4v: Ensure that the TTEs CP and CV bits are the same (both set) for the primary cpu and secondary cpus INTSTACK mappings


# 1.383 01-Apr-2015 palle

sun4v: Implement handling of cpu_mondo trap - from OpenBSD - tested using the Legion simulator


# 1.382 04-Mar-2015 palle

sun4v: revert some of the logic introduced in revision 1.378 - flushw is not necessary on sun4v (OpenBSD patches the flushw instruction to a nop instruction) - with these changes the kernel reaches cpu_boot_secondary_processors() when running in the Legion simulator (crashes due to missing handling of cpu_mondo_trap)


# 1.381 02-Mar-2015 nakayama

prom_printf converts "\n" to "\r\n" internally, so omit "\r".


# 1.380 02-Mar-2015 nakayama

PANICSTACK is a pointer itself, not a pointer to pointer.


# 1.379 02-Mar-2015 nakayama

Use panic stack temporarily for calling prom_printf in a trap
handler.

It seems that openfirmware cannot handle over 4GB pointers, and
stack pointers may point to over 4GB since VA layout was rearranged
by rev 1.33 of vmparam.h. Therefore, use panic stack to avoid
panicking in OF_write used by prom_printf.


# 1.378 23-Feb-2015 palle

sun4v: sparc_interupt - ensure that the trap level and globals level are the same when the flushw instruction is issued - othwise warnings occur when using the sun4v Legion simulator.


Revision tags: nick-nhusb-base
# 1.377 26-Oct-2014 palle

branches: 1.377.2;
sun4v: Create CLEANWIN0 and CLEANWIN1 macros for handling clean window traps on both sun4u and sun4u (based on the original code inlined in the sun4u trap table). Update trap tables accordingly for both sun4u and sun4v. Ok martin@


# 1.376 24-Oct-2014 nakayama

Fix typo in comment.


# 1.375 18-Oct-2014 snj

src is too big these days to tolerate superfluous apostrophes. It's
"its", people!


# 1.374 15-Oct-2014 palle

sun4v: fixed bug causing the real address to be incorrectly calculated as zero


# 1.373 24-Sep-2014 palle

sun4v: add code to enable startup of secondary cpus on both sun4u and sun4v systems - ok martin@


# 1.372 04-Sep-2014 palle

sun4v: All cpus must be setup with a TSB descriptor, so pmap_setup_tsb_sun4v() must take a pointer to the TSB descriptor


# 1.371 31-Aug-2014 palle

sun4v: Split the NORMAL_GLOBALS and ALTERNATE_GLOBALS macros to _SUN4U and _SUN4V variants. Rework the return_from_trap logic to use the new variants so it is possible to use a global register as scratch register.


# 1.370 14-Aug-2014 nakayama

Add missing delay slot in DEBUG kernel.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.369 30-Jul-2014 palle

branches: 1.369.2;
Fix ALTERNATE_GLOBALS so it at least works on sun4u - using a scratch register is not a good idea...


# 1.368 27-Jul-2014 palle

sun4v: Introduce a new macro ALTERNATE_GLOBALS (matching NORMAL_GLOBALS). Two new helper macros ENABLE_INTERRUPTS and DISABLE_INTERRUPTS are also created. With these changes the GENERIC.UP kernel will reach rootmount on sun4v systems - ok martin@


# 1.367 26-Jul-2014 palle

Improved the NORMAL_GLOBALS macro in the sun4u case, so only the relevant bit (AG) in %pstate is affected - ok martin@


# 1.366 24-Jul-2014 palle

sun4v: add missing spill/fill handling for trap level 1 + cosmetic changes to comments for trap level 0 entries


# 1.365 19-Jul-2014 palle

sun4v: Introduce a NORMAL_GLOBALS macro - first used in sparc_interrupt - other relevant uses will be handled as the sun4v work is progressesing - ok martin@


# 1.364 16-Jul-2014 palle

sun4v: Introduce SET_MMU_CONTEXTID macro for setting the mmu context id on both sun4u and sun4v


# 1.363 13-Jul-2014 palle

sun4v: add interrupt handling to sun4v trap table


# 1.362 13-Jul-2014 palle

Bugfix: add missing cmp instruction to GET_MAXCWP macro


# 1.361 30-Jun-2014 palle

sun4v: The maximum number of register windows is a constant and thus not available via the %ver register (sun4u only). Introduce a macro GET_MAXCWP that handles this, so cpu_switchto() works properly on sun4v. Other relevant reference to %ver can be adapted to use GET_MAXCWP as the sun4v port progresses. OK martin@


# 1.360 31-May-2014 palle

sun4v: added missing dtsb miss handling for trap level 1 - with this update the kernel now reaches configure() on sun4v systems


# 1.359 30-May-2014 palle

Remove debugging code introduced by accident in locore.s revision 1.357


Revision tags: yamt-pagecache-base9 rmind-smpnet-nbase rmind-smpnet-base
# 1.358 05-May-2014 palle

sun4v: the trap base address should be assigned to %l1 so %tba is properly setup later in the code - now the kernel gets as far as printing the copyright disclaimer, kernel version and total and available memory before crashing


# 1.357 21-Apr-2014 palle

sun4v: Update comment: modified -> access


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.356 21-Feb-2014 palle

branches: 1.356.2;
sun4v: Rename TLB_ defines to SUN4U_TLB_ so entries created using TSB_DATA() are properly setup for sun4u and sun4v. Relocate the cputyp variable from autoconf.c to locore.s and make it const in param.h so optimized code can be generated. Parts from OpenBSD. Optimization suggested by nakayama@. OK martin@, mrg@, nakayama@


# 1.355 31-Jan-2014 tsutsui

defined(LKM) -> defined(MODULAR)


# 1.354 26-Jan-2014 palle

sun4v: Add handling of spill/fill and dtsb miss traps (with a XXX to be handled later)


# 1.353 07-Jan-2014 palle

sun4v: trap table setup - currently populated with dummy entries which will be properly implemented later - parts from OpenBSD - OK martin@


# 1.352 29-Dec-2013 nakayama

Make buildable w/o options SUN4V.


# 1.351 27-Dec-2013 palle

a) make the hunt through the cpus list more generic b) sun4v: ensure that the interrupt stack is mapped permanently and the TSB is setup properly - parts from OpenBSD. OK martin@


# 1.350 06-Dec-2013 nakayama

Increase an interrupt depth only in the case of hardware interrupts,
and remove the ci_idepth trick in softint_fastintr.

Fixes the following diagnostic panic reported in port-sparc64.

panic: kernel diagnostic assertion "!cpu_intr_p()" failed: file
"../../../../kern/subr_xcall.c", line 351


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 1.349 24-May-2013 nakayama

branches: 1.349.2;
Disable interrupts after calling data_access_error as with
data_access_fault.


# 1.348 28-Apr-2013 nakayama

Use macros in machine/asm.h instead of locally defined, and
introduce CASPTRA for casxa/casa.


Revision tags: agc-symver-base
# 1.347 23-Jan-2013 martin

Fix sparc64_ipi_ccall by adding proper trap setup.
Fixes xcall(9) problems, as exposed by pserialize(9). Noticed by
J. Hannken-Illjes, cause pointed out by Takeshi Nakayama.


# 1.346 23-Jan-2013 martin

Sligthly clean up the (by default unused) #ifdef TRAPS_USE_IG


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.345 10-Nov-2012 nakayama

Revise comment.


# 1.344 10-Nov-2012 nakayama

Use macro instead of magic number.


# 1.343 09-Nov-2012 nakayama

Make setstick() and getstick() to inline functions.


# 1.342 08-Nov-2012 macallan

use system tick timer instead of %tick on UltraSPARC-III-ish CPUs
review & fixes by Takeshi Nakayama


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.341 17-Mar-2012 mrg

branches: 1.341.2;
port the corrected ECC error handling code from freebsd. i noticed my U10
took one of these and then hang. it shouldn't hang, there's a 'sir' here that
doesn't seem to reset properly. oh well.

tested by simulated a trap via 'ta 0x10' and considering that the same, but
it hasn't been tested against a real ECC error yet.


Revision tags: jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base4
# 1.340 03-Mar-2012 nakayama

Fix the root cause of the hack "disable optimizations for uvm_bio.c
on 32 bit kernels".

gcc converts a division in the calculation of UBC_UMAP_ADDR macro
to multiplication (smul or combination of add/sll), and the
register of its result contains a garbage in upper 32 bits (the
upper 32 bits of smul/add/sll's result isn't zero cleared).

Then it passes to pseg_get{,_real} through pmap_extract without the
zero clear of upper 32 bits in the optimization case. So the
result of pseg_get and pmap_extact sometimes gets screwed up.


Revision tags: jmcneill-usbmp-base5 jmcneill-usbmp-base3
# 1.339 19-Feb-2012 rmind

Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.


Revision tags: jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.338 04-Sep-2011 nakayama

branches: 1.338.2; 1.338.6; 1.338.8;
ih_pil is an interrupt level, not an interrupt mask.


# 1.337 27-Jul-2011 nakayama

ivec is assigned to hardware, so count its event counter up in
interrupt_vector, not in softint, and do some optimization.


# 1.336 20-Jul-2011 macallan

add per ivec event counters


# 1.335 12-Jul-2011 mrg

rename sparc64 BLOCK_SIZE and BLOCK_ALIGN to have SPARC64_ prefixes.
for the assembler files, define the old names to the new names
since using the new names cause ugliness due to longer identifer
names, and reduces churn.

fixes build issues in dtv and vaguely makes <machine/psl.h> slightly
less name-space invasive.


# 1.334 18-Jun-2011 nakayama

Add fast softint(9) support for sparc64.

Reviewed on port-sparc64.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 1.333 12-May-2011 mrg

branches: 1.333.2;
first steps towards fujitsu SPARC64 support:

- SPARC64 systems have interrupts with upto 14 bits set, but we only look
at the first 11 bits. trim non IPI interrupts to 11 bits


Revision tags: uebayasi-xip-base7 bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 jym-xensuspend-nbase jym-xensuspend-base
# 1.332 20-Dec-2010 matt

branches: 1.332.2;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.


Revision tags: uebayasi-xip-base6 uebayasi-xip-base5 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 1.331 10-Jul-2010 nakayama

Clear the upper word explicitly before combining two 32-bit values to 64-bit
on 32-bit kernels.


# 1.330 23-May-2010 martin

Split copy related functions out of locore.s into copy.S, move functions
only needed on multiprocessors into mp_subr.S.


# 1.329 17-May-2010 martin

Simplify primary CPU startup slightly by using the fact that our cpuinfo's
curpcb pointer points to the uarea/pcb of lwp0 and by remembering the pointer
to this cpuinfo, thus avoiding a few CPUINFO_VA references.


Revision tags: uebayasi-xip-base1
# 1.328 20-Mar-2010 chs

fix copy{in,out}{,str}() to return the error returned by uvm_fault().
fixes PR 41813.


Revision tags: yamt-nfs-mp-base9
# 1.327 10-Mar-2010 mrg

branches: 1.327.2;
XXX: workaround we'd like to remove when pmap / uvm locking is cleaned up:

- rename pseg_get() and pseg_set() to pseg_get_real() and pseg_set_real().
- if USE_LOCKSAFE_PSEG_GETSET is defined, which it current is by default,
define pseg_[gs]et() in terms of functions that take a new pseg_lock
mutex at IPL_VM while calling into the real functions.

this seems to avoid the pseg_set() crashes we've seen:
1 - spare needed, when pseg_get() just worked for this pmap
2 - the 2rd ldxa via ASI_PHYS_CACHED in pseg_set() loads garbage
into %o4, and causes the 3rd ldxa to fault


# 1.326 08-Mar-2010 mrg

blast_dcache() SMP friendly:

- blast_dcache() becomes sp_blast_dcache(dcache_size, dcache_line_size)
- new smp_blast_dcache(sparc64_cpuset_t) that blasts the D$ on this cpuset
- sparc64_ipi_blast_dcache() to support the above
- in pmap_remove_all(), when freeing mmu contexts for this pmap, mark
the set of cpus to blast the d$ on as well and convert the
blast_dcache() call into smp_blast_dcache() on the cpus who ran this
pmap, or, sp_blast_dcache(dcache_size, dcache_line_size)
- convert the remaining blast_dcache() in machdep.c to sp_blast_dcache()
- in pmap_destroy()/pmap_remove_all() take the pmap_lock() always since
we assert it is held always.

with these changes, NFS builds on the U60 seem to be stable now, and
the USIII machines also can often complete a single build.sh run now,
diskful or diskless.


reviewed by mlelstv and partially by martin, tested by martin and myself,
with some ideas from chuq as well.


# 1.325 07-Mar-2010 mrg

need _ALIGN in locore.h as well, for DEBUG kernels.


# 1.324 07-Mar-2010 mrg

gas has supported SPARC ".empty" for a long while; get rid of an
ancient workaround.


# 1.323 06-Mar-2010 mrg

move the memcpy/memset implementations out into their own file, with the
block copy versions as well. move some of the definitions in locore.s
into a new locore.h.

locore.s is almost 2000 lines shorter with this change.


# 1.322 04-Mar-2010 mrg

- in _bus_dmamap_unload(), pmap_page_protect() and pmap_clear_reference()
switch the dcache_flush_page() into a dcache_flush_page_all()
- in both pmap_kremove()/pmap_remove(), remove the blast_dcache() call
and replace it with dcache_flush_page_all()
- in pmap_get_page() [used to allocate PTP's], always call pmap_zero_page(pa)
- flush the dcache of the dst page in pmap_{copy,zero}_page() by redirecting
throught a C function that calls the (renamed) asm. the old asm code had a
comment about needing to do this...
- add a couple of membar #Sync's that the USIII manual recommends


based on discussions with chuq@, skrll@ and martin@.


these help my SB2000 / SB2500 with both disk / nfs builds and other tasks,
sometimes lasting for several hours before failing or asserting.


# 1.321 24-Feb-2010 mrg

when handing back page table pages to UVM, flush them from the dcache
on all CPUs.

idea from skrll@, and makes my disk-based SB2000 stable.

tested on U60, SB2000 and SB2500.


# 1.320 24-Feb-2010 mrg

- re-introduce sp_tlb_flush_pte() and sp_tlb_flush_all() that call
the right USI/USIII version.
- define tlb_flush_pte() in terms of sp_tlb_flush_pte() for the
!MULTIPROCESSOR case

this centralises some CPU_IS_USIII_UP() tests.


# 1.319 22-Feb-2010 mrg

move {dump,print}_[id]tlb() into a separate file.


# 1.318 22-Feb-2010 mrg

- store the maximum [id]cache size / line size for each cpu

- remove patch_kernel() since it isn't necessary and has been patching
the wrong thing in general.

- implement USIII versions of blast_icache(), dcache_flush_page() and
cache_flush_phys(). use the newly recorded cache size/line sizes.

- in winfixsave, flush the D$ with the right size index and ops. this
kills one of the wrong tag->inval patches.

- for blast_dcache(), use the newly recorded dcache_size/line_size.

- for blast_icache(), use the newly recorded cache size/line sizes.
for the USIII verison, disable the I$ while writing to ASI_ICACHE_TAG.


these changes removed several hard coded cache sizes values, some very
wrong kernel patching, and seem to make the current failure modes for
USIII less common, but not gone.


# 1.317 15-Feb-2010 mrg

- don't flush 32-bit entries for 64-bit code, it does not seem to be
necessary. #define TLB_FLUSH_LOWVA to turn it back on.
- remove the #if 0'd code in sparc64_ipi_flush_pte_usiii(), i have
verified that it is not required.
- add a missing membar #Sync to sp_tlb_flush_pte_usiii().


# 1.316 15-Feb-2010 nakayama

Fix linker error of GENERIC32 kernel.


# 1.315 15-Feb-2010 mrg

use TLB_SIZE_SPITFIRE in a couple of places, and note that the
{print,dump}_[id]tlb() versions are currently spitfire specific.


# 1.314 15-Feb-2010 mrg

introduce a new patch_kernel() and call it from the end of bootstrap().
use it to patch up TLB flush instructions that don't match for USI/II
and later. we can also hopefully use this to make GENERIC.MP minimally
expensive on single CPU machines as well.

this is the last piece needed to get GENERIC/GENERIC.MP to boot on the
USIII* machines.

idea and some initial code from openbsd.


# 1.313 13-Feb-2010 mrg

remove KTR support. it's never been a working part of netbsd src tree.


# 1.312 09-Feb-2010 wiz

Fix typo in comment.


Revision tags: uebayasi-xip-base
# 1.311 06-Feb-2010 mrg

branches: 1.311.2;
- properly map the schizo interrupt registers, so we can use the normal
virtual mappings to access them.
- with the above fxied, kill SCHIZO_BUS_SPACE_BROKEN, and introduce
an options CHEETAH for now, that disables the SPITFIRE code in locore.
- merge schizo_init() into schizo_attach() and clean up the softc a bit.


with this we are only one more step away from GENERIC booting on USIII
machines.


# 1.310 02-Feb-2010 mrg

- split sp_tlb_flush_pte() and switchtoctx() into sp_tlb_flush_pte_us()/
sp_tlb_flush_pte_usiii() and switchtoctx_us()/switchtoctx_usiii() and
implement the latter while i'm here. it works ... sometimes i think,
but also sometimes panics/hangs.
- fix a comment in sparc64_ipi_flush_pte_usiii()


# 1.309 02-Feb-2010 mrg

for now, reduce a few #ifdef SPITFIRE cases by introducing a new
ASI_DCACHE_TAG_OR_INV that is either ASI_DCACHE_{TAG,_INVALIDATE}.

increase the common code in cache_flush_phys().


# 1.308 01-Feb-2010 mrg

- sp_tlb_flush_all() becomes sp_tlb_flush_all_us() and sp_tlb_flush_all_usiii()
- sparc64_ipi_flush_pte() becomes sparc64_ipi_flush_pte_us() and
sparc64_ipi_flush_pte_usiii()
- add some commented out code to disable interrupts and raise the traplevel
in sparc64_ipi_flush_pte_usiii()
- cache_flush_phys() was missing a little of code in the cheetah case


# 1.307 01-Feb-2010 mrg

for USIII, use the new "tlb demap all" operation in sp_tlb_flush_all()


# 1.306 01-Feb-2010 mrg

remove unused icache_flush_page() implementation.


# 1.305 23-Jan-2010 mrg

remove the final uses of DATA_START.

now we can remove the 16KB space reserved at the start of the data segment,
and i now understand why i wrote this now removed comment 3.5 years ago:
"this shouldn't be needed... but kernel usually hangs without it"


# 1.304 23-Jan-2010 mrg

remove most of the code that writes debugging info DATA_START + offset.


# 1.303 23-Jan-2010 mrg

remove CHKPT() macro and uses. it's likely wrong in SMP land and probably should
be replaced with KTR-style uses if necessary.


# 1.302 23-Jan-2010 mrg

fix a comment.


Revision tags: matt-premerge-20091211
# 1.301 10-Dec-2009 rmind

Rename L_ADDR to L_PCB and amend some comments accordingly.


# 1.300 05-Dec-2009 mrg

- adjust the PA mask to the 43 bits supported by USIII.
- rework the spitfire/cheetah cache_flush_phys() to avoid several #ifdefs
- add a membar #Sync after sparc64_ipi_drop_fpstate (probably unnecessary)


# 1.299 30-Nov-2009 nakayama

sp_tlb_flush_pte for cheetah:
- restore interrupts properly in case of %tl > 0.


# 1.298 30-Nov-2009 mrg

stablize UP USIII support by blocking interrupts around sp_tlb_flush_pte()
i was seeing stack corruption while taking an interrupt in this function.

get USIII SMP mostly working by implementing the cheetah version of
sparc64_ipi_flush_pte().


SMP support is still not entirely stable. i can reproducably get a:

panic: fpusave_lwp ipi didn't

while running build.sh, when an awk process is exiting. other simple
heavy work loads do not crash for me right now.


# 1.297 30-Nov-2009 mrg

delete some no longer used code:
- smp_tlb_flush_ctx()
- smp_tlb_flush_all()
- sparc64_ipi_flush_ctx()
- sparc64_ipi_flush_all()
- sp_tlb_flush_ctx()


# 1.296 29-Nov-2009 nakayama

- calculate end PA correctly.
- wrap more spitfire specific (flushing I$) code.
- fix inverted #if condition for flushing I$ (and restore ASI_ICACHE_TAG).


# 1.295 28-Nov-2009 mrg

implement enough code to get SB2000/SB2500 booting to multiuser. does
not last long if you use it, but an idle machine has stayed up 10 hours.

- for the !SPITFIRE case, use ASI_DCACHE_INVALIDATE instead of
ASI_DCACHE_TAG when clearing tlb entries. from openbsd.

- convert some comment "! Not yet" into "WRITEME", so that attempting
to build a USIII MULTIPROCESSOR kernel fails to build until the code
is written.

- add some more WRITEME's for the above.

- implement a !SPITFIRE version of sp_tlb_flush_all(). since there are
no spare regs, for now just always increase %tl around this call. (we
could maybe store a token in %o3 along with the saved %pstate info.)


# 1.294 26-Nov-2009 matt

Kill proc0paddr. Use lwp0.l_addr instead.


# 1.293 25-Nov-2009 mrg

s/L_ADDR/L_PCB/, requested by rmind.


# 1.292 17-Oct-2009 nakayama

Wrap unused code with #if 0 which is called from #if 0'ed code.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5
# 1.291 30-May-2009 martin

cpu_setfunc() can not use lwp_trampoline, as that has additional lwp startup
semantics. Use a simpler setfunc_trampoline instead.


# 1.290 18-May-2009 nakayama

Remove random() from locore.s since it is in libkern.


# 1.289 16-May-2009 nakayama

Remove clear %tick in locore.s since it is cleared at cpu_initclocks() in
clock.c.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 nick-hppapmap-base mjf-devfs2-base
# 1.288 15-Dec-2008 mrg

restore some old "intrdebug" code, but leave it under NOT_DEBUG. most
of it works, but one that prints func/arg for each handler is not very
stable...

for now, while schizo bus space pointer accesses aren't working, add
a SCHIZO_BUS_SPACE_BROKEN option so you can build a kernel with schizo.

with this, and the prior schizo interrupt fix, you can now fail to run
/sbin/init!


Revision tags: haad-dm-base2 haad-nbase2 haad-dm-base
# 1.287 09-Dec-2008 martin

Get rid of get_maxctx() - it doesn't work on newer cpus and we will have
to find a better way for (some) sun4v machines - all sun4u use 13 bit
contexts anyway.


Revision tags: netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 ad-audiomp2-base netbsd-5-base
# 1.286 30-Oct-2008 nakayama

branches: 1.286.2; 1.286.6;
Wrap more code specific to USE_BLOCK_STORE_LOAD.


Revision tags: matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4
# 1.285 05-Oct-2008 nakayama

branches: 1.285.2;
- in flushing cache, use 32 as increment/decrement value to match the
cache line size.
- remove useless restore of %asi.
- remove nop in delay slot if we can.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 1.284 10-Jul-2008 nakayama

Use proper CCR.


# 1.283 10-Jul-2008 nakayama

sparc64_ipi_save_fpstate:
- use primary MMU context for consistency with other trap/interrupt handlers.

sparc64_ipi_save_fpstate, savefpstate:
- avoid storing fp registers as we can.

sparc64_ipi_save_fpstate, savefpstate, loadfpstate:
- remove unaligned case since buffers allocated with pool_cache are ensured
64-byte aligned.

Ok by martin@.


# 1.282 02-Jul-2008 nakayama

branches: 1.282.2;
UltraSPARCs don't have floating point queue, and reading %fq regsiter
will cause illegal instruction trap. So remove the code handling them.


# 1.281 29-Jun-2008 nakayama

Wrap IPI calls with #ifdef MULTIPROCESSOR.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.280 14-Jun-2008 nakayama

Close unterminated comment.
Fix unexpected behavior in case of loadfpstate from unaligned buffer.


Revision tags: yamt-pf42-base3
# 1.279 31-May-2008 nakayama

branches: 1.279.2;
openfirmware_exit:
- disable interrupts with %pstate.
- prepare 64-bit stack and enable 64-bit addresses for 32-bit SMP kernels.


Revision tags: hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 yamt-nfs-mp-base yamt-pf42-base
# 1.278 16-Apr-2008 nakayama

branches: 1.278.2; 1.278.4; 1.278.6;
Disable TRAPSTATS which was accidentally enabled when yamt-idlelwp branch
was merged.

Ok by martin@.


# 1.277 14-Apr-2008 nakayama

Remove sparc64_ipi_sync_tick.

Since we can use counter-timer as timecounter instead of %tick on SMP kernel,
it is not necessary to sync all CPUs %tick registers.


# 1.276 14-Apr-2008 nakayama

Add workaround for BB_ERRATA_1 on writing to TICK_CMPR register in
next_tick(). If writing to TICK_CMPR fails, we lose hardclock interrupt
on secondary CPUs.

About BB_ERRATA_1 from comment in OpenSolaris:

/*
* Writes to the TICK_COMPARE register sometimes fail on blackbird modules.
* The failure occurs only when the following instruction decodes to wr or
* wrpr. The workaround is to immediately follow writes to TICK_COMPARE
* with a read, thus stalling the pipe and keeping following instructions
* from causing data corruption. Aligning to a quadword will ensure these
* two instructions are not split due to i$ misses.
*/


# 1.275 28-Mar-2008 nakayama

Don't read fplwp content in delay slot for considering the case fplwp was
modifiled.

Reported by Chris Ross on port-sparc64.


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.274 20-Mar-2008 nakayama

- remove disabling interrupt in IPI.
- unused VA bits in MMU demap is 13 bits, not 12 bits.


# 1.273 18-Mar-2008 nakayama

Fix a race when increment an interrupt level event counter.


# 1.272 17-Mar-2008 nakayama

Fix a race condition in IPI handlers of save/drop fpstate, from OpenBSD.
Reported and tested by martin@.


# 1.271 17-Mar-2008 nakayama

Make schedintr interrupt handler per-CPU.
While there rename tickintr interrupt handler and share initialization
code with schedintr.


# 1.270 14-Mar-2008 nakayama

Improve IPI handling:
- make IPI takes two arguments.
- add IPI event counters per-CPU.
- implement IPI functions which were missing or broken.
- insert DELAY while halting primary CPU in IPI handler.


# 1.269 02-Mar-2008 nakayama

- make interrupt pending list per-CPU.
- make tickintr() MP-safe.
- remove unused port-sparc derived interrupt code.

Ok by martin@.


# 1.268 02-Mar-2008 nakayama

Don't get IPI handler argument (from bogus address), and ack IRQ twice.


# 1.267 28-Feb-2008 martin

Make TSBs and MMU contexts per-cpu.


Revision tags: nick-net80211-sync-base mjf-devfs-base hpcarm-cleanup-base
# 1.266 26-Jan-2008 nakayama

branches: 1.266.2; 1.266.6;
Fix for 32-bit kernels.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.265 15-Jan-2008 skrll

Store a sensbile PCB_PC value in snapshot - the return point.

This helps gdb somewhat.

OK'd by martin.


# 1.264 14-Jan-2008 martin

Fix register name typo/copy&pasto - %g6 is not %o6/%sp.
From OpenBSD.


Revision tags: matt-armv6-base
# 1.263 06-Jan-2008 martin

Load the next cpu_info pointer with LDPTR instead of ld.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2
# 1.262 09-Dec-2007 martin

branches: 1.262.2;
Provide cpu_intr_p(), at least for non-MULTIPROCESSOR kernels.
Based on suggestions by Andrew Doran.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.261 22-Oct-2007 martin

branches: 1.261.2; 1.261.4; 1.261.6;
Remove an unused .globl declaration


Revision tags: yamt-x86pmap-base4
# 1.260 17-Oct-2007 garbled

Merge the ppcoea-renovation branch to HEAD.

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

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

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base ppcoea-renovation-base vmlocking-base
# 1.259 09-Sep-2007 martin

branches: 1.259.4;
Make cpufrequency and friends per cpu values.
Prepare a hz tick interrupt on secondary CPUs via %tick, but do not
enable it yet, as it breaks ddb.


# 1.258 09-Sep-2007 martin

Do not ACK IPIs before we finished loading all arguments.


# 1.257 06-Sep-2007 martin

Remove the (now unused) second 64k page mapped per CPU.
From matthew green, with small changes by me. All bugs are mine.


# 1.256 25-Aug-2007 martin

branches: 1.256.2;
Remove INITSTACK completely - at the time we used to switch to it, we
already have access to all of lwp0 and it's uarea - so we can switch
to the correct lwp0 stack easily before calling main.


# 1.255 25-Aug-2007 martin

When exiting to OF, use the interrupt stack instead of INITSTACK


# 1.254 25-Aug-2007 martin

Rework cpu_mp_startup slightly:
- temporarily use the cpu's interrupt stack untill we are ready
to access non-OF-based mappings, then directly switch to the cpu's
idlelwp's uarea stack
- disable interrupts untill we are ready to call C code


# 1.253 13-Aug-2007 macallan

remove two restore without matching save


Revision tags: nick-csl-alignment-base matt-mips64-base mjf-ufs-trans-base
# 1.252 06-Jul-2007 martin

branches: 1.252.4; 1.252.8;
A few nits for 32bit SMP kernels, noticed by mrg.
While there, simplify the fpstate IPIs a bit.


# 1.251 05-Jul-2007 martin

sparc64_ipi_save_fpstate is not a leaf function - create a full grown
stack frame.


# 1.250 28-May-2007 mrg

clean up cpu_switchto() a little - no need to flushw or membar
excessively. optimise an rdpr. tested by tnn.


# 1.249 23-May-2007 martin

Fix a stupid bug in the save_fpstate ipi, which caused overwriting of
struct lwp of the lwp owning the fpu. Fix clearing the fplwp - %o0 will
not survive the call to savefpstate - duh!


# 1.248 20-May-2007 martin

Simplify tf_tstate setting when leaving for userland initially - I seem
to have confused the if with the else case of the previous C code.
Funny that it worked at all.


# 1.247 20-May-2007 martin

cpu_switchto() has to return it's first arg, always. This differs from
my reading of the documentation, but helps in the real world and seems
to be what other ports do.


# 1.246 20-May-2007 martin

Remove special case handling for userland lwps from cpu_lwp_fork, instead
do it in lwp_trampoline when we first return to userland.


# 1.245 19-May-2007 martin

cpu_idle is a leaf function, so we better "return from leaf".
Use return value from cpu_switchto for previous lwp in lwp_trampoline.
Also shamelessly steal a comment from uwe written for sparc that explains
all this.
Thanks to tnn, mrg, and uwe for helping to debug this.


# 1.244 17-May-2007 yamt

merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base ad-audiomp-base
# 1.243 22-Feb-2007 martin

branches: 1.243.4; 1.243.6; 1.243.12;
uvm.page_idle_zero now is a bool, not a 32bit value any more.


# 1.242 21-Feb-2007 mrg

shave 9 insns off the tsb setup in cpu_initialize & cpu_mp_startup.


# 1.241 21-Feb-2007 martin

Get rid of unused (thus always zero) "curlwp" variable hidden in assembler
code (C code always uses a cpuinfo based macro).


# 1.240 18-Feb-2007 martin

Make use of another call delay slot, pointed out by uwe.


# 1.239 18-Feb-2007 martin

Make use of a call delay slot and avoid a bogus EMPTY.
Spotted by Juergen Hannken-Illjes, with input from Andrew Doran and
Valeriy E. Ushakov.


# 1.238 18-Feb-2007 martin

Whitespace cosmetics


# 1.237 18-Feb-2007 martin

Backout previous: EMPTY was misused


# 1.236 18-Feb-2007 martin

Make EMPTY expand to nop with gas, as it is used to mark empty branch
delay slots.


# 1.235 15-Feb-2007 martin

branches: 1.235.2;
Fix obvious copy&pasto in SCHED_DEBUG register usage.


Revision tags: post-newlock2-merge
# 1.234 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.233 25-Dec-2006 wiz

Spell "relevant" correctly. From Zafer Aydogan.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.232 25-Oct-2006 mrg

branches: 1.232.2; 1.232.4;
- note that __idle_u should go away but doing so breaks things
- fix several comments to reality
- clean up the #ifdef NO_VCACHE code slightly
- use call instead of set/jmpl
- remove a couple of unnecessary stores to curlwp


Revision tags: yamt-splraiseipl-base2
# 1.231 18-Oct-2006 rjs

Clean up some comments. Cosmetic change to use correct structure
offset names.

Optimize out two instructions from sparc64_ipi_save_fpstate and
sparc64_ipi_drop_fpstate.


# 1.230 17-Oct-2006 mrg

allocate 128KB (as opposed to 64KB) per-cpu, and place the interrupt
stack, cpu_info structure, panicstack, idle uarea and normal kernel
stack in here. the idle uarea and kernel stack are in the 2nd 64KB
page. the interrupt stack and cpu_info structure are as the same
place in the 1st 64KB page, and the panicstack grows down from the
top of this page. update comments in param.h to suit (XXX: a lot
of these constants should move to a header file that will not pollute
the name space so much.) map these pages identically between
cpu_initialise() and cpu_mp_startup(), and deal with the two 64KB
pages in pmap_extract(). keep an unmapped 64KB page between them.

don't initialise the unused "ci_eintstack" member of the cpu_info
structure

use constants to initialise many addresses in the cpu_info structure,
consolidating these assignments from cpu0 and cpu>0

delete u0/estack0/panicstack from locore.s

clean up some wrong comments in locore.s

fix a 32bit-only bug in cpu_mp_startup().

delete 'u0' entirely.


this fixes recent random lossage seen on port-sparc64: processes
stuck in RUN state, data faults, and hangs.


# 1.229 04-Oct-2006 mrg

use call instead of set/jmpl. add an entry point for idle that expects
sched_lock to be unlocked, and use this for non-boot cpu's. complete a
comment describing how registers in idle_switch are expected to be set.


# 1.228 03-Oct-2006 mrg

use the same SAVE_LOCALS_INS definition for 32 bit and 64 bit kernels.
refactor TRAP_SETUP() a little between these two versions to be more alike.


# 1.227 03-Oct-2006 mrg

use the correct size/type for MP variables (pointers and longs).

a 32 bit MULTIPROCESSOR kernel now builds (and crashes quickly.)


# 1.226 03-Oct-2006 mrg

in the 64bit version of SAVE_LOCAL_INS, s/BIAS/STKB/ to allow future
sharing of the 32 and 64 bit versions of the {TRAP,INTR}_SETUP macros.


# 1.225 19-Sep-2006 mrg

- remove some way old FP setup/teardown code
- put the block memcpy/memset inside #ifdef USE_BLOCK_STORE_LOAD which
is (now) defined.

no functional change, same .o is generated.


# 1.224 19-Sep-2006 mrg

re-order the changes in rev 1.217 to give registers a little bit of
time to settle between usage, like it was before hand.


# 1.223 19-Sep-2006 mrg

- remove a wrong comment.
- add a new entry point for idle called idle_switch that is called by
cpu_switch() in the MP case when sched_whichqs is zero, properly
setting up the idle stack. from petrov@ via martin@.


# 1.222 19-Sep-2006 mrg

rework interrupt_vector() slightly:
- for the IPI case, avoid loading the address of intrlev into %g3
- remove some NOT_DEBUG code
- load the interrupt argument #2 in the delay slot

this removes 2 nops during interrupt processing for the normal
case, and an additional 2 ALU instructions for IPIs


# 1.221 18-Sep-2006 mrg

- sparc64_ipi_halt(): we shouldn't return from sparc64_ipi_halt_thiscpu()
so replace a branch with a 'sir'
- in #if 0 code, in sparc64_ipi_flush_pte() and sparc64_ipi_flush_ctx()
save/restore the out registers that the sp_tlb_flush_xxx() versions
around calling them
- in sp_tlb_flush_pte() and sp_tlb_flush_ctx(), replace global register
usage with out registers so that we don't clobber the (alternate)
global registers when these are called from IPI context


# 1.220 18-Sep-2006 mrg

- remove an extra 'sir' that followed one in a macro
- add some named labels to some spill/fill handlers
- remove 2 unused strings


Revision tags: yamt-splraiseipl-base
# 1.219 18-Sep-2006 martin

branches: 1.219.2;
Lazy FPU handling for the MULTIPROCESSOR case


# 1.218 16-Sep-2006 nakayama

From OpenBSD:
- reload %fprs for checking it again.
- use symbolic names for checking in %fprs.

revision 1.51
date: 2005/07/18 14:50:11; author: deraadt; state: Exp; lines: +2 -1
cache a copy of the fprs so we know what fp restore we should do after

revision 1.50
date: 2005/07/14 01:46:13; author: deraadt; state: Exp; lines: +4 -4
use symbolic names for checking in %fprs, as above


# 1.217 16-Sep-2006 nakayama

Fix a couple of %y register save/restore errors, inspired from OpenBSD.

revision 1.44
date: 2004/04/23 04:18:17; author: marc; state: Exp; lines: +5 -4

fix a couple of %y register save/restore errors
1) don't save %y in a register that is later used before restoring %y
2) always restore %y after calling a signal handler
tested by drahn@, OK pval


# 1.216 15-Sep-2006 martin

Do not bother to save fpu state when we are about to get rid of it.


Revision tags: yamt-pdpolicy-base9
# 1.215 13-Sep-2006 mrg

SMP cleanup. provide support for multiple CPUs in DDB. (SMP itself
is still not working.)

cpu.h:
- add a pointer for DDB regs in SMP environment to struct cpu_info
- remove the #defines for mp_pause_cpus() and mp_resume_cpus()
cpuset.h:
- remove CPUSET_ALL() and rename CPUSET_ALL_BUT() to CPUSET_EXCEPT()
from petrov.
db_machdep.h:
- rename the members of db_regs_t to be the same as sparc
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- redo DDB_REGS to no longer be a pointer to a fixed data structure
but to one allocated per-cpu when ddb is entered
- move a bunch of prototypes in here
intr.h:
- remove SPARC64_IPI_* macros, no longer used
db_interface.c:
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- make "nil" a 64 bit entity
- change the ddb register access methods to work in multiprocessor
environment, it is now very much like sparc does it
- in kdb_trap() avoid accessing ddb_regp when it is NULL
- update several messages to include the cpu number
- unpause other cpus much later when resuming from ddb
- rename db_lock() to db_lock_cmd(), as the sparc-like code has
db_lock as a simple lock
- remove "mach cpus" command, and replace it with "mach cpu" (which
does the same) and also implement "mach cpu N" to switch to
another cpus saved trapframe
db_trace.c:
- update for the ddb_regs -> ddb_regp change
genassym.cf:
- add TF_KSTACK as offsetof(struct trapframe64, tf_kstack)
ipifuncs.c:
- overhaul extensively
- remove all normal interrupt handlers as IPI's, we now handle
them all specially in locore.s:interrupt_vector
- add a simplelock around all ipi functions - it's not safe for
multiple cpus to be sending IPI's to each other right now
- rename sparc64_ipi_pause() to sparc64_ipi_pause_thiscpu() and,
if DDB is configured, enable it to save the passed-in trapframe
to a db_regs_t for this cpu's saved DDB registers.
- remove the "ipimask" system (SPARC64_IPI_* macros) and instead
pass functions directly
- in sparc64_send_ipi() always set the interrupt arguments to 0,
the address and argument of the to be called function. (the
argument right now is the address of ipi_tlb_args variable, and
part of the reason why only one CPU can send IPI's at a time.)
don't wait forever for an IPI to complete. some of this is
from petrov.
- rename sparc64_ipi_{halt,pause,resume}_cpus() to
mp_{halt,pause,resume}_cpus()
- new function mp_cpu_is_paused() used to avoid access missing
saved DDB registers
- actually broadcast the flush in smp_tlb_flush_pte(),
smp_tlb_flush_ctx() and smp_tlb_flush_all(). the other end may
not do anything yet in the pte/ctx cases yet...
kgdb_machdep.c:
- rework for changed member names in db_regs_t.
locore.s:
- shave an instruction from syscall_setup() (set + ld -> sethi + ld)
- remove some old dead debug code
- add new sparc64_ipi_halt IPI entry point, it just calls the C
vector to shutdown.
- add new sparc64_ipi_pause IPI entry point, which just traps into
the debugger using the normal breakpoint trap. these cpus usually
lose the race in db_interface.c:db_suspend_others() and end up
calling the C vector sparc64_ipi_pause_thiscpu().
- add #if 0'ed code to sparc64_ipi_flush_{pte,ctx}() IPI entry
points to call the sp_ version of these functions.
- in rft_kernel (return from trap, kernel), check to see if the
%tpc is at the sparc64_ipi_pause_trap_point and if so, call
"done" not "retry"
- rework cpu_switch slightly: save the passed-in lwp instead of
using the one in curlwp
- in cpu_loadproc(), save the new lwp not the old lwp, to curlwp
- in cpu_initialize(), set %tl to zero as well. from petrov.
- in cpu_exit(), fix a load register confusion. from petrov.
- change some "set" in delay branch to "mov".
machdep.c:
- deal with function renames
pmap.c:
- remove a spurious space
trap.c:
- remove unused "trapstats" variable
- add cpu number to a couple of messages


# 1.214 09-Sep-2006 mrg

significant clean up effort, largely from petrov@ via martin@.

- fix a bunch of comments for proc->lwp
- remove old TRAPTRACE, NOT_DEBUG, etc. code that has bit-rotted
- put some older DEBUG code under NOT_DEBUG
- add a bunch of new debugging/tracing code ("KTR") that depends on
other changes not yet present.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base yamt-pdpolicy-base5 chap-midi-base simonb-timecounters-base rpaulo-netinet-merge-pcb-base
# 1.213 14-May-2006 elad

branches: 1.213.6; 1.213.8;
integrate kauth.


# 1.212 12-May-2006 skrll

Fix some comments.


Revision tags: elad-kernelauth-base
# 1.211 09-May-2006 rjs

Load CPCB in cpu_mp_startup.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.210 11-Feb-2006 cdi

branches: 1.210.2; 1.210.4; 1.210.6;
ANSIfication: u_intN_t -> uintN_t, use ANSI function declarations/definitions
instead of K&R ones.


# 1.209 27-Jan-2006 cdi

branches: 1.209.2; 1.209.4;
Alter sparc64 bootstrap, catch up to ofwboot v1.9:

- Accept bootinfo structure passed down from ofwboot v1.9
- Drop kernel re-mapping code
- Use permanent 4MB mappings provided by the loader instead
- Change kernel entry address to point directly at the code instead of pointing
at the trap table's first slot. This allows the bootloader to detect
those kernels which are aware of the new boot scheme
- Due to the changes in kernel mapping code, alter secondary CPU bootstrap
code to use trampoline just like FreeBSD does (some FreeBSD code is used
here as well)


# 1.208 12-Jan-2006 cdi

Fix a typo: %g0 should be used instead of %o0 when initializing FPU in dostart:
and cpu_mp_startup:, %o0 is not even initialized at this point.


# 1.207 11-Dec-2005 christos

branches: 1.207.2;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 1.206 10-Jul-2005 christos

Re-factor syscall, and make it use syscall_{plain,fancy}.


# 1.205 31-May-2005 chs

branches: 1.205.2;
remove vestigal {,e}intr{names,cnt} symbols now that vmstat doesn't need them.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.204 12-Feb-2005 chs

branches: 1.204.4; 1.204.6; 1.204.8;
in sparc_interrupt(), wait to enable interrupts until just before calling
the handler and disable them again right after the handler returns.
we don't want another hardware interrupt coming in while we're mucking
with the list pointers. also, clear the intrhand's ih_pending pointer
before calling the handler rather than after, so that if another interrupt
comes in while the handler is running, we can put the intrhand back on
the list so it will be called again.

in send_softint(), disable interrupts via %pstate instead of %pil, so that
hardware interrupts at higher levels are blocked while we manipulate the
intrpending list. also, if the intrhand already has ih_pending set,
don't bother poking the SET_SOFTINT register again, since being on the list
implies that there is already a softint pending in the hardware.

these appear to fix PR 21750 (the "sleep forever" problem).

while I'm here, remove more vestiges of the !INTRLIST softint stuff
(code and comments). and in sparc64_ipi_flush_all(), interrupts are
already disabled so we don't need to fiddle with %pstate.


Revision tags: yamt-km-base2
# 1.203 30-Jan-2005 martin

Remove the no long usefull variants selected by undefining INTRLIST and
INTR_INTERLOCK to improve readability. Same object code generated as before.


Revision tags: yamt-km-base
# 1.202 16-Jan-2005 chs

branches: 1.202.2;
use ENTRY_NOPROFILE() for various entry points,
stack traces work better that way.


Revision tags: kent-audio1-beforemerge kent-audio1-base
# 1.201 03-Dec-2004 chs

branches: 1.201.4;
remove cache_flush_virt() and PADDRT, they're no longer used.
allocate a stack frame for blast_dcache() when profiling so it shows up.
in dcache_flush_page(), use a stride of 32 instead of 16 to match the
cache line size. correct various comments.


# 1.200 08-Nov-2004 petrov

Don't compile sparc64_ipi functions when UP.


# 1.199 25-Oct-2004 martin

No need to clear %o1 when returning a 64 bit integer from pseg_get if we
are compiling for a 64 bit kernel.


# 1.198 24-Jul-2004 nakayama

Change interrupt pending list end value to -1, to avoid linking an
interrupt handler twice.

It may fix "sleep forever" bug.


# 1.197 09-Apr-2004 petrov

Clean-up unused defines and variables.


Revision tags: netbsd-2-0-base
# 1.196 26-Mar-2004 petrov

branches: 1.196.2;
Use want_resched from cpu_info area.


# 1.195 23-Mar-2004 martin

Replace intrcnts by evcnts. XXX - needs slight tweaking for MULTIPROCESSOR.


# 1.194 14-Mar-2004 chs

checkpoint of MP work from dennis and myself. includes cross-processor
interrupt framework, a sledgehammer TLB invalidation and misc MP fixes.
doesn't work at all yet.


# 1.193 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.192 19-Jan-2004 martin

Rename switchexit to cpu_exit and g/c the old C implementation of cpu_exit.


# 1.191 18-Jan-2004 martin

Support RAS for 32bit kernels too.


# 1.190 16-Jan-2004 martin

In proc_trampoline don't bother to clear condition codes in the trap
frame, since we no longer rely on this.
While there fix a few comments.


# 1.189 08-Jan-2004 martin

Minor cleanup


# 1.188 06-Jan-2004 martin

Implement restartable atomic sequences (RAS) for sparc64.


# 1.187 06-Jan-2004 petrov

Spinup secondary cpus. Based on codes sent to me by Dennis Chernoivanov
and Chuck Silvers.


# 1.186 04-Jan-2004 jdolecek

update to recent changes - exit2() doesn't exist anymore and the
exit path always calls lwp_exit2()
pointed out Martin Husemann


# 1.185 02-Dec-2003 martin

Minor cleanup: remove unused code, sync a comment with current reality.


# 1.184 25-Nov-2003 cdi

Use per-cpu pcb, curlwp and fplwp rather than global ones. This brings
GENERIC.MP configuration to a usable state.

Approved by petrov@.


# 1.183 24-Nov-2003 cdi

Call 'proc_trampoline_mp' from 'proc_trampoline' in a multiprocessor
configuration. Fix process locking. Approved by petrov@.


# 1.182 20-Nov-2003 petrov

Remove nwindows calculation, it's not used. Set l_cpu in cpu_switch.


# 1.181 09-Nov-2003 martin

Get rid of bcopy/bzero.


# 1.180 26-Oct-2003 christos

Initial siginfo support for sparc64 (untested). COMPAT_16 sigcontext signal
delivery tested.


# 1.179 24-Aug-2003 chs

add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default. the changes
fall into two basic catagories:

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

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

originally from openbsd, adapted for netbsd by me.


# 1.178 08-Jul-2003 cdi

traceit: don't use %g7 as it is to become curcpu() register. Add comments.


# 1.177 18-May-2003 martin

branches: 1.177.2;
Make kernels with options KGDB at least compile.
Still needs some work to make it working.


# 1.176 29-Apr-2003 nakayama

Use BLOCK_ALIGN rather than BLOCK_SIZE for aligning a pointer.


# 1.175 27-Apr-2003 ragge

Preserve the symbol table in the LKM || KSYMS cases also.


# 1.174 04-Apr-2003 petrov

use branch slot in pmap_copy_page.


# 1.173 24-Mar-2003 nakayama

Divide `set' instruction in delay slot (from OpenBSD change to rev 1.30).


# 1.172 10-Feb-2003 martin

Remove some #if 0 code and a few XXX marked membars w/o proper
justification for their existence.


# 1.171 09-Feb-2003 martin

Remove left over pieces from reusing the signal trampoline for upcalls.
This should fix signal delivery for 32bit kernels.


# 1.170 05-Feb-2003 nakayama

Switch to use cycle counter (%tick) based microtime().

This is derived from alpha/microtime.c and i386/tsc_microtime.c,
and will share with both ports.

This should fix PR port-sparc64/18452.
(approved by martin)


# 1.169 04-Feb-2003 martin

Fix return value of pseg_set, which I accidently broke in rev. 1.164.

Fix register names in comment and shave off another register (hint
from uwe).


# 1.168 01-Feb-2003 martin

Rearrange register usage in pseg_set a bit and shave off %g4.


# 1.167 01-Feb-2003 martin

Remove a few #ifdef _LP64 by using STPTR/LDPTR macros.
Thanks to Matthew Green for the pointer.


# 1.166 31-Jan-2003 martin

Apply leaf procedure optimization to pseg_set (again).


# 1.165 31-Jan-2003 martin

Make the pmap count resident/wired mappings on the fly instead of
walking the page tables whenever this information is needed.

Add an option PMAP_COUNT_DEBUG to assert the new counts and the
page table walk agree.

The old solution had very bad performance impact, for example
by the high CPU load when running top(1).

Thanks to Simon Burge for pointing at the cause of the problem and
to Valeriy E. Ushakov for optimizing my simple minded assembler code.


# 1.164 27-Jan-2003 martin

Remove unused function pseg_find (which looked quite similar to
pseg_get anyway).


# 1.163 18-Jan-2003 thorpej

Merge the nathanw_sa branch.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.162 16-Jan-2003 petrov

Move dump_dtlb back under DDB.


# 1.161 15-Jan-2003 chs

fix two bugs in my last pmap rework:
- in tlb_flush_all(), don't skip TLB entries with the high bit on,
I was confused about which MMU register it was using. it's also fine
to use the last hardware context.
- in pmap_create(), don't allocate a hardware context for the new pmap.
it's unnecessary, and when this would cause us to recycle all the contexts,
it would result in the current process's context being set to 0
(ie. the kernel's context). the current process could then return to
userspace without going through the context-switch code (and thus without
having a hardware context reallocated). this would lead to user mappings
being entered in the kernel's context later, causing all sorts of trouble.
add some assertions to catch this kind of thing.


Revision tags: fvdl_fs64_base
# 1.160 25-Dec-2002 petrov

new function dump_itlb.


Revision tags: gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.159 22-Sep-2002 chs

many improvements:
- use struct vm_page_md for attaching pv entries to struct vm_page
- change pseg_set()'s return value to indicate whether the spare page
was used as an L2 or L3 PTP.
- use a pool for pv entries instead of malloc().
- put PTPs on a list attached to the pmap so we can free them
more efficiently (by just walking the list) in pmap_destroy().
- use the new pmap_remove_all() interface to avoid flushing the cache and TLB
for each pmap_remove() that's done as we are tearing down an address space.
- in pmap_enter(), handle replacing an existing mapping more efficiently
than just calling pmap_remove() on it. also, skip flushing the
TSB and TLB if there was no previous mapping, since there can't be
anything we need to flush. also, preload the TSB if we're pre-setting
the mod/ref bits.
- allocate hardware contexts like the MIPS pmap:
allocate them all sequentially without reuse, then once we run out
just invalidate all user TLB entries and flush the entire L1 dcache.
- fix pmap_extract() for the case where the va is not page-aligned and
nothing is mapped there.
- fix calculation of TSB size. it was comparing physmem (which is
in units of pages) to constants that only make sense if they are
in units of bytes.
- avoid sleeping in pmap_enter(), instead let the caller do it.
- use pmap_kenter_pa() instead of pmap_enter() where appropriate.
- remove code to handle impossible cases in various functions.
- tweak asm code to pipeline a little better.
- remove many unnecessary spls and membars.
- lots of code cleanup.
- no doubt other stuff that I've forgotten.

the result of all this is that a fork+exit microbenchmark is 34% faster
and a fork+exec+exit microbenchmark is 28% faster.


Revision tags: gehenna-devsw-base
# 1.158 18-Jul-2002 wiz

Spell 'should' correctly.


# 1.157 07-Jun-2002 eeh

Shave 10% off the time needed to flush the D$ through a bit of instruction
reordering.


# 1.156 05-Jun-2002 eeh

Handle improperly aligned stack pointers more cleanly.


# 1.155 04-Jun-2002 eeh

Fix the fork trampoline to properly use the supplied tstate.


# 1.154 31-May-2002 thorpej

Make this work with an ISO C preprocessor.


Revision tags: netbsd-1-6-base
# 1.153 14-May-2002 eeh

branches: 1.153.2; 1.153.4;
Only save locals and ins in trapframes for DEBUG kernels.


# 1.152 04-May-2002 kleink

Add some comments to the CPP conditionals controlling the trap macro
definitions, to ease navigation somewhat.


# 1.151 16-Apr-2002 eeh

Make lots of routines profile-friendly and get rid of some cruft.


Revision tags: eeh-devprop-base
# 1.150 21-Mar-2002 petrov

Not needed debug stuff deleted.


# 1.149 16-Mar-2002 mrg

tell newer binutils that our use of %g2 and %g3 is OK here.


# 1.148 15-Mar-2002 eeh

Cleanup MMU initialization to prevent hangs.


Revision tags: newlock-base ifpoll-base
# 1.147 09-Feb-2002 eeh

branches: 1.147.4;
Fix microsecond calculation in microtime.


# 1.146 07-Feb-2002 eeh

Fix register allocation in microtime().


# 1.145 29-Jan-2002 eeh

Shift the UPAID in the correct direction.


# 1.144 17-Jan-2002 eeh

Be more tolerant of unaligned stack pointers.


# 1.143 17-Jan-2002 eeh

Enable block insns in bcopy and bzero.


# 1.142 16-Jan-2002 eeh

In bcopy use 32-bit comparisons in 32-bit kernels.


# 1.141 16-Jan-2002 eeh

Use correct calculation for the trapframe in softtrap for ILP32.


# 1.140 20-Nov-2001 lukem

- pull in opt_kgdb.h where necessary
- replace opt_kgdb_machdep.h with opt_kgdb.h
- defparam opt_kgdb.h:
KGDB_DEV KGDB_DEVNAME KGDB_DEVADDR KGDB_DEVRATE KGDB_DEVMODE
- move from opt_ddbparam.h to opt_ddb.h:
DDB_FROMCONSOLE DDB_ONPANIC DDB_HISTORY_SIZE DDB_BREAK_CHAR SYMTAB_SPACE
- replace KGDBDEV with KGDB_DEV
- replace KGDBADDR with KGDB_DEVADDR
- replace KGDBMODE with KGDB_DEVMODE
- replace KGDBRATE with KGDB_DEVRATE
- use `9600' instead of `0x2580' for 9600 baud rate
- use correct quotes for options KGDB_DEVNAME="\"com\""
- use correct quotes for options KGDB_DEV="17*256+0"
- remove unnecessary dependancy on Makefile for kgdb_stub.o
- minor whitespace cleanup


Revision tags: thorpej-mips-cache-base thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf
# 1.139 14-Sep-2001 thorpej

branches: 1.139.4;
Don't declare intrhand[] here -- that's taken care of in intr.c.


Revision tags: thorpej-devvp-base
# 1.138 30-Aug-2001 eeh

branches: 1.138.2;
Preliminary UltraSPARC III suport (not enabled yet).


# 1.137 13-Aug-2001 jdolecek

g/c _remque()/_insque(); use the C version in libkern


# 1.136 09-Aug-2001 eeh

Fix context masking lossage caused by last version.


# 1.135 08-Aug-2001 eeh

Clean up the trap code to handle the changes cause by supporting non-faulting
accesses. Also change the parameter order so trap frames are easy to find.


# 1.134 07-Aug-2001 eeh

Make sure C code always has ASI_PRIMARY_NOFAULT in the %asi register so
the compiler will be happy if it ever starts generating speculative loads.


# 1.133 05-Aug-2001 eeh

Add support for non-faulting loads and optimize MMU miss handling paths.


# 1.132 02-Aug-2001 eeh

Fix bcopy.


# 1.131 02-Aug-2001 eeh

Sync bzero w/libc version.


# 1.130 01-Aug-2001 eeh

Integrate fixes from userland memset.


# 1.129 31-Jul-2001 eeh

Code cleanup and optimization.


# 1.128 23-Jul-2001 eeh

Get rid of some debug code that really isn't all that useful any more.


# 1.127 19-Jul-2001 eeh

Do ignore unregistered interrupts instead of faulting.


# 1.126 16-Jul-2001 eeh

Make bcopy a 32-bit friendly.


# 1.125 11-Jul-2001 eeh

Fix problems booting 32-bit kernels and dispatching level-15 interrupts.


# 1.124 08-Jul-2001 eeh

branches: 1.124.2;
Code cleanup. Add block_disable to let you turn on block set/copy routines.


# 1.123 05-Jul-2001 eeh

New block bzero and bcopy.


# 1.122 04-Jul-2001 eeh

Replace old bcopy with a much faster version.


# 1.121 01-Jul-2001 martin

Disable axidently enabled debug code to make -current compile again.


# 1.120 30-Jun-2001 eeh

Use a newer version (still disabled) of block bcopy.


# 1.119 30-Jun-2001 eeh

Fixup fpu save restore, get rid of some unused copy functions, and add
a new bcopy.


# 1.118 21-Jun-2001 eeh

Allow multiple 4MB pages for both kernel text and kernel data.

Note: DEBUG checks will not allow accesses to the hole between
text and data segments, so you may need to update programs that
use libkvm before relocating the start of kernel data.


# 1.117 06-Jun-2001 mrg

extract the netbsd32, sunos, 32 bit svr4 and 64 bit svr4 sigcode out into
separate files, so that compat lkms can link with them as well.


# 1.116 30-May-2001 lukem

add missing #include "opt_kgdb.h"


Revision tags: thorpej_scsipi_beforemerge
# 1.115 25-Apr-2001 simonb

Spell occurred correctly.


Revision tags: thorpej_scsipi_nbase thorpej_scsipi_base
# 1.114 09-Apr-2001 eeh

Interrupt latency fix from sparc port. (Hm. One insn instead of 5).


# 1.113 07-Mar-2001 eeh

Fix inverted preprocessor logic. (Spotted by Charles.)


# 1.112 21-Feb-2001 eeh

branches: 1.112.2;
Add support for 64-bit SVR4 (Solaris 8) binaries.


# 1.111 10-Feb-2001 pk

Fix conditional for svr4 compat inclusion.


# 1.110 05-Feb-2001 eeh

Add signal trampoline for 64-bit svr4 emulations.


# 1.109 31-Dec-2000 eeh

Make INCR() atomic.


# 1.108 29-Dec-2000 eeh

pseg_get tells us whether it really needed that spare page after all.


# 1.107 07-Dec-2000 eeh

Fixup calculating where fpstate should be saved in the signal trampoline
code so it doesn't overwrite something important like the registers.


# 1.106 09-Nov-2000 eeh

Fix ILP32 bug in probe_get().


# 1.105 22-Oct-2000 pk

Restore revision 1.102.

I hope it sticks this time..


# 1.104 20-Oct-2000 eeh

Fix hang in 32-bit kernels caused by relocation of KERNBASE.


# 1.103 04-Oct-2000 eeh

Fix interrupt lossage problem and some cosmetic changes.


# 1.102 01-Oct-2000 pk

cpu_initialize: global registers aren't preserved across calls to
prom_printf(), so replace %g3 with %l7 (which isn't used despite
the `usage' comment).

Also, clean up white-space turds.


# 1.101 29-Sep-2000 eeh

This seems to fix the interrupt lossage of non-debug kernels.


# 1.100 28-Sep-2000 eeh

Fix INTR_SETUP() to properly distinguish kernel and user addresses.

Make microtime() return the correct time on %tick machines.

Re-enable debug stuff in dostart for now to detect kernel mapping issues.


# 1.99 25-Sep-2000 pk

Missing `#if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)'


# 1.98 17-Sep-2000 eeh

Make the improved %tick changes work with machines that use the counter-timer
for the clock.


# 1.97 12-Sep-2000 eeh

Fix new version of microtime.


# 1.96 11-Sep-2000 eeh

(Hopefully) fix clock skew on machines that us %tick for the clock (UIIi).


# 1.95 31-Aug-2000 eeh

Use casx instead of stx to change entries in the page table trees.


# 1.94 23-Aug-2000 eeh

Update the scheduler to the new locking scheme.


# 1.93 10-Aug-2000 eeh

Fix signal delivery.


# 1.92 02-Aug-2000 eeh

Get kernel profiling to work. Now if only gprof worked....


# 1.91 01-Aug-2000 eeh

Overhaul cache flush code and coredump code.


# 1.90 25-Jul-2000 pk

Re-instate a couple of delay slot NOPs marked `XXX spitfire bug?'


# 1.89 24-Jul-2000 mycroft

Optimization to pmap_zero_page(): we only need to use the first 16 FP regs,
as in bzero().


# 1.88 24-Jul-2000 mycroft

Fix a whitespace glitch.


# 1.87 24-Jul-2000 mycroft

Pull in the bzero() changes from libc for real, with a couple of kernel-
specific hacks:
* Make the bias handling depend on STKB, so it switches correctly for 32-bit
kernels.
* Use the 32-bit stw/ld for 32-bit kernels.
* Add a few `-STKB's that were missed in the previous change.


# 1.86 24-Jul-2000 pk

Cosmetic & readability:
- local label cleanup in interrupt handling code;
- in debugging sections when testing `intrdebug': use a unique
local label (97) to enhanced clarity;
- comment-out unused code;
- kill a bug as the satisfying result of doing all of the above.


# 1.85 24-Jul-2000 eeh

Fix stack issues in bzero.


# 1.84 24-Jul-2000 mycroft

Revert the previous change for now. I don't have time to debug it tonight.


# 1.83 23-Jul-2000 mycroft

Copy bzero change from libc.


# 1.82 20-Jul-2000 pk

Since `intrcnt' points to an array of long ints, reserve the appropriate
amount of space depending on _LP64. Provide macros to load/store signed
and unsigned long ints.

Also, make the `intrcnt' and `intrpending' arrays 16 entries long, as on
sparc/v9 interrupt #15 is just a regular interrupt.


# 1.81 19-Jul-2000 eeh

Fix merge problem.


# 1.80 19-Jul-2000 eeh

Disable interrupt interlock using ih->ih_pending field. Seems to cause
more problems than it solves.


# 1.79 19-Jul-2000 eeh

Miscellaneous cleanup.


# 1.78 18-Jul-2000 pk

Correct args usage comment in probeget.
Whitespace cleanup.


# 1.77 18-Jul-2000 pk

probeget: 9 -> 0x9


# 1.76 18-Jul-2000 pk

If `ih_pending' is set simply return from the trap, don't schedule another
soft interrupt.


Revision tags: mrg-merge-1-5-top
# 1.75 18-Jul-2000 pk

openfirmware: don't lower %pil


# 1.74 17-Jul-2000 pk

Kill typos in interrupt code.


# 1.73 17-Jul-2000 pk

probeget: do the same song and dance as ld*a() macros in ctlreg.h do.


# 1.72 14-Jul-2000 eeh

Move some macro definitions out of genassym and into locore.s


# 1.71 08-Jul-2000 mrg

backout part of previous: turn off intrdebug, and another debug message


# 1.70 07-Jul-2000 pk

Changes for readability:
- #define LP64 dependent STACKFRAME macro once
- use a LOAD_ASCIZ macro for setting up the format string
for debug messages.


# 1.69 07-Jul-2000 eeh

Temporary fix to prevent the clock from stopping on UIIi machines.


# 1.68 03-Jul-2000 eeh

Prevent interrupts from being posted if they are active and deprecate polled
interrupts. This seems to eliminate the spurious interrupts.


# 1.67 02-Jul-2000 eeh

Clean up interrupt handling some more.


# 1.66 30-Jun-2000 eeh

Fix interrupt delivery on UltraSPARC IIi machines.


# 1.65 24-Jun-2000 eeh

With these changes the kernel seems almost stable again.


# 1.64 24-Jun-2000 eeh

More VM cleanup:

Move the cpu_info structure above the interrupt stack so it won't
get corrupted if the stack overflows.

Flush the D$ before and after all MMU bypass accesses since the
D$ latches all of those.


# 1.63 23-Jun-2000 eeh

Make probeget() and probeset() really work for a change.


Revision tags: netbsd-1-5-base
# 1.62 19-Jun-2000 eeh

branches: 1.62.2;
Have separate data and text segments, make text read-only.


# 1.61 12-Jun-2000 eeh

Start reorganizing the kernel for MULTIPROCESSOR support.


# 1.60 31-May-2000 thorpej

Add a comment about needing to initialize p_cpu when multiple
processors are supported.


Revision tags: minoura-xpg4dl-base
# 1.59 26-May-2000 thorpej

branches: 1.59.2;
First sweep at scheduler state cleanup. Collect MI scheduler
state into global and per-CPU scheduler state:

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

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

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

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

Tested on i386 and Alpha. Changes are mostly mechanical, but apologies
in advance if it doesn't compile on a particular platform.


# 1.58 26-May-2000 thorpej

Don't set `runtime' here; it's done at the end of mi_switch().
cvS: ----------------------------------------------------------------------


# 1.57 26-May-2000 thorpej

Introduce a new process state distinct from SRUN called SONPROC
which indicates that the process is actually running on a
processor. Test against SONPROC as appropriate rather than
combinations of SRUN and curproc. Update all context switch code
to properly set SONPROC when the process becomes the current
process on the CPU.


# 1.56 22-Apr-2000 eeh

If we trap due to a bad kernel stack, try to switch to the interrupt strack
before breaking into the debugger.


# 1.55 18-Apr-2000 eeh

Prevent the system from getting watchdog reset by returning directly to user
mode if restoring the user window traps. Also reduce the time we run with
%tl>0.


# 1.54 13-Apr-2000 eeh

Apparently gas 2.9.5 (don't ask) does not like to add values to %lo()
directives so move the additions inside %lo() to make it happy.
Hopefully this won't break older versions.


# 1.53 10-Apr-2000 mrg

- fix a speeling error
- rename some numbered labels to be a bit less confusing.
- remove dead code
- fix a debug error message (argh!)


# 1.52 10-Apr-2000 pk

Get a kernel without DDB to build.


# 1.51 16-Mar-2000 eeh

Revamp interrupts again:

Fix a bug causing interrmittent panics in interrupt dispatch.
Use interrupt vectors for softints.
Add a new send_softint interface.
Improved D$ flushing.
Improve traptrace and other debugging enhancements.


Revision tags: chs-ubc2-newbase
# 1.50 16-Jan-2000 eeh

Interrupt handlers return zero if they didn't handle the interrupt.


# 1.49 10-Jan-2000 eeh

Add debugger single-stepping and fix interrupt dispatch bugs.


# 1.48 30-Dec-1999 eeh

Lots of changes:

remove ffs()
add bzero that uses block store insns
save %gsr to fpstate
revert to physical accesses for pmap_zero_page so we don't
have conflicting page mappings
general cleanup.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base fvdl-softdep-base
# 1.47 06-Nov-1999 eeh

Handle zero length properly in copyinstr() copyoutstr() and copystr().


Revision tags: comdex-fall-1999-base
# 1.46 11-Oct-1999 eeh

branches: 1.46.2; 1.46.4;
Update to post 1.4.


# 1.45 05-Oct-1999 eeh

branches: 1.45.2;
Make broken versions of gas happy by using sethi/or instead of set for
(negative) addresses.


# 1.44 17-Sep-1999 thorpej

Centralize the declaration and clearing of `cold'.


Revision tags: chs-ubc2-base
# 1.43 18-Jul-1999 eeh

More fun with pmap.


# 1.42 21-Jun-1999 eeh

Improve TRAPTRACE. Add FLTRACE that only tracks MMU faults.


# 1.41 05-Jun-1999 eeh

Make pbrobeget() and probeset() work for 64-bit values as well. To do this
the arguments are changed so the address is first and the ASI second so we
can have the address in %o0:%o1 and not worry about unused registers.

Also a bit of copyright cleanup.


# 1.40 05-Jun-1999 mrg

update a commit slightly.


# 1.39 30-May-1999 eeh

Add code to support using %tick as the system clock if no "counter-timer" node
is found.


# 1.38 09-May-1999 eeh

Fixup non-DEBUG kernels.


# 1.37 29-Apr-1999 christos

Add sunos_sigcode (32 bit only)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.36 26-Mar-1999 eeh

branches: 1.36.4;
COMPAT_SPARC32 -> COMPAT_NETBSD32


# 1.35 25-Mar-1999 mrg

clean and up make compile


# 1.34 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.33 22-Mar-1999 eeh

Need to set up the pointers properly for partial FPU register stores.


# 1.32 22-Mar-1999 eeh

Flush D$ on bypass accesses.


# 1.31 28-Feb-1999 eeh

Use block load/store in pmap_zero_page()/pmap_copy_page().


# 1.30 17-Feb-1999 eeh

Let's test out vectored interrupts.


# 1.29 15-Feb-1999 hubertf

RCS ID police


# 1.28 11-Feb-1999 mrg

fix a comment pasto.


# 1.27 11-Jan-1999 eeh

Finally fixed 64-bit signal trampoline.


# 1.26 10-Jan-1999 eeh

Handle the symbol table properly in a 32-bit kernel that was booted from a
64-bit bootloader.


# 1.25 09-Jan-1999 eeh

More signal fixup.


Revision tags: kenh-if-detach-base
# 1.24 26-Nov-1998 mycroft

Sync kcopy() with 32-bit SPARC version.


# 1.23 16-Nov-1998 eeh

Fixup the last broken bits of the signal handling code.


Revision tags: chs-ubc-base
# 1.22 08-Oct-1998 eeh

Fix more syscall32 and signal breakage.


# 1.21 22-Sep-1998 eeh

More fixup in the signal area.

64-bit syscall cleanup.

Add emulation for some new FPU insns: conversion to 64-bit long int and
conditional moves.


# 1.20 17-Sep-1998 thorpej

SYS_sigreturn -> SYS___sigreturn14.


# 1.19 13-Sep-1998 eeh

Fixup signal changes (hopefully). However SUN_COMPAT is likely broken by
this and I don't know how to fix it.

We can now exec a 64-bit init through a really ugly hack (don't ask.)


# 1.18 11-Sep-1998 eeh

Add labels for the compat_sparc32 signal trampoline and break -- er -- fix
suword and fuword.


# 1.17 09-Sep-1998 eeh

Don't use %tick for microtime on 32-bit kernels -- breaks gettimeofday.


# 1.16 09-Sep-1998 thorpej

Adjust for the new "reaper" kernel thread: do not free the vmspace and
u-area in machine-dependent code. Instead, call exit2() to schedule
the reaper to free them for us, once it is safe to do so (i.e. we are
no longer running on the dead proc's vmspace and stack).


# 1.15 07-Sep-1998 eeh

Fix data corruption problem caused by broken debug code.


# 1.14 07-Sep-1998 eeh

Add new 64-bit trap vectors.


# 1.13 06-Sep-1998 eeh

32-bit fixup.


# 1.12 06-Sep-1998 eeh

Disable some debug stuff.


# 1.11 05-Sep-1998 eeh

It slices. It dices. It does everything except exec a sparc32_compat init.


# 1.10 02-Sep-1998 eeh

Periodic update: now starts probing devices.


# 1.9 30-Aug-1998 eeh

Some more 64-bit cleanup. Now everything compiles.


# 1.8 29-Aug-1998 eeh

Some more 64-bit-ification.


# 1.7 27-Aug-1998 eeh

Add 64-bit pmap support:

Moved from a two level 512/1024 entry setup mapping 32 (9/10/13) bits
respectively to a three level 1024/1024/1024 entry setup mapping 43
(10/10/10/13) bits. In 32-bit mode we waste about 1/12 pages mapping the high
11 bits. We also only manage 43 of the possible 44 bits of virtual address
space, wasting half of it. Oh well, maybe we'll do better next revision.


Revision tags: PMAP32
# 1.6 26-Aug-1998 mrg

panicstack: is needed outside of DEBUG. use _C_LABEL, and printf not db_printf (incase no ddb!)


# 1.5 13-Aug-1998 eeh

Merge paddr_t changes into the main branch.


Revision tags: eeh-paddr_t-base
# 1.4 07-Jul-1998 eeh

branches: 1.4.2;
General update:

Added genassym.cf
Removed lderr which should never have gotten in
Removed lots of dead code from locore.s
Added some softint stuff to intr.c
Added support for halt -p
esp and le both use bus_dmamap_*() functions now
instead of kdvma_mapin()
groundwork for PCI (but we still have no drivers for
any sun4u PCI devices)


# 1.3 04-Jul-1998 jonathan

defopt DDB.


# 1.2 26-Jun-1998 thorpej

defopt COMPAT_SVR4


# 1.1 20-Jun-1998 eeh

branches: 1.1.1;
Initial revision


Revision tags: thorpej-cfargs-base thorpej-futex-base
# 1.427 03-Apr-2021 palle

Improve cpu_idle() by allowing a platform specific implementaion (same logic as the sparc implementation) - currently only used by sun4v


# 1.426 30-Mar-2021 palle

sun4v: handle spill trap properly when trap level is 1 and otherwin is non-zero - ensure that all windows are spilled to the pcb like the sun4u winfixsave code path


# 1.425 22-Feb-2021 palle

branches: 1.425.2;
sun4v: handle spill normal user traps properly when current trap level is 1 - registers are spilled to the PA of the stack to avoid further mmu-related traps, since sun4v only has 2 trap levels


# 1.424 20-Dec-2020 palle

sun4v: add comment in sun4v_tl1_ptbl_miss code path - no functional change


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1
# 1.423 08-Jan-2020 skrll

branches: 1.423.6;
oldlwp is always non-NULL in cpu_switchto so remove the test for NULL.


# 1.422 08-Jan-2020 ad

Hopefully fix some problems seen with MP support on non-x86, in particular
where curcpu() is defined as curlwp->l_cpu:

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

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

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

- Remove some KERNEL_LOCK handling which hasn't been needed for years.


Revision tags: netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 ad-namecache-base netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.421 18-Jul-2019 palle

branches: 1.421.4;
sun4v: added some missing comments to the code in pcbspill


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 1.420 07-Apr-2019 mrg

make trap 0x70 a TRAP() not UTRAP(). we should be able to handle
fast ECC error as a normal trap, and i saw this once a few years
ago but it never repeated so i haven't been able to test this.


# 1.419 08-Feb-2019 palle

sun4v: Improve comment for next_stick_init() - no functional changes


# 1.418 08-Feb-2019 palle

sun4v: initialize %stickcmpr properly when establishing interrupt - fixes issue seen on newer sun4v/SPARC-T5 system where the interrupt never fires.


# 1.417 08-Feb-2019 palle

sun4v: introduce macros for handling spill traps from userlevevel @ traplevel 1 (from OpenBSD) - spill traps at level 1 from userspace now works better


# 1.416 08-Feb-2019 palle

sun4v: add comment documenting the contents of the %g2 register - no functional changes


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126
# 1.415 04-Nov-2018 palle

Ensure that the 64-bit condition codes are used instead of the 32-bit condition codes. ok martin@


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.414 26-May-2018 palle

branches: 1.414.2;
next_stick() - fix typy in comment: tick->stick


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.413 11-Apr-2018 palle

sun4v: handle MMU-related traps properly when they occur at trap level 1. This fixes issues when user-level LWPs access the user-level stack


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 1.412 26-Aug-2017 palle

branches: 1.412.2;
sun4v: Avoid touching the %tick_cmpr register which is not present on never systems (Oracle SPARC Architecture 2011 and beyond). Based on code from OpenBSD locore.s revision 1.177. Tested on both sun4u (qemu and USIII) and sun4v (qemu and T5-2). ok martin@


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2
# 1.411 06-May-2017 palle

sun4v: The %ver register is not available on sun4v - use GET_MAXCWP introduced in rev. 1.361. Verified using qemu (sun4u and sun4v) and on real sun4v hw (t2000)


Revision tags: prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.410 18-Apr-2017 palle

branches: 1.410.2;
sun4v: Add handling of trap 0x06c @ trap level 1 - based on code from OpenBSD, but slightly adapted to NetBSD. verified using qemu


Revision tags: jdolecek-ncq-base pgoyette-localcount-20170320
# 1.409 19-Feb-2017 palle

sun4v: rft_user needs special handling (a manual fill) since the restore instruction may cause the number of trap levels to exceed the maximum for sun4v - inspired by code from the the openbsd rft_user code path - verified using qemu for both sun4u and sun4v


# 1.408 10-Feb-2017 palle

sun4v: Added handling of trap type 0x034 (address alignment error) + fixed typo mmfsa -> mmufsa. Verified for both sun4u and sun4v using qemu.


Revision tags: nick-nhusb-base-20170204
# 1.407 30-Jan-2017 palle

sun4v: Hook up syscall handling to the trap table. Verified using qemu for both sun4u and sun4v.


# 1.406 27-Jan-2017 palle

sun4v: implement missing handling of itsb traps 0x008 and 0x009. Based on code from OpenBSD. Tested using qemu.


Revision tags: bouyer-socketcan-base
# 1.405 07-Jan-2017 palle

branches: 1.405.2;
sun4v: slowtrap() now selects normal globals properly on both sun4u and sun4v platforms. Verified using qemu for both sun4u and sun4v systems


Revision tags: pgoyette-localcount-20170107
# 1.404 05-Jan-2017 palle

sun4v: TRAP_SETUP() updated to set mmu context id properly for both sun4v and sun4u platforms. Verified using qemu for both sun4u and sun4v systems


# 1.403 04-Jan-2017 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x00-0x23 and 0x28-0x30


# 1.402 29-Dec-2016 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x32-0x7f


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.401 20-Sep-2016 nakayama

Fix RAS for 32-bit kernels. trapframe is always 64-bit.


Revision tags: localcount-20160914
# 1.400 23-Aug-2016 palle

sun4v: rework sun4v_datatrap so it works properly when running on a T2-based system like T5120 - for some reason %tl is 0 when entering sun4v_datatrap causing a crash (sir instruction), so ignore the %tl value for now upon entry to sun4v_datatrap - with this fix both T1 and T2 based systems reach the same point - hangs in rft_user after the init process is started


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726
# 1.399 18-Jul-2016 palle

sun4v: handle device interrupts properly - both legacy (sysino) and cookies


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 1.398 04-Jun-2016 palle

branches: 1.398.2;
sun4v: rtf_user now uses macros GET_MMU_CONTEXTID and SET_MMU_CONTEXTID. Tested on sun4u (QEMU) and sun4v (T2000). Parts from OpenBSD.


Revision tags: nick-nhusb-base-20160529
# 1.397 18-May-2016 nakayama

Decrement %tl in trap handler not to make it zero unconditionally
for the nested trap, and remove useless mov.


# 1.396 17-May-2016 palle

sun4v: Implement missng MMU protection trap handling - mostly from OpenBSD


# 1.395 16-May-2016 palle

Avoid assembler-specific defines by using the export keyword in genassym.cf instead


# 1.394 15-May-2016 nakayama

%g1 is not preserved across function call, so load it before
return_from_trap.


# 1.393 13-May-2016 palle

sun4v: add missing implementation of sun4v_datatrap_tl0 so data_access_fault() is called - mostly from OpenBSD


# 1.392 13-May-2016 nakayama

- ci_paddr is always 64-bit.
- intrlev is array of pointer.
- ih_ack is pointer.


# 1.391 10-May-2016 palle

sun4v: make device interrupts work. Introduce a new intrhand_alloc() function for allocation of interrupt handlers and adapt to this. Parts from OpenBSD. ok martin@


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.390 09-Mar-2016 nakayama

32-bit kernels use 32-bit stack.


# 1.389 03-Mar-2016 palle

sun4v: rft_kernel should pay attention to the number of register windows that can be restored. We cannot rely on fill traps to occur, since sun4v only has two trap levels available in privileged mode. Based on code from OpenBSD. ok martin@


# 1.388 14-Feb-2016 palle

sun4v: add breakpoint trap entry to the sun4v trap table


# 1.387 03-Feb-2016 palle

sun4v: extend dmmu_set_secondary_context() to handle both sun4u and sun4v. ok martin@


Revision tags: nick-nhusb-base-20151226
# 1.386 06-Nov-2015 martin

Basically revert r1.246 of locore.s and r1.73 of vm_machdep.c:

Remove special case handling for userland lwps from cpu_lwp_fork,
instead do it in lwp_trampoline when we first return to userland.

which was a stupid idea - since we did now set all fork child's %tstate
(and thus %pstate when back in userland) to the current kernel's userland
default. This meant we lost the address mask bit for 32bit processes and
all memory model details for 64bit ones.

Move it back to cpu_lwp_fork and fix the condition to only do it once when
forking init.


# 1.385 05-Nov-2015 martin

Most of the time return_from_trap already got called with tf->tf_tstate
loaded in register %g1 - make it so for two more callers and remove
the reload of that value.


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606 nick-nhusb-base-20150406
# 1.384 05-Apr-2015 palle

sun4v: Ensure that the TTEs CP and CV bits are the same (both set) for the primary cpu and secondary cpus INTSTACK mappings


# 1.383 01-Apr-2015 palle

sun4v: Implement handling of cpu_mondo trap - from OpenBSD - tested using the Legion simulator


# 1.382 04-Mar-2015 palle

sun4v: revert some of the logic introduced in revision 1.378 - flushw is not necessary on sun4v (OpenBSD patches the flushw instruction to a nop instruction) - with these changes the kernel reaches cpu_boot_secondary_processors() when running in the Legion simulator (crashes due to missing handling of cpu_mondo_trap)


# 1.381 02-Mar-2015 nakayama

prom_printf converts "\n" to "\r\n" internally, so omit "\r".


# 1.380 02-Mar-2015 nakayama

PANICSTACK is a pointer itself, not a pointer to pointer.


# 1.379 02-Mar-2015 nakayama

Use panic stack temporarily for calling prom_printf in a trap
handler.

It seems that openfirmware cannot handle over 4GB pointers, and
stack pointers may point to over 4GB since VA layout was rearranged
by rev 1.33 of vmparam.h. Therefore, use panic stack to avoid
panicking in OF_write used by prom_printf.


# 1.378 23-Feb-2015 palle

sun4v: sparc_interupt - ensure that the trap level and globals level are the same when the flushw instruction is issued - othwise warnings occur when using the sun4v Legion simulator.


Revision tags: nick-nhusb-base
# 1.377 26-Oct-2014 palle

branches: 1.377.2;
sun4v: Create CLEANWIN0 and CLEANWIN1 macros for handling clean window traps on both sun4u and sun4u (based on the original code inlined in the sun4u trap table). Update trap tables accordingly for both sun4u and sun4v. Ok martin@


# 1.376 24-Oct-2014 nakayama

Fix typo in comment.


# 1.375 18-Oct-2014 snj

src is too big these days to tolerate superfluous apostrophes. It's
"its", people!


# 1.374 15-Oct-2014 palle

sun4v: fixed bug causing the real address to be incorrectly calculated as zero


# 1.373 24-Sep-2014 palle

sun4v: add code to enable startup of secondary cpus on both sun4u and sun4v systems - ok martin@


# 1.372 04-Sep-2014 palle

sun4v: All cpus must be setup with a TSB descriptor, so pmap_setup_tsb_sun4v() must take a pointer to the TSB descriptor


# 1.371 31-Aug-2014 palle

sun4v: Split the NORMAL_GLOBALS and ALTERNATE_GLOBALS macros to _SUN4U and _SUN4V variants. Rework the return_from_trap logic to use the new variants so it is possible to use a global register as scratch register.


# 1.370 14-Aug-2014 nakayama

Add missing delay slot in DEBUG kernel.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.369 30-Jul-2014 palle

branches: 1.369.2;
Fix ALTERNATE_GLOBALS so it at least works on sun4u - using a scratch register is not a good idea...


# 1.368 27-Jul-2014 palle

sun4v: Introduce a new macro ALTERNATE_GLOBALS (matching NORMAL_GLOBALS). Two new helper macros ENABLE_INTERRUPTS and DISABLE_INTERRUPTS are also created. With these changes the GENERIC.UP kernel will reach rootmount on sun4v systems - ok martin@


# 1.367 26-Jul-2014 palle

Improved the NORMAL_GLOBALS macro in the sun4u case, so only the relevant bit (AG) in %pstate is affected - ok martin@


# 1.366 24-Jul-2014 palle

sun4v: add missing spill/fill handling for trap level 1 + cosmetic changes to comments for trap level 0 entries


# 1.365 19-Jul-2014 palle

sun4v: Introduce a NORMAL_GLOBALS macro - first used in sparc_interrupt - other relevant uses will be handled as the sun4v work is progressesing - ok martin@


# 1.364 16-Jul-2014 palle

sun4v: Introduce SET_MMU_CONTEXTID macro for setting the mmu context id on both sun4u and sun4v


# 1.363 13-Jul-2014 palle

sun4v: add interrupt handling to sun4v trap table


# 1.362 13-Jul-2014 palle

Bugfix: add missing cmp instruction to GET_MAXCWP macro


# 1.361 30-Jun-2014 palle

sun4v: The maximum number of register windows is a constant and thus not available via the %ver register (sun4u only). Introduce a macro GET_MAXCWP that handles this, so cpu_switchto() works properly on sun4v. Other relevant reference to %ver can be adapted to use GET_MAXCWP as the sun4v port progresses. OK martin@


# 1.360 31-May-2014 palle

sun4v: added missing dtsb miss handling for trap level 1 - with this update the kernel now reaches configure() on sun4v systems


# 1.359 30-May-2014 palle

Remove debugging code introduced by accident in locore.s revision 1.357


Revision tags: yamt-pagecache-base9 rmind-smpnet-nbase rmind-smpnet-base
# 1.358 05-May-2014 palle

sun4v: the trap base address should be assigned to %l1 so %tba is properly setup later in the code - now the kernel gets as far as printing the copyright disclaimer, kernel version and total and available memory before crashing


# 1.357 21-Apr-2014 palle

sun4v: Update comment: modified -> access


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.356 21-Feb-2014 palle

branches: 1.356.2;
sun4v: Rename TLB_ defines to SUN4U_TLB_ so entries created using TSB_DATA() are properly setup for sun4u and sun4v. Relocate the cputyp variable from autoconf.c to locore.s and make it const in param.h so optimized code can be generated. Parts from OpenBSD. Optimization suggested by nakayama@. OK martin@, mrg@, nakayama@


# 1.355 31-Jan-2014 tsutsui

defined(LKM) -> defined(MODULAR)


# 1.354 26-Jan-2014 palle

sun4v: Add handling of spill/fill and dtsb miss traps (with a XXX to be handled later)


# 1.353 07-Jan-2014 palle

sun4v: trap table setup - currently populated with dummy entries which will be properly implemented later - parts from OpenBSD - OK martin@


# 1.352 29-Dec-2013 nakayama

Make buildable w/o options SUN4V.


# 1.351 27-Dec-2013 palle

a) make the hunt through the cpus list more generic b) sun4v: ensure that the interrupt stack is mapped permanently and the TSB is setup properly - parts from OpenBSD. OK martin@


# 1.350 06-Dec-2013 nakayama

Increase an interrupt depth only in the case of hardware interrupts,
and remove the ci_idepth trick in softint_fastintr.

Fixes the following diagnostic panic reported in port-sparc64.

panic: kernel diagnostic assertion "!cpu_intr_p()" failed: file
"../../../../kern/subr_xcall.c", line 351


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 1.349 24-May-2013 nakayama

branches: 1.349.2;
Disable interrupts after calling data_access_error as with
data_access_fault.


# 1.348 28-Apr-2013 nakayama

Use macros in machine/asm.h instead of locally defined, and
introduce CASPTRA for casxa/casa.


Revision tags: agc-symver-base
# 1.347 23-Jan-2013 martin

Fix sparc64_ipi_ccall by adding proper trap setup.
Fixes xcall(9) problems, as exposed by pserialize(9). Noticed by
J. Hannken-Illjes, cause pointed out by Takeshi Nakayama.


# 1.346 23-Jan-2013 martin

Sligthly clean up the (by default unused) #ifdef TRAPS_USE_IG


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.345 10-Nov-2012 nakayama

Revise comment.


# 1.344 10-Nov-2012 nakayama

Use macro instead of magic number.


# 1.343 09-Nov-2012 nakayama

Make setstick() and getstick() to inline functions.


# 1.342 08-Nov-2012 macallan

use system tick timer instead of %tick on UltraSPARC-III-ish CPUs
review & fixes by Takeshi Nakayama


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.341 17-Mar-2012 mrg

branches: 1.341.2;
port the corrected ECC error handling code from freebsd. i noticed my U10
took one of these and then hang. it shouldn't hang, there's a 'sir' here that
doesn't seem to reset properly. oh well.

tested by simulated a trap via 'ta 0x10' and considering that the same, but
it hasn't been tested against a real ECC error yet.


Revision tags: jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base4
# 1.340 03-Mar-2012 nakayama

Fix the root cause of the hack "disable optimizations for uvm_bio.c
on 32 bit kernels".

gcc converts a division in the calculation of UBC_UMAP_ADDR macro
to multiplication (smul or combination of add/sll), and the
register of its result contains a garbage in upper 32 bits (the
upper 32 bits of smul/add/sll's result isn't zero cleared).

Then it passes to pseg_get{,_real} through pmap_extract without the
zero clear of upper 32 bits in the optimization case. So the
result of pseg_get and pmap_extact sometimes gets screwed up.


Revision tags: jmcneill-usbmp-base5 jmcneill-usbmp-base3
# 1.339 19-Feb-2012 rmind

Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.


Revision tags: jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.338 04-Sep-2011 nakayama

branches: 1.338.2; 1.338.6; 1.338.8;
ih_pil is an interrupt level, not an interrupt mask.


# 1.337 27-Jul-2011 nakayama

ivec is assigned to hardware, so count its event counter up in
interrupt_vector, not in softint, and do some optimization.


# 1.336 20-Jul-2011 macallan

add per ivec event counters


# 1.335 12-Jul-2011 mrg

rename sparc64 BLOCK_SIZE and BLOCK_ALIGN to have SPARC64_ prefixes.
for the assembler files, define the old names to the new names
since using the new names cause ugliness due to longer identifer
names, and reduces churn.

fixes build issues in dtv and vaguely makes <machine/psl.h> slightly
less name-space invasive.


# 1.334 18-Jun-2011 nakayama

Add fast softint(9) support for sparc64.

Reviewed on port-sparc64.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 1.333 12-May-2011 mrg

branches: 1.333.2;
first steps towards fujitsu SPARC64 support:

- SPARC64 systems have interrupts with upto 14 bits set, but we only look
at the first 11 bits. trim non IPI interrupts to 11 bits


Revision tags: uebayasi-xip-base7 bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 jym-xensuspend-nbase jym-xensuspend-base
# 1.332 20-Dec-2010 matt

branches: 1.332.2;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.


Revision tags: uebayasi-xip-base6 uebayasi-xip-base5 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 1.331 10-Jul-2010 nakayama

Clear the upper word explicitly before combining two 32-bit values to 64-bit
on 32-bit kernels.


# 1.330 23-May-2010 martin

Split copy related functions out of locore.s into copy.S, move functions
only needed on multiprocessors into mp_subr.S.


# 1.329 17-May-2010 martin

Simplify primary CPU startup slightly by using the fact that our cpuinfo's
curpcb pointer points to the uarea/pcb of lwp0 and by remembering the pointer
to this cpuinfo, thus avoiding a few CPUINFO_VA references.


Revision tags: uebayasi-xip-base1
# 1.328 20-Mar-2010 chs

fix copy{in,out}{,str}() to return the error returned by uvm_fault().
fixes PR 41813.


Revision tags: yamt-nfs-mp-base9
# 1.327 10-Mar-2010 mrg

branches: 1.327.2;
XXX: workaround we'd like to remove when pmap / uvm locking is cleaned up:

- rename pseg_get() and pseg_set() to pseg_get_real() and pseg_set_real().
- if USE_LOCKSAFE_PSEG_GETSET is defined, which it current is by default,
define pseg_[gs]et() in terms of functions that take a new pseg_lock
mutex at IPL_VM while calling into the real functions.

this seems to avoid the pseg_set() crashes we've seen:
1 - spare needed, when pseg_get() just worked for this pmap
2 - the 2rd ldxa via ASI_PHYS_CACHED in pseg_set() loads garbage
into %o4, and causes the 3rd ldxa to fault


# 1.326 08-Mar-2010 mrg

blast_dcache() SMP friendly:

- blast_dcache() becomes sp_blast_dcache(dcache_size, dcache_line_size)
- new smp_blast_dcache(sparc64_cpuset_t) that blasts the D$ on this cpuset
- sparc64_ipi_blast_dcache() to support the above
- in pmap_remove_all(), when freeing mmu contexts for this pmap, mark
the set of cpus to blast the d$ on as well and convert the
blast_dcache() call into smp_blast_dcache() on the cpus who ran this
pmap, or, sp_blast_dcache(dcache_size, dcache_line_size)
- convert the remaining blast_dcache() in machdep.c to sp_blast_dcache()
- in pmap_destroy()/pmap_remove_all() take the pmap_lock() always since
we assert it is held always.

with these changes, NFS builds on the U60 seem to be stable now, and
the USIII machines also can often complete a single build.sh run now,
diskful or diskless.


reviewed by mlelstv and partially by martin, tested by martin and myself,
with some ideas from chuq as well.


# 1.325 07-Mar-2010 mrg

need _ALIGN in locore.h as well, for DEBUG kernels.


# 1.324 07-Mar-2010 mrg

gas has supported SPARC ".empty" for a long while; get rid of an
ancient workaround.


# 1.323 06-Mar-2010 mrg

move the memcpy/memset implementations out into their own file, with the
block copy versions as well. move some of the definitions in locore.s
into a new locore.h.

locore.s is almost 2000 lines shorter with this change.


# 1.322 04-Mar-2010 mrg

- in _bus_dmamap_unload(), pmap_page_protect() and pmap_clear_reference()
switch the dcache_flush_page() into a dcache_flush_page_all()
- in both pmap_kremove()/pmap_remove(), remove the blast_dcache() call
and replace it with dcache_flush_page_all()
- in pmap_get_page() [used to allocate PTP's], always call pmap_zero_page(pa)
- flush the dcache of the dst page in pmap_{copy,zero}_page() by redirecting
throught a C function that calls the (renamed) asm. the old asm code had a
comment about needing to do this...
- add a couple of membar #Sync's that the USIII manual recommends


based on discussions with chuq@, skrll@ and martin@.


these help my SB2000 / SB2500 with both disk / nfs builds and other tasks,
sometimes lasting for several hours before failing or asserting.


# 1.321 24-Feb-2010 mrg

when handing back page table pages to UVM, flush them from the dcache
on all CPUs.

idea from skrll@, and makes my disk-based SB2000 stable.

tested on U60, SB2000 and SB2500.


# 1.320 24-Feb-2010 mrg

- re-introduce sp_tlb_flush_pte() and sp_tlb_flush_all() that call
the right USI/USIII version.
- define tlb_flush_pte() in terms of sp_tlb_flush_pte() for the
!MULTIPROCESSOR case

this centralises some CPU_IS_USIII_UP() tests.


# 1.319 22-Feb-2010 mrg

move {dump,print}_[id]tlb() into a separate file.


# 1.318 22-Feb-2010 mrg

- store the maximum [id]cache size / line size for each cpu

- remove patch_kernel() since it isn't necessary and has been patching
the wrong thing in general.

- implement USIII versions of blast_icache(), dcache_flush_page() and
cache_flush_phys(). use the newly recorded cache size/line sizes.

- in winfixsave, flush the D$ with the right size index and ops. this
kills one of the wrong tag->inval patches.

- for blast_dcache(), use the newly recorded dcache_size/line_size.

- for blast_icache(), use the newly recorded cache size/line sizes.
for the USIII verison, disable the I$ while writing to ASI_ICACHE_TAG.


these changes removed several hard coded cache sizes values, some very
wrong kernel patching, and seem to make the current failure modes for
USIII less common, but not gone.


# 1.317 15-Feb-2010 mrg

- don't flush 32-bit entries for 64-bit code, it does not seem to be
necessary. #define TLB_FLUSH_LOWVA to turn it back on.
- remove the #if 0'd code in sparc64_ipi_flush_pte_usiii(), i have
verified that it is not required.
- add a missing membar #Sync to sp_tlb_flush_pte_usiii().


# 1.316 15-Feb-2010 nakayama

Fix linker error of GENERIC32 kernel.


# 1.315 15-Feb-2010 mrg

use TLB_SIZE_SPITFIRE in a couple of places, and note that the
{print,dump}_[id]tlb() versions are currently spitfire specific.


# 1.314 15-Feb-2010 mrg

introduce a new patch_kernel() and call it from the end of bootstrap().
use it to patch up TLB flush instructions that don't match for USI/II
and later. we can also hopefully use this to make GENERIC.MP minimally
expensive on single CPU machines as well.

this is the last piece needed to get GENERIC/GENERIC.MP to boot on the
USIII* machines.

idea and some initial code from openbsd.


# 1.313 13-Feb-2010 mrg

remove KTR support. it's never been a working part of netbsd src tree.


# 1.312 09-Feb-2010 wiz

Fix typo in comment.


Revision tags: uebayasi-xip-base
# 1.311 06-Feb-2010 mrg

branches: 1.311.2;
- properly map the schizo interrupt registers, so we can use the normal
virtual mappings to access them.
- with the above fxied, kill SCHIZO_BUS_SPACE_BROKEN, and introduce
an options CHEETAH for now, that disables the SPITFIRE code in locore.
- merge schizo_init() into schizo_attach() and clean up the softc a bit.


with this we are only one more step away from GENERIC booting on USIII
machines.


# 1.310 02-Feb-2010 mrg

- split sp_tlb_flush_pte() and switchtoctx() into sp_tlb_flush_pte_us()/
sp_tlb_flush_pte_usiii() and switchtoctx_us()/switchtoctx_usiii() and
implement the latter while i'm here. it works ... sometimes i think,
but also sometimes panics/hangs.
- fix a comment in sparc64_ipi_flush_pte_usiii()


# 1.309 02-Feb-2010 mrg

for now, reduce a few #ifdef SPITFIRE cases by introducing a new
ASI_DCACHE_TAG_OR_INV that is either ASI_DCACHE_{TAG,_INVALIDATE}.

increase the common code in cache_flush_phys().


# 1.308 01-Feb-2010 mrg

- sp_tlb_flush_all() becomes sp_tlb_flush_all_us() and sp_tlb_flush_all_usiii()
- sparc64_ipi_flush_pte() becomes sparc64_ipi_flush_pte_us() and
sparc64_ipi_flush_pte_usiii()
- add some commented out code to disable interrupts and raise the traplevel
in sparc64_ipi_flush_pte_usiii()
- cache_flush_phys() was missing a little of code in the cheetah case


# 1.307 01-Feb-2010 mrg

for USIII, use the new "tlb demap all" operation in sp_tlb_flush_all()


# 1.306 01-Feb-2010 mrg

remove unused icache_flush_page() implementation.


# 1.305 23-Jan-2010 mrg

remove the final uses of DATA_START.

now we can remove the 16KB space reserved at the start of the data segment,
and i now understand why i wrote this now removed comment 3.5 years ago:
"this shouldn't be needed... but kernel usually hangs without it"


# 1.304 23-Jan-2010 mrg

remove most of the code that writes debugging info DATA_START + offset.


# 1.303 23-Jan-2010 mrg

remove CHKPT() macro and uses. it's likely wrong in SMP land and probably should
be replaced with KTR-style uses if necessary.


# 1.302 23-Jan-2010 mrg

fix a comment.


Revision tags: matt-premerge-20091211
# 1.301 10-Dec-2009 rmind

Rename L_ADDR to L_PCB and amend some comments accordingly.


# 1.300 05-Dec-2009 mrg

- adjust the PA mask to the 43 bits supported by USIII.
- rework the spitfire/cheetah cache_flush_phys() to avoid several #ifdefs
- add a membar #Sync after sparc64_ipi_drop_fpstate (probably unnecessary)


# 1.299 30-Nov-2009 nakayama

sp_tlb_flush_pte for cheetah:
- restore interrupts properly in case of %tl > 0.


# 1.298 30-Nov-2009 mrg

stablize UP USIII support by blocking interrupts around sp_tlb_flush_pte()
i was seeing stack corruption while taking an interrupt in this function.

get USIII SMP mostly working by implementing the cheetah version of
sparc64_ipi_flush_pte().


SMP support is still not entirely stable. i can reproducably get a:

panic: fpusave_lwp ipi didn't

while running build.sh, when an awk process is exiting. other simple
heavy work loads do not crash for me right now.


# 1.297 30-Nov-2009 mrg

delete some no longer used code:
- smp_tlb_flush_ctx()
- smp_tlb_flush_all()
- sparc64_ipi_flush_ctx()
- sparc64_ipi_flush_all()
- sp_tlb_flush_ctx()


# 1.296 29-Nov-2009 nakayama

- calculate end PA correctly.
- wrap more spitfire specific (flushing I$) code.
- fix inverted #if condition for flushing I$ (and restore ASI_ICACHE_TAG).


# 1.295 28-Nov-2009 mrg

implement enough code to get SB2000/SB2500 booting to multiuser. does
not last long if you use it, but an idle machine has stayed up 10 hours.

- for the !SPITFIRE case, use ASI_DCACHE_INVALIDATE instead of
ASI_DCACHE_TAG when clearing tlb entries. from openbsd.

- convert some comment "! Not yet" into "WRITEME", so that attempting
to build a USIII MULTIPROCESSOR kernel fails to build until the code
is written.

- add some more WRITEME's for the above.

- implement a !SPITFIRE version of sp_tlb_flush_all(). since there are
no spare regs, for now just always increase %tl around this call. (we
could maybe store a token in %o3 along with the saved %pstate info.)


# 1.294 26-Nov-2009 matt

Kill proc0paddr. Use lwp0.l_addr instead.


# 1.293 25-Nov-2009 mrg

s/L_ADDR/L_PCB/, requested by rmind.


# 1.292 17-Oct-2009 nakayama

Wrap unused code with #if 0 which is called from #if 0'ed code.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5
# 1.291 30-May-2009 martin

cpu_setfunc() can not use lwp_trampoline, as that has additional lwp startup
semantics. Use a simpler setfunc_trampoline instead.


# 1.290 18-May-2009 nakayama

Remove random() from locore.s since it is in libkern.


# 1.289 16-May-2009 nakayama

Remove clear %tick in locore.s since it is cleared at cpu_initclocks() in
clock.c.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 nick-hppapmap-base mjf-devfs2-base
# 1.288 15-Dec-2008 mrg

restore some old "intrdebug" code, but leave it under NOT_DEBUG. most
of it works, but one that prints func/arg for each handler is not very
stable...

for now, while schizo bus space pointer accesses aren't working, add
a SCHIZO_BUS_SPACE_BROKEN option so you can build a kernel with schizo.

with this, and the prior schizo interrupt fix, you can now fail to run
/sbin/init!


Revision tags: haad-dm-base2 haad-nbase2 haad-dm-base
# 1.287 09-Dec-2008 martin

Get rid of get_maxctx() - it doesn't work on newer cpus and we will have
to find a better way for (some) sun4v machines - all sun4u use 13 bit
contexts anyway.


Revision tags: netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 ad-audiomp2-base netbsd-5-base
# 1.286 30-Oct-2008 nakayama

branches: 1.286.2; 1.286.6;
Wrap more code specific to USE_BLOCK_STORE_LOAD.


Revision tags: matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4
# 1.285 05-Oct-2008 nakayama

branches: 1.285.2;
- in flushing cache, use 32 as increment/decrement value to match the
cache line size.
- remove useless restore of %asi.
- remove nop in delay slot if we can.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 1.284 10-Jul-2008 nakayama

Use proper CCR.


# 1.283 10-Jul-2008 nakayama

sparc64_ipi_save_fpstate:
- use primary MMU context for consistency with other trap/interrupt handlers.

sparc64_ipi_save_fpstate, savefpstate:
- avoid storing fp registers as we can.

sparc64_ipi_save_fpstate, savefpstate, loadfpstate:
- remove unaligned case since buffers allocated with pool_cache are ensured
64-byte aligned.

Ok by martin@.


# 1.282 02-Jul-2008 nakayama

branches: 1.282.2;
UltraSPARCs don't have floating point queue, and reading %fq regsiter
will cause illegal instruction trap. So remove the code handling them.


# 1.281 29-Jun-2008 nakayama

Wrap IPI calls with #ifdef MULTIPROCESSOR.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.280 14-Jun-2008 nakayama

Close unterminated comment.
Fix unexpected behavior in case of loadfpstate from unaligned buffer.


Revision tags: yamt-pf42-base3
# 1.279 31-May-2008 nakayama

branches: 1.279.2;
openfirmware_exit:
- disable interrupts with %pstate.
- prepare 64-bit stack and enable 64-bit addresses for 32-bit SMP kernels.


Revision tags: hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 yamt-nfs-mp-base yamt-pf42-base
# 1.278 16-Apr-2008 nakayama

branches: 1.278.2; 1.278.4; 1.278.6;
Disable TRAPSTATS which was accidentally enabled when yamt-idlelwp branch
was merged.

Ok by martin@.


# 1.277 14-Apr-2008 nakayama

Remove sparc64_ipi_sync_tick.

Since we can use counter-timer as timecounter instead of %tick on SMP kernel,
it is not necessary to sync all CPUs %tick registers.


# 1.276 14-Apr-2008 nakayama

Add workaround for BB_ERRATA_1 on writing to TICK_CMPR register in
next_tick(). If writing to TICK_CMPR fails, we lose hardclock interrupt
on secondary CPUs.

About BB_ERRATA_1 from comment in OpenSolaris:

/*
* Writes to the TICK_COMPARE register sometimes fail on blackbird modules.
* The failure occurs only when the following instruction decodes to wr or
* wrpr. The workaround is to immediately follow writes to TICK_COMPARE
* with a read, thus stalling the pipe and keeping following instructions
* from causing data corruption. Aligning to a quadword will ensure these
* two instructions are not split due to i$ misses.
*/


# 1.275 28-Mar-2008 nakayama

Don't read fplwp content in delay slot for considering the case fplwp was
modifiled.

Reported by Chris Ross on port-sparc64.


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.274 20-Mar-2008 nakayama

- remove disabling interrupt in IPI.
- unused VA bits in MMU demap is 13 bits, not 12 bits.


# 1.273 18-Mar-2008 nakayama

Fix a race when increment an interrupt level event counter.


# 1.272 17-Mar-2008 nakayama

Fix a race condition in IPI handlers of save/drop fpstate, from OpenBSD.
Reported and tested by martin@.


# 1.271 17-Mar-2008 nakayama

Make schedintr interrupt handler per-CPU.
While there rename tickintr interrupt handler and share initialization
code with schedintr.


# 1.270 14-Mar-2008 nakayama

Improve IPI handling:
- make IPI takes two arguments.
- add IPI event counters per-CPU.
- implement IPI functions which were missing or broken.
- insert DELAY while halting primary CPU in IPI handler.


# 1.269 02-Mar-2008 nakayama

- make interrupt pending list per-CPU.
- make tickintr() MP-safe.
- remove unused port-sparc derived interrupt code.

Ok by martin@.


# 1.268 02-Mar-2008 nakayama

Don't get IPI handler argument (from bogus address), and ack IRQ twice.


# 1.267 28-Feb-2008 martin

Make TSBs and MMU contexts per-cpu.


Revision tags: nick-net80211-sync-base mjf-devfs-base hpcarm-cleanup-base
# 1.266 26-Jan-2008 nakayama

branches: 1.266.2; 1.266.6;
Fix for 32-bit kernels.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.265 15-Jan-2008 skrll

Store a sensbile PCB_PC value in snapshot - the return point.

This helps gdb somewhat.

OK'd by martin.


# 1.264 14-Jan-2008 martin

Fix register name typo/copy&pasto - %g6 is not %o6/%sp.
From OpenBSD.


Revision tags: matt-armv6-base
# 1.263 06-Jan-2008 martin

Load the next cpu_info pointer with LDPTR instead of ld.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2
# 1.262 09-Dec-2007 martin

branches: 1.262.2;
Provide cpu_intr_p(), at least for non-MULTIPROCESSOR kernels.
Based on suggestions by Andrew Doran.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.261 22-Oct-2007 martin

branches: 1.261.2; 1.261.4; 1.261.6;
Remove an unused .globl declaration


Revision tags: yamt-x86pmap-base4
# 1.260 17-Oct-2007 garbled

Merge the ppcoea-renovation branch to HEAD.

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

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

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base ppcoea-renovation-base vmlocking-base
# 1.259 09-Sep-2007 martin

branches: 1.259.4;
Make cpufrequency and friends per cpu values.
Prepare a hz tick interrupt on secondary CPUs via %tick, but do not
enable it yet, as it breaks ddb.


# 1.258 09-Sep-2007 martin

Do not ACK IPIs before we finished loading all arguments.


# 1.257 06-Sep-2007 martin

Remove the (now unused) second 64k page mapped per CPU.
From matthew green, with small changes by me. All bugs are mine.


# 1.256 25-Aug-2007 martin

branches: 1.256.2;
Remove INITSTACK completely - at the time we used to switch to it, we
already have access to all of lwp0 and it's uarea - so we can switch
to the correct lwp0 stack easily before calling main.


# 1.255 25-Aug-2007 martin

When exiting to OF, use the interrupt stack instead of INITSTACK


# 1.254 25-Aug-2007 martin

Rework cpu_mp_startup slightly:
- temporarily use the cpu's interrupt stack untill we are ready
to access non-OF-based mappings, then directly switch to the cpu's
idlelwp's uarea stack
- disable interrupts untill we are ready to call C code


# 1.253 13-Aug-2007 macallan

remove two restore without matching save


Revision tags: nick-csl-alignment-base matt-mips64-base mjf-ufs-trans-base
# 1.252 06-Jul-2007 martin

branches: 1.252.4; 1.252.8;
A few nits for 32bit SMP kernels, noticed by mrg.
While there, simplify the fpstate IPIs a bit.


# 1.251 05-Jul-2007 martin

sparc64_ipi_save_fpstate is not a leaf function - create a full grown
stack frame.


# 1.250 28-May-2007 mrg

clean up cpu_switchto() a little - no need to flushw or membar
excessively. optimise an rdpr. tested by tnn.


# 1.249 23-May-2007 martin

Fix a stupid bug in the save_fpstate ipi, which caused overwriting of
struct lwp of the lwp owning the fpu. Fix clearing the fplwp - %o0 will
not survive the call to savefpstate - duh!


# 1.248 20-May-2007 martin

Simplify tf_tstate setting when leaving for userland initially - I seem
to have confused the if with the else case of the previous C code.
Funny that it worked at all.


# 1.247 20-May-2007 martin

cpu_switchto() has to return it's first arg, always. This differs from
my reading of the documentation, but helps in the real world and seems
to be what other ports do.


# 1.246 20-May-2007 martin

Remove special case handling for userland lwps from cpu_lwp_fork, instead
do it in lwp_trampoline when we first return to userland.


# 1.245 19-May-2007 martin

cpu_idle is a leaf function, so we better "return from leaf".
Use return value from cpu_switchto for previous lwp in lwp_trampoline.
Also shamelessly steal a comment from uwe written for sparc that explains
all this.
Thanks to tnn, mrg, and uwe for helping to debug this.


# 1.244 17-May-2007 yamt

merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base ad-audiomp-base
# 1.243 22-Feb-2007 martin

branches: 1.243.4; 1.243.6; 1.243.12;
uvm.page_idle_zero now is a bool, not a 32bit value any more.


# 1.242 21-Feb-2007 mrg

shave 9 insns off the tsb setup in cpu_initialize & cpu_mp_startup.


# 1.241 21-Feb-2007 martin

Get rid of unused (thus always zero) "curlwp" variable hidden in assembler
code (C code always uses a cpuinfo based macro).


# 1.240 18-Feb-2007 martin

Make use of another call delay slot, pointed out by uwe.


# 1.239 18-Feb-2007 martin

Make use of a call delay slot and avoid a bogus EMPTY.
Spotted by Juergen Hannken-Illjes, with input from Andrew Doran and
Valeriy E. Ushakov.


# 1.238 18-Feb-2007 martin

Whitespace cosmetics


# 1.237 18-Feb-2007 martin

Backout previous: EMPTY was misused


# 1.236 18-Feb-2007 martin

Make EMPTY expand to nop with gas, as it is used to mark empty branch
delay slots.


# 1.235 15-Feb-2007 martin

branches: 1.235.2;
Fix obvious copy&pasto in SCHED_DEBUG register usage.


Revision tags: post-newlock2-merge
# 1.234 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.233 25-Dec-2006 wiz

Spell "relevant" correctly. From Zafer Aydogan.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.232 25-Oct-2006 mrg

branches: 1.232.2; 1.232.4;
- note that __idle_u should go away but doing so breaks things
- fix several comments to reality
- clean up the #ifdef NO_VCACHE code slightly
- use call instead of set/jmpl
- remove a couple of unnecessary stores to curlwp


Revision tags: yamt-splraiseipl-base2
# 1.231 18-Oct-2006 rjs

Clean up some comments. Cosmetic change to use correct structure
offset names.

Optimize out two instructions from sparc64_ipi_save_fpstate and
sparc64_ipi_drop_fpstate.


# 1.230 17-Oct-2006 mrg

allocate 128KB (as opposed to 64KB) per-cpu, and place the interrupt
stack, cpu_info structure, panicstack, idle uarea and normal kernel
stack in here. the idle uarea and kernel stack are in the 2nd 64KB
page. the interrupt stack and cpu_info structure are as the same
place in the 1st 64KB page, and the panicstack grows down from the
top of this page. update comments in param.h to suit (XXX: a lot
of these constants should move to a header file that will not pollute
the name space so much.) map these pages identically between
cpu_initialise() and cpu_mp_startup(), and deal with the two 64KB
pages in pmap_extract(). keep an unmapped 64KB page between them.

don't initialise the unused "ci_eintstack" member of the cpu_info
structure

use constants to initialise many addresses in the cpu_info structure,
consolidating these assignments from cpu0 and cpu>0

delete u0/estack0/panicstack from locore.s

clean up some wrong comments in locore.s

fix a 32bit-only bug in cpu_mp_startup().

delete 'u0' entirely.


this fixes recent random lossage seen on port-sparc64: processes
stuck in RUN state, data faults, and hangs.


# 1.229 04-Oct-2006 mrg

use call instead of set/jmpl. add an entry point for idle that expects
sched_lock to be unlocked, and use this for non-boot cpu's. complete a
comment describing how registers in idle_switch are expected to be set.


# 1.228 03-Oct-2006 mrg

use the same SAVE_LOCALS_INS definition for 32 bit and 64 bit kernels.
refactor TRAP_SETUP() a little between these two versions to be more alike.


# 1.227 03-Oct-2006 mrg

use the correct size/type for MP variables (pointers and longs).

a 32 bit MULTIPROCESSOR kernel now builds (and crashes quickly.)


# 1.226 03-Oct-2006 mrg

in the 64bit version of SAVE_LOCAL_INS, s/BIAS/STKB/ to allow future
sharing of the 32 and 64 bit versions of the {TRAP,INTR}_SETUP macros.


# 1.225 19-Sep-2006 mrg

- remove some way old FP setup/teardown code
- put the block memcpy/memset inside #ifdef USE_BLOCK_STORE_LOAD which
is (now) defined.

no functional change, same .o is generated.


# 1.224 19-Sep-2006 mrg

re-order the changes in rev 1.217 to give registers a little bit of
time to settle between usage, like it was before hand.


# 1.223 19-Sep-2006 mrg

- remove a wrong comment.
- add a new entry point for idle called idle_switch that is called by
cpu_switch() in the MP case when sched_whichqs is zero, properly
setting up the idle stack. from petrov@ via martin@.


# 1.222 19-Sep-2006 mrg

rework interrupt_vector() slightly:
- for the IPI case, avoid loading the address of intrlev into %g3
- remove some NOT_DEBUG code
- load the interrupt argument #2 in the delay slot

this removes 2 nops during interrupt processing for the normal
case, and an additional 2 ALU instructions for IPIs


# 1.221 18-Sep-2006 mrg

- sparc64_ipi_halt(): we shouldn't return from sparc64_ipi_halt_thiscpu()
so replace a branch with a 'sir'
- in #if 0 code, in sparc64_ipi_flush_pte() and sparc64_ipi_flush_ctx()
save/restore the out registers that the sp_tlb_flush_xxx() versions
around calling them
- in sp_tlb_flush_pte() and sp_tlb_flush_ctx(), replace global register
usage with out registers so that we don't clobber the (alternate)
global registers when these are called from IPI context


# 1.220 18-Sep-2006 mrg

- remove an extra 'sir' that followed one in a macro
- add some named labels to some spill/fill handlers
- remove 2 unused strings


Revision tags: yamt-splraiseipl-base
# 1.219 18-Sep-2006 martin

branches: 1.219.2;
Lazy FPU handling for the MULTIPROCESSOR case


# 1.218 16-Sep-2006 nakayama

From OpenBSD:
- reload %fprs for checking it again.
- use symbolic names for checking in %fprs.

revision 1.51
date: 2005/07/18 14:50:11; author: deraadt; state: Exp; lines: +2 -1
cache a copy of the fprs so we know what fp restore we should do after

revision 1.50
date: 2005/07/14 01:46:13; author: deraadt; state: Exp; lines: +4 -4
use symbolic names for checking in %fprs, as above


# 1.217 16-Sep-2006 nakayama

Fix a couple of %y register save/restore errors, inspired from OpenBSD.

revision 1.44
date: 2004/04/23 04:18:17; author: marc; state: Exp; lines: +5 -4

fix a couple of %y register save/restore errors
1) don't save %y in a register that is later used before restoring %y
2) always restore %y after calling a signal handler
tested by drahn@, OK pval


# 1.216 15-Sep-2006 martin

Do not bother to save fpu state when we are about to get rid of it.


Revision tags: yamt-pdpolicy-base9
# 1.215 13-Sep-2006 mrg

SMP cleanup. provide support for multiple CPUs in DDB. (SMP itself
is still not working.)

cpu.h:
- add a pointer for DDB regs in SMP environment to struct cpu_info
- remove the #defines for mp_pause_cpus() and mp_resume_cpus()
cpuset.h:
- remove CPUSET_ALL() and rename CPUSET_ALL_BUT() to CPUSET_EXCEPT()
from petrov.
db_machdep.h:
- rename the members of db_regs_t to be the same as sparc
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- redo DDB_REGS to no longer be a pointer to a fixed data structure
but to one allocated per-cpu when ddb is entered
- move a bunch of prototypes in here
intr.h:
- remove SPARC64_IPI_* macros, no longer used
db_interface.c:
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- make "nil" a 64 bit entity
- change the ddb register access methods to work in multiprocessor
environment, it is now very much like sparc does it
- in kdb_trap() avoid accessing ddb_regp when it is NULL
- update several messages to include the cpu number
- unpause other cpus much later when resuming from ddb
- rename db_lock() to db_lock_cmd(), as the sparc-like code has
db_lock as a simple lock
- remove "mach cpus" command, and replace it with "mach cpu" (which
does the same) and also implement "mach cpu N" to switch to
another cpus saved trapframe
db_trace.c:
- update for the ddb_regs -> ddb_regp change
genassym.cf:
- add TF_KSTACK as offsetof(struct trapframe64, tf_kstack)
ipifuncs.c:
- overhaul extensively
- remove all normal interrupt handlers as IPI's, we now handle
them all specially in locore.s:interrupt_vector
- add a simplelock around all ipi functions - it's not safe for
multiple cpus to be sending IPI's to each other right now
- rename sparc64_ipi_pause() to sparc64_ipi_pause_thiscpu() and,
if DDB is configured, enable it to save the passed-in trapframe
to a db_regs_t for this cpu's saved DDB registers.
- remove the "ipimask" system (SPARC64_IPI_* macros) and instead
pass functions directly
- in sparc64_send_ipi() always set the interrupt arguments to 0,
the address and argument of the to be called function. (the
argument right now is the address of ipi_tlb_args variable, and
part of the reason why only one CPU can send IPI's at a time.)
don't wait forever for an IPI to complete. some of this is
from petrov.
- rename sparc64_ipi_{halt,pause,resume}_cpus() to
mp_{halt,pause,resume}_cpus()
- new function mp_cpu_is_paused() used to avoid access missing
saved DDB registers
- actually broadcast the flush in smp_tlb_flush_pte(),
smp_tlb_flush_ctx() and smp_tlb_flush_all(). the other end may
not do anything yet in the pte/ctx cases yet...
kgdb_machdep.c:
- rework for changed member names in db_regs_t.
locore.s:
- shave an instruction from syscall_setup() (set + ld -> sethi + ld)
- remove some old dead debug code
- add new sparc64_ipi_halt IPI entry point, it just calls the C
vector to shutdown.
- add new sparc64_ipi_pause IPI entry point, which just traps into
the debugger using the normal breakpoint trap. these cpus usually
lose the race in db_interface.c:db_suspend_others() and end up
calling the C vector sparc64_ipi_pause_thiscpu().
- add #if 0'ed code to sparc64_ipi_flush_{pte,ctx}() IPI entry
points to call the sp_ version of these functions.
- in rft_kernel (return from trap, kernel), check to see if the
%tpc is at the sparc64_ipi_pause_trap_point and if so, call
"done" not "retry"
- rework cpu_switch slightly: save the passed-in lwp instead of
using the one in curlwp
- in cpu_loadproc(), save the new lwp not the old lwp, to curlwp
- in cpu_initialize(), set %tl to zero as well. from petrov.
- in cpu_exit(), fix a load register confusion. from petrov.
- change some "set" in delay branch to "mov".
machdep.c:
- deal with function renames
pmap.c:
- remove a spurious space
trap.c:
- remove unused "trapstats" variable
- add cpu number to a couple of messages


# 1.214 09-Sep-2006 mrg

significant clean up effort, largely from petrov@ via martin@.

- fix a bunch of comments for proc->lwp
- remove old TRAPTRACE, NOT_DEBUG, etc. code that has bit-rotted
- put some older DEBUG code under NOT_DEBUG
- add a bunch of new debugging/tracing code ("KTR") that depends on
other changes not yet present.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base yamt-pdpolicy-base5 chap-midi-base simonb-timecounters-base rpaulo-netinet-merge-pcb-base
# 1.213 14-May-2006 elad

branches: 1.213.6; 1.213.8;
integrate kauth.


# 1.212 12-May-2006 skrll

Fix some comments.


Revision tags: elad-kernelauth-base
# 1.211 09-May-2006 rjs

Load CPCB in cpu_mp_startup.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.210 11-Feb-2006 cdi

branches: 1.210.2; 1.210.4; 1.210.6;
ANSIfication: u_intN_t -> uintN_t, use ANSI function declarations/definitions
instead of K&R ones.


# 1.209 27-Jan-2006 cdi

branches: 1.209.2; 1.209.4;
Alter sparc64 bootstrap, catch up to ofwboot v1.9:

- Accept bootinfo structure passed down from ofwboot v1.9
- Drop kernel re-mapping code
- Use permanent 4MB mappings provided by the loader instead
- Change kernel entry address to point directly at the code instead of pointing
at the trap table's first slot. This allows the bootloader to detect
those kernels which are aware of the new boot scheme
- Due to the changes in kernel mapping code, alter secondary CPU bootstrap
code to use trampoline just like FreeBSD does (some FreeBSD code is used
here as well)


# 1.208 12-Jan-2006 cdi

Fix a typo: %g0 should be used instead of %o0 when initializing FPU in dostart:
and cpu_mp_startup:, %o0 is not even initialized at this point.


# 1.207 11-Dec-2005 christos

branches: 1.207.2;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 1.206 10-Jul-2005 christos

Re-factor syscall, and make it use syscall_{plain,fancy}.


# 1.205 31-May-2005 chs

branches: 1.205.2;
remove vestigal {,e}intr{names,cnt} symbols now that vmstat doesn't need them.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.204 12-Feb-2005 chs

branches: 1.204.4; 1.204.6; 1.204.8;
in sparc_interrupt(), wait to enable interrupts until just before calling
the handler and disable them again right after the handler returns.
we don't want another hardware interrupt coming in while we're mucking
with the list pointers. also, clear the intrhand's ih_pending pointer
before calling the handler rather than after, so that if another interrupt
comes in while the handler is running, we can put the intrhand back on
the list so it will be called again.

in send_softint(), disable interrupts via %pstate instead of %pil, so that
hardware interrupts at higher levels are blocked while we manipulate the
intrpending list. also, if the intrhand already has ih_pending set,
don't bother poking the SET_SOFTINT register again, since being on the list
implies that there is already a softint pending in the hardware.

these appear to fix PR 21750 (the "sleep forever" problem).

while I'm here, remove more vestiges of the !INTRLIST softint stuff
(code and comments). and in sparc64_ipi_flush_all(), interrupts are
already disabled so we don't need to fiddle with %pstate.


Revision tags: yamt-km-base2
# 1.203 30-Jan-2005 martin

Remove the no long usefull variants selected by undefining INTRLIST and
INTR_INTERLOCK to improve readability. Same object code generated as before.


Revision tags: yamt-km-base
# 1.202 16-Jan-2005 chs

branches: 1.202.2;
use ENTRY_NOPROFILE() for various entry points,
stack traces work better that way.


Revision tags: kent-audio1-beforemerge kent-audio1-base
# 1.201 03-Dec-2004 chs

branches: 1.201.4;
remove cache_flush_virt() and PADDRT, they're no longer used.
allocate a stack frame for blast_dcache() when profiling so it shows up.
in dcache_flush_page(), use a stride of 32 instead of 16 to match the
cache line size. correct various comments.


# 1.200 08-Nov-2004 petrov

Don't compile sparc64_ipi functions when UP.


# 1.199 25-Oct-2004 martin

No need to clear %o1 when returning a 64 bit integer from pseg_get if we
are compiling for a 64 bit kernel.


# 1.198 24-Jul-2004 nakayama

Change interrupt pending list end value to -1, to avoid linking an
interrupt handler twice.

It may fix "sleep forever" bug.


# 1.197 09-Apr-2004 petrov

Clean-up unused defines and variables.


Revision tags: netbsd-2-0-base
# 1.196 26-Mar-2004 petrov

branches: 1.196.2;
Use want_resched from cpu_info area.


# 1.195 23-Mar-2004 martin

Replace intrcnts by evcnts. XXX - needs slight tweaking for MULTIPROCESSOR.


# 1.194 14-Mar-2004 chs

checkpoint of MP work from dennis and myself. includes cross-processor
interrupt framework, a sledgehammer TLB invalidation and misc MP fixes.
doesn't work at all yet.


# 1.193 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.192 19-Jan-2004 martin

Rename switchexit to cpu_exit and g/c the old C implementation of cpu_exit.


# 1.191 18-Jan-2004 martin

Support RAS for 32bit kernels too.


# 1.190 16-Jan-2004 martin

In proc_trampoline don't bother to clear condition codes in the trap
frame, since we no longer rely on this.
While there fix a few comments.


# 1.189 08-Jan-2004 martin

Minor cleanup


# 1.188 06-Jan-2004 martin

Implement restartable atomic sequences (RAS) for sparc64.


# 1.187 06-Jan-2004 petrov

Spinup secondary cpus. Based on codes sent to me by Dennis Chernoivanov
and Chuck Silvers.


# 1.186 04-Jan-2004 jdolecek

update to recent changes - exit2() doesn't exist anymore and the
exit path always calls lwp_exit2()
pointed out Martin Husemann


# 1.185 02-Dec-2003 martin

Minor cleanup: remove unused code, sync a comment with current reality.


# 1.184 25-Nov-2003 cdi

Use per-cpu pcb, curlwp and fplwp rather than global ones. This brings
GENERIC.MP configuration to a usable state.

Approved by petrov@.


# 1.183 24-Nov-2003 cdi

Call 'proc_trampoline_mp' from 'proc_trampoline' in a multiprocessor
configuration. Fix process locking. Approved by petrov@.


# 1.182 20-Nov-2003 petrov

Remove nwindows calculation, it's not used. Set l_cpu in cpu_switch.


# 1.181 09-Nov-2003 martin

Get rid of bcopy/bzero.


# 1.180 26-Oct-2003 christos

Initial siginfo support for sparc64 (untested). COMPAT_16 sigcontext signal
delivery tested.


# 1.179 24-Aug-2003 chs

add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default. the changes
fall into two basic catagories:

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

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

originally from openbsd, adapted for netbsd by me.


# 1.178 08-Jul-2003 cdi

traceit: don't use %g7 as it is to become curcpu() register. Add comments.


# 1.177 18-May-2003 martin

branches: 1.177.2;
Make kernels with options KGDB at least compile.
Still needs some work to make it working.


# 1.176 29-Apr-2003 nakayama

Use BLOCK_ALIGN rather than BLOCK_SIZE for aligning a pointer.


# 1.175 27-Apr-2003 ragge

Preserve the symbol table in the LKM || KSYMS cases also.


# 1.174 04-Apr-2003 petrov

use branch slot in pmap_copy_page.


# 1.173 24-Mar-2003 nakayama

Divide `set' instruction in delay slot (from OpenBSD change to rev 1.30).


# 1.172 10-Feb-2003 martin

Remove some #if 0 code and a few XXX marked membars w/o proper
justification for their existence.


# 1.171 09-Feb-2003 martin

Remove left over pieces from reusing the signal trampoline for upcalls.
This should fix signal delivery for 32bit kernels.


# 1.170 05-Feb-2003 nakayama

Switch to use cycle counter (%tick) based microtime().

This is derived from alpha/microtime.c and i386/tsc_microtime.c,
and will share with both ports.

This should fix PR port-sparc64/18452.
(approved by martin)


# 1.169 04-Feb-2003 martin

Fix return value of pseg_set, which I accidently broke in rev. 1.164.

Fix register names in comment and shave off another register (hint
from uwe).


# 1.168 01-Feb-2003 martin

Rearrange register usage in pseg_set a bit and shave off %g4.


# 1.167 01-Feb-2003 martin

Remove a few #ifdef _LP64 by using STPTR/LDPTR macros.
Thanks to Matthew Green for the pointer.


# 1.166 31-Jan-2003 martin

Apply leaf procedure optimization to pseg_set (again).


# 1.165 31-Jan-2003 martin

Make the pmap count resident/wired mappings on the fly instead of
walking the page tables whenever this information is needed.

Add an option PMAP_COUNT_DEBUG to assert the new counts and the
page table walk agree.

The old solution had very bad performance impact, for example
by the high CPU load when running top(1).

Thanks to Simon Burge for pointing at the cause of the problem and
to Valeriy E. Ushakov for optimizing my simple minded assembler code.


# 1.164 27-Jan-2003 martin

Remove unused function pseg_find (which looked quite similar to
pseg_get anyway).


# 1.163 18-Jan-2003 thorpej

Merge the nathanw_sa branch.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.162 16-Jan-2003 petrov

Move dump_dtlb back under DDB.


# 1.161 15-Jan-2003 chs

fix two bugs in my last pmap rework:
- in tlb_flush_all(), don't skip TLB entries with the high bit on,
I was confused about which MMU register it was using. it's also fine
to use the last hardware context.
- in pmap_create(), don't allocate a hardware context for the new pmap.
it's unnecessary, and when this would cause us to recycle all the contexts,
it would result in the current process's context being set to 0
(ie. the kernel's context). the current process could then return to
userspace without going through the context-switch code (and thus without
having a hardware context reallocated). this would lead to user mappings
being entered in the kernel's context later, causing all sorts of trouble.
add some assertions to catch this kind of thing.


Revision tags: fvdl_fs64_base
# 1.160 25-Dec-2002 petrov

new function dump_itlb.


Revision tags: gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.159 22-Sep-2002 chs

many improvements:
- use struct vm_page_md for attaching pv entries to struct vm_page
- change pseg_set()'s return value to indicate whether the spare page
was used as an L2 or L3 PTP.
- use a pool for pv entries instead of malloc().
- put PTPs on a list attached to the pmap so we can free them
more efficiently (by just walking the list) in pmap_destroy().
- use the new pmap_remove_all() interface to avoid flushing the cache and TLB
for each pmap_remove() that's done as we are tearing down an address space.
- in pmap_enter(), handle replacing an existing mapping more efficiently
than just calling pmap_remove() on it. also, skip flushing the
TSB and TLB if there was no previous mapping, since there can't be
anything we need to flush. also, preload the TSB if we're pre-setting
the mod/ref bits.
- allocate hardware contexts like the MIPS pmap:
allocate them all sequentially without reuse, then once we run out
just invalidate all user TLB entries and flush the entire L1 dcache.
- fix pmap_extract() for the case where the va is not page-aligned and
nothing is mapped there.
- fix calculation of TSB size. it was comparing physmem (which is
in units of pages) to constants that only make sense if they are
in units of bytes.
- avoid sleeping in pmap_enter(), instead let the caller do it.
- use pmap_kenter_pa() instead of pmap_enter() where appropriate.
- remove code to handle impossible cases in various functions.
- tweak asm code to pipeline a little better.
- remove many unnecessary spls and membars.
- lots of code cleanup.
- no doubt other stuff that I've forgotten.

the result of all this is that a fork+exit microbenchmark is 34% faster
and a fork+exec+exit microbenchmark is 28% faster.


Revision tags: gehenna-devsw-base
# 1.158 18-Jul-2002 wiz

Spell 'should' correctly.


# 1.157 07-Jun-2002 eeh

Shave 10% off the time needed to flush the D$ through a bit of instruction
reordering.


# 1.156 05-Jun-2002 eeh

Handle improperly aligned stack pointers more cleanly.


# 1.155 04-Jun-2002 eeh

Fix the fork trampoline to properly use the supplied tstate.


# 1.154 31-May-2002 thorpej

Make this work with an ISO C preprocessor.


Revision tags: netbsd-1-6-base
# 1.153 14-May-2002 eeh

branches: 1.153.2; 1.153.4;
Only save locals and ins in trapframes for DEBUG kernels.


# 1.152 04-May-2002 kleink

Add some comments to the CPP conditionals controlling the trap macro
definitions, to ease navigation somewhat.


# 1.151 16-Apr-2002 eeh

Make lots of routines profile-friendly and get rid of some cruft.


Revision tags: eeh-devprop-base
# 1.150 21-Mar-2002 petrov

Not needed debug stuff deleted.


# 1.149 16-Mar-2002 mrg

tell newer binutils that our use of %g2 and %g3 is OK here.


# 1.148 15-Mar-2002 eeh

Cleanup MMU initialization to prevent hangs.


Revision tags: newlock-base ifpoll-base
# 1.147 09-Feb-2002 eeh

branches: 1.147.4;
Fix microsecond calculation in microtime.


# 1.146 07-Feb-2002 eeh

Fix register allocation in microtime().


# 1.145 29-Jan-2002 eeh

Shift the UPAID in the correct direction.


# 1.144 17-Jan-2002 eeh

Be more tolerant of unaligned stack pointers.


# 1.143 17-Jan-2002 eeh

Enable block insns in bcopy and bzero.


# 1.142 16-Jan-2002 eeh

In bcopy use 32-bit comparisons in 32-bit kernels.


# 1.141 16-Jan-2002 eeh

Use correct calculation for the trapframe in softtrap for ILP32.


# 1.140 20-Nov-2001 lukem

- pull in opt_kgdb.h where necessary
- replace opt_kgdb_machdep.h with opt_kgdb.h
- defparam opt_kgdb.h:
KGDB_DEV KGDB_DEVNAME KGDB_DEVADDR KGDB_DEVRATE KGDB_DEVMODE
- move from opt_ddbparam.h to opt_ddb.h:
DDB_FROMCONSOLE DDB_ONPANIC DDB_HISTORY_SIZE DDB_BREAK_CHAR SYMTAB_SPACE
- replace KGDBDEV with KGDB_DEV
- replace KGDBADDR with KGDB_DEVADDR
- replace KGDBMODE with KGDB_DEVMODE
- replace KGDBRATE with KGDB_DEVRATE
- use `9600' instead of `0x2580' for 9600 baud rate
- use correct quotes for options KGDB_DEVNAME="\"com\""
- use correct quotes for options KGDB_DEV="17*256+0"
- remove unnecessary dependancy on Makefile for kgdb_stub.o
- minor whitespace cleanup


Revision tags: thorpej-mips-cache-base thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf
# 1.139 14-Sep-2001 thorpej

branches: 1.139.4;
Don't declare intrhand[] here -- that's taken care of in intr.c.


Revision tags: thorpej-devvp-base
# 1.138 30-Aug-2001 eeh

branches: 1.138.2;
Preliminary UltraSPARC III suport (not enabled yet).


# 1.137 13-Aug-2001 jdolecek

g/c _remque()/_insque(); use the C version in libkern


# 1.136 09-Aug-2001 eeh

Fix context masking lossage caused by last version.


# 1.135 08-Aug-2001 eeh

Clean up the trap code to handle the changes cause by supporting non-faulting
accesses. Also change the parameter order so trap frames are easy to find.


# 1.134 07-Aug-2001 eeh

Make sure C code always has ASI_PRIMARY_NOFAULT in the %asi register so
the compiler will be happy if it ever starts generating speculative loads.


# 1.133 05-Aug-2001 eeh

Add support for non-faulting loads and optimize MMU miss handling paths.


# 1.132 02-Aug-2001 eeh

Fix bcopy.


# 1.131 02-Aug-2001 eeh

Sync bzero w/libc version.


# 1.130 01-Aug-2001 eeh

Integrate fixes from userland memset.


# 1.129 31-Jul-2001 eeh

Code cleanup and optimization.


# 1.128 23-Jul-2001 eeh

Get rid of some debug code that really isn't all that useful any more.


# 1.127 19-Jul-2001 eeh

Do ignore unregistered interrupts instead of faulting.


# 1.126 16-Jul-2001 eeh

Make bcopy a 32-bit friendly.


# 1.125 11-Jul-2001 eeh

Fix problems booting 32-bit kernels and dispatching level-15 interrupts.


# 1.124 08-Jul-2001 eeh

branches: 1.124.2;
Code cleanup. Add block_disable to let you turn on block set/copy routines.


# 1.123 05-Jul-2001 eeh

New block bzero and bcopy.


# 1.122 04-Jul-2001 eeh

Replace old bcopy with a much faster version.


# 1.121 01-Jul-2001 martin

Disable axidently enabled debug code to make -current compile again.


# 1.120 30-Jun-2001 eeh

Use a newer version (still disabled) of block bcopy.


# 1.119 30-Jun-2001 eeh

Fixup fpu save restore, get rid of some unused copy functions, and add
a new bcopy.


# 1.118 21-Jun-2001 eeh

Allow multiple 4MB pages for both kernel text and kernel data.

Note: DEBUG checks will not allow accesses to the hole between
text and data segments, so you may need to update programs that
use libkvm before relocating the start of kernel data.


# 1.117 06-Jun-2001 mrg

extract the netbsd32, sunos, 32 bit svr4 and 64 bit svr4 sigcode out into
separate files, so that compat lkms can link with them as well.


# 1.116 30-May-2001 lukem

add missing #include "opt_kgdb.h"


Revision tags: thorpej_scsipi_beforemerge
# 1.115 25-Apr-2001 simonb

Spell occurred correctly.


Revision tags: thorpej_scsipi_nbase thorpej_scsipi_base
# 1.114 09-Apr-2001 eeh

Interrupt latency fix from sparc port. (Hm. One insn instead of 5).


# 1.113 07-Mar-2001 eeh

Fix inverted preprocessor logic. (Spotted by Charles.)


# 1.112 21-Feb-2001 eeh

branches: 1.112.2;
Add support for 64-bit SVR4 (Solaris 8) binaries.


# 1.111 10-Feb-2001 pk

Fix conditional for svr4 compat inclusion.


# 1.110 05-Feb-2001 eeh

Add signal trampoline for 64-bit svr4 emulations.


# 1.109 31-Dec-2000 eeh

Make INCR() atomic.


# 1.108 29-Dec-2000 eeh

pseg_get tells us whether it really needed that spare page after all.


# 1.107 07-Dec-2000 eeh

Fixup calculating where fpstate should be saved in the signal trampoline
code so it doesn't overwrite something important like the registers.


# 1.106 09-Nov-2000 eeh

Fix ILP32 bug in probe_get().


# 1.105 22-Oct-2000 pk

Restore revision 1.102.

I hope it sticks this time..


# 1.104 20-Oct-2000 eeh

Fix hang in 32-bit kernels caused by relocation of KERNBASE.


# 1.103 04-Oct-2000 eeh

Fix interrupt lossage problem and some cosmetic changes.


# 1.102 01-Oct-2000 pk

cpu_initialize: global registers aren't preserved across calls to
prom_printf(), so replace %g3 with %l7 (which isn't used despite
the `usage' comment).

Also, clean up white-space turds.


# 1.101 29-Sep-2000 eeh

This seems to fix the interrupt lossage of non-debug kernels.


# 1.100 28-Sep-2000 eeh

Fix INTR_SETUP() to properly distinguish kernel and user addresses.

Make microtime() return the correct time on %tick machines.

Re-enable debug stuff in dostart for now to detect kernel mapping issues.


# 1.99 25-Sep-2000 pk

Missing `#if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)'


# 1.98 17-Sep-2000 eeh

Make the improved %tick changes work with machines that use the counter-timer
for the clock.


# 1.97 12-Sep-2000 eeh

Fix new version of microtime.


# 1.96 11-Sep-2000 eeh

(Hopefully) fix clock skew on machines that us %tick for the clock (UIIi).


# 1.95 31-Aug-2000 eeh

Use casx instead of stx to change entries in the page table trees.


# 1.94 23-Aug-2000 eeh

Update the scheduler to the new locking scheme.


# 1.93 10-Aug-2000 eeh

Fix signal delivery.


# 1.92 02-Aug-2000 eeh

Get kernel profiling to work. Now if only gprof worked....


# 1.91 01-Aug-2000 eeh

Overhaul cache flush code and coredump code.


# 1.90 25-Jul-2000 pk

Re-instate a couple of delay slot NOPs marked `XXX spitfire bug?'


# 1.89 24-Jul-2000 mycroft

Optimization to pmap_zero_page(): we only need to use the first 16 FP regs,
as in bzero().


# 1.88 24-Jul-2000 mycroft

Fix a whitespace glitch.


# 1.87 24-Jul-2000 mycroft

Pull in the bzero() changes from libc for real, with a couple of kernel-
specific hacks:
* Make the bias handling depend on STKB, so it switches correctly for 32-bit
kernels.
* Use the 32-bit stw/ld for 32-bit kernels.
* Add a few `-STKB's that were missed in the previous change.


# 1.86 24-Jul-2000 pk

Cosmetic & readability:
- local label cleanup in interrupt handling code;
- in debugging sections when testing `intrdebug': use a unique
local label (97) to enhanced clarity;
- comment-out unused code;
- kill a bug as the satisfying result of doing all of the above.


# 1.85 24-Jul-2000 eeh

Fix stack issues in bzero.


# 1.84 24-Jul-2000 mycroft

Revert the previous change for now. I don't have time to debug it tonight.


# 1.83 23-Jul-2000 mycroft

Copy bzero change from libc.


# 1.82 20-Jul-2000 pk

Since `intrcnt' points to an array of long ints, reserve the appropriate
amount of space depending on _LP64. Provide macros to load/store signed
and unsigned long ints.

Also, make the `intrcnt' and `intrpending' arrays 16 entries long, as on
sparc/v9 interrupt #15 is just a regular interrupt.


# 1.81 19-Jul-2000 eeh

Fix merge problem.


# 1.80 19-Jul-2000 eeh

Disable interrupt interlock using ih->ih_pending field. Seems to cause
more problems than it solves.


# 1.79 19-Jul-2000 eeh

Miscellaneous cleanup.


# 1.78 18-Jul-2000 pk

Correct args usage comment in probeget.
Whitespace cleanup.


# 1.77 18-Jul-2000 pk

probeget: 9 -> 0x9


# 1.76 18-Jul-2000 pk

If `ih_pending' is set simply return from the trap, don't schedule another
soft interrupt.


Revision tags: mrg-merge-1-5-top
# 1.75 18-Jul-2000 pk

openfirmware: don't lower %pil


# 1.74 17-Jul-2000 pk

Kill typos in interrupt code.


# 1.73 17-Jul-2000 pk

probeget: do the same song and dance as ld*a() macros in ctlreg.h do.


# 1.72 14-Jul-2000 eeh

Move some macro definitions out of genassym and into locore.s


# 1.71 08-Jul-2000 mrg

backout part of previous: turn off intrdebug, and another debug message


# 1.70 07-Jul-2000 pk

Changes for readability:
- #define LP64 dependent STACKFRAME macro once
- use a LOAD_ASCIZ macro for setting up the format string
for debug messages.


# 1.69 07-Jul-2000 eeh

Temporary fix to prevent the clock from stopping on UIIi machines.


# 1.68 03-Jul-2000 eeh

Prevent interrupts from being posted if they are active and deprecate polled
interrupts. This seems to eliminate the spurious interrupts.


# 1.67 02-Jul-2000 eeh

Clean up interrupt handling some more.


# 1.66 30-Jun-2000 eeh

Fix interrupt delivery on UltraSPARC IIi machines.


# 1.65 24-Jun-2000 eeh

With these changes the kernel seems almost stable again.


# 1.64 24-Jun-2000 eeh

More VM cleanup:

Move the cpu_info structure above the interrupt stack so it won't
get corrupted if the stack overflows.

Flush the D$ before and after all MMU bypass accesses since the
D$ latches all of those.


# 1.63 23-Jun-2000 eeh

Make probeget() and probeset() really work for a change.


Revision tags: netbsd-1-5-base
# 1.62 19-Jun-2000 eeh

branches: 1.62.2;
Have separate data and text segments, make text read-only.


# 1.61 12-Jun-2000 eeh

Start reorganizing the kernel for MULTIPROCESSOR support.


# 1.60 31-May-2000 thorpej

Add a comment about needing to initialize p_cpu when multiple
processors are supported.


Revision tags: minoura-xpg4dl-base
# 1.59 26-May-2000 thorpej

branches: 1.59.2;
First sweep at scheduler state cleanup. Collect MI scheduler
state into global and per-CPU scheduler state:

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

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

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

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

Tested on i386 and Alpha. Changes are mostly mechanical, but apologies
in advance if it doesn't compile on a particular platform.


# 1.58 26-May-2000 thorpej

Don't set `runtime' here; it's done at the end of mi_switch().
cvS: ----------------------------------------------------------------------


# 1.57 26-May-2000 thorpej

Introduce a new process state distinct from SRUN called SONPROC
which indicates that the process is actually running on a
processor. Test against SONPROC as appropriate rather than
combinations of SRUN and curproc. Update all context switch code
to properly set SONPROC when the process becomes the current
process on the CPU.


# 1.56 22-Apr-2000 eeh

If we trap due to a bad kernel stack, try to switch to the interrupt strack
before breaking into the debugger.


# 1.55 18-Apr-2000 eeh

Prevent the system from getting watchdog reset by returning directly to user
mode if restoring the user window traps. Also reduce the time we run with
%tl>0.


# 1.54 13-Apr-2000 eeh

Apparently gas 2.9.5 (don't ask) does not like to add values to %lo()
directives so move the additions inside %lo() to make it happy.
Hopefully this won't break older versions.


# 1.53 10-Apr-2000 mrg

- fix a speeling error
- rename some numbered labels to be a bit less confusing.
- remove dead code
- fix a debug error message (argh!)


# 1.52 10-Apr-2000 pk

Get a kernel without DDB to build.


# 1.51 16-Mar-2000 eeh

Revamp interrupts again:

Fix a bug causing interrmittent panics in interrupt dispatch.
Use interrupt vectors for softints.
Add a new send_softint interface.
Improved D$ flushing.
Improve traptrace and other debugging enhancements.


Revision tags: chs-ubc2-newbase
# 1.50 16-Jan-2000 eeh

Interrupt handlers return zero if they didn't handle the interrupt.


# 1.49 10-Jan-2000 eeh

Add debugger single-stepping and fix interrupt dispatch bugs.


# 1.48 30-Dec-1999 eeh

Lots of changes:

remove ffs()
add bzero that uses block store insns
save %gsr to fpstate
revert to physical accesses for pmap_zero_page so we don't
have conflicting page mappings
general cleanup.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base fvdl-softdep-base
# 1.47 06-Nov-1999 eeh

Handle zero length properly in copyinstr() copyoutstr() and copystr().


Revision tags: comdex-fall-1999-base
# 1.46 11-Oct-1999 eeh

branches: 1.46.2; 1.46.4;
Update to post 1.4.


# 1.45 05-Oct-1999 eeh

branches: 1.45.2;
Make broken versions of gas happy by using sethi/or instead of set for
(negative) addresses.


# 1.44 17-Sep-1999 thorpej

Centralize the declaration and clearing of `cold'.


Revision tags: chs-ubc2-base
# 1.43 18-Jul-1999 eeh

More fun with pmap.


# 1.42 21-Jun-1999 eeh

Improve TRAPTRACE. Add FLTRACE that only tracks MMU faults.


# 1.41 05-Jun-1999 eeh

Make pbrobeget() and probeset() work for 64-bit values as well. To do this
the arguments are changed so the address is first and the ASI second so we
can have the address in %o0:%o1 and not worry about unused registers.

Also a bit of copyright cleanup.


# 1.40 05-Jun-1999 mrg

update a commit slightly.


# 1.39 30-May-1999 eeh

Add code to support using %tick as the system clock if no "counter-timer" node
is found.


# 1.38 09-May-1999 eeh

Fixup non-DEBUG kernels.


# 1.37 29-Apr-1999 christos

Add sunos_sigcode (32 bit only)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.36 26-Mar-1999 eeh

branches: 1.36.4;
COMPAT_SPARC32 -> COMPAT_NETBSD32


# 1.35 25-Mar-1999 mrg

clean and up make compile


# 1.34 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.33 22-Mar-1999 eeh

Need to set up the pointers properly for partial FPU register stores.


# 1.32 22-Mar-1999 eeh

Flush D$ on bypass accesses.


# 1.31 28-Feb-1999 eeh

Use block load/store in pmap_zero_page()/pmap_copy_page().


# 1.30 17-Feb-1999 eeh

Let's test out vectored interrupts.


# 1.29 15-Feb-1999 hubertf

RCS ID police


# 1.28 11-Feb-1999 mrg

fix a comment pasto.


# 1.27 11-Jan-1999 eeh

Finally fixed 64-bit signal trampoline.


# 1.26 10-Jan-1999 eeh

Handle the symbol table properly in a 32-bit kernel that was booted from a
64-bit bootloader.


# 1.25 09-Jan-1999 eeh

More signal fixup.


Revision tags: kenh-if-detach-base
# 1.24 26-Nov-1998 mycroft

Sync kcopy() with 32-bit SPARC version.


# 1.23 16-Nov-1998 eeh

Fixup the last broken bits of the signal handling code.


Revision tags: chs-ubc-base
# 1.22 08-Oct-1998 eeh

Fix more syscall32 and signal breakage.


# 1.21 22-Sep-1998 eeh

More fixup in the signal area.

64-bit syscall cleanup.

Add emulation for some new FPU insns: conversion to 64-bit long int and
conditional moves.


# 1.20 17-Sep-1998 thorpej

SYS_sigreturn -> SYS___sigreturn14.


# 1.19 13-Sep-1998 eeh

Fixup signal changes (hopefully). However SUN_COMPAT is likely broken by
this and I don't know how to fix it.

We can now exec a 64-bit init through a really ugly hack (don't ask.)


# 1.18 11-Sep-1998 eeh

Add labels for the compat_sparc32 signal trampoline and break -- er -- fix
suword and fuword.


# 1.17 09-Sep-1998 eeh

Don't use %tick for microtime on 32-bit kernels -- breaks gettimeofday.


# 1.16 09-Sep-1998 thorpej

Adjust for the new "reaper" kernel thread: do not free the vmspace and
u-area in machine-dependent code. Instead, call exit2() to schedule
the reaper to free them for us, once it is safe to do so (i.e. we are
no longer running on the dead proc's vmspace and stack).


# 1.15 07-Sep-1998 eeh

Fix data corruption problem caused by broken debug code.


# 1.14 07-Sep-1998 eeh

Add new 64-bit trap vectors.


# 1.13 06-Sep-1998 eeh

32-bit fixup.


# 1.12 06-Sep-1998 eeh

Disable some debug stuff.


# 1.11 05-Sep-1998 eeh

It slices. It dices. It does everything except exec a sparc32_compat init.


# 1.10 02-Sep-1998 eeh

Periodic update: now starts probing devices.


# 1.9 30-Aug-1998 eeh

Some more 64-bit cleanup. Now everything compiles.


# 1.8 29-Aug-1998 eeh

Some more 64-bit-ification.


# 1.7 27-Aug-1998 eeh

Add 64-bit pmap support:

Moved from a two level 512/1024 entry setup mapping 32 (9/10/13) bits
respectively to a three level 1024/1024/1024 entry setup mapping 43
(10/10/10/13) bits. In 32-bit mode we waste about 1/12 pages mapping the high
11 bits. We also only manage 43 of the possible 44 bits of virtual address
space, wasting half of it. Oh well, maybe we'll do better next revision.


Revision tags: PMAP32
# 1.6 26-Aug-1998 mrg

panicstack: is needed outside of DEBUG. use _C_LABEL, and printf not db_printf (incase no ddb!)


# 1.5 13-Aug-1998 eeh

Merge paddr_t changes into the main branch.


Revision tags: eeh-paddr_t-base
# 1.4 07-Jul-1998 eeh

branches: 1.4.2;
General update:

Added genassym.cf
Removed lderr which should never have gotten in
Removed lots of dead code from locore.s
Added some softint stuff to intr.c
Added support for halt -p
esp and le both use bus_dmamap_*() functions now
instead of kdvma_mapin()
groundwork for PCI (but we still have no drivers for
any sun4u PCI devices)


# 1.3 04-Jul-1998 jonathan

defopt DDB.


# 1.2 26-Jun-1998 thorpej

defopt COMPAT_SVR4


# 1.1 20-Jun-1998 eeh

branches: 1.1.1;
Initial revision


# 1.426 30-Mar-2021 palle

sun4v: handle spill trap properly when trap level is 1 and otherwin is non-zero - ensure that all windows are spilled to the pcb like the sun4u winfixsave code path


Revision tags: thorpej-cfargs-base
# 1.425 22-Feb-2021 palle

sun4v: handle spill normal user traps properly when current trap level is 1 - registers are spilled to the PA of the stack to avoid further mmu-related traps, since sun4v only has 2 trap levels


Revision tags: thorpej-futex-base
# 1.424 20-Dec-2020 palle

sun4v: add comment in sun4v_tl1_ptbl_miss code path - no functional change


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1
# 1.423 08-Jan-2020 skrll

branches: 1.423.6;
oldlwp is always non-NULL in cpu_switchto so remove the test for NULL.


# 1.422 08-Jan-2020 ad

Hopefully fix some problems seen with MP support on non-x86, in particular
where curcpu() is defined as curlwp->l_cpu:

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

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

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

- Remove some KERNEL_LOCK handling which hasn't been needed for years.


Revision tags: netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 ad-namecache-base netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.421 18-Jul-2019 palle

branches: 1.421.4;
sun4v: added some missing comments to the code in pcbspill


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 1.420 07-Apr-2019 mrg

make trap 0x70 a TRAP() not UTRAP(). we should be able to handle
fast ECC error as a normal trap, and i saw this once a few years
ago but it never repeated so i haven't been able to test this.


# 1.419 08-Feb-2019 palle

sun4v: Improve comment for next_stick_init() - no functional changes


# 1.418 08-Feb-2019 palle

sun4v: initialize %stickcmpr properly when establishing interrupt - fixes issue seen on newer sun4v/SPARC-T5 system where the interrupt never fires.


# 1.417 08-Feb-2019 palle

sun4v: introduce macros for handling spill traps from userlevevel @ traplevel 1 (from OpenBSD) - spill traps at level 1 from userspace now works better


# 1.416 08-Feb-2019 palle

sun4v: add comment documenting the contents of the %g2 register - no functional changes


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126
# 1.415 04-Nov-2018 palle

Ensure that the 64-bit condition codes are used instead of the 32-bit condition codes. ok martin@


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.414 26-May-2018 palle

branches: 1.414.2;
next_stick() - fix typy in comment: tick->stick


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.413 11-Apr-2018 palle

sun4v: handle MMU-related traps properly when they occur at trap level 1. This fixes issues when user-level LWPs access the user-level stack


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 1.412 26-Aug-2017 palle

branches: 1.412.2;
sun4v: Avoid touching the %tick_cmpr register which is not present on never systems (Oracle SPARC Architecture 2011 and beyond). Based on code from OpenBSD locore.s revision 1.177. Tested on both sun4u (qemu and USIII) and sun4v (qemu and T5-2). ok martin@


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2
# 1.411 06-May-2017 palle

sun4v: The %ver register is not available on sun4v - use GET_MAXCWP introduced in rev. 1.361. Verified using qemu (sun4u and sun4v) and on real sun4v hw (t2000)


Revision tags: prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.410 18-Apr-2017 palle

branches: 1.410.2;
sun4v: Add handling of trap 0x06c @ trap level 1 - based on code from OpenBSD, but slightly adapted to NetBSD. verified using qemu


Revision tags: jdolecek-ncq-base pgoyette-localcount-20170320
# 1.409 19-Feb-2017 palle

sun4v: rft_user needs special handling (a manual fill) since the restore instruction may cause the number of trap levels to exceed the maximum for sun4v - inspired by code from the the openbsd rft_user code path - verified using qemu for both sun4u and sun4v


# 1.408 10-Feb-2017 palle

sun4v: Added handling of trap type 0x034 (address alignment error) + fixed typo mmfsa -> mmufsa. Verified for both sun4u and sun4v using qemu.


Revision tags: nick-nhusb-base-20170204
# 1.407 30-Jan-2017 palle

sun4v: Hook up syscall handling to the trap table. Verified using qemu for both sun4u and sun4v.


# 1.406 27-Jan-2017 palle

sun4v: implement missing handling of itsb traps 0x008 and 0x009. Based on code from OpenBSD. Tested using qemu.


Revision tags: bouyer-socketcan-base
# 1.405 07-Jan-2017 palle

branches: 1.405.2;
sun4v: slowtrap() now selects normal globals properly on both sun4u and sun4v platforms. Verified using qemu for both sun4u and sun4v systems


Revision tags: pgoyette-localcount-20170107
# 1.404 05-Jan-2017 palle

sun4v: TRAP_SETUP() updated to set mmu context id properly for both sun4v and sun4u platforms. Verified using qemu for both sun4u and sun4v systems


# 1.403 04-Jan-2017 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x00-0x23 and 0x28-0x30


# 1.402 29-Dec-2016 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x32-0x7f


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.401 20-Sep-2016 nakayama

Fix RAS for 32-bit kernels. trapframe is always 64-bit.


Revision tags: localcount-20160914
# 1.400 23-Aug-2016 palle

sun4v: rework sun4v_datatrap so it works properly when running on a T2-based system like T5120 - for some reason %tl is 0 when entering sun4v_datatrap causing a crash (sir instruction), so ignore the %tl value for now upon entry to sun4v_datatrap - with this fix both T1 and T2 based systems reach the same point - hangs in rft_user after the init process is started


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726
# 1.399 18-Jul-2016 palle

sun4v: handle device interrupts properly - both legacy (sysino) and cookies


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 1.398 04-Jun-2016 palle

branches: 1.398.2;
sun4v: rtf_user now uses macros GET_MMU_CONTEXTID and SET_MMU_CONTEXTID. Tested on sun4u (QEMU) and sun4v (T2000). Parts from OpenBSD.


Revision tags: nick-nhusb-base-20160529
# 1.397 18-May-2016 nakayama

Decrement %tl in trap handler not to make it zero unconditionally
for the nested trap, and remove useless mov.


# 1.396 17-May-2016 palle

sun4v: Implement missng MMU protection trap handling - mostly from OpenBSD


# 1.395 16-May-2016 palle

Avoid assembler-specific defines by using the export keyword in genassym.cf instead


# 1.394 15-May-2016 nakayama

%g1 is not preserved across function call, so load it before
return_from_trap.


# 1.393 13-May-2016 palle

sun4v: add missing implementation of sun4v_datatrap_tl0 so data_access_fault() is called - mostly from OpenBSD


# 1.392 13-May-2016 nakayama

- ci_paddr is always 64-bit.
- intrlev is array of pointer.
- ih_ack is pointer.


# 1.391 10-May-2016 palle

sun4v: make device interrupts work. Introduce a new intrhand_alloc() function for allocation of interrupt handlers and adapt to this. Parts from OpenBSD. ok martin@


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.390 09-Mar-2016 nakayama

32-bit kernels use 32-bit stack.


# 1.389 03-Mar-2016 palle

sun4v: rft_kernel should pay attention to the number of register windows that can be restored. We cannot rely on fill traps to occur, since sun4v only has two trap levels available in privileged mode. Based on code from OpenBSD. ok martin@


# 1.388 14-Feb-2016 palle

sun4v: add breakpoint trap entry to the sun4v trap table


# 1.387 03-Feb-2016 palle

sun4v: extend dmmu_set_secondary_context() to handle both sun4u and sun4v. ok martin@


Revision tags: nick-nhusb-base-20151226
# 1.386 06-Nov-2015 martin

Basically revert r1.246 of locore.s and r1.73 of vm_machdep.c:

Remove special case handling for userland lwps from cpu_lwp_fork,
instead do it in lwp_trampoline when we first return to userland.

which was a stupid idea - since we did now set all fork child's %tstate
(and thus %pstate when back in userland) to the current kernel's userland
default. This meant we lost the address mask bit for 32bit processes and
all memory model details for 64bit ones.

Move it back to cpu_lwp_fork and fix the condition to only do it once when
forking init.


# 1.385 05-Nov-2015 martin

Most of the time return_from_trap already got called with tf->tf_tstate
loaded in register %g1 - make it so for two more callers and remove
the reload of that value.


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606 nick-nhusb-base-20150406
# 1.384 05-Apr-2015 palle

sun4v: Ensure that the TTEs CP and CV bits are the same (both set) for the primary cpu and secondary cpus INTSTACK mappings


# 1.383 01-Apr-2015 palle

sun4v: Implement handling of cpu_mondo trap - from OpenBSD - tested using the Legion simulator


# 1.382 04-Mar-2015 palle

sun4v: revert some of the logic introduced in revision 1.378 - flushw is not necessary on sun4v (OpenBSD patches the flushw instruction to a nop instruction) - with these changes the kernel reaches cpu_boot_secondary_processors() when running in the Legion simulator (crashes due to missing handling of cpu_mondo_trap)


# 1.381 02-Mar-2015 nakayama

prom_printf converts "\n" to "\r\n" internally, so omit "\r".


# 1.380 02-Mar-2015 nakayama

PANICSTACK is a pointer itself, not a pointer to pointer.


# 1.379 02-Mar-2015 nakayama

Use panic stack temporarily for calling prom_printf in a trap
handler.

It seems that openfirmware cannot handle over 4GB pointers, and
stack pointers may point to over 4GB since VA layout was rearranged
by rev 1.33 of vmparam.h. Therefore, use panic stack to avoid
panicking in OF_write used by prom_printf.


# 1.378 23-Feb-2015 palle

sun4v: sparc_interupt - ensure that the trap level and globals level are the same when the flushw instruction is issued - othwise warnings occur when using the sun4v Legion simulator.


Revision tags: nick-nhusb-base
# 1.377 26-Oct-2014 palle

branches: 1.377.2;
sun4v: Create CLEANWIN0 and CLEANWIN1 macros for handling clean window traps on both sun4u and sun4u (based on the original code inlined in the sun4u trap table). Update trap tables accordingly for both sun4u and sun4v. Ok martin@


# 1.376 24-Oct-2014 nakayama

Fix typo in comment.


# 1.375 18-Oct-2014 snj

src is too big these days to tolerate superfluous apostrophes. It's
"its", people!


# 1.374 15-Oct-2014 palle

sun4v: fixed bug causing the real address to be incorrectly calculated as zero


# 1.373 24-Sep-2014 palle

sun4v: add code to enable startup of secondary cpus on both sun4u and sun4v systems - ok martin@


# 1.372 04-Sep-2014 palle

sun4v: All cpus must be setup with a TSB descriptor, so pmap_setup_tsb_sun4v() must take a pointer to the TSB descriptor


# 1.371 31-Aug-2014 palle

sun4v: Split the NORMAL_GLOBALS and ALTERNATE_GLOBALS macros to _SUN4U and _SUN4V variants. Rework the return_from_trap logic to use the new variants so it is possible to use a global register as scratch register.


# 1.370 14-Aug-2014 nakayama

Add missing delay slot in DEBUG kernel.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.369 30-Jul-2014 palle

branches: 1.369.2;
Fix ALTERNATE_GLOBALS so it at least works on sun4u - using a scratch register is not a good idea...


# 1.368 27-Jul-2014 palle

sun4v: Introduce a new macro ALTERNATE_GLOBALS (matching NORMAL_GLOBALS). Two new helper macros ENABLE_INTERRUPTS and DISABLE_INTERRUPTS are also created. With these changes the GENERIC.UP kernel will reach rootmount on sun4v systems - ok martin@


# 1.367 26-Jul-2014 palle

Improved the NORMAL_GLOBALS macro in the sun4u case, so only the relevant bit (AG) in %pstate is affected - ok martin@


# 1.366 24-Jul-2014 palle

sun4v: add missing spill/fill handling for trap level 1 + cosmetic changes to comments for trap level 0 entries


# 1.365 19-Jul-2014 palle

sun4v: Introduce a NORMAL_GLOBALS macro - first used in sparc_interrupt - other relevant uses will be handled as the sun4v work is progressesing - ok martin@


# 1.364 16-Jul-2014 palle

sun4v: Introduce SET_MMU_CONTEXTID macro for setting the mmu context id on both sun4u and sun4v


# 1.363 13-Jul-2014 palle

sun4v: add interrupt handling to sun4v trap table


# 1.362 13-Jul-2014 palle

Bugfix: add missing cmp instruction to GET_MAXCWP macro


# 1.361 30-Jun-2014 palle

sun4v: The maximum number of register windows is a constant and thus not available via the %ver register (sun4u only). Introduce a macro GET_MAXCWP that handles this, so cpu_switchto() works properly on sun4v. Other relevant reference to %ver can be adapted to use GET_MAXCWP as the sun4v port progresses. OK martin@


# 1.360 31-May-2014 palle

sun4v: added missing dtsb miss handling for trap level 1 - with this update the kernel now reaches configure() on sun4v systems


# 1.359 30-May-2014 palle

Remove debugging code introduced by accident in locore.s revision 1.357


Revision tags: yamt-pagecache-base9 rmind-smpnet-nbase rmind-smpnet-base
# 1.358 05-May-2014 palle

sun4v: the trap base address should be assigned to %l1 so %tba is properly setup later in the code - now the kernel gets as far as printing the copyright disclaimer, kernel version and total and available memory before crashing


# 1.357 21-Apr-2014 palle

sun4v: Update comment: modified -> access


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.356 21-Feb-2014 palle

branches: 1.356.2;
sun4v: Rename TLB_ defines to SUN4U_TLB_ so entries created using TSB_DATA() are properly setup for sun4u and sun4v. Relocate the cputyp variable from autoconf.c to locore.s and make it const in param.h so optimized code can be generated. Parts from OpenBSD. Optimization suggested by nakayama@. OK martin@, mrg@, nakayama@


# 1.355 31-Jan-2014 tsutsui

defined(LKM) -> defined(MODULAR)


# 1.354 26-Jan-2014 palle

sun4v: Add handling of spill/fill and dtsb miss traps (with a XXX to be handled later)


# 1.353 07-Jan-2014 palle

sun4v: trap table setup - currently populated with dummy entries which will be properly implemented later - parts from OpenBSD - OK martin@


# 1.352 29-Dec-2013 nakayama

Make buildable w/o options SUN4V.


# 1.351 27-Dec-2013 palle

a) make the hunt through the cpus list more generic b) sun4v: ensure that the interrupt stack is mapped permanently and the TSB is setup properly - parts from OpenBSD. OK martin@


# 1.350 06-Dec-2013 nakayama

Increase an interrupt depth only in the case of hardware interrupts,
and remove the ci_idepth trick in softint_fastintr.

Fixes the following diagnostic panic reported in port-sparc64.

panic: kernel diagnostic assertion "!cpu_intr_p()" failed: file
"../../../../kern/subr_xcall.c", line 351


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 1.349 24-May-2013 nakayama

branches: 1.349.2;
Disable interrupts after calling data_access_error as with
data_access_fault.


# 1.348 28-Apr-2013 nakayama

Use macros in machine/asm.h instead of locally defined, and
introduce CASPTRA for casxa/casa.


Revision tags: agc-symver-base
# 1.347 23-Jan-2013 martin

Fix sparc64_ipi_ccall by adding proper trap setup.
Fixes xcall(9) problems, as exposed by pserialize(9). Noticed by
J. Hannken-Illjes, cause pointed out by Takeshi Nakayama.


# 1.346 23-Jan-2013 martin

Sligthly clean up the (by default unused) #ifdef TRAPS_USE_IG


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.345 10-Nov-2012 nakayama

Revise comment.


# 1.344 10-Nov-2012 nakayama

Use macro instead of magic number.


# 1.343 09-Nov-2012 nakayama

Make setstick() and getstick() to inline functions.


# 1.342 08-Nov-2012 macallan

use system tick timer instead of %tick on UltraSPARC-III-ish CPUs
review & fixes by Takeshi Nakayama


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.341 17-Mar-2012 mrg

branches: 1.341.2;
port the corrected ECC error handling code from freebsd. i noticed my U10
took one of these and then hang. it shouldn't hang, there's a 'sir' here that
doesn't seem to reset properly. oh well.

tested by simulated a trap via 'ta 0x10' and considering that the same, but
it hasn't been tested against a real ECC error yet.


Revision tags: jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base4
# 1.340 03-Mar-2012 nakayama

Fix the root cause of the hack "disable optimizations for uvm_bio.c
on 32 bit kernels".

gcc converts a division in the calculation of UBC_UMAP_ADDR macro
to multiplication (smul or combination of add/sll), and the
register of its result contains a garbage in upper 32 bits (the
upper 32 bits of smul/add/sll's result isn't zero cleared).

Then it passes to pseg_get{,_real} through pmap_extract without the
zero clear of upper 32 bits in the optimization case. So the
result of pseg_get and pmap_extact sometimes gets screwed up.


Revision tags: jmcneill-usbmp-base5 jmcneill-usbmp-base3
# 1.339 19-Feb-2012 rmind

Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.


Revision tags: jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.338 04-Sep-2011 nakayama

branches: 1.338.2; 1.338.6; 1.338.8;
ih_pil is an interrupt level, not an interrupt mask.


# 1.337 27-Jul-2011 nakayama

ivec is assigned to hardware, so count its event counter up in
interrupt_vector, not in softint, and do some optimization.


# 1.336 20-Jul-2011 macallan

add per ivec event counters


# 1.335 12-Jul-2011 mrg

rename sparc64 BLOCK_SIZE and BLOCK_ALIGN to have SPARC64_ prefixes.
for the assembler files, define the old names to the new names
since using the new names cause ugliness due to longer identifer
names, and reduces churn.

fixes build issues in dtv and vaguely makes <machine/psl.h> slightly
less name-space invasive.


# 1.334 18-Jun-2011 nakayama

Add fast softint(9) support for sparc64.

Reviewed on port-sparc64.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 1.333 12-May-2011 mrg

branches: 1.333.2;
first steps towards fujitsu SPARC64 support:

- SPARC64 systems have interrupts with upto 14 bits set, but we only look
at the first 11 bits. trim non IPI interrupts to 11 bits


Revision tags: uebayasi-xip-base7 bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 jym-xensuspend-nbase jym-xensuspend-base
# 1.332 20-Dec-2010 matt

branches: 1.332.2;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.


Revision tags: uebayasi-xip-base6 uebayasi-xip-base5 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 1.331 10-Jul-2010 nakayama

Clear the upper word explicitly before combining two 32-bit values to 64-bit
on 32-bit kernels.


# 1.330 23-May-2010 martin

Split copy related functions out of locore.s into copy.S, move functions
only needed on multiprocessors into mp_subr.S.


# 1.329 17-May-2010 martin

Simplify primary CPU startup slightly by using the fact that our cpuinfo's
curpcb pointer points to the uarea/pcb of lwp0 and by remembering the pointer
to this cpuinfo, thus avoiding a few CPUINFO_VA references.


Revision tags: uebayasi-xip-base1
# 1.328 20-Mar-2010 chs

fix copy{in,out}{,str}() to return the error returned by uvm_fault().
fixes PR 41813.


Revision tags: yamt-nfs-mp-base9
# 1.327 10-Mar-2010 mrg

branches: 1.327.2;
XXX: workaround we'd like to remove when pmap / uvm locking is cleaned up:

- rename pseg_get() and pseg_set() to pseg_get_real() and pseg_set_real().
- if USE_LOCKSAFE_PSEG_GETSET is defined, which it current is by default,
define pseg_[gs]et() in terms of functions that take a new pseg_lock
mutex at IPL_VM while calling into the real functions.

this seems to avoid the pseg_set() crashes we've seen:
1 - spare needed, when pseg_get() just worked for this pmap
2 - the 2rd ldxa via ASI_PHYS_CACHED in pseg_set() loads garbage
into %o4, and causes the 3rd ldxa to fault


# 1.326 08-Mar-2010 mrg

blast_dcache() SMP friendly:

- blast_dcache() becomes sp_blast_dcache(dcache_size, dcache_line_size)
- new smp_blast_dcache(sparc64_cpuset_t) that blasts the D$ on this cpuset
- sparc64_ipi_blast_dcache() to support the above
- in pmap_remove_all(), when freeing mmu contexts for this pmap, mark
the set of cpus to blast the d$ on as well and convert the
blast_dcache() call into smp_blast_dcache() on the cpus who ran this
pmap, or, sp_blast_dcache(dcache_size, dcache_line_size)
- convert the remaining blast_dcache() in machdep.c to sp_blast_dcache()
- in pmap_destroy()/pmap_remove_all() take the pmap_lock() always since
we assert it is held always.

with these changes, NFS builds on the U60 seem to be stable now, and
the USIII machines also can often complete a single build.sh run now,
diskful or diskless.


reviewed by mlelstv and partially by martin, tested by martin and myself,
with some ideas from chuq as well.


# 1.325 07-Mar-2010 mrg

need _ALIGN in locore.h as well, for DEBUG kernels.


# 1.324 07-Mar-2010 mrg

gas has supported SPARC ".empty" for a long while; get rid of an
ancient workaround.


# 1.323 06-Mar-2010 mrg

move the memcpy/memset implementations out into their own file, with the
block copy versions as well. move some of the definitions in locore.s
into a new locore.h.

locore.s is almost 2000 lines shorter with this change.


# 1.322 04-Mar-2010 mrg

- in _bus_dmamap_unload(), pmap_page_protect() and pmap_clear_reference()
switch the dcache_flush_page() into a dcache_flush_page_all()
- in both pmap_kremove()/pmap_remove(), remove the blast_dcache() call
and replace it with dcache_flush_page_all()
- in pmap_get_page() [used to allocate PTP's], always call pmap_zero_page(pa)
- flush the dcache of the dst page in pmap_{copy,zero}_page() by redirecting
throught a C function that calls the (renamed) asm. the old asm code had a
comment about needing to do this...
- add a couple of membar #Sync's that the USIII manual recommends


based on discussions with chuq@, skrll@ and martin@.


these help my SB2000 / SB2500 with both disk / nfs builds and other tasks,
sometimes lasting for several hours before failing or asserting.


# 1.321 24-Feb-2010 mrg

when handing back page table pages to UVM, flush them from the dcache
on all CPUs.

idea from skrll@, and makes my disk-based SB2000 stable.

tested on U60, SB2000 and SB2500.


# 1.320 24-Feb-2010 mrg

- re-introduce sp_tlb_flush_pte() and sp_tlb_flush_all() that call
the right USI/USIII version.
- define tlb_flush_pte() in terms of sp_tlb_flush_pte() for the
!MULTIPROCESSOR case

this centralises some CPU_IS_USIII_UP() tests.


# 1.319 22-Feb-2010 mrg

move {dump,print}_[id]tlb() into a separate file.


# 1.318 22-Feb-2010 mrg

- store the maximum [id]cache size / line size for each cpu

- remove patch_kernel() since it isn't necessary and has been patching
the wrong thing in general.

- implement USIII versions of blast_icache(), dcache_flush_page() and
cache_flush_phys(). use the newly recorded cache size/line sizes.

- in winfixsave, flush the D$ with the right size index and ops. this
kills one of the wrong tag->inval patches.

- for blast_dcache(), use the newly recorded dcache_size/line_size.

- for blast_icache(), use the newly recorded cache size/line sizes.
for the USIII verison, disable the I$ while writing to ASI_ICACHE_TAG.


these changes removed several hard coded cache sizes values, some very
wrong kernel patching, and seem to make the current failure modes for
USIII less common, but not gone.


# 1.317 15-Feb-2010 mrg

- don't flush 32-bit entries for 64-bit code, it does not seem to be
necessary. #define TLB_FLUSH_LOWVA to turn it back on.
- remove the #if 0'd code in sparc64_ipi_flush_pte_usiii(), i have
verified that it is not required.
- add a missing membar #Sync to sp_tlb_flush_pte_usiii().


# 1.316 15-Feb-2010 nakayama

Fix linker error of GENERIC32 kernel.


# 1.315 15-Feb-2010 mrg

use TLB_SIZE_SPITFIRE in a couple of places, and note that the
{print,dump}_[id]tlb() versions are currently spitfire specific.


# 1.314 15-Feb-2010 mrg

introduce a new patch_kernel() and call it from the end of bootstrap().
use it to patch up TLB flush instructions that don't match for USI/II
and later. we can also hopefully use this to make GENERIC.MP minimally
expensive on single CPU machines as well.

this is the last piece needed to get GENERIC/GENERIC.MP to boot on the
USIII* machines.

idea and some initial code from openbsd.


# 1.313 13-Feb-2010 mrg

remove KTR support. it's never been a working part of netbsd src tree.


# 1.312 09-Feb-2010 wiz

Fix typo in comment.


Revision tags: uebayasi-xip-base
# 1.311 06-Feb-2010 mrg

branches: 1.311.2;
- properly map the schizo interrupt registers, so we can use the normal
virtual mappings to access them.
- with the above fxied, kill SCHIZO_BUS_SPACE_BROKEN, and introduce
an options CHEETAH for now, that disables the SPITFIRE code in locore.
- merge schizo_init() into schizo_attach() and clean up the softc a bit.


with this we are only one more step away from GENERIC booting on USIII
machines.


# 1.310 02-Feb-2010 mrg

- split sp_tlb_flush_pte() and switchtoctx() into sp_tlb_flush_pte_us()/
sp_tlb_flush_pte_usiii() and switchtoctx_us()/switchtoctx_usiii() and
implement the latter while i'm here. it works ... sometimes i think,
but also sometimes panics/hangs.
- fix a comment in sparc64_ipi_flush_pte_usiii()


# 1.309 02-Feb-2010 mrg

for now, reduce a few #ifdef SPITFIRE cases by introducing a new
ASI_DCACHE_TAG_OR_INV that is either ASI_DCACHE_{TAG,_INVALIDATE}.

increase the common code in cache_flush_phys().


# 1.308 01-Feb-2010 mrg

- sp_tlb_flush_all() becomes sp_tlb_flush_all_us() and sp_tlb_flush_all_usiii()
- sparc64_ipi_flush_pte() becomes sparc64_ipi_flush_pte_us() and
sparc64_ipi_flush_pte_usiii()
- add some commented out code to disable interrupts and raise the traplevel
in sparc64_ipi_flush_pte_usiii()
- cache_flush_phys() was missing a little of code in the cheetah case


# 1.307 01-Feb-2010 mrg

for USIII, use the new "tlb demap all" operation in sp_tlb_flush_all()


# 1.306 01-Feb-2010 mrg

remove unused icache_flush_page() implementation.


# 1.305 23-Jan-2010 mrg

remove the final uses of DATA_START.

now we can remove the 16KB space reserved at the start of the data segment,
and i now understand why i wrote this now removed comment 3.5 years ago:
"this shouldn't be needed... but kernel usually hangs without it"


# 1.304 23-Jan-2010 mrg

remove most of the code that writes debugging info DATA_START + offset.


# 1.303 23-Jan-2010 mrg

remove CHKPT() macro and uses. it's likely wrong in SMP land and probably should
be replaced with KTR-style uses if necessary.


# 1.302 23-Jan-2010 mrg

fix a comment.


Revision tags: matt-premerge-20091211
# 1.301 10-Dec-2009 rmind

Rename L_ADDR to L_PCB and amend some comments accordingly.


# 1.300 05-Dec-2009 mrg

- adjust the PA mask to the 43 bits supported by USIII.
- rework the spitfire/cheetah cache_flush_phys() to avoid several #ifdefs
- add a membar #Sync after sparc64_ipi_drop_fpstate (probably unnecessary)


# 1.299 30-Nov-2009 nakayama

sp_tlb_flush_pte for cheetah:
- restore interrupts properly in case of %tl > 0.


# 1.298 30-Nov-2009 mrg

stablize UP USIII support by blocking interrupts around sp_tlb_flush_pte()
i was seeing stack corruption while taking an interrupt in this function.

get USIII SMP mostly working by implementing the cheetah version of
sparc64_ipi_flush_pte().


SMP support is still not entirely stable. i can reproducably get a:

panic: fpusave_lwp ipi didn't

while running build.sh, when an awk process is exiting. other simple
heavy work loads do not crash for me right now.


# 1.297 30-Nov-2009 mrg

delete some no longer used code:
- smp_tlb_flush_ctx()
- smp_tlb_flush_all()
- sparc64_ipi_flush_ctx()
- sparc64_ipi_flush_all()
- sp_tlb_flush_ctx()


# 1.296 29-Nov-2009 nakayama

- calculate end PA correctly.
- wrap more spitfire specific (flushing I$) code.
- fix inverted #if condition for flushing I$ (and restore ASI_ICACHE_TAG).


# 1.295 28-Nov-2009 mrg

implement enough code to get SB2000/SB2500 booting to multiuser. does
not last long if you use it, but an idle machine has stayed up 10 hours.

- for the !SPITFIRE case, use ASI_DCACHE_INVALIDATE instead of
ASI_DCACHE_TAG when clearing tlb entries. from openbsd.

- convert some comment "! Not yet" into "WRITEME", so that attempting
to build a USIII MULTIPROCESSOR kernel fails to build until the code
is written.

- add some more WRITEME's for the above.

- implement a !SPITFIRE version of sp_tlb_flush_all(). since there are
no spare regs, for now just always increase %tl around this call. (we
could maybe store a token in %o3 along with the saved %pstate info.)


# 1.294 26-Nov-2009 matt

Kill proc0paddr. Use lwp0.l_addr instead.


# 1.293 25-Nov-2009 mrg

s/L_ADDR/L_PCB/, requested by rmind.


# 1.292 17-Oct-2009 nakayama

Wrap unused code with #if 0 which is called from #if 0'ed code.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5
# 1.291 30-May-2009 martin

cpu_setfunc() can not use lwp_trampoline, as that has additional lwp startup
semantics. Use a simpler setfunc_trampoline instead.


# 1.290 18-May-2009 nakayama

Remove random() from locore.s since it is in libkern.


# 1.289 16-May-2009 nakayama

Remove clear %tick in locore.s since it is cleared at cpu_initclocks() in
clock.c.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 nick-hppapmap-base mjf-devfs2-base
# 1.288 15-Dec-2008 mrg

restore some old "intrdebug" code, but leave it under NOT_DEBUG. most
of it works, but one that prints func/arg for each handler is not very
stable...

for now, while schizo bus space pointer accesses aren't working, add
a SCHIZO_BUS_SPACE_BROKEN option so you can build a kernel with schizo.

with this, and the prior schizo interrupt fix, you can now fail to run
/sbin/init!


Revision tags: haad-dm-base2 haad-nbase2 haad-dm-base
# 1.287 09-Dec-2008 martin

Get rid of get_maxctx() - it doesn't work on newer cpus and we will have
to find a better way for (some) sun4v machines - all sun4u use 13 bit
contexts anyway.


Revision tags: netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 ad-audiomp2-base netbsd-5-base
# 1.286 30-Oct-2008 nakayama

branches: 1.286.2; 1.286.6;
Wrap more code specific to USE_BLOCK_STORE_LOAD.


Revision tags: matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4
# 1.285 05-Oct-2008 nakayama

branches: 1.285.2;
- in flushing cache, use 32 as increment/decrement value to match the
cache line size.
- remove useless restore of %asi.
- remove nop in delay slot if we can.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 1.284 10-Jul-2008 nakayama

Use proper CCR.


# 1.283 10-Jul-2008 nakayama

sparc64_ipi_save_fpstate:
- use primary MMU context for consistency with other trap/interrupt handlers.

sparc64_ipi_save_fpstate, savefpstate:
- avoid storing fp registers as we can.

sparc64_ipi_save_fpstate, savefpstate, loadfpstate:
- remove unaligned case since buffers allocated with pool_cache are ensured
64-byte aligned.

Ok by martin@.


# 1.282 02-Jul-2008 nakayama

branches: 1.282.2;
UltraSPARCs don't have floating point queue, and reading %fq regsiter
will cause illegal instruction trap. So remove the code handling them.


# 1.281 29-Jun-2008 nakayama

Wrap IPI calls with #ifdef MULTIPROCESSOR.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.280 14-Jun-2008 nakayama

Close unterminated comment.
Fix unexpected behavior in case of loadfpstate from unaligned buffer.


Revision tags: yamt-pf42-base3
# 1.279 31-May-2008 nakayama

branches: 1.279.2;
openfirmware_exit:
- disable interrupts with %pstate.
- prepare 64-bit stack and enable 64-bit addresses for 32-bit SMP kernels.


Revision tags: hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 yamt-nfs-mp-base yamt-pf42-base
# 1.278 16-Apr-2008 nakayama

branches: 1.278.2; 1.278.4; 1.278.6;
Disable TRAPSTATS which was accidentally enabled when yamt-idlelwp branch
was merged.

Ok by martin@.


# 1.277 14-Apr-2008 nakayama

Remove sparc64_ipi_sync_tick.

Since we can use counter-timer as timecounter instead of %tick on SMP kernel,
it is not necessary to sync all CPUs %tick registers.


# 1.276 14-Apr-2008 nakayama

Add workaround for BB_ERRATA_1 on writing to TICK_CMPR register in
next_tick(). If writing to TICK_CMPR fails, we lose hardclock interrupt
on secondary CPUs.

About BB_ERRATA_1 from comment in OpenSolaris:

/*
* Writes to the TICK_COMPARE register sometimes fail on blackbird modules.
* The failure occurs only when the following instruction decodes to wr or
* wrpr. The workaround is to immediately follow writes to TICK_COMPARE
* with a read, thus stalling the pipe and keeping following instructions
* from causing data corruption. Aligning to a quadword will ensure these
* two instructions are not split due to i$ misses.
*/


# 1.275 28-Mar-2008 nakayama

Don't read fplwp content in delay slot for considering the case fplwp was
modifiled.

Reported by Chris Ross on port-sparc64.


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.274 20-Mar-2008 nakayama

- remove disabling interrupt in IPI.
- unused VA bits in MMU demap is 13 bits, not 12 bits.


# 1.273 18-Mar-2008 nakayama

Fix a race when increment an interrupt level event counter.


# 1.272 17-Mar-2008 nakayama

Fix a race condition in IPI handlers of save/drop fpstate, from OpenBSD.
Reported and tested by martin@.


# 1.271 17-Mar-2008 nakayama

Make schedintr interrupt handler per-CPU.
While there rename tickintr interrupt handler and share initialization
code with schedintr.


# 1.270 14-Mar-2008 nakayama

Improve IPI handling:
- make IPI takes two arguments.
- add IPI event counters per-CPU.
- implement IPI functions which were missing or broken.
- insert DELAY while halting primary CPU in IPI handler.


# 1.269 02-Mar-2008 nakayama

- make interrupt pending list per-CPU.
- make tickintr() MP-safe.
- remove unused port-sparc derived interrupt code.

Ok by martin@.


# 1.268 02-Mar-2008 nakayama

Don't get IPI handler argument (from bogus address), and ack IRQ twice.


# 1.267 28-Feb-2008 martin

Make TSBs and MMU contexts per-cpu.


Revision tags: nick-net80211-sync-base mjf-devfs-base hpcarm-cleanup-base
# 1.266 26-Jan-2008 nakayama

branches: 1.266.2; 1.266.6;
Fix for 32-bit kernels.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.265 15-Jan-2008 skrll

Store a sensbile PCB_PC value in snapshot - the return point.

This helps gdb somewhat.

OK'd by martin.


# 1.264 14-Jan-2008 martin

Fix register name typo/copy&pasto - %g6 is not %o6/%sp.
From OpenBSD.


Revision tags: matt-armv6-base
# 1.263 06-Jan-2008 martin

Load the next cpu_info pointer with LDPTR instead of ld.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2
# 1.262 09-Dec-2007 martin

branches: 1.262.2;
Provide cpu_intr_p(), at least for non-MULTIPROCESSOR kernels.
Based on suggestions by Andrew Doran.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.261 22-Oct-2007 martin

branches: 1.261.2; 1.261.4; 1.261.6;
Remove an unused .globl declaration


Revision tags: yamt-x86pmap-base4
# 1.260 17-Oct-2007 garbled

Merge the ppcoea-renovation branch to HEAD.

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

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

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base ppcoea-renovation-base vmlocking-base
# 1.259 09-Sep-2007 martin

branches: 1.259.4;
Make cpufrequency and friends per cpu values.
Prepare a hz tick interrupt on secondary CPUs via %tick, but do not
enable it yet, as it breaks ddb.


# 1.258 09-Sep-2007 martin

Do not ACK IPIs before we finished loading all arguments.


# 1.257 06-Sep-2007 martin

Remove the (now unused) second 64k page mapped per CPU.
From matthew green, with small changes by me. All bugs are mine.


# 1.256 25-Aug-2007 martin

branches: 1.256.2;
Remove INITSTACK completely - at the time we used to switch to it, we
already have access to all of lwp0 and it's uarea - so we can switch
to the correct lwp0 stack easily before calling main.


# 1.255 25-Aug-2007 martin

When exiting to OF, use the interrupt stack instead of INITSTACK


# 1.254 25-Aug-2007 martin

Rework cpu_mp_startup slightly:
- temporarily use the cpu's interrupt stack untill we are ready
to access non-OF-based mappings, then directly switch to the cpu's
idlelwp's uarea stack
- disable interrupts untill we are ready to call C code


# 1.253 13-Aug-2007 macallan

remove two restore without matching save


Revision tags: nick-csl-alignment-base matt-mips64-base mjf-ufs-trans-base
# 1.252 06-Jul-2007 martin

branches: 1.252.4; 1.252.8;
A few nits for 32bit SMP kernels, noticed by mrg.
While there, simplify the fpstate IPIs a bit.


# 1.251 05-Jul-2007 martin

sparc64_ipi_save_fpstate is not a leaf function - create a full grown
stack frame.


# 1.250 28-May-2007 mrg

clean up cpu_switchto() a little - no need to flushw or membar
excessively. optimise an rdpr. tested by tnn.


# 1.249 23-May-2007 martin

Fix a stupid bug in the save_fpstate ipi, which caused overwriting of
struct lwp of the lwp owning the fpu. Fix clearing the fplwp - %o0 will
not survive the call to savefpstate - duh!


# 1.248 20-May-2007 martin

Simplify tf_tstate setting when leaving for userland initially - I seem
to have confused the if with the else case of the previous C code.
Funny that it worked at all.


# 1.247 20-May-2007 martin

cpu_switchto() has to return it's first arg, always. This differs from
my reading of the documentation, but helps in the real world and seems
to be what other ports do.


# 1.246 20-May-2007 martin

Remove special case handling for userland lwps from cpu_lwp_fork, instead
do it in lwp_trampoline when we first return to userland.


# 1.245 19-May-2007 martin

cpu_idle is a leaf function, so we better "return from leaf".
Use return value from cpu_switchto for previous lwp in lwp_trampoline.
Also shamelessly steal a comment from uwe written for sparc that explains
all this.
Thanks to tnn, mrg, and uwe for helping to debug this.


# 1.244 17-May-2007 yamt

merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base ad-audiomp-base
# 1.243 22-Feb-2007 martin

branches: 1.243.4; 1.243.6; 1.243.12;
uvm.page_idle_zero now is a bool, not a 32bit value any more.


# 1.242 21-Feb-2007 mrg

shave 9 insns off the tsb setup in cpu_initialize & cpu_mp_startup.


# 1.241 21-Feb-2007 martin

Get rid of unused (thus always zero) "curlwp" variable hidden in assembler
code (C code always uses a cpuinfo based macro).


# 1.240 18-Feb-2007 martin

Make use of another call delay slot, pointed out by uwe.


# 1.239 18-Feb-2007 martin

Make use of a call delay slot and avoid a bogus EMPTY.
Spotted by Juergen Hannken-Illjes, with input from Andrew Doran and
Valeriy E. Ushakov.


# 1.238 18-Feb-2007 martin

Whitespace cosmetics


# 1.237 18-Feb-2007 martin

Backout previous: EMPTY was misused


# 1.236 18-Feb-2007 martin

Make EMPTY expand to nop with gas, as it is used to mark empty branch
delay slots.


# 1.235 15-Feb-2007 martin

branches: 1.235.2;
Fix obvious copy&pasto in SCHED_DEBUG register usage.


Revision tags: post-newlock2-merge
# 1.234 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.233 25-Dec-2006 wiz

Spell "relevant" correctly. From Zafer Aydogan.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.232 25-Oct-2006 mrg

branches: 1.232.2; 1.232.4;
- note that __idle_u should go away but doing so breaks things
- fix several comments to reality
- clean up the #ifdef NO_VCACHE code slightly
- use call instead of set/jmpl
- remove a couple of unnecessary stores to curlwp


Revision tags: yamt-splraiseipl-base2
# 1.231 18-Oct-2006 rjs

Clean up some comments. Cosmetic change to use correct structure
offset names.

Optimize out two instructions from sparc64_ipi_save_fpstate and
sparc64_ipi_drop_fpstate.


# 1.230 17-Oct-2006 mrg

allocate 128KB (as opposed to 64KB) per-cpu, and place the interrupt
stack, cpu_info structure, panicstack, idle uarea and normal kernel
stack in here. the idle uarea and kernel stack are in the 2nd 64KB
page. the interrupt stack and cpu_info structure are as the same
place in the 1st 64KB page, and the panicstack grows down from the
top of this page. update comments in param.h to suit (XXX: a lot
of these constants should move to a header file that will not pollute
the name space so much.) map these pages identically between
cpu_initialise() and cpu_mp_startup(), and deal with the two 64KB
pages in pmap_extract(). keep an unmapped 64KB page between them.

don't initialise the unused "ci_eintstack" member of the cpu_info
structure

use constants to initialise many addresses in the cpu_info structure,
consolidating these assignments from cpu0 and cpu>0

delete u0/estack0/panicstack from locore.s

clean up some wrong comments in locore.s

fix a 32bit-only bug in cpu_mp_startup().

delete 'u0' entirely.


this fixes recent random lossage seen on port-sparc64: processes
stuck in RUN state, data faults, and hangs.


# 1.229 04-Oct-2006 mrg

use call instead of set/jmpl. add an entry point for idle that expects
sched_lock to be unlocked, and use this for non-boot cpu's. complete a
comment describing how registers in idle_switch are expected to be set.


# 1.228 03-Oct-2006 mrg

use the same SAVE_LOCALS_INS definition for 32 bit and 64 bit kernels.
refactor TRAP_SETUP() a little between these two versions to be more alike.


# 1.227 03-Oct-2006 mrg

use the correct size/type for MP variables (pointers and longs).

a 32 bit MULTIPROCESSOR kernel now builds (and crashes quickly.)


# 1.226 03-Oct-2006 mrg

in the 64bit version of SAVE_LOCAL_INS, s/BIAS/STKB/ to allow future
sharing of the 32 and 64 bit versions of the {TRAP,INTR}_SETUP macros.


# 1.225 19-Sep-2006 mrg

- remove some way old FP setup/teardown code
- put the block memcpy/memset inside #ifdef USE_BLOCK_STORE_LOAD which
is (now) defined.

no functional change, same .o is generated.


# 1.224 19-Sep-2006 mrg

re-order the changes in rev 1.217 to give registers a little bit of
time to settle between usage, like it was before hand.


# 1.223 19-Sep-2006 mrg

- remove a wrong comment.
- add a new entry point for idle called idle_switch that is called by
cpu_switch() in the MP case when sched_whichqs is zero, properly
setting up the idle stack. from petrov@ via martin@.


# 1.222 19-Sep-2006 mrg

rework interrupt_vector() slightly:
- for the IPI case, avoid loading the address of intrlev into %g3
- remove some NOT_DEBUG code
- load the interrupt argument #2 in the delay slot

this removes 2 nops during interrupt processing for the normal
case, and an additional 2 ALU instructions for IPIs


# 1.221 18-Sep-2006 mrg

- sparc64_ipi_halt(): we shouldn't return from sparc64_ipi_halt_thiscpu()
so replace a branch with a 'sir'
- in #if 0 code, in sparc64_ipi_flush_pte() and sparc64_ipi_flush_ctx()
save/restore the out registers that the sp_tlb_flush_xxx() versions
around calling them
- in sp_tlb_flush_pte() and sp_tlb_flush_ctx(), replace global register
usage with out registers so that we don't clobber the (alternate)
global registers when these are called from IPI context


# 1.220 18-Sep-2006 mrg

- remove an extra 'sir' that followed one in a macro
- add some named labels to some spill/fill handlers
- remove 2 unused strings


Revision tags: yamt-splraiseipl-base
# 1.219 18-Sep-2006 martin

branches: 1.219.2;
Lazy FPU handling for the MULTIPROCESSOR case


# 1.218 16-Sep-2006 nakayama

From OpenBSD:
- reload %fprs for checking it again.
- use symbolic names for checking in %fprs.

revision 1.51
date: 2005/07/18 14:50:11; author: deraadt; state: Exp; lines: +2 -1
cache a copy of the fprs so we know what fp restore we should do after

revision 1.50
date: 2005/07/14 01:46:13; author: deraadt; state: Exp; lines: +4 -4
use symbolic names for checking in %fprs, as above


# 1.217 16-Sep-2006 nakayama

Fix a couple of %y register save/restore errors, inspired from OpenBSD.

revision 1.44
date: 2004/04/23 04:18:17; author: marc; state: Exp; lines: +5 -4

fix a couple of %y register save/restore errors
1) don't save %y in a register that is later used before restoring %y
2) always restore %y after calling a signal handler
tested by drahn@, OK pval


# 1.216 15-Sep-2006 martin

Do not bother to save fpu state when we are about to get rid of it.


Revision tags: yamt-pdpolicy-base9
# 1.215 13-Sep-2006 mrg

SMP cleanup. provide support for multiple CPUs in DDB. (SMP itself
is still not working.)

cpu.h:
- add a pointer for DDB regs in SMP environment to struct cpu_info
- remove the #defines for mp_pause_cpus() and mp_resume_cpus()
cpuset.h:
- remove CPUSET_ALL() and rename CPUSET_ALL_BUT() to CPUSET_EXCEPT()
from petrov.
db_machdep.h:
- rename the members of db_regs_t to be the same as sparc
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- redo DDB_REGS to no longer be a pointer to a fixed data structure
but to one allocated per-cpu when ddb is entered
- move a bunch of prototypes in here
intr.h:
- remove SPARC64_IPI_* macros, no longer used
db_interface.c:
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- make "nil" a 64 bit entity
- change the ddb register access methods to work in multiprocessor
environment, it is now very much like sparc does it
- in kdb_trap() avoid accessing ddb_regp when it is NULL
- update several messages to include the cpu number
- unpause other cpus much later when resuming from ddb
- rename db_lock() to db_lock_cmd(), as the sparc-like code has
db_lock as a simple lock
- remove "mach cpus" command, and replace it with "mach cpu" (which
does the same) and also implement "mach cpu N" to switch to
another cpus saved trapframe
db_trace.c:
- update for the ddb_regs -> ddb_regp change
genassym.cf:
- add TF_KSTACK as offsetof(struct trapframe64, tf_kstack)
ipifuncs.c:
- overhaul extensively
- remove all normal interrupt handlers as IPI's, we now handle
them all specially in locore.s:interrupt_vector
- add a simplelock around all ipi functions - it's not safe for
multiple cpus to be sending IPI's to each other right now
- rename sparc64_ipi_pause() to sparc64_ipi_pause_thiscpu() and,
if DDB is configured, enable it to save the passed-in trapframe
to a db_regs_t for this cpu's saved DDB registers.
- remove the "ipimask" system (SPARC64_IPI_* macros) and instead
pass functions directly
- in sparc64_send_ipi() always set the interrupt arguments to 0,
the address and argument of the to be called function. (the
argument right now is the address of ipi_tlb_args variable, and
part of the reason why only one CPU can send IPI's at a time.)
don't wait forever for an IPI to complete. some of this is
from petrov.
- rename sparc64_ipi_{halt,pause,resume}_cpus() to
mp_{halt,pause,resume}_cpus()
- new function mp_cpu_is_paused() used to avoid access missing
saved DDB registers
- actually broadcast the flush in smp_tlb_flush_pte(),
smp_tlb_flush_ctx() and smp_tlb_flush_all(). the other end may
not do anything yet in the pte/ctx cases yet...
kgdb_machdep.c:
- rework for changed member names in db_regs_t.
locore.s:
- shave an instruction from syscall_setup() (set + ld -> sethi + ld)
- remove some old dead debug code
- add new sparc64_ipi_halt IPI entry point, it just calls the C
vector to shutdown.
- add new sparc64_ipi_pause IPI entry point, which just traps into
the debugger using the normal breakpoint trap. these cpus usually
lose the race in db_interface.c:db_suspend_others() and end up
calling the C vector sparc64_ipi_pause_thiscpu().
- add #if 0'ed code to sparc64_ipi_flush_{pte,ctx}() IPI entry
points to call the sp_ version of these functions.
- in rft_kernel (return from trap, kernel), check to see if the
%tpc is at the sparc64_ipi_pause_trap_point and if so, call
"done" not "retry"
- rework cpu_switch slightly: save the passed-in lwp instead of
using the one in curlwp
- in cpu_loadproc(), save the new lwp not the old lwp, to curlwp
- in cpu_initialize(), set %tl to zero as well. from petrov.
- in cpu_exit(), fix a load register confusion. from petrov.
- change some "set" in delay branch to "mov".
machdep.c:
- deal with function renames
pmap.c:
- remove a spurious space
trap.c:
- remove unused "trapstats" variable
- add cpu number to a couple of messages


# 1.214 09-Sep-2006 mrg

significant clean up effort, largely from petrov@ via martin@.

- fix a bunch of comments for proc->lwp
- remove old TRAPTRACE, NOT_DEBUG, etc. code that has bit-rotted
- put some older DEBUG code under NOT_DEBUG
- add a bunch of new debugging/tracing code ("KTR") that depends on
other changes not yet present.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base yamt-pdpolicy-base5 chap-midi-base simonb-timecounters-base rpaulo-netinet-merge-pcb-base
# 1.213 14-May-2006 elad

branches: 1.213.6; 1.213.8;
integrate kauth.


# 1.212 12-May-2006 skrll

Fix some comments.


Revision tags: elad-kernelauth-base
# 1.211 09-May-2006 rjs

Load CPCB in cpu_mp_startup.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.210 11-Feb-2006 cdi

branches: 1.210.2; 1.210.4; 1.210.6;
ANSIfication: u_intN_t -> uintN_t, use ANSI function declarations/definitions
instead of K&R ones.


# 1.209 27-Jan-2006 cdi

branches: 1.209.2; 1.209.4;
Alter sparc64 bootstrap, catch up to ofwboot v1.9:

- Accept bootinfo structure passed down from ofwboot v1.9
- Drop kernel re-mapping code
- Use permanent 4MB mappings provided by the loader instead
- Change kernel entry address to point directly at the code instead of pointing
at the trap table's first slot. This allows the bootloader to detect
those kernels which are aware of the new boot scheme
- Due to the changes in kernel mapping code, alter secondary CPU bootstrap
code to use trampoline just like FreeBSD does (some FreeBSD code is used
here as well)


# 1.208 12-Jan-2006 cdi

Fix a typo: %g0 should be used instead of %o0 when initializing FPU in dostart:
and cpu_mp_startup:, %o0 is not even initialized at this point.


# 1.207 11-Dec-2005 christos

branches: 1.207.2;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 1.206 10-Jul-2005 christos

Re-factor syscall, and make it use syscall_{plain,fancy}.


# 1.205 31-May-2005 chs

branches: 1.205.2;
remove vestigal {,e}intr{names,cnt} symbols now that vmstat doesn't need them.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.204 12-Feb-2005 chs

branches: 1.204.4; 1.204.6; 1.204.8;
in sparc_interrupt(), wait to enable interrupts until just before calling
the handler and disable them again right after the handler returns.
we don't want another hardware interrupt coming in while we're mucking
with the list pointers. also, clear the intrhand's ih_pending pointer
before calling the handler rather than after, so that if another interrupt
comes in while the handler is running, we can put the intrhand back on
the list so it will be called again.

in send_softint(), disable interrupts via %pstate instead of %pil, so that
hardware interrupts at higher levels are blocked while we manipulate the
intrpending list. also, if the intrhand already has ih_pending set,
don't bother poking the SET_SOFTINT register again, since being on the list
implies that there is already a softint pending in the hardware.

these appear to fix PR 21750 (the "sleep forever" problem).

while I'm here, remove more vestiges of the !INTRLIST softint stuff
(code and comments). and in sparc64_ipi_flush_all(), interrupts are
already disabled so we don't need to fiddle with %pstate.


Revision tags: yamt-km-base2
# 1.203 30-Jan-2005 martin

Remove the no long usefull variants selected by undefining INTRLIST and
INTR_INTERLOCK to improve readability. Same object code generated as before.


Revision tags: yamt-km-base
# 1.202 16-Jan-2005 chs

branches: 1.202.2;
use ENTRY_NOPROFILE() for various entry points,
stack traces work better that way.


Revision tags: kent-audio1-beforemerge kent-audio1-base
# 1.201 03-Dec-2004 chs

branches: 1.201.4;
remove cache_flush_virt() and PADDRT, they're no longer used.
allocate a stack frame for blast_dcache() when profiling so it shows up.
in dcache_flush_page(), use a stride of 32 instead of 16 to match the
cache line size. correct various comments.


# 1.200 08-Nov-2004 petrov

Don't compile sparc64_ipi functions when UP.


# 1.199 25-Oct-2004 martin

No need to clear %o1 when returning a 64 bit integer from pseg_get if we
are compiling for a 64 bit kernel.


# 1.198 24-Jul-2004 nakayama

Change interrupt pending list end value to -1, to avoid linking an
interrupt handler twice.

It may fix "sleep forever" bug.


# 1.197 09-Apr-2004 petrov

Clean-up unused defines and variables.


Revision tags: netbsd-2-0-base
# 1.196 26-Mar-2004 petrov

branches: 1.196.2;
Use want_resched from cpu_info area.


# 1.195 23-Mar-2004 martin

Replace intrcnts by evcnts. XXX - needs slight tweaking for MULTIPROCESSOR.


# 1.194 14-Mar-2004 chs

checkpoint of MP work from dennis and myself. includes cross-processor
interrupt framework, a sledgehammer TLB invalidation and misc MP fixes.
doesn't work at all yet.


# 1.193 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.192 19-Jan-2004 martin

Rename switchexit to cpu_exit and g/c the old C implementation of cpu_exit.


# 1.191 18-Jan-2004 martin

Support RAS for 32bit kernels too.


# 1.190 16-Jan-2004 martin

In proc_trampoline don't bother to clear condition codes in the trap
frame, since we no longer rely on this.
While there fix a few comments.


# 1.189 08-Jan-2004 martin

Minor cleanup


# 1.188 06-Jan-2004 martin

Implement restartable atomic sequences (RAS) for sparc64.


# 1.187 06-Jan-2004 petrov

Spinup secondary cpus. Based on codes sent to me by Dennis Chernoivanov
and Chuck Silvers.


# 1.186 04-Jan-2004 jdolecek

update to recent changes - exit2() doesn't exist anymore and the
exit path always calls lwp_exit2()
pointed out Martin Husemann


# 1.185 02-Dec-2003 martin

Minor cleanup: remove unused code, sync a comment with current reality.


# 1.184 25-Nov-2003 cdi

Use per-cpu pcb, curlwp and fplwp rather than global ones. This brings
GENERIC.MP configuration to a usable state.

Approved by petrov@.


# 1.183 24-Nov-2003 cdi

Call 'proc_trampoline_mp' from 'proc_trampoline' in a multiprocessor
configuration. Fix process locking. Approved by petrov@.


# 1.182 20-Nov-2003 petrov

Remove nwindows calculation, it's not used. Set l_cpu in cpu_switch.


# 1.181 09-Nov-2003 martin

Get rid of bcopy/bzero.


# 1.180 26-Oct-2003 christos

Initial siginfo support for sparc64 (untested). COMPAT_16 sigcontext signal
delivery tested.


# 1.179 24-Aug-2003 chs

add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default. the changes
fall into two basic catagories:

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

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

originally from openbsd, adapted for netbsd by me.


# 1.178 08-Jul-2003 cdi

traceit: don't use %g7 as it is to become curcpu() register. Add comments.


# 1.177 18-May-2003 martin

branches: 1.177.2;
Make kernels with options KGDB at least compile.
Still needs some work to make it working.


# 1.176 29-Apr-2003 nakayama

Use BLOCK_ALIGN rather than BLOCK_SIZE for aligning a pointer.


# 1.175 27-Apr-2003 ragge

Preserve the symbol table in the LKM || KSYMS cases also.


# 1.174 04-Apr-2003 petrov

use branch slot in pmap_copy_page.


# 1.173 24-Mar-2003 nakayama

Divide `set' instruction in delay slot (from OpenBSD change to rev 1.30).


# 1.172 10-Feb-2003 martin

Remove some #if 0 code and a few XXX marked membars w/o proper
justification for their existence.


# 1.171 09-Feb-2003 martin

Remove left over pieces from reusing the signal trampoline for upcalls.
This should fix signal delivery for 32bit kernels.


# 1.170 05-Feb-2003 nakayama

Switch to use cycle counter (%tick) based microtime().

This is derived from alpha/microtime.c and i386/tsc_microtime.c,
and will share with both ports.

This should fix PR port-sparc64/18452.
(approved by martin)


# 1.169 04-Feb-2003 martin

Fix return value of pseg_set, which I accidently broke in rev. 1.164.

Fix register names in comment and shave off another register (hint
from uwe).


# 1.168 01-Feb-2003 martin

Rearrange register usage in pseg_set a bit and shave off %g4.


# 1.167 01-Feb-2003 martin

Remove a few #ifdef _LP64 by using STPTR/LDPTR macros.
Thanks to Matthew Green for the pointer.


# 1.166 31-Jan-2003 martin

Apply leaf procedure optimization to pseg_set (again).


# 1.165 31-Jan-2003 martin

Make the pmap count resident/wired mappings on the fly instead of
walking the page tables whenever this information is needed.

Add an option PMAP_COUNT_DEBUG to assert the new counts and the
page table walk agree.

The old solution had very bad performance impact, for example
by the high CPU load when running top(1).

Thanks to Simon Burge for pointing at the cause of the problem and
to Valeriy E. Ushakov for optimizing my simple minded assembler code.


# 1.164 27-Jan-2003 martin

Remove unused function pseg_find (which looked quite similar to
pseg_get anyway).


# 1.163 18-Jan-2003 thorpej

Merge the nathanw_sa branch.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.162 16-Jan-2003 petrov

Move dump_dtlb back under DDB.


# 1.161 15-Jan-2003 chs

fix two bugs in my last pmap rework:
- in tlb_flush_all(), don't skip TLB entries with the high bit on,
I was confused about which MMU register it was using. it's also fine
to use the last hardware context.
- in pmap_create(), don't allocate a hardware context for the new pmap.
it's unnecessary, and when this would cause us to recycle all the contexts,
it would result in the current process's context being set to 0
(ie. the kernel's context). the current process could then return to
userspace without going through the context-switch code (and thus without
having a hardware context reallocated). this would lead to user mappings
being entered in the kernel's context later, causing all sorts of trouble.
add some assertions to catch this kind of thing.


Revision tags: fvdl_fs64_base
# 1.160 25-Dec-2002 petrov

new function dump_itlb.


Revision tags: gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.159 22-Sep-2002 chs

many improvements:
- use struct vm_page_md for attaching pv entries to struct vm_page
- change pseg_set()'s return value to indicate whether the spare page
was used as an L2 or L3 PTP.
- use a pool for pv entries instead of malloc().
- put PTPs on a list attached to the pmap so we can free them
more efficiently (by just walking the list) in pmap_destroy().
- use the new pmap_remove_all() interface to avoid flushing the cache and TLB
for each pmap_remove() that's done as we are tearing down an address space.
- in pmap_enter(), handle replacing an existing mapping more efficiently
than just calling pmap_remove() on it. also, skip flushing the
TSB and TLB if there was no previous mapping, since there can't be
anything we need to flush. also, preload the TSB if we're pre-setting
the mod/ref bits.
- allocate hardware contexts like the MIPS pmap:
allocate them all sequentially without reuse, then once we run out
just invalidate all user TLB entries and flush the entire L1 dcache.
- fix pmap_extract() for the case where the va is not page-aligned and
nothing is mapped there.
- fix calculation of TSB size. it was comparing physmem (which is
in units of pages) to constants that only make sense if they are
in units of bytes.
- avoid sleeping in pmap_enter(), instead let the caller do it.
- use pmap_kenter_pa() instead of pmap_enter() where appropriate.
- remove code to handle impossible cases in various functions.
- tweak asm code to pipeline a little better.
- remove many unnecessary spls and membars.
- lots of code cleanup.
- no doubt other stuff that I've forgotten.

the result of all this is that a fork+exit microbenchmark is 34% faster
and a fork+exec+exit microbenchmark is 28% faster.


Revision tags: gehenna-devsw-base
# 1.158 18-Jul-2002 wiz

Spell 'should' correctly.


# 1.157 07-Jun-2002 eeh

Shave 10% off the time needed to flush the D$ through a bit of instruction
reordering.


# 1.156 05-Jun-2002 eeh

Handle improperly aligned stack pointers more cleanly.


# 1.155 04-Jun-2002 eeh

Fix the fork trampoline to properly use the supplied tstate.


# 1.154 31-May-2002 thorpej

Make this work with an ISO C preprocessor.


Revision tags: netbsd-1-6-base
# 1.153 14-May-2002 eeh

branches: 1.153.2; 1.153.4;
Only save locals and ins in trapframes for DEBUG kernels.


# 1.152 04-May-2002 kleink

Add some comments to the CPP conditionals controlling the trap macro
definitions, to ease navigation somewhat.


# 1.151 16-Apr-2002 eeh

Make lots of routines profile-friendly and get rid of some cruft.


Revision tags: eeh-devprop-base
# 1.150 21-Mar-2002 petrov

Not needed debug stuff deleted.


# 1.149 16-Mar-2002 mrg

tell newer binutils that our use of %g2 and %g3 is OK here.


# 1.148 15-Mar-2002 eeh

Cleanup MMU initialization to prevent hangs.


Revision tags: newlock-base ifpoll-base
# 1.147 09-Feb-2002 eeh

branches: 1.147.4;
Fix microsecond calculation in microtime.


# 1.146 07-Feb-2002 eeh

Fix register allocation in microtime().


# 1.145 29-Jan-2002 eeh

Shift the UPAID in the correct direction.


# 1.144 17-Jan-2002 eeh

Be more tolerant of unaligned stack pointers.


# 1.143 17-Jan-2002 eeh

Enable block insns in bcopy and bzero.


# 1.142 16-Jan-2002 eeh

In bcopy use 32-bit comparisons in 32-bit kernels.


# 1.141 16-Jan-2002 eeh

Use correct calculation for the trapframe in softtrap for ILP32.


# 1.140 20-Nov-2001 lukem

- pull in opt_kgdb.h where necessary
- replace opt_kgdb_machdep.h with opt_kgdb.h
- defparam opt_kgdb.h:
KGDB_DEV KGDB_DEVNAME KGDB_DEVADDR KGDB_DEVRATE KGDB_DEVMODE
- move from opt_ddbparam.h to opt_ddb.h:
DDB_FROMCONSOLE DDB_ONPANIC DDB_HISTORY_SIZE DDB_BREAK_CHAR SYMTAB_SPACE
- replace KGDBDEV with KGDB_DEV
- replace KGDBADDR with KGDB_DEVADDR
- replace KGDBMODE with KGDB_DEVMODE
- replace KGDBRATE with KGDB_DEVRATE
- use `9600' instead of `0x2580' for 9600 baud rate
- use correct quotes for options KGDB_DEVNAME="\"com\""
- use correct quotes for options KGDB_DEV="17*256+0"
- remove unnecessary dependancy on Makefile for kgdb_stub.o
- minor whitespace cleanup


Revision tags: thorpej-mips-cache-base thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf
# 1.139 14-Sep-2001 thorpej

branches: 1.139.4;
Don't declare intrhand[] here -- that's taken care of in intr.c.


Revision tags: thorpej-devvp-base
# 1.138 30-Aug-2001 eeh

branches: 1.138.2;
Preliminary UltraSPARC III suport (not enabled yet).


# 1.137 13-Aug-2001 jdolecek

g/c _remque()/_insque(); use the C version in libkern


# 1.136 09-Aug-2001 eeh

Fix context masking lossage caused by last version.


# 1.135 08-Aug-2001 eeh

Clean up the trap code to handle the changes cause by supporting non-faulting
accesses. Also change the parameter order so trap frames are easy to find.


# 1.134 07-Aug-2001 eeh

Make sure C code always has ASI_PRIMARY_NOFAULT in the %asi register so
the compiler will be happy if it ever starts generating speculative loads.


# 1.133 05-Aug-2001 eeh

Add support for non-faulting loads and optimize MMU miss handling paths.


# 1.132 02-Aug-2001 eeh

Fix bcopy.


# 1.131 02-Aug-2001 eeh

Sync bzero w/libc version.


# 1.130 01-Aug-2001 eeh

Integrate fixes from userland memset.


# 1.129 31-Jul-2001 eeh

Code cleanup and optimization.


# 1.128 23-Jul-2001 eeh

Get rid of some debug code that really isn't all that useful any more.


# 1.127 19-Jul-2001 eeh

Do ignore unregistered interrupts instead of faulting.


# 1.126 16-Jul-2001 eeh

Make bcopy a 32-bit friendly.


# 1.125 11-Jul-2001 eeh

Fix problems booting 32-bit kernels and dispatching level-15 interrupts.


# 1.124 08-Jul-2001 eeh

branches: 1.124.2;
Code cleanup. Add block_disable to let you turn on block set/copy routines.


# 1.123 05-Jul-2001 eeh

New block bzero and bcopy.


# 1.122 04-Jul-2001 eeh

Replace old bcopy with a much faster version.


# 1.121 01-Jul-2001 martin

Disable axidently enabled debug code to make -current compile again.


# 1.120 30-Jun-2001 eeh

Use a newer version (still disabled) of block bcopy.


# 1.119 30-Jun-2001 eeh

Fixup fpu save restore, get rid of some unused copy functions, and add
a new bcopy.


# 1.118 21-Jun-2001 eeh

Allow multiple 4MB pages for both kernel text and kernel data.

Note: DEBUG checks will not allow accesses to the hole between
text and data segments, so you may need to update programs that
use libkvm before relocating the start of kernel data.


# 1.117 06-Jun-2001 mrg

extract the netbsd32, sunos, 32 bit svr4 and 64 bit svr4 sigcode out into
separate files, so that compat lkms can link with them as well.


# 1.116 30-May-2001 lukem

add missing #include "opt_kgdb.h"


Revision tags: thorpej_scsipi_beforemerge
# 1.115 25-Apr-2001 simonb

Spell occurred correctly.


Revision tags: thorpej_scsipi_nbase thorpej_scsipi_base
# 1.114 09-Apr-2001 eeh

Interrupt latency fix from sparc port. (Hm. One insn instead of 5).


# 1.113 07-Mar-2001 eeh

Fix inverted preprocessor logic. (Spotted by Charles.)


# 1.112 21-Feb-2001 eeh

branches: 1.112.2;
Add support for 64-bit SVR4 (Solaris 8) binaries.


# 1.111 10-Feb-2001 pk

Fix conditional for svr4 compat inclusion.


# 1.110 05-Feb-2001 eeh

Add signal trampoline for 64-bit svr4 emulations.


# 1.109 31-Dec-2000 eeh

Make INCR() atomic.


# 1.108 29-Dec-2000 eeh

pseg_get tells us whether it really needed that spare page after all.


# 1.107 07-Dec-2000 eeh

Fixup calculating where fpstate should be saved in the signal trampoline
code so it doesn't overwrite something important like the registers.


# 1.106 09-Nov-2000 eeh

Fix ILP32 bug in probe_get().


# 1.105 22-Oct-2000 pk

Restore revision 1.102.

I hope it sticks this time..


# 1.104 20-Oct-2000 eeh

Fix hang in 32-bit kernels caused by relocation of KERNBASE.


# 1.103 04-Oct-2000 eeh

Fix interrupt lossage problem and some cosmetic changes.


# 1.102 01-Oct-2000 pk

cpu_initialize: global registers aren't preserved across calls to
prom_printf(), so replace %g3 with %l7 (which isn't used despite
the `usage' comment).

Also, clean up white-space turds.


# 1.101 29-Sep-2000 eeh

This seems to fix the interrupt lossage of non-debug kernels.


# 1.100 28-Sep-2000 eeh

Fix INTR_SETUP() to properly distinguish kernel and user addresses.

Make microtime() return the correct time on %tick machines.

Re-enable debug stuff in dostart for now to detect kernel mapping issues.


# 1.99 25-Sep-2000 pk

Missing `#if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)'


# 1.98 17-Sep-2000 eeh

Make the improved %tick changes work with machines that use the counter-timer
for the clock.


# 1.97 12-Sep-2000 eeh

Fix new version of microtime.


# 1.96 11-Sep-2000 eeh

(Hopefully) fix clock skew on machines that us %tick for the clock (UIIi).


# 1.95 31-Aug-2000 eeh

Use casx instead of stx to change entries in the page table trees.


# 1.94 23-Aug-2000 eeh

Update the scheduler to the new locking scheme.


# 1.93 10-Aug-2000 eeh

Fix signal delivery.


# 1.92 02-Aug-2000 eeh

Get kernel profiling to work. Now if only gprof worked....


# 1.91 01-Aug-2000 eeh

Overhaul cache flush code and coredump code.


# 1.90 25-Jul-2000 pk

Re-instate a couple of delay slot NOPs marked `XXX spitfire bug?'


# 1.89 24-Jul-2000 mycroft

Optimization to pmap_zero_page(): we only need to use the first 16 FP regs,
as in bzero().


# 1.88 24-Jul-2000 mycroft

Fix a whitespace glitch.


# 1.87 24-Jul-2000 mycroft

Pull in the bzero() changes from libc for real, with a couple of kernel-
specific hacks:
* Make the bias handling depend on STKB, so it switches correctly for 32-bit
kernels.
* Use the 32-bit stw/ld for 32-bit kernels.
* Add a few `-STKB's that were missed in the previous change.


# 1.86 24-Jul-2000 pk

Cosmetic & readability:
- local label cleanup in interrupt handling code;
- in debugging sections when testing `intrdebug': use a unique
local label (97) to enhanced clarity;
- comment-out unused code;
- kill a bug as the satisfying result of doing all of the above.


# 1.85 24-Jul-2000 eeh

Fix stack issues in bzero.


# 1.84 24-Jul-2000 mycroft

Revert the previous change for now. I don't have time to debug it tonight.


# 1.83 23-Jul-2000 mycroft

Copy bzero change from libc.


# 1.82 20-Jul-2000 pk

Since `intrcnt' points to an array of long ints, reserve the appropriate
amount of space depending on _LP64. Provide macros to load/store signed
and unsigned long ints.

Also, make the `intrcnt' and `intrpending' arrays 16 entries long, as on
sparc/v9 interrupt #15 is just a regular interrupt.


# 1.81 19-Jul-2000 eeh

Fix merge problem.


# 1.80 19-Jul-2000 eeh

Disable interrupt interlock using ih->ih_pending field. Seems to cause
more problems than it solves.


# 1.79 19-Jul-2000 eeh

Miscellaneous cleanup.


# 1.78 18-Jul-2000 pk

Correct args usage comment in probeget.
Whitespace cleanup.


# 1.77 18-Jul-2000 pk

probeget: 9 -> 0x9


# 1.76 18-Jul-2000 pk

If `ih_pending' is set simply return from the trap, don't schedule another
soft interrupt.


Revision tags: mrg-merge-1-5-top
# 1.75 18-Jul-2000 pk

openfirmware: don't lower %pil


# 1.74 17-Jul-2000 pk

Kill typos in interrupt code.


# 1.73 17-Jul-2000 pk

probeget: do the same song and dance as ld*a() macros in ctlreg.h do.


# 1.72 14-Jul-2000 eeh

Move some macro definitions out of genassym and into locore.s


# 1.71 08-Jul-2000 mrg

backout part of previous: turn off intrdebug, and another debug message


# 1.70 07-Jul-2000 pk

Changes for readability:
- #define LP64 dependent STACKFRAME macro once
- use a LOAD_ASCIZ macro for setting up the format string
for debug messages.


# 1.69 07-Jul-2000 eeh

Temporary fix to prevent the clock from stopping on UIIi machines.


# 1.68 03-Jul-2000 eeh

Prevent interrupts from being posted if they are active and deprecate polled
interrupts. This seems to eliminate the spurious interrupts.


# 1.67 02-Jul-2000 eeh

Clean up interrupt handling some more.


# 1.66 30-Jun-2000 eeh

Fix interrupt delivery on UltraSPARC IIi machines.


# 1.65 24-Jun-2000 eeh

With these changes the kernel seems almost stable again.


# 1.64 24-Jun-2000 eeh

More VM cleanup:

Move the cpu_info structure above the interrupt stack so it won't
get corrupted if the stack overflows.

Flush the D$ before and after all MMU bypass accesses since the
D$ latches all of those.


# 1.63 23-Jun-2000 eeh

Make probeget() and probeset() really work for a change.


Revision tags: netbsd-1-5-base
# 1.62 19-Jun-2000 eeh

branches: 1.62.2;
Have separate data and text segments, make text read-only.


# 1.61 12-Jun-2000 eeh

Start reorganizing the kernel for MULTIPROCESSOR support.


# 1.60 31-May-2000 thorpej

Add a comment about needing to initialize p_cpu when multiple
processors are supported.


Revision tags: minoura-xpg4dl-base
# 1.59 26-May-2000 thorpej

branches: 1.59.2;
First sweep at scheduler state cleanup. Collect MI scheduler
state into global and per-CPU scheduler state:

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

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

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

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

Tested on i386 and Alpha. Changes are mostly mechanical, but apologies
in advance if it doesn't compile on a particular platform.


# 1.58 26-May-2000 thorpej

Don't set `runtime' here; it's done at the end of mi_switch().
cvS: ----------------------------------------------------------------------


# 1.57 26-May-2000 thorpej

Introduce a new process state distinct from SRUN called SONPROC
which indicates that the process is actually running on a
processor. Test against SONPROC as appropriate rather than
combinations of SRUN and curproc. Update all context switch code
to properly set SONPROC when the process becomes the current
process on the CPU.


# 1.56 22-Apr-2000 eeh

If we trap due to a bad kernel stack, try to switch to the interrupt strack
before breaking into the debugger.


# 1.55 18-Apr-2000 eeh

Prevent the system from getting watchdog reset by returning directly to user
mode if restoring the user window traps. Also reduce the time we run with
%tl>0.


# 1.54 13-Apr-2000 eeh

Apparently gas 2.9.5 (don't ask) does not like to add values to %lo()
directives so move the additions inside %lo() to make it happy.
Hopefully this won't break older versions.


# 1.53 10-Apr-2000 mrg

- fix a speeling error
- rename some numbered labels to be a bit less confusing.
- remove dead code
- fix a debug error message (argh!)


# 1.52 10-Apr-2000 pk

Get a kernel without DDB to build.


# 1.51 16-Mar-2000 eeh

Revamp interrupts again:

Fix a bug causing interrmittent panics in interrupt dispatch.
Use interrupt vectors for softints.
Add a new send_softint interface.
Improved D$ flushing.
Improve traptrace and other debugging enhancements.


Revision tags: chs-ubc2-newbase
# 1.50 16-Jan-2000 eeh

Interrupt handlers return zero if they didn't handle the interrupt.


# 1.49 10-Jan-2000 eeh

Add debugger single-stepping and fix interrupt dispatch bugs.


# 1.48 30-Dec-1999 eeh

Lots of changes:

remove ffs()
add bzero that uses block store insns
save %gsr to fpstate
revert to physical accesses for pmap_zero_page so we don't
have conflicting page mappings
general cleanup.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base fvdl-softdep-base
# 1.47 06-Nov-1999 eeh

Handle zero length properly in copyinstr() copyoutstr() and copystr().


Revision tags: comdex-fall-1999-base
# 1.46 11-Oct-1999 eeh

branches: 1.46.2; 1.46.4;
Update to post 1.4.


# 1.45 05-Oct-1999 eeh

branches: 1.45.2;
Make broken versions of gas happy by using sethi/or instead of set for
(negative) addresses.


# 1.44 17-Sep-1999 thorpej

Centralize the declaration and clearing of `cold'.


Revision tags: chs-ubc2-base
# 1.43 18-Jul-1999 eeh

More fun with pmap.


# 1.42 21-Jun-1999 eeh

Improve TRAPTRACE. Add FLTRACE that only tracks MMU faults.


# 1.41 05-Jun-1999 eeh

Make pbrobeget() and probeset() work for 64-bit values as well. To do this
the arguments are changed so the address is first and the ASI second so we
can have the address in %o0:%o1 and not worry about unused registers.

Also a bit of copyright cleanup.


# 1.40 05-Jun-1999 mrg

update a commit slightly.


# 1.39 30-May-1999 eeh

Add code to support using %tick as the system clock if no "counter-timer" node
is found.


# 1.38 09-May-1999 eeh

Fixup non-DEBUG kernels.


# 1.37 29-Apr-1999 christos

Add sunos_sigcode (32 bit only)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.36 26-Mar-1999 eeh

branches: 1.36.4;
COMPAT_SPARC32 -> COMPAT_NETBSD32


# 1.35 25-Mar-1999 mrg

clean and up make compile


# 1.34 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.33 22-Mar-1999 eeh

Need to set up the pointers properly for partial FPU register stores.


# 1.32 22-Mar-1999 eeh

Flush D$ on bypass accesses.


# 1.31 28-Feb-1999 eeh

Use block load/store in pmap_zero_page()/pmap_copy_page().


# 1.30 17-Feb-1999 eeh

Let's test out vectored interrupts.


# 1.29 15-Feb-1999 hubertf

RCS ID police


# 1.28 11-Feb-1999 mrg

fix a comment pasto.


# 1.27 11-Jan-1999 eeh

Finally fixed 64-bit signal trampoline.


# 1.26 10-Jan-1999 eeh

Handle the symbol table properly in a 32-bit kernel that was booted from a
64-bit bootloader.


# 1.25 09-Jan-1999 eeh

More signal fixup.


Revision tags: kenh-if-detach-base
# 1.24 26-Nov-1998 mycroft

Sync kcopy() with 32-bit SPARC version.


# 1.23 16-Nov-1998 eeh

Fixup the last broken bits of the signal handling code.


Revision tags: chs-ubc-base
# 1.22 08-Oct-1998 eeh

Fix more syscall32 and signal breakage.


# 1.21 22-Sep-1998 eeh

More fixup in the signal area.

64-bit syscall cleanup.

Add emulation for some new FPU insns: conversion to 64-bit long int and
conditional moves.


# 1.20 17-Sep-1998 thorpej

SYS_sigreturn -> SYS___sigreturn14.


# 1.19 13-Sep-1998 eeh

Fixup signal changes (hopefully). However SUN_COMPAT is likely broken by
this and I don't know how to fix it.

We can now exec a 64-bit init through a really ugly hack (don't ask.)


# 1.18 11-Sep-1998 eeh

Add labels for the compat_sparc32 signal trampoline and break -- er -- fix
suword and fuword.


# 1.17 09-Sep-1998 eeh

Don't use %tick for microtime on 32-bit kernels -- breaks gettimeofday.


# 1.16 09-Sep-1998 thorpej

Adjust for the new "reaper" kernel thread: do not free the vmspace and
u-area in machine-dependent code. Instead, call exit2() to schedule
the reaper to free them for us, once it is safe to do so (i.e. we are
no longer running on the dead proc's vmspace and stack).


# 1.15 07-Sep-1998 eeh

Fix data corruption problem caused by broken debug code.


# 1.14 07-Sep-1998 eeh

Add new 64-bit trap vectors.


# 1.13 06-Sep-1998 eeh

32-bit fixup.


# 1.12 06-Sep-1998 eeh

Disable some debug stuff.


# 1.11 05-Sep-1998 eeh

It slices. It dices. It does everything except exec a sparc32_compat init.


# 1.10 02-Sep-1998 eeh

Periodic update: now starts probing devices.


# 1.9 30-Aug-1998 eeh

Some more 64-bit cleanup. Now everything compiles.


# 1.8 29-Aug-1998 eeh

Some more 64-bit-ification.


# 1.7 27-Aug-1998 eeh

Add 64-bit pmap support:

Moved from a two level 512/1024 entry setup mapping 32 (9/10/13) bits
respectively to a three level 1024/1024/1024 entry setup mapping 43
(10/10/10/13) bits. In 32-bit mode we waste about 1/12 pages mapping the high
11 bits. We also only manage 43 of the possible 44 bits of virtual address
space, wasting half of it. Oh well, maybe we'll do better next revision.


Revision tags: PMAP32
# 1.6 26-Aug-1998 mrg

panicstack: is needed outside of DEBUG. use _C_LABEL, and printf not db_printf (incase no ddb!)


# 1.5 13-Aug-1998 eeh

Merge paddr_t changes into the main branch.


Revision tags: eeh-paddr_t-base
# 1.4 07-Jul-1998 eeh

branches: 1.4.2;
General update:

Added genassym.cf
Removed lderr which should never have gotten in
Removed lots of dead code from locore.s
Added some softint stuff to intr.c
Added support for halt -p
esp and le both use bus_dmamap_*() functions now
instead of kdvma_mapin()
groundwork for PCI (but we still have no drivers for
any sun4u PCI devices)


# 1.3 04-Jul-1998 jonathan

defopt DDB.


# 1.2 26-Jun-1998 thorpej

defopt COMPAT_SVR4


# 1.1 20-Jun-1998 eeh

branches: 1.1.1;
Initial revision


# 1.425 22-Feb-2021 palle

sun4v: handle spill normal user traps properly when current trap level is 1 - registers are spilled to the PA of the stack to avoid further mmu-related traps, since sun4v only has 2 trap levels


Revision tags: thorpej-futex-base
# 1.424 20-Dec-2020 palle

sun4v: add comment in sun4v_tl1_ptbl_miss code path - no functional change


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1
# 1.423 08-Jan-2020 skrll

branches: 1.423.6;
oldlwp is always non-NULL in cpu_switchto so remove the test for NULL.


# 1.422 08-Jan-2020 ad

Hopefully fix some problems seen with MP support on non-x86, in particular
where curcpu() is defined as curlwp->l_cpu:

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

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

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

- Remove some KERNEL_LOCK handling which hasn't been needed for years.


Revision tags: netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 ad-namecache-base netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.421 18-Jul-2019 palle

branches: 1.421.4;
sun4v: added some missing comments to the code in pcbspill


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 1.420 07-Apr-2019 mrg

make trap 0x70 a TRAP() not UTRAP(). we should be able to handle
fast ECC error as a normal trap, and i saw this once a few years
ago but it never repeated so i haven't been able to test this.


# 1.419 08-Feb-2019 palle

sun4v: Improve comment for next_stick_init() - no functional changes


# 1.418 08-Feb-2019 palle

sun4v: initialize %stickcmpr properly when establishing interrupt - fixes issue seen on newer sun4v/SPARC-T5 system where the interrupt never fires.


# 1.417 08-Feb-2019 palle

sun4v: introduce macros for handling spill traps from userlevevel @ traplevel 1 (from OpenBSD) - spill traps at level 1 from userspace now works better


# 1.416 08-Feb-2019 palle

sun4v: add comment documenting the contents of the %g2 register - no functional changes


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126
# 1.415 04-Nov-2018 palle

Ensure that the 64-bit condition codes are used instead of the 32-bit condition codes. ok martin@


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.414 26-May-2018 palle

branches: 1.414.2;
next_stick() - fix typy in comment: tick->stick


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.413 11-Apr-2018 palle

sun4v: handle MMU-related traps properly when they occur at trap level 1. This fixes issues when user-level LWPs access the user-level stack


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 1.412 26-Aug-2017 palle

branches: 1.412.2;
sun4v: Avoid touching the %tick_cmpr register which is not present on never systems (Oracle SPARC Architecture 2011 and beyond). Based on code from OpenBSD locore.s revision 1.177. Tested on both sun4u (qemu and USIII) and sun4v (qemu and T5-2). ok martin@


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2
# 1.411 06-May-2017 palle

sun4v: The %ver register is not available on sun4v - use GET_MAXCWP introduced in rev. 1.361. Verified using qemu (sun4u and sun4v) and on real sun4v hw (t2000)


Revision tags: prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.410 18-Apr-2017 palle

branches: 1.410.2;
sun4v: Add handling of trap 0x06c @ trap level 1 - based on code from OpenBSD, but slightly adapted to NetBSD. verified using qemu


Revision tags: jdolecek-ncq-base pgoyette-localcount-20170320
# 1.409 19-Feb-2017 palle

sun4v: rft_user needs special handling (a manual fill) since the restore instruction may cause the number of trap levels to exceed the maximum for sun4v - inspired by code from the the openbsd rft_user code path - verified using qemu for both sun4u and sun4v


# 1.408 10-Feb-2017 palle

sun4v: Added handling of trap type 0x034 (address alignment error) + fixed typo mmfsa -> mmufsa. Verified for both sun4u and sun4v using qemu.


Revision tags: nick-nhusb-base-20170204
# 1.407 30-Jan-2017 palle

sun4v: Hook up syscall handling to the trap table. Verified using qemu for both sun4u and sun4v.


# 1.406 27-Jan-2017 palle

sun4v: implement missing handling of itsb traps 0x008 and 0x009. Based on code from OpenBSD. Tested using qemu.


Revision tags: bouyer-socketcan-base
# 1.405 07-Jan-2017 palle

branches: 1.405.2;
sun4v: slowtrap() now selects normal globals properly on both sun4u and sun4v platforms. Verified using qemu for both sun4u and sun4v systems


Revision tags: pgoyette-localcount-20170107
# 1.404 05-Jan-2017 palle

sun4v: TRAP_SETUP() updated to set mmu context id properly for both sun4v and sun4u platforms. Verified using qemu for both sun4u and sun4v systems


# 1.403 04-Jan-2017 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x00-0x23 and 0x28-0x30


# 1.402 29-Dec-2016 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x32-0x7f


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.401 20-Sep-2016 nakayama

Fix RAS for 32-bit kernels. trapframe is always 64-bit.


Revision tags: localcount-20160914
# 1.400 23-Aug-2016 palle

sun4v: rework sun4v_datatrap so it works properly when running on a T2-based system like T5120 - for some reason %tl is 0 when entering sun4v_datatrap causing a crash (sir instruction), so ignore the %tl value for now upon entry to sun4v_datatrap - with this fix both T1 and T2 based systems reach the same point - hangs in rft_user after the init process is started


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726
# 1.399 18-Jul-2016 palle

sun4v: handle device interrupts properly - both legacy (sysino) and cookies


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 1.398 04-Jun-2016 palle

branches: 1.398.2;
sun4v: rtf_user now uses macros GET_MMU_CONTEXTID and SET_MMU_CONTEXTID. Tested on sun4u (QEMU) and sun4v (T2000). Parts from OpenBSD.


Revision tags: nick-nhusb-base-20160529
# 1.397 18-May-2016 nakayama

Decrement %tl in trap handler not to make it zero unconditionally
for the nested trap, and remove useless mov.


# 1.396 17-May-2016 palle

sun4v: Implement missng MMU protection trap handling - mostly from OpenBSD


# 1.395 16-May-2016 palle

Avoid assembler-specific defines by using the export keyword in genassym.cf instead


# 1.394 15-May-2016 nakayama

%g1 is not preserved across function call, so load it before
return_from_trap.


# 1.393 13-May-2016 palle

sun4v: add missing implementation of sun4v_datatrap_tl0 so data_access_fault() is called - mostly from OpenBSD


# 1.392 13-May-2016 nakayama

- ci_paddr is always 64-bit.
- intrlev is array of pointer.
- ih_ack is pointer.


# 1.391 10-May-2016 palle

sun4v: make device interrupts work. Introduce a new intrhand_alloc() function for allocation of interrupt handlers and adapt to this. Parts from OpenBSD. ok martin@


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.390 09-Mar-2016 nakayama

32-bit kernels use 32-bit stack.


# 1.389 03-Mar-2016 palle

sun4v: rft_kernel should pay attention to the number of register windows that can be restored. We cannot rely on fill traps to occur, since sun4v only has two trap levels available in privileged mode. Based on code from OpenBSD. ok martin@


# 1.388 14-Feb-2016 palle

sun4v: add breakpoint trap entry to the sun4v trap table


# 1.387 03-Feb-2016 palle

sun4v: extend dmmu_set_secondary_context() to handle both sun4u and sun4v. ok martin@


Revision tags: nick-nhusb-base-20151226
# 1.386 06-Nov-2015 martin

Basically revert r1.246 of locore.s and r1.73 of vm_machdep.c:

Remove special case handling for userland lwps from cpu_lwp_fork,
instead do it in lwp_trampoline when we first return to userland.

which was a stupid idea - since we did now set all fork child's %tstate
(and thus %pstate when back in userland) to the current kernel's userland
default. This meant we lost the address mask bit for 32bit processes and
all memory model details for 64bit ones.

Move it back to cpu_lwp_fork and fix the condition to only do it once when
forking init.


# 1.385 05-Nov-2015 martin

Most of the time return_from_trap already got called with tf->tf_tstate
loaded in register %g1 - make it so for two more callers and remove
the reload of that value.


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606 nick-nhusb-base-20150406
# 1.384 05-Apr-2015 palle

sun4v: Ensure that the TTEs CP and CV bits are the same (both set) for the primary cpu and secondary cpus INTSTACK mappings


# 1.383 01-Apr-2015 palle

sun4v: Implement handling of cpu_mondo trap - from OpenBSD - tested using the Legion simulator


# 1.382 04-Mar-2015 palle

sun4v: revert some of the logic introduced in revision 1.378 - flushw is not necessary on sun4v (OpenBSD patches the flushw instruction to a nop instruction) - with these changes the kernel reaches cpu_boot_secondary_processors() when running in the Legion simulator (crashes due to missing handling of cpu_mondo_trap)


# 1.381 02-Mar-2015 nakayama

prom_printf converts "\n" to "\r\n" internally, so omit "\r".


# 1.380 02-Mar-2015 nakayama

PANICSTACK is a pointer itself, not a pointer to pointer.


# 1.379 02-Mar-2015 nakayama

Use panic stack temporarily for calling prom_printf in a trap
handler.

It seems that openfirmware cannot handle over 4GB pointers, and
stack pointers may point to over 4GB since VA layout was rearranged
by rev 1.33 of vmparam.h. Therefore, use panic stack to avoid
panicking in OF_write used by prom_printf.


# 1.378 23-Feb-2015 palle

sun4v: sparc_interupt - ensure that the trap level and globals level are the same when the flushw instruction is issued - othwise warnings occur when using the sun4v Legion simulator.


Revision tags: nick-nhusb-base
# 1.377 26-Oct-2014 palle

branches: 1.377.2;
sun4v: Create CLEANWIN0 and CLEANWIN1 macros for handling clean window traps on both sun4u and sun4u (based on the original code inlined in the sun4u trap table). Update trap tables accordingly for both sun4u and sun4v. Ok martin@


# 1.376 24-Oct-2014 nakayama

Fix typo in comment.


# 1.375 18-Oct-2014 snj

src is too big these days to tolerate superfluous apostrophes. It's
"its", people!


# 1.374 15-Oct-2014 palle

sun4v: fixed bug causing the real address to be incorrectly calculated as zero


# 1.373 24-Sep-2014 palle

sun4v: add code to enable startup of secondary cpus on both sun4u and sun4v systems - ok martin@


# 1.372 04-Sep-2014 palle

sun4v: All cpus must be setup with a TSB descriptor, so pmap_setup_tsb_sun4v() must take a pointer to the TSB descriptor


# 1.371 31-Aug-2014 palle

sun4v: Split the NORMAL_GLOBALS and ALTERNATE_GLOBALS macros to _SUN4U and _SUN4V variants. Rework the return_from_trap logic to use the new variants so it is possible to use a global register as scratch register.


# 1.370 14-Aug-2014 nakayama

Add missing delay slot in DEBUG kernel.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.369 30-Jul-2014 palle

branches: 1.369.2;
Fix ALTERNATE_GLOBALS so it at least works on sun4u - using a scratch register is not a good idea...


# 1.368 27-Jul-2014 palle

sun4v: Introduce a new macro ALTERNATE_GLOBALS (matching NORMAL_GLOBALS). Two new helper macros ENABLE_INTERRUPTS and DISABLE_INTERRUPTS are also created. With these changes the GENERIC.UP kernel will reach rootmount on sun4v systems - ok martin@


# 1.367 26-Jul-2014 palle

Improved the NORMAL_GLOBALS macro in the sun4u case, so only the relevant bit (AG) in %pstate is affected - ok martin@


# 1.366 24-Jul-2014 palle

sun4v: add missing spill/fill handling for trap level 1 + cosmetic changes to comments for trap level 0 entries


# 1.365 19-Jul-2014 palle

sun4v: Introduce a NORMAL_GLOBALS macro - first used in sparc_interrupt - other relevant uses will be handled as the sun4v work is progressesing - ok martin@


# 1.364 16-Jul-2014 palle

sun4v: Introduce SET_MMU_CONTEXTID macro for setting the mmu context id on both sun4u and sun4v


# 1.363 13-Jul-2014 palle

sun4v: add interrupt handling to sun4v trap table


# 1.362 13-Jul-2014 palle

Bugfix: add missing cmp instruction to GET_MAXCWP macro


# 1.361 30-Jun-2014 palle

sun4v: The maximum number of register windows is a constant and thus not available via the %ver register (sun4u only). Introduce a macro GET_MAXCWP that handles this, so cpu_switchto() works properly on sun4v. Other relevant reference to %ver can be adapted to use GET_MAXCWP as the sun4v port progresses. OK martin@


# 1.360 31-May-2014 palle

sun4v: added missing dtsb miss handling for trap level 1 - with this update the kernel now reaches configure() on sun4v systems


# 1.359 30-May-2014 palle

Remove debugging code introduced by accident in locore.s revision 1.357


Revision tags: yamt-pagecache-base9 rmind-smpnet-nbase rmind-smpnet-base
# 1.358 05-May-2014 palle

sun4v: the trap base address should be assigned to %l1 so %tba is properly setup later in the code - now the kernel gets as far as printing the copyright disclaimer, kernel version and total and available memory before crashing


# 1.357 21-Apr-2014 palle

sun4v: Update comment: modified -> access


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.356 21-Feb-2014 palle

branches: 1.356.2;
sun4v: Rename TLB_ defines to SUN4U_TLB_ so entries created using TSB_DATA() are properly setup for sun4u and sun4v. Relocate the cputyp variable from autoconf.c to locore.s and make it const in param.h so optimized code can be generated. Parts from OpenBSD. Optimization suggested by nakayama@. OK martin@, mrg@, nakayama@


# 1.355 31-Jan-2014 tsutsui

defined(LKM) -> defined(MODULAR)


# 1.354 26-Jan-2014 palle

sun4v: Add handling of spill/fill and dtsb miss traps (with a XXX to be handled later)


# 1.353 07-Jan-2014 palle

sun4v: trap table setup - currently populated with dummy entries which will be properly implemented later - parts from OpenBSD - OK martin@


# 1.352 29-Dec-2013 nakayama

Make buildable w/o options SUN4V.


# 1.351 27-Dec-2013 palle

a) make the hunt through the cpus list more generic b) sun4v: ensure that the interrupt stack is mapped permanently and the TSB is setup properly - parts from OpenBSD. OK martin@


# 1.350 06-Dec-2013 nakayama

Increase an interrupt depth only in the case of hardware interrupts,
and remove the ci_idepth trick in softint_fastintr.

Fixes the following diagnostic panic reported in port-sparc64.

panic: kernel diagnostic assertion "!cpu_intr_p()" failed: file
"../../../../kern/subr_xcall.c", line 351


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 1.349 24-May-2013 nakayama

branches: 1.349.2;
Disable interrupts after calling data_access_error as with
data_access_fault.


# 1.348 28-Apr-2013 nakayama

Use macros in machine/asm.h instead of locally defined, and
introduce CASPTRA for casxa/casa.


Revision tags: agc-symver-base
# 1.347 23-Jan-2013 martin

Fix sparc64_ipi_ccall by adding proper trap setup.
Fixes xcall(9) problems, as exposed by pserialize(9). Noticed by
J. Hannken-Illjes, cause pointed out by Takeshi Nakayama.


# 1.346 23-Jan-2013 martin

Sligthly clean up the (by default unused) #ifdef TRAPS_USE_IG


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.345 10-Nov-2012 nakayama

Revise comment.


# 1.344 10-Nov-2012 nakayama

Use macro instead of magic number.


# 1.343 09-Nov-2012 nakayama

Make setstick() and getstick() to inline functions.


# 1.342 08-Nov-2012 macallan

use system tick timer instead of %tick on UltraSPARC-III-ish CPUs
review & fixes by Takeshi Nakayama


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.341 17-Mar-2012 mrg

branches: 1.341.2;
port the corrected ECC error handling code from freebsd. i noticed my U10
took one of these and then hang. it shouldn't hang, there's a 'sir' here that
doesn't seem to reset properly. oh well.

tested by simulated a trap via 'ta 0x10' and considering that the same, but
it hasn't been tested against a real ECC error yet.


Revision tags: jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base4
# 1.340 03-Mar-2012 nakayama

Fix the root cause of the hack "disable optimizations for uvm_bio.c
on 32 bit kernels".

gcc converts a division in the calculation of UBC_UMAP_ADDR macro
to multiplication (smul or combination of add/sll), and the
register of its result contains a garbage in upper 32 bits (the
upper 32 bits of smul/add/sll's result isn't zero cleared).

Then it passes to pseg_get{,_real} through pmap_extract without the
zero clear of upper 32 bits in the optimization case. So the
result of pseg_get and pmap_extact sometimes gets screwed up.


Revision tags: jmcneill-usbmp-base5 jmcneill-usbmp-base3
# 1.339 19-Feb-2012 rmind

Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.


Revision tags: jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.338 04-Sep-2011 nakayama

branches: 1.338.2; 1.338.6; 1.338.8;
ih_pil is an interrupt level, not an interrupt mask.


# 1.337 27-Jul-2011 nakayama

ivec is assigned to hardware, so count its event counter up in
interrupt_vector, not in softint, and do some optimization.


# 1.336 20-Jul-2011 macallan

add per ivec event counters


# 1.335 12-Jul-2011 mrg

rename sparc64 BLOCK_SIZE and BLOCK_ALIGN to have SPARC64_ prefixes.
for the assembler files, define the old names to the new names
since using the new names cause ugliness due to longer identifer
names, and reduces churn.

fixes build issues in dtv and vaguely makes <machine/psl.h> slightly
less name-space invasive.


# 1.334 18-Jun-2011 nakayama

Add fast softint(9) support for sparc64.

Reviewed on port-sparc64.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 1.333 12-May-2011 mrg

branches: 1.333.2;
first steps towards fujitsu SPARC64 support:

- SPARC64 systems have interrupts with upto 14 bits set, but we only look
at the first 11 bits. trim non IPI interrupts to 11 bits


Revision tags: uebayasi-xip-base7 bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 jym-xensuspend-nbase jym-xensuspend-base
# 1.332 20-Dec-2010 matt

branches: 1.332.2;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.


Revision tags: uebayasi-xip-base6 uebayasi-xip-base5 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 1.331 10-Jul-2010 nakayama

Clear the upper word explicitly before combining two 32-bit values to 64-bit
on 32-bit kernels.


# 1.330 23-May-2010 martin

Split copy related functions out of locore.s into copy.S, move functions
only needed on multiprocessors into mp_subr.S.


# 1.329 17-May-2010 martin

Simplify primary CPU startup slightly by using the fact that our cpuinfo's
curpcb pointer points to the uarea/pcb of lwp0 and by remembering the pointer
to this cpuinfo, thus avoiding a few CPUINFO_VA references.


Revision tags: uebayasi-xip-base1
# 1.328 20-Mar-2010 chs

fix copy{in,out}{,str}() to return the error returned by uvm_fault().
fixes PR 41813.


Revision tags: yamt-nfs-mp-base9
# 1.327 10-Mar-2010 mrg

branches: 1.327.2;
XXX: workaround we'd like to remove when pmap / uvm locking is cleaned up:

- rename pseg_get() and pseg_set() to pseg_get_real() and pseg_set_real().
- if USE_LOCKSAFE_PSEG_GETSET is defined, which it current is by default,
define pseg_[gs]et() in terms of functions that take a new pseg_lock
mutex at IPL_VM while calling into the real functions.

this seems to avoid the pseg_set() crashes we've seen:
1 - spare needed, when pseg_get() just worked for this pmap
2 - the 2rd ldxa via ASI_PHYS_CACHED in pseg_set() loads garbage
into %o4, and causes the 3rd ldxa to fault


# 1.326 08-Mar-2010 mrg

blast_dcache() SMP friendly:

- blast_dcache() becomes sp_blast_dcache(dcache_size, dcache_line_size)
- new smp_blast_dcache(sparc64_cpuset_t) that blasts the D$ on this cpuset
- sparc64_ipi_blast_dcache() to support the above
- in pmap_remove_all(), when freeing mmu contexts for this pmap, mark
the set of cpus to blast the d$ on as well and convert the
blast_dcache() call into smp_blast_dcache() on the cpus who ran this
pmap, or, sp_blast_dcache(dcache_size, dcache_line_size)
- convert the remaining blast_dcache() in machdep.c to sp_blast_dcache()
- in pmap_destroy()/pmap_remove_all() take the pmap_lock() always since
we assert it is held always.

with these changes, NFS builds on the U60 seem to be stable now, and
the USIII machines also can often complete a single build.sh run now,
diskful or diskless.


reviewed by mlelstv and partially by martin, tested by martin and myself,
with some ideas from chuq as well.


# 1.325 07-Mar-2010 mrg

need _ALIGN in locore.h as well, for DEBUG kernels.


# 1.324 07-Mar-2010 mrg

gas has supported SPARC ".empty" for a long while; get rid of an
ancient workaround.


# 1.323 06-Mar-2010 mrg

move the memcpy/memset implementations out into their own file, with the
block copy versions as well. move some of the definitions in locore.s
into a new locore.h.

locore.s is almost 2000 lines shorter with this change.


# 1.322 04-Mar-2010 mrg

- in _bus_dmamap_unload(), pmap_page_protect() and pmap_clear_reference()
switch the dcache_flush_page() into a dcache_flush_page_all()
- in both pmap_kremove()/pmap_remove(), remove the blast_dcache() call
and replace it with dcache_flush_page_all()
- in pmap_get_page() [used to allocate PTP's], always call pmap_zero_page(pa)
- flush the dcache of the dst page in pmap_{copy,zero}_page() by redirecting
throught a C function that calls the (renamed) asm. the old asm code had a
comment about needing to do this...
- add a couple of membar #Sync's that the USIII manual recommends


based on discussions with chuq@, skrll@ and martin@.


these help my SB2000 / SB2500 with both disk / nfs builds and other tasks,
sometimes lasting for several hours before failing or asserting.


# 1.321 24-Feb-2010 mrg

when handing back page table pages to UVM, flush them from the dcache
on all CPUs.

idea from skrll@, and makes my disk-based SB2000 stable.

tested on U60, SB2000 and SB2500.


# 1.320 24-Feb-2010 mrg

- re-introduce sp_tlb_flush_pte() and sp_tlb_flush_all() that call
the right USI/USIII version.
- define tlb_flush_pte() in terms of sp_tlb_flush_pte() for the
!MULTIPROCESSOR case

this centralises some CPU_IS_USIII_UP() tests.


# 1.319 22-Feb-2010 mrg

move {dump,print}_[id]tlb() into a separate file.


# 1.318 22-Feb-2010 mrg

- store the maximum [id]cache size / line size for each cpu

- remove patch_kernel() since it isn't necessary and has been patching
the wrong thing in general.

- implement USIII versions of blast_icache(), dcache_flush_page() and
cache_flush_phys(). use the newly recorded cache size/line sizes.

- in winfixsave, flush the D$ with the right size index and ops. this
kills one of the wrong tag->inval patches.

- for blast_dcache(), use the newly recorded dcache_size/line_size.

- for blast_icache(), use the newly recorded cache size/line sizes.
for the USIII verison, disable the I$ while writing to ASI_ICACHE_TAG.


these changes removed several hard coded cache sizes values, some very
wrong kernel patching, and seem to make the current failure modes for
USIII less common, but not gone.


# 1.317 15-Feb-2010 mrg

- don't flush 32-bit entries for 64-bit code, it does not seem to be
necessary. #define TLB_FLUSH_LOWVA to turn it back on.
- remove the #if 0'd code in sparc64_ipi_flush_pte_usiii(), i have
verified that it is not required.
- add a missing membar #Sync to sp_tlb_flush_pte_usiii().


# 1.316 15-Feb-2010 nakayama

Fix linker error of GENERIC32 kernel.


# 1.315 15-Feb-2010 mrg

use TLB_SIZE_SPITFIRE in a couple of places, and note that the
{print,dump}_[id]tlb() versions are currently spitfire specific.


# 1.314 15-Feb-2010 mrg

introduce a new patch_kernel() and call it from the end of bootstrap().
use it to patch up TLB flush instructions that don't match for USI/II
and later. we can also hopefully use this to make GENERIC.MP minimally
expensive on single CPU machines as well.

this is the last piece needed to get GENERIC/GENERIC.MP to boot on the
USIII* machines.

idea and some initial code from openbsd.


# 1.313 13-Feb-2010 mrg

remove KTR support. it's never been a working part of netbsd src tree.


# 1.312 09-Feb-2010 wiz

Fix typo in comment.


Revision tags: uebayasi-xip-base
# 1.311 06-Feb-2010 mrg

branches: 1.311.2;
- properly map the schizo interrupt registers, so we can use the normal
virtual mappings to access them.
- with the above fxied, kill SCHIZO_BUS_SPACE_BROKEN, and introduce
an options CHEETAH for now, that disables the SPITFIRE code in locore.
- merge schizo_init() into schizo_attach() and clean up the softc a bit.


with this we are only one more step away from GENERIC booting on USIII
machines.


# 1.310 02-Feb-2010 mrg

- split sp_tlb_flush_pte() and switchtoctx() into sp_tlb_flush_pte_us()/
sp_tlb_flush_pte_usiii() and switchtoctx_us()/switchtoctx_usiii() and
implement the latter while i'm here. it works ... sometimes i think,
but also sometimes panics/hangs.
- fix a comment in sparc64_ipi_flush_pte_usiii()


# 1.309 02-Feb-2010 mrg

for now, reduce a few #ifdef SPITFIRE cases by introducing a new
ASI_DCACHE_TAG_OR_INV that is either ASI_DCACHE_{TAG,_INVALIDATE}.

increase the common code in cache_flush_phys().


# 1.308 01-Feb-2010 mrg

- sp_tlb_flush_all() becomes sp_tlb_flush_all_us() and sp_tlb_flush_all_usiii()
- sparc64_ipi_flush_pte() becomes sparc64_ipi_flush_pte_us() and
sparc64_ipi_flush_pte_usiii()
- add some commented out code to disable interrupts and raise the traplevel
in sparc64_ipi_flush_pte_usiii()
- cache_flush_phys() was missing a little of code in the cheetah case


# 1.307 01-Feb-2010 mrg

for USIII, use the new "tlb demap all" operation in sp_tlb_flush_all()


# 1.306 01-Feb-2010 mrg

remove unused icache_flush_page() implementation.


# 1.305 23-Jan-2010 mrg

remove the final uses of DATA_START.

now we can remove the 16KB space reserved at the start of the data segment,
and i now understand why i wrote this now removed comment 3.5 years ago:
"this shouldn't be needed... but kernel usually hangs without it"


# 1.304 23-Jan-2010 mrg

remove most of the code that writes debugging info DATA_START + offset.


# 1.303 23-Jan-2010 mrg

remove CHKPT() macro and uses. it's likely wrong in SMP land and probably should
be replaced with KTR-style uses if necessary.


# 1.302 23-Jan-2010 mrg

fix a comment.


Revision tags: matt-premerge-20091211
# 1.301 10-Dec-2009 rmind

Rename L_ADDR to L_PCB and amend some comments accordingly.


# 1.300 05-Dec-2009 mrg

- adjust the PA mask to the 43 bits supported by USIII.
- rework the spitfire/cheetah cache_flush_phys() to avoid several #ifdefs
- add a membar #Sync after sparc64_ipi_drop_fpstate (probably unnecessary)


# 1.299 30-Nov-2009 nakayama

sp_tlb_flush_pte for cheetah:
- restore interrupts properly in case of %tl > 0.


# 1.298 30-Nov-2009 mrg

stablize UP USIII support by blocking interrupts around sp_tlb_flush_pte()
i was seeing stack corruption while taking an interrupt in this function.

get USIII SMP mostly working by implementing the cheetah version of
sparc64_ipi_flush_pte().


SMP support is still not entirely stable. i can reproducably get a:

panic: fpusave_lwp ipi didn't

while running build.sh, when an awk process is exiting. other simple
heavy work loads do not crash for me right now.


# 1.297 30-Nov-2009 mrg

delete some no longer used code:
- smp_tlb_flush_ctx()
- smp_tlb_flush_all()
- sparc64_ipi_flush_ctx()
- sparc64_ipi_flush_all()
- sp_tlb_flush_ctx()


# 1.296 29-Nov-2009 nakayama

- calculate end PA correctly.
- wrap more spitfire specific (flushing I$) code.
- fix inverted #if condition for flushing I$ (and restore ASI_ICACHE_TAG).


# 1.295 28-Nov-2009 mrg

implement enough code to get SB2000/SB2500 booting to multiuser. does
not last long if you use it, but an idle machine has stayed up 10 hours.

- for the !SPITFIRE case, use ASI_DCACHE_INVALIDATE instead of
ASI_DCACHE_TAG when clearing tlb entries. from openbsd.

- convert some comment "! Not yet" into "WRITEME", so that attempting
to build a USIII MULTIPROCESSOR kernel fails to build until the code
is written.

- add some more WRITEME's for the above.

- implement a !SPITFIRE version of sp_tlb_flush_all(). since there are
no spare regs, for now just always increase %tl around this call. (we
could maybe store a token in %o3 along with the saved %pstate info.)


# 1.294 26-Nov-2009 matt

Kill proc0paddr. Use lwp0.l_addr instead.


# 1.293 25-Nov-2009 mrg

s/L_ADDR/L_PCB/, requested by rmind.


# 1.292 17-Oct-2009 nakayama

Wrap unused code with #if 0 which is called from #if 0'ed code.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5
# 1.291 30-May-2009 martin

cpu_setfunc() can not use lwp_trampoline, as that has additional lwp startup
semantics. Use a simpler setfunc_trampoline instead.


# 1.290 18-May-2009 nakayama

Remove random() from locore.s since it is in libkern.


# 1.289 16-May-2009 nakayama

Remove clear %tick in locore.s since it is cleared at cpu_initclocks() in
clock.c.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 nick-hppapmap-base mjf-devfs2-base
# 1.288 15-Dec-2008 mrg

restore some old "intrdebug" code, but leave it under NOT_DEBUG. most
of it works, but one that prints func/arg for each handler is not very
stable...

for now, while schizo bus space pointer accesses aren't working, add
a SCHIZO_BUS_SPACE_BROKEN option so you can build a kernel with schizo.

with this, and the prior schizo interrupt fix, you can now fail to run
/sbin/init!


Revision tags: haad-dm-base2 haad-nbase2 haad-dm-base
# 1.287 09-Dec-2008 martin

Get rid of get_maxctx() - it doesn't work on newer cpus and we will have
to find a better way for (some) sun4v machines - all sun4u use 13 bit
contexts anyway.


Revision tags: netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 ad-audiomp2-base netbsd-5-base
# 1.286 30-Oct-2008 nakayama

branches: 1.286.2; 1.286.6;
Wrap more code specific to USE_BLOCK_STORE_LOAD.


Revision tags: matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4
# 1.285 05-Oct-2008 nakayama

branches: 1.285.2;
- in flushing cache, use 32 as increment/decrement value to match the
cache line size.
- remove useless restore of %asi.
- remove nop in delay slot if we can.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 1.284 10-Jul-2008 nakayama

Use proper CCR.


# 1.283 10-Jul-2008 nakayama

sparc64_ipi_save_fpstate:
- use primary MMU context for consistency with other trap/interrupt handlers.

sparc64_ipi_save_fpstate, savefpstate:
- avoid storing fp registers as we can.

sparc64_ipi_save_fpstate, savefpstate, loadfpstate:
- remove unaligned case since buffers allocated with pool_cache are ensured
64-byte aligned.

Ok by martin@.


# 1.282 02-Jul-2008 nakayama

branches: 1.282.2;
UltraSPARCs don't have floating point queue, and reading %fq regsiter
will cause illegal instruction trap. So remove the code handling them.


# 1.281 29-Jun-2008 nakayama

Wrap IPI calls with #ifdef MULTIPROCESSOR.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.280 14-Jun-2008 nakayama

Close unterminated comment.
Fix unexpected behavior in case of loadfpstate from unaligned buffer.


Revision tags: yamt-pf42-base3
# 1.279 31-May-2008 nakayama

branches: 1.279.2;
openfirmware_exit:
- disable interrupts with %pstate.
- prepare 64-bit stack and enable 64-bit addresses for 32-bit SMP kernels.


Revision tags: hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 yamt-nfs-mp-base yamt-pf42-base
# 1.278 16-Apr-2008 nakayama

branches: 1.278.2; 1.278.4; 1.278.6;
Disable TRAPSTATS which was accidentally enabled when yamt-idlelwp branch
was merged.

Ok by martin@.


# 1.277 14-Apr-2008 nakayama

Remove sparc64_ipi_sync_tick.

Since we can use counter-timer as timecounter instead of %tick on SMP kernel,
it is not necessary to sync all CPUs %tick registers.


# 1.276 14-Apr-2008 nakayama

Add workaround for BB_ERRATA_1 on writing to TICK_CMPR register in
next_tick(). If writing to TICK_CMPR fails, we lose hardclock interrupt
on secondary CPUs.

About BB_ERRATA_1 from comment in OpenSolaris:

/*
* Writes to the TICK_COMPARE register sometimes fail on blackbird modules.
* The failure occurs only when the following instruction decodes to wr or
* wrpr. The workaround is to immediately follow writes to TICK_COMPARE
* with a read, thus stalling the pipe and keeping following instructions
* from causing data corruption. Aligning to a quadword will ensure these
* two instructions are not split due to i$ misses.
*/


# 1.275 28-Mar-2008 nakayama

Don't read fplwp content in delay slot for considering the case fplwp was
modifiled.

Reported by Chris Ross on port-sparc64.


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.274 20-Mar-2008 nakayama

- remove disabling interrupt in IPI.
- unused VA bits in MMU demap is 13 bits, not 12 bits.


# 1.273 18-Mar-2008 nakayama

Fix a race when increment an interrupt level event counter.


# 1.272 17-Mar-2008 nakayama

Fix a race condition in IPI handlers of save/drop fpstate, from OpenBSD.
Reported and tested by martin@.


# 1.271 17-Mar-2008 nakayama

Make schedintr interrupt handler per-CPU.
While there rename tickintr interrupt handler and share initialization
code with schedintr.


# 1.270 14-Mar-2008 nakayama

Improve IPI handling:
- make IPI takes two arguments.
- add IPI event counters per-CPU.
- implement IPI functions which were missing or broken.
- insert DELAY while halting primary CPU in IPI handler.


# 1.269 02-Mar-2008 nakayama

- make interrupt pending list per-CPU.
- make tickintr() MP-safe.
- remove unused port-sparc derived interrupt code.

Ok by martin@.


# 1.268 02-Mar-2008 nakayama

Don't get IPI handler argument (from bogus address), and ack IRQ twice.


# 1.267 28-Feb-2008 martin

Make TSBs and MMU contexts per-cpu.


Revision tags: nick-net80211-sync-base mjf-devfs-base hpcarm-cleanup-base
# 1.266 26-Jan-2008 nakayama

branches: 1.266.2; 1.266.6;
Fix for 32-bit kernels.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.265 15-Jan-2008 skrll

Store a sensbile PCB_PC value in snapshot - the return point.

This helps gdb somewhat.

OK'd by martin.


# 1.264 14-Jan-2008 martin

Fix register name typo/copy&pasto - %g6 is not %o6/%sp.
From OpenBSD.


Revision tags: matt-armv6-base
# 1.263 06-Jan-2008 martin

Load the next cpu_info pointer with LDPTR instead of ld.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2
# 1.262 09-Dec-2007 martin

branches: 1.262.2;
Provide cpu_intr_p(), at least for non-MULTIPROCESSOR kernels.
Based on suggestions by Andrew Doran.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.261 22-Oct-2007 martin

branches: 1.261.2; 1.261.4; 1.261.6;
Remove an unused .globl declaration


Revision tags: yamt-x86pmap-base4
# 1.260 17-Oct-2007 garbled

Merge the ppcoea-renovation branch to HEAD.

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

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

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base ppcoea-renovation-base vmlocking-base
# 1.259 09-Sep-2007 martin

branches: 1.259.4;
Make cpufrequency and friends per cpu values.
Prepare a hz tick interrupt on secondary CPUs via %tick, but do not
enable it yet, as it breaks ddb.


# 1.258 09-Sep-2007 martin

Do not ACK IPIs before we finished loading all arguments.


# 1.257 06-Sep-2007 martin

Remove the (now unused) second 64k page mapped per CPU.
From matthew green, with small changes by me. All bugs are mine.


# 1.256 25-Aug-2007 martin

branches: 1.256.2;
Remove INITSTACK completely - at the time we used to switch to it, we
already have access to all of lwp0 and it's uarea - so we can switch
to the correct lwp0 stack easily before calling main.


# 1.255 25-Aug-2007 martin

When exiting to OF, use the interrupt stack instead of INITSTACK


# 1.254 25-Aug-2007 martin

Rework cpu_mp_startup slightly:
- temporarily use the cpu's interrupt stack untill we are ready
to access non-OF-based mappings, then directly switch to the cpu's
idlelwp's uarea stack
- disable interrupts untill we are ready to call C code


# 1.253 13-Aug-2007 macallan

remove two restore without matching save


Revision tags: nick-csl-alignment-base matt-mips64-base mjf-ufs-trans-base
# 1.252 06-Jul-2007 martin

branches: 1.252.4; 1.252.8;
A few nits for 32bit SMP kernels, noticed by mrg.
While there, simplify the fpstate IPIs a bit.


# 1.251 05-Jul-2007 martin

sparc64_ipi_save_fpstate is not a leaf function - create a full grown
stack frame.


# 1.250 28-May-2007 mrg

clean up cpu_switchto() a little - no need to flushw or membar
excessively. optimise an rdpr. tested by tnn.


# 1.249 23-May-2007 martin

Fix a stupid bug in the save_fpstate ipi, which caused overwriting of
struct lwp of the lwp owning the fpu. Fix clearing the fplwp - %o0 will
not survive the call to savefpstate - duh!


# 1.248 20-May-2007 martin

Simplify tf_tstate setting when leaving for userland initially - I seem
to have confused the if with the else case of the previous C code.
Funny that it worked at all.


# 1.247 20-May-2007 martin

cpu_switchto() has to return it's first arg, always. This differs from
my reading of the documentation, but helps in the real world and seems
to be what other ports do.


# 1.246 20-May-2007 martin

Remove special case handling for userland lwps from cpu_lwp_fork, instead
do it in lwp_trampoline when we first return to userland.


# 1.245 19-May-2007 martin

cpu_idle is a leaf function, so we better "return from leaf".
Use return value from cpu_switchto for previous lwp in lwp_trampoline.
Also shamelessly steal a comment from uwe written for sparc that explains
all this.
Thanks to tnn, mrg, and uwe for helping to debug this.


# 1.244 17-May-2007 yamt

merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base ad-audiomp-base
# 1.243 22-Feb-2007 martin

branches: 1.243.4; 1.243.6; 1.243.12;
uvm.page_idle_zero now is a bool, not a 32bit value any more.


# 1.242 21-Feb-2007 mrg

shave 9 insns off the tsb setup in cpu_initialize & cpu_mp_startup.


# 1.241 21-Feb-2007 martin

Get rid of unused (thus always zero) "curlwp" variable hidden in assembler
code (C code always uses a cpuinfo based macro).


# 1.240 18-Feb-2007 martin

Make use of another call delay slot, pointed out by uwe.


# 1.239 18-Feb-2007 martin

Make use of a call delay slot and avoid a bogus EMPTY.
Spotted by Juergen Hannken-Illjes, with input from Andrew Doran and
Valeriy E. Ushakov.


# 1.238 18-Feb-2007 martin

Whitespace cosmetics


# 1.237 18-Feb-2007 martin

Backout previous: EMPTY was misused


# 1.236 18-Feb-2007 martin

Make EMPTY expand to nop with gas, as it is used to mark empty branch
delay slots.


# 1.235 15-Feb-2007 martin

branches: 1.235.2;
Fix obvious copy&pasto in SCHED_DEBUG register usage.


Revision tags: post-newlock2-merge
# 1.234 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.233 25-Dec-2006 wiz

Spell "relevant" correctly. From Zafer Aydogan.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.232 25-Oct-2006 mrg

branches: 1.232.2; 1.232.4;
- note that __idle_u should go away but doing so breaks things
- fix several comments to reality
- clean up the #ifdef NO_VCACHE code slightly
- use call instead of set/jmpl
- remove a couple of unnecessary stores to curlwp


Revision tags: yamt-splraiseipl-base2
# 1.231 18-Oct-2006 rjs

Clean up some comments. Cosmetic change to use correct structure
offset names.

Optimize out two instructions from sparc64_ipi_save_fpstate and
sparc64_ipi_drop_fpstate.


# 1.230 17-Oct-2006 mrg

allocate 128KB (as opposed to 64KB) per-cpu, and place the interrupt
stack, cpu_info structure, panicstack, idle uarea and normal kernel
stack in here. the idle uarea and kernel stack are in the 2nd 64KB
page. the interrupt stack and cpu_info structure are as the same
place in the 1st 64KB page, and the panicstack grows down from the
top of this page. update comments in param.h to suit (XXX: a lot
of these constants should move to a header file that will not pollute
the name space so much.) map these pages identically between
cpu_initialise() and cpu_mp_startup(), and deal with the two 64KB
pages in pmap_extract(). keep an unmapped 64KB page between them.

don't initialise the unused "ci_eintstack" member of the cpu_info
structure

use constants to initialise many addresses in the cpu_info structure,
consolidating these assignments from cpu0 and cpu>0

delete u0/estack0/panicstack from locore.s

clean up some wrong comments in locore.s

fix a 32bit-only bug in cpu_mp_startup().

delete 'u0' entirely.


this fixes recent random lossage seen on port-sparc64: processes
stuck in RUN state, data faults, and hangs.


# 1.229 04-Oct-2006 mrg

use call instead of set/jmpl. add an entry point for idle that expects
sched_lock to be unlocked, and use this for non-boot cpu's. complete a
comment describing how registers in idle_switch are expected to be set.


# 1.228 03-Oct-2006 mrg

use the same SAVE_LOCALS_INS definition for 32 bit and 64 bit kernels.
refactor TRAP_SETUP() a little between these two versions to be more alike.


# 1.227 03-Oct-2006 mrg

use the correct size/type for MP variables (pointers and longs).

a 32 bit MULTIPROCESSOR kernel now builds (and crashes quickly.)


# 1.226 03-Oct-2006 mrg

in the 64bit version of SAVE_LOCAL_INS, s/BIAS/STKB/ to allow future
sharing of the 32 and 64 bit versions of the {TRAP,INTR}_SETUP macros.


# 1.225 19-Sep-2006 mrg

- remove some way old FP setup/teardown code
- put the block memcpy/memset inside #ifdef USE_BLOCK_STORE_LOAD which
is (now) defined.

no functional change, same .o is generated.


# 1.224 19-Sep-2006 mrg

re-order the changes in rev 1.217 to give registers a little bit of
time to settle between usage, like it was before hand.


# 1.223 19-Sep-2006 mrg

- remove a wrong comment.
- add a new entry point for idle called idle_switch that is called by
cpu_switch() in the MP case when sched_whichqs is zero, properly
setting up the idle stack. from petrov@ via martin@.


# 1.222 19-Sep-2006 mrg

rework interrupt_vector() slightly:
- for the IPI case, avoid loading the address of intrlev into %g3
- remove some NOT_DEBUG code
- load the interrupt argument #2 in the delay slot

this removes 2 nops during interrupt processing for the normal
case, and an additional 2 ALU instructions for IPIs


# 1.221 18-Sep-2006 mrg

- sparc64_ipi_halt(): we shouldn't return from sparc64_ipi_halt_thiscpu()
so replace a branch with a 'sir'
- in #if 0 code, in sparc64_ipi_flush_pte() and sparc64_ipi_flush_ctx()
save/restore the out registers that the sp_tlb_flush_xxx() versions
around calling them
- in sp_tlb_flush_pte() and sp_tlb_flush_ctx(), replace global register
usage with out registers so that we don't clobber the (alternate)
global registers when these are called from IPI context


# 1.220 18-Sep-2006 mrg

- remove an extra 'sir' that followed one in a macro
- add some named labels to some spill/fill handlers
- remove 2 unused strings


Revision tags: yamt-splraiseipl-base
# 1.219 18-Sep-2006 martin

branches: 1.219.2;
Lazy FPU handling for the MULTIPROCESSOR case


# 1.218 16-Sep-2006 nakayama

From OpenBSD:
- reload %fprs for checking it again.
- use symbolic names for checking in %fprs.

revision 1.51
date: 2005/07/18 14:50:11; author: deraadt; state: Exp; lines: +2 -1
cache a copy of the fprs so we know what fp restore we should do after

revision 1.50
date: 2005/07/14 01:46:13; author: deraadt; state: Exp; lines: +4 -4
use symbolic names for checking in %fprs, as above


# 1.217 16-Sep-2006 nakayama

Fix a couple of %y register save/restore errors, inspired from OpenBSD.

revision 1.44
date: 2004/04/23 04:18:17; author: marc; state: Exp; lines: +5 -4

fix a couple of %y register save/restore errors
1) don't save %y in a register that is later used before restoring %y
2) always restore %y after calling a signal handler
tested by drahn@, OK pval


# 1.216 15-Sep-2006 martin

Do not bother to save fpu state when we are about to get rid of it.


Revision tags: yamt-pdpolicy-base9
# 1.215 13-Sep-2006 mrg

SMP cleanup. provide support for multiple CPUs in DDB. (SMP itself
is still not working.)

cpu.h:
- add a pointer for DDB regs in SMP environment to struct cpu_info
- remove the #defines for mp_pause_cpus() and mp_resume_cpus()
cpuset.h:
- remove CPUSET_ALL() and rename CPUSET_ALL_BUT() to CPUSET_EXCEPT()
from petrov.
db_machdep.h:
- rename the members of db_regs_t to be the same as sparc
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- redo DDB_REGS to no longer be a pointer to a fixed data structure
but to one allocated per-cpu when ddb is entered
- move a bunch of prototypes in here
intr.h:
- remove SPARC64_IPI_* macros, no longer used
db_interface.c:
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- make "nil" a 64 bit entity
- change the ddb register access methods to work in multiprocessor
environment, it is now very much like sparc does it
- in kdb_trap() avoid accessing ddb_regp when it is NULL
- update several messages to include the cpu number
- unpause other cpus much later when resuming from ddb
- rename db_lock() to db_lock_cmd(), as the sparc-like code has
db_lock as a simple lock
- remove "mach cpus" command, and replace it with "mach cpu" (which
does the same) and also implement "mach cpu N" to switch to
another cpus saved trapframe
db_trace.c:
- update for the ddb_regs -> ddb_regp change
genassym.cf:
- add TF_KSTACK as offsetof(struct trapframe64, tf_kstack)
ipifuncs.c:
- overhaul extensively
- remove all normal interrupt handlers as IPI's, we now handle
them all specially in locore.s:interrupt_vector
- add a simplelock around all ipi functions - it's not safe for
multiple cpus to be sending IPI's to each other right now
- rename sparc64_ipi_pause() to sparc64_ipi_pause_thiscpu() and,
if DDB is configured, enable it to save the passed-in trapframe
to a db_regs_t for this cpu's saved DDB registers.
- remove the "ipimask" system (SPARC64_IPI_* macros) and instead
pass functions directly
- in sparc64_send_ipi() always set the interrupt arguments to 0,
the address and argument of the to be called function. (the
argument right now is the address of ipi_tlb_args variable, and
part of the reason why only one CPU can send IPI's at a time.)
don't wait forever for an IPI to complete. some of this is
from petrov.
- rename sparc64_ipi_{halt,pause,resume}_cpus() to
mp_{halt,pause,resume}_cpus()
- new function mp_cpu_is_paused() used to avoid access missing
saved DDB registers
- actually broadcast the flush in smp_tlb_flush_pte(),
smp_tlb_flush_ctx() and smp_tlb_flush_all(). the other end may
not do anything yet in the pte/ctx cases yet...
kgdb_machdep.c:
- rework for changed member names in db_regs_t.
locore.s:
- shave an instruction from syscall_setup() (set + ld -> sethi + ld)
- remove some old dead debug code
- add new sparc64_ipi_halt IPI entry point, it just calls the C
vector to shutdown.
- add new sparc64_ipi_pause IPI entry point, which just traps into
the debugger using the normal breakpoint trap. these cpus usually
lose the race in db_interface.c:db_suspend_others() and end up
calling the C vector sparc64_ipi_pause_thiscpu().
- add #if 0'ed code to sparc64_ipi_flush_{pte,ctx}() IPI entry
points to call the sp_ version of these functions.
- in rft_kernel (return from trap, kernel), check to see if the
%tpc is at the sparc64_ipi_pause_trap_point and if so, call
"done" not "retry"
- rework cpu_switch slightly: save the passed-in lwp instead of
using the one in curlwp
- in cpu_loadproc(), save the new lwp not the old lwp, to curlwp
- in cpu_initialize(), set %tl to zero as well. from petrov.
- in cpu_exit(), fix a load register confusion. from petrov.
- change some "set" in delay branch to "mov".
machdep.c:
- deal with function renames
pmap.c:
- remove a spurious space
trap.c:
- remove unused "trapstats" variable
- add cpu number to a couple of messages


# 1.214 09-Sep-2006 mrg

significant clean up effort, largely from petrov@ via martin@.

- fix a bunch of comments for proc->lwp
- remove old TRAPTRACE, NOT_DEBUG, etc. code that has bit-rotted
- put some older DEBUG code under NOT_DEBUG
- add a bunch of new debugging/tracing code ("KTR") that depends on
other changes not yet present.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base yamt-pdpolicy-base5 chap-midi-base simonb-timecounters-base rpaulo-netinet-merge-pcb-base
# 1.213 14-May-2006 elad

branches: 1.213.6; 1.213.8;
integrate kauth.


# 1.212 12-May-2006 skrll

Fix some comments.


Revision tags: elad-kernelauth-base
# 1.211 09-May-2006 rjs

Load CPCB in cpu_mp_startup.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.210 11-Feb-2006 cdi

branches: 1.210.2; 1.210.4; 1.210.6;
ANSIfication: u_intN_t -> uintN_t, use ANSI function declarations/definitions
instead of K&R ones.


# 1.209 27-Jan-2006 cdi

branches: 1.209.2; 1.209.4;
Alter sparc64 bootstrap, catch up to ofwboot v1.9:

- Accept bootinfo structure passed down from ofwboot v1.9
- Drop kernel re-mapping code
- Use permanent 4MB mappings provided by the loader instead
- Change kernel entry address to point directly at the code instead of pointing
at the trap table's first slot. This allows the bootloader to detect
those kernels which are aware of the new boot scheme
- Due to the changes in kernel mapping code, alter secondary CPU bootstrap
code to use trampoline just like FreeBSD does (some FreeBSD code is used
here as well)


# 1.208 12-Jan-2006 cdi

Fix a typo: %g0 should be used instead of %o0 when initializing FPU in dostart:
and cpu_mp_startup:, %o0 is not even initialized at this point.


# 1.207 11-Dec-2005 christos

branches: 1.207.2;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 1.206 10-Jul-2005 christos

Re-factor syscall, and make it use syscall_{plain,fancy}.


# 1.205 31-May-2005 chs

branches: 1.205.2;
remove vestigal {,e}intr{names,cnt} symbols now that vmstat doesn't need them.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.204 12-Feb-2005 chs

branches: 1.204.4; 1.204.6; 1.204.8;
in sparc_interrupt(), wait to enable interrupts until just before calling
the handler and disable them again right after the handler returns.
we don't want another hardware interrupt coming in while we're mucking
with the list pointers. also, clear the intrhand's ih_pending pointer
before calling the handler rather than after, so that if another interrupt
comes in while the handler is running, we can put the intrhand back on
the list so it will be called again.

in send_softint(), disable interrupts via %pstate instead of %pil, so that
hardware interrupts at higher levels are blocked while we manipulate the
intrpending list. also, if the intrhand already has ih_pending set,
don't bother poking the SET_SOFTINT register again, since being on the list
implies that there is already a softint pending in the hardware.

these appear to fix PR 21750 (the "sleep forever" problem).

while I'm here, remove more vestiges of the !INTRLIST softint stuff
(code and comments). and in sparc64_ipi_flush_all(), interrupts are
already disabled so we don't need to fiddle with %pstate.


Revision tags: yamt-km-base2
# 1.203 30-Jan-2005 martin

Remove the no long usefull variants selected by undefining INTRLIST and
INTR_INTERLOCK to improve readability. Same object code generated as before.


Revision tags: yamt-km-base
# 1.202 16-Jan-2005 chs

branches: 1.202.2;
use ENTRY_NOPROFILE() for various entry points,
stack traces work better that way.


Revision tags: kent-audio1-beforemerge kent-audio1-base
# 1.201 03-Dec-2004 chs

branches: 1.201.4;
remove cache_flush_virt() and PADDRT, they're no longer used.
allocate a stack frame for blast_dcache() when profiling so it shows up.
in dcache_flush_page(), use a stride of 32 instead of 16 to match the
cache line size. correct various comments.


# 1.200 08-Nov-2004 petrov

Don't compile sparc64_ipi functions when UP.


# 1.199 25-Oct-2004 martin

No need to clear %o1 when returning a 64 bit integer from pseg_get if we
are compiling for a 64 bit kernel.


# 1.198 24-Jul-2004 nakayama

Change interrupt pending list end value to -1, to avoid linking an
interrupt handler twice.

It may fix "sleep forever" bug.


# 1.197 09-Apr-2004 petrov

Clean-up unused defines and variables.


Revision tags: netbsd-2-0-base
# 1.196 26-Mar-2004 petrov

branches: 1.196.2;
Use want_resched from cpu_info area.


# 1.195 23-Mar-2004 martin

Replace intrcnts by evcnts. XXX - needs slight tweaking for MULTIPROCESSOR.


# 1.194 14-Mar-2004 chs

checkpoint of MP work from dennis and myself. includes cross-processor
interrupt framework, a sledgehammer TLB invalidation and misc MP fixes.
doesn't work at all yet.


# 1.193 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.192 19-Jan-2004 martin

Rename switchexit to cpu_exit and g/c the old C implementation of cpu_exit.


# 1.191 18-Jan-2004 martin

Support RAS for 32bit kernels too.


# 1.190 16-Jan-2004 martin

In proc_trampoline don't bother to clear condition codes in the trap
frame, since we no longer rely on this.
While there fix a few comments.


# 1.189 08-Jan-2004 martin

Minor cleanup


# 1.188 06-Jan-2004 martin

Implement restartable atomic sequences (RAS) for sparc64.


# 1.187 06-Jan-2004 petrov

Spinup secondary cpus. Based on codes sent to me by Dennis Chernoivanov
and Chuck Silvers.


# 1.186 04-Jan-2004 jdolecek

update to recent changes - exit2() doesn't exist anymore and the
exit path always calls lwp_exit2()
pointed out Martin Husemann


# 1.185 02-Dec-2003 martin

Minor cleanup: remove unused code, sync a comment with current reality.


# 1.184 25-Nov-2003 cdi

Use per-cpu pcb, curlwp and fplwp rather than global ones. This brings
GENERIC.MP configuration to a usable state.

Approved by petrov@.


# 1.183 24-Nov-2003 cdi

Call 'proc_trampoline_mp' from 'proc_trampoline' in a multiprocessor
configuration. Fix process locking. Approved by petrov@.


# 1.182 20-Nov-2003 petrov

Remove nwindows calculation, it's not used. Set l_cpu in cpu_switch.


# 1.181 09-Nov-2003 martin

Get rid of bcopy/bzero.


# 1.180 26-Oct-2003 christos

Initial siginfo support for sparc64 (untested). COMPAT_16 sigcontext signal
delivery tested.


# 1.179 24-Aug-2003 chs

add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default. the changes
fall into two basic catagories:

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

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

originally from openbsd, adapted for netbsd by me.


# 1.178 08-Jul-2003 cdi

traceit: don't use %g7 as it is to become curcpu() register. Add comments.


# 1.177 18-May-2003 martin

branches: 1.177.2;
Make kernels with options KGDB at least compile.
Still needs some work to make it working.


# 1.176 29-Apr-2003 nakayama

Use BLOCK_ALIGN rather than BLOCK_SIZE for aligning a pointer.


# 1.175 27-Apr-2003 ragge

Preserve the symbol table in the LKM || KSYMS cases also.


# 1.174 04-Apr-2003 petrov

use branch slot in pmap_copy_page.


# 1.173 24-Mar-2003 nakayama

Divide `set' instruction in delay slot (from OpenBSD change to rev 1.30).


# 1.172 10-Feb-2003 martin

Remove some #if 0 code and a few XXX marked membars w/o proper
justification for their existence.


# 1.171 09-Feb-2003 martin

Remove left over pieces from reusing the signal trampoline for upcalls.
This should fix signal delivery for 32bit kernels.


# 1.170 05-Feb-2003 nakayama

Switch to use cycle counter (%tick) based microtime().

This is derived from alpha/microtime.c and i386/tsc_microtime.c,
and will share with both ports.

This should fix PR port-sparc64/18452.
(approved by martin)


# 1.169 04-Feb-2003 martin

Fix return value of pseg_set, which I accidently broke in rev. 1.164.

Fix register names in comment and shave off another register (hint
from uwe).


# 1.168 01-Feb-2003 martin

Rearrange register usage in pseg_set a bit and shave off %g4.


# 1.167 01-Feb-2003 martin

Remove a few #ifdef _LP64 by using STPTR/LDPTR macros.
Thanks to Matthew Green for the pointer.


# 1.166 31-Jan-2003 martin

Apply leaf procedure optimization to pseg_set (again).


# 1.165 31-Jan-2003 martin

Make the pmap count resident/wired mappings on the fly instead of
walking the page tables whenever this information is needed.

Add an option PMAP_COUNT_DEBUG to assert the new counts and the
page table walk agree.

The old solution had very bad performance impact, for example
by the high CPU load when running top(1).

Thanks to Simon Burge for pointing at the cause of the problem and
to Valeriy E. Ushakov for optimizing my simple minded assembler code.


# 1.164 27-Jan-2003 martin

Remove unused function pseg_find (which looked quite similar to
pseg_get anyway).


# 1.163 18-Jan-2003 thorpej

Merge the nathanw_sa branch.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.162 16-Jan-2003 petrov

Move dump_dtlb back under DDB.


# 1.161 15-Jan-2003 chs

fix two bugs in my last pmap rework:
- in tlb_flush_all(), don't skip TLB entries with the high bit on,
I was confused about which MMU register it was using. it's also fine
to use the last hardware context.
- in pmap_create(), don't allocate a hardware context for the new pmap.
it's unnecessary, and when this would cause us to recycle all the contexts,
it would result in the current process's context being set to 0
(ie. the kernel's context). the current process could then return to
userspace without going through the context-switch code (and thus without
having a hardware context reallocated). this would lead to user mappings
being entered in the kernel's context later, causing all sorts of trouble.
add some assertions to catch this kind of thing.


Revision tags: fvdl_fs64_base
# 1.160 25-Dec-2002 petrov

new function dump_itlb.


Revision tags: gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.159 22-Sep-2002 chs

many improvements:
- use struct vm_page_md for attaching pv entries to struct vm_page
- change pseg_set()'s return value to indicate whether the spare page
was used as an L2 or L3 PTP.
- use a pool for pv entries instead of malloc().
- put PTPs on a list attached to the pmap so we can free them
more efficiently (by just walking the list) in pmap_destroy().
- use the new pmap_remove_all() interface to avoid flushing the cache and TLB
for each pmap_remove() that's done as we are tearing down an address space.
- in pmap_enter(), handle replacing an existing mapping more efficiently
than just calling pmap_remove() on it. also, skip flushing the
TSB and TLB if there was no previous mapping, since there can't be
anything we need to flush. also, preload the TSB if we're pre-setting
the mod/ref bits.
- allocate hardware contexts like the MIPS pmap:
allocate them all sequentially without reuse, then once we run out
just invalidate all user TLB entries and flush the entire L1 dcache.
- fix pmap_extract() for the case where the va is not page-aligned and
nothing is mapped there.
- fix calculation of TSB size. it was comparing physmem (which is
in units of pages) to constants that only make sense if they are
in units of bytes.
- avoid sleeping in pmap_enter(), instead let the caller do it.
- use pmap_kenter_pa() instead of pmap_enter() where appropriate.
- remove code to handle impossible cases in various functions.
- tweak asm code to pipeline a little better.
- remove many unnecessary spls and membars.
- lots of code cleanup.
- no doubt other stuff that I've forgotten.

the result of all this is that a fork+exit microbenchmark is 34% faster
and a fork+exec+exit microbenchmark is 28% faster.


Revision tags: gehenna-devsw-base
# 1.158 18-Jul-2002 wiz

Spell 'should' correctly.


# 1.157 07-Jun-2002 eeh

Shave 10% off the time needed to flush the D$ through a bit of instruction
reordering.


# 1.156 05-Jun-2002 eeh

Handle improperly aligned stack pointers more cleanly.


# 1.155 04-Jun-2002 eeh

Fix the fork trampoline to properly use the supplied tstate.


# 1.154 31-May-2002 thorpej

Make this work with an ISO C preprocessor.


Revision tags: netbsd-1-6-base
# 1.153 14-May-2002 eeh

branches: 1.153.2; 1.153.4;
Only save locals and ins in trapframes for DEBUG kernels.


# 1.152 04-May-2002 kleink

Add some comments to the CPP conditionals controlling the trap macro
definitions, to ease navigation somewhat.


# 1.151 16-Apr-2002 eeh

Make lots of routines profile-friendly and get rid of some cruft.


Revision tags: eeh-devprop-base
# 1.150 21-Mar-2002 petrov

Not needed debug stuff deleted.


# 1.149 16-Mar-2002 mrg

tell newer binutils that our use of %g2 and %g3 is OK here.


# 1.148 15-Mar-2002 eeh

Cleanup MMU initialization to prevent hangs.


Revision tags: newlock-base ifpoll-base
# 1.147 09-Feb-2002 eeh

branches: 1.147.4;
Fix microsecond calculation in microtime.


# 1.146 07-Feb-2002 eeh

Fix register allocation in microtime().


# 1.145 29-Jan-2002 eeh

Shift the UPAID in the correct direction.


# 1.144 17-Jan-2002 eeh

Be more tolerant of unaligned stack pointers.


# 1.143 17-Jan-2002 eeh

Enable block insns in bcopy and bzero.


# 1.142 16-Jan-2002 eeh

In bcopy use 32-bit comparisons in 32-bit kernels.


# 1.141 16-Jan-2002 eeh

Use correct calculation for the trapframe in softtrap for ILP32.


# 1.140 20-Nov-2001 lukem

- pull in opt_kgdb.h where necessary
- replace opt_kgdb_machdep.h with opt_kgdb.h
- defparam opt_kgdb.h:
KGDB_DEV KGDB_DEVNAME KGDB_DEVADDR KGDB_DEVRATE KGDB_DEVMODE
- move from opt_ddbparam.h to opt_ddb.h:
DDB_FROMCONSOLE DDB_ONPANIC DDB_HISTORY_SIZE DDB_BREAK_CHAR SYMTAB_SPACE
- replace KGDBDEV with KGDB_DEV
- replace KGDBADDR with KGDB_DEVADDR
- replace KGDBMODE with KGDB_DEVMODE
- replace KGDBRATE with KGDB_DEVRATE
- use `9600' instead of `0x2580' for 9600 baud rate
- use correct quotes for options KGDB_DEVNAME="\"com\""
- use correct quotes for options KGDB_DEV="17*256+0"
- remove unnecessary dependancy on Makefile for kgdb_stub.o
- minor whitespace cleanup


Revision tags: thorpej-mips-cache-base thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf
# 1.139 14-Sep-2001 thorpej

branches: 1.139.4;
Don't declare intrhand[] here -- that's taken care of in intr.c.


Revision tags: thorpej-devvp-base
# 1.138 30-Aug-2001 eeh

branches: 1.138.2;
Preliminary UltraSPARC III suport (not enabled yet).


# 1.137 13-Aug-2001 jdolecek

g/c _remque()/_insque(); use the C version in libkern


# 1.136 09-Aug-2001 eeh

Fix context masking lossage caused by last version.


# 1.135 08-Aug-2001 eeh

Clean up the trap code to handle the changes cause by supporting non-faulting
accesses. Also change the parameter order so trap frames are easy to find.


# 1.134 07-Aug-2001 eeh

Make sure C code always has ASI_PRIMARY_NOFAULT in the %asi register so
the compiler will be happy if it ever starts generating speculative loads.


# 1.133 05-Aug-2001 eeh

Add support for non-faulting loads and optimize MMU miss handling paths.


# 1.132 02-Aug-2001 eeh

Fix bcopy.


# 1.131 02-Aug-2001 eeh

Sync bzero w/libc version.


# 1.130 01-Aug-2001 eeh

Integrate fixes from userland memset.


# 1.129 31-Jul-2001 eeh

Code cleanup and optimization.


# 1.128 23-Jul-2001 eeh

Get rid of some debug code that really isn't all that useful any more.


# 1.127 19-Jul-2001 eeh

Do ignore unregistered interrupts instead of faulting.


# 1.126 16-Jul-2001 eeh

Make bcopy a 32-bit friendly.


# 1.125 11-Jul-2001 eeh

Fix problems booting 32-bit kernels and dispatching level-15 interrupts.


# 1.124 08-Jul-2001 eeh

branches: 1.124.2;
Code cleanup. Add block_disable to let you turn on block set/copy routines.


# 1.123 05-Jul-2001 eeh

New block bzero and bcopy.


# 1.122 04-Jul-2001 eeh

Replace old bcopy with a much faster version.


# 1.121 01-Jul-2001 martin

Disable axidently enabled debug code to make -current compile again.


# 1.120 30-Jun-2001 eeh

Use a newer version (still disabled) of block bcopy.


# 1.119 30-Jun-2001 eeh

Fixup fpu save restore, get rid of some unused copy functions, and add
a new bcopy.


# 1.118 21-Jun-2001 eeh

Allow multiple 4MB pages for both kernel text and kernel data.

Note: DEBUG checks will not allow accesses to the hole between
text and data segments, so you may need to update programs that
use libkvm before relocating the start of kernel data.


# 1.117 06-Jun-2001 mrg

extract the netbsd32, sunos, 32 bit svr4 and 64 bit svr4 sigcode out into
separate files, so that compat lkms can link with them as well.


# 1.116 30-May-2001 lukem

add missing #include "opt_kgdb.h"


Revision tags: thorpej_scsipi_beforemerge
# 1.115 25-Apr-2001 simonb

Spell occurred correctly.


Revision tags: thorpej_scsipi_nbase thorpej_scsipi_base
# 1.114 09-Apr-2001 eeh

Interrupt latency fix from sparc port. (Hm. One insn instead of 5).


# 1.113 07-Mar-2001 eeh

Fix inverted preprocessor logic. (Spotted by Charles.)


# 1.112 21-Feb-2001 eeh

branches: 1.112.2;
Add support for 64-bit SVR4 (Solaris 8) binaries.


# 1.111 10-Feb-2001 pk

Fix conditional for svr4 compat inclusion.


# 1.110 05-Feb-2001 eeh

Add signal trampoline for 64-bit svr4 emulations.


# 1.109 31-Dec-2000 eeh

Make INCR() atomic.


# 1.108 29-Dec-2000 eeh

pseg_get tells us whether it really needed that spare page after all.


# 1.107 07-Dec-2000 eeh

Fixup calculating where fpstate should be saved in the signal trampoline
code so it doesn't overwrite something important like the registers.


# 1.106 09-Nov-2000 eeh

Fix ILP32 bug in probe_get().


# 1.105 22-Oct-2000 pk

Restore revision 1.102.

I hope it sticks this time..


# 1.104 20-Oct-2000 eeh

Fix hang in 32-bit kernels caused by relocation of KERNBASE.


# 1.103 04-Oct-2000 eeh

Fix interrupt lossage problem and some cosmetic changes.


# 1.102 01-Oct-2000 pk

cpu_initialize: global registers aren't preserved across calls to
prom_printf(), so replace %g3 with %l7 (which isn't used despite
the `usage' comment).

Also, clean up white-space turds.


# 1.101 29-Sep-2000 eeh

This seems to fix the interrupt lossage of non-debug kernels.


# 1.100 28-Sep-2000 eeh

Fix INTR_SETUP() to properly distinguish kernel and user addresses.

Make microtime() return the correct time on %tick machines.

Re-enable debug stuff in dostart for now to detect kernel mapping issues.


# 1.99 25-Sep-2000 pk

Missing `#if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)'


# 1.98 17-Sep-2000 eeh

Make the improved %tick changes work with machines that use the counter-timer
for the clock.


# 1.97 12-Sep-2000 eeh

Fix new version of microtime.


# 1.96 11-Sep-2000 eeh

(Hopefully) fix clock skew on machines that us %tick for the clock (UIIi).


# 1.95 31-Aug-2000 eeh

Use casx instead of stx to change entries in the page table trees.


# 1.94 23-Aug-2000 eeh

Update the scheduler to the new locking scheme.


# 1.93 10-Aug-2000 eeh

Fix signal delivery.


# 1.92 02-Aug-2000 eeh

Get kernel profiling to work. Now if only gprof worked....


# 1.91 01-Aug-2000 eeh

Overhaul cache flush code and coredump code.


# 1.90 25-Jul-2000 pk

Re-instate a couple of delay slot NOPs marked `XXX spitfire bug?'


# 1.89 24-Jul-2000 mycroft

Optimization to pmap_zero_page(): we only need to use the first 16 FP regs,
as in bzero().


# 1.88 24-Jul-2000 mycroft

Fix a whitespace glitch.


# 1.87 24-Jul-2000 mycroft

Pull in the bzero() changes from libc for real, with a couple of kernel-
specific hacks:
* Make the bias handling depend on STKB, so it switches correctly for 32-bit
kernels.
* Use the 32-bit stw/ld for 32-bit kernels.
* Add a few `-STKB's that were missed in the previous change.


# 1.86 24-Jul-2000 pk

Cosmetic & readability:
- local label cleanup in interrupt handling code;
- in debugging sections when testing `intrdebug': use a unique
local label (97) to enhanced clarity;
- comment-out unused code;
- kill a bug as the satisfying result of doing all of the above.


# 1.85 24-Jul-2000 eeh

Fix stack issues in bzero.


# 1.84 24-Jul-2000 mycroft

Revert the previous change for now. I don't have time to debug it tonight.


# 1.83 23-Jul-2000 mycroft

Copy bzero change from libc.


# 1.82 20-Jul-2000 pk

Since `intrcnt' points to an array of long ints, reserve the appropriate
amount of space depending on _LP64. Provide macros to load/store signed
and unsigned long ints.

Also, make the `intrcnt' and `intrpending' arrays 16 entries long, as on
sparc/v9 interrupt #15 is just a regular interrupt.


# 1.81 19-Jul-2000 eeh

Fix merge problem.


# 1.80 19-Jul-2000 eeh

Disable interrupt interlock using ih->ih_pending field. Seems to cause
more problems than it solves.


# 1.79 19-Jul-2000 eeh

Miscellaneous cleanup.


# 1.78 18-Jul-2000 pk

Correct args usage comment in probeget.
Whitespace cleanup.


# 1.77 18-Jul-2000 pk

probeget: 9 -> 0x9


# 1.76 18-Jul-2000 pk

If `ih_pending' is set simply return from the trap, don't schedule another
soft interrupt.


Revision tags: mrg-merge-1-5-top
# 1.75 18-Jul-2000 pk

openfirmware: don't lower %pil


# 1.74 17-Jul-2000 pk

Kill typos in interrupt code.


# 1.73 17-Jul-2000 pk

probeget: do the same song and dance as ld*a() macros in ctlreg.h do.


# 1.72 14-Jul-2000 eeh

Move some macro definitions out of genassym and into locore.s


# 1.71 08-Jul-2000 mrg

backout part of previous: turn off intrdebug, and another debug message


# 1.70 07-Jul-2000 pk

Changes for readability:
- #define LP64 dependent STACKFRAME macro once
- use a LOAD_ASCIZ macro for setting up the format string
for debug messages.


# 1.69 07-Jul-2000 eeh

Temporary fix to prevent the clock from stopping on UIIi machines.


# 1.68 03-Jul-2000 eeh

Prevent interrupts from being posted if they are active and deprecate polled
interrupts. This seems to eliminate the spurious interrupts.


# 1.67 02-Jul-2000 eeh

Clean up interrupt handling some more.


# 1.66 30-Jun-2000 eeh

Fix interrupt delivery on UltraSPARC IIi machines.


# 1.65 24-Jun-2000 eeh

With these changes the kernel seems almost stable again.


# 1.64 24-Jun-2000 eeh

More VM cleanup:

Move the cpu_info structure above the interrupt stack so it won't
get corrupted if the stack overflows.

Flush the D$ before and after all MMU bypass accesses since the
D$ latches all of those.


# 1.63 23-Jun-2000 eeh

Make probeget() and probeset() really work for a change.


Revision tags: netbsd-1-5-base
# 1.62 19-Jun-2000 eeh

branches: 1.62.2;
Have separate data and text segments, make text read-only.


# 1.61 12-Jun-2000 eeh

Start reorganizing the kernel for MULTIPROCESSOR support.


# 1.60 31-May-2000 thorpej

Add a comment about needing to initialize p_cpu when multiple
processors are supported.


Revision tags: minoura-xpg4dl-base
# 1.59 26-May-2000 thorpej

branches: 1.59.2;
First sweep at scheduler state cleanup. Collect MI scheduler
state into global and per-CPU scheduler state:

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

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

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

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

Tested on i386 and Alpha. Changes are mostly mechanical, but apologies
in advance if it doesn't compile on a particular platform.


# 1.58 26-May-2000 thorpej

Don't set `runtime' here; it's done at the end of mi_switch().
cvS: ----------------------------------------------------------------------


# 1.57 26-May-2000 thorpej

Introduce a new process state distinct from SRUN called SONPROC
which indicates that the process is actually running on a
processor. Test against SONPROC as appropriate rather than
combinations of SRUN and curproc. Update all context switch code
to properly set SONPROC when the process becomes the current
process on the CPU.


# 1.56 22-Apr-2000 eeh

If we trap due to a bad kernel stack, try to switch to the interrupt strack
before breaking into the debugger.


# 1.55 18-Apr-2000 eeh

Prevent the system from getting watchdog reset by returning directly to user
mode if restoring the user window traps. Also reduce the time we run with
%tl>0.


# 1.54 13-Apr-2000 eeh

Apparently gas 2.9.5 (don't ask) does not like to add values to %lo()
directives so move the additions inside %lo() to make it happy.
Hopefully this won't break older versions.


# 1.53 10-Apr-2000 mrg

- fix a speeling error
- rename some numbered labels to be a bit less confusing.
- remove dead code
- fix a debug error message (argh!)


# 1.52 10-Apr-2000 pk

Get a kernel without DDB to build.


# 1.51 16-Mar-2000 eeh

Revamp interrupts again:

Fix a bug causing interrmittent panics in interrupt dispatch.
Use interrupt vectors for softints.
Add a new send_softint interface.
Improved D$ flushing.
Improve traptrace and other debugging enhancements.


Revision tags: chs-ubc2-newbase
# 1.50 16-Jan-2000 eeh

Interrupt handlers return zero if they didn't handle the interrupt.


# 1.49 10-Jan-2000 eeh

Add debugger single-stepping and fix interrupt dispatch bugs.


# 1.48 30-Dec-1999 eeh

Lots of changes:

remove ffs()
add bzero that uses block store insns
save %gsr to fpstate
revert to physical accesses for pmap_zero_page so we don't
have conflicting page mappings
general cleanup.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base fvdl-softdep-base
# 1.47 06-Nov-1999 eeh

Handle zero length properly in copyinstr() copyoutstr() and copystr().


Revision tags: comdex-fall-1999-base
# 1.46 11-Oct-1999 eeh

branches: 1.46.2; 1.46.4;
Update to post 1.4.


# 1.45 05-Oct-1999 eeh

branches: 1.45.2;
Make broken versions of gas happy by using sethi/or instead of set for
(negative) addresses.


# 1.44 17-Sep-1999 thorpej

Centralize the declaration and clearing of `cold'.


Revision tags: chs-ubc2-base
# 1.43 18-Jul-1999 eeh

More fun with pmap.


# 1.42 21-Jun-1999 eeh

Improve TRAPTRACE. Add FLTRACE that only tracks MMU faults.


# 1.41 05-Jun-1999 eeh

Make pbrobeget() and probeset() work for 64-bit values as well. To do this
the arguments are changed so the address is first and the ASI second so we
can have the address in %o0:%o1 and not worry about unused registers.

Also a bit of copyright cleanup.


# 1.40 05-Jun-1999 mrg

update a commit slightly.


# 1.39 30-May-1999 eeh

Add code to support using %tick as the system clock if no "counter-timer" node
is found.


# 1.38 09-May-1999 eeh

Fixup non-DEBUG kernels.


# 1.37 29-Apr-1999 christos

Add sunos_sigcode (32 bit only)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.36 26-Mar-1999 eeh

branches: 1.36.4;
COMPAT_SPARC32 -> COMPAT_NETBSD32


# 1.35 25-Mar-1999 mrg

clean and up make compile


# 1.34 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.33 22-Mar-1999 eeh

Need to set up the pointers properly for partial FPU register stores.


# 1.32 22-Mar-1999 eeh

Flush D$ on bypass accesses.


# 1.31 28-Feb-1999 eeh

Use block load/store in pmap_zero_page()/pmap_copy_page().


# 1.30 17-Feb-1999 eeh

Let's test out vectored interrupts.


# 1.29 15-Feb-1999 hubertf

RCS ID police


# 1.28 11-Feb-1999 mrg

fix a comment pasto.


# 1.27 11-Jan-1999 eeh

Finally fixed 64-bit signal trampoline.


# 1.26 10-Jan-1999 eeh

Handle the symbol table properly in a 32-bit kernel that was booted from a
64-bit bootloader.


# 1.25 09-Jan-1999 eeh

More signal fixup.


Revision tags: kenh-if-detach-base
# 1.24 26-Nov-1998 mycroft

Sync kcopy() with 32-bit SPARC version.


# 1.23 16-Nov-1998 eeh

Fixup the last broken bits of the signal handling code.


Revision tags: chs-ubc-base
# 1.22 08-Oct-1998 eeh

Fix more syscall32 and signal breakage.


# 1.21 22-Sep-1998 eeh

More fixup in the signal area.

64-bit syscall cleanup.

Add emulation for some new FPU insns: conversion to 64-bit long int and
conditional moves.


# 1.20 17-Sep-1998 thorpej

SYS_sigreturn -> SYS___sigreturn14.


# 1.19 13-Sep-1998 eeh

Fixup signal changes (hopefully). However SUN_COMPAT is likely broken by
this and I don't know how to fix it.

We can now exec a 64-bit init through a really ugly hack (don't ask.)


# 1.18 11-Sep-1998 eeh

Add labels for the compat_sparc32 signal trampoline and break -- er -- fix
suword and fuword.


# 1.17 09-Sep-1998 eeh

Don't use %tick for microtime on 32-bit kernels -- breaks gettimeofday.


# 1.16 09-Sep-1998 thorpej

Adjust for the new "reaper" kernel thread: do not free the vmspace and
u-area in machine-dependent code. Instead, call exit2() to schedule
the reaper to free them for us, once it is safe to do so (i.e. we are
no longer running on the dead proc's vmspace and stack).


# 1.15 07-Sep-1998 eeh

Fix data corruption problem caused by broken debug code.


# 1.14 07-Sep-1998 eeh

Add new 64-bit trap vectors.


# 1.13 06-Sep-1998 eeh

32-bit fixup.


# 1.12 06-Sep-1998 eeh

Disable some debug stuff.


# 1.11 05-Sep-1998 eeh

It slices. It dices. It does everything except exec a sparc32_compat init.


# 1.10 02-Sep-1998 eeh

Periodic update: now starts probing devices.


# 1.9 30-Aug-1998 eeh

Some more 64-bit cleanup. Now everything compiles.


# 1.8 29-Aug-1998 eeh

Some more 64-bit-ification.


# 1.7 27-Aug-1998 eeh

Add 64-bit pmap support:

Moved from a two level 512/1024 entry setup mapping 32 (9/10/13) bits
respectively to a three level 1024/1024/1024 entry setup mapping 43
(10/10/10/13) bits. In 32-bit mode we waste about 1/12 pages mapping the high
11 bits. We also only manage 43 of the possible 44 bits of virtual address
space, wasting half of it. Oh well, maybe we'll do better next revision.


Revision tags: PMAP32
# 1.6 26-Aug-1998 mrg

panicstack: is needed outside of DEBUG. use _C_LABEL, and printf not db_printf (incase no ddb!)


# 1.5 13-Aug-1998 eeh

Merge paddr_t changes into the main branch.


Revision tags: eeh-paddr_t-base
# 1.4 07-Jul-1998 eeh

branches: 1.4.2;
General update:

Added genassym.cf
Removed lderr which should never have gotten in
Removed lots of dead code from locore.s
Added some softint stuff to intr.c
Added support for halt -p
esp and le both use bus_dmamap_*() functions now
instead of kdvma_mapin()
groundwork for PCI (but we still have no drivers for
any sun4u PCI devices)


# 1.3 04-Jul-1998 jonathan

defopt DDB.


# 1.2 26-Jun-1998 thorpej

defopt COMPAT_SVR4


# 1.1 20-Jun-1998 eeh

branches: 1.1.1;
Initial revision


# 1.424 20-Dec-2020 palle

sun4v: add comment in sun4v_tl1_ptbl_miss code path - no functional change


Revision tags: thorpej-futex-base bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3 ad-namecache-base2 ad-namecache-base1
# 1.423 08-Jan-2020 skrll

oldlwp is always non-NULL in cpu_switchto so remove the test for NULL.


# 1.422 08-Jan-2020 ad

Hopefully fix some problems seen with MP support on non-x86, in particular
where curcpu() is defined as curlwp->l_cpu:

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

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

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

- Remove some KERNEL_LOCK handling which hasn't been needed for years.


Revision tags: netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 ad-namecache-base netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.421 18-Jul-2019 palle

branches: 1.421.4;
sun4v: added some missing comments to the code in pcbspill


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 1.420 07-Apr-2019 mrg

make trap 0x70 a TRAP() not UTRAP(). we should be able to handle
fast ECC error as a normal trap, and i saw this once a few years
ago but it never repeated so i haven't been able to test this.


# 1.419 08-Feb-2019 palle

sun4v: Improve comment for next_stick_init() - no functional changes


# 1.418 08-Feb-2019 palle

sun4v: initialize %stickcmpr properly when establishing interrupt - fixes issue seen on newer sun4v/SPARC-T5 system where the interrupt never fires.


# 1.417 08-Feb-2019 palle

sun4v: introduce macros for handling spill traps from userlevevel @ traplevel 1 (from OpenBSD) - spill traps at level 1 from userspace now works better


# 1.416 08-Feb-2019 palle

sun4v: add comment documenting the contents of the %g2 register - no functional changes


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126
# 1.415 04-Nov-2018 palle

Ensure that the 64-bit condition codes are used instead of the 32-bit condition codes. ok martin@


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.414 26-May-2018 palle

branches: 1.414.2;
next_stick() - fix typy in comment: tick->stick


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.413 11-Apr-2018 palle

sun4v: handle MMU-related traps properly when they occur at trap level 1. This fixes issues when user-level LWPs access the user-level stack


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 1.412 26-Aug-2017 palle

branches: 1.412.2;
sun4v: Avoid touching the %tick_cmpr register which is not present on never systems (Oracle SPARC Architecture 2011 and beyond). Based on code from OpenBSD locore.s revision 1.177. Tested on both sun4u (qemu and USIII) and sun4v (qemu and T5-2). ok martin@


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2
# 1.411 06-May-2017 palle

sun4v: The %ver register is not available on sun4v - use GET_MAXCWP introduced in rev. 1.361. Verified using qemu (sun4u and sun4v) and on real sun4v hw (t2000)


Revision tags: prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.410 18-Apr-2017 palle

branches: 1.410.2;
sun4v: Add handling of trap 0x06c @ trap level 1 - based on code from OpenBSD, but slightly adapted to NetBSD. verified using qemu


Revision tags: jdolecek-ncq-base pgoyette-localcount-20170320
# 1.409 19-Feb-2017 palle

sun4v: rft_user needs special handling (a manual fill) since the restore instruction may cause the number of trap levels to exceed the maximum for sun4v - inspired by code from the the openbsd rft_user code path - verified using qemu for both sun4u and sun4v


# 1.408 10-Feb-2017 palle

sun4v: Added handling of trap type 0x034 (address alignment error) + fixed typo mmfsa -> mmufsa. Verified for both sun4u and sun4v using qemu.


Revision tags: nick-nhusb-base-20170204
# 1.407 30-Jan-2017 palle

sun4v: Hook up syscall handling to the trap table. Verified using qemu for both sun4u and sun4v.


# 1.406 27-Jan-2017 palle

sun4v: implement missing handling of itsb traps 0x008 and 0x009. Based on code from OpenBSD. Tested using qemu.


Revision tags: bouyer-socketcan-base
# 1.405 07-Jan-2017 palle

branches: 1.405.2;
sun4v: slowtrap() now selects normal globals properly on both sun4u and sun4v platforms. Verified using qemu for both sun4u and sun4v systems


Revision tags: pgoyette-localcount-20170107
# 1.404 05-Jan-2017 palle

sun4v: TRAP_SETUP() updated to set mmu context id properly for both sun4v and sun4u platforms. Verified using qemu for both sun4u and sun4v systems


# 1.403 04-Jan-2017 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x00-0x23 and 0x28-0x30


# 1.402 29-Dec-2016 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x32-0x7f


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.401 20-Sep-2016 nakayama

Fix RAS for 32-bit kernels. trapframe is always 64-bit.


Revision tags: localcount-20160914
# 1.400 23-Aug-2016 palle

sun4v: rework sun4v_datatrap so it works properly when running on a T2-based system like T5120 - for some reason %tl is 0 when entering sun4v_datatrap causing a crash (sir instruction), so ignore the %tl value for now upon entry to sun4v_datatrap - with this fix both T1 and T2 based systems reach the same point - hangs in rft_user after the init process is started


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726
# 1.399 18-Jul-2016 palle

sun4v: handle device interrupts properly - both legacy (sysino) and cookies


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 1.398 04-Jun-2016 palle

branches: 1.398.2;
sun4v: rtf_user now uses macros GET_MMU_CONTEXTID and SET_MMU_CONTEXTID. Tested on sun4u (QEMU) and sun4v (T2000). Parts from OpenBSD.


Revision tags: nick-nhusb-base-20160529
# 1.397 18-May-2016 nakayama

Decrement %tl in trap handler not to make it zero unconditionally
for the nested trap, and remove useless mov.


# 1.396 17-May-2016 palle

sun4v: Implement missng MMU protection trap handling - mostly from OpenBSD


# 1.395 16-May-2016 palle

Avoid assembler-specific defines by using the export keyword in genassym.cf instead


# 1.394 15-May-2016 nakayama

%g1 is not preserved across function call, so load it before
return_from_trap.


# 1.393 13-May-2016 palle

sun4v: add missing implementation of sun4v_datatrap_tl0 so data_access_fault() is called - mostly from OpenBSD


# 1.392 13-May-2016 nakayama

- ci_paddr is always 64-bit.
- intrlev is array of pointer.
- ih_ack is pointer.


# 1.391 10-May-2016 palle

sun4v: make device interrupts work. Introduce a new intrhand_alloc() function for allocation of interrupt handlers and adapt to this. Parts from OpenBSD. ok martin@


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.390 09-Mar-2016 nakayama

32-bit kernels use 32-bit stack.


# 1.389 03-Mar-2016 palle

sun4v: rft_kernel should pay attention to the number of register windows that can be restored. We cannot rely on fill traps to occur, since sun4v only has two trap levels available in privileged mode. Based on code from OpenBSD. ok martin@


# 1.388 14-Feb-2016 palle

sun4v: add breakpoint trap entry to the sun4v trap table


# 1.387 03-Feb-2016 palle

sun4v: extend dmmu_set_secondary_context() to handle both sun4u and sun4v. ok martin@


Revision tags: nick-nhusb-base-20151226
# 1.386 06-Nov-2015 martin

Basically revert r1.246 of locore.s and r1.73 of vm_machdep.c:

Remove special case handling for userland lwps from cpu_lwp_fork,
instead do it in lwp_trampoline when we first return to userland.

which was a stupid idea - since we did now set all fork child's %tstate
(and thus %pstate when back in userland) to the current kernel's userland
default. This meant we lost the address mask bit for 32bit processes and
all memory model details for 64bit ones.

Move it back to cpu_lwp_fork and fix the condition to only do it once when
forking init.


# 1.385 05-Nov-2015 martin

Most of the time return_from_trap already got called with tf->tf_tstate
loaded in register %g1 - make it so for two more callers and remove
the reload of that value.


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606 nick-nhusb-base-20150406
# 1.384 05-Apr-2015 palle

sun4v: Ensure that the TTEs CP and CV bits are the same (both set) for the primary cpu and secondary cpus INTSTACK mappings


# 1.383 01-Apr-2015 palle

sun4v: Implement handling of cpu_mondo trap - from OpenBSD - tested using the Legion simulator


# 1.382 04-Mar-2015 palle

sun4v: revert some of the logic introduced in revision 1.378 - flushw is not necessary on sun4v (OpenBSD patches the flushw instruction to a nop instruction) - with these changes the kernel reaches cpu_boot_secondary_processors() when running in the Legion simulator (crashes due to missing handling of cpu_mondo_trap)


# 1.381 02-Mar-2015 nakayama

prom_printf converts "\n" to "\r\n" internally, so omit "\r".


# 1.380 02-Mar-2015 nakayama

PANICSTACK is a pointer itself, not a pointer to pointer.


# 1.379 02-Mar-2015 nakayama

Use panic stack temporarily for calling prom_printf in a trap
handler.

It seems that openfirmware cannot handle over 4GB pointers, and
stack pointers may point to over 4GB since VA layout was rearranged
by rev 1.33 of vmparam.h. Therefore, use panic stack to avoid
panicking in OF_write used by prom_printf.


# 1.378 23-Feb-2015 palle

sun4v: sparc_interupt - ensure that the trap level and globals level are the same when the flushw instruction is issued - othwise warnings occur when using the sun4v Legion simulator.


Revision tags: nick-nhusb-base
# 1.377 26-Oct-2014 palle

branches: 1.377.2;
sun4v: Create CLEANWIN0 and CLEANWIN1 macros for handling clean window traps on both sun4u and sun4u (based on the original code inlined in the sun4u trap table). Update trap tables accordingly for both sun4u and sun4v. Ok martin@


# 1.376 24-Oct-2014 nakayama

Fix typo in comment.


# 1.375 18-Oct-2014 snj

src is too big these days to tolerate superfluous apostrophes. It's
"its", people!


# 1.374 15-Oct-2014 palle

sun4v: fixed bug causing the real address to be incorrectly calculated as zero


# 1.373 24-Sep-2014 palle

sun4v: add code to enable startup of secondary cpus on both sun4u and sun4v systems - ok martin@


# 1.372 04-Sep-2014 palle

sun4v: All cpus must be setup with a TSB descriptor, so pmap_setup_tsb_sun4v() must take a pointer to the TSB descriptor


# 1.371 31-Aug-2014 palle

sun4v: Split the NORMAL_GLOBALS and ALTERNATE_GLOBALS macros to _SUN4U and _SUN4V variants. Rework the return_from_trap logic to use the new variants so it is possible to use a global register as scratch register.


# 1.370 14-Aug-2014 nakayama

Add missing delay slot in DEBUG kernel.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.369 30-Jul-2014 palle

branches: 1.369.2;
Fix ALTERNATE_GLOBALS so it at least works on sun4u - using a scratch register is not a good idea...


# 1.368 27-Jul-2014 palle

sun4v: Introduce a new macro ALTERNATE_GLOBALS (matching NORMAL_GLOBALS). Two new helper macros ENABLE_INTERRUPTS and DISABLE_INTERRUPTS are also created. With these changes the GENERIC.UP kernel will reach rootmount on sun4v systems - ok martin@


# 1.367 26-Jul-2014 palle

Improved the NORMAL_GLOBALS macro in the sun4u case, so only the relevant bit (AG) in %pstate is affected - ok martin@


# 1.366 24-Jul-2014 palle

sun4v: add missing spill/fill handling for trap level 1 + cosmetic changes to comments for trap level 0 entries


# 1.365 19-Jul-2014 palle

sun4v: Introduce a NORMAL_GLOBALS macro - first used in sparc_interrupt - other relevant uses will be handled as the sun4v work is progressesing - ok martin@


# 1.364 16-Jul-2014 palle

sun4v: Introduce SET_MMU_CONTEXTID macro for setting the mmu context id on both sun4u and sun4v


# 1.363 13-Jul-2014 palle

sun4v: add interrupt handling to sun4v trap table


# 1.362 13-Jul-2014 palle

Bugfix: add missing cmp instruction to GET_MAXCWP macro


# 1.361 30-Jun-2014 palle

sun4v: The maximum number of register windows is a constant and thus not available via the %ver register (sun4u only). Introduce a macro GET_MAXCWP that handles this, so cpu_switchto() works properly on sun4v. Other relevant reference to %ver can be adapted to use GET_MAXCWP as the sun4v port progresses. OK martin@


# 1.360 31-May-2014 palle

sun4v: added missing dtsb miss handling for trap level 1 - with this update the kernel now reaches configure() on sun4v systems


# 1.359 30-May-2014 palle

Remove debugging code introduced by accident in locore.s revision 1.357


Revision tags: yamt-pagecache-base9 rmind-smpnet-nbase rmind-smpnet-base
# 1.358 05-May-2014 palle

sun4v: the trap base address should be assigned to %l1 so %tba is properly setup later in the code - now the kernel gets as far as printing the copyright disclaimer, kernel version and total and available memory before crashing


# 1.357 21-Apr-2014 palle

sun4v: Update comment: modified -> access


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.356 21-Feb-2014 palle

branches: 1.356.2;
sun4v: Rename TLB_ defines to SUN4U_TLB_ so entries created using TSB_DATA() are properly setup for sun4u and sun4v. Relocate the cputyp variable from autoconf.c to locore.s and make it const in param.h so optimized code can be generated. Parts from OpenBSD. Optimization suggested by nakayama@. OK martin@, mrg@, nakayama@


# 1.355 31-Jan-2014 tsutsui

defined(LKM) -> defined(MODULAR)


# 1.354 26-Jan-2014 palle

sun4v: Add handling of spill/fill and dtsb miss traps (with a XXX to be handled later)


# 1.353 07-Jan-2014 palle

sun4v: trap table setup - currently populated with dummy entries which will be properly implemented later - parts from OpenBSD - OK martin@


# 1.352 29-Dec-2013 nakayama

Make buildable w/o options SUN4V.


# 1.351 27-Dec-2013 palle

a) make the hunt through the cpus list more generic b) sun4v: ensure that the interrupt stack is mapped permanently and the TSB is setup properly - parts from OpenBSD. OK martin@


# 1.350 06-Dec-2013 nakayama

Increase an interrupt depth only in the case of hardware interrupts,
and remove the ci_idepth trick in softint_fastintr.

Fixes the following diagnostic panic reported in port-sparc64.

panic: kernel diagnostic assertion "!cpu_intr_p()" failed: file
"../../../../kern/subr_xcall.c", line 351


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 1.349 24-May-2013 nakayama

branches: 1.349.2;
Disable interrupts after calling data_access_error as with
data_access_fault.


# 1.348 28-Apr-2013 nakayama

Use macros in machine/asm.h instead of locally defined, and
introduce CASPTRA for casxa/casa.


Revision tags: agc-symver-base
# 1.347 23-Jan-2013 martin

Fix sparc64_ipi_ccall by adding proper trap setup.
Fixes xcall(9) problems, as exposed by pserialize(9). Noticed by
J. Hannken-Illjes, cause pointed out by Takeshi Nakayama.


# 1.346 23-Jan-2013 martin

Sligthly clean up the (by default unused) #ifdef TRAPS_USE_IG


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.345 10-Nov-2012 nakayama

Revise comment.


# 1.344 10-Nov-2012 nakayama

Use macro instead of magic number.


# 1.343 09-Nov-2012 nakayama

Make setstick() and getstick() to inline functions.


# 1.342 08-Nov-2012 macallan

use system tick timer instead of %tick on UltraSPARC-III-ish CPUs
review & fixes by Takeshi Nakayama


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.341 17-Mar-2012 mrg

branches: 1.341.2;
port the corrected ECC error handling code from freebsd. i noticed my U10
took one of these and then hang. it shouldn't hang, there's a 'sir' here that
doesn't seem to reset properly. oh well.

tested by simulated a trap via 'ta 0x10' and considering that the same, but
it hasn't been tested against a real ECC error yet.


Revision tags: jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base4
# 1.340 03-Mar-2012 nakayama

Fix the root cause of the hack "disable optimizations for uvm_bio.c
on 32 bit kernels".

gcc converts a division in the calculation of UBC_UMAP_ADDR macro
to multiplication (smul or combination of add/sll), and the
register of its result contains a garbage in upper 32 bits (the
upper 32 bits of smul/add/sll's result isn't zero cleared).

Then it passes to pseg_get{,_real} through pmap_extract without the
zero clear of upper 32 bits in the optimization case. So the
result of pseg_get and pmap_extact sometimes gets screwed up.


Revision tags: jmcneill-usbmp-base5 jmcneill-usbmp-base3
# 1.339 19-Feb-2012 rmind

Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.


Revision tags: jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.338 04-Sep-2011 nakayama

branches: 1.338.2; 1.338.6; 1.338.8;
ih_pil is an interrupt level, not an interrupt mask.


# 1.337 27-Jul-2011 nakayama

ivec is assigned to hardware, so count its event counter up in
interrupt_vector, not in softint, and do some optimization.


# 1.336 20-Jul-2011 macallan

add per ivec event counters


# 1.335 12-Jul-2011 mrg

rename sparc64 BLOCK_SIZE and BLOCK_ALIGN to have SPARC64_ prefixes.
for the assembler files, define the old names to the new names
since using the new names cause ugliness due to longer identifer
names, and reduces churn.

fixes build issues in dtv and vaguely makes <machine/psl.h> slightly
less name-space invasive.


# 1.334 18-Jun-2011 nakayama

Add fast softint(9) support for sparc64.

Reviewed on port-sparc64.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 1.333 12-May-2011 mrg

branches: 1.333.2;
first steps towards fujitsu SPARC64 support:

- SPARC64 systems have interrupts with upto 14 bits set, but we only look
at the first 11 bits. trim non IPI interrupts to 11 bits


Revision tags: uebayasi-xip-base7 bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 jym-xensuspend-nbase jym-xensuspend-base
# 1.332 20-Dec-2010 matt

branches: 1.332.2;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.


Revision tags: uebayasi-xip-base6 uebayasi-xip-base5 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 1.331 10-Jul-2010 nakayama

Clear the upper word explicitly before combining two 32-bit values to 64-bit
on 32-bit kernels.


# 1.330 23-May-2010 martin

Split copy related functions out of locore.s into copy.S, move functions
only needed on multiprocessors into mp_subr.S.


# 1.329 17-May-2010 martin

Simplify primary CPU startup slightly by using the fact that our cpuinfo's
curpcb pointer points to the uarea/pcb of lwp0 and by remembering the pointer
to this cpuinfo, thus avoiding a few CPUINFO_VA references.


Revision tags: uebayasi-xip-base1
# 1.328 20-Mar-2010 chs

fix copy{in,out}{,str}() to return the error returned by uvm_fault().
fixes PR 41813.


Revision tags: yamt-nfs-mp-base9
# 1.327 10-Mar-2010 mrg

branches: 1.327.2;
XXX: workaround we'd like to remove when pmap / uvm locking is cleaned up:

- rename pseg_get() and pseg_set() to pseg_get_real() and pseg_set_real().
- if USE_LOCKSAFE_PSEG_GETSET is defined, which it current is by default,
define pseg_[gs]et() in terms of functions that take a new pseg_lock
mutex at IPL_VM while calling into the real functions.

this seems to avoid the pseg_set() crashes we've seen:
1 - spare needed, when pseg_get() just worked for this pmap
2 - the 2rd ldxa via ASI_PHYS_CACHED in pseg_set() loads garbage
into %o4, and causes the 3rd ldxa to fault


# 1.326 08-Mar-2010 mrg

blast_dcache() SMP friendly:

- blast_dcache() becomes sp_blast_dcache(dcache_size, dcache_line_size)
- new smp_blast_dcache(sparc64_cpuset_t) that blasts the D$ on this cpuset
- sparc64_ipi_blast_dcache() to support the above
- in pmap_remove_all(), when freeing mmu contexts for this pmap, mark
the set of cpus to blast the d$ on as well and convert the
blast_dcache() call into smp_blast_dcache() on the cpus who ran this
pmap, or, sp_blast_dcache(dcache_size, dcache_line_size)
- convert the remaining blast_dcache() in machdep.c to sp_blast_dcache()
- in pmap_destroy()/pmap_remove_all() take the pmap_lock() always since
we assert it is held always.

with these changes, NFS builds on the U60 seem to be stable now, and
the USIII machines also can often complete a single build.sh run now,
diskful or diskless.


reviewed by mlelstv and partially by martin, tested by martin and myself,
with some ideas from chuq as well.


# 1.325 07-Mar-2010 mrg

need _ALIGN in locore.h as well, for DEBUG kernels.


# 1.324 07-Mar-2010 mrg

gas has supported SPARC ".empty" for a long while; get rid of an
ancient workaround.


# 1.323 06-Mar-2010 mrg

move the memcpy/memset implementations out into their own file, with the
block copy versions as well. move some of the definitions in locore.s
into a new locore.h.

locore.s is almost 2000 lines shorter with this change.


# 1.322 04-Mar-2010 mrg

- in _bus_dmamap_unload(), pmap_page_protect() and pmap_clear_reference()
switch the dcache_flush_page() into a dcache_flush_page_all()
- in both pmap_kremove()/pmap_remove(), remove the blast_dcache() call
and replace it with dcache_flush_page_all()
- in pmap_get_page() [used to allocate PTP's], always call pmap_zero_page(pa)
- flush the dcache of the dst page in pmap_{copy,zero}_page() by redirecting
throught a C function that calls the (renamed) asm. the old asm code had a
comment about needing to do this...
- add a couple of membar #Sync's that the USIII manual recommends


based on discussions with chuq@, skrll@ and martin@.


these help my SB2000 / SB2500 with both disk / nfs builds and other tasks,
sometimes lasting for several hours before failing or asserting.


# 1.321 24-Feb-2010 mrg

when handing back page table pages to UVM, flush them from the dcache
on all CPUs.

idea from skrll@, and makes my disk-based SB2000 stable.

tested on U60, SB2000 and SB2500.


# 1.320 24-Feb-2010 mrg

- re-introduce sp_tlb_flush_pte() and sp_tlb_flush_all() that call
the right USI/USIII version.
- define tlb_flush_pte() in terms of sp_tlb_flush_pte() for the
!MULTIPROCESSOR case

this centralises some CPU_IS_USIII_UP() tests.


# 1.319 22-Feb-2010 mrg

move {dump,print}_[id]tlb() into a separate file.


# 1.318 22-Feb-2010 mrg

- store the maximum [id]cache size / line size for each cpu

- remove patch_kernel() since it isn't necessary and has been patching
the wrong thing in general.

- implement USIII versions of blast_icache(), dcache_flush_page() and
cache_flush_phys(). use the newly recorded cache size/line sizes.

- in winfixsave, flush the D$ with the right size index and ops. this
kills one of the wrong tag->inval patches.

- for blast_dcache(), use the newly recorded dcache_size/line_size.

- for blast_icache(), use the newly recorded cache size/line sizes.
for the USIII verison, disable the I$ while writing to ASI_ICACHE_TAG.


these changes removed several hard coded cache sizes values, some very
wrong kernel patching, and seem to make the current failure modes for
USIII less common, but not gone.


# 1.317 15-Feb-2010 mrg

- don't flush 32-bit entries for 64-bit code, it does not seem to be
necessary. #define TLB_FLUSH_LOWVA to turn it back on.
- remove the #if 0'd code in sparc64_ipi_flush_pte_usiii(), i have
verified that it is not required.
- add a missing membar #Sync to sp_tlb_flush_pte_usiii().


# 1.316 15-Feb-2010 nakayama

Fix linker error of GENERIC32 kernel.


# 1.315 15-Feb-2010 mrg

use TLB_SIZE_SPITFIRE in a couple of places, and note that the
{print,dump}_[id]tlb() versions are currently spitfire specific.


# 1.314 15-Feb-2010 mrg

introduce a new patch_kernel() and call it from the end of bootstrap().
use it to patch up TLB flush instructions that don't match for USI/II
and later. we can also hopefully use this to make GENERIC.MP minimally
expensive on single CPU machines as well.

this is the last piece needed to get GENERIC/GENERIC.MP to boot on the
USIII* machines.

idea and some initial code from openbsd.


# 1.313 13-Feb-2010 mrg

remove KTR support. it's never been a working part of netbsd src tree.


# 1.312 09-Feb-2010 wiz

Fix typo in comment.


Revision tags: uebayasi-xip-base
# 1.311 06-Feb-2010 mrg

branches: 1.311.2;
- properly map the schizo interrupt registers, so we can use the normal
virtual mappings to access them.
- with the above fxied, kill SCHIZO_BUS_SPACE_BROKEN, and introduce
an options CHEETAH for now, that disables the SPITFIRE code in locore.
- merge schizo_init() into schizo_attach() and clean up the softc a bit.


with this we are only one more step away from GENERIC booting on USIII
machines.


# 1.310 02-Feb-2010 mrg

- split sp_tlb_flush_pte() and switchtoctx() into sp_tlb_flush_pte_us()/
sp_tlb_flush_pte_usiii() and switchtoctx_us()/switchtoctx_usiii() and
implement the latter while i'm here. it works ... sometimes i think,
but also sometimes panics/hangs.
- fix a comment in sparc64_ipi_flush_pte_usiii()


# 1.309 02-Feb-2010 mrg

for now, reduce a few #ifdef SPITFIRE cases by introducing a new
ASI_DCACHE_TAG_OR_INV that is either ASI_DCACHE_{TAG,_INVALIDATE}.

increase the common code in cache_flush_phys().


# 1.308 01-Feb-2010 mrg

- sp_tlb_flush_all() becomes sp_tlb_flush_all_us() and sp_tlb_flush_all_usiii()
- sparc64_ipi_flush_pte() becomes sparc64_ipi_flush_pte_us() and
sparc64_ipi_flush_pte_usiii()
- add some commented out code to disable interrupts and raise the traplevel
in sparc64_ipi_flush_pte_usiii()
- cache_flush_phys() was missing a little of code in the cheetah case


# 1.307 01-Feb-2010 mrg

for USIII, use the new "tlb demap all" operation in sp_tlb_flush_all()


# 1.306 01-Feb-2010 mrg

remove unused icache_flush_page() implementation.


# 1.305 23-Jan-2010 mrg

remove the final uses of DATA_START.

now we can remove the 16KB space reserved at the start of the data segment,
and i now understand why i wrote this now removed comment 3.5 years ago:
"this shouldn't be needed... but kernel usually hangs without it"


# 1.304 23-Jan-2010 mrg

remove most of the code that writes debugging info DATA_START + offset.


# 1.303 23-Jan-2010 mrg

remove CHKPT() macro and uses. it's likely wrong in SMP land and probably should
be replaced with KTR-style uses if necessary.


# 1.302 23-Jan-2010 mrg

fix a comment.


Revision tags: matt-premerge-20091211
# 1.301 10-Dec-2009 rmind

Rename L_ADDR to L_PCB and amend some comments accordingly.


# 1.300 05-Dec-2009 mrg

- adjust the PA mask to the 43 bits supported by USIII.
- rework the spitfire/cheetah cache_flush_phys() to avoid several #ifdefs
- add a membar #Sync after sparc64_ipi_drop_fpstate (probably unnecessary)


# 1.299 30-Nov-2009 nakayama

sp_tlb_flush_pte for cheetah:
- restore interrupts properly in case of %tl > 0.


# 1.298 30-Nov-2009 mrg

stablize UP USIII support by blocking interrupts around sp_tlb_flush_pte()
i was seeing stack corruption while taking an interrupt in this function.

get USIII SMP mostly working by implementing the cheetah version of
sparc64_ipi_flush_pte().


SMP support is still not entirely stable. i can reproducably get a:

panic: fpusave_lwp ipi didn't

while running build.sh, when an awk process is exiting. other simple
heavy work loads do not crash for me right now.


# 1.297 30-Nov-2009 mrg

delete some no longer used code:
- smp_tlb_flush_ctx()
- smp_tlb_flush_all()
- sparc64_ipi_flush_ctx()
- sparc64_ipi_flush_all()
- sp_tlb_flush_ctx()


# 1.296 29-Nov-2009 nakayama

- calculate end PA correctly.
- wrap more spitfire specific (flushing I$) code.
- fix inverted #if condition for flushing I$ (and restore ASI_ICACHE_TAG).


# 1.295 28-Nov-2009 mrg

implement enough code to get SB2000/SB2500 booting to multiuser. does
not last long if you use it, but an idle machine has stayed up 10 hours.

- for the !SPITFIRE case, use ASI_DCACHE_INVALIDATE instead of
ASI_DCACHE_TAG when clearing tlb entries. from openbsd.

- convert some comment "! Not yet" into "WRITEME", so that attempting
to build a USIII MULTIPROCESSOR kernel fails to build until the code
is written.

- add some more WRITEME's for the above.

- implement a !SPITFIRE version of sp_tlb_flush_all(). since there are
no spare regs, for now just always increase %tl around this call. (we
could maybe store a token in %o3 along with the saved %pstate info.)


# 1.294 26-Nov-2009 matt

Kill proc0paddr. Use lwp0.l_addr instead.


# 1.293 25-Nov-2009 mrg

s/L_ADDR/L_PCB/, requested by rmind.


# 1.292 17-Oct-2009 nakayama

Wrap unused code with #if 0 which is called from #if 0'ed code.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5
# 1.291 30-May-2009 martin

cpu_setfunc() can not use lwp_trampoline, as that has additional lwp startup
semantics. Use a simpler setfunc_trampoline instead.


# 1.290 18-May-2009 nakayama

Remove random() from locore.s since it is in libkern.


# 1.289 16-May-2009 nakayama

Remove clear %tick in locore.s since it is cleared at cpu_initclocks() in
clock.c.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 nick-hppapmap-base mjf-devfs2-base
# 1.288 15-Dec-2008 mrg

restore some old "intrdebug" code, but leave it under NOT_DEBUG. most
of it works, but one that prints func/arg for each handler is not very
stable...

for now, while schizo bus space pointer accesses aren't working, add
a SCHIZO_BUS_SPACE_BROKEN option so you can build a kernel with schizo.

with this, and the prior schizo interrupt fix, you can now fail to run
/sbin/init!


Revision tags: haad-dm-base2 haad-nbase2 haad-dm-base
# 1.287 09-Dec-2008 martin

Get rid of get_maxctx() - it doesn't work on newer cpus and we will have
to find a better way for (some) sun4v machines - all sun4u use 13 bit
contexts anyway.


Revision tags: netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 ad-audiomp2-base netbsd-5-base
# 1.286 30-Oct-2008 nakayama

branches: 1.286.2; 1.286.6;
Wrap more code specific to USE_BLOCK_STORE_LOAD.


Revision tags: matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4
# 1.285 05-Oct-2008 nakayama

branches: 1.285.2;
- in flushing cache, use 32 as increment/decrement value to match the
cache line size.
- remove useless restore of %asi.
- remove nop in delay slot if we can.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 1.284 10-Jul-2008 nakayama

Use proper CCR.


# 1.283 10-Jul-2008 nakayama

sparc64_ipi_save_fpstate:
- use primary MMU context for consistency with other trap/interrupt handlers.

sparc64_ipi_save_fpstate, savefpstate:
- avoid storing fp registers as we can.

sparc64_ipi_save_fpstate, savefpstate, loadfpstate:
- remove unaligned case since buffers allocated with pool_cache are ensured
64-byte aligned.

Ok by martin@.


# 1.282 02-Jul-2008 nakayama

branches: 1.282.2;
UltraSPARCs don't have floating point queue, and reading %fq regsiter
will cause illegal instruction trap. So remove the code handling them.


# 1.281 29-Jun-2008 nakayama

Wrap IPI calls with #ifdef MULTIPROCESSOR.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.280 14-Jun-2008 nakayama

Close unterminated comment.
Fix unexpected behavior in case of loadfpstate from unaligned buffer.


Revision tags: yamt-pf42-base3
# 1.279 31-May-2008 nakayama

branches: 1.279.2;
openfirmware_exit:
- disable interrupts with %pstate.
- prepare 64-bit stack and enable 64-bit addresses for 32-bit SMP kernels.


Revision tags: hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 yamt-nfs-mp-base yamt-pf42-base
# 1.278 16-Apr-2008 nakayama

branches: 1.278.2; 1.278.4; 1.278.6;
Disable TRAPSTATS which was accidentally enabled when yamt-idlelwp branch
was merged.

Ok by martin@.


# 1.277 14-Apr-2008 nakayama

Remove sparc64_ipi_sync_tick.

Since we can use counter-timer as timecounter instead of %tick on SMP kernel,
it is not necessary to sync all CPUs %tick registers.


# 1.276 14-Apr-2008 nakayama

Add workaround for BB_ERRATA_1 on writing to TICK_CMPR register in
next_tick(). If writing to TICK_CMPR fails, we lose hardclock interrupt
on secondary CPUs.

About BB_ERRATA_1 from comment in OpenSolaris:

/*
* Writes to the TICK_COMPARE register sometimes fail on blackbird modules.
* The failure occurs only when the following instruction decodes to wr or
* wrpr. The workaround is to immediately follow writes to TICK_COMPARE
* with a read, thus stalling the pipe and keeping following instructions
* from causing data corruption. Aligning to a quadword will ensure these
* two instructions are not split due to i$ misses.
*/


# 1.275 28-Mar-2008 nakayama

Don't read fplwp content in delay slot for considering the case fplwp was
modifiled.

Reported by Chris Ross on port-sparc64.


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.274 20-Mar-2008 nakayama

- remove disabling interrupt in IPI.
- unused VA bits in MMU demap is 13 bits, not 12 bits.


# 1.273 18-Mar-2008 nakayama

Fix a race when increment an interrupt level event counter.


# 1.272 17-Mar-2008 nakayama

Fix a race condition in IPI handlers of save/drop fpstate, from OpenBSD.
Reported and tested by martin@.


# 1.271 17-Mar-2008 nakayama

Make schedintr interrupt handler per-CPU.
While there rename tickintr interrupt handler and share initialization
code with schedintr.


# 1.270 14-Mar-2008 nakayama

Improve IPI handling:
- make IPI takes two arguments.
- add IPI event counters per-CPU.
- implement IPI functions which were missing or broken.
- insert DELAY while halting primary CPU in IPI handler.


# 1.269 02-Mar-2008 nakayama

- make interrupt pending list per-CPU.
- make tickintr() MP-safe.
- remove unused port-sparc derived interrupt code.

Ok by martin@.


# 1.268 02-Mar-2008 nakayama

Don't get IPI handler argument (from bogus address), and ack IRQ twice.


# 1.267 28-Feb-2008 martin

Make TSBs and MMU contexts per-cpu.


Revision tags: nick-net80211-sync-base mjf-devfs-base hpcarm-cleanup-base
# 1.266 26-Jan-2008 nakayama

branches: 1.266.2; 1.266.6;
Fix for 32-bit kernels.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.265 15-Jan-2008 skrll

Store a sensbile PCB_PC value in snapshot - the return point.

This helps gdb somewhat.

OK'd by martin.


# 1.264 14-Jan-2008 martin

Fix register name typo/copy&pasto - %g6 is not %o6/%sp.
From OpenBSD.


Revision tags: matt-armv6-base
# 1.263 06-Jan-2008 martin

Load the next cpu_info pointer with LDPTR instead of ld.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2
# 1.262 09-Dec-2007 martin

branches: 1.262.2;
Provide cpu_intr_p(), at least for non-MULTIPROCESSOR kernels.
Based on suggestions by Andrew Doran.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.261 22-Oct-2007 martin

branches: 1.261.2; 1.261.4; 1.261.6;
Remove an unused .globl declaration


Revision tags: yamt-x86pmap-base4
# 1.260 17-Oct-2007 garbled

Merge the ppcoea-renovation branch to HEAD.

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

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

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base ppcoea-renovation-base vmlocking-base
# 1.259 09-Sep-2007 martin

branches: 1.259.4;
Make cpufrequency and friends per cpu values.
Prepare a hz tick interrupt on secondary CPUs via %tick, but do not
enable it yet, as it breaks ddb.


# 1.258 09-Sep-2007 martin

Do not ACK IPIs before we finished loading all arguments.


# 1.257 06-Sep-2007 martin

Remove the (now unused) second 64k page mapped per CPU.
From matthew green, with small changes by me. All bugs are mine.


# 1.256 25-Aug-2007 martin

branches: 1.256.2;
Remove INITSTACK completely - at the time we used to switch to it, we
already have access to all of lwp0 and it's uarea - so we can switch
to the correct lwp0 stack easily before calling main.


# 1.255 25-Aug-2007 martin

When exiting to OF, use the interrupt stack instead of INITSTACK


# 1.254 25-Aug-2007 martin

Rework cpu_mp_startup slightly:
- temporarily use the cpu's interrupt stack untill we are ready
to access non-OF-based mappings, then directly switch to the cpu's
idlelwp's uarea stack
- disable interrupts untill we are ready to call C code


# 1.253 13-Aug-2007 macallan

remove two restore without matching save


Revision tags: nick-csl-alignment-base matt-mips64-base mjf-ufs-trans-base
# 1.252 06-Jul-2007 martin

branches: 1.252.4; 1.252.8;
A few nits for 32bit SMP kernels, noticed by mrg.
While there, simplify the fpstate IPIs a bit.


# 1.251 05-Jul-2007 martin

sparc64_ipi_save_fpstate is not a leaf function - create a full grown
stack frame.


# 1.250 28-May-2007 mrg

clean up cpu_switchto() a little - no need to flushw or membar
excessively. optimise an rdpr. tested by tnn.


# 1.249 23-May-2007 martin

Fix a stupid bug in the save_fpstate ipi, which caused overwriting of
struct lwp of the lwp owning the fpu. Fix clearing the fplwp - %o0 will
not survive the call to savefpstate - duh!


# 1.248 20-May-2007 martin

Simplify tf_tstate setting when leaving for userland initially - I seem
to have confused the if with the else case of the previous C code.
Funny that it worked at all.


# 1.247 20-May-2007 martin

cpu_switchto() has to return it's first arg, always. This differs from
my reading of the documentation, but helps in the real world and seems
to be what other ports do.


# 1.246 20-May-2007 martin

Remove special case handling for userland lwps from cpu_lwp_fork, instead
do it in lwp_trampoline when we first return to userland.


# 1.245 19-May-2007 martin

cpu_idle is a leaf function, so we better "return from leaf".
Use return value from cpu_switchto for previous lwp in lwp_trampoline.
Also shamelessly steal a comment from uwe written for sparc that explains
all this.
Thanks to tnn, mrg, and uwe for helping to debug this.


# 1.244 17-May-2007 yamt

merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base ad-audiomp-base
# 1.243 22-Feb-2007 martin

branches: 1.243.4; 1.243.6; 1.243.12;
uvm.page_idle_zero now is a bool, not a 32bit value any more.


# 1.242 21-Feb-2007 mrg

shave 9 insns off the tsb setup in cpu_initialize & cpu_mp_startup.


# 1.241 21-Feb-2007 martin

Get rid of unused (thus always zero) "curlwp" variable hidden in assembler
code (C code always uses a cpuinfo based macro).


# 1.240 18-Feb-2007 martin

Make use of another call delay slot, pointed out by uwe.


# 1.239 18-Feb-2007 martin

Make use of a call delay slot and avoid a bogus EMPTY.
Spotted by Juergen Hannken-Illjes, with input from Andrew Doran and
Valeriy E. Ushakov.


# 1.238 18-Feb-2007 martin

Whitespace cosmetics


# 1.237 18-Feb-2007 martin

Backout previous: EMPTY was misused


# 1.236 18-Feb-2007 martin

Make EMPTY expand to nop with gas, as it is used to mark empty branch
delay slots.


# 1.235 15-Feb-2007 martin

branches: 1.235.2;
Fix obvious copy&pasto in SCHED_DEBUG register usage.


Revision tags: post-newlock2-merge
# 1.234 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.233 25-Dec-2006 wiz

Spell "relevant" correctly. From Zafer Aydogan.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.232 25-Oct-2006 mrg

branches: 1.232.2; 1.232.4;
- note that __idle_u should go away but doing so breaks things
- fix several comments to reality
- clean up the #ifdef NO_VCACHE code slightly
- use call instead of set/jmpl
- remove a couple of unnecessary stores to curlwp


Revision tags: yamt-splraiseipl-base2
# 1.231 18-Oct-2006 rjs

Clean up some comments. Cosmetic change to use correct structure
offset names.

Optimize out two instructions from sparc64_ipi_save_fpstate and
sparc64_ipi_drop_fpstate.


# 1.230 17-Oct-2006 mrg

allocate 128KB (as opposed to 64KB) per-cpu, and place the interrupt
stack, cpu_info structure, panicstack, idle uarea and normal kernel
stack in here. the idle uarea and kernel stack are in the 2nd 64KB
page. the interrupt stack and cpu_info structure are as the same
place in the 1st 64KB page, and the panicstack grows down from the
top of this page. update comments in param.h to suit (XXX: a lot
of these constants should move to a header file that will not pollute
the name space so much.) map these pages identically between
cpu_initialise() and cpu_mp_startup(), and deal with the two 64KB
pages in pmap_extract(). keep an unmapped 64KB page between them.

don't initialise the unused "ci_eintstack" member of the cpu_info
structure

use constants to initialise many addresses in the cpu_info structure,
consolidating these assignments from cpu0 and cpu>0

delete u0/estack0/panicstack from locore.s

clean up some wrong comments in locore.s

fix a 32bit-only bug in cpu_mp_startup().

delete 'u0' entirely.


this fixes recent random lossage seen on port-sparc64: processes
stuck in RUN state, data faults, and hangs.


# 1.229 04-Oct-2006 mrg

use call instead of set/jmpl. add an entry point for idle that expects
sched_lock to be unlocked, and use this for non-boot cpu's. complete a
comment describing how registers in idle_switch are expected to be set.


# 1.228 03-Oct-2006 mrg

use the same SAVE_LOCALS_INS definition for 32 bit and 64 bit kernels.
refactor TRAP_SETUP() a little between these two versions to be more alike.


# 1.227 03-Oct-2006 mrg

use the correct size/type for MP variables (pointers and longs).

a 32 bit MULTIPROCESSOR kernel now builds (and crashes quickly.)


# 1.226 03-Oct-2006 mrg

in the 64bit version of SAVE_LOCAL_INS, s/BIAS/STKB/ to allow future
sharing of the 32 and 64 bit versions of the {TRAP,INTR}_SETUP macros.


# 1.225 19-Sep-2006 mrg

- remove some way old FP setup/teardown code
- put the block memcpy/memset inside #ifdef USE_BLOCK_STORE_LOAD which
is (now) defined.

no functional change, same .o is generated.


# 1.224 19-Sep-2006 mrg

re-order the changes in rev 1.217 to give registers a little bit of
time to settle between usage, like it was before hand.


# 1.223 19-Sep-2006 mrg

- remove a wrong comment.
- add a new entry point for idle called idle_switch that is called by
cpu_switch() in the MP case when sched_whichqs is zero, properly
setting up the idle stack. from petrov@ via martin@.


# 1.222 19-Sep-2006 mrg

rework interrupt_vector() slightly:
- for the IPI case, avoid loading the address of intrlev into %g3
- remove some NOT_DEBUG code
- load the interrupt argument #2 in the delay slot

this removes 2 nops during interrupt processing for the normal
case, and an additional 2 ALU instructions for IPIs


# 1.221 18-Sep-2006 mrg

- sparc64_ipi_halt(): we shouldn't return from sparc64_ipi_halt_thiscpu()
so replace a branch with a 'sir'
- in #if 0 code, in sparc64_ipi_flush_pte() and sparc64_ipi_flush_ctx()
save/restore the out registers that the sp_tlb_flush_xxx() versions
around calling them
- in sp_tlb_flush_pte() and sp_tlb_flush_ctx(), replace global register
usage with out registers so that we don't clobber the (alternate)
global registers when these are called from IPI context


# 1.220 18-Sep-2006 mrg

- remove an extra 'sir' that followed one in a macro
- add some named labels to some spill/fill handlers
- remove 2 unused strings


Revision tags: yamt-splraiseipl-base
# 1.219 18-Sep-2006 martin

branches: 1.219.2;
Lazy FPU handling for the MULTIPROCESSOR case


# 1.218 16-Sep-2006 nakayama

From OpenBSD:
- reload %fprs for checking it again.
- use symbolic names for checking in %fprs.

revision 1.51
date: 2005/07/18 14:50:11; author: deraadt; state: Exp; lines: +2 -1
cache a copy of the fprs so we know what fp restore we should do after

revision 1.50
date: 2005/07/14 01:46:13; author: deraadt; state: Exp; lines: +4 -4
use symbolic names for checking in %fprs, as above


# 1.217 16-Sep-2006 nakayama

Fix a couple of %y register save/restore errors, inspired from OpenBSD.

revision 1.44
date: 2004/04/23 04:18:17; author: marc; state: Exp; lines: +5 -4

fix a couple of %y register save/restore errors
1) don't save %y in a register that is later used before restoring %y
2) always restore %y after calling a signal handler
tested by drahn@, OK pval


# 1.216 15-Sep-2006 martin

Do not bother to save fpu state when we are about to get rid of it.


Revision tags: yamt-pdpolicy-base9
# 1.215 13-Sep-2006 mrg

SMP cleanup. provide support for multiple CPUs in DDB. (SMP itself
is still not working.)

cpu.h:
- add a pointer for DDB regs in SMP environment to struct cpu_info
- remove the #defines for mp_pause_cpus() and mp_resume_cpus()
cpuset.h:
- remove CPUSET_ALL() and rename CPUSET_ALL_BUT() to CPUSET_EXCEPT()
from petrov.
db_machdep.h:
- rename the members of db_regs_t to be the same as sparc
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- redo DDB_REGS to no longer be a pointer to a fixed data structure
but to one allocated per-cpu when ddb is entered
- move a bunch of prototypes in here
intr.h:
- remove SPARC64_IPI_* macros, no longer used
db_interface.c:
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- make "nil" a 64 bit entity
- change the ddb register access methods to work in multiprocessor
environment, it is now very much like sparc does it
- in kdb_trap() avoid accessing ddb_regp when it is NULL
- update several messages to include the cpu number
- unpause other cpus much later when resuming from ddb
- rename db_lock() to db_lock_cmd(), as the sparc-like code has
db_lock as a simple lock
- remove "mach cpus" command, and replace it with "mach cpu" (which
does the same) and also implement "mach cpu N" to switch to
another cpus saved trapframe
db_trace.c:
- update for the ddb_regs -> ddb_regp change
genassym.cf:
- add TF_KSTACK as offsetof(struct trapframe64, tf_kstack)
ipifuncs.c:
- overhaul extensively
- remove all normal interrupt handlers as IPI's, we now handle
them all specially in locore.s:interrupt_vector
- add a simplelock around all ipi functions - it's not safe for
multiple cpus to be sending IPI's to each other right now
- rename sparc64_ipi_pause() to sparc64_ipi_pause_thiscpu() and,
if DDB is configured, enable it to save the passed-in trapframe
to a db_regs_t for this cpu's saved DDB registers.
- remove the "ipimask" system (SPARC64_IPI_* macros) and instead
pass functions directly
- in sparc64_send_ipi() always set the interrupt arguments to 0,
the address and argument of the to be called function. (the
argument right now is the address of ipi_tlb_args variable, and
part of the reason why only one CPU can send IPI's at a time.)
don't wait forever for an IPI to complete. some of this is
from petrov.
- rename sparc64_ipi_{halt,pause,resume}_cpus() to
mp_{halt,pause,resume}_cpus()
- new function mp_cpu_is_paused() used to avoid access missing
saved DDB registers
- actually broadcast the flush in smp_tlb_flush_pte(),
smp_tlb_flush_ctx() and smp_tlb_flush_all(). the other end may
not do anything yet in the pte/ctx cases yet...
kgdb_machdep.c:
- rework for changed member names in db_regs_t.
locore.s:
- shave an instruction from syscall_setup() (set + ld -> sethi + ld)
- remove some old dead debug code
- add new sparc64_ipi_halt IPI entry point, it just calls the C
vector to shutdown.
- add new sparc64_ipi_pause IPI entry point, which just traps into
the debugger using the normal breakpoint trap. these cpus usually
lose the race in db_interface.c:db_suspend_others() and end up
calling the C vector sparc64_ipi_pause_thiscpu().
- add #if 0'ed code to sparc64_ipi_flush_{pte,ctx}() IPI entry
points to call the sp_ version of these functions.
- in rft_kernel (return from trap, kernel), check to see if the
%tpc is at the sparc64_ipi_pause_trap_point and if so, call
"done" not "retry"
- rework cpu_switch slightly: save the passed-in lwp instead of
using the one in curlwp
- in cpu_loadproc(), save the new lwp not the old lwp, to curlwp
- in cpu_initialize(), set %tl to zero as well. from petrov.
- in cpu_exit(), fix a load register confusion. from petrov.
- change some "set" in delay branch to "mov".
machdep.c:
- deal with function renames
pmap.c:
- remove a spurious space
trap.c:
- remove unused "trapstats" variable
- add cpu number to a couple of messages


# 1.214 09-Sep-2006 mrg

significant clean up effort, largely from petrov@ via martin@.

- fix a bunch of comments for proc->lwp
- remove old TRAPTRACE, NOT_DEBUG, etc. code that has bit-rotted
- put some older DEBUG code under NOT_DEBUG
- add a bunch of new debugging/tracing code ("KTR") that depends on
other changes not yet present.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base yamt-pdpolicy-base5 chap-midi-base simonb-timecounters-base rpaulo-netinet-merge-pcb-base
# 1.213 14-May-2006 elad

branches: 1.213.6; 1.213.8;
integrate kauth.


# 1.212 12-May-2006 skrll

Fix some comments.


Revision tags: elad-kernelauth-base
# 1.211 09-May-2006 rjs

Load CPCB in cpu_mp_startup.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.210 11-Feb-2006 cdi

branches: 1.210.2; 1.210.4; 1.210.6;
ANSIfication: u_intN_t -> uintN_t, use ANSI function declarations/definitions
instead of K&R ones.


# 1.209 27-Jan-2006 cdi

branches: 1.209.2; 1.209.4;
Alter sparc64 bootstrap, catch up to ofwboot v1.9:

- Accept bootinfo structure passed down from ofwboot v1.9
- Drop kernel re-mapping code
- Use permanent 4MB mappings provided by the loader instead
- Change kernel entry address to point directly at the code instead of pointing
at the trap table's first slot. This allows the bootloader to detect
those kernels which are aware of the new boot scheme
- Due to the changes in kernel mapping code, alter secondary CPU bootstrap
code to use trampoline just like FreeBSD does (some FreeBSD code is used
here as well)


# 1.208 12-Jan-2006 cdi

Fix a typo: %g0 should be used instead of %o0 when initializing FPU in dostart:
and cpu_mp_startup:, %o0 is not even initialized at this point.


# 1.207 11-Dec-2005 christos

branches: 1.207.2;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 1.206 10-Jul-2005 christos

Re-factor syscall, and make it use syscall_{plain,fancy}.


# 1.205 31-May-2005 chs

branches: 1.205.2;
remove vestigal {,e}intr{names,cnt} symbols now that vmstat doesn't need them.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.204 12-Feb-2005 chs

branches: 1.204.4; 1.204.6; 1.204.8;
in sparc_interrupt(), wait to enable interrupts until just before calling
the handler and disable them again right after the handler returns.
we don't want another hardware interrupt coming in while we're mucking
with the list pointers. also, clear the intrhand's ih_pending pointer
before calling the handler rather than after, so that if another interrupt
comes in while the handler is running, we can put the intrhand back on
the list so it will be called again.

in send_softint(), disable interrupts via %pstate instead of %pil, so that
hardware interrupts at higher levels are blocked while we manipulate the
intrpending list. also, if the intrhand already has ih_pending set,
don't bother poking the SET_SOFTINT register again, since being on the list
implies that there is already a softint pending in the hardware.

these appear to fix PR 21750 (the "sleep forever" problem).

while I'm here, remove more vestiges of the !INTRLIST softint stuff
(code and comments). and in sparc64_ipi_flush_all(), interrupts are
already disabled so we don't need to fiddle with %pstate.


Revision tags: yamt-km-base2
# 1.203 30-Jan-2005 martin

Remove the no long usefull variants selected by undefining INTRLIST and
INTR_INTERLOCK to improve readability. Same object code generated as before.


Revision tags: yamt-km-base
# 1.202 16-Jan-2005 chs

branches: 1.202.2;
use ENTRY_NOPROFILE() for various entry points,
stack traces work better that way.


Revision tags: kent-audio1-beforemerge kent-audio1-base
# 1.201 03-Dec-2004 chs

branches: 1.201.4;
remove cache_flush_virt() and PADDRT, they're no longer used.
allocate a stack frame for blast_dcache() when profiling so it shows up.
in dcache_flush_page(), use a stride of 32 instead of 16 to match the
cache line size. correct various comments.


# 1.200 08-Nov-2004 petrov

Don't compile sparc64_ipi functions when UP.


# 1.199 25-Oct-2004 martin

No need to clear %o1 when returning a 64 bit integer from pseg_get if we
are compiling for a 64 bit kernel.


# 1.198 24-Jul-2004 nakayama

Change interrupt pending list end value to -1, to avoid linking an
interrupt handler twice.

It may fix "sleep forever" bug.


# 1.197 09-Apr-2004 petrov

Clean-up unused defines and variables.


Revision tags: netbsd-2-0-base
# 1.196 26-Mar-2004 petrov

branches: 1.196.2;
Use want_resched from cpu_info area.


# 1.195 23-Mar-2004 martin

Replace intrcnts by evcnts. XXX - needs slight tweaking for MULTIPROCESSOR.


# 1.194 14-Mar-2004 chs

checkpoint of MP work from dennis and myself. includes cross-processor
interrupt framework, a sledgehammer TLB invalidation and misc MP fixes.
doesn't work at all yet.


# 1.193 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.192 19-Jan-2004 martin

Rename switchexit to cpu_exit and g/c the old C implementation of cpu_exit.


# 1.191 18-Jan-2004 martin

Support RAS for 32bit kernels too.


# 1.190 16-Jan-2004 martin

In proc_trampoline don't bother to clear condition codes in the trap
frame, since we no longer rely on this.
While there fix a few comments.


# 1.189 08-Jan-2004 martin

Minor cleanup


# 1.188 06-Jan-2004 martin

Implement restartable atomic sequences (RAS) for sparc64.


# 1.187 06-Jan-2004 petrov

Spinup secondary cpus. Based on codes sent to me by Dennis Chernoivanov
and Chuck Silvers.


# 1.186 04-Jan-2004 jdolecek

update to recent changes - exit2() doesn't exist anymore and the
exit path always calls lwp_exit2()
pointed out Martin Husemann


# 1.185 02-Dec-2003 martin

Minor cleanup: remove unused code, sync a comment with current reality.


# 1.184 25-Nov-2003 cdi

Use per-cpu pcb, curlwp and fplwp rather than global ones. This brings
GENERIC.MP configuration to a usable state.

Approved by petrov@.


# 1.183 24-Nov-2003 cdi

Call 'proc_trampoline_mp' from 'proc_trampoline' in a multiprocessor
configuration. Fix process locking. Approved by petrov@.


# 1.182 20-Nov-2003 petrov

Remove nwindows calculation, it's not used. Set l_cpu in cpu_switch.


# 1.181 09-Nov-2003 martin

Get rid of bcopy/bzero.


# 1.180 26-Oct-2003 christos

Initial siginfo support for sparc64 (untested). COMPAT_16 sigcontext signal
delivery tested.


# 1.179 24-Aug-2003 chs

add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default. the changes
fall into two basic catagories:

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

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

originally from openbsd, adapted for netbsd by me.


# 1.178 08-Jul-2003 cdi

traceit: don't use %g7 as it is to become curcpu() register. Add comments.


# 1.177 18-May-2003 martin

branches: 1.177.2;
Make kernels with options KGDB at least compile.
Still needs some work to make it working.


# 1.176 29-Apr-2003 nakayama

Use BLOCK_ALIGN rather than BLOCK_SIZE for aligning a pointer.


# 1.175 27-Apr-2003 ragge

Preserve the symbol table in the LKM || KSYMS cases also.


# 1.174 04-Apr-2003 petrov

use branch slot in pmap_copy_page.


# 1.173 24-Mar-2003 nakayama

Divide `set' instruction in delay slot (from OpenBSD change to rev 1.30).


# 1.172 10-Feb-2003 martin

Remove some #if 0 code and a few XXX marked membars w/o proper
justification for their existence.


# 1.171 09-Feb-2003 martin

Remove left over pieces from reusing the signal trampoline for upcalls.
This should fix signal delivery for 32bit kernels.


# 1.170 05-Feb-2003 nakayama

Switch to use cycle counter (%tick) based microtime().

This is derived from alpha/microtime.c and i386/tsc_microtime.c,
and will share with both ports.

This should fix PR port-sparc64/18452.
(approved by martin)


# 1.169 04-Feb-2003 martin

Fix return value of pseg_set, which I accidently broke in rev. 1.164.

Fix register names in comment and shave off another register (hint
from uwe).


# 1.168 01-Feb-2003 martin

Rearrange register usage in pseg_set a bit and shave off %g4.


# 1.167 01-Feb-2003 martin

Remove a few #ifdef _LP64 by using STPTR/LDPTR macros.
Thanks to Matthew Green for the pointer.


# 1.166 31-Jan-2003 martin

Apply leaf procedure optimization to pseg_set (again).


# 1.165 31-Jan-2003 martin

Make the pmap count resident/wired mappings on the fly instead of
walking the page tables whenever this information is needed.

Add an option PMAP_COUNT_DEBUG to assert the new counts and the
page table walk agree.

The old solution had very bad performance impact, for example
by the high CPU load when running top(1).

Thanks to Simon Burge for pointing at the cause of the problem and
to Valeriy E. Ushakov for optimizing my simple minded assembler code.


# 1.164 27-Jan-2003 martin

Remove unused function pseg_find (which looked quite similar to
pseg_get anyway).


# 1.163 18-Jan-2003 thorpej

Merge the nathanw_sa branch.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.162 16-Jan-2003 petrov

Move dump_dtlb back under DDB.


# 1.161 15-Jan-2003 chs

fix two bugs in my last pmap rework:
- in tlb_flush_all(), don't skip TLB entries with the high bit on,
I was confused about which MMU register it was using. it's also fine
to use the last hardware context.
- in pmap_create(), don't allocate a hardware context for the new pmap.
it's unnecessary, and when this would cause us to recycle all the contexts,
it would result in the current process's context being set to 0
(ie. the kernel's context). the current process could then return to
userspace without going through the context-switch code (and thus without
having a hardware context reallocated). this would lead to user mappings
being entered in the kernel's context later, causing all sorts of trouble.
add some assertions to catch this kind of thing.


Revision tags: fvdl_fs64_base
# 1.160 25-Dec-2002 petrov

new function dump_itlb.


Revision tags: gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.159 22-Sep-2002 chs

many improvements:
- use struct vm_page_md for attaching pv entries to struct vm_page
- change pseg_set()'s return value to indicate whether the spare page
was used as an L2 or L3 PTP.
- use a pool for pv entries instead of malloc().
- put PTPs on a list attached to the pmap so we can free them
more efficiently (by just walking the list) in pmap_destroy().
- use the new pmap_remove_all() interface to avoid flushing the cache and TLB
for each pmap_remove() that's done as we are tearing down an address space.
- in pmap_enter(), handle replacing an existing mapping more efficiently
than just calling pmap_remove() on it. also, skip flushing the
TSB and TLB if there was no previous mapping, since there can't be
anything we need to flush. also, preload the TSB if we're pre-setting
the mod/ref bits.
- allocate hardware contexts like the MIPS pmap:
allocate them all sequentially without reuse, then once we run out
just invalidate all user TLB entries and flush the entire L1 dcache.
- fix pmap_extract() for the case where the va is not page-aligned and
nothing is mapped there.
- fix calculation of TSB size. it was comparing physmem (which is
in units of pages) to constants that only make sense if they are
in units of bytes.
- avoid sleeping in pmap_enter(), instead let the caller do it.
- use pmap_kenter_pa() instead of pmap_enter() where appropriate.
- remove code to handle impossible cases in various functions.
- tweak asm code to pipeline a little better.
- remove many unnecessary spls and membars.
- lots of code cleanup.
- no doubt other stuff that I've forgotten.

the result of all this is that a fork+exit microbenchmark is 34% faster
and a fork+exec+exit microbenchmark is 28% faster.


Revision tags: gehenna-devsw-base
# 1.158 18-Jul-2002 wiz

Spell 'should' correctly.


# 1.157 07-Jun-2002 eeh

Shave 10% off the time needed to flush the D$ through a bit of instruction
reordering.


# 1.156 05-Jun-2002 eeh

Handle improperly aligned stack pointers more cleanly.


# 1.155 04-Jun-2002 eeh

Fix the fork trampoline to properly use the supplied tstate.


# 1.154 31-May-2002 thorpej

Make this work with an ISO C preprocessor.


Revision tags: netbsd-1-6-base
# 1.153 14-May-2002 eeh

branches: 1.153.2; 1.153.4;
Only save locals and ins in trapframes for DEBUG kernels.


# 1.152 04-May-2002 kleink

Add some comments to the CPP conditionals controlling the trap macro
definitions, to ease navigation somewhat.


# 1.151 16-Apr-2002 eeh

Make lots of routines profile-friendly and get rid of some cruft.


Revision tags: eeh-devprop-base
# 1.150 21-Mar-2002 petrov

Not needed debug stuff deleted.


# 1.149 16-Mar-2002 mrg

tell newer binutils that our use of %g2 and %g3 is OK here.


# 1.148 15-Mar-2002 eeh

Cleanup MMU initialization to prevent hangs.


Revision tags: newlock-base ifpoll-base
# 1.147 09-Feb-2002 eeh

branches: 1.147.4;
Fix microsecond calculation in microtime.


# 1.146 07-Feb-2002 eeh

Fix register allocation in microtime().


# 1.145 29-Jan-2002 eeh

Shift the UPAID in the correct direction.


# 1.144 17-Jan-2002 eeh

Be more tolerant of unaligned stack pointers.


# 1.143 17-Jan-2002 eeh

Enable block insns in bcopy and bzero.


# 1.142 16-Jan-2002 eeh

In bcopy use 32-bit comparisons in 32-bit kernels.


# 1.141 16-Jan-2002 eeh

Use correct calculation for the trapframe in softtrap for ILP32.


# 1.140 20-Nov-2001 lukem

- pull in opt_kgdb.h where necessary
- replace opt_kgdb_machdep.h with opt_kgdb.h
- defparam opt_kgdb.h:
KGDB_DEV KGDB_DEVNAME KGDB_DEVADDR KGDB_DEVRATE KGDB_DEVMODE
- move from opt_ddbparam.h to opt_ddb.h:
DDB_FROMCONSOLE DDB_ONPANIC DDB_HISTORY_SIZE DDB_BREAK_CHAR SYMTAB_SPACE
- replace KGDBDEV with KGDB_DEV
- replace KGDBADDR with KGDB_DEVADDR
- replace KGDBMODE with KGDB_DEVMODE
- replace KGDBRATE with KGDB_DEVRATE
- use `9600' instead of `0x2580' for 9600 baud rate
- use correct quotes for options KGDB_DEVNAME="\"com\""
- use correct quotes for options KGDB_DEV="17*256+0"
- remove unnecessary dependancy on Makefile for kgdb_stub.o
- minor whitespace cleanup


Revision tags: thorpej-mips-cache-base thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf
# 1.139 14-Sep-2001 thorpej

branches: 1.139.4;
Don't declare intrhand[] here -- that's taken care of in intr.c.


Revision tags: thorpej-devvp-base
# 1.138 30-Aug-2001 eeh

branches: 1.138.2;
Preliminary UltraSPARC III suport (not enabled yet).


# 1.137 13-Aug-2001 jdolecek

g/c _remque()/_insque(); use the C version in libkern


# 1.136 09-Aug-2001 eeh

Fix context masking lossage caused by last version.


# 1.135 08-Aug-2001 eeh

Clean up the trap code to handle the changes cause by supporting non-faulting
accesses. Also change the parameter order so trap frames are easy to find.


# 1.134 07-Aug-2001 eeh

Make sure C code always has ASI_PRIMARY_NOFAULT in the %asi register so
the compiler will be happy if it ever starts generating speculative loads.


# 1.133 05-Aug-2001 eeh

Add support for non-faulting loads and optimize MMU miss handling paths.


# 1.132 02-Aug-2001 eeh

Fix bcopy.


# 1.131 02-Aug-2001 eeh

Sync bzero w/libc version.


# 1.130 01-Aug-2001 eeh

Integrate fixes from userland memset.


# 1.129 31-Jul-2001 eeh

Code cleanup and optimization.


# 1.128 23-Jul-2001 eeh

Get rid of some debug code that really isn't all that useful any more.


# 1.127 19-Jul-2001 eeh

Do ignore unregistered interrupts instead of faulting.


# 1.126 16-Jul-2001 eeh

Make bcopy a 32-bit friendly.


# 1.125 11-Jul-2001 eeh

Fix problems booting 32-bit kernels and dispatching level-15 interrupts.


# 1.124 08-Jul-2001 eeh

branches: 1.124.2;
Code cleanup. Add block_disable to let you turn on block set/copy routines.


# 1.123 05-Jul-2001 eeh

New block bzero and bcopy.


# 1.122 04-Jul-2001 eeh

Replace old bcopy with a much faster version.


# 1.121 01-Jul-2001 martin

Disable axidently enabled debug code to make -current compile again.


# 1.120 30-Jun-2001 eeh

Use a newer version (still disabled) of block bcopy.


# 1.119 30-Jun-2001 eeh

Fixup fpu save restore, get rid of some unused copy functions, and add
a new bcopy.


# 1.118 21-Jun-2001 eeh

Allow multiple 4MB pages for both kernel text and kernel data.

Note: DEBUG checks will not allow accesses to the hole between
text and data segments, so you may need to update programs that
use libkvm before relocating the start of kernel data.


# 1.117 06-Jun-2001 mrg

extract the netbsd32, sunos, 32 bit svr4 and 64 bit svr4 sigcode out into
separate files, so that compat lkms can link with them as well.


# 1.116 30-May-2001 lukem

add missing #include "opt_kgdb.h"


Revision tags: thorpej_scsipi_beforemerge
# 1.115 25-Apr-2001 simonb

Spell occurred correctly.


Revision tags: thorpej_scsipi_nbase thorpej_scsipi_base
# 1.114 09-Apr-2001 eeh

Interrupt latency fix from sparc port. (Hm. One insn instead of 5).


# 1.113 07-Mar-2001 eeh

Fix inverted preprocessor logic. (Spotted by Charles.)


# 1.112 21-Feb-2001 eeh

branches: 1.112.2;
Add support for 64-bit SVR4 (Solaris 8) binaries.


# 1.111 10-Feb-2001 pk

Fix conditional for svr4 compat inclusion.


# 1.110 05-Feb-2001 eeh

Add signal trampoline for 64-bit svr4 emulations.


# 1.109 31-Dec-2000 eeh

Make INCR() atomic.


# 1.108 29-Dec-2000 eeh

pseg_get tells us whether it really needed that spare page after all.


# 1.107 07-Dec-2000 eeh

Fixup calculating where fpstate should be saved in the signal trampoline
code so it doesn't overwrite something important like the registers.


# 1.106 09-Nov-2000 eeh

Fix ILP32 bug in probe_get().


# 1.105 22-Oct-2000 pk

Restore revision 1.102.

I hope it sticks this time..


# 1.104 20-Oct-2000 eeh

Fix hang in 32-bit kernels caused by relocation of KERNBASE.


# 1.103 04-Oct-2000 eeh

Fix interrupt lossage problem and some cosmetic changes.


# 1.102 01-Oct-2000 pk

cpu_initialize: global registers aren't preserved across calls to
prom_printf(), so replace %g3 with %l7 (which isn't used despite
the `usage' comment).

Also, clean up white-space turds.


# 1.101 29-Sep-2000 eeh

This seems to fix the interrupt lossage of non-debug kernels.


# 1.100 28-Sep-2000 eeh

Fix INTR_SETUP() to properly distinguish kernel and user addresses.

Make microtime() return the correct time on %tick machines.

Re-enable debug stuff in dostart for now to detect kernel mapping issues.


# 1.99 25-Sep-2000 pk

Missing `#if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)'


# 1.98 17-Sep-2000 eeh

Make the improved %tick changes work with machines that use the counter-timer
for the clock.


# 1.97 12-Sep-2000 eeh

Fix new version of microtime.


# 1.96 11-Sep-2000 eeh

(Hopefully) fix clock skew on machines that us %tick for the clock (UIIi).


# 1.95 31-Aug-2000 eeh

Use casx instead of stx to change entries in the page table trees.


# 1.94 23-Aug-2000 eeh

Update the scheduler to the new locking scheme.


# 1.93 10-Aug-2000 eeh

Fix signal delivery.


# 1.92 02-Aug-2000 eeh

Get kernel profiling to work. Now if only gprof worked....


# 1.91 01-Aug-2000 eeh

Overhaul cache flush code and coredump code.


# 1.90 25-Jul-2000 pk

Re-instate a couple of delay slot NOPs marked `XXX spitfire bug?'


# 1.89 24-Jul-2000 mycroft

Optimization to pmap_zero_page(): we only need to use the first 16 FP regs,
as in bzero().


# 1.88 24-Jul-2000 mycroft

Fix a whitespace glitch.


# 1.87 24-Jul-2000 mycroft

Pull in the bzero() changes from libc for real, with a couple of kernel-
specific hacks:
* Make the bias handling depend on STKB, so it switches correctly for 32-bit
kernels.
* Use the 32-bit stw/ld for 32-bit kernels.
* Add a few `-STKB's that were missed in the previous change.


# 1.86 24-Jul-2000 pk

Cosmetic & readability:
- local label cleanup in interrupt handling code;
- in debugging sections when testing `intrdebug': use a unique
local label (97) to enhanced clarity;
- comment-out unused code;
- kill a bug as the satisfying result of doing all of the above.


# 1.85 24-Jul-2000 eeh

Fix stack issues in bzero.


# 1.84 24-Jul-2000 mycroft

Revert the previous change for now. I don't have time to debug it tonight.


# 1.83 23-Jul-2000 mycroft

Copy bzero change from libc.


# 1.82 20-Jul-2000 pk

Since `intrcnt' points to an array of long ints, reserve the appropriate
amount of space depending on _LP64. Provide macros to load/store signed
and unsigned long ints.

Also, make the `intrcnt' and `intrpending' arrays 16 entries long, as on
sparc/v9 interrupt #15 is just a regular interrupt.


# 1.81 19-Jul-2000 eeh

Fix merge problem.


# 1.80 19-Jul-2000 eeh

Disable interrupt interlock using ih->ih_pending field. Seems to cause
more problems than it solves.


# 1.79 19-Jul-2000 eeh

Miscellaneous cleanup.


# 1.78 18-Jul-2000 pk

Correct args usage comment in probeget.
Whitespace cleanup.


# 1.77 18-Jul-2000 pk

probeget: 9 -> 0x9


# 1.76 18-Jul-2000 pk

If `ih_pending' is set simply return from the trap, don't schedule another
soft interrupt.


Revision tags: mrg-merge-1-5-top
# 1.75 18-Jul-2000 pk

openfirmware: don't lower %pil


# 1.74 17-Jul-2000 pk

Kill typos in interrupt code.


# 1.73 17-Jul-2000 pk

probeget: do the same song and dance as ld*a() macros in ctlreg.h do.


# 1.72 14-Jul-2000 eeh

Move some macro definitions out of genassym and into locore.s


# 1.71 08-Jul-2000 mrg

backout part of previous: turn off intrdebug, and another debug message


# 1.70 07-Jul-2000 pk

Changes for readability:
- #define LP64 dependent STACKFRAME macro once
- use a LOAD_ASCIZ macro for setting up the format string
for debug messages.


# 1.69 07-Jul-2000 eeh

Temporary fix to prevent the clock from stopping on UIIi machines.


# 1.68 03-Jul-2000 eeh

Prevent interrupts from being posted if they are active and deprecate polled
interrupts. This seems to eliminate the spurious interrupts.


# 1.67 02-Jul-2000 eeh

Clean up interrupt handling some more.


# 1.66 30-Jun-2000 eeh

Fix interrupt delivery on UltraSPARC IIi machines.


# 1.65 24-Jun-2000 eeh

With these changes the kernel seems almost stable again.


# 1.64 24-Jun-2000 eeh

More VM cleanup:

Move the cpu_info structure above the interrupt stack so it won't
get corrupted if the stack overflows.

Flush the D$ before and after all MMU bypass accesses since the
D$ latches all of those.


# 1.63 23-Jun-2000 eeh

Make probeget() and probeset() really work for a change.


Revision tags: netbsd-1-5-base
# 1.62 19-Jun-2000 eeh

branches: 1.62.2;
Have separate data and text segments, make text read-only.


# 1.61 12-Jun-2000 eeh

Start reorganizing the kernel for MULTIPROCESSOR support.


# 1.60 31-May-2000 thorpej

Add a comment about needing to initialize p_cpu when multiple
processors are supported.


Revision tags: minoura-xpg4dl-base
# 1.59 26-May-2000 thorpej

branches: 1.59.2;
First sweep at scheduler state cleanup. Collect MI scheduler
state into global and per-CPU scheduler state:

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

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

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

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

Tested on i386 and Alpha. Changes are mostly mechanical, but apologies
in advance if it doesn't compile on a particular platform.


# 1.58 26-May-2000 thorpej

Don't set `runtime' here; it's done at the end of mi_switch().
cvS: ----------------------------------------------------------------------


# 1.57 26-May-2000 thorpej

Introduce a new process state distinct from SRUN called SONPROC
which indicates that the process is actually running on a
processor. Test against SONPROC as appropriate rather than
combinations of SRUN and curproc. Update all context switch code
to properly set SONPROC when the process becomes the current
process on the CPU.


# 1.56 22-Apr-2000 eeh

If we trap due to a bad kernel stack, try to switch to the interrupt strack
before breaking into the debugger.


# 1.55 18-Apr-2000 eeh

Prevent the system from getting watchdog reset by returning directly to user
mode if restoring the user window traps. Also reduce the time we run with
%tl>0.


# 1.54 13-Apr-2000 eeh

Apparently gas 2.9.5 (don't ask) does not like to add values to %lo()
directives so move the additions inside %lo() to make it happy.
Hopefully this won't break older versions.


# 1.53 10-Apr-2000 mrg

- fix a speeling error
- rename some numbered labels to be a bit less confusing.
- remove dead code
- fix a debug error message (argh!)


# 1.52 10-Apr-2000 pk

Get a kernel without DDB to build.


# 1.51 16-Mar-2000 eeh

Revamp interrupts again:

Fix a bug causing interrmittent panics in interrupt dispatch.
Use interrupt vectors for softints.
Add a new send_softint interface.
Improved D$ flushing.
Improve traptrace and other debugging enhancements.


Revision tags: chs-ubc2-newbase
# 1.50 16-Jan-2000 eeh

Interrupt handlers return zero if they didn't handle the interrupt.


# 1.49 10-Jan-2000 eeh

Add debugger single-stepping and fix interrupt dispatch bugs.


# 1.48 30-Dec-1999 eeh

Lots of changes:

remove ffs()
add bzero that uses block store insns
save %gsr to fpstate
revert to physical accesses for pmap_zero_page so we don't
have conflicting page mappings
general cleanup.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base fvdl-softdep-base
# 1.47 06-Nov-1999 eeh

Handle zero length properly in copyinstr() copyoutstr() and copystr().


Revision tags: comdex-fall-1999-base
# 1.46 11-Oct-1999 eeh

branches: 1.46.2; 1.46.4;
Update to post 1.4.


# 1.45 05-Oct-1999 eeh

branches: 1.45.2;
Make broken versions of gas happy by using sethi/or instead of set for
(negative) addresses.


# 1.44 17-Sep-1999 thorpej

Centralize the declaration and clearing of `cold'.


Revision tags: chs-ubc2-base
# 1.43 18-Jul-1999 eeh

More fun with pmap.


# 1.42 21-Jun-1999 eeh

Improve TRAPTRACE. Add FLTRACE that only tracks MMU faults.


# 1.41 05-Jun-1999 eeh

Make pbrobeget() and probeset() work for 64-bit values as well. To do this
the arguments are changed so the address is first and the ASI second so we
can have the address in %o0:%o1 and not worry about unused registers.

Also a bit of copyright cleanup.


# 1.40 05-Jun-1999 mrg

update a commit slightly.


# 1.39 30-May-1999 eeh

Add code to support using %tick as the system clock if no "counter-timer" node
is found.


# 1.38 09-May-1999 eeh

Fixup non-DEBUG kernels.


# 1.37 29-Apr-1999 christos

Add sunos_sigcode (32 bit only)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.36 26-Mar-1999 eeh

branches: 1.36.4;
COMPAT_SPARC32 -> COMPAT_NETBSD32


# 1.35 25-Mar-1999 mrg

clean and up make compile


# 1.34 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.33 22-Mar-1999 eeh

Need to set up the pointers properly for partial FPU register stores.


# 1.32 22-Mar-1999 eeh

Flush D$ on bypass accesses.


# 1.31 28-Feb-1999 eeh

Use block load/store in pmap_zero_page()/pmap_copy_page().


# 1.30 17-Feb-1999 eeh

Let's test out vectored interrupts.


# 1.29 15-Feb-1999 hubertf

RCS ID police


# 1.28 11-Feb-1999 mrg

fix a comment pasto.


# 1.27 11-Jan-1999 eeh

Finally fixed 64-bit signal trampoline.


# 1.26 10-Jan-1999 eeh

Handle the symbol table properly in a 32-bit kernel that was booted from a
64-bit bootloader.


# 1.25 09-Jan-1999 eeh

More signal fixup.


Revision tags: kenh-if-detach-base
# 1.24 26-Nov-1998 mycroft

Sync kcopy() with 32-bit SPARC version.


# 1.23 16-Nov-1998 eeh

Fixup the last broken bits of the signal handling code.


Revision tags: chs-ubc-base
# 1.22 08-Oct-1998 eeh

Fix more syscall32 and signal breakage.


# 1.21 22-Sep-1998 eeh

More fixup in the signal area.

64-bit syscall cleanup.

Add emulation for some new FPU insns: conversion to 64-bit long int and
conditional moves.


# 1.20 17-Sep-1998 thorpej

SYS_sigreturn -> SYS___sigreturn14.


# 1.19 13-Sep-1998 eeh

Fixup signal changes (hopefully). However SUN_COMPAT is likely broken by
this and I don't know how to fix it.

We can now exec a 64-bit init through a really ugly hack (don't ask.)


# 1.18 11-Sep-1998 eeh

Add labels for the compat_sparc32 signal trampoline and break -- er -- fix
suword and fuword.


# 1.17 09-Sep-1998 eeh

Don't use %tick for microtime on 32-bit kernels -- breaks gettimeofday.


# 1.16 09-Sep-1998 thorpej

Adjust for the new "reaper" kernel thread: do not free the vmspace and
u-area in machine-dependent code. Instead, call exit2() to schedule
the reaper to free them for us, once it is safe to do so (i.e. we are
no longer running on the dead proc's vmspace and stack).


# 1.15 07-Sep-1998 eeh

Fix data corruption problem caused by broken debug code.


# 1.14 07-Sep-1998 eeh

Add new 64-bit trap vectors.


# 1.13 06-Sep-1998 eeh

32-bit fixup.


# 1.12 06-Sep-1998 eeh

Disable some debug stuff.


# 1.11 05-Sep-1998 eeh

It slices. It dices. It does everything except exec a sparc32_compat init.


# 1.10 02-Sep-1998 eeh

Periodic update: now starts probing devices.


# 1.9 30-Aug-1998 eeh

Some more 64-bit cleanup. Now everything compiles.


# 1.8 29-Aug-1998 eeh

Some more 64-bit-ification.


# 1.7 27-Aug-1998 eeh

Add 64-bit pmap support:

Moved from a two level 512/1024 entry setup mapping 32 (9/10/13) bits
respectively to a three level 1024/1024/1024 entry setup mapping 43
(10/10/10/13) bits. In 32-bit mode we waste about 1/12 pages mapping the high
11 bits. We also only manage 43 of the possible 44 bits of virtual address
space, wasting half of it. Oh well, maybe we'll do better next revision.


Revision tags: PMAP32
# 1.6 26-Aug-1998 mrg

panicstack: is needed outside of DEBUG. use _C_LABEL, and printf not db_printf (incase no ddb!)


# 1.5 13-Aug-1998 eeh

Merge paddr_t changes into the main branch.


Revision tags: eeh-paddr_t-base
# 1.4 07-Jul-1998 eeh

branches: 1.4.2;
General update:

Added genassym.cf
Removed lderr which should never have gotten in
Removed lots of dead code from locore.s
Added some softint stuff to intr.c
Added support for halt -p
esp and le both use bus_dmamap_*() functions now
instead of kdvma_mapin()
groundwork for PCI (but we still have no drivers for
any sun4u PCI devices)


# 1.3 04-Jul-1998 jonathan

defopt DDB.


# 1.2 26-Jun-1998 thorpej

defopt COMPAT_SVR4


# 1.1 20-Jun-1998 eeh

branches: 1.1.1;
Initial revision


# 1.423 08-Jan-2020 skrll

oldlwp is always non-NULL in cpu_switchto so remove the test for NULL.


# 1.422 08-Jan-2020 ad

Hopefully fix some problems seen with MP support on non-x86, in particular
where curcpu() is defined as curlwp->l_cpu:

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

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

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

- Remove some KERNEL_LOCK handling which hasn't been needed for years.


Revision tags: ad-namecache-base netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.421 18-Jul-2019 palle

sun4v: added some missing comments to the code in pcbspill


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 1.420 07-Apr-2019 mrg

make trap 0x70 a TRAP() not UTRAP(). we should be able to handle
fast ECC error as a normal trap, and i saw this once a few years
ago but it never repeated so i haven't been able to test this.


# 1.419 08-Feb-2019 palle

sun4v: Improve comment for next_stick_init() - no functional changes


# 1.418 08-Feb-2019 palle

sun4v: initialize %stickcmpr properly when establishing interrupt - fixes issue seen on newer sun4v/SPARC-T5 system where the interrupt never fires.


# 1.417 08-Feb-2019 palle

sun4v: introduce macros for handling spill traps from userlevevel @ traplevel 1 (from OpenBSD) - spill traps at level 1 from userspace now works better


# 1.416 08-Feb-2019 palle

sun4v: add comment documenting the contents of the %g2 register - no functional changes


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126
# 1.415 04-Nov-2018 palle

Ensure that the 64-bit condition codes are used instead of the 32-bit condition codes. ok martin@


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.414 26-May-2018 palle

branches: 1.414.2;
next_stick() - fix typy in comment: tick->stick


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.413 11-Apr-2018 palle

sun4v: handle MMU-related traps properly when they occur at trap level 1. This fixes issues when user-level LWPs access the user-level stack


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 1.412 26-Aug-2017 palle

branches: 1.412.2;
sun4v: Avoid touching the %tick_cmpr register which is not present on never systems (Oracle SPARC Architecture 2011 and beyond). Based on code from OpenBSD locore.s revision 1.177. Tested on both sun4u (qemu and USIII) and sun4v (qemu and T5-2). ok martin@


Revision tags: netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2
# 1.411 06-May-2017 palle

sun4v: The %ver register is not available on sun4v - use GET_MAXCWP introduced in rev. 1.361. Verified using qemu (sun4u and sun4v) and on real sun4v hw (t2000)


Revision tags: prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.410 18-Apr-2017 palle

branches: 1.410.2;
sun4v: Add handling of trap 0x06c @ trap level 1 - based on code from OpenBSD, but slightly adapted to NetBSD. verified using qemu


Revision tags: jdolecek-ncq-base pgoyette-localcount-20170320
# 1.409 19-Feb-2017 palle

sun4v: rft_user needs special handling (a manual fill) since the restore instruction may cause the number of trap levels to exceed the maximum for sun4v - inspired by code from the the openbsd rft_user code path - verified using qemu for both sun4u and sun4v


# 1.408 10-Feb-2017 palle

sun4v: Added handling of trap type 0x034 (address alignment error) + fixed typo mmfsa -> mmufsa. Verified for both sun4u and sun4v using qemu.


Revision tags: nick-nhusb-base-20170204
# 1.407 30-Jan-2017 palle

sun4v: Hook up syscall handling to the trap table. Verified using qemu for both sun4u and sun4v.


# 1.406 27-Jan-2017 palle

sun4v: implement missing handling of itsb traps 0x008 and 0x009. Based on code from OpenBSD. Tested using qemu.


Revision tags: bouyer-socketcan-base
# 1.405 07-Jan-2017 palle

branches: 1.405.2;
sun4v: slowtrap() now selects normal globals properly on both sun4u and sun4v platforms. Verified using qemu for both sun4u and sun4v systems


Revision tags: pgoyette-localcount-20170107
# 1.404 05-Jan-2017 palle

sun4v: TRAP_SETUP() updated to set mmu context id properly for both sun4v and sun4u platforms. Verified using qemu for both sun4u and sun4v systems


# 1.403 04-Jan-2017 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x00-0x23 and 0x28-0x30


# 1.402 29-Dec-2016 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x32-0x7f


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.401 20-Sep-2016 nakayama

Fix RAS for 32-bit kernels. trapframe is always 64-bit.


Revision tags: localcount-20160914
# 1.400 23-Aug-2016 palle

sun4v: rework sun4v_datatrap so it works properly when running on a T2-based system like T5120 - for some reason %tl is 0 when entering sun4v_datatrap causing a crash (sir instruction), so ignore the %tl value for now upon entry to sun4v_datatrap - with this fix both T1 and T2 based systems reach the same point - hangs in rft_user after the init process is started


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726
# 1.399 18-Jul-2016 palle

sun4v: handle device interrupts properly - both legacy (sysino) and cookies


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 1.398 04-Jun-2016 palle

branches: 1.398.2;
sun4v: rtf_user now uses macros GET_MMU_CONTEXTID and SET_MMU_CONTEXTID. Tested on sun4u (QEMU) and sun4v (T2000). Parts from OpenBSD.


Revision tags: nick-nhusb-base-20160529
# 1.397 18-May-2016 nakayama

Decrement %tl in trap handler not to make it zero unconditionally
for the nested trap, and remove useless mov.


# 1.396 17-May-2016 palle

sun4v: Implement missng MMU protection trap handling - mostly from OpenBSD


# 1.395 16-May-2016 palle

Avoid assembler-specific defines by using the export keyword in genassym.cf instead


# 1.394 15-May-2016 nakayama

%g1 is not preserved across function call, so load it before
return_from_trap.


# 1.393 13-May-2016 palle

sun4v: add missing implementation of sun4v_datatrap_tl0 so data_access_fault() is called - mostly from OpenBSD


# 1.392 13-May-2016 nakayama

- ci_paddr is always 64-bit.
- intrlev is array of pointer.
- ih_ack is pointer.


# 1.391 10-May-2016 palle

sun4v: make device interrupts work. Introduce a new intrhand_alloc() function for allocation of interrupt handlers and adapt to this. Parts from OpenBSD. ok martin@


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.390 09-Mar-2016 nakayama

32-bit kernels use 32-bit stack.


# 1.389 03-Mar-2016 palle

sun4v: rft_kernel should pay attention to the number of register windows that can be restored. We cannot rely on fill traps to occur, since sun4v only has two trap levels available in privileged mode. Based on code from OpenBSD. ok martin@


# 1.388 14-Feb-2016 palle

sun4v: add breakpoint trap entry to the sun4v trap table


# 1.387 03-Feb-2016 palle

sun4v: extend dmmu_set_secondary_context() to handle both sun4u and sun4v. ok martin@


Revision tags: nick-nhusb-base-20151226
# 1.386 06-Nov-2015 martin

Basically revert r1.246 of locore.s and r1.73 of vm_machdep.c:

Remove special case handling for userland lwps from cpu_lwp_fork,
instead do it in lwp_trampoline when we first return to userland.

which was a stupid idea - since we did now set all fork child's %tstate
(and thus %pstate when back in userland) to the current kernel's userland
default. This meant we lost the address mask bit for 32bit processes and
all memory model details for 64bit ones.

Move it back to cpu_lwp_fork and fix the condition to only do it once when
forking init.


# 1.385 05-Nov-2015 martin

Most of the time return_from_trap already got called with tf->tf_tstate
loaded in register %g1 - make it so for two more callers and remove
the reload of that value.


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606 nick-nhusb-base-20150406
# 1.384 05-Apr-2015 palle

sun4v: Ensure that the TTEs CP and CV bits are the same (both set) for the primary cpu and secondary cpus INTSTACK mappings


# 1.383 01-Apr-2015 palle

sun4v: Implement handling of cpu_mondo trap - from OpenBSD - tested using the Legion simulator


# 1.382 04-Mar-2015 palle

sun4v: revert some of the logic introduced in revision 1.378 - flushw is not necessary on sun4v (OpenBSD patches the flushw instruction to a nop instruction) - with these changes the kernel reaches cpu_boot_secondary_processors() when running in the Legion simulator (crashes due to missing handling of cpu_mondo_trap)


# 1.381 02-Mar-2015 nakayama

prom_printf converts "\n" to "\r\n" internally, so omit "\r".


# 1.380 02-Mar-2015 nakayama

PANICSTACK is a pointer itself, not a pointer to pointer.


# 1.379 02-Mar-2015 nakayama

Use panic stack temporarily for calling prom_printf in a trap
handler.

It seems that openfirmware cannot handle over 4GB pointers, and
stack pointers may point to over 4GB since VA layout was rearranged
by rev 1.33 of vmparam.h. Therefore, use panic stack to avoid
panicking in OF_write used by prom_printf.


# 1.378 23-Feb-2015 palle

sun4v: sparc_interupt - ensure that the trap level and globals level are the same when the flushw instruction is issued - othwise warnings occur when using the sun4v Legion simulator.


Revision tags: nick-nhusb-base
# 1.377 26-Oct-2014 palle

branches: 1.377.2;
sun4v: Create CLEANWIN0 and CLEANWIN1 macros for handling clean window traps on both sun4u and sun4u (based on the original code inlined in the sun4u trap table). Update trap tables accordingly for both sun4u and sun4v. Ok martin@


# 1.376 24-Oct-2014 nakayama

Fix typo in comment.


# 1.375 18-Oct-2014 snj

src is too big these days to tolerate superfluous apostrophes. It's
"its", people!


# 1.374 15-Oct-2014 palle

sun4v: fixed bug causing the real address to be incorrectly calculated as zero


# 1.373 24-Sep-2014 palle

sun4v: add code to enable startup of secondary cpus on both sun4u and sun4v systems - ok martin@


# 1.372 04-Sep-2014 palle

sun4v: All cpus must be setup with a TSB descriptor, so pmap_setup_tsb_sun4v() must take a pointer to the TSB descriptor


# 1.371 31-Aug-2014 palle

sun4v: Split the NORMAL_GLOBALS and ALTERNATE_GLOBALS macros to _SUN4U and _SUN4V variants. Rework the return_from_trap logic to use the new variants so it is possible to use a global register as scratch register.


# 1.370 14-Aug-2014 nakayama

Add missing delay slot in DEBUG kernel.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.369 30-Jul-2014 palle

branches: 1.369.2;
Fix ALTERNATE_GLOBALS so it at least works on sun4u - using a scratch register is not a good idea...


# 1.368 27-Jul-2014 palle

sun4v: Introduce a new macro ALTERNATE_GLOBALS (matching NORMAL_GLOBALS). Two new helper macros ENABLE_INTERRUPTS and DISABLE_INTERRUPTS are also created. With these changes the GENERIC.UP kernel will reach rootmount on sun4v systems - ok martin@


# 1.367 26-Jul-2014 palle

Improved the NORMAL_GLOBALS macro in the sun4u case, so only the relevant bit (AG) in %pstate is affected - ok martin@


# 1.366 24-Jul-2014 palle

sun4v: add missing spill/fill handling for trap level 1 + cosmetic changes to comments for trap level 0 entries


# 1.365 19-Jul-2014 palle

sun4v: Introduce a NORMAL_GLOBALS macro - first used in sparc_interrupt - other relevant uses will be handled as the sun4v work is progressesing - ok martin@


# 1.364 16-Jul-2014 palle

sun4v: Introduce SET_MMU_CONTEXTID macro for setting the mmu context id on both sun4u and sun4v


# 1.363 13-Jul-2014 palle

sun4v: add interrupt handling to sun4v trap table


# 1.362 13-Jul-2014 palle

Bugfix: add missing cmp instruction to GET_MAXCWP macro


# 1.361 30-Jun-2014 palle

sun4v: The maximum number of register windows is a constant and thus not available via the %ver register (sun4u only). Introduce a macro GET_MAXCWP that handles this, so cpu_switchto() works properly on sun4v. Other relevant reference to %ver can be adapted to use GET_MAXCWP as the sun4v port progresses. OK martin@


# 1.360 31-May-2014 palle

sun4v: added missing dtsb miss handling for trap level 1 - with this update the kernel now reaches configure() on sun4v systems


# 1.359 30-May-2014 palle

Remove debugging code introduced by accident in locore.s revision 1.357


Revision tags: yamt-pagecache-base9 rmind-smpnet-nbase rmind-smpnet-base
# 1.358 05-May-2014 palle

sun4v: the trap base address should be assigned to %l1 so %tba is properly setup later in the code - now the kernel gets as far as printing the copyright disclaimer, kernel version and total and available memory before crashing


# 1.357 21-Apr-2014 palle

sun4v: Update comment: modified -> access


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.356 21-Feb-2014 palle

branches: 1.356.2;
sun4v: Rename TLB_ defines to SUN4U_TLB_ so entries created using TSB_DATA() are properly setup for sun4u and sun4v. Relocate the cputyp variable from autoconf.c to locore.s and make it const in param.h so optimized code can be generated. Parts from OpenBSD. Optimization suggested by nakayama@. OK martin@, mrg@, nakayama@


# 1.355 31-Jan-2014 tsutsui

defined(LKM) -> defined(MODULAR)


# 1.354 26-Jan-2014 palle

sun4v: Add handling of spill/fill and dtsb miss traps (with a XXX to be handled later)


# 1.353 07-Jan-2014 palle

sun4v: trap table setup - currently populated with dummy entries which will be properly implemented later - parts from OpenBSD - OK martin@


# 1.352 29-Dec-2013 nakayama

Make buildable w/o options SUN4V.


# 1.351 27-Dec-2013 palle

a) make the hunt through the cpus list more generic b) sun4v: ensure that the interrupt stack is mapped permanently and the TSB is setup properly - parts from OpenBSD. OK martin@


# 1.350 06-Dec-2013 nakayama

Increase an interrupt depth only in the case of hardware interrupts,
and remove the ci_idepth trick in softint_fastintr.

Fixes the following diagnostic panic reported in port-sparc64.

panic: kernel diagnostic assertion "!cpu_intr_p()" failed: file
"../../../../kern/subr_xcall.c", line 351


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 1.349 24-May-2013 nakayama

branches: 1.349.2;
Disable interrupts after calling data_access_error as with
data_access_fault.


# 1.348 28-Apr-2013 nakayama

Use macros in machine/asm.h instead of locally defined, and
introduce CASPTRA for casxa/casa.


Revision tags: agc-symver-base
# 1.347 23-Jan-2013 martin

Fix sparc64_ipi_ccall by adding proper trap setup.
Fixes xcall(9) problems, as exposed by pserialize(9). Noticed by
J. Hannken-Illjes, cause pointed out by Takeshi Nakayama.


# 1.346 23-Jan-2013 martin

Sligthly clean up the (by default unused) #ifdef TRAPS_USE_IG


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.345 10-Nov-2012 nakayama

Revise comment.


# 1.344 10-Nov-2012 nakayama

Use macro instead of magic number.


# 1.343 09-Nov-2012 nakayama

Make setstick() and getstick() to inline functions.


# 1.342 08-Nov-2012 macallan

use system tick timer instead of %tick on UltraSPARC-III-ish CPUs
review & fixes by Takeshi Nakayama


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.341 17-Mar-2012 mrg

branches: 1.341.2;
port the corrected ECC error handling code from freebsd. i noticed my U10
took one of these and then hang. it shouldn't hang, there's a 'sir' here that
doesn't seem to reset properly. oh well.

tested by simulated a trap via 'ta 0x10' and considering that the same, but
it hasn't been tested against a real ECC error yet.


Revision tags: jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base4
# 1.340 03-Mar-2012 nakayama

Fix the root cause of the hack "disable optimizations for uvm_bio.c
on 32 bit kernels".

gcc converts a division in the calculation of UBC_UMAP_ADDR macro
to multiplication (smul or combination of add/sll), and the
register of its result contains a garbage in upper 32 bits (the
upper 32 bits of smul/add/sll's result isn't zero cleared).

Then it passes to pseg_get{,_real} through pmap_extract without the
zero clear of upper 32 bits in the optimization case. So the
result of pseg_get and pmap_extact sometimes gets screwed up.


Revision tags: jmcneill-usbmp-base5 jmcneill-usbmp-base3
# 1.339 19-Feb-2012 rmind

Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.


Revision tags: jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.338 04-Sep-2011 nakayama

branches: 1.338.2; 1.338.6; 1.338.8;
ih_pil is an interrupt level, not an interrupt mask.


# 1.337 27-Jul-2011 nakayama

ivec is assigned to hardware, so count its event counter up in
interrupt_vector, not in softint, and do some optimization.


# 1.336 20-Jul-2011 macallan

add per ivec event counters


# 1.335 12-Jul-2011 mrg

rename sparc64 BLOCK_SIZE and BLOCK_ALIGN to have SPARC64_ prefixes.
for the assembler files, define the old names to the new names
since using the new names cause ugliness due to longer identifer
names, and reduces churn.

fixes build issues in dtv and vaguely makes <machine/psl.h> slightly
less name-space invasive.


# 1.334 18-Jun-2011 nakayama

Add fast softint(9) support for sparc64.

Reviewed on port-sparc64.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 1.333 12-May-2011 mrg

branches: 1.333.2;
first steps towards fujitsu SPARC64 support:

- SPARC64 systems have interrupts with upto 14 bits set, but we only look
at the first 11 bits. trim non IPI interrupts to 11 bits


Revision tags: uebayasi-xip-base7 bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 jym-xensuspend-nbase jym-xensuspend-base
# 1.332 20-Dec-2010 matt

branches: 1.332.2;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.


Revision tags: uebayasi-xip-base6 uebayasi-xip-base5 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 1.331 10-Jul-2010 nakayama

Clear the upper word explicitly before combining two 32-bit values to 64-bit
on 32-bit kernels.


# 1.330 23-May-2010 martin

Split copy related functions out of locore.s into copy.S, move functions
only needed on multiprocessors into mp_subr.S.


# 1.329 17-May-2010 martin

Simplify primary CPU startup slightly by using the fact that our cpuinfo's
curpcb pointer points to the uarea/pcb of lwp0 and by remembering the pointer
to this cpuinfo, thus avoiding a few CPUINFO_VA references.


Revision tags: uebayasi-xip-base1
# 1.328 20-Mar-2010 chs

fix copy{in,out}{,str}() to return the error returned by uvm_fault().
fixes PR 41813.


Revision tags: yamt-nfs-mp-base9
# 1.327 10-Mar-2010 mrg

branches: 1.327.2;
XXX: workaround we'd like to remove when pmap / uvm locking is cleaned up:

- rename pseg_get() and pseg_set() to pseg_get_real() and pseg_set_real().
- if USE_LOCKSAFE_PSEG_GETSET is defined, which it current is by default,
define pseg_[gs]et() in terms of functions that take a new pseg_lock
mutex at IPL_VM while calling into the real functions.

this seems to avoid the pseg_set() crashes we've seen:
1 - spare needed, when pseg_get() just worked for this pmap
2 - the 2rd ldxa via ASI_PHYS_CACHED in pseg_set() loads garbage
into %o4, and causes the 3rd ldxa to fault


# 1.326 08-Mar-2010 mrg

blast_dcache() SMP friendly:

- blast_dcache() becomes sp_blast_dcache(dcache_size, dcache_line_size)
- new smp_blast_dcache(sparc64_cpuset_t) that blasts the D$ on this cpuset
- sparc64_ipi_blast_dcache() to support the above
- in pmap_remove_all(), when freeing mmu contexts for this pmap, mark
the set of cpus to blast the d$ on as well and convert the
blast_dcache() call into smp_blast_dcache() on the cpus who ran this
pmap, or, sp_blast_dcache(dcache_size, dcache_line_size)
- convert the remaining blast_dcache() in machdep.c to sp_blast_dcache()
- in pmap_destroy()/pmap_remove_all() take the pmap_lock() always since
we assert it is held always.

with these changes, NFS builds on the U60 seem to be stable now, and
the USIII machines also can often complete a single build.sh run now,
diskful or diskless.


reviewed by mlelstv and partially by martin, tested by martin and myself,
with some ideas from chuq as well.


# 1.325 07-Mar-2010 mrg

need _ALIGN in locore.h as well, for DEBUG kernels.


# 1.324 07-Mar-2010 mrg

gas has supported SPARC ".empty" for a long while; get rid of an
ancient workaround.


# 1.323 06-Mar-2010 mrg

move the memcpy/memset implementations out into their own file, with the
block copy versions as well. move some of the definitions in locore.s
into a new locore.h.

locore.s is almost 2000 lines shorter with this change.


# 1.322 04-Mar-2010 mrg

- in _bus_dmamap_unload(), pmap_page_protect() and pmap_clear_reference()
switch the dcache_flush_page() into a dcache_flush_page_all()
- in both pmap_kremove()/pmap_remove(), remove the blast_dcache() call
and replace it with dcache_flush_page_all()
- in pmap_get_page() [used to allocate PTP's], always call pmap_zero_page(pa)
- flush the dcache of the dst page in pmap_{copy,zero}_page() by redirecting
throught a C function that calls the (renamed) asm. the old asm code had a
comment about needing to do this...
- add a couple of membar #Sync's that the USIII manual recommends


based on discussions with chuq@, skrll@ and martin@.


these help my SB2000 / SB2500 with both disk / nfs builds and other tasks,
sometimes lasting for several hours before failing or asserting.


# 1.321 24-Feb-2010 mrg

when handing back page table pages to UVM, flush them from the dcache
on all CPUs.

idea from skrll@, and makes my disk-based SB2000 stable.

tested on U60, SB2000 and SB2500.


# 1.320 24-Feb-2010 mrg

- re-introduce sp_tlb_flush_pte() and sp_tlb_flush_all() that call
the right USI/USIII version.
- define tlb_flush_pte() in terms of sp_tlb_flush_pte() for the
!MULTIPROCESSOR case

this centralises some CPU_IS_USIII_UP() tests.


# 1.319 22-Feb-2010 mrg

move {dump,print}_[id]tlb() into a separate file.


# 1.318 22-Feb-2010 mrg

- store the maximum [id]cache size / line size for each cpu

- remove patch_kernel() since it isn't necessary and has been patching
the wrong thing in general.

- implement USIII versions of blast_icache(), dcache_flush_page() and
cache_flush_phys(). use the newly recorded cache size/line sizes.

- in winfixsave, flush the D$ with the right size index and ops. this
kills one of the wrong tag->inval patches.

- for blast_dcache(), use the newly recorded dcache_size/line_size.

- for blast_icache(), use the newly recorded cache size/line sizes.
for the USIII verison, disable the I$ while writing to ASI_ICACHE_TAG.


these changes removed several hard coded cache sizes values, some very
wrong kernel patching, and seem to make the current failure modes for
USIII less common, but not gone.


# 1.317 15-Feb-2010 mrg

- don't flush 32-bit entries for 64-bit code, it does not seem to be
necessary. #define TLB_FLUSH_LOWVA to turn it back on.
- remove the #if 0'd code in sparc64_ipi_flush_pte_usiii(), i have
verified that it is not required.
- add a missing membar #Sync to sp_tlb_flush_pte_usiii().


# 1.316 15-Feb-2010 nakayama

Fix linker error of GENERIC32 kernel.


# 1.315 15-Feb-2010 mrg

use TLB_SIZE_SPITFIRE in a couple of places, and note that the
{print,dump}_[id]tlb() versions are currently spitfire specific.


# 1.314 15-Feb-2010 mrg

introduce a new patch_kernel() and call it from the end of bootstrap().
use it to patch up TLB flush instructions that don't match for USI/II
and later. we can also hopefully use this to make GENERIC.MP minimally
expensive on single CPU machines as well.

this is the last piece needed to get GENERIC/GENERIC.MP to boot on the
USIII* machines.

idea and some initial code from openbsd.


# 1.313 13-Feb-2010 mrg

remove KTR support. it's never been a working part of netbsd src tree.


# 1.312 09-Feb-2010 wiz

Fix typo in comment.


Revision tags: uebayasi-xip-base
# 1.311 06-Feb-2010 mrg

branches: 1.311.2;
- properly map the schizo interrupt registers, so we can use the normal
virtual mappings to access them.
- with the above fxied, kill SCHIZO_BUS_SPACE_BROKEN, and introduce
an options CHEETAH for now, that disables the SPITFIRE code in locore.
- merge schizo_init() into schizo_attach() and clean up the softc a bit.


with this we are only one more step away from GENERIC booting on USIII
machines.


# 1.310 02-Feb-2010 mrg

- split sp_tlb_flush_pte() and switchtoctx() into sp_tlb_flush_pte_us()/
sp_tlb_flush_pte_usiii() and switchtoctx_us()/switchtoctx_usiii() and
implement the latter while i'm here. it works ... sometimes i think,
but also sometimes panics/hangs.
- fix a comment in sparc64_ipi_flush_pte_usiii()


# 1.309 02-Feb-2010 mrg

for now, reduce a few #ifdef SPITFIRE cases by introducing a new
ASI_DCACHE_TAG_OR_INV that is either ASI_DCACHE_{TAG,_INVALIDATE}.

increase the common code in cache_flush_phys().


# 1.308 01-Feb-2010 mrg

- sp_tlb_flush_all() becomes sp_tlb_flush_all_us() and sp_tlb_flush_all_usiii()
- sparc64_ipi_flush_pte() becomes sparc64_ipi_flush_pte_us() and
sparc64_ipi_flush_pte_usiii()
- add some commented out code to disable interrupts and raise the traplevel
in sparc64_ipi_flush_pte_usiii()
- cache_flush_phys() was missing a little of code in the cheetah case


# 1.307 01-Feb-2010 mrg

for USIII, use the new "tlb demap all" operation in sp_tlb_flush_all()


# 1.306 01-Feb-2010 mrg

remove unused icache_flush_page() implementation.


# 1.305 23-Jan-2010 mrg

remove the final uses of DATA_START.

now we can remove the 16KB space reserved at the start of the data segment,
and i now understand why i wrote this now removed comment 3.5 years ago:
"this shouldn't be needed... but kernel usually hangs without it"


# 1.304 23-Jan-2010 mrg

remove most of the code that writes debugging info DATA_START + offset.


# 1.303 23-Jan-2010 mrg

remove CHKPT() macro and uses. it's likely wrong in SMP land and probably should
be replaced with KTR-style uses if necessary.


# 1.302 23-Jan-2010 mrg

fix a comment.


Revision tags: matt-premerge-20091211
# 1.301 10-Dec-2009 rmind

Rename L_ADDR to L_PCB and amend some comments accordingly.


# 1.300 05-Dec-2009 mrg

- adjust the PA mask to the 43 bits supported by USIII.
- rework the spitfire/cheetah cache_flush_phys() to avoid several #ifdefs
- add a membar #Sync after sparc64_ipi_drop_fpstate (probably unnecessary)


# 1.299 30-Nov-2009 nakayama

sp_tlb_flush_pte for cheetah:
- restore interrupts properly in case of %tl > 0.


# 1.298 30-Nov-2009 mrg

stablize UP USIII support by blocking interrupts around sp_tlb_flush_pte()
i was seeing stack corruption while taking an interrupt in this function.

get USIII SMP mostly working by implementing the cheetah version of
sparc64_ipi_flush_pte().


SMP support is still not entirely stable. i can reproducably get a:

panic: fpusave_lwp ipi didn't

while running build.sh, when an awk process is exiting. other simple
heavy work loads do not crash for me right now.


# 1.297 30-Nov-2009 mrg

delete some no longer used code:
- smp_tlb_flush_ctx()
- smp_tlb_flush_all()
- sparc64_ipi_flush_ctx()
- sparc64_ipi_flush_all()
- sp_tlb_flush_ctx()


# 1.296 29-Nov-2009 nakayama

- calculate end PA correctly.
- wrap more spitfire specific (flushing I$) code.
- fix inverted #if condition for flushing I$ (and restore ASI_ICACHE_TAG).


# 1.295 28-Nov-2009 mrg

implement enough code to get SB2000/SB2500 booting to multiuser. does
not last long if you use it, but an idle machine has stayed up 10 hours.

- for the !SPITFIRE case, use ASI_DCACHE_INVALIDATE instead of
ASI_DCACHE_TAG when clearing tlb entries. from openbsd.

- convert some comment "! Not yet" into "WRITEME", so that attempting
to build a USIII MULTIPROCESSOR kernel fails to build until the code
is written.

- add some more WRITEME's for the above.

- implement a !SPITFIRE version of sp_tlb_flush_all(). since there are
no spare regs, for now just always increase %tl around this call. (we
could maybe store a token in %o3 along with the saved %pstate info.)


# 1.294 26-Nov-2009 matt

Kill proc0paddr. Use lwp0.l_addr instead.


# 1.293 25-Nov-2009 mrg

s/L_ADDR/L_PCB/, requested by rmind.


# 1.292 17-Oct-2009 nakayama

Wrap unused code with #if 0 which is called from #if 0'ed code.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5
# 1.291 30-May-2009 martin

cpu_setfunc() can not use lwp_trampoline, as that has additional lwp startup
semantics. Use a simpler setfunc_trampoline instead.


# 1.290 18-May-2009 nakayama

Remove random() from locore.s since it is in libkern.


# 1.289 16-May-2009 nakayama

Remove clear %tick in locore.s since it is cleared at cpu_initclocks() in
clock.c.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 nick-hppapmap-base mjf-devfs2-base
# 1.288 15-Dec-2008 mrg

restore some old "intrdebug" code, but leave it under NOT_DEBUG. most
of it works, but one that prints func/arg for each handler is not very
stable...

for now, while schizo bus space pointer accesses aren't working, add
a SCHIZO_BUS_SPACE_BROKEN option so you can build a kernel with schizo.

with this, and the prior schizo interrupt fix, you can now fail to run
/sbin/init!


Revision tags: haad-dm-base2 haad-nbase2 haad-dm-base
# 1.287 09-Dec-2008 martin

Get rid of get_maxctx() - it doesn't work on newer cpus and we will have
to find a better way for (some) sun4v machines - all sun4u use 13 bit
contexts anyway.


Revision tags: netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 ad-audiomp2-base netbsd-5-base
# 1.286 30-Oct-2008 nakayama

branches: 1.286.2; 1.286.6;
Wrap more code specific to USE_BLOCK_STORE_LOAD.


Revision tags: matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4
# 1.285 05-Oct-2008 nakayama

branches: 1.285.2;
- in flushing cache, use 32 as increment/decrement value to match the
cache line size.
- remove useless restore of %asi.
- remove nop in delay slot if we can.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 1.284 10-Jul-2008 nakayama

Use proper CCR.


# 1.283 10-Jul-2008 nakayama

sparc64_ipi_save_fpstate:
- use primary MMU context for consistency with other trap/interrupt handlers.

sparc64_ipi_save_fpstate, savefpstate:
- avoid storing fp registers as we can.

sparc64_ipi_save_fpstate, savefpstate, loadfpstate:
- remove unaligned case since buffers allocated with pool_cache are ensured
64-byte aligned.

Ok by martin@.


# 1.282 02-Jul-2008 nakayama

branches: 1.282.2;
UltraSPARCs don't have floating point queue, and reading %fq regsiter
will cause illegal instruction trap. So remove the code handling them.


# 1.281 29-Jun-2008 nakayama

Wrap IPI calls with #ifdef MULTIPROCESSOR.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.280 14-Jun-2008 nakayama

Close unterminated comment.
Fix unexpected behavior in case of loadfpstate from unaligned buffer.


Revision tags: yamt-pf42-base3
# 1.279 31-May-2008 nakayama

branches: 1.279.2;
openfirmware_exit:
- disable interrupts with %pstate.
- prepare 64-bit stack and enable 64-bit addresses for 32-bit SMP kernels.


Revision tags: hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 yamt-nfs-mp-base yamt-pf42-base
# 1.278 16-Apr-2008 nakayama

branches: 1.278.2; 1.278.4; 1.278.6;
Disable TRAPSTATS which was accidentally enabled when yamt-idlelwp branch
was merged.

Ok by martin@.


# 1.277 14-Apr-2008 nakayama

Remove sparc64_ipi_sync_tick.

Since we can use counter-timer as timecounter instead of %tick on SMP kernel,
it is not necessary to sync all CPUs %tick registers.


# 1.276 14-Apr-2008 nakayama

Add workaround for BB_ERRATA_1 on writing to TICK_CMPR register in
next_tick(). If writing to TICK_CMPR fails, we lose hardclock interrupt
on secondary CPUs.

About BB_ERRATA_1 from comment in OpenSolaris:

/*
* Writes to the TICK_COMPARE register sometimes fail on blackbird modules.
* The failure occurs only when the following instruction decodes to wr or
* wrpr. The workaround is to immediately follow writes to TICK_COMPARE
* with a read, thus stalling the pipe and keeping following instructions
* from causing data corruption. Aligning to a quadword will ensure these
* two instructions are not split due to i$ misses.
*/


# 1.275 28-Mar-2008 nakayama

Don't read fplwp content in delay slot for considering the case fplwp was
modifiled.

Reported by Chris Ross on port-sparc64.


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.274 20-Mar-2008 nakayama

- remove disabling interrupt in IPI.
- unused VA bits in MMU demap is 13 bits, not 12 bits.


# 1.273 18-Mar-2008 nakayama

Fix a race when increment an interrupt level event counter.


# 1.272 17-Mar-2008 nakayama

Fix a race condition in IPI handlers of save/drop fpstate, from OpenBSD.
Reported and tested by martin@.


# 1.271 17-Mar-2008 nakayama

Make schedintr interrupt handler per-CPU.
While there rename tickintr interrupt handler and share initialization
code with schedintr.


# 1.270 14-Mar-2008 nakayama

Improve IPI handling:
- make IPI takes two arguments.
- add IPI event counters per-CPU.
- implement IPI functions which were missing or broken.
- insert DELAY while halting primary CPU in IPI handler.


# 1.269 02-Mar-2008 nakayama

- make interrupt pending list per-CPU.
- make tickintr() MP-safe.
- remove unused port-sparc derived interrupt code.

Ok by martin@.


# 1.268 02-Mar-2008 nakayama

Don't get IPI handler argument (from bogus address), and ack IRQ twice.


# 1.267 28-Feb-2008 martin

Make TSBs and MMU contexts per-cpu.


Revision tags: nick-net80211-sync-base mjf-devfs-base hpcarm-cleanup-base
# 1.266 26-Jan-2008 nakayama

branches: 1.266.2; 1.266.6;
Fix for 32-bit kernels.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.265 15-Jan-2008 skrll

Store a sensbile PCB_PC value in snapshot - the return point.

This helps gdb somewhat.

OK'd by martin.


# 1.264 14-Jan-2008 martin

Fix register name typo/copy&pasto - %g6 is not %o6/%sp.
From OpenBSD.


Revision tags: matt-armv6-base
# 1.263 06-Jan-2008 martin

Load the next cpu_info pointer with LDPTR instead of ld.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2
# 1.262 09-Dec-2007 martin

branches: 1.262.2;
Provide cpu_intr_p(), at least for non-MULTIPROCESSOR kernels.
Based on suggestions by Andrew Doran.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.261 22-Oct-2007 martin

branches: 1.261.2; 1.261.4; 1.261.6;
Remove an unused .globl declaration


Revision tags: yamt-x86pmap-base4
# 1.260 17-Oct-2007 garbled

Merge the ppcoea-renovation branch to HEAD.

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

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

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base ppcoea-renovation-base vmlocking-base
# 1.259 09-Sep-2007 martin

branches: 1.259.4;
Make cpufrequency and friends per cpu values.
Prepare a hz tick interrupt on secondary CPUs via %tick, but do not
enable it yet, as it breaks ddb.


# 1.258 09-Sep-2007 martin

Do not ACK IPIs before we finished loading all arguments.


# 1.257 06-Sep-2007 martin

Remove the (now unused) second 64k page mapped per CPU.
From matthew green, with small changes by me. All bugs are mine.


# 1.256 25-Aug-2007 martin

branches: 1.256.2;
Remove INITSTACK completely - at the time we used to switch to it, we
already have access to all of lwp0 and it's uarea - so we can switch
to the correct lwp0 stack easily before calling main.


# 1.255 25-Aug-2007 martin

When exiting to OF, use the interrupt stack instead of INITSTACK


# 1.254 25-Aug-2007 martin

Rework cpu_mp_startup slightly:
- temporarily use the cpu's interrupt stack untill we are ready
to access non-OF-based mappings, then directly switch to the cpu's
idlelwp's uarea stack
- disable interrupts untill we are ready to call C code


# 1.253 13-Aug-2007 macallan

remove two restore without matching save


Revision tags: nick-csl-alignment-base matt-mips64-base mjf-ufs-trans-base
# 1.252 06-Jul-2007 martin

branches: 1.252.4; 1.252.8;
A few nits for 32bit SMP kernels, noticed by mrg.
While there, simplify the fpstate IPIs a bit.


# 1.251 05-Jul-2007 martin

sparc64_ipi_save_fpstate is not a leaf function - create a full grown
stack frame.


# 1.250 28-May-2007 mrg

clean up cpu_switchto() a little - no need to flushw or membar
excessively. optimise an rdpr. tested by tnn.


# 1.249 23-May-2007 martin

Fix a stupid bug in the save_fpstate ipi, which caused overwriting of
struct lwp of the lwp owning the fpu. Fix clearing the fplwp - %o0 will
not survive the call to savefpstate - duh!


# 1.248 20-May-2007 martin

Simplify tf_tstate setting when leaving for userland initially - I seem
to have confused the if with the else case of the previous C code.
Funny that it worked at all.


# 1.247 20-May-2007 martin

cpu_switchto() has to return it's first arg, always. This differs from
my reading of the documentation, but helps in the real world and seems
to be what other ports do.


# 1.246 20-May-2007 martin

Remove special case handling for userland lwps from cpu_lwp_fork, instead
do it in lwp_trampoline when we first return to userland.


# 1.245 19-May-2007 martin

cpu_idle is a leaf function, so we better "return from leaf".
Use return value from cpu_switchto for previous lwp in lwp_trampoline.
Also shamelessly steal a comment from uwe written for sparc that explains
all this.
Thanks to tnn, mrg, and uwe for helping to debug this.


# 1.244 17-May-2007 yamt

merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base ad-audiomp-base
# 1.243 22-Feb-2007 martin

branches: 1.243.4; 1.243.6; 1.243.12;
uvm.page_idle_zero now is a bool, not a 32bit value any more.


# 1.242 21-Feb-2007 mrg

shave 9 insns off the tsb setup in cpu_initialize & cpu_mp_startup.


# 1.241 21-Feb-2007 martin

Get rid of unused (thus always zero) "curlwp" variable hidden in assembler
code (C code always uses a cpuinfo based macro).


# 1.240 18-Feb-2007 martin

Make use of another call delay slot, pointed out by uwe.


# 1.239 18-Feb-2007 martin

Make use of a call delay slot and avoid a bogus EMPTY.
Spotted by Juergen Hannken-Illjes, with input from Andrew Doran and
Valeriy E. Ushakov.


# 1.238 18-Feb-2007 martin

Whitespace cosmetics


# 1.237 18-Feb-2007 martin

Backout previous: EMPTY was misused


# 1.236 18-Feb-2007 martin

Make EMPTY expand to nop with gas, as it is used to mark empty branch
delay slots.


# 1.235 15-Feb-2007 martin

branches: 1.235.2;
Fix obvious copy&pasto in SCHED_DEBUG register usage.


Revision tags: post-newlock2-merge
# 1.234 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.233 25-Dec-2006 wiz

Spell "relevant" correctly. From Zafer Aydogan.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.232 25-Oct-2006 mrg

branches: 1.232.2; 1.232.4;
- note that __idle_u should go away but doing so breaks things
- fix several comments to reality
- clean up the #ifdef NO_VCACHE code slightly
- use call instead of set/jmpl
- remove a couple of unnecessary stores to curlwp


Revision tags: yamt-splraiseipl-base2
# 1.231 18-Oct-2006 rjs

Clean up some comments. Cosmetic change to use correct structure
offset names.

Optimize out two instructions from sparc64_ipi_save_fpstate and
sparc64_ipi_drop_fpstate.


# 1.230 17-Oct-2006 mrg

allocate 128KB (as opposed to 64KB) per-cpu, and place the interrupt
stack, cpu_info structure, panicstack, idle uarea and normal kernel
stack in here. the idle uarea and kernel stack are in the 2nd 64KB
page. the interrupt stack and cpu_info structure are as the same
place in the 1st 64KB page, and the panicstack grows down from the
top of this page. update comments in param.h to suit (XXX: a lot
of these constants should move to a header file that will not pollute
the name space so much.) map these pages identically between
cpu_initialise() and cpu_mp_startup(), and deal with the two 64KB
pages in pmap_extract(). keep an unmapped 64KB page between them.

don't initialise the unused "ci_eintstack" member of the cpu_info
structure

use constants to initialise many addresses in the cpu_info structure,
consolidating these assignments from cpu0 and cpu>0

delete u0/estack0/panicstack from locore.s

clean up some wrong comments in locore.s

fix a 32bit-only bug in cpu_mp_startup().

delete 'u0' entirely.


this fixes recent random lossage seen on port-sparc64: processes
stuck in RUN state, data faults, and hangs.


# 1.229 04-Oct-2006 mrg

use call instead of set/jmpl. add an entry point for idle that expects
sched_lock to be unlocked, and use this for non-boot cpu's. complete a
comment describing how registers in idle_switch are expected to be set.


# 1.228 03-Oct-2006 mrg

use the same SAVE_LOCALS_INS definition for 32 bit and 64 bit kernels.
refactor TRAP_SETUP() a little between these two versions to be more alike.


# 1.227 03-Oct-2006 mrg

use the correct size/type for MP variables (pointers and longs).

a 32 bit MULTIPROCESSOR kernel now builds (and crashes quickly.)


# 1.226 03-Oct-2006 mrg

in the 64bit version of SAVE_LOCAL_INS, s/BIAS/STKB/ to allow future
sharing of the 32 and 64 bit versions of the {TRAP,INTR}_SETUP macros.


# 1.225 19-Sep-2006 mrg

- remove some way old FP setup/teardown code
- put the block memcpy/memset inside #ifdef USE_BLOCK_STORE_LOAD which
is (now) defined.

no functional change, same .o is generated.


# 1.224 19-Sep-2006 mrg

re-order the changes in rev 1.217 to give registers a little bit of
time to settle between usage, like it was before hand.


# 1.223 19-Sep-2006 mrg

- remove a wrong comment.
- add a new entry point for idle called idle_switch that is called by
cpu_switch() in the MP case when sched_whichqs is zero, properly
setting up the idle stack. from petrov@ via martin@.


# 1.222 19-Sep-2006 mrg

rework interrupt_vector() slightly:
- for the IPI case, avoid loading the address of intrlev into %g3
- remove some NOT_DEBUG code
- load the interrupt argument #2 in the delay slot

this removes 2 nops during interrupt processing for the normal
case, and an additional 2 ALU instructions for IPIs


# 1.221 18-Sep-2006 mrg

- sparc64_ipi_halt(): we shouldn't return from sparc64_ipi_halt_thiscpu()
so replace a branch with a 'sir'
- in #if 0 code, in sparc64_ipi_flush_pte() and sparc64_ipi_flush_ctx()
save/restore the out registers that the sp_tlb_flush_xxx() versions
around calling them
- in sp_tlb_flush_pte() and sp_tlb_flush_ctx(), replace global register
usage with out registers so that we don't clobber the (alternate)
global registers when these are called from IPI context


# 1.220 18-Sep-2006 mrg

- remove an extra 'sir' that followed one in a macro
- add some named labels to some spill/fill handlers
- remove 2 unused strings


Revision tags: yamt-splraiseipl-base
# 1.219 18-Sep-2006 martin

branches: 1.219.2;
Lazy FPU handling for the MULTIPROCESSOR case


# 1.218 16-Sep-2006 nakayama

From OpenBSD:
- reload %fprs for checking it again.
- use symbolic names for checking in %fprs.

revision 1.51
date: 2005/07/18 14:50:11; author: deraadt; state: Exp; lines: +2 -1
cache a copy of the fprs so we know what fp restore we should do after

revision 1.50
date: 2005/07/14 01:46:13; author: deraadt; state: Exp; lines: +4 -4
use symbolic names for checking in %fprs, as above


# 1.217 16-Sep-2006 nakayama

Fix a couple of %y register save/restore errors, inspired from OpenBSD.

revision 1.44
date: 2004/04/23 04:18:17; author: marc; state: Exp; lines: +5 -4

fix a couple of %y register save/restore errors
1) don't save %y in a register that is later used before restoring %y
2) always restore %y after calling a signal handler
tested by drahn@, OK pval


# 1.216 15-Sep-2006 martin

Do not bother to save fpu state when we are about to get rid of it.


Revision tags: yamt-pdpolicy-base9
# 1.215 13-Sep-2006 mrg

SMP cleanup. provide support for multiple CPUs in DDB. (SMP itself
is still not working.)

cpu.h:
- add a pointer for DDB regs in SMP environment to struct cpu_info
- remove the #defines for mp_pause_cpus() and mp_resume_cpus()
cpuset.h:
- remove CPUSET_ALL() and rename CPUSET_ALL_BUT() to CPUSET_EXCEPT()
from petrov.
db_machdep.h:
- rename the members of db_regs_t to be the same as sparc
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- redo DDB_REGS to no longer be a pointer to a fixed data structure
but to one allocated per-cpu when ddb is entered
- move a bunch of prototypes in here
intr.h:
- remove SPARC64_IPI_* macros, no longer used
db_interface.c:
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- make "nil" a 64 bit entity
- change the ddb register access methods to work in multiprocessor
environment, it is now very much like sparc does it
- in kdb_trap() avoid accessing ddb_regp when it is NULL
- update several messages to include the cpu number
- unpause other cpus much later when resuming from ddb
- rename db_lock() to db_lock_cmd(), as the sparc-like code has
db_lock as a simple lock
- remove "mach cpus" command, and replace it with "mach cpu" (which
does the same) and also implement "mach cpu N" to switch to
another cpus saved trapframe
db_trace.c:
- update for the ddb_regs -> ddb_regp change
genassym.cf:
- add TF_KSTACK as offsetof(struct trapframe64, tf_kstack)
ipifuncs.c:
- overhaul extensively
- remove all normal interrupt handlers as IPI's, we now handle
them all specially in locore.s:interrupt_vector
- add a simplelock around all ipi functions - it's not safe for
multiple cpus to be sending IPI's to each other right now
- rename sparc64_ipi_pause() to sparc64_ipi_pause_thiscpu() and,
if DDB is configured, enable it to save the passed-in trapframe
to a db_regs_t for this cpu's saved DDB registers.
- remove the "ipimask" system (SPARC64_IPI_* macros) and instead
pass functions directly
- in sparc64_send_ipi() always set the interrupt arguments to 0,
the address and argument of the to be called function. (the
argument right now is the address of ipi_tlb_args variable, and
part of the reason why only one CPU can send IPI's at a time.)
don't wait forever for an IPI to complete. some of this is
from petrov.
- rename sparc64_ipi_{halt,pause,resume}_cpus() to
mp_{halt,pause,resume}_cpus()
- new function mp_cpu_is_paused() used to avoid access missing
saved DDB registers
- actually broadcast the flush in smp_tlb_flush_pte(),
smp_tlb_flush_ctx() and smp_tlb_flush_all(). the other end may
not do anything yet in the pte/ctx cases yet...
kgdb_machdep.c:
- rework for changed member names in db_regs_t.
locore.s:
- shave an instruction from syscall_setup() (set + ld -> sethi + ld)
- remove some old dead debug code
- add new sparc64_ipi_halt IPI entry point, it just calls the C
vector to shutdown.
- add new sparc64_ipi_pause IPI entry point, which just traps into
the debugger using the normal breakpoint trap. these cpus usually
lose the race in db_interface.c:db_suspend_others() and end up
calling the C vector sparc64_ipi_pause_thiscpu().
- add #if 0'ed code to sparc64_ipi_flush_{pte,ctx}() IPI entry
points to call the sp_ version of these functions.
- in rft_kernel (return from trap, kernel), check to see if the
%tpc is at the sparc64_ipi_pause_trap_point and if so, call
"done" not "retry"
- rework cpu_switch slightly: save the passed-in lwp instead of
using the one in curlwp
- in cpu_loadproc(), save the new lwp not the old lwp, to curlwp
- in cpu_initialize(), set %tl to zero as well. from petrov.
- in cpu_exit(), fix a load register confusion. from petrov.
- change some "set" in delay branch to "mov".
machdep.c:
- deal with function renames
pmap.c:
- remove a spurious space
trap.c:
- remove unused "trapstats" variable
- add cpu number to a couple of messages


# 1.214 09-Sep-2006 mrg

significant clean up effort, largely from petrov@ via martin@.

- fix a bunch of comments for proc->lwp
- remove old TRAPTRACE, NOT_DEBUG, etc. code that has bit-rotted
- put some older DEBUG code under NOT_DEBUG
- add a bunch of new debugging/tracing code ("KTR") that depends on
other changes not yet present.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base yamt-pdpolicy-base5 chap-midi-base simonb-timecounters-base rpaulo-netinet-merge-pcb-base
# 1.213 14-May-2006 elad

branches: 1.213.6; 1.213.8;
integrate kauth.


# 1.212 12-May-2006 skrll

Fix some comments.


Revision tags: elad-kernelauth-base
# 1.211 09-May-2006 rjs

Load CPCB in cpu_mp_startup.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.210 11-Feb-2006 cdi

branches: 1.210.2; 1.210.4; 1.210.6;
ANSIfication: u_intN_t -> uintN_t, use ANSI function declarations/definitions
instead of K&R ones.


# 1.209 27-Jan-2006 cdi

branches: 1.209.2; 1.209.4;
Alter sparc64 bootstrap, catch up to ofwboot v1.9:

- Accept bootinfo structure passed down from ofwboot v1.9
- Drop kernel re-mapping code
- Use permanent 4MB mappings provided by the loader instead
- Change kernel entry address to point directly at the code instead of pointing
at the trap table's first slot. This allows the bootloader to detect
those kernels which are aware of the new boot scheme
- Due to the changes in kernel mapping code, alter secondary CPU bootstrap
code to use trampoline just like FreeBSD does (some FreeBSD code is used
here as well)


# 1.208 12-Jan-2006 cdi

Fix a typo: %g0 should be used instead of %o0 when initializing FPU in dostart:
and cpu_mp_startup:, %o0 is not even initialized at this point.


# 1.207 11-Dec-2005 christos

branches: 1.207.2;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 1.206 10-Jul-2005 christos

Re-factor syscall, and make it use syscall_{plain,fancy}.


# 1.205 31-May-2005 chs

branches: 1.205.2;
remove vestigal {,e}intr{names,cnt} symbols now that vmstat doesn't need them.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.204 12-Feb-2005 chs

branches: 1.204.4; 1.204.6; 1.204.8;
in sparc_interrupt(), wait to enable interrupts until just before calling
the handler and disable them again right after the handler returns.
we don't want another hardware interrupt coming in while we're mucking
with the list pointers. also, clear the intrhand's ih_pending pointer
before calling the handler rather than after, so that if another interrupt
comes in while the handler is running, we can put the intrhand back on
the list so it will be called again.

in send_softint(), disable interrupts via %pstate instead of %pil, so that
hardware interrupts at higher levels are blocked while we manipulate the
intrpending list. also, if the intrhand already has ih_pending set,
don't bother poking the SET_SOFTINT register again, since being on the list
implies that there is already a softint pending in the hardware.

these appear to fix PR 21750 (the "sleep forever" problem).

while I'm here, remove more vestiges of the !INTRLIST softint stuff
(code and comments). and in sparc64_ipi_flush_all(), interrupts are
already disabled so we don't need to fiddle with %pstate.


Revision tags: yamt-km-base2
# 1.203 30-Jan-2005 martin

Remove the no long usefull variants selected by undefining INTRLIST and
INTR_INTERLOCK to improve readability. Same object code generated as before.


Revision tags: yamt-km-base
# 1.202 16-Jan-2005 chs

branches: 1.202.2;
use ENTRY_NOPROFILE() for various entry points,
stack traces work better that way.


Revision tags: kent-audio1-beforemerge kent-audio1-base
# 1.201 03-Dec-2004 chs

branches: 1.201.4;
remove cache_flush_virt() and PADDRT, they're no longer used.
allocate a stack frame for blast_dcache() when profiling so it shows up.
in dcache_flush_page(), use a stride of 32 instead of 16 to match the
cache line size. correct various comments.


# 1.200 08-Nov-2004 petrov

Don't compile sparc64_ipi functions when UP.


# 1.199 25-Oct-2004 martin

No need to clear %o1 when returning a 64 bit integer from pseg_get if we
are compiling for a 64 bit kernel.


# 1.198 24-Jul-2004 nakayama

Change interrupt pending list end value to -1, to avoid linking an
interrupt handler twice.

It may fix "sleep forever" bug.


# 1.197 09-Apr-2004 petrov

Clean-up unused defines and variables.


Revision tags: netbsd-2-0-base
# 1.196 26-Mar-2004 petrov

branches: 1.196.2;
Use want_resched from cpu_info area.


# 1.195 23-Mar-2004 martin

Replace intrcnts by evcnts. XXX - needs slight tweaking for MULTIPROCESSOR.


# 1.194 14-Mar-2004 chs

checkpoint of MP work from dennis and myself. includes cross-processor
interrupt framework, a sledgehammer TLB invalidation and misc MP fixes.
doesn't work at all yet.


# 1.193 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.192 19-Jan-2004 martin

Rename switchexit to cpu_exit and g/c the old C implementation of cpu_exit.


# 1.191 18-Jan-2004 martin

Support RAS for 32bit kernels too.


# 1.190 16-Jan-2004 martin

In proc_trampoline don't bother to clear condition codes in the trap
frame, since we no longer rely on this.
While there fix a few comments.


# 1.189 08-Jan-2004 martin

Minor cleanup


# 1.188 06-Jan-2004 martin

Implement restartable atomic sequences (RAS) for sparc64.


# 1.187 06-Jan-2004 petrov

Spinup secondary cpus. Based on codes sent to me by Dennis Chernoivanov
and Chuck Silvers.


# 1.186 04-Jan-2004 jdolecek

update to recent changes - exit2() doesn't exist anymore and the
exit path always calls lwp_exit2()
pointed out Martin Husemann


# 1.185 02-Dec-2003 martin

Minor cleanup: remove unused code, sync a comment with current reality.


# 1.184 25-Nov-2003 cdi

Use per-cpu pcb, curlwp and fplwp rather than global ones. This brings
GENERIC.MP configuration to a usable state.

Approved by petrov@.


# 1.183 24-Nov-2003 cdi

Call 'proc_trampoline_mp' from 'proc_trampoline' in a multiprocessor
configuration. Fix process locking. Approved by petrov@.


# 1.182 20-Nov-2003 petrov

Remove nwindows calculation, it's not used. Set l_cpu in cpu_switch.


# 1.181 09-Nov-2003 martin

Get rid of bcopy/bzero.


# 1.180 26-Oct-2003 christos

Initial siginfo support for sparc64 (untested). COMPAT_16 sigcontext signal
delivery tested.


# 1.179 24-Aug-2003 chs

add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default. the changes
fall into two basic catagories:

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

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

originally from openbsd, adapted for netbsd by me.


# 1.178 08-Jul-2003 cdi

traceit: don't use %g7 as it is to become curcpu() register. Add comments.


# 1.177 18-May-2003 martin

branches: 1.177.2;
Make kernels with options KGDB at least compile.
Still needs some work to make it working.


# 1.176 29-Apr-2003 nakayama

Use BLOCK_ALIGN rather than BLOCK_SIZE for aligning a pointer.


# 1.175 27-Apr-2003 ragge

Preserve the symbol table in the LKM || KSYMS cases also.


# 1.174 04-Apr-2003 petrov

use branch slot in pmap_copy_page.


# 1.173 24-Mar-2003 nakayama

Divide `set' instruction in delay slot (from OpenBSD change to rev 1.30).


# 1.172 10-Feb-2003 martin

Remove some #if 0 code and a few XXX marked membars w/o proper
justification for their existence.


# 1.171 09-Feb-2003 martin

Remove left over pieces from reusing the signal trampoline for upcalls.
This should fix signal delivery for 32bit kernels.


# 1.170 05-Feb-2003 nakayama

Switch to use cycle counter (%tick) based microtime().

This is derived from alpha/microtime.c and i386/tsc_microtime.c,
and will share with both ports.

This should fix PR port-sparc64/18452.
(approved by martin)


# 1.169 04-Feb-2003 martin

Fix return value of pseg_set, which I accidently broke in rev. 1.164.

Fix register names in comment and shave off another register (hint
from uwe).


# 1.168 01-Feb-2003 martin

Rearrange register usage in pseg_set a bit and shave off %g4.


# 1.167 01-Feb-2003 martin

Remove a few #ifdef _LP64 by using STPTR/LDPTR macros.
Thanks to Matthew Green for the pointer.


# 1.166 31-Jan-2003 martin

Apply leaf procedure optimization to pseg_set (again).


# 1.165 31-Jan-2003 martin

Make the pmap count resident/wired mappings on the fly instead of
walking the page tables whenever this information is needed.

Add an option PMAP_COUNT_DEBUG to assert the new counts and the
page table walk agree.

The old solution had very bad performance impact, for example
by the high CPU load when running top(1).

Thanks to Simon Burge for pointing at the cause of the problem and
to Valeriy E. Ushakov for optimizing my simple minded assembler code.


# 1.164 27-Jan-2003 martin

Remove unused function pseg_find (which looked quite similar to
pseg_get anyway).


# 1.163 18-Jan-2003 thorpej

Merge the nathanw_sa branch.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.162 16-Jan-2003 petrov

Move dump_dtlb back under DDB.


# 1.161 15-Jan-2003 chs

fix two bugs in my last pmap rework:
- in tlb_flush_all(), don't skip TLB entries with the high bit on,
I was confused about which MMU register it was using. it's also fine
to use the last hardware context.
- in pmap_create(), don't allocate a hardware context for the new pmap.
it's unnecessary, and when this would cause us to recycle all the contexts,
it would result in the current process's context being set to 0
(ie. the kernel's context). the current process could then return to
userspace without going through the context-switch code (and thus without
having a hardware context reallocated). this would lead to user mappings
being entered in the kernel's context later, causing all sorts of trouble.
add some assertions to catch this kind of thing.


Revision tags: fvdl_fs64_base
# 1.160 25-Dec-2002 petrov

new function dump_itlb.


Revision tags: gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.159 22-Sep-2002 chs

many improvements:
- use struct vm_page_md for attaching pv entries to struct vm_page
- change pseg_set()'s return value to indicate whether the spare page
was used as an L2 or L3 PTP.
- use a pool for pv entries instead of malloc().
- put PTPs on a list attached to the pmap so we can free them
more efficiently (by just walking the list) in pmap_destroy().
- use the new pmap_remove_all() interface to avoid flushing the cache and TLB
for each pmap_remove() that's done as we are tearing down an address space.
- in pmap_enter(), handle replacing an existing mapping more efficiently
than just calling pmap_remove() on it. also, skip flushing the
TSB and TLB if there was no previous mapping, since there can't be
anything we need to flush. also, preload the TSB if we're pre-setting
the mod/ref bits.
- allocate hardware contexts like the MIPS pmap:
allocate them all sequentially without reuse, then once we run out
just invalidate all user TLB entries and flush the entire L1 dcache.
- fix pmap_extract() for the case where the va is not page-aligned and
nothing is mapped there.
- fix calculation of TSB size. it was comparing physmem (which is
in units of pages) to constants that only make sense if they are
in units of bytes.
- avoid sleeping in pmap_enter(), instead let the caller do it.
- use pmap_kenter_pa() instead of pmap_enter() where appropriate.
- remove code to handle impossible cases in various functions.
- tweak asm code to pipeline a little better.
- remove many unnecessary spls and membars.
- lots of code cleanup.
- no doubt other stuff that I've forgotten.

the result of all this is that a fork+exit microbenchmark is 34% faster
and a fork+exec+exit microbenchmark is 28% faster.


Revision tags: gehenna-devsw-base
# 1.158 18-Jul-2002 wiz

Spell 'should' correctly.


# 1.157 07-Jun-2002 eeh

Shave 10% off the time needed to flush the D$ through a bit of instruction
reordering.


# 1.156 05-Jun-2002 eeh

Handle improperly aligned stack pointers more cleanly.


# 1.155 04-Jun-2002 eeh

Fix the fork trampoline to properly use the supplied tstate.


# 1.154 31-May-2002 thorpej

Make this work with an ISO C preprocessor.


Revision tags: netbsd-1-6-base
# 1.153 14-May-2002 eeh

branches: 1.153.2; 1.153.4;
Only save locals and ins in trapframes for DEBUG kernels.


# 1.152 04-May-2002 kleink

Add some comments to the CPP conditionals controlling the trap macro
definitions, to ease navigation somewhat.


# 1.151 16-Apr-2002 eeh

Make lots of routines profile-friendly and get rid of some cruft.


Revision tags: eeh-devprop-base
# 1.150 21-Mar-2002 petrov

Not needed debug stuff deleted.


# 1.149 16-Mar-2002 mrg

tell newer binutils that our use of %g2 and %g3 is OK here.


# 1.148 15-Mar-2002 eeh

Cleanup MMU initialization to prevent hangs.


Revision tags: newlock-base ifpoll-base
# 1.147 09-Feb-2002 eeh

branches: 1.147.4;
Fix microsecond calculation in microtime.


# 1.146 07-Feb-2002 eeh

Fix register allocation in microtime().


# 1.145 29-Jan-2002 eeh

Shift the UPAID in the correct direction.


# 1.144 17-Jan-2002 eeh

Be more tolerant of unaligned stack pointers.


# 1.143 17-Jan-2002 eeh

Enable block insns in bcopy and bzero.


# 1.142 16-Jan-2002 eeh

In bcopy use 32-bit comparisons in 32-bit kernels.


# 1.141 16-Jan-2002 eeh

Use correct calculation for the trapframe in softtrap for ILP32.


# 1.140 20-Nov-2001 lukem

- pull in opt_kgdb.h where necessary
- replace opt_kgdb_machdep.h with opt_kgdb.h
- defparam opt_kgdb.h:
KGDB_DEV KGDB_DEVNAME KGDB_DEVADDR KGDB_DEVRATE KGDB_DEVMODE
- move from opt_ddbparam.h to opt_ddb.h:
DDB_FROMCONSOLE DDB_ONPANIC DDB_HISTORY_SIZE DDB_BREAK_CHAR SYMTAB_SPACE
- replace KGDBDEV with KGDB_DEV
- replace KGDBADDR with KGDB_DEVADDR
- replace KGDBMODE with KGDB_DEVMODE
- replace KGDBRATE with KGDB_DEVRATE
- use `9600' instead of `0x2580' for 9600 baud rate
- use correct quotes for options KGDB_DEVNAME="\"com\""
- use correct quotes for options KGDB_DEV="17*256+0"
- remove unnecessary dependancy on Makefile for kgdb_stub.o
- minor whitespace cleanup


Revision tags: thorpej-mips-cache-base thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf
# 1.139 14-Sep-2001 thorpej

branches: 1.139.4;
Don't declare intrhand[] here -- that's taken care of in intr.c.


Revision tags: thorpej-devvp-base
# 1.138 30-Aug-2001 eeh

branches: 1.138.2;
Preliminary UltraSPARC III suport (not enabled yet).


# 1.137 13-Aug-2001 jdolecek

g/c _remque()/_insque(); use the C version in libkern


# 1.136 09-Aug-2001 eeh

Fix context masking lossage caused by last version.


# 1.135 08-Aug-2001 eeh

Clean up the trap code to handle the changes cause by supporting non-faulting
accesses. Also change the parameter order so trap frames are easy to find.


# 1.134 07-Aug-2001 eeh

Make sure C code always has ASI_PRIMARY_NOFAULT in the %asi register so
the compiler will be happy if it ever starts generating speculative loads.


# 1.133 05-Aug-2001 eeh

Add support for non-faulting loads and optimize MMU miss handling paths.


# 1.132 02-Aug-2001 eeh

Fix bcopy.


# 1.131 02-Aug-2001 eeh

Sync bzero w/libc version.


# 1.130 01-Aug-2001 eeh

Integrate fixes from userland memset.


# 1.129 31-Jul-2001 eeh

Code cleanup and optimization.


# 1.128 23-Jul-2001 eeh

Get rid of some debug code that really isn't all that useful any more.


# 1.127 19-Jul-2001 eeh

Do ignore unregistered interrupts instead of faulting.


# 1.126 16-Jul-2001 eeh

Make bcopy a 32-bit friendly.


# 1.125 11-Jul-2001 eeh

Fix problems booting 32-bit kernels and dispatching level-15 interrupts.


# 1.124 08-Jul-2001 eeh

branches: 1.124.2;
Code cleanup. Add block_disable to let you turn on block set/copy routines.


# 1.123 05-Jul-2001 eeh

New block bzero and bcopy.


# 1.122 04-Jul-2001 eeh

Replace old bcopy with a much faster version.


# 1.121 01-Jul-2001 martin

Disable axidently enabled debug code to make -current compile again.


# 1.120 30-Jun-2001 eeh

Use a newer version (still disabled) of block bcopy.


# 1.119 30-Jun-2001 eeh

Fixup fpu save restore, get rid of some unused copy functions, and add
a new bcopy.


# 1.118 21-Jun-2001 eeh

Allow multiple 4MB pages for both kernel text and kernel data.

Note: DEBUG checks will not allow accesses to the hole between
text and data segments, so you may need to update programs that
use libkvm before relocating the start of kernel data.


# 1.117 06-Jun-2001 mrg

extract the netbsd32, sunos, 32 bit svr4 and 64 bit svr4 sigcode out into
separate files, so that compat lkms can link with them as well.


# 1.116 30-May-2001 lukem

add missing #include "opt_kgdb.h"


Revision tags: thorpej_scsipi_beforemerge
# 1.115 25-Apr-2001 simonb

Spell occurred correctly.


Revision tags: thorpej_scsipi_nbase thorpej_scsipi_base
# 1.114 09-Apr-2001 eeh

Interrupt latency fix from sparc port. (Hm. One insn instead of 5).


# 1.113 07-Mar-2001 eeh

Fix inverted preprocessor logic. (Spotted by Charles.)


# 1.112 21-Feb-2001 eeh

branches: 1.112.2;
Add support for 64-bit SVR4 (Solaris 8) binaries.


# 1.111 10-Feb-2001 pk

Fix conditional for svr4 compat inclusion.


# 1.110 05-Feb-2001 eeh

Add signal trampoline for 64-bit svr4 emulations.


# 1.109 31-Dec-2000 eeh

Make INCR() atomic.


# 1.108 29-Dec-2000 eeh

pseg_get tells us whether it really needed that spare page after all.


# 1.107 07-Dec-2000 eeh

Fixup calculating where fpstate should be saved in the signal trampoline
code so it doesn't overwrite something important like the registers.


# 1.106 09-Nov-2000 eeh

Fix ILP32 bug in probe_get().


# 1.105 22-Oct-2000 pk

Restore revision 1.102.

I hope it sticks this time..


# 1.104 20-Oct-2000 eeh

Fix hang in 32-bit kernels caused by relocation of KERNBASE.


# 1.103 04-Oct-2000 eeh

Fix interrupt lossage problem and some cosmetic changes.


# 1.102 01-Oct-2000 pk

cpu_initialize: global registers aren't preserved across calls to
prom_printf(), so replace %g3 with %l7 (which isn't used despite
the `usage' comment).

Also, clean up white-space turds.


# 1.101 29-Sep-2000 eeh

This seems to fix the interrupt lossage of non-debug kernels.


# 1.100 28-Sep-2000 eeh

Fix INTR_SETUP() to properly distinguish kernel and user addresses.

Make microtime() return the correct time on %tick machines.

Re-enable debug stuff in dostart for now to detect kernel mapping issues.


# 1.99 25-Sep-2000 pk

Missing `#if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)'


# 1.98 17-Sep-2000 eeh

Make the improved %tick changes work with machines that use the counter-timer
for the clock.


# 1.97 12-Sep-2000 eeh

Fix new version of microtime.


# 1.96 11-Sep-2000 eeh

(Hopefully) fix clock skew on machines that us %tick for the clock (UIIi).


# 1.95 31-Aug-2000 eeh

Use casx instead of stx to change entries in the page table trees.


# 1.94 23-Aug-2000 eeh

Update the scheduler to the new locking scheme.


# 1.93 10-Aug-2000 eeh

Fix signal delivery.


# 1.92 02-Aug-2000 eeh

Get kernel profiling to work. Now if only gprof worked....


# 1.91 01-Aug-2000 eeh

Overhaul cache flush code and coredump code.


# 1.90 25-Jul-2000 pk

Re-instate a couple of delay slot NOPs marked `XXX spitfire bug?'


# 1.89 24-Jul-2000 mycroft

Optimization to pmap_zero_page(): we only need to use the first 16 FP regs,
as in bzero().


# 1.88 24-Jul-2000 mycroft

Fix a whitespace glitch.


# 1.87 24-Jul-2000 mycroft

Pull in the bzero() changes from libc for real, with a couple of kernel-
specific hacks:
* Make the bias handling depend on STKB, so it switches correctly for 32-bit
kernels.
* Use the 32-bit stw/ld for 32-bit kernels.
* Add a few `-STKB's that were missed in the previous change.


# 1.86 24-Jul-2000 pk

Cosmetic & readability:
- local label cleanup in interrupt handling code;
- in debugging sections when testing `intrdebug': use a unique
local label (97) to enhanced clarity;
- comment-out unused code;
- kill a bug as the satisfying result of doing all of the above.


# 1.85 24-Jul-2000 eeh

Fix stack issues in bzero.


# 1.84 24-Jul-2000 mycroft

Revert the previous change for now. I don't have time to debug it tonight.


# 1.83 23-Jul-2000 mycroft

Copy bzero change from libc.


# 1.82 20-Jul-2000 pk

Since `intrcnt' points to an array of long ints, reserve the appropriate
amount of space depending on _LP64. Provide macros to load/store signed
and unsigned long ints.

Also, make the `intrcnt' and `intrpending' arrays 16 entries long, as on
sparc/v9 interrupt #15 is just a regular interrupt.


# 1.81 19-Jul-2000 eeh

Fix merge problem.


# 1.80 19-Jul-2000 eeh

Disable interrupt interlock using ih->ih_pending field. Seems to cause
more problems than it solves.


# 1.79 19-Jul-2000 eeh

Miscellaneous cleanup.


# 1.78 18-Jul-2000 pk

Correct args usage comment in probeget.
Whitespace cleanup.


# 1.77 18-Jul-2000 pk

probeget: 9 -> 0x9


# 1.76 18-Jul-2000 pk

If `ih_pending' is set simply return from the trap, don't schedule another
soft interrupt.


Revision tags: mrg-merge-1-5-top
# 1.75 18-Jul-2000 pk

openfirmware: don't lower %pil


# 1.74 17-Jul-2000 pk

Kill typos in interrupt code.


# 1.73 17-Jul-2000 pk

probeget: do the same song and dance as ld*a() macros in ctlreg.h do.


# 1.72 14-Jul-2000 eeh

Move some macro definitions out of genassym and into locore.s


# 1.71 08-Jul-2000 mrg

backout part of previous: turn off intrdebug, and another debug message


# 1.70 07-Jul-2000 pk

Changes for readability:
- #define LP64 dependent STACKFRAME macro once
- use a LOAD_ASCIZ macro for setting up the format string
for debug messages.


# 1.69 07-Jul-2000 eeh

Temporary fix to prevent the clock from stopping on UIIi machines.


# 1.68 03-Jul-2000 eeh

Prevent interrupts from being posted if they are active and deprecate polled
interrupts. This seems to eliminate the spurious interrupts.


# 1.67 02-Jul-2000 eeh

Clean up interrupt handling some more.


# 1.66 30-Jun-2000 eeh

Fix interrupt delivery on UltraSPARC IIi machines.


# 1.65 24-Jun-2000 eeh

With these changes the kernel seems almost stable again.


# 1.64 24-Jun-2000 eeh

More VM cleanup:

Move the cpu_info structure above the interrupt stack so it won't
get corrupted if the stack overflows.

Flush the D$ before and after all MMU bypass accesses since the
D$ latches all of those.


# 1.63 23-Jun-2000 eeh

Make probeget() and probeset() really work for a change.


Revision tags: netbsd-1-5-base
# 1.62 19-Jun-2000 eeh

branches: 1.62.2;
Have separate data and text segments, make text read-only.


# 1.61 12-Jun-2000 eeh

Start reorganizing the kernel for MULTIPROCESSOR support.


# 1.60 31-May-2000 thorpej

Add a comment about needing to initialize p_cpu when multiple
processors are supported.


Revision tags: minoura-xpg4dl-base
# 1.59 26-May-2000 thorpej

branches: 1.59.2;
First sweep at scheduler state cleanup. Collect MI scheduler
state into global and per-CPU scheduler state:

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

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

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

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

Tested on i386 and Alpha. Changes are mostly mechanical, but apologies
in advance if it doesn't compile on a particular platform.


# 1.58 26-May-2000 thorpej

Don't set `runtime' here; it's done at the end of mi_switch().
cvS: ----------------------------------------------------------------------


# 1.57 26-May-2000 thorpej

Introduce a new process state distinct from SRUN called SONPROC
which indicates that the process is actually running on a
processor. Test against SONPROC as appropriate rather than
combinations of SRUN and curproc. Update all context switch code
to properly set SONPROC when the process becomes the current
process on the CPU.


# 1.56 22-Apr-2000 eeh

If we trap due to a bad kernel stack, try to switch to the interrupt strack
before breaking into the debugger.


# 1.55 18-Apr-2000 eeh

Prevent the system from getting watchdog reset by returning directly to user
mode if restoring the user window traps. Also reduce the time we run with
%tl>0.


# 1.54 13-Apr-2000 eeh

Apparently gas 2.9.5 (don't ask) does not like to add values to %lo()
directives so move the additions inside %lo() to make it happy.
Hopefully this won't break older versions.


# 1.53 10-Apr-2000 mrg

- fix a speeling error
- rename some numbered labels to be a bit less confusing.
- remove dead code
- fix a debug error message (argh!)


# 1.52 10-Apr-2000 pk

Get a kernel without DDB to build.


# 1.51 16-Mar-2000 eeh

Revamp interrupts again:

Fix a bug causing interrmittent panics in interrupt dispatch.
Use interrupt vectors for softints.
Add a new send_softint interface.
Improved D$ flushing.
Improve traptrace and other debugging enhancements.


Revision tags: chs-ubc2-newbase
# 1.50 16-Jan-2000 eeh

Interrupt handlers return zero if they didn't handle the interrupt.


# 1.49 10-Jan-2000 eeh

Add debugger single-stepping and fix interrupt dispatch bugs.


# 1.48 30-Dec-1999 eeh

Lots of changes:

remove ffs()
add bzero that uses block store insns
save %gsr to fpstate
revert to physical accesses for pmap_zero_page so we don't
have conflicting page mappings
general cleanup.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base fvdl-softdep-base
# 1.47 06-Nov-1999 eeh

Handle zero length properly in copyinstr() copyoutstr() and copystr().


Revision tags: comdex-fall-1999-base
# 1.46 11-Oct-1999 eeh

branches: 1.46.2; 1.46.4;
Update to post 1.4.


# 1.45 05-Oct-1999 eeh

branches: 1.45.2;
Make broken versions of gas happy by using sethi/or instead of set for
(negative) addresses.


# 1.44 17-Sep-1999 thorpej

Centralize the declaration and clearing of `cold'.


Revision tags: chs-ubc2-base
# 1.43 18-Jul-1999 eeh

More fun with pmap.


# 1.42 21-Jun-1999 eeh

Improve TRAPTRACE. Add FLTRACE that only tracks MMU faults.


# 1.41 05-Jun-1999 eeh

Make pbrobeget() and probeset() work for 64-bit values as well. To do this
the arguments are changed so the address is first and the ASI second so we
can have the address in %o0:%o1 and not worry about unused registers.

Also a bit of copyright cleanup.


# 1.40 05-Jun-1999 mrg

update a commit slightly.


# 1.39 30-May-1999 eeh

Add code to support using %tick as the system clock if no "counter-timer" node
is found.


# 1.38 09-May-1999 eeh

Fixup non-DEBUG kernels.


# 1.37 29-Apr-1999 christos

Add sunos_sigcode (32 bit only)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.36 26-Mar-1999 eeh

branches: 1.36.4;
COMPAT_SPARC32 -> COMPAT_NETBSD32


# 1.35 25-Mar-1999 mrg

clean and up make compile


# 1.34 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.33 22-Mar-1999 eeh

Need to set up the pointers properly for partial FPU register stores.


# 1.32 22-Mar-1999 eeh

Flush D$ on bypass accesses.


# 1.31 28-Feb-1999 eeh

Use block load/store in pmap_zero_page()/pmap_copy_page().


# 1.30 17-Feb-1999 eeh

Let's test out vectored interrupts.


# 1.29 15-Feb-1999 hubertf

RCS ID police


# 1.28 11-Feb-1999 mrg

fix a comment pasto.


# 1.27 11-Jan-1999 eeh

Finally fixed 64-bit signal trampoline.


# 1.26 10-Jan-1999 eeh

Handle the symbol table properly in a 32-bit kernel that was booted from a
64-bit bootloader.


# 1.25 09-Jan-1999 eeh

More signal fixup.


Revision tags: kenh-if-detach-base
# 1.24 26-Nov-1998 mycroft

Sync kcopy() with 32-bit SPARC version.


# 1.23 16-Nov-1998 eeh

Fixup the last broken bits of the signal handling code.


Revision tags: chs-ubc-base
# 1.22 08-Oct-1998 eeh

Fix more syscall32 and signal breakage.


# 1.21 22-Sep-1998 eeh

More fixup in the signal area.

64-bit syscall cleanup.

Add emulation for some new FPU insns: conversion to 64-bit long int and
conditional moves.


# 1.20 17-Sep-1998 thorpej

SYS_sigreturn -> SYS___sigreturn14.


# 1.19 13-Sep-1998 eeh

Fixup signal changes (hopefully). However SUN_COMPAT is likely broken by
this and I don't know how to fix it.

We can now exec a 64-bit init through a really ugly hack (don't ask.)


# 1.18 11-Sep-1998 eeh

Add labels for the compat_sparc32 signal trampoline and break -- er -- fix
suword and fuword.


# 1.17 09-Sep-1998 eeh

Don't use %tick for microtime on 32-bit kernels -- breaks gettimeofday.


# 1.16 09-Sep-1998 thorpej

Adjust for the new "reaper" kernel thread: do not free the vmspace and
u-area in machine-dependent code. Instead, call exit2() to schedule
the reaper to free them for us, once it is safe to do so (i.e. we are
no longer running on the dead proc's vmspace and stack).


# 1.15 07-Sep-1998 eeh

Fix data corruption problem caused by broken debug code.


# 1.14 07-Sep-1998 eeh

Add new 64-bit trap vectors.


# 1.13 06-Sep-1998 eeh

32-bit fixup.


# 1.12 06-Sep-1998 eeh

Disable some debug stuff.


# 1.11 05-Sep-1998 eeh

It slices. It dices. It does everything except exec a sparc32_compat init.


# 1.10 02-Sep-1998 eeh

Periodic update: now starts probing devices.


# 1.9 30-Aug-1998 eeh

Some more 64-bit cleanup. Now everything compiles.


# 1.8 29-Aug-1998 eeh

Some more 64-bit-ification.


# 1.7 27-Aug-1998 eeh

Add 64-bit pmap support:

Moved from a two level 512/1024 entry setup mapping 32 (9/10/13) bits
respectively to a three level 1024/1024/1024 entry setup mapping 43
(10/10/10/13) bits. In 32-bit mode we waste about 1/12 pages mapping the high
11 bits. We also only manage 43 of the possible 44 bits of virtual address
space, wasting half of it. Oh well, maybe we'll do better next revision.


Revision tags: PMAP32
# 1.6 26-Aug-1998 mrg

panicstack: is needed outside of DEBUG. use _C_LABEL, and printf not db_printf (incase no ddb!)


# 1.5 13-Aug-1998 eeh

Merge paddr_t changes into the main branch.


Revision tags: eeh-paddr_t-base
# 1.4 07-Jul-1998 eeh

branches: 1.4.2;
General update:

Added genassym.cf
Removed lderr which should never have gotten in
Removed lots of dead code from locore.s
Added some softint stuff to intr.c
Added support for halt -p
esp and le both use bus_dmamap_*() functions now
instead of kdvma_mapin()
groundwork for PCI (but we still have no drivers for
any sun4u PCI devices)


# 1.3 04-Jul-1998 jonathan

defopt DDB.


# 1.2 26-Jun-1998 thorpej

defopt COMPAT_SVR4


# 1.1 20-Jun-1998 eeh

branches: 1.1.1;
Initial revision


# 1.421 18-Jul-2019 palle

sun4v: added some missing comments to the code in pcbspill


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 1.420 07-Apr-2019 mrg

make trap 0x70 a TRAP() not UTRAP(). we should be able to handle
fast ECC error as a normal trap, and i saw this once a few years
ago but it never repeated so i haven't been able to test this.


# 1.419 08-Feb-2019 palle

sun4v: Improve comment for next_stick_init() - no functional changes


# 1.418 08-Feb-2019 palle

sun4v: initialize %stickcmpr properly when establishing interrupt - fixes issue seen on newer sun4v/SPARC-T5 system where the interrupt never fires.


# 1.417 08-Feb-2019 palle

sun4v: introduce macros for handling spill traps from userlevevel @ traplevel 1 (from OpenBSD) - spill traps at level 1 from userspace now works better


# 1.416 08-Feb-2019 palle

sun4v: add comment documenting the contents of the %g2 register - no functional changes


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126
# 1.415 04-Nov-2018 palle

Ensure that the 64-bit condition codes are used instead of the 32-bit condition codes. ok martin@


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.414 26-May-2018 palle

branches: 1.414.2;
next_stick() - fix typy in comment: tick->stick


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.413 11-Apr-2018 palle

sun4v: handle MMU-related traps properly when they occur at trap level 1. This fixes issues when user-level LWPs access the user-level stack


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 1.412 26-Aug-2017 palle

branches: 1.412.2;
sun4v: Avoid touching the %tick_cmpr register which is not present on never systems (Oracle SPARC Architecture 2011 and beyond). Based on code from OpenBSD locore.s revision 1.177. Tested on both sun4u (qemu and USIII) and sun4v (qemu and T5-2). ok martin@


Revision tags: netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2
# 1.411 06-May-2017 palle

sun4v: The %ver register is not available on sun4v - use GET_MAXCWP introduced in rev. 1.361. Verified using qemu (sun4u and sun4v) and on real sun4v hw (t2000)


Revision tags: prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.410 18-Apr-2017 palle

branches: 1.410.2;
sun4v: Add handling of trap 0x06c @ trap level 1 - based on code from OpenBSD, but slightly adapted to NetBSD. verified using qemu


Revision tags: jdolecek-ncq-base pgoyette-localcount-20170320
# 1.409 19-Feb-2017 palle

sun4v: rft_user needs special handling (a manual fill) since the restore instruction may cause the number of trap levels to exceed the maximum for sun4v - inspired by code from the the openbsd rft_user code path - verified using qemu for both sun4u and sun4v


# 1.408 10-Feb-2017 palle

sun4v: Added handling of trap type 0x034 (address alignment error) + fixed typo mmfsa -> mmufsa. Verified for both sun4u and sun4v using qemu.


Revision tags: nick-nhusb-base-20170204
# 1.407 30-Jan-2017 palle

sun4v: Hook up syscall handling to the trap table. Verified using qemu for both sun4u and sun4v.


# 1.406 27-Jan-2017 palle

sun4v: implement missing handling of itsb traps 0x008 and 0x009. Based on code from OpenBSD. Tested using qemu.


Revision tags: bouyer-socketcan-base
# 1.405 07-Jan-2017 palle

branches: 1.405.2;
sun4v: slowtrap() now selects normal globals properly on both sun4u and sun4v platforms. Verified using qemu for both sun4u and sun4v systems


Revision tags: pgoyette-localcount-20170107
# 1.404 05-Jan-2017 palle

sun4v: TRAP_SETUP() updated to set mmu context id properly for both sun4v and sun4u platforms. Verified using qemu for both sun4u and sun4v systems


# 1.403 04-Jan-2017 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x00-0x23 and 0x28-0x30


# 1.402 29-Dec-2016 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x32-0x7f


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.401 20-Sep-2016 nakayama

Fix RAS for 32-bit kernels. trapframe is always 64-bit.


Revision tags: localcount-20160914
# 1.400 23-Aug-2016 palle

sun4v: rework sun4v_datatrap so it works properly when running on a T2-based system like T5120 - for some reason %tl is 0 when entering sun4v_datatrap causing a crash (sir instruction), so ignore the %tl value for now upon entry to sun4v_datatrap - with this fix both T1 and T2 based systems reach the same point - hangs in rft_user after the init process is started


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726
# 1.399 18-Jul-2016 palle

sun4v: handle device interrupts properly - both legacy (sysino) and cookies


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 1.398 04-Jun-2016 palle

branches: 1.398.2;
sun4v: rtf_user now uses macros GET_MMU_CONTEXTID and SET_MMU_CONTEXTID. Tested on sun4u (QEMU) and sun4v (T2000). Parts from OpenBSD.


Revision tags: nick-nhusb-base-20160529
# 1.397 18-May-2016 nakayama

Decrement %tl in trap handler not to make it zero unconditionally
for the nested trap, and remove useless mov.


# 1.396 17-May-2016 palle

sun4v: Implement missng MMU protection trap handling - mostly from OpenBSD


# 1.395 16-May-2016 palle

Avoid assembler-specific defines by using the export keyword in genassym.cf instead


# 1.394 15-May-2016 nakayama

%g1 is not preserved across function call, so load it before
return_from_trap.


# 1.393 13-May-2016 palle

sun4v: add missing implementation of sun4v_datatrap_tl0 so data_access_fault() is called - mostly from OpenBSD


# 1.392 13-May-2016 nakayama

- ci_paddr is always 64-bit.
- intrlev is array of pointer.
- ih_ack is pointer.


# 1.391 10-May-2016 palle

sun4v: make device interrupts work. Introduce a new intrhand_alloc() function for allocation of interrupt handlers and adapt to this. Parts from OpenBSD. ok martin@


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.390 09-Mar-2016 nakayama

32-bit kernels use 32-bit stack.


# 1.389 03-Mar-2016 palle

sun4v: rft_kernel should pay attention to the number of register windows that can be restored. We cannot rely on fill traps to occur, since sun4v only has two trap levels available in privileged mode. Based on code from OpenBSD. ok martin@


# 1.388 14-Feb-2016 palle

sun4v: add breakpoint trap entry to the sun4v trap table


# 1.387 03-Feb-2016 palle

sun4v: extend dmmu_set_secondary_context() to handle both sun4u and sun4v. ok martin@


Revision tags: nick-nhusb-base-20151226
# 1.386 06-Nov-2015 martin

Basically revert r1.246 of locore.s and r1.73 of vm_machdep.c:

Remove special case handling for userland lwps from cpu_lwp_fork,
instead do it in lwp_trampoline when we first return to userland.

which was a stupid idea - since we did now set all fork child's %tstate
(and thus %pstate when back in userland) to the current kernel's userland
default. This meant we lost the address mask bit for 32bit processes and
all memory model details for 64bit ones.

Move it back to cpu_lwp_fork and fix the condition to only do it once when
forking init.


# 1.385 05-Nov-2015 martin

Most of the time return_from_trap already got called with tf->tf_tstate
loaded in register %g1 - make it so for two more callers and remove
the reload of that value.


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606 nick-nhusb-base-20150406
# 1.384 05-Apr-2015 palle

sun4v: Ensure that the TTEs CP and CV bits are the same (both set) for the primary cpu and secondary cpus INTSTACK mappings


# 1.383 01-Apr-2015 palle

sun4v: Implement handling of cpu_mondo trap - from OpenBSD - tested using the Legion simulator


# 1.382 04-Mar-2015 palle

sun4v: revert some of the logic introduced in revision 1.378 - flushw is not necessary on sun4v (OpenBSD patches the flushw instruction to a nop instruction) - with these changes the kernel reaches cpu_boot_secondary_processors() when running in the Legion simulator (crashes due to missing handling of cpu_mondo_trap)


# 1.381 02-Mar-2015 nakayama

prom_printf converts "\n" to "\r\n" internally, so omit "\r".


# 1.380 02-Mar-2015 nakayama

PANICSTACK is a pointer itself, not a pointer to pointer.


# 1.379 02-Mar-2015 nakayama

Use panic stack temporarily for calling prom_printf in a trap
handler.

It seems that openfirmware cannot handle over 4GB pointers, and
stack pointers may point to over 4GB since VA layout was rearranged
by rev 1.33 of vmparam.h. Therefore, use panic stack to avoid
panicking in OF_write used by prom_printf.


# 1.378 23-Feb-2015 palle

sun4v: sparc_interupt - ensure that the trap level and globals level are the same when the flushw instruction is issued - othwise warnings occur when using the sun4v Legion simulator.


Revision tags: nick-nhusb-base
# 1.377 26-Oct-2014 palle

branches: 1.377.2;
sun4v: Create CLEANWIN0 and CLEANWIN1 macros for handling clean window traps on both sun4u and sun4u (based on the original code inlined in the sun4u trap table). Update trap tables accordingly for both sun4u and sun4v. Ok martin@


# 1.376 24-Oct-2014 nakayama

Fix typo in comment.


# 1.375 18-Oct-2014 snj

src is too big these days to tolerate superfluous apostrophes. It's
"its", people!


# 1.374 15-Oct-2014 palle

sun4v: fixed bug causing the real address to be incorrectly calculated as zero


# 1.373 24-Sep-2014 palle

sun4v: add code to enable startup of secondary cpus on both sun4u and sun4v systems - ok martin@


# 1.372 04-Sep-2014 palle

sun4v: All cpus must be setup with a TSB descriptor, so pmap_setup_tsb_sun4v() must take a pointer to the TSB descriptor


# 1.371 31-Aug-2014 palle

sun4v: Split the NORMAL_GLOBALS and ALTERNATE_GLOBALS macros to _SUN4U and _SUN4V variants. Rework the return_from_trap logic to use the new variants so it is possible to use a global register as scratch register.


# 1.370 14-Aug-2014 nakayama

Add missing delay slot in DEBUG kernel.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.369 30-Jul-2014 palle

branches: 1.369.2;
Fix ALTERNATE_GLOBALS so it at least works on sun4u - using a scratch register is not a good idea...


# 1.368 27-Jul-2014 palle

sun4v: Introduce a new macro ALTERNATE_GLOBALS (matching NORMAL_GLOBALS). Two new helper macros ENABLE_INTERRUPTS and DISABLE_INTERRUPTS are also created. With these changes the GENERIC.UP kernel will reach rootmount on sun4v systems - ok martin@


# 1.367 26-Jul-2014 palle

Improved the NORMAL_GLOBALS macro in the sun4u case, so only the relevant bit (AG) in %pstate is affected - ok martin@


# 1.366 24-Jul-2014 palle

sun4v: add missing spill/fill handling for trap level 1 + cosmetic changes to comments for trap level 0 entries


# 1.365 19-Jul-2014 palle

sun4v: Introduce a NORMAL_GLOBALS macro - first used in sparc_interrupt - other relevant uses will be handled as the sun4v work is progressesing - ok martin@


# 1.364 16-Jul-2014 palle

sun4v: Introduce SET_MMU_CONTEXTID macro for setting the mmu context id on both sun4u and sun4v


# 1.363 13-Jul-2014 palle

sun4v: add interrupt handling to sun4v trap table


# 1.362 13-Jul-2014 palle

Bugfix: add missing cmp instruction to GET_MAXCWP macro


# 1.361 30-Jun-2014 palle

sun4v: The maximum number of register windows is a constant and thus not available via the %ver register (sun4u only). Introduce a macro GET_MAXCWP that handles this, so cpu_switchto() works properly on sun4v. Other relevant reference to %ver can be adapted to use GET_MAXCWP as the sun4v port progresses. OK martin@


# 1.360 31-May-2014 palle

sun4v: added missing dtsb miss handling for trap level 1 - with this update the kernel now reaches configure() on sun4v systems


# 1.359 30-May-2014 palle

Remove debugging code introduced by accident in locore.s revision 1.357


Revision tags: yamt-pagecache-base9 rmind-smpnet-nbase rmind-smpnet-base
# 1.358 05-May-2014 palle

sun4v: the trap base address should be assigned to %l1 so %tba is properly setup later in the code - now the kernel gets as far as printing the copyright disclaimer, kernel version and total and available memory before crashing


# 1.357 21-Apr-2014 palle

sun4v: Update comment: modified -> access


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.356 21-Feb-2014 palle

branches: 1.356.2;
sun4v: Rename TLB_ defines to SUN4U_TLB_ so entries created using TSB_DATA() are properly setup for sun4u and sun4v. Relocate the cputyp variable from autoconf.c to locore.s and make it const in param.h so optimized code can be generated. Parts from OpenBSD. Optimization suggested by nakayama@. OK martin@, mrg@, nakayama@


# 1.355 31-Jan-2014 tsutsui

defined(LKM) -> defined(MODULAR)


# 1.354 26-Jan-2014 palle

sun4v: Add handling of spill/fill and dtsb miss traps (with a XXX to be handled later)


# 1.353 07-Jan-2014 palle

sun4v: trap table setup - currently populated with dummy entries which will be properly implemented later - parts from OpenBSD - OK martin@


# 1.352 29-Dec-2013 nakayama

Make buildable w/o options SUN4V.


# 1.351 27-Dec-2013 palle

a) make the hunt through the cpus list more generic b) sun4v: ensure that the interrupt stack is mapped permanently and the TSB is setup properly - parts from OpenBSD. OK martin@


# 1.350 06-Dec-2013 nakayama

Increase an interrupt depth only in the case of hardware interrupts,
and remove the ci_idepth trick in softint_fastintr.

Fixes the following diagnostic panic reported in port-sparc64.

panic: kernel diagnostic assertion "!cpu_intr_p()" failed: file
"../../../../kern/subr_xcall.c", line 351


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 1.349 24-May-2013 nakayama

branches: 1.349.2;
Disable interrupts after calling data_access_error as with
data_access_fault.


# 1.348 28-Apr-2013 nakayama

Use macros in machine/asm.h instead of locally defined, and
introduce CASPTRA for casxa/casa.


Revision tags: agc-symver-base
# 1.347 23-Jan-2013 martin

Fix sparc64_ipi_ccall by adding proper trap setup.
Fixes xcall(9) problems, as exposed by pserialize(9). Noticed by
J. Hannken-Illjes, cause pointed out by Takeshi Nakayama.


# 1.346 23-Jan-2013 martin

Sligthly clean up the (by default unused) #ifdef TRAPS_USE_IG


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.345 10-Nov-2012 nakayama

Revise comment.


# 1.344 10-Nov-2012 nakayama

Use macro instead of magic number.


# 1.343 09-Nov-2012 nakayama

Make setstick() and getstick() to inline functions.


# 1.342 08-Nov-2012 macallan

use system tick timer instead of %tick on UltraSPARC-III-ish CPUs
review & fixes by Takeshi Nakayama


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.341 17-Mar-2012 mrg

branches: 1.341.2;
port the corrected ECC error handling code from freebsd. i noticed my U10
took one of these and then hang. it shouldn't hang, there's a 'sir' here that
doesn't seem to reset properly. oh well.

tested by simulated a trap via 'ta 0x10' and considering that the same, but
it hasn't been tested against a real ECC error yet.


Revision tags: jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base4
# 1.340 03-Mar-2012 nakayama

Fix the root cause of the hack "disable optimizations for uvm_bio.c
on 32 bit kernels".

gcc converts a division in the calculation of UBC_UMAP_ADDR macro
to multiplication (smul or combination of add/sll), and the
register of its result contains a garbage in upper 32 bits (the
upper 32 bits of smul/add/sll's result isn't zero cleared).

Then it passes to pseg_get{,_real} through pmap_extract without the
zero clear of upper 32 bits in the optimization case. So the
result of pseg_get and pmap_extact sometimes gets screwed up.


Revision tags: jmcneill-usbmp-base5 jmcneill-usbmp-base3
# 1.339 19-Feb-2012 rmind

Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.


Revision tags: jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.338 04-Sep-2011 nakayama

branches: 1.338.2; 1.338.6; 1.338.8;
ih_pil is an interrupt level, not an interrupt mask.


# 1.337 27-Jul-2011 nakayama

ivec is assigned to hardware, so count its event counter up in
interrupt_vector, not in softint, and do some optimization.


# 1.336 20-Jul-2011 macallan

add per ivec event counters


# 1.335 12-Jul-2011 mrg

rename sparc64 BLOCK_SIZE and BLOCK_ALIGN to have SPARC64_ prefixes.
for the assembler files, define the old names to the new names
since using the new names cause ugliness due to longer identifer
names, and reduces churn.

fixes build issues in dtv and vaguely makes <machine/psl.h> slightly
less name-space invasive.


# 1.334 18-Jun-2011 nakayama

Add fast softint(9) support for sparc64.

Reviewed on port-sparc64.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 1.333 12-May-2011 mrg

branches: 1.333.2;
first steps towards fujitsu SPARC64 support:

- SPARC64 systems have interrupts with upto 14 bits set, but we only look
at the first 11 bits. trim non IPI interrupts to 11 bits


Revision tags: uebayasi-xip-base7 bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 jym-xensuspend-nbase jym-xensuspend-base
# 1.332 20-Dec-2010 matt

branches: 1.332.2;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.


Revision tags: uebayasi-xip-base6 uebayasi-xip-base5 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 1.331 10-Jul-2010 nakayama

Clear the upper word explicitly before combining two 32-bit values to 64-bit
on 32-bit kernels.


# 1.330 23-May-2010 martin

Split copy related functions out of locore.s into copy.S, move functions
only needed on multiprocessors into mp_subr.S.


# 1.329 17-May-2010 martin

Simplify primary CPU startup slightly by using the fact that our cpuinfo's
curpcb pointer points to the uarea/pcb of lwp0 and by remembering the pointer
to this cpuinfo, thus avoiding a few CPUINFO_VA references.


Revision tags: uebayasi-xip-base1
# 1.328 20-Mar-2010 chs

fix copy{in,out}{,str}() to return the error returned by uvm_fault().
fixes PR 41813.


Revision tags: yamt-nfs-mp-base9
# 1.327 10-Mar-2010 mrg

branches: 1.327.2;
XXX: workaround we'd like to remove when pmap / uvm locking is cleaned up:

- rename pseg_get() and pseg_set() to pseg_get_real() and pseg_set_real().
- if USE_LOCKSAFE_PSEG_GETSET is defined, which it current is by default,
define pseg_[gs]et() in terms of functions that take a new pseg_lock
mutex at IPL_VM while calling into the real functions.

this seems to avoid the pseg_set() crashes we've seen:
1 - spare needed, when pseg_get() just worked for this pmap
2 - the 2rd ldxa via ASI_PHYS_CACHED in pseg_set() loads garbage
into %o4, and causes the 3rd ldxa to fault


# 1.326 08-Mar-2010 mrg

blast_dcache() SMP friendly:

- blast_dcache() becomes sp_blast_dcache(dcache_size, dcache_line_size)
- new smp_blast_dcache(sparc64_cpuset_t) that blasts the D$ on this cpuset
- sparc64_ipi_blast_dcache() to support the above
- in pmap_remove_all(), when freeing mmu contexts for this pmap, mark
the set of cpus to blast the d$ on as well and convert the
blast_dcache() call into smp_blast_dcache() on the cpus who ran this
pmap, or, sp_blast_dcache(dcache_size, dcache_line_size)
- convert the remaining blast_dcache() in machdep.c to sp_blast_dcache()
- in pmap_destroy()/pmap_remove_all() take the pmap_lock() always since
we assert it is held always.

with these changes, NFS builds on the U60 seem to be stable now, and
the USIII machines also can often complete a single build.sh run now,
diskful or diskless.


reviewed by mlelstv and partially by martin, tested by martin and myself,
with some ideas from chuq as well.


# 1.325 07-Mar-2010 mrg

need _ALIGN in locore.h as well, for DEBUG kernels.


# 1.324 07-Mar-2010 mrg

gas has supported SPARC ".empty" for a long while; get rid of an
ancient workaround.


# 1.323 06-Mar-2010 mrg

move the memcpy/memset implementations out into their own file, with the
block copy versions as well. move some of the definitions in locore.s
into a new locore.h.

locore.s is almost 2000 lines shorter with this change.


# 1.322 04-Mar-2010 mrg

- in _bus_dmamap_unload(), pmap_page_protect() and pmap_clear_reference()
switch the dcache_flush_page() into a dcache_flush_page_all()
- in both pmap_kremove()/pmap_remove(), remove the blast_dcache() call
and replace it with dcache_flush_page_all()
- in pmap_get_page() [used to allocate PTP's], always call pmap_zero_page(pa)
- flush the dcache of the dst page in pmap_{copy,zero}_page() by redirecting
throught a C function that calls the (renamed) asm. the old asm code had a
comment about needing to do this...
- add a couple of membar #Sync's that the USIII manual recommends


based on discussions with chuq@, skrll@ and martin@.


these help my SB2000 / SB2500 with both disk / nfs builds and other tasks,
sometimes lasting for several hours before failing or asserting.


# 1.321 24-Feb-2010 mrg

when handing back page table pages to UVM, flush them from the dcache
on all CPUs.

idea from skrll@, and makes my disk-based SB2000 stable.

tested on U60, SB2000 and SB2500.


# 1.320 24-Feb-2010 mrg

- re-introduce sp_tlb_flush_pte() and sp_tlb_flush_all() that call
the right USI/USIII version.
- define tlb_flush_pte() in terms of sp_tlb_flush_pte() for the
!MULTIPROCESSOR case

this centralises some CPU_IS_USIII_UP() tests.


# 1.319 22-Feb-2010 mrg

move {dump,print}_[id]tlb() into a separate file.


# 1.318 22-Feb-2010 mrg

- store the maximum [id]cache size / line size for each cpu

- remove patch_kernel() since it isn't necessary and has been patching
the wrong thing in general.

- implement USIII versions of blast_icache(), dcache_flush_page() and
cache_flush_phys(). use the newly recorded cache size/line sizes.

- in winfixsave, flush the D$ with the right size index and ops. this
kills one of the wrong tag->inval patches.

- for blast_dcache(), use the newly recorded dcache_size/line_size.

- for blast_icache(), use the newly recorded cache size/line sizes.
for the USIII verison, disable the I$ while writing to ASI_ICACHE_TAG.


these changes removed several hard coded cache sizes values, some very
wrong kernel patching, and seem to make the current failure modes for
USIII less common, but not gone.


# 1.317 15-Feb-2010 mrg

- don't flush 32-bit entries for 64-bit code, it does not seem to be
necessary. #define TLB_FLUSH_LOWVA to turn it back on.
- remove the #if 0'd code in sparc64_ipi_flush_pte_usiii(), i have
verified that it is not required.
- add a missing membar #Sync to sp_tlb_flush_pte_usiii().


# 1.316 15-Feb-2010 nakayama

Fix linker error of GENERIC32 kernel.


# 1.315 15-Feb-2010 mrg

use TLB_SIZE_SPITFIRE in a couple of places, and note that the
{print,dump}_[id]tlb() versions are currently spitfire specific.


# 1.314 15-Feb-2010 mrg

introduce a new patch_kernel() and call it from the end of bootstrap().
use it to patch up TLB flush instructions that don't match for USI/II
and later. we can also hopefully use this to make GENERIC.MP minimally
expensive on single CPU machines as well.

this is the last piece needed to get GENERIC/GENERIC.MP to boot on the
USIII* machines.

idea and some initial code from openbsd.


# 1.313 13-Feb-2010 mrg

remove KTR support. it's never been a working part of netbsd src tree.


# 1.312 09-Feb-2010 wiz

Fix typo in comment.


Revision tags: uebayasi-xip-base
# 1.311 06-Feb-2010 mrg

branches: 1.311.2;
- properly map the schizo interrupt registers, so we can use the normal
virtual mappings to access them.
- with the above fxied, kill SCHIZO_BUS_SPACE_BROKEN, and introduce
an options CHEETAH for now, that disables the SPITFIRE code in locore.
- merge schizo_init() into schizo_attach() and clean up the softc a bit.


with this we are only one more step away from GENERIC booting on USIII
machines.


# 1.310 02-Feb-2010 mrg

- split sp_tlb_flush_pte() and switchtoctx() into sp_tlb_flush_pte_us()/
sp_tlb_flush_pte_usiii() and switchtoctx_us()/switchtoctx_usiii() and
implement the latter while i'm here. it works ... sometimes i think,
but also sometimes panics/hangs.
- fix a comment in sparc64_ipi_flush_pte_usiii()


# 1.309 02-Feb-2010 mrg

for now, reduce a few #ifdef SPITFIRE cases by introducing a new
ASI_DCACHE_TAG_OR_INV that is either ASI_DCACHE_{TAG,_INVALIDATE}.

increase the common code in cache_flush_phys().


# 1.308 01-Feb-2010 mrg

- sp_tlb_flush_all() becomes sp_tlb_flush_all_us() and sp_tlb_flush_all_usiii()
- sparc64_ipi_flush_pte() becomes sparc64_ipi_flush_pte_us() and
sparc64_ipi_flush_pte_usiii()
- add some commented out code to disable interrupts and raise the traplevel
in sparc64_ipi_flush_pte_usiii()
- cache_flush_phys() was missing a little of code in the cheetah case


# 1.307 01-Feb-2010 mrg

for USIII, use the new "tlb demap all" operation in sp_tlb_flush_all()


# 1.306 01-Feb-2010 mrg

remove unused icache_flush_page() implementation.


# 1.305 23-Jan-2010 mrg

remove the final uses of DATA_START.

now we can remove the 16KB space reserved at the start of the data segment,
and i now understand why i wrote this now removed comment 3.5 years ago:
"this shouldn't be needed... but kernel usually hangs without it"


# 1.304 23-Jan-2010 mrg

remove most of the code that writes debugging info DATA_START + offset.


# 1.303 23-Jan-2010 mrg

remove CHKPT() macro and uses. it's likely wrong in SMP land and probably should
be replaced with KTR-style uses if necessary.


# 1.302 23-Jan-2010 mrg

fix a comment.


Revision tags: matt-premerge-20091211
# 1.301 10-Dec-2009 rmind

Rename L_ADDR to L_PCB and amend some comments accordingly.


# 1.300 05-Dec-2009 mrg

- adjust the PA mask to the 43 bits supported by USIII.
- rework the spitfire/cheetah cache_flush_phys() to avoid several #ifdefs
- add a membar #Sync after sparc64_ipi_drop_fpstate (probably unnecessary)


# 1.299 30-Nov-2009 nakayama

sp_tlb_flush_pte for cheetah:
- restore interrupts properly in case of %tl > 0.


# 1.298 30-Nov-2009 mrg

stablize UP USIII support by blocking interrupts around sp_tlb_flush_pte()
i was seeing stack corruption while taking an interrupt in this function.

get USIII SMP mostly working by implementing the cheetah version of
sparc64_ipi_flush_pte().


SMP support is still not entirely stable. i can reproducably get a:

panic: fpusave_lwp ipi didn't

while running build.sh, when an awk process is exiting. other simple
heavy work loads do not crash for me right now.


# 1.297 30-Nov-2009 mrg

delete some no longer used code:
- smp_tlb_flush_ctx()
- smp_tlb_flush_all()
- sparc64_ipi_flush_ctx()
- sparc64_ipi_flush_all()
- sp_tlb_flush_ctx()


# 1.296 29-Nov-2009 nakayama

- calculate end PA correctly.
- wrap more spitfire specific (flushing I$) code.
- fix inverted #if condition for flushing I$ (and restore ASI_ICACHE_TAG).


# 1.295 28-Nov-2009 mrg

implement enough code to get SB2000/SB2500 booting to multiuser. does
not last long if you use it, but an idle machine has stayed up 10 hours.

- for the !SPITFIRE case, use ASI_DCACHE_INVALIDATE instead of
ASI_DCACHE_TAG when clearing tlb entries. from openbsd.

- convert some comment "! Not yet" into "WRITEME", so that attempting
to build a USIII MULTIPROCESSOR kernel fails to build until the code
is written.

- add some more WRITEME's for the above.

- implement a !SPITFIRE version of sp_tlb_flush_all(). since there are
no spare regs, for now just always increase %tl around this call. (we
could maybe store a token in %o3 along with the saved %pstate info.)


# 1.294 26-Nov-2009 matt

Kill proc0paddr. Use lwp0.l_addr instead.


# 1.293 25-Nov-2009 mrg

s/L_ADDR/L_PCB/, requested by rmind.


# 1.292 17-Oct-2009 nakayama

Wrap unused code with #if 0 which is called from #if 0'ed code.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5
# 1.291 30-May-2009 martin

cpu_setfunc() can not use lwp_trampoline, as that has additional lwp startup
semantics. Use a simpler setfunc_trampoline instead.


# 1.290 18-May-2009 nakayama

Remove random() from locore.s since it is in libkern.


# 1.289 16-May-2009 nakayama

Remove clear %tick in locore.s since it is cleared at cpu_initclocks() in
clock.c.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 nick-hppapmap-base mjf-devfs2-base
# 1.288 15-Dec-2008 mrg

restore some old "intrdebug" code, but leave it under NOT_DEBUG. most
of it works, but one that prints func/arg for each handler is not very
stable...

for now, while schizo bus space pointer accesses aren't working, add
a SCHIZO_BUS_SPACE_BROKEN option so you can build a kernel with schizo.

with this, and the prior schizo interrupt fix, you can now fail to run
/sbin/init!


Revision tags: haad-dm-base2 haad-nbase2 haad-dm-base
# 1.287 09-Dec-2008 martin

Get rid of get_maxctx() - it doesn't work on newer cpus and we will have
to find a better way for (some) sun4v machines - all sun4u use 13 bit
contexts anyway.


Revision tags: netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 ad-audiomp2-base netbsd-5-base
# 1.286 30-Oct-2008 nakayama

branches: 1.286.2; 1.286.6;
Wrap more code specific to USE_BLOCK_STORE_LOAD.


Revision tags: matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4
# 1.285 05-Oct-2008 nakayama

branches: 1.285.2;
- in flushing cache, use 32 as increment/decrement value to match the
cache line size.
- remove useless restore of %asi.
- remove nop in delay slot if we can.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 1.284 10-Jul-2008 nakayama

Use proper CCR.


# 1.283 10-Jul-2008 nakayama

sparc64_ipi_save_fpstate:
- use primary MMU context for consistency with other trap/interrupt handlers.

sparc64_ipi_save_fpstate, savefpstate:
- avoid storing fp registers as we can.

sparc64_ipi_save_fpstate, savefpstate, loadfpstate:
- remove unaligned case since buffers allocated with pool_cache are ensured
64-byte aligned.

Ok by martin@.


# 1.282 02-Jul-2008 nakayama

branches: 1.282.2;
UltraSPARCs don't have floating point queue, and reading %fq regsiter
will cause illegal instruction trap. So remove the code handling them.


# 1.281 29-Jun-2008 nakayama

Wrap IPI calls with #ifdef MULTIPROCESSOR.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.280 14-Jun-2008 nakayama

Close unterminated comment.
Fix unexpected behavior in case of loadfpstate from unaligned buffer.


Revision tags: yamt-pf42-base3
# 1.279 31-May-2008 nakayama

branches: 1.279.2;
openfirmware_exit:
- disable interrupts with %pstate.
- prepare 64-bit stack and enable 64-bit addresses for 32-bit SMP kernels.


Revision tags: hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 yamt-nfs-mp-base yamt-pf42-base
# 1.278 16-Apr-2008 nakayama

branches: 1.278.2; 1.278.4; 1.278.6;
Disable TRAPSTATS which was accidentally enabled when yamt-idlelwp branch
was merged.

Ok by martin@.


# 1.277 14-Apr-2008 nakayama

Remove sparc64_ipi_sync_tick.

Since we can use counter-timer as timecounter instead of %tick on SMP kernel,
it is not necessary to sync all CPUs %tick registers.


# 1.276 14-Apr-2008 nakayama

Add workaround for BB_ERRATA_1 on writing to TICK_CMPR register in
next_tick(). If writing to TICK_CMPR fails, we lose hardclock interrupt
on secondary CPUs.

About BB_ERRATA_1 from comment in OpenSolaris:

/*
* Writes to the TICK_COMPARE register sometimes fail on blackbird modules.
* The failure occurs only when the following instruction decodes to wr or
* wrpr. The workaround is to immediately follow writes to TICK_COMPARE
* with a read, thus stalling the pipe and keeping following instructions
* from causing data corruption. Aligning to a quadword will ensure these
* two instructions are not split due to i$ misses.
*/


# 1.275 28-Mar-2008 nakayama

Don't read fplwp content in delay slot for considering the case fplwp was
modifiled.

Reported by Chris Ross on port-sparc64.


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.274 20-Mar-2008 nakayama

- remove disabling interrupt in IPI.
- unused VA bits in MMU demap is 13 bits, not 12 bits.


# 1.273 18-Mar-2008 nakayama

Fix a race when increment an interrupt level event counter.


# 1.272 17-Mar-2008 nakayama

Fix a race condition in IPI handlers of save/drop fpstate, from OpenBSD.
Reported and tested by martin@.


# 1.271 17-Mar-2008 nakayama

Make schedintr interrupt handler per-CPU.
While there rename tickintr interrupt handler and share initialization
code with schedintr.


# 1.270 14-Mar-2008 nakayama

Improve IPI handling:
- make IPI takes two arguments.
- add IPI event counters per-CPU.
- implement IPI functions which were missing or broken.
- insert DELAY while halting primary CPU in IPI handler.


# 1.269 02-Mar-2008 nakayama

- make interrupt pending list per-CPU.
- make tickintr() MP-safe.
- remove unused port-sparc derived interrupt code.

Ok by martin@.


# 1.268 02-Mar-2008 nakayama

Don't get IPI handler argument (from bogus address), and ack IRQ twice.


# 1.267 28-Feb-2008 martin

Make TSBs and MMU contexts per-cpu.


Revision tags: nick-net80211-sync-base mjf-devfs-base hpcarm-cleanup-base
# 1.266 26-Jan-2008 nakayama

branches: 1.266.2; 1.266.6;
Fix for 32-bit kernels.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.265 15-Jan-2008 skrll

Store a sensbile PCB_PC value in snapshot - the return point.

This helps gdb somewhat.

OK'd by martin.


# 1.264 14-Jan-2008 martin

Fix register name typo/copy&pasto - %g6 is not %o6/%sp.
From OpenBSD.


Revision tags: matt-armv6-base
# 1.263 06-Jan-2008 martin

Load the next cpu_info pointer with LDPTR instead of ld.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2
# 1.262 09-Dec-2007 martin

branches: 1.262.2;
Provide cpu_intr_p(), at least for non-MULTIPROCESSOR kernels.
Based on suggestions by Andrew Doran.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.261 22-Oct-2007 martin

branches: 1.261.2; 1.261.4; 1.261.6;
Remove an unused .globl declaration


Revision tags: yamt-x86pmap-base4
# 1.260 17-Oct-2007 garbled

Merge the ppcoea-renovation branch to HEAD.

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

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

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base ppcoea-renovation-base vmlocking-base
# 1.259 09-Sep-2007 martin

branches: 1.259.4;
Make cpufrequency and friends per cpu values.
Prepare a hz tick interrupt on secondary CPUs via %tick, but do not
enable it yet, as it breaks ddb.


# 1.258 09-Sep-2007 martin

Do not ACK IPIs before we finished loading all arguments.


# 1.257 06-Sep-2007 martin

Remove the (now unused) second 64k page mapped per CPU.
From matthew green, with small changes by me. All bugs are mine.


# 1.256 25-Aug-2007 martin

branches: 1.256.2;
Remove INITSTACK completely - at the time we used to switch to it, we
already have access to all of lwp0 and it's uarea - so we can switch
to the correct lwp0 stack easily before calling main.


# 1.255 25-Aug-2007 martin

When exiting to OF, use the interrupt stack instead of INITSTACK


# 1.254 25-Aug-2007 martin

Rework cpu_mp_startup slightly:
- temporarily use the cpu's interrupt stack untill we are ready
to access non-OF-based mappings, then directly switch to the cpu's
idlelwp's uarea stack
- disable interrupts untill we are ready to call C code


# 1.253 13-Aug-2007 macallan

remove two restore without matching save


Revision tags: nick-csl-alignment-base matt-mips64-base mjf-ufs-trans-base
# 1.252 06-Jul-2007 martin

branches: 1.252.4; 1.252.8;
A few nits for 32bit SMP kernels, noticed by mrg.
While there, simplify the fpstate IPIs a bit.


# 1.251 05-Jul-2007 martin

sparc64_ipi_save_fpstate is not a leaf function - create a full grown
stack frame.


# 1.250 28-May-2007 mrg

clean up cpu_switchto() a little - no need to flushw or membar
excessively. optimise an rdpr. tested by tnn.


# 1.249 23-May-2007 martin

Fix a stupid bug in the save_fpstate ipi, which caused overwriting of
struct lwp of the lwp owning the fpu. Fix clearing the fplwp - %o0 will
not survive the call to savefpstate - duh!


# 1.248 20-May-2007 martin

Simplify tf_tstate setting when leaving for userland initially - I seem
to have confused the if with the else case of the previous C code.
Funny that it worked at all.


# 1.247 20-May-2007 martin

cpu_switchto() has to return it's first arg, always. This differs from
my reading of the documentation, but helps in the real world and seems
to be what other ports do.


# 1.246 20-May-2007 martin

Remove special case handling for userland lwps from cpu_lwp_fork, instead
do it in lwp_trampoline when we first return to userland.


# 1.245 19-May-2007 martin

cpu_idle is a leaf function, so we better "return from leaf".
Use return value from cpu_switchto for previous lwp in lwp_trampoline.
Also shamelessly steal a comment from uwe written for sparc that explains
all this.
Thanks to tnn, mrg, and uwe for helping to debug this.


# 1.244 17-May-2007 yamt

merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base ad-audiomp-base
# 1.243 22-Feb-2007 martin

branches: 1.243.4; 1.243.6; 1.243.12;
uvm.page_idle_zero now is a bool, not a 32bit value any more.


# 1.242 21-Feb-2007 mrg

shave 9 insns off the tsb setup in cpu_initialize & cpu_mp_startup.


# 1.241 21-Feb-2007 martin

Get rid of unused (thus always zero) "curlwp" variable hidden in assembler
code (C code always uses a cpuinfo based macro).


# 1.240 18-Feb-2007 martin

Make use of another call delay slot, pointed out by uwe.


# 1.239 18-Feb-2007 martin

Make use of a call delay slot and avoid a bogus EMPTY.
Spotted by Juergen Hannken-Illjes, with input from Andrew Doran and
Valeriy E. Ushakov.


# 1.238 18-Feb-2007 martin

Whitespace cosmetics


# 1.237 18-Feb-2007 martin

Backout previous: EMPTY was misused


# 1.236 18-Feb-2007 martin

Make EMPTY expand to nop with gas, as it is used to mark empty branch
delay slots.


# 1.235 15-Feb-2007 martin

branches: 1.235.2;
Fix obvious copy&pasto in SCHED_DEBUG register usage.


Revision tags: post-newlock2-merge
# 1.234 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.233 25-Dec-2006 wiz

Spell "relevant" correctly. From Zafer Aydogan.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.232 25-Oct-2006 mrg

branches: 1.232.2; 1.232.4;
- note that __idle_u should go away but doing so breaks things
- fix several comments to reality
- clean up the #ifdef NO_VCACHE code slightly
- use call instead of set/jmpl
- remove a couple of unnecessary stores to curlwp


Revision tags: yamt-splraiseipl-base2
# 1.231 18-Oct-2006 rjs

Clean up some comments. Cosmetic change to use correct structure
offset names.

Optimize out two instructions from sparc64_ipi_save_fpstate and
sparc64_ipi_drop_fpstate.


# 1.230 17-Oct-2006 mrg

allocate 128KB (as opposed to 64KB) per-cpu, and place the interrupt
stack, cpu_info structure, panicstack, idle uarea and normal kernel
stack in here. the idle uarea and kernel stack are in the 2nd 64KB
page. the interrupt stack and cpu_info structure are as the same
place in the 1st 64KB page, and the panicstack grows down from the
top of this page. update comments in param.h to suit (XXX: a lot
of these constants should move to a header file that will not pollute
the name space so much.) map these pages identically between
cpu_initialise() and cpu_mp_startup(), and deal with the two 64KB
pages in pmap_extract(). keep an unmapped 64KB page between them.

don't initialise the unused "ci_eintstack" member of the cpu_info
structure

use constants to initialise many addresses in the cpu_info structure,
consolidating these assignments from cpu0 and cpu>0

delete u0/estack0/panicstack from locore.s

clean up some wrong comments in locore.s

fix a 32bit-only bug in cpu_mp_startup().

delete 'u0' entirely.


this fixes recent random lossage seen on port-sparc64: processes
stuck in RUN state, data faults, and hangs.


# 1.229 04-Oct-2006 mrg

use call instead of set/jmpl. add an entry point for idle that expects
sched_lock to be unlocked, and use this for non-boot cpu's. complete a
comment describing how registers in idle_switch are expected to be set.


# 1.228 03-Oct-2006 mrg

use the same SAVE_LOCALS_INS definition for 32 bit and 64 bit kernels.
refactor TRAP_SETUP() a little between these two versions to be more alike.


# 1.227 03-Oct-2006 mrg

use the correct size/type for MP variables (pointers and longs).

a 32 bit MULTIPROCESSOR kernel now builds (and crashes quickly.)


# 1.226 03-Oct-2006 mrg

in the 64bit version of SAVE_LOCAL_INS, s/BIAS/STKB/ to allow future
sharing of the 32 and 64 bit versions of the {TRAP,INTR}_SETUP macros.


# 1.225 19-Sep-2006 mrg

- remove some way old FP setup/teardown code
- put the block memcpy/memset inside #ifdef USE_BLOCK_STORE_LOAD which
is (now) defined.

no functional change, same .o is generated.


# 1.224 19-Sep-2006 mrg

re-order the changes in rev 1.217 to give registers a little bit of
time to settle between usage, like it was before hand.


# 1.223 19-Sep-2006 mrg

- remove a wrong comment.
- add a new entry point for idle called idle_switch that is called by
cpu_switch() in the MP case when sched_whichqs is zero, properly
setting up the idle stack. from petrov@ via martin@.


# 1.222 19-Sep-2006 mrg

rework interrupt_vector() slightly:
- for the IPI case, avoid loading the address of intrlev into %g3
- remove some NOT_DEBUG code
- load the interrupt argument #2 in the delay slot

this removes 2 nops during interrupt processing for the normal
case, and an additional 2 ALU instructions for IPIs


# 1.221 18-Sep-2006 mrg

- sparc64_ipi_halt(): we shouldn't return from sparc64_ipi_halt_thiscpu()
so replace a branch with a 'sir'
- in #if 0 code, in sparc64_ipi_flush_pte() and sparc64_ipi_flush_ctx()
save/restore the out registers that the sp_tlb_flush_xxx() versions
around calling them
- in sp_tlb_flush_pte() and sp_tlb_flush_ctx(), replace global register
usage with out registers so that we don't clobber the (alternate)
global registers when these are called from IPI context


# 1.220 18-Sep-2006 mrg

- remove an extra 'sir' that followed one in a macro
- add some named labels to some spill/fill handlers
- remove 2 unused strings


Revision tags: yamt-splraiseipl-base
# 1.219 18-Sep-2006 martin

branches: 1.219.2;
Lazy FPU handling for the MULTIPROCESSOR case


# 1.218 16-Sep-2006 nakayama

From OpenBSD:
- reload %fprs for checking it again.
- use symbolic names for checking in %fprs.

revision 1.51
date: 2005/07/18 14:50:11; author: deraadt; state: Exp; lines: +2 -1
cache a copy of the fprs so we know what fp restore we should do after

revision 1.50
date: 2005/07/14 01:46:13; author: deraadt; state: Exp; lines: +4 -4
use symbolic names for checking in %fprs, as above


# 1.217 16-Sep-2006 nakayama

Fix a couple of %y register save/restore errors, inspired from OpenBSD.

revision 1.44
date: 2004/04/23 04:18:17; author: marc; state: Exp; lines: +5 -4

fix a couple of %y register save/restore errors
1) don't save %y in a register that is later used before restoring %y
2) always restore %y after calling a signal handler
tested by drahn@, OK pval


# 1.216 15-Sep-2006 martin

Do not bother to save fpu state when we are about to get rid of it.


Revision tags: yamt-pdpolicy-base9
# 1.215 13-Sep-2006 mrg

SMP cleanup. provide support for multiple CPUs in DDB. (SMP itself
is still not working.)

cpu.h:
- add a pointer for DDB regs in SMP environment to struct cpu_info
- remove the #defines for mp_pause_cpus() and mp_resume_cpus()
cpuset.h:
- remove CPUSET_ALL() and rename CPUSET_ALL_BUT() to CPUSET_EXCEPT()
from petrov.
db_machdep.h:
- rename the members of db_regs_t to be the same as sparc
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- redo DDB_REGS to no longer be a pointer to a fixed data structure
but to one allocated per-cpu when ddb is entered
- move a bunch of prototypes in here
intr.h:
- remove SPARC64_IPI_* macros, no longer used
db_interface.c:
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- make "nil" a 64 bit entity
- change the ddb register access methods to work in multiprocessor
environment, it is now very much like sparc does it
- in kdb_trap() avoid accessing ddb_regp when it is NULL
- update several messages to include the cpu number
- unpause other cpus much later when resuming from ddb
- rename db_lock() to db_lock_cmd(), as the sparc-like code has
db_lock as a simple lock
- remove "mach cpus" command, and replace it with "mach cpu" (which
does the same) and also implement "mach cpu N" to switch to
another cpus saved trapframe
db_trace.c:
- update for the ddb_regs -> ddb_regp change
genassym.cf:
- add TF_KSTACK as offsetof(struct trapframe64, tf_kstack)
ipifuncs.c:
- overhaul extensively
- remove all normal interrupt handlers as IPI's, we now handle
them all specially in locore.s:interrupt_vector
- add a simplelock around all ipi functions - it's not safe for
multiple cpus to be sending IPI's to each other right now
- rename sparc64_ipi_pause() to sparc64_ipi_pause_thiscpu() and,
if DDB is configured, enable it to save the passed-in trapframe
to a db_regs_t for this cpu's saved DDB registers.
- remove the "ipimask" system (SPARC64_IPI_* macros) and instead
pass functions directly
- in sparc64_send_ipi() always set the interrupt arguments to 0,
the address and argument of the to be called function. (the
argument right now is the address of ipi_tlb_args variable, and
part of the reason why only one CPU can send IPI's at a time.)
don't wait forever for an IPI to complete. some of this is
from petrov.
- rename sparc64_ipi_{halt,pause,resume}_cpus() to
mp_{halt,pause,resume}_cpus()
- new function mp_cpu_is_paused() used to avoid access missing
saved DDB registers
- actually broadcast the flush in smp_tlb_flush_pte(),
smp_tlb_flush_ctx() and smp_tlb_flush_all(). the other end may
not do anything yet in the pte/ctx cases yet...
kgdb_machdep.c:
- rework for changed member names in db_regs_t.
locore.s:
- shave an instruction from syscall_setup() (set + ld -> sethi + ld)
- remove some old dead debug code
- add new sparc64_ipi_halt IPI entry point, it just calls the C
vector to shutdown.
- add new sparc64_ipi_pause IPI entry point, which just traps into
the debugger using the normal breakpoint trap. these cpus usually
lose the race in db_interface.c:db_suspend_others() and end up
calling the C vector sparc64_ipi_pause_thiscpu().
- add #if 0'ed code to sparc64_ipi_flush_{pte,ctx}() IPI entry
points to call the sp_ version of these functions.
- in rft_kernel (return from trap, kernel), check to see if the
%tpc is at the sparc64_ipi_pause_trap_point and if so, call
"done" not "retry"
- rework cpu_switch slightly: save the passed-in lwp instead of
using the one in curlwp
- in cpu_loadproc(), save the new lwp not the old lwp, to curlwp
- in cpu_initialize(), set %tl to zero as well. from petrov.
- in cpu_exit(), fix a load register confusion. from petrov.
- change some "set" in delay branch to "mov".
machdep.c:
- deal with function renames
pmap.c:
- remove a spurious space
trap.c:
- remove unused "trapstats" variable
- add cpu number to a couple of messages


# 1.214 09-Sep-2006 mrg

significant clean up effort, largely from petrov@ via martin@.

- fix a bunch of comments for proc->lwp
- remove old TRAPTRACE, NOT_DEBUG, etc. code that has bit-rotted
- put some older DEBUG code under NOT_DEBUG
- add a bunch of new debugging/tracing code ("KTR") that depends on
other changes not yet present.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base yamt-pdpolicy-base5 chap-midi-base simonb-timecounters-base rpaulo-netinet-merge-pcb-base
# 1.213 14-May-2006 elad

branches: 1.213.6; 1.213.8;
integrate kauth.


# 1.212 12-May-2006 skrll

Fix some comments.


Revision tags: elad-kernelauth-base
# 1.211 09-May-2006 rjs

Load CPCB in cpu_mp_startup.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.210 11-Feb-2006 cdi

branches: 1.210.2; 1.210.4; 1.210.6;
ANSIfication: u_intN_t -> uintN_t, use ANSI function declarations/definitions
instead of K&R ones.


# 1.209 27-Jan-2006 cdi

branches: 1.209.2; 1.209.4;
Alter sparc64 bootstrap, catch up to ofwboot v1.9:

- Accept bootinfo structure passed down from ofwboot v1.9
- Drop kernel re-mapping code
- Use permanent 4MB mappings provided by the loader instead
- Change kernel entry address to point directly at the code instead of pointing
at the trap table's first slot. This allows the bootloader to detect
those kernels which are aware of the new boot scheme
- Due to the changes in kernel mapping code, alter secondary CPU bootstrap
code to use trampoline just like FreeBSD does (some FreeBSD code is used
here as well)


# 1.208 12-Jan-2006 cdi

Fix a typo: %g0 should be used instead of %o0 when initializing FPU in dostart:
and cpu_mp_startup:, %o0 is not even initialized at this point.


# 1.207 11-Dec-2005 christos

branches: 1.207.2;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 1.206 10-Jul-2005 christos

Re-factor syscall, and make it use syscall_{plain,fancy}.


# 1.205 31-May-2005 chs

branches: 1.205.2;
remove vestigal {,e}intr{names,cnt} symbols now that vmstat doesn't need them.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.204 12-Feb-2005 chs

branches: 1.204.4; 1.204.6; 1.204.8;
in sparc_interrupt(), wait to enable interrupts until just before calling
the handler and disable them again right after the handler returns.
we don't want another hardware interrupt coming in while we're mucking
with the list pointers. also, clear the intrhand's ih_pending pointer
before calling the handler rather than after, so that if another interrupt
comes in while the handler is running, we can put the intrhand back on
the list so it will be called again.

in send_softint(), disable interrupts via %pstate instead of %pil, so that
hardware interrupts at higher levels are blocked while we manipulate the
intrpending list. also, if the intrhand already has ih_pending set,
don't bother poking the SET_SOFTINT register again, since being on the list
implies that there is already a softint pending in the hardware.

these appear to fix PR 21750 (the "sleep forever" problem).

while I'm here, remove more vestiges of the !INTRLIST softint stuff
(code and comments). and in sparc64_ipi_flush_all(), interrupts are
already disabled so we don't need to fiddle with %pstate.


Revision tags: yamt-km-base2
# 1.203 30-Jan-2005 martin

Remove the no long usefull variants selected by undefining INTRLIST and
INTR_INTERLOCK to improve readability. Same object code generated as before.


Revision tags: yamt-km-base
# 1.202 16-Jan-2005 chs

branches: 1.202.2;
use ENTRY_NOPROFILE() for various entry points,
stack traces work better that way.


Revision tags: kent-audio1-beforemerge kent-audio1-base
# 1.201 03-Dec-2004 chs

branches: 1.201.4;
remove cache_flush_virt() and PADDRT, they're no longer used.
allocate a stack frame for blast_dcache() when profiling so it shows up.
in dcache_flush_page(), use a stride of 32 instead of 16 to match the
cache line size. correct various comments.


# 1.200 08-Nov-2004 petrov

Don't compile sparc64_ipi functions when UP.


# 1.199 25-Oct-2004 martin

No need to clear %o1 when returning a 64 bit integer from pseg_get if we
are compiling for a 64 bit kernel.


# 1.198 24-Jul-2004 nakayama

Change interrupt pending list end value to -1, to avoid linking an
interrupt handler twice.

It may fix "sleep forever" bug.


# 1.197 09-Apr-2004 petrov

Clean-up unused defines and variables.


Revision tags: netbsd-2-0-base
# 1.196 26-Mar-2004 petrov

branches: 1.196.2;
Use want_resched from cpu_info area.


# 1.195 23-Mar-2004 martin

Replace intrcnts by evcnts. XXX - needs slight tweaking for MULTIPROCESSOR.


# 1.194 14-Mar-2004 chs

checkpoint of MP work from dennis and myself. includes cross-processor
interrupt framework, a sledgehammer TLB invalidation and misc MP fixes.
doesn't work at all yet.


# 1.193 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.192 19-Jan-2004 martin

Rename switchexit to cpu_exit and g/c the old C implementation of cpu_exit.


# 1.191 18-Jan-2004 martin

Support RAS for 32bit kernels too.


# 1.190 16-Jan-2004 martin

In proc_trampoline don't bother to clear condition codes in the trap
frame, since we no longer rely on this.
While there fix a few comments.


# 1.189 08-Jan-2004 martin

Minor cleanup


# 1.188 06-Jan-2004 martin

Implement restartable atomic sequences (RAS) for sparc64.


# 1.187 06-Jan-2004 petrov

Spinup secondary cpus. Based on codes sent to me by Dennis Chernoivanov
and Chuck Silvers.


# 1.186 04-Jan-2004 jdolecek

update to recent changes - exit2() doesn't exist anymore and the
exit path always calls lwp_exit2()
pointed out Martin Husemann


# 1.185 02-Dec-2003 martin

Minor cleanup: remove unused code, sync a comment with current reality.


# 1.184 25-Nov-2003 cdi

Use per-cpu pcb, curlwp and fplwp rather than global ones. This brings
GENERIC.MP configuration to a usable state.

Approved by petrov@.


# 1.183 24-Nov-2003 cdi

Call 'proc_trampoline_mp' from 'proc_trampoline' in a multiprocessor
configuration. Fix process locking. Approved by petrov@.


# 1.182 20-Nov-2003 petrov

Remove nwindows calculation, it's not used. Set l_cpu in cpu_switch.


# 1.181 09-Nov-2003 martin

Get rid of bcopy/bzero.


# 1.180 26-Oct-2003 christos

Initial siginfo support for sparc64 (untested). COMPAT_16 sigcontext signal
delivery tested.


# 1.179 24-Aug-2003 chs

add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default. the changes
fall into two basic catagories:

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

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

originally from openbsd, adapted for netbsd by me.


# 1.178 08-Jul-2003 cdi

traceit: don't use %g7 as it is to become curcpu() register. Add comments.


# 1.177 18-May-2003 martin

branches: 1.177.2;
Make kernels with options KGDB at least compile.
Still needs some work to make it working.


# 1.176 29-Apr-2003 nakayama

Use BLOCK_ALIGN rather than BLOCK_SIZE for aligning a pointer.


# 1.175 27-Apr-2003 ragge

Preserve the symbol table in the LKM || KSYMS cases also.


# 1.174 04-Apr-2003 petrov

use branch slot in pmap_copy_page.


# 1.173 24-Mar-2003 nakayama

Divide `set' instruction in delay slot (from OpenBSD change to rev 1.30).


# 1.172 10-Feb-2003 martin

Remove some #if 0 code and a few XXX marked membars w/o proper
justification for their existence.


# 1.171 09-Feb-2003 martin

Remove left over pieces from reusing the signal trampoline for upcalls.
This should fix signal delivery for 32bit kernels.


# 1.170 05-Feb-2003 nakayama

Switch to use cycle counter (%tick) based microtime().

This is derived from alpha/microtime.c and i386/tsc_microtime.c,
and will share with both ports.

This should fix PR port-sparc64/18452.
(approved by martin)


# 1.169 04-Feb-2003 martin

Fix return value of pseg_set, which I accidently broke in rev. 1.164.

Fix register names in comment and shave off another register (hint
from uwe).


# 1.168 01-Feb-2003 martin

Rearrange register usage in pseg_set a bit and shave off %g4.


# 1.167 01-Feb-2003 martin

Remove a few #ifdef _LP64 by using STPTR/LDPTR macros.
Thanks to Matthew Green for the pointer.


# 1.166 31-Jan-2003 martin

Apply leaf procedure optimization to pseg_set (again).


# 1.165 31-Jan-2003 martin

Make the pmap count resident/wired mappings on the fly instead of
walking the page tables whenever this information is needed.

Add an option PMAP_COUNT_DEBUG to assert the new counts and the
page table walk agree.

The old solution had very bad performance impact, for example
by the high CPU load when running top(1).

Thanks to Simon Burge for pointing at the cause of the problem and
to Valeriy E. Ushakov for optimizing my simple minded assembler code.


# 1.164 27-Jan-2003 martin

Remove unused function pseg_find (which looked quite similar to
pseg_get anyway).


# 1.163 18-Jan-2003 thorpej

Merge the nathanw_sa branch.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.162 16-Jan-2003 petrov

Move dump_dtlb back under DDB.


# 1.161 15-Jan-2003 chs

fix two bugs in my last pmap rework:
- in tlb_flush_all(), don't skip TLB entries with the high bit on,
I was confused about which MMU register it was using. it's also fine
to use the last hardware context.
- in pmap_create(), don't allocate a hardware context for the new pmap.
it's unnecessary, and when this would cause us to recycle all the contexts,
it would result in the current process's context being set to 0
(ie. the kernel's context). the current process could then return to
userspace without going through the context-switch code (and thus without
having a hardware context reallocated). this would lead to user mappings
being entered in the kernel's context later, causing all sorts of trouble.
add some assertions to catch this kind of thing.


Revision tags: fvdl_fs64_base
# 1.160 25-Dec-2002 petrov

new function dump_itlb.


Revision tags: gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.159 22-Sep-2002 chs

many improvements:
- use struct vm_page_md for attaching pv entries to struct vm_page
- change pseg_set()'s return value to indicate whether the spare page
was used as an L2 or L3 PTP.
- use a pool for pv entries instead of malloc().
- put PTPs on a list attached to the pmap so we can free them
more efficiently (by just walking the list) in pmap_destroy().
- use the new pmap_remove_all() interface to avoid flushing the cache and TLB
for each pmap_remove() that's done as we are tearing down an address space.
- in pmap_enter(), handle replacing an existing mapping more efficiently
than just calling pmap_remove() on it. also, skip flushing the
TSB and TLB if there was no previous mapping, since there can't be
anything we need to flush. also, preload the TSB if we're pre-setting
the mod/ref bits.
- allocate hardware contexts like the MIPS pmap:
allocate them all sequentially without reuse, then once we run out
just invalidate all user TLB entries and flush the entire L1 dcache.
- fix pmap_extract() for the case where the va is not page-aligned and
nothing is mapped there.
- fix calculation of TSB size. it was comparing physmem (which is
in units of pages) to constants that only make sense if they are
in units of bytes.
- avoid sleeping in pmap_enter(), instead let the caller do it.
- use pmap_kenter_pa() instead of pmap_enter() where appropriate.
- remove code to handle impossible cases in various functions.
- tweak asm code to pipeline a little better.
- remove many unnecessary spls and membars.
- lots of code cleanup.
- no doubt other stuff that I've forgotten.

the result of all this is that a fork+exit microbenchmark is 34% faster
and a fork+exec+exit microbenchmark is 28% faster.


Revision tags: gehenna-devsw-base
# 1.158 18-Jul-2002 wiz

Spell 'should' correctly.


# 1.157 07-Jun-2002 eeh

Shave 10% off the time needed to flush the D$ through a bit of instruction
reordering.


# 1.156 05-Jun-2002 eeh

Handle improperly aligned stack pointers more cleanly.


# 1.155 04-Jun-2002 eeh

Fix the fork trampoline to properly use the supplied tstate.


# 1.154 31-May-2002 thorpej

Make this work with an ISO C preprocessor.


Revision tags: netbsd-1-6-base
# 1.153 14-May-2002 eeh

branches: 1.153.2; 1.153.4;
Only save locals and ins in trapframes for DEBUG kernels.


# 1.152 04-May-2002 kleink

Add some comments to the CPP conditionals controlling the trap macro
definitions, to ease navigation somewhat.


# 1.151 16-Apr-2002 eeh

Make lots of routines profile-friendly and get rid of some cruft.


Revision tags: eeh-devprop-base
# 1.150 21-Mar-2002 petrov

Not needed debug stuff deleted.


# 1.149 16-Mar-2002 mrg

tell newer binutils that our use of %g2 and %g3 is OK here.


# 1.148 15-Mar-2002 eeh

Cleanup MMU initialization to prevent hangs.


Revision tags: newlock-base ifpoll-base
# 1.147 09-Feb-2002 eeh

branches: 1.147.4;
Fix microsecond calculation in microtime.


# 1.146 07-Feb-2002 eeh

Fix register allocation in microtime().


# 1.145 29-Jan-2002 eeh

Shift the UPAID in the correct direction.


# 1.144 17-Jan-2002 eeh

Be more tolerant of unaligned stack pointers.


# 1.143 17-Jan-2002 eeh

Enable block insns in bcopy and bzero.


# 1.142 16-Jan-2002 eeh

In bcopy use 32-bit comparisons in 32-bit kernels.


# 1.141 16-Jan-2002 eeh

Use correct calculation for the trapframe in softtrap for ILP32.


# 1.140 20-Nov-2001 lukem

- pull in opt_kgdb.h where necessary
- replace opt_kgdb_machdep.h with opt_kgdb.h
- defparam opt_kgdb.h:
KGDB_DEV KGDB_DEVNAME KGDB_DEVADDR KGDB_DEVRATE KGDB_DEVMODE
- move from opt_ddbparam.h to opt_ddb.h:
DDB_FROMCONSOLE DDB_ONPANIC DDB_HISTORY_SIZE DDB_BREAK_CHAR SYMTAB_SPACE
- replace KGDBDEV with KGDB_DEV
- replace KGDBADDR with KGDB_DEVADDR
- replace KGDBMODE with KGDB_DEVMODE
- replace KGDBRATE with KGDB_DEVRATE
- use `9600' instead of `0x2580' for 9600 baud rate
- use correct quotes for options KGDB_DEVNAME="\"com\""
- use correct quotes for options KGDB_DEV="17*256+0"
- remove unnecessary dependancy on Makefile for kgdb_stub.o
- minor whitespace cleanup


Revision tags: thorpej-mips-cache-base thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf
# 1.139 14-Sep-2001 thorpej

branches: 1.139.4;
Don't declare intrhand[] here -- that's taken care of in intr.c.


Revision tags: thorpej-devvp-base
# 1.138 30-Aug-2001 eeh

branches: 1.138.2;
Preliminary UltraSPARC III suport (not enabled yet).


# 1.137 13-Aug-2001 jdolecek

g/c _remque()/_insque(); use the C version in libkern


# 1.136 09-Aug-2001 eeh

Fix context masking lossage caused by last version.


# 1.135 08-Aug-2001 eeh

Clean up the trap code to handle the changes cause by supporting non-faulting
accesses. Also change the parameter order so trap frames are easy to find.


# 1.134 07-Aug-2001 eeh

Make sure C code always has ASI_PRIMARY_NOFAULT in the %asi register so
the compiler will be happy if it ever starts generating speculative loads.


# 1.133 05-Aug-2001 eeh

Add support for non-faulting loads and optimize MMU miss handling paths.


# 1.132 02-Aug-2001 eeh

Fix bcopy.


# 1.131 02-Aug-2001 eeh

Sync bzero w/libc version.


# 1.130 01-Aug-2001 eeh

Integrate fixes from userland memset.


# 1.129 31-Jul-2001 eeh

Code cleanup and optimization.


# 1.128 23-Jul-2001 eeh

Get rid of some debug code that really isn't all that useful any more.


# 1.127 19-Jul-2001 eeh

Do ignore unregistered interrupts instead of faulting.


# 1.126 16-Jul-2001 eeh

Make bcopy a 32-bit friendly.


# 1.125 11-Jul-2001 eeh

Fix problems booting 32-bit kernels and dispatching level-15 interrupts.


# 1.124 08-Jul-2001 eeh

branches: 1.124.2;
Code cleanup. Add block_disable to let you turn on block set/copy routines.


# 1.123 05-Jul-2001 eeh

New block bzero and bcopy.


# 1.122 04-Jul-2001 eeh

Replace old bcopy with a much faster version.


# 1.121 01-Jul-2001 martin

Disable axidently enabled debug code to make -current compile again.


# 1.120 30-Jun-2001 eeh

Use a newer version (still disabled) of block bcopy.


# 1.119 30-Jun-2001 eeh

Fixup fpu save restore, get rid of some unused copy functions, and add
a new bcopy.


# 1.118 21-Jun-2001 eeh

Allow multiple 4MB pages for both kernel text and kernel data.

Note: DEBUG checks will not allow accesses to the hole between
text and data segments, so you may need to update programs that
use libkvm before relocating the start of kernel data.


# 1.117 06-Jun-2001 mrg

extract the netbsd32, sunos, 32 bit svr4 and 64 bit svr4 sigcode out into
separate files, so that compat lkms can link with them as well.


# 1.116 30-May-2001 lukem

add missing #include "opt_kgdb.h"


Revision tags: thorpej_scsipi_beforemerge
# 1.115 25-Apr-2001 simonb

Spell occurred correctly.


Revision tags: thorpej_scsipi_nbase thorpej_scsipi_base
# 1.114 09-Apr-2001 eeh

Interrupt latency fix from sparc port. (Hm. One insn instead of 5).


# 1.113 07-Mar-2001 eeh

Fix inverted preprocessor logic. (Spotted by Charles.)


# 1.112 21-Feb-2001 eeh

branches: 1.112.2;
Add support for 64-bit SVR4 (Solaris 8) binaries.


# 1.111 10-Feb-2001 pk

Fix conditional for svr4 compat inclusion.


# 1.110 05-Feb-2001 eeh

Add signal trampoline for 64-bit svr4 emulations.


# 1.109 31-Dec-2000 eeh

Make INCR() atomic.


# 1.108 29-Dec-2000 eeh

pseg_get tells us whether it really needed that spare page after all.


# 1.107 07-Dec-2000 eeh

Fixup calculating where fpstate should be saved in the signal trampoline
code so it doesn't overwrite something important like the registers.


# 1.106 09-Nov-2000 eeh

Fix ILP32 bug in probe_get().


# 1.105 22-Oct-2000 pk

Restore revision 1.102.

I hope it sticks this time..


# 1.104 20-Oct-2000 eeh

Fix hang in 32-bit kernels caused by relocation of KERNBASE.


# 1.103 04-Oct-2000 eeh

Fix interrupt lossage problem and some cosmetic changes.


# 1.102 01-Oct-2000 pk

cpu_initialize: global registers aren't preserved across calls to
prom_printf(), so replace %g3 with %l7 (which isn't used despite
the `usage' comment).

Also, clean up white-space turds.


# 1.101 29-Sep-2000 eeh

This seems to fix the interrupt lossage of non-debug kernels.


# 1.100 28-Sep-2000 eeh

Fix INTR_SETUP() to properly distinguish kernel and user addresses.

Make microtime() return the correct time on %tick machines.

Re-enable debug stuff in dostart for now to detect kernel mapping issues.


# 1.99 25-Sep-2000 pk

Missing `#if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)'


# 1.98 17-Sep-2000 eeh

Make the improved %tick changes work with machines that use the counter-timer
for the clock.


# 1.97 12-Sep-2000 eeh

Fix new version of microtime.


# 1.96 11-Sep-2000 eeh

(Hopefully) fix clock skew on machines that us %tick for the clock (UIIi).


# 1.95 31-Aug-2000 eeh

Use casx instead of stx to change entries in the page table trees.


# 1.94 23-Aug-2000 eeh

Update the scheduler to the new locking scheme.


# 1.93 10-Aug-2000 eeh

Fix signal delivery.


# 1.92 02-Aug-2000 eeh

Get kernel profiling to work. Now if only gprof worked....


# 1.91 01-Aug-2000 eeh

Overhaul cache flush code and coredump code.


# 1.90 25-Jul-2000 pk

Re-instate a couple of delay slot NOPs marked `XXX spitfire bug?'


# 1.89 24-Jul-2000 mycroft

Optimization to pmap_zero_page(): we only need to use the first 16 FP regs,
as in bzero().


# 1.88 24-Jul-2000 mycroft

Fix a whitespace glitch.


# 1.87 24-Jul-2000 mycroft

Pull in the bzero() changes from libc for real, with a couple of kernel-
specific hacks:
* Make the bias handling depend on STKB, so it switches correctly for 32-bit
kernels.
* Use the 32-bit stw/ld for 32-bit kernels.
* Add a few `-STKB's that were missed in the previous change.


# 1.86 24-Jul-2000 pk

Cosmetic & readability:
- local label cleanup in interrupt handling code;
- in debugging sections when testing `intrdebug': use a unique
local label (97) to enhanced clarity;
- comment-out unused code;
- kill a bug as the satisfying result of doing all of the above.


# 1.85 24-Jul-2000 eeh

Fix stack issues in bzero.


# 1.84 24-Jul-2000 mycroft

Revert the previous change for now. I don't have time to debug it tonight.


# 1.83 23-Jul-2000 mycroft

Copy bzero change from libc.


# 1.82 20-Jul-2000 pk

Since `intrcnt' points to an array of long ints, reserve the appropriate
amount of space depending on _LP64. Provide macros to load/store signed
and unsigned long ints.

Also, make the `intrcnt' and `intrpending' arrays 16 entries long, as on
sparc/v9 interrupt #15 is just a regular interrupt.


# 1.81 19-Jul-2000 eeh

Fix merge problem.


# 1.80 19-Jul-2000 eeh

Disable interrupt interlock using ih->ih_pending field. Seems to cause
more problems than it solves.


# 1.79 19-Jul-2000 eeh

Miscellaneous cleanup.


# 1.78 18-Jul-2000 pk

Correct args usage comment in probeget.
Whitespace cleanup.


# 1.77 18-Jul-2000 pk

probeget: 9 -> 0x9


# 1.76 18-Jul-2000 pk

If `ih_pending' is set simply return from the trap, don't schedule another
soft interrupt.


Revision tags: mrg-merge-1-5-top
# 1.75 18-Jul-2000 pk

openfirmware: don't lower %pil


# 1.74 17-Jul-2000 pk

Kill typos in interrupt code.


# 1.73 17-Jul-2000 pk

probeget: do the same song and dance as ld*a() macros in ctlreg.h do.


# 1.72 14-Jul-2000 eeh

Move some macro definitions out of genassym and into locore.s


# 1.71 08-Jul-2000 mrg

backout part of previous: turn off intrdebug, and another debug message


# 1.70 07-Jul-2000 pk

Changes for readability:
- #define LP64 dependent STACKFRAME macro once
- use a LOAD_ASCIZ macro for setting up the format string
for debug messages.


# 1.69 07-Jul-2000 eeh

Temporary fix to prevent the clock from stopping on UIIi machines.


# 1.68 03-Jul-2000 eeh

Prevent interrupts from being posted if they are active and deprecate polled
interrupts. This seems to eliminate the spurious interrupts.


# 1.67 02-Jul-2000 eeh

Clean up interrupt handling some more.


# 1.66 30-Jun-2000 eeh

Fix interrupt delivery on UltraSPARC IIi machines.


# 1.65 24-Jun-2000 eeh

With these changes the kernel seems almost stable again.


# 1.64 24-Jun-2000 eeh

More VM cleanup:

Move the cpu_info structure above the interrupt stack so it won't
get corrupted if the stack overflows.

Flush the D$ before and after all MMU bypass accesses since the
D$ latches all of those.


# 1.63 23-Jun-2000 eeh

Make probeget() and probeset() really work for a change.


Revision tags: netbsd-1-5-base
# 1.62 19-Jun-2000 eeh

branches: 1.62.2;
Have separate data and text segments, make text read-only.


# 1.61 12-Jun-2000 eeh

Start reorganizing the kernel for MULTIPROCESSOR support.


# 1.60 31-May-2000 thorpej

Add a comment about needing to initialize p_cpu when multiple
processors are supported.


Revision tags: minoura-xpg4dl-base
# 1.59 26-May-2000 thorpej

branches: 1.59.2;
First sweep at scheduler state cleanup. Collect MI scheduler
state into global and per-CPU scheduler state:

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

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

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

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

Tested on i386 and Alpha. Changes are mostly mechanical, but apologies
in advance if it doesn't compile on a particular platform.


# 1.58 26-May-2000 thorpej

Don't set `runtime' here; it's done at the end of mi_switch().
cvS: ----------------------------------------------------------------------


# 1.57 26-May-2000 thorpej

Introduce a new process state distinct from SRUN called SONPROC
which indicates that the process is actually running on a
processor. Test against SONPROC as appropriate rather than
combinations of SRUN and curproc. Update all context switch code
to properly set SONPROC when the process becomes the current
process on the CPU.


# 1.56 22-Apr-2000 eeh

If we trap due to a bad kernel stack, try to switch to the interrupt strack
before breaking into the debugger.


# 1.55 18-Apr-2000 eeh

Prevent the system from getting watchdog reset by returning directly to user
mode if restoring the user window traps. Also reduce the time we run with
%tl>0.


# 1.54 13-Apr-2000 eeh

Apparently gas 2.9.5 (don't ask) does not like to add values to %lo()
directives so move the additions inside %lo() to make it happy.
Hopefully this won't break older versions.


# 1.53 10-Apr-2000 mrg

- fix a speeling error
- rename some numbered labels to be a bit less confusing.
- remove dead code
- fix a debug error message (argh!)


# 1.52 10-Apr-2000 pk

Get a kernel without DDB to build.


# 1.51 16-Mar-2000 eeh

Revamp interrupts again:

Fix a bug causing interrmittent panics in interrupt dispatch.
Use interrupt vectors for softints.
Add a new send_softint interface.
Improved D$ flushing.
Improve traptrace and other debugging enhancements.


Revision tags: chs-ubc2-newbase
# 1.50 16-Jan-2000 eeh

Interrupt handlers return zero if they didn't handle the interrupt.


# 1.49 10-Jan-2000 eeh

Add debugger single-stepping and fix interrupt dispatch bugs.


# 1.48 30-Dec-1999 eeh

Lots of changes:

remove ffs()
add bzero that uses block store insns
save %gsr to fpstate
revert to physical accesses for pmap_zero_page so we don't
have conflicting page mappings
general cleanup.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base fvdl-softdep-base
# 1.47 06-Nov-1999 eeh

Handle zero length properly in copyinstr() copyoutstr() and copystr().


Revision tags: comdex-fall-1999-base
# 1.46 11-Oct-1999 eeh

branches: 1.46.2; 1.46.4;
Update to post 1.4.


# 1.45 05-Oct-1999 eeh

branches: 1.45.2;
Make broken versions of gas happy by using sethi/or instead of set for
(negative) addresses.


# 1.44 17-Sep-1999 thorpej

Centralize the declaration and clearing of `cold'.


Revision tags: chs-ubc2-base
# 1.43 18-Jul-1999 eeh

More fun with pmap.


# 1.42 21-Jun-1999 eeh

Improve TRAPTRACE. Add FLTRACE that only tracks MMU faults.


# 1.41 05-Jun-1999 eeh

Make pbrobeget() and probeset() work for 64-bit values as well. To do this
the arguments are changed so the address is first and the ASI second so we
can have the address in %o0:%o1 and not worry about unused registers.

Also a bit of copyright cleanup.


# 1.40 05-Jun-1999 mrg

update a commit slightly.


# 1.39 30-May-1999 eeh

Add code to support using %tick as the system clock if no "counter-timer" node
is found.


# 1.38 09-May-1999 eeh

Fixup non-DEBUG kernels.


# 1.37 29-Apr-1999 christos

Add sunos_sigcode (32 bit only)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.36 26-Mar-1999 eeh

branches: 1.36.4;
COMPAT_SPARC32 -> COMPAT_NETBSD32


# 1.35 25-Mar-1999 mrg

clean and up make compile


# 1.34 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.33 22-Mar-1999 eeh

Need to set up the pointers properly for partial FPU register stores.


# 1.32 22-Mar-1999 eeh

Flush D$ on bypass accesses.


# 1.31 28-Feb-1999 eeh

Use block load/store in pmap_zero_page()/pmap_copy_page().


# 1.30 17-Feb-1999 eeh

Let's test out vectored interrupts.


# 1.29 15-Feb-1999 hubertf

RCS ID police


# 1.28 11-Feb-1999 mrg

fix a comment pasto.


# 1.27 11-Jan-1999 eeh

Finally fixed 64-bit signal trampoline.


# 1.26 10-Jan-1999 eeh

Handle the symbol table properly in a 32-bit kernel that was booted from a
64-bit bootloader.


# 1.25 09-Jan-1999 eeh

More signal fixup.


Revision tags: kenh-if-detach-base
# 1.24 26-Nov-1998 mycroft

Sync kcopy() with 32-bit SPARC version.


# 1.23 16-Nov-1998 eeh

Fixup the last broken bits of the signal handling code.


Revision tags: chs-ubc-base
# 1.22 08-Oct-1998 eeh

Fix more syscall32 and signal breakage.


# 1.21 22-Sep-1998 eeh

More fixup in the signal area.

64-bit syscall cleanup.

Add emulation for some new FPU insns: conversion to 64-bit long int and
conditional moves.


# 1.20 17-Sep-1998 thorpej

SYS_sigreturn -> SYS___sigreturn14.


# 1.19 13-Sep-1998 eeh

Fixup signal changes (hopefully). However SUN_COMPAT is likely broken by
this and I don't know how to fix it.

We can now exec a 64-bit init through a really ugly hack (don't ask.)


# 1.18 11-Sep-1998 eeh

Add labels for the compat_sparc32 signal trampoline and break -- er -- fix
suword and fuword.


# 1.17 09-Sep-1998 eeh

Don't use %tick for microtime on 32-bit kernels -- breaks gettimeofday.


# 1.16 09-Sep-1998 thorpej

Adjust for the new "reaper" kernel thread: do not free the vmspace and
u-area in machine-dependent code. Instead, call exit2() to schedule
the reaper to free them for us, once it is safe to do so (i.e. we are
no longer running on the dead proc's vmspace and stack).


# 1.15 07-Sep-1998 eeh

Fix data corruption problem caused by broken debug code.


# 1.14 07-Sep-1998 eeh

Add new 64-bit trap vectors.


# 1.13 06-Sep-1998 eeh

32-bit fixup.


# 1.12 06-Sep-1998 eeh

Disable some debug stuff.


# 1.11 05-Sep-1998 eeh

It slices. It dices. It does everything except exec a sparc32_compat init.


# 1.10 02-Sep-1998 eeh

Periodic update: now starts probing devices.


# 1.9 30-Aug-1998 eeh

Some more 64-bit cleanup. Now everything compiles.


# 1.8 29-Aug-1998 eeh

Some more 64-bit-ification.


# 1.7 27-Aug-1998 eeh

Add 64-bit pmap support:

Moved from a two level 512/1024 entry setup mapping 32 (9/10/13) bits
respectively to a three level 1024/1024/1024 entry setup mapping 43
(10/10/10/13) bits. In 32-bit mode we waste about 1/12 pages mapping the high
11 bits. We also only manage 43 of the possible 44 bits of virtual address
space, wasting half of it. Oh well, maybe we'll do better next revision.


Revision tags: PMAP32
# 1.6 26-Aug-1998 mrg

panicstack: is needed outside of DEBUG. use _C_LABEL, and printf not db_printf (incase no ddb!)


# 1.5 13-Aug-1998 eeh

Merge paddr_t changes into the main branch.


Revision tags: eeh-paddr_t-base
# 1.4 07-Jul-1998 eeh

branches: 1.4.2;
General update:

Added genassym.cf
Removed lderr which should never have gotten in
Removed lots of dead code from locore.s
Added some softint stuff to intr.c
Added support for halt -p
esp and le both use bus_dmamap_*() functions now
instead of kdvma_mapin()
groundwork for PCI (but we still have no drivers for
any sun4u PCI devices)


# 1.3 04-Jul-1998 jonathan

defopt DDB.


# 1.2 26-Jun-1998 thorpej

defopt COMPAT_SVR4


# 1.1 20-Jun-1998 eeh

branches: 1.1.1;
Initial revision


Revision tags: isaki-audio2-base
# 1.420 07-Apr-2019 mrg

make trap 0x70 a TRAP() not UTRAP(). we should be able to handle
fast ECC error as a normal trap, and i saw this once a few years
ago but it never repeated so i haven't been able to test this.


# 1.419 08-Feb-2019 palle

sun4v: Improve comment for next_stick_init() - no functional changes


# 1.418 08-Feb-2019 palle

sun4v: initialize %stickcmpr properly when establishing interrupt - fixes issue seen on newer sun4v/SPARC-T5 system where the interrupt never fires.


# 1.417 08-Feb-2019 palle

sun4v: introduce macros for handling spill traps from userlevevel @ traplevel 1 (from OpenBSD) - spill traps at level 1 from userspace now works better


# 1.416 08-Feb-2019 palle

sun4v: add comment documenting the contents of the %g2 register - no functional changes


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126
# 1.415 04-Nov-2018 palle

Ensure that the 64-bit condition codes are used instead of the 32-bit condition codes. ok martin@


Revision tags: pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.414 26-May-2018 palle

next_stick() - fix typy in comment: tick->stick


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 1.413 11-Apr-2018 palle

sun4v: handle MMU-related traps properly when they occur at trap level 1. This fixes issues when user-level LWPs access the user-level stack


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 1.412 26-Aug-2017 palle

branches: 1.412.2;
sun4v: Avoid touching the %tick_cmpr register which is not present on never systems (Oracle SPARC Architecture 2011 and beyond). Based on code from OpenBSD locore.s revision 1.177. Tested on both sun4u (qemu and USIII) and sun4v (qemu and T5-2). ok martin@


Revision tags: netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2
# 1.411 06-May-2017 palle

sun4v: The %ver register is not available on sun4v - use GET_MAXCWP introduced in rev. 1.361. Verified using qemu (sun4u and sun4v) and on real sun4v hw (t2000)


Revision tags: prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.410 18-Apr-2017 palle

branches: 1.410.2;
sun4v: Add handling of trap 0x06c @ trap level 1 - based on code from OpenBSD, but slightly adapted to NetBSD. verified using qemu


Revision tags: jdolecek-ncq-base pgoyette-localcount-20170320
# 1.409 19-Feb-2017 palle

sun4v: rft_user needs special handling (a manual fill) since the restore instruction may cause the number of trap levels to exceed the maximum for sun4v - inspired by code from the the openbsd rft_user code path - verified using qemu for both sun4u and sun4v


# 1.408 10-Feb-2017 palle

sun4v: Added handling of trap type 0x034 (address alignment error) + fixed typo mmfsa -> mmufsa. Verified for both sun4u and sun4v using qemu.


Revision tags: nick-nhusb-base-20170204
# 1.407 30-Jan-2017 palle

sun4v: Hook up syscall handling to the trap table. Verified using qemu for both sun4u and sun4v.


# 1.406 27-Jan-2017 palle

sun4v: implement missing handling of itsb traps 0x008 and 0x009. Based on code from OpenBSD. Tested using qemu.


Revision tags: bouyer-socketcan-base
# 1.405 07-Jan-2017 palle

branches: 1.405.2;
sun4v: slowtrap() now selects normal globals properly on both sun4u and sun4v platforms. Verified using qemu for both sun4u and sun4v systems


Revision tags: pgoyette-localcount-20170107
# 1.404 05-Jan-2017 palle

sun4v: TRAP_SETUP() updated to set mmu context id properly for both sun4v and sun4u platforms. Verified using qemu for both sun4u and sun4v systems


# 1.403 04-Jan-2017 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x00-0x23 and 0x28-0x30


# 1.402 29-Dec-2016 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x32-0x7f


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.401 20-Sep-2016 nakayama

Fix RAS for 32-bit kernels. trapframe is always 64-bit.


Revision tags: localcount-20160914
# 1.400 23-Aug-2016 palle

sun4v: rework sun4v_datatrap so it works properly when running on a T2-based system like T5120 - for some reason %tl is 0 when entering sun4v_datatrap causing a crash (sir instruction), so ignore the %tl value for now upon entry to sun4v_datatrap - with this fix both T1 and T2 based systems reach the same point - hangs in rft_user after the init process is started


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726
# 1.399 18-Jul-2016 palle

sun4v: handle device interrupts properly - both legacy (sysino) and cookies


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 1.398 04-Jun-2016 palle

branches: 1.398.2;
sun4v: rtf_user now uses macros GET_MMU_CONTEXTID and SET_MMU_CONTEXTID. Tested on sun4u (QEMU) and sun4v (T2000). Parts from OpenBSD.


Revision tags: nick-nhusb-base-20160529
# 1.397 18-May-2016 nakayama

Decrement %tl in trap handler not to make it zero unconditionally
for the nested trap, and remove useless mov.


# 1.396 17-May-2016 palle

sun4v: Implement missng MMU protection trap handling - mostly from OpenBSD


# 1.395 16-May-2016 palle

Avoid assembler-specific defines by using the export keyword in genassym.cf instead


# 1.394 15-May-2016 nakayama

%g1 is not preserved across function call, so load it before
return_from_trap.


# 1.393 13-May-2016 palle

sun4v: add missing implementation of sun4v_datatrap_tl0 so data_access_fault() is called - mostly from OpenBSD


# 1.392 13-May-2016 nakayama

- ci_paddr is always 64-bit.
- intrlev is array of pointer.
- ih_ack is pointer.


# 1.391 10-May-2016 palle

sun4v: make device interrupts work. Introduce a new intrhand_alloc() function for allocation of interrupt handlers and adapt to this. Parts from OpenBSD. ok martin@


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.390 09-Mar-2016 nakayama

32-bit kernels use 32-bit stack.


# 1.389 03-Mar-2016 palle

sun4v: rft_kernel should pay attention to the number of register windows that can be restored. We cannot rely on fill traps to occur, since sun4v only has two trap levels available in privileged mode. Based on code from OpenBSD. ok martin@


# 1.388 14-Feb-2016 palle

sun4v: add breakpoint trap entry to the sun4v trap table


# 1.387 03-Feb-2016 palle

sun4v: extend dmmu_set_secondary_context() to handle both sun4u and sun4v. ok martin@


Revision tags: nick-nhusb-base-20151226
# 1.386 06-Nov-2015 martin

Basically revert r1.246 of locore.s and r1.73 of vm_machdep.c:

Remove special case handling for userland lwps from cpu_lwp_fork,
instead do it in lwp_trampoline when we first return to userland.

which was a stupid idea - since we did now set all fork child's %tstate
(and thus %pstate when back in userland) to the current kernel's userland
default. This meant we lost the address mask bit for 32bit processes and
all memory model details for 64bit ones.

Move it back to cpu_lwp_fork and fix the condition to only do it once when
forking init.


# 1.385 05-Nov-2015 martin

Most of the time return_from_trap already got called with tf->tf_tstate
loaded in register %g1 - make it so for two more callers and remove
the reload of that value.


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606 nick-nhusb-base-20150406
# 1.384 05-Apr-2015 palle

sun4v: Ensure that the TTEs CP and CV bits are the same (both set) for the primary cpu and secondary cpus INTSTACK mappings


# 1.383 01-Apr-2015 palle

sun4v: Implement handling of cpu_mondo trap - from OpenBSD - tested using the Legion simulator


# 1.382 04-Mar-2015 palle

sun4v: revert some of the logic introduced in revision 1.378 - flushw is not necessary on sun4v (OpenBSD patches the flushw instruction to a nop instruction) - with these changes the kernel reaches cpu_boot_secondary_processors() when running in the Legion simulator (crashes due to missing handling of cpu_mondo_trap)


# 1.381 02-Mar-2015 nakayama

prom_printf converts "\n" to "\r\n" internally, so omit "\r".


# 1.380 02-Mar-2015 nakayama

PANICSTACK is a pointer itself, not a pointer to pointer.


# 1.379 02-Mar-2015 nakayama

Use panic stack temporarily for calling prom_printf in a trap
handler.

It seems that openfirmware cannot handle over 4GB pointers, and
stack pointers may point to over 4GB since VA layout was rearranged
by rev 1.33 of vmparam.h. Therefore, use panic stack to avoid
panicking in OF_write used by prom_printf.


# 1.378 23-Feb-2015 palle

sun4v: sparc_interupt - ensure that the trap level and globals level are the same when the flushw instruction is issued - othwise warnings occur when using the sun4v Legion simulator.


Revision tags: nick-nhusb-base
# 1.377 26-Oct-2014 palle

branches: 1.377.2;
sun4v: Create CLEANWIN0 and CLEANWIN1 macros for handling clean window traps on both sun4u and sun4u (based on the original code inlined in the sun4u trap table). Update trap tables accordingly for both sun4u and sun4v. Ok martin@


# 1.376 24-Oct-2014 nakayama

Fix typo in comment.


# 1.375 18-Oct-2014 snj

src is too big these days to tolerate superfluous apostrophes. It's
"its", people!


# 1.374 15-Oct-2014 palle

sun4v: fixed bug causing the real address to be incorrectly calculated as zero


# 1.373 24-Sep-2014 palle

sun4v: add code to enable startup of secondary cpus on both sun4u and sun4v systems - ok martin@


# 1.372 04-Sep-2014 palle

sun4v: All cpus must be setup with a TSB descriptor, so pmap_setup_tsb_sun4v() must take a pointer to the TSB descriptor


# 1.371 31-Aug-2014 palle

sun4v: Split the NORMAL_GLOBALS and ALTERNATE_GLOBALS macros to _SUN4U and _SUN4V variants. Rework the return_from_trap logic to use the new variants so it is possible to use a global register as scratch register.


# 1.370 14-Aug-2014 nakayama

Add missing delay slot in DEBUG kernel.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.369 30-Jul-2014 palle

branches: 1.369.2;
Fix ALTERNATE_GLOBALS so it at least works on sun4u - using a scratch register is not a good idea...


# 1.368 27-Jul-2014 palle

sun4v: Introduce a new macro ALTERNATE_GLOBALS (matching NORMAL_GLOBALS). Two new helper macros ENABLE_INTERRUPTS and DISABLE_INTERRUPTS are also created. With these changes the GENERIC.UP kernel will reach rootmount on sun4v systems - ok martin@


# 1.367 26-Jul-2014 palle

Improved the NORMAL_GLOBALS macro in the sun4u case, so only the relevant bit (AG) in %pstate is affected - ok martin@


# 1.366 24-Jul-2014 palle

sun4v: add missing spill/fill handling for trap level 1 + cosmetic changes to comments for trap level 0 entries


# 1.365 19-Jul-2014 palle

sun4v: Introduce a NORMAL_GLOBALS macro - first used in sparc_interrupt - other relevant uses will be handled as the sun4v work is progressesing - ok martin@


# 1.364 16-Jul-2014 palle

sun4v: Introduce SET_MMU_CONTEXTID macro for setting the mmu context id on both sun4u and sun4v


# 1.363 13-Jul-2014 palle

sun4v: add interrupt handling to sun4v trap table


# 1.362 13-Jul-2014 palle

Bugfix: add missing cmp instruction to GET_MAXCWP macro


# 1.361 30-Jun-2014 palle

sun4v: The maximum number of register windows is a constant and thus not available via the %ver register (sun4u only). Introduce a macro GET_MAXCWP that handles this, so cpu_switchto() works properly on sun4v. Other relevant reference to %ver can be adapted to use GET_MAXCWP as the sun4v port progresses. OK martin@


# 1.360 31-May-2014 palle

sun4v: added missing dtsb miss handling for trap level 1 - with this update the kernel now reaches configure() on sun4v systems


# 1.359 30-May-2014 palle

Remove debugging code introduced by accident in locore.s revision 1.357


Revision tags: yamt-pagecache-base9 rmind-smpnet-nbase rmind-smpnet-base
# 1.358 05-May-2014 palle

sun4v: the trap base address should be assigned to %l1 so %tba is properly setup later in the code - now the kernel gets as far as printing the copyright disclaimer, kernel version and total and available memory before crashing


# 1.357 21-Apr-2014 palle

sun4v: Update comment: modified -> access


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.356 21-Feb-2014 palle

branches: 1.356.2;
sun4v: Rename TLB_ defines to SUN4U_TLB_ so entries created using TSB_DATA() are properly setup for sun4u and sun4v. Relocate the cputyp variable from autoconf.c to locore.s and make it const in param.h so optimized code can be generated. Parts from OpenBSD. Optimization suggested by nakayama@. OK martin@, mrg@, nakayama@


# 1.355 31-Jan-2014 tsutsui

defined(LKM) -> defined(MODULAR)


# 1.354 26-Jan-2014 palle

sun4v: Add handling of spill/fill and dtsb miss traps (with a XXX to be handled later)


# 1.353 07-Jan-2014 palle

sun4v: trap table setup - currently populated with dummy entries which will be properly implemented later - parts from OpenBSD - OK martin@


# 1.352 29-Dec-2013 nakayama

Make buildable w/o options SUN4V.


# 1.351 27-Dec-2013 palle

a) make the hunt through the cpus list more generic b) sun4v: ensure that the interrupt stack is mapped permanently and the TSB is setup properly - parts from OpenBSD. OK martin@


# 1.350 06-Dec-2013 nakayama

Increase an interrupt depth only in the case of hardware interrupts,
and remove the ci_idepth trick in softint_fastintr.

Fixes the following diagnostic panic reported in port-sparc64.

panic: kernel diagnostic assertion "!cpu_intr_p()" failed: file
"../../../../kern/subr_xcall.c", line 351


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 1.349 24-May-2013 nakayama

branches: 1.349.2;
Disable interrupts after calling data_access_error as with
data_access_fault.


# 1.348 28-Apr-2013 nakayama

Use macros in machine/asm.h instead of locally defined, and
introduce CASPTRA for casxa/casa.


Revision tags: agc-symver-base
# 1.347 23-Jan-2013 martin

Fix sparc64_ipi_ccall by adding proper trap setup.
Fixes xcall(9) problems, as exposed by pserialize(9). Noticed by
J. Hannken-Illjes, cause pointed out by Takeshi Nakayama.


# 1.346 23-Jan-2013 martin

Sligthly clean up the (by default unused) #ifdef TRAPS_USE_IG


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.345 10-Nov-2012 nakayama

Revise comment.


# 1.344 10-Nov-2012 nakayama

Use macro instead of magic number.


# 1.343 09-Nov-2012 nakayama

Make setstick() and getstick() to inline functions.


# 1.342 08-Nov-2012 macallan

use system tick timer instead of %tick on UltraSPARC-III-ish CPUs
review & fixes by Takeshi Nakayama


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.341 17-Mar-2012 mrg

branches: 1.341.2;
port the corrected ECC error handling code from freebsd. i noticed my U10
took one of these and then hang. it shouldn't hang, there's a 'sir' here that
doesn't seem to reset properly. oh well.

tested by simulated a trap via 'ta 0x10' and considering that the same, but
it hasn't been tested against a real ECC error yet.


Revision tags: jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base4
# 1.340 03-Mar-2012 nakayama

Fix the root cause of the hack "disable optimizations for uvm_bio.c
on 32 bit kernels".

gcc converts a division in the calculation of UBC_UMAP_ADDR macro
to multiplication (smul or combination of add/sll), and the
register of its result contains a garbage in upper 32 bits (the
upper 32 bits of smul/add/sll's result isn't zero cleared).

Then it passes to pseg_get{,_real} through pmap_extract without the
zero clear of upper 32 bits in the optimization case. So the
result of pseg_get and pmap_extact sometimes gets screwed up.


Revision tags: jmcneill-usbmp-base5 jmcneill-usbmp-base3
# 1.339 19-Feb-2012 rmind

Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.


Revision tags: jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.338 04-Sep-2011 nakayama

branches: 1.338.2; 1.338.6; 1.338.8;
ih_pil is an interrupt level, not an interrupt mask.


# 1.337 27-Jul-2011 nakayama

ivec is assigned to hardware, so count its event counter up in
interrupt_vector, not in softint, and do some optimization.


# 1.336 20-Jul-2011 macallan

add per ivec event counters


# 1.335 12-Jul-2011 mrg

rename sparc64 BLOCK_SIZE and BLOCK_ALIGN to have SPARC64_ prefixes.
for the assembler files, define the old names to the new names
since using the new names cause ugliness due to longer identifer
names, and reduces churn.

fixes build issues in dtv and vaguely makes <machine/psl.h> slightly
less name-space invasive.


# 1.334 18-Jun-2011 nakayama

Add fast softint(9) support for sparc64.

Reviewed on port-sparc64.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 1.333 12-May-2011 mrg

branches: 1.333.2;
first steps towards fujitsu SPARC64 support:

- SPARC64 systems have interrupts with upto 14 bits set, but we only look
at the first 11 bits. trim non IPI interrupts to 11 bits


Revision tags: uebayasi-xip-base7 bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 jym-xensuspend-nbase jym-xensuspend-base
# 1.332 20-Dec-2010 matt

branches: 1.332.2;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.


Revision tags: uebayasi-xip-base6 uebayasi-xip-base5 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 1.331 10-Jul-2010 nakayama

Clear the upper word explicitly before combining two 32-bit values to 64-bit
on 32-bit kernels.


# 1.330 23-May-2010 martin

Split copy related functions out of locore.s into copy.S, move functions
only needed on multiprocessors into mp_subr.S.


# 1.329 17-May-2010 martin

Simplify primary CPU startup slightly by using the fact that our cpuinfo's
curpcb pointer points to the uarea/pcb of lwp0 and by remembering the pointer
to this cpuinfo, thus avoiding a few CPUINFO_VA references.


Revision tags: uebayasi-xip-base1
# 1.328 20-Mar-2010 chs

fix copy{in,out}{,str}() to return the error returned by uvm_fault().
fixes PR 41813.


Revision tags: yamt-nfs-mp-base9
# 1.327 10-Mar-2010 mrg

branches: 1.327.2;
XXX: workaround we'd like to remove when pmap / uvm locking is cleaned up:

- rename pseg_get() and pseg_set() to pseg_get_real() and pseg_set_real().
- if USE_LOCKSAFE_PSEG_GETSET is defined, which it current is by default,
define pseg_[gs]et() in terms of functions that take a new pseg_lock
mutex at IPL_VM while calling into the real functions.

this seems to avoid the pseg_set() crashes we've seen:
1 - spare needed, when pseg_get() just worked for this pmap
2 - the 2rd ldxa via ASI_PHYS_CACHED in pseg_set() loads garbage
into %o4, and causes the 3rd ldxa to fault


# 1.326 08-Mar-2010 mrg

blast_dcache() SMP friendly:

- blast_dcache() becomes sp_blast_dcache(dcache_size, dcache_line_size)
- new smp_blast_dcache(sparc64_cpuset_t) that blasts the D$ on this cpuset
- sparc64_ipi_blast_dcache() to support the above
- in pmap_remove_all(), when freeing mmu contexts for this pmap, mark
the set of cpus to blast the d$ on as well and convert the
blast_dcache() call into smp_blast_dcache() on the cpus who ran this
pmap, or, sp_blast_dcache(dcache_size, dcache_line_size)
- convert the remaining blast_dcache() in machdep.c to sp_blast_dcache()
- in pmap_destroy()/pmap_remove_all() take the pmap_lock() always since
we assert it is held always.

with these changes, NFS builds on the U60 seem to be stable now, and
the USIII machines also can often complete a single build.sh run now,
diskful or diskless.


reviewed by mlelstv and partially by martin, tested by martin and myself,
with some ideas from chuq as well.


# 1.325 07-Mar-2010 mrg

need _ALIGN in locore.h as well, for DEBUG kernels.


# 1.324 07-Mar-2010 mrg

gas has supported SPARC ".empty" for a long while; get rid of an
ancient workaround.


# 1.323 06-Mar-2010 mrg

move the memcpy/memset implementations out into their own file, with the
block copy versions as well. move some of the definitions in locore.s
into a new locore.h.

locore.s is almost 2000 lines shorter with this change.


# 1.322 04-Mar-2010 mrg

- in _bus_dmamap_unload(), pmap_page_protect() and pmap_clear_reference()
switch the dcache_flush_page() into a dcache_flush_page_all()
- in both pmap_kremove()/pmap_remove(), remove the blast_dcache() call
and replace it with dcache_flush_page_all()
- in pmap_get_page() [used to allocate PTP's], always call pmap_zero_page(pa)
- flush the dcache of the dst page in pmap_{copy,zero}_page() by redirecting
throught a C function that calls the (renamed) asm. the old asm code had a
comment about needing to do this...
- add a couple of membar #Sync's that the USIII manual recommends


based on discussions with chuq@, skrll@ and martin@.


these help my SB2000 / SB2500 with both disk / nfs builds and other tasks,
sometimes lasting for several hours before failing or asserting.


# 1.321 24-Feb-2010 mrg

when handing back page table pages to UVM, flush them from the dcache
on all CPUs.

idea from skrll@, and makes my disk-based SB2000 stable.

tested on U60, SB2000 and SB2500.


# 1.320 24-Feb-2010 mrg

- re-introduce sp_tlb_flush_pte() and sp_tlb_flush_all() that call
the right USI/USIII version.
- define tlb_flush_pte() in terms of sp_tlb_flush_pte() for the
!MULTIPROCESSOR case

this centralises some CPU_IS_USIII_UP() tests.


# 1.319 22-Feb-2010 mrg

move {dump,print}_[id]tlb() into a separate file.


# 1.318 22-Feb-2010 mrg

- store the maximum [id]cache size / line size for each cpu

- remove patch_kernel() since it isn't necessary and has been patching
the wrong thing in general.

- implement USIII versions of blast_icache(), dcache_flush_page() and
cache_flush_phys(). use the newly recorded cache size/line sizes.

- in winfixsave, flush the D$ with the right size index and ops. this
kills one of the wrong tag->inval patches.

- for blast_dcache(), use the newly recorded dcache_size/line_size.

- for blast_icache(), use the newly recorded cache size/line sizes.
for the USIII verison, disable the I$ while writing to ASI_ICACHE_TAG.


these changes removed several hard coded cache sizes values, some very
wrong kernel patching, and seem to make the current failure modes for
USIII less common, but not gone.


# 1.317 15-Feb-2010 mrg

- don't flush 32-bit entries for 64-bit code, it does not seem to be
necessary. #define TLB_FLUSH_LOWVA to turn it back on.
- remove the #if 0'd code in sparc64_ipi_flush_pte_usiii(), i have
verified that it is not required.
- add a missing membar #Sync to sp_tlb_flush_pte_usiii().


# 1.316 15-Feb-2010 nakayama

Fix linker error of GENERIC32 kernel.


# 1.315 15-Feb-2010 mrg

use TLB_SIZE_SPITFIRE in a couple of places, and note that the
{print,dump}_[id]tlb() versions are currently spitfire specific.


# 1.314 15-Feb-2010 mrg

introduce a new patch_kernel() and call it from the end of bootstrap().
use it to patch up TLB flush instructions that don't match for USI/II
and later. we can also hopefully use this to make GENERIC.MP minimally
expensive on single CPU machines as well.

this is the last piece needed to get GENERIC/GENERIC.MP to boot on the
USIII* machines.

idea and some initial code from openbsd.


# 1.313 13-Feb-2010 mrg

remove KTR support. it's never been a working part of netbsd src tree.


# 1.312 09-Feb-2010 wiz

Fix typo in comment.


Revision tags: uebayasi-xip-base
# 1.311 06-Feb-2010 mrg

branches: 1.311.2;
- properly map the schizo interrupt registers, so we can use the normal
virtual mappings to access them.
- with the above fxied, kill SCHIZO_BUS_SPACE_BROKEN, and introduce
an options CHEETAH for now, that disables the SPITFIRE code in locore.
- merge schizo_init() into schizo_attach() and clean up the softc a bit.


with this we are only one more step away from GENERIC booting on USIII
machines.


# 1.310 02-Feb-2010 mrg

- split sp_tlb_flush_pte() and switchtoctx() into sp_tlb_flush_pte_us()/
sp_tlb_flush_pte_usiii() and switchtoctx_us()/switchtoctx_usiii() and
implement the latter while i'm here. it works ... sometimes i think,
but also sometimes panics/hangs.
- fix a comment in sparc64_ipi_flush_pte_usiii()


# 1.309 02-Feb-2010 mrg

for now, reduce a few #ifdef SPITFIRE cases by introducing a new
ASI_DCACHE_TAG_OR_INV that is either ASI_DCACHE_{TAG,_INVALIDATE}.

increase the common code in cache_flush_phys().


# 1.308 01-Feb-2010 mrg

- sp_tlb_flush_all() becomes sp_tlb_flush_all_us() and sp_tlb_flush_all_usiii()
- sparc64_ipi_flush_pte() becomes sparc64_ipi_flush_pte_us() and
sparc64_ipi_flush_pte_usiii()
- add some commented out code to disable interrupts and raise the traplevel
in sparc64_ipi_flush_pte_usiii()
- cache_flush_phys() was missing a little of code in the cheetah case


# 1.307 01-Feb-2010 mrg

for USIII, use the new "tlb demap all" operation in sp_tlb_flush_all()


# 1.306 01-Feb-2010 mrg

remove unused icache_flush_page() implementation.


# 1.305 23-Jan-2010 mrg

remove the final uses of DATA_START.

now we can remove the 16KB space reserved at the start of the data segment,
and i now understand why i wrote this now removed comment 3.5 years ago:
"this shouldn't be needed... but kernel usually hangs without it"


# 1.304 23-Jan-2010 mrg

remove most of the code that writes debugging info DATA_START + offset.


# 1.303 23-Jan-2010 mrg

remove CHKPT() macro and uses. it's likely wrong in SMP land and probably should
be replaced with KTR-style uses if necessary.


# 1.302 23-Jan-2010 mrg

fix a comment.


Revision tags: matt-premerge-20091211
# 1.301 10-Dec-2009 rmind

Rename L_ADDR to L_PCB and amend some comments accordingly.


# 1.300 05-Dec-2009 mrg

- adjust the PA mask to the 43 bits supported by USIII.
- rework the spitfire/cheetah cache_flush_phys() to avoid several #ifdefs
- add a membar #Sync after sparc64_ipi_drop_fpstate (probably unnecessary)


# 1.299 30-Nov-2009 nakayama

sp_tlb_flush_pte for cheetah:
- restore interrupts properly in case of %tl > 0.


# 1.298 30-Nov-2009 mrg

stablize UP USIII support by blocking interrupts around sp_tlb_flush_pte()
i was seeing stack corruption while taking an interrupt in this function.

get USIII SMP mostly working by implementing the cheetah version of
sparc64_ipi_flush_pte().


SMP support is still not entirely stable. i can reproducably get a:

panic: fpusave_lwp ipi didn't

while running build.sh, when an awk process is exiting. other simple
heavy work loads do not crash for me right now.


# 1.297 30-Nov-2009 mrg

delete some no longer used code:
- smp_tlb_flush_ctx()
- smp_tlb_flush_all()
- sparc64_ipi_flush_ctx()
- sparc64_ipi_flush_all()
- sp_tlb_flush_ctx()


# 1.296 29-Nov-2009 nakayama

- calculate end PA correctly.
- wrap more spitfire specific (flushing I$) code.
- fix inverted #if condition for flushing I$ (and restore ASI_ICACHE_TAG).


# 1.295 28-Nov-2009 mrg

implement enough code to get SB2000/SB2500 booting to multiuser. does
not last long if you use it, but an idle machine has stayed up 10 hours.

- for the !SPITFIRE case, use ASI_DCACHE_INVALIDATE instead of
ASI_DCACHE_TAG when clearing tlb entries. from openbsd.

- convert some comment "! Not yet" into "WRITEME", so that attempting
to build a USIII MULTIPROCESSOR kernel fails to build until the code
is written.

- add some more WRITEME's for the above.

- implement a !SPITFIRE version of sp_tlb_flush_all(). since there are
no spare regs, for now just always increase %tl around this call. (we
could maybe store a token in %o3 along with the saved %pstate info.)


# 1.294 26-Nov-2009 matt

Kill proc0paddr. Use lwp0.l_addr instead.


# 1.293 25-Nov-2009 mrg

s/L_ADDR/L_PCB/, requested by rmind.


# 1.292 17-Oct-2009 nakayama

Wrap unused code with #if 0 which is called from #if 0'ed code.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5
# 1.291 30-May-2009 martin

cpu_setfunc() can not use lwp_trampoline, as that has additional lwp startup
semantics. Use a simpler setfunc_trampoline instead.


# 1.290 18-May-2009 nakayama

Remove random() from locore.s since it is in libkern.


# 1.289 16-May-2009 nakayama

Remove clear %tick in locore.s since it is cleared at cpu_initclocks() in
clock.c.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 nick-hppapmap-base mjf-devfs2-base
# 1.288 15-Dec-2008 mrg

restore some old "intrdebug" code, but leave it under NOT_DEBUG. most
of it works, but one that prints func/arg for each handler is not very
stable...

for now, while schizo bus space pointer accesses aren't working, add
a SCHIZO_BUS_SPACE_BROKEN option so you can build a kernel with schizo.

with this, and the prior schizo interrupt fix, you can now fail to run
/sbin/init!


Revision tags: haad-dm-base2 haad-nbase2 haad-dm-base
# 1.287 09-Dec-2008 martin

Get rid of get_maxctx() - it doesn't work on newer cpus and we will have
to find a better way for (some) sun4v machines - all sun4u use 13 bit
contexts anyway.


Revision tags: netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 ad-audiomp2-base netbsd-5-base
# 1.286 30-Oct-2008 nakayama

branches: 1.286.2; 1.286.6;
Wrap more code specific to USE_BLOCK_STORE_LOAD.


Revision tags: matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4
# 1.285 05-Oct-2008 nakayama

branches: 1.285.2;
- in flushing cache, use 32 as increment/decrement value to match the
cache line size.
- remove useless restore of %asi.
- remove nop in delay slot if we can.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 1.284 10-Jul-2008 nakayama

Use proper CCR.


# 1.283 10-Jul-2008 nakayama

sparc64_ipi_save_fpstate:
- use primary MMU context for consistency with other trap/interrupt handlers.

sparc64_ipi_save_fpstate, savefpstate:
- avoid storing fp registers as we can.

sparc64_ipi_save_fpstate, savefpstate, loadfpstate:
- remove unaligned case since buffers allocated with pool_cache are ensured
64-byte aligned.

Ok by martin@.


# 1.282 02-Jul-2008 nakayama

branches: 1.282.2;
UltraSPARCs don't have floating point queue, and reading %fq regsiter
will cause illegal instruction trap. So remove the code handling them.


# 1.281 29-Jun-2008 nakayama

Wrap IPI calls with #ifdef MULTIPROCESSOR.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.280 14-Jun-2008 nakayama

Close unterminated comment.
Fix unexpected behavior in case of loadfpstate from unaligned buffer.


Revision tags: yamt-pf42-base3
# 1.279 31-May-2008 nakayama

branches: 1.279.2;
openfirmware_exit:
- disable interrupts with %pstate.
- prepare 64-bit stack and enable 64-bit addresses for 32-bit SMP kernels.


Revision tags: hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 yamt-nfs-mp-base yamt-pf42-base
# 1.278 16-Apr-2008 nakayama

branches: 1.278.2; 1.278.4; 1.278.6;
Disable TRAPSTATS which was accidentally enabled when yamt-idlelwp branch
was merged.

Ok by martin@.


# 1.277 14-Apr-2008 nakayama

Remove sparc64_ipi_sync_tick.

Since we can use counter-timer as timecounter instead of %tick on SMP kernel,
it is not necessary to sync all CPUs %tick registers.


# 1.276 14-Apr-2008 nakayama

Add workaround for BB_ERRATA_1 on writing to TICK_CMPR register in
next_tick(). If writing to TICK_CMPR fails, we lose hardclock interrupt
on secondary CPUs.

About BB_ERRATA_1 from comment in OpenSolaris:

/*
* Writes to the TICK_COMPARE register sometimes fail on blackbird modules.
* The failure occurs only when the following instruction decodes to wr or
* wrpr. The workaround is to immediately follow writes to TICK_COMPARE
* with a read, thus stalling the pipe and keeping following instructions
* from causing data corruption. Aligning to a quadword will ensure these
* two instructions are not split due to i$ misses.
*/


# 1.275 28-Mar-2008 nakayama

Don't read fplwp content in delay slot for considering the case fplwp was
modifiled.

Reported by Chris Ross on port-sparc64.


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.274 20-Mar-2008 nakayama

- remove disabling interrupt in IPI.
- unused VA bits in MMU demap is 13 bits, not 12 bits.


# 1.273 18-Mar-2008 nakayama

Fix a race when increment an interrupt level event counter.


# 1.272 17-Mar-2008 nakayama

Fix a race condition in IPI handlers of save/drop fpstate, from OpenBSD.
Reported and tested by martin@.


# 1.271 17-Mar-2008 nakayama

Make schedintr interrupt handler per-CPU.
While there rename tickintr interrupt handler and share initialization
code with schedintr.


# 1.270 14-Mar-2008 nakayama

Improve IPI handling:
- make IPI takes two arguments.
- add IPI event counters per-CPU.
- implement IPI functions which were missing or broken.
- insert DELAY while halting primary CPU in IPI handler.


# 1.269 02-Mar-2008 nakayama

- make interrupt pending list per-CPU.
- make tickintr() MP-safe.
- remove unused port-sparc derived interrupt code.

Ok by martin@.


# 1.268 02-Mar-2008 nakayama

Don't get IPI handler argument (from bogus address), and ack IRQ twice.


# 1.267 28-Feb-2008 martin

Make TSBs and MMU contexts per-cpu.


Revision tags: nick-net80211-sync-base mjf-devfs-base hpcarm-cleanup-base
# 1.266 26-Jan-2008 nakayama

branches: 1.266.2; 1.266.6;
Fix for 32-bit kernels.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.265 15-Jan-2008 skrll

Store a sensbile PCB_PC value in snapshot - the return point.

This helps gdb somewhat.

OK'd by martin.


# 1.264 14-Jan-2008 martin

Fix register name typo/copy&pasto - %g6 is not %o6/%sp.
From OpenBSD.


Revision tags: matt-armv6-base
# 1.263 06-Jan-2008 martin

Load the next cpu_info pointer with LDPTR instead of ld.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2
# 1.262 09-Dec-2007 martin

branches: 1.262.2;
Provide cpu_intr_p(), at least for non-MULTIPROCESSOR kernels.
Based on suggestions by Andrew Doran.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.261 22-Oct-2007 martin

branches: 1.261.2; 1.261.4; 1.261.6;
Remove an unused .globl declaration


Revision tags: yamt-x86pmap-base4
# 1.260 17-Oct-2007 garbled

Merge the ppcoea-renovation branch to HEAD.

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

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

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base ppcoea-renovation-base vmlocking-base
# 1.259 09-Sep-2007 martin

branches: 1.259.4;
Make cpufrequency and friends per cpu values.
Prepare a hz tick interrupt on secondary CPUs via %tick, but do not
enable it yet, as it breaks ddb.


# 1.258 09-Sep-2007 martin

Do not ACK IPIs before we finished loading all arguments.


# 1.257 06-Sep-2007 martin

Remove the (now unused) second 64k page mapped per CPU.
From matthew green, with small changes by me. All bugs are mine.


# 1.256 25-Aug-2007 martin

branches: 1.256.2;
Remove INITSTACK completely - at the time we used to switch to it, we
already have access to all of lwp0 and it's uarea - so we can switch
to the correct lwp0 stack easily before calling main.


# 1.255 25-Aug-2007 martin

When exiting to OF, use the interrupt stack instead of INITSTACK


# 1.254 25-Aug-2007 martin

Rework cpu_mp_startup slightly:
- temporarily use the cpu's interrupt stack untill we are ready
to access non-OF-based mappings, then directly switch to the cpu's
idlelwp's uarea stack
- disable interrupts untill we are ready to call C code


# 1.253 13-Aug-2007 macallan

remove two restore without matching save


Revision tags: nick-csl-alignment-base matt-mips64-base mjf-ufs-trans-base
# 1.252 06-Jul-2007 martin

branches: 1.252.4; 1.252.8;
A few nits for 32bit SMP kernels, noticed by mrg.
While there, simplify the fpstate IPIs a bit.


# 1.251 05-Jul-2007 martin

sparc64_ipi_save_fpstate is not a leaf function - create a full grown
stack frame.


# 1.250 28-May-2007 mrg

clean up cpu_switchto() a little - no need to flushw or membar
excessively. optimise an rdpr. tested by tnn.


# 1.249 23-May-2007 martin

Fix a stupid bug in the save_fpstate ipi, which caused overwriting of
struct lwp of the lwp owning the fpu. Fix clearing the fplwp - %o0 will
not survive the call to savefpstate - duh!


# 1.248 20-May-2007 martin

Simplify tf_tstate setting when leaving for userland initially - I seem
to have confused the if with the else case of the previous C code.
Funny that it worked at all.


# 1.247 20-May-2007 martin

cpu_switchto() has to return it's first arg, always. This differs from
my reading of the documentation, but helps in the real world and seems
to be what other ports do.


# 1.246 20-May-2007 martin

Remove special case handling for userland lwps from cpu_lwp_fork, instead
do it in lwp_trampoline when we first return to userland.


# 1.245 19-May-2007 martin

cpu_idle is a leaf function, so we better "return from leaf".
Use return value from cpu_switchto for previous lwp in lwp_trampoline.
Also shamelessly steal a comment from uwe written for sparc that explains
all this.
Thanks to tnn, mrg, and uwe for helping to debug this.


# 1.244 17-May-2007 yamt

merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base ad-audiomp-base
# 1.243 22-Feb-2007 martin

branches: 1.243.4; 1.243.6; 1.243.12;
uvm.page_idle_zero now is a bool, not a 32bit value any more.


# 1.242 21-Feb-2007 mrg

shave 9 insns off the tsb setup in cpu_initialize & cpu_mp_startup.


# 1.241 21-Feb-2007 martin

Get rid of unused (thus always zero) "curlwp" variable hidden in assembler
code (C code always uses a cpuinfo based macro).


# 1.240 18-Feb-2007 martin

Make use of another call delay slot, pointed out by uwe.


# 1.239 18-Feb-2007 martin

Make use of a call delay slot and avoid a bogus EMPTY.
Spotted by Juergen Hannken-Illjes, with input from Andrew Doran and
Valeriy E. Ushakov.


# 1.238 18-Feb-2007 martin

Whitespace cosmetics


# 1.237 18-Feb-2007 martin

Backout previous: EMPTY was misused


# 1.236 18-Feb-2007 martin

Make EMPTY expand to nop with gas, as it is used to mark empty branch
delay slots.


# 1.235 15-Feb-2007 martin

branches: 1.235.2;
Fix obvious copy&pasto in SCHED_DEBUG register usage.


Revision tags: post-newlock2-merge
# 1.234 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.233 25-Dec-2006 wiz

Spell "relevant" correctly. From Zafer Aydogan.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.232 25-Oct-2006 mrg

branches: 1.232.2; 1.232.4;
- note that __idle_u should go away but doing so breaks things
- fix several comments to reality
- clean up the #ifdef NO_VCACHE code slightly
- use call instead of set/jmpl
- remove a couple of unnecessary stores to curlwp


Revision tags: yamt-splraiseipl-base2
# 1.231 18-Oct-2006 rjs

Clean up some comments. Cosmetic change to use correct structure
offset names.

Optimize out two instructions from sparc64_ipi_save_fpstate and
sparc64_ipi_drop_fpstate.


# 1.230 17-Oct-2006 mrg

allocate 128KB (as opposed to 64KB) per-cpu, and place the interrupt
stack, cpu_info structure, panicstack, idle uarea and normal kernel
stack in here. the idle uarea and kernel stack are in the 2nd 64KB
page. the interrupt stack and cpu_info structure are as the same
place in the 1st 64KB page, and the panicstack grows down from the
top of this page. update comments in param.h to suit (XXX: a lot
of these constants should move to a header file that will not pollute
the name space so much.) map these pages identically between
cpu_initialise() and cpu_mp_startup(), and deal with the two 64KB
pages in pmap_extract(). keep an unmapped 64KB page between them.

don't initialise the unused "ci_eintstack" member of the cpu_info
structure

use constants to initialise many addresses in the cpu_info structure,
consolidating these assignments from cpu0 and cpu>0

delete u0/estack0/panicstack from locore.s

clean up some wrong comments in locore.s

fix a 32bit-only bug in cpu_mp_startup().

delete 'u0' entirely.


this fixes recent random lossage seen on port-sparc64: processes
stuck in RUN state, data faults, and hangs.


# 1.229 04-Oct-2006 mrg

use call instead of set/jmpl. add an entry point for idle that expects
sched_lock to be unlocked, and use this for non-boot cpu's. complete a
comment describing how registers in idle_switch are expected to be set.


# 1.228 03-Oct-2006 mrg

use the same SAVE_LOCALS_INS definition for 32 bit and 64 bit kernels.
refactor TRAP_SETUP() a little between these two versions to be more alike.


# 1.227 03-Oct-2006 mrg

use the correct size/type for MP variables (pointers and longs).

a 32 bit MULTIPROCESSOR kernel now builds (and crashes quickly.)


# 1.226 03-Oct-2006 mrg

in the 64bit version of SAVE_LOCAL_INS, s/BIAS/STKB/ to allow future
sharing of the 32 and 64 bit versions of the {TRAP,INTR}_SETUP macros.


# 1.225 19-Sep-2006 mrg

- remove some way old FP setup/teardown code
- put the block memcpy/memset inside #ifdef USE_BLOCK_STORE_LOAD which
is (now) defined.

no functional change, same .o is generated.


# 1.224 19-Sep-2006 mrg

re-order the changes in rev 1.217 to give registers a little bit of
time to settle between usage, like it was before hand.


# 1.223 19-Sep-2006 mrg

- remove a wrong comment.
- add a new entry point for idle called idle_switch that is called by
cpu_switch() in the MP case when sched_whichqs is zero, properly
setting up the idle stack. from petrov@ via martin@.


# 1.222 19-Sep-2006 mrg

rework interrupt_vector() slightly:
- for the IPI case, avoid loading the address of intrlev into %g3
- remove some NOT_DEBUG code
- load the interrupt argument #2 in the delay slot

this removes 2 nops during interrupt processing for the normal
case, and an additional 2 ALU instructions for IPIs


# 1.221 18-Sep-2006 mrg

- sparc64_ipi_halt(): we shouldn't return from sparc64_ipi_halt_thiscpu()
so replace a branch with a 'sir'
- in #if 0 code, in sparc64_ipi_flush_pte() and sparc64_ipi_flush_ctx()
save/restore the out registers that the sp_tlb_flush_xxx() versions
around calling them
- in sp_tlb_flush_pte() and sp_tlb_flush_ctx(), replace global register
usage with out registers so that we don't clobber the (alternate)
global registers when these are called from IPI context


# 1.220 18-Sep-2006 mrg

- remove an extra 'sir' that followed one in a macro
- add some named labels to some spill/fill handlers
- remove 2 unused strings


Revision tags: yamt-splraiseipl-base
# 1.219 18-Sep-2006 martin

branches: 1.219.2;
Lazy FPU handling for the MULTIPROCESSOR case


# 1.218 16-Sep-2006 nakayama

From OpenBSD:
- reload %fprs for checking it again.
- use symbolic names for checking in %fprs.

revision 1.51
date: 2005/07/18 14:50:11; author: deraadt; state: Exp; lines: +2 -1
cache a copy of the fprs so we know what fp restore we should do after

revision 1.50
date: 2005/07/14 01:46:13; author: deraadt; state: Exp; lines: +4 -4
use symbolic names for checking in %fprs, as above


# 1.217 16-Sep-2006 nakayama

Fix a couple of %y register save/restore errors, inspired from OpenBSD.

revision 1.44
date: 2004/04/23 04:18:17; author: marc; state: Exp; lines: +5 -4

fix a couple of %y register save/restore errors
1) don't save %y in a register that is later used before restoring %y
2) always restore %y after calling a signal handler
tested by drahn@, OK pval


# 1.216 15-Sep-2006 martin

Do not bother to save fpu state when we are about to get rid of it.


Revision tags: yamt-pdpolicy-base9
# 1.215 13-Sep-2006 mrg

SMP cleanup. provide support for multiple CPUs in DDB. (SMP itself
is still not working.)

cpu.h:
- add a pointer for DDB regs in SMP environment to struct cpu_info
- remove the #defines for mp_pause_cpus() and mp_resume_cpus()
cpuset.h:
- remove CPUSET_ALL() and rename CPUSET_ALL_BUT() to CPUSET_EXCEPT()
from petrov.
db_machdep.h:
- rename the members of db_regs_t to be the same as sparc
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- redo DDB_REGS to no longer be a pointer to a fixed data structure
but to one allocated per-cpu when ddb is entered
- move a bunch of prototypes in here
intr.h:
- remove SPARC64_IPI_* macros, no longer used
db_interface.c:
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- make "nil" a 64 bit entity
- change the ddb register access methods to work in multiprocessor
environment, it is now very much like sparc does it
- in kdb_trap() avoid accessing ddb_regp when it is NULL
- update several messages to include the cpu number
- unpause other cpus much later when resuming from ddb
- rename db_lock() to db_lock_cmd(), as the sparc-like code has
db_lock as a simple lock
- remove "mach cpus" command, and replace it with "mach cpu" (which
does the same) and also implement "mach cpu N" to switch to
another cpus saved trapframe
db_trace.c:
- update for the ddb_regs -> ddb_regp change
genassym.cf:
- add TF_KSTACK as offsetof(struct trapframe64, tf_kstack)
ipifuncs.c:
- overhaul extensively
- remove all normal interrupt handlers as IPI's, we now handle
them all specially in locore.s:interrupt_vector
- add a simplelock around all ipi functions - it's not safe for
multiple cpus to be sending IPI's to each other right now
- rename sparc64_ipi_pause() to sparc64_ipi_pause_thiscpu() and,
if DDB is configured, enable it to save the passed-in trapframe
to a db_regs_t for this cpu's saved DDB registers.
- remove the "ipimask" system (SPARC64_IPI_* macros) and instead
pass functions directly
- in sparc64_send_ipi() always set the interrupt arguments to 0,
the address and argument of the to be called function. (the
argument right now is the address of ipi_tlb_args variable, and
part of the reason why only one CPU can send IPI's at a time.)
don't wait forever for an IPI to complete. some of this is
from petrov.
- rename sparc64_ipi_{halt,pause,resume}_cpus() to
mp_{halt,pause,resume}_cpus()
- new function mp_cpu_is_paused() used to avoid access missing
saved DDB registers
- actually broadcast the flush in smp_tlb_flush_pte(),
smp_tlb_flush_ctx() and smp_tlb_flush_all(). the other end may
not do anything yet in the pte/ctx cases yet...
kgdb_machdep.c:
- rework for changed member names in db_regs_t.
locore.s:
- shave an instruction from syscall_setup() (set + ld -> sethi + ld)
- remove some old dead debug code
- add new sparc64_ipi_halt IPI entry point, it just calls the C
vector to shutdown.
- add new sparc64_ipi_pause IPI entry point, which just traps into
the debugger using the normal breakpoint trap. these cpus usually
lose the race in db_interface.c:db_suspend_others() and end up
calling the C vector sparc64_ipi_pause_thiscpu().
- add #if 0'ed code to sparc64_ipi_flush_{pte,ctx}() IPI entry
points to call the sp_ version of these functions.
- in rft_kernel (return from trap, kernel), check to see if the
%tpc is at the sparc64_ipi_pause_trap_point and if so, call
"done" not "retry"
- rework cpu_switch slightly: save the passed-in lwp instead of
using the one in curlwp
- in cpu_loadproc(), save the new lwp not the old lwp, to curlwp
- in cpu_initialize(), set %tl to zero as well. from petrov.
- in cpu_exit(), fix a load register confusion. from petrov.
- change some "set" in delay branch to "mov".
machdep.c:
- deal with function renames
pmap.c:
- remove a spurious space
trap.c:
- remove unused "trapstats" variable
- add cpu number to a couple of messages


# 1.214 09-Sep-2006 mrg

significant clean up effort, largely from petrov@ via martin@.

- fix a bunch of comments for proc->lwp
- remove old TRAPTRACE, NOT_DEBUG, etc. code that has bit-rotted
- put some older DEBUG code under NOT_DEBUG
- add a bunch of new debugging/tracing code ("KTR") that depends on
other changes not yet present.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base yamt-pdpolicy-base5 chap-midi-base simonb-timecounters-base rpaulo-netinet-merge-pcb-base
# 1.213 14-May-2006 elad

branches: 1.213.6; 1.213.8;
integrate kauth.


# 1.212 12-May-2006 skrll

Fix some comments.


Revision tags: elad-kernelauth-base
# 1.211 09-May-2006 rjs

Load CPCB in cpu_mp_startup.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.210 11-Feb-2006 cdi

branches: 1.210.2; 1.210.4; 1.210.6;
ANSIfication: u_intN_t -> uintN_t, use ANSI function declarations/definitions
instead of K&R ones.


# 1.209 27-Jan-2006 cdi

branches: 1.209.2; 1.209.4;
Alter sparc64 bootstrap, catch up to ofwboot v1.9:

- Accept bootinfo structure passed down from ofwboot v1.9
- Drop kernel re-mapping code
- Use permanent 4MB mappings provided by the loader instead
- Change kernel entry address to point directly at the code instead of pointing
at the trap table's first slot. This allows the bootloader to detect
those kernels which are aware of the new boot scheme
- Due to the changes in kernel mapping code, alter secondary CPU bootstrap
code to use trampoline just like FreeBSD does (some FreeBSD code is used
here as well)


# 1.208 12-Jan-2006 cdi

Fix a typo: %g0 should be used instead of %o0 when initializing FPU in dostart:
and cpu_mp_startup:, %o0 is not even initialized at this point.


# 1.207 11-Dec-2005 christos

branches: 1.207.2;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 1.206 10-Jul-2005 christos

Re-factor syscall, and make it use syscall_{plain,fancy}.


# 1.205 31-May-2005 chs

branches: 1.205.2;
remove vestigal {,e}intr{names,cnt} symbols now that vmstat doesn't need them.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.204 12-Feb-2005 chs

branches: 1.204.4; 1.204.6; 1.204.8;
in sparc_interrupt(), wait to enable interrupts until just before calling
the handler and disable them again right after the handler returns.
we don't want another hardware interrupt coming in while we're mucking
with the list pointers. also, clear the intrhand's ih_pending pointer
before calling the handler rather than after, so that if another interrupt
comes in while the handler is running, we can put the intrhand back on
the list so it will be called again.

in send_softint(), disable interrupts via %pstate instead of %pil, so that
hardware interrupts at higher levels are blocked while we manipulate the
intrpending list. also, if the intrhand already has ih_pending set,
don't bother poking the SET_SOFTINT register again, since being on the list
implies that there is already a softint pending in the hardware.

these appear to fix PR 21750 (the "sleep forever" problem).

while I'm here, remove more vestiges of the !INTRLIST softint stuff
(code and comments). and in sparc64_ipi_flush_all(), interrupts are
already disabled so we don't need to fiddle with %pstate.


Revision tags: yamt-km-base2
# 1.203 30-Jan-2005 martin

Remove the no long usefull variants selected by undefining INTRLIST and
INTR_INTERLOCK to improve readability. Same object code generated as before.


Revision tags: yamt-km-base
# 1.202 16-Jan-2005 chs

branches: 1.202.2;
use ENTRY_NOPROFILE() for various entry points,
stack traces work better that way.


Revision tags: kent-audio1-beforemerge kent-audio1-base
# 1.201 03-Dec-2004 chs

branches: 1.201.4;
remove cache_flush_virt() and PADDRT, they're no longer used.
allocate a stack frame for blast_dcache() when profiling so it shows up.
in dcache_flush_page(), use a stride of 32 instead of 16 to match the
cache line size. correct various comments.


# 1.200 08-Nov-2004 petrov

Don't compile sparc64_ipi functions when UP.


# 1.199 25-Oct-2004 martin

No need to clear %o1 when returning a 64 bit integer from pseg_get if we
are compiling for a 64 bit kernel.


# 1.198 24-Jul-2004 nakayama

Change interrupt pending list end value to -1, to avoid linking an
interrupt handler twice.

It may fix "sleep forever" bug.


# 1.197 09-Apr-2004 petrov

Clean-up unused defines and variables.


Revision tags: netbsd-2-0-base
# 1.196 26-Mar-2004 petrov

branches: 1.196.2;
Use want_resched from cpu_info area.


# 1.195 23-Mar-2004 martin

Replace intrcnts by evcnts. XXX - needs slight tweaking for MULTIPROCESSOR.


# 1.194 14-Mar-2004 chs

checkpoint of MP work from dennis and myself. includes cross-processor
interrupt framework, a sledgehammer TLB invalidation and misc MP fixes.
doesn't work at all yet.


# 1.193 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.192 19-Jan-2004 martin

Rename switchexit to cpu_exit and g/c the old C implementation of cpu_exit.


# 1.191 18-Jan-2004 martin

Support RAS for 32bit kernels too.


# 1.190 16-Jan-2004 martin

In proc_trampoline don't bother to clear condition codes in the trap
frame, since we no longer rely on this.
While there fix a few comments.


# 1.189 08-Jan-2004 martin

Minor cleanup


# 1.188 06-Jan-2004 martin

Implement restartable atomic sequences (RAS) for sparc64.


# 1.187 06-Jan-2004 petrov

Spinup secondary cpus. Based on codes sent to me by Dennis Chernoivanov
and Chuck Silvers.


# 1.186 04-Jan-2004 jdolecek

update to recent changes - exit2() doesn't exist anymore and the
exit path always calls lwp_exit2()
pointed out Martin Husemann


# 1.185 02-Dec-2003 martin

Minor cleanup: remove unused code, sync a comment with current reality.


# 1.184 25-Nov-2003 cdi

Use per-cpu pcb, curlwp and fplwp rather than global ones. This brings
GENERIC.MP configuration to a usable state.

Approved by petrov@.


# 1.183 24-Nov-2003 cdi

Call 'proc_trampoline_mp' from 'proc_trampoline' in a multiprocessor
configuration. Fix process locking. Approved by petrov@.


# 1.182 20-Nov-2003 petrov

Remove nwindows calculation, it's not used. Set l_cpu in cpu_switch.


# 1.181 09-Nov-2003 martin

Get rid of bcopy/bzero.


# 1.180 26-Oct-2003 christos

Initial siginfo support for sparc64 (untested). COMPAT_16 sigcontext signal
delivery tested.


# 1.179 24-Aug-2003 chs

add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default. the changes
fall into two basic catagories:

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

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

originally from openbsd, adapted for netbsd by me.


# 1.178 08-Jul-2003 cdi

traceit: don't use %g7 as it is to become curcpu() register. Add comments.


# 1.177 18-May-2003 martin

branches: 1.177.2;
Make kernels with options KGDB at least compile.
Still needs some work to make it working.


# 1.176 29-Apr-2003 nakayama

Use BLOCK_ALIGN rather than BLOCK_SIZE for aligning a pointer.


# 1.175 27-Apr-2003 ragge

Preserve the symbol table in the LKM || KSYMS cases also.


# 1.174 04-Apr-2003 petrov

use branch slot in pmap_copy_page.


# 1.173 24-Mar-2003 nakayama

Divide `set' instruction in delay slot (from OpenBSD change to rev 1.30).


# 1.172 10-Feb-2003 martin

Remove some #if 0 code and a few XXX marked membars w/o proper
justification for their existence.


# 1.171 09-Feb-2003 martin

Remove left over pieces from reusing the signal trampoline for upcalls.
This should fix signal delivery for 32bit kernels.


# 1.170 05-Feb-2003 nakayama

Switch to use cycle counter (%tick) based microtime().

This is derived from alpha/microtime.c and i386/tsc_microtime.c,
and will share with both ports.

This should fix PR port-sparc64/18452.
(approved by martin)


# 1.169 04-Feb-2003 martin

Fix return value of pseg_set, which I accidently broke in rev. 1.164.

Fix register names in comment and shave off another register (hint
from uwe).


# 1.168 01-Feb-2003 martin

Rearrange register usage in pseg_set a bit and shave off %g4.


# 1.167 01-Feb-2003 martin

Remove a few #ifdef _LP64 by using STPTR/LDPTR macros.
Thanks to Matthew Green for the pointer.


# 1.166 31-Jan-2003 martin

Apply leaf procedure optimization to pseg_set (again).


# 1.165 31-Jan-2003 martin

Make the pmap count resident/wired mappings on the fly instead of
walking the page tables whenever this information is needed.

Add an option PMAP_COUNT_DEBUG to assert the new counts and the
page table walk agree.

The old solution had very bad performance impact, for example
by the high CPU load when running top(1).

Thanks to Simon Burge for pointing at the cause of the problem and
to Valeriy E. Ushakov for optimizing my simple minded assembler code.


# 1.164 27-Jan-2003 martin

Remove unused function pseg_find (which looked quite similar to
pseg_get anyway).


# 1.163 18-Jan-2003 thorpej

Merge the nathanw_sa branch.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.162 16-Jan-2003 petrov

Move dump_dtlb back under DDB.


# 1.161 15-Jan-2003 chs

fix two bugs in my last pmap rework:
- in tlb_flush_all(), don't skip TLB entries with the high bit on,
I was confused about which MMU register it was using. it's also fine
to use the last hardware context.
- in pmap_create(), don't allocate a hardware context for the new pmap.
it's unnecessary, and when this would cause us to recycle all the contexts,
it would result in the current process's context being set to 0
(ie. the kernel's context). the current process could then return to
userspace without going through the context-switch code (and thus without
having a hardware context reallocated). this would lead to user mappings
being entered in the kernel's context later, causing all sorts of trouble.
add some assertions to catch this kind of thing.


Revision tags: fvdl_fs64_base
# 1.160 25-Dec-2002 petrov

new function dump_itlb.


Revision tags: gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.159 22-Sep-2002 chs

many improvements:
- use struct vm_page_md for attaching pv entries to struct vm_page
- change pseg_set()'s return value to indicate whether the spare page
was used as an L2 or L3 PTP.
- use a pool for pv entries instead of malloc().
- put PTPs on a list attached to the pmap so we can free them
more efficiently (by just walking the list) in pmap_destroy().
- use the new pmap_remove_all() interface to avoid flushing the cache and TLB
for each pmap_remove() that's done as we are tearing down an address space.
- in pmap_enter(), handle replacing an existing mapping more efficiently
than just calling pmap_remove() on it. also, skip flushing the
TSB and TLB if there was no previous mapping, since there can't be
anything we need to flush. also, preload the TSB if we're pre-setting
the mod/ref bits.
- allocate hardware contexts like the MIPS pmap:
allocate them all sequentially without reuse, then once we run out
just invalidate all user TLB entries and flush the entire L1 dcache.
- fix pmap_extract() for the case where the va is not page-aligned and
nothing is mapped there.
- fix calculation of TSB size. it was comparing physmem (which is
in units of pages) to constants that only make sense if they are
in units of bytes.
- avoid sleeping in pmap_enter(), instead let the caller do it.
- use pmap_kenter_pa() instead of pmap_enter() where appropriate.
- remove code to handle impossible cases in various functions.
- tweak asm code to pipeline a little better.
- remove many unnecessary spls and membars.
- lots of code cleanup.
- no doubt other stuff that I've forgotten.

the result of all this is that a fork+exit microbenchmark is 34% faster
and a fork+exec+exit microbenchmark is 28% faster.


Revision tags: gehenna-devsw-base
# 1.158 18-Jul-2002 wiz

Spell 'should' correctly.


# 1.157 07-Jun-2002 eeh

Shave 10% off the time needed to flush the D$ through a bit of instruction
reordering.


# 1.156 05-Jun-2002 eeh

Handle improperly aligned stack pointers more cleanly.


# 1.155 04-Jun-2002 eeh

Fix the fork trampoline to properly use the supplied tstate.


# 1.154 31-May-2002 thorpej

Make this work with an ISO C preprocessor.


Revision tags: netbsd-1-6-base
# 1.153 14-May-2002 eeh

branches: 1.153.2; 1.153.4;
Only save locals and ins in trapframes for DEBUG kernels.


# 1.152 04-May-2002 kleink

Add some comments to the CPP conditionals controlling the trap macro
definitions, to ease navigation somewhat.


# 1.151 16-Apr-2002 eeh

Make lots of routines profile-friendly and get rid of some cruft.


Revision tags: eeh-devprop-base
# 1.150 21-Mar-2002 petrov

Not needed debug stuff deleted.


# 1.149 16-Mar-2002 mrg

tell newer binutils that our use of %g2 and %g3 is OK here.


# 1.148 15-Mar-2002 eeh

Cleanup MMU initialization to prevent hangs.


Revision tags: newlock-base ifpoll-base
# 1.147 09-Feb-2002 eeh

branches: 1.147.4;
Fix microsecond calculation in microtime.


# 1.146 07-Feb-2002 eeh

Fix register allocation in microtime().


# 1.145 29-Jan-2002 eeh

Shift the UPAID in the correct direction.


# 1.144 17-Jan-2002 eeh

Be more tolerant of unaligned stack pointers.


# 1.143 17-Jan-2002 eeh

Enable block insns in bcopy and bzero.


# 1.142 16-Jan-2002 eeh

In bcopy use 32-bit comparisons in 32-bit kernels.


# 1.141 16-Jan-2002 eeh

Use correct calculation for the trapframe in softtrap for ILP32.


# 1.140 20-Nov-2001 lukem

- pull in opt_kgdb.h where necessary
- replace opt_kgdb_machdep.h with opt_kgdb.h
- defparam opt_kgdb.h:
KGDB_DEV KGDB_DEVNAME KGDB_DEVADDR KGDB_DEVRATE KGDB_DEVMODE
- move from opt_ddbparam.h to opt_ddb.h:
DDB_FROMCONSOLE DDB_ONPANIC DDB_HISTORY_SIZE DDB_BREAK_CHAR SYMTAB_SPACE
- replace KGDBDEV with KGDB_DEV
- replace KGDBADDR with KGDB_DEVADDR
- replace KGDBMODE with KGDB_DEVMODE
- replace KGDBRATE with KGDB_DEVRATE
- use `9600' instead of `0x2580' for 9600 baud rate
- use correct quotes for options KGDB_DEVNAME="\"com\""
- use correct quotes for options KGDB_DEV="17*256+0"
- remove unnecessary dependancy on Makefile for kgdb_stub.o
- minor whitespace cleanup


Revision tags: thorpej-mips-cache-base thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf
# 1.139 14-Sep-2001 thorpej

branches: 1.139.4;
Don't declare intrhand[] here -- that's taken care of in intr.c.


Revision tags: thorpej-devvp-base
# 1.138 30-Aug-2001 eeh

branches: 1.138.2;
Preliminary UltraSPARC III suport (not enabled yet).


# 1.137 13-Aug-2001 jdolecek

g/c _remque()/_insque(); use the C version in libkern


# 1.136 09-Aug-2001 eeh

Fix context masking lossage caused by last version.


# 1.135 08-Aug-2001 eeh

Clean up the trap code to handle the changes cause by supporting non-faulting
accesses. Also change the parameter order so trap frames are easy to find.


# 1.134 07-Aug-2001 eeh

Make sure C code always has ASI_PRIMARY_NOFAULT in the %asi register so
the compiler will be happy if it ever starts generating speculative loads.


# 1.133 05-Aug-2001 eeh

Add support for non-faulting loads and optimize MMU miss handling paths.


# 1.132 02-Aug-2001 eeh

Fix bcopy.


# 1.131 02-Aug-2001 eeh

Sync bzero w/libc version.


# 1.130 01-Aug-2001 eeh

Integrate fixes from userland memset.


# 1.129 31-Jul-2001 eeh

Code cleanup and optimization.


# 1.128 23-Jul-2001 eeh

Get rid of some debug code that really isn't all that useful any more.


# 1.127 19-Jul-2001 eeh

Do ignore unregistered interrupts instead of faulting.


# 1.126 16-Jul-2001 eeh

Make bcopy a 32-bit friendly.


# 1.125 11-Jul-2001 eeh

Fix problems booting 32-bit kernels and dispatching level-15 interrupts.


# 1.124 08-Jul-2001 eeh

branches: 1.124.2;
Code cleanup. Add block_disable to let you turn on block set/copy routines.


# 1.123 05-Jul-2001 eeh

New block bzero and bcopy.


# 1.122 04-Jul-2001 eeh

Replace old bcopy with a much faster version.


# 1.121 01-Jul-2001 martin

Disable axidently enabled debug code to make -current compile again.


# 1.120 30-Jun-2001 eeh

Use a newer version (still disabled) of block bcopy.


# 1.119 30-Jun-2001 eeh

Fixup fpu save restore, get rid of some unused copy functions, and add
a new bcopy.


# 1.118 21-Jun-2001 eeh

Allow multiple 4MB pages for both kernel text and kernel data.

Note: DEBUG checks will not allow accesses to the hole between
text and data segments, so you may need to update programs that
use libkvm before relocating the start of kernel data.


# 1.117 06-Jun-2001 mrg

extract the netbsd32, sunos, 32 bit svr4 and 64 bit svr4 sigcode out into
separate files, so that compat lkms can link with them as well.


# 1.116 30-May-2001 lukem

add missing #include "opt_kgdb.h"


Revision tags: thorpej_scsipi_beforemerge
# 1.115 25-Apr-2001 simonb

Spell occurred correctly.


Revision tags: thorpej_scsipi_nbase thorpej_scsipi_base
# 1.114 09-Apr-2001 eeh

Interrupt latency fix from sparc port. (Hm. One insn instead of 5).


# 1.113 07-Mar-2001 eeh

Fix inverted preprocessor logic. (Spotted by Charles.)


# 1.112 21-Feb-2001 eeh

branches: 1.112.2;
Add support for 64-bit SVR4 (Solaris 8) binaries.


# 1.111 10-Feb-2001 pk

Fix conditional for svr4 compat inclusion.


# 1.110 05-Feb-2001 eeh

Add signal trampoline for 64-bit svr4 emulations.


# 1.109 31-Dec-2000 eeh

Make INCR() atomic.


# 1.108 29-Dec-2000 eeh

pseg_get tells us whether it really needed that spare page after all.


# 1.107 07-Dec-2000 eeh

Fixup calculating where fpstate should be saved in the signal trampoline
code so it doesn't overwrite something important like the registers.


# 1.106 09-Nov-2000 eeh

Fix ILP32 bug in probe_get().


# 1.105 22-Oct-2000 pk

Restore revision 1.102.

I hope it sticks this time..


# 1.104 20-Oct-2000 eeh

Fix hang in 32-bit kernels caused by relocation of KERNBASE.


# 1.103 04-Oct-2000 eeh

Fix interrupt lossage problem and some cosmetic changes.


# 1.102 01-Oct-2000 pk

cpu_initialize: global registers aren't preserved across calls to
prom_printf(), so replace %g3 with %l7 (which isn't used despite
the `usage' comment).

Also, clean up white-space turds.


# 1.101 29-Sep-2000 eeh

This seems to fix the interrupt lossage of non-debug kernels.


# 1.100 28-Sep-2000 eeh

Fix INTR_SETUP() to properly distinguish kernel and user addresses.

Make microtime() return the correct time on %tick machines.

Re-enable debug stuff in dostart for now to detect kernel mapping issues.


# 1.99 25-Sep-2000 pk

Missing `#if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)'


# 1.98 17-Sep-2000 eeh

Make the improved %tick changes work with machines that use the counter-timer
for the clock.


# 1.97 12-Sep-2000 eeh

Fix new version of microtime.


# 1.96 11-Sep-2000 eeh

(Hopefully) fix clock skew on machines that us %tick for the clock (UIIi).


# 1.95 31-Aug-2000 eeh

Use casx instead of stx to change entries in the page table trees.


# 1.94 23-Aug-2000 eeh

Update the scheduler to the new locking scheme.


# 1.93 10-Aug-2000 eeh

Fix signal delivery.


# 1.92 02-Aug-2000 eeh

Get kernel profiling to work. Now if only gprof worked....


# 1.91 01-Aug-2000 eeh

Overhaul cache flush code and coredump code.


# 1.90 25-Jul-2000 pk

Re-instate a couple of delay slot NOPs marked `XXX spitfire bug?'


# 1.89 24-Jul-2000 mycroft

Optimization to pmap_zero_page(): we only need to use the first 16 FP regs,
as in bzero().


# 1.88 24-Jul-2000 mycroft

Fix a whitespace glitch.


# 1.87 24-Jul-2000 mycroft

Pull in the bzero() changes from libc for real, with a couple of kernel-
specific hacks:
* Make the bias handling depend on STKB, so it switches correctly for 32-bit
kernels.
* Use the 32-bit stw/ld for 32-bit kernels.
* Add a few `-STKB's that were missed in the previous change.


# 1.86 24-Jul-2000 pk

Cosmetic & readability:
- local label cleanup in interrupt handling code;
- in debugging sections when testing `intrdebug': use a unique
local label (97) to enhanced clarity;
- comment-out unused code;
- kill a bug as the satisfying result of doing all of the above.


# 1.85 24-Jul-2000 eeh

Fix stack issues in bzero.


# 1.84 24-Jul-2000 mycroft

Revert the previous change for now. I don't have time to debug it tonight.


# 1.83 23-Jul-2000 mycroft

Copy bzero change from libc.


# 1.82 20-Jul-2000 pk

Since `intrcnt' points to an array of long ints, reserve the appropriate
amount of space depending on _LP64. Provide macros to load/store signed
and unsigned long ints.

Also, make the `intrcnt' and `intrpending' arrays 16 entries long, as on
sparc/v9 interrupt #15 is just a regular interrupt.


# 1.81 19-Jul-2000 eeh

Fix merge problem.


# 1.80 19-Jul-2000 eeh

Disable interrupt interlock using ih->ih_pending field. Seems to cause
more problems than it solves.


# 1.79 19-Jul-2000 eeh

Miscellaneous cleanup.


# 1.78 18-Jul-2000 pk

Correct args usage comment in probeget.
Whitespace cleanup.


# 1.77 18-Jul-2000 pk

probeget: 9 -> 0x9


# 1.76 18-Jul-2000 pk

If `ih_pending' is set simply return from the trap, don't schedule another
soft interrupt.


Revision tags: mrg-merge-1-5-top
# 1.75 18-Jul-2000 pk

openfirmware: don't lower %pil


# 1.74 17-Jul-2000 pk

Kill typos in interrupt code.


# 1.73 17-Jul-2000 pk

probeget: do the same song and dance as ld*a() macros in ctlreg.h do.


# 1.72 14-Jul-2000 eeh

Move some macro definitions out of genassym and into locore.s


# 1.71 08-Jul-2000 mrg

backout part of previous: turn off intrdebug, and another debug message


# 1.70 07-Jul-2000 pk

Changes for readability:
- #define LP64 dependent STACKFRAME macro once
- use a LOAD_ASCIZ macro for setting up the format string
for debug messages.


# 1.69 07-Jul-2000 eeh

Temporary fix to prevent the clock from stopping on UIIi machines.


# 1.68 03-Jul-2000 eeh

Prevent interrupts from being posted if they are active and deprecate polled
interrupts. This seems to eliminate the spurious interrupts.


# 1.67 02-Jul-2000 eeh

Clean up interrupt handling some more.


# 1.66 30-Jun-2000 eeh

Fix interrupt delivery on UltraSPARC IIi machines.


# 1.65 24-Jun-2000 eeh

With these changes the kernel seems almost stable again.


# 1.64 24-Jun-2000 eeh

More VM cleanup:

Move the cpu_info structure above the interrupt stack so it won't
get corrupted if the stack overflows.

Flush the D$ before and after all MMU bypass accesses since the
D$ latches all of those.


# 1.63 23-Jun-2000 eeh

Make probeget() and probeset() really work for a change.


Revision tags: netbsd-1-5-base
# 1.62 19-Jun-2000 eeh

branches: 1.62.2;
Have separate data and text segments, make text read-only.


# 1.61 12-Jun-2000 eeh

Start reorganizing the kernel for MULTIPROCESSOR support.


# 1.60 31-May-2000 thorpej

Add a comment about needing to initialize p_cpu when multiple
processors are supported.


Revision tags: minoura-xpg4dl-base
# 1.59 26-May-2000 thorpej

branches: 1.59.2;
First sweep at scheduler state cleanup. Collect MI scheduler
state into global and per-CPU scheduler state:

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

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

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

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

Tested on i386 and Alpha. Changes are mostly mechanical, but apologies
in advance if it doesn't compile on a particular platform.


# 1.58 26-May-2000 thorpej

Don't set `runtime' here; it's done at the end of mi_switch().
cvS: ----------------------------------------------------------------------


# 1.57 26-May-2000 thorpej

Introduce a new process state distinct from SRUN called SONPROC
which indicates that the process is actually running on a
processor. Test against SONPROC as appropriate rather than
combinations of SRUN and curproc. Update all context switch code
to properly set SONPROC when the process becomes the current
process on the CPU.


# 1.56 22-Apr-2000 eeh

If we trap due to a bad kernel stack, try to switch to the interrupt strack
before breaking into the debugger.


# 1.55 18-Apr-2000 eeh

Prevent the system from getting watchdog reset by returning directly to user
mode if restoring the user window traps. Also reduce the time we run with
%tl>0.


# 1.54 13-Apr-2000 eeh

Apparently gas 2.9.5 (don't ask) does not like to add values to %lo()
directives so move the additions inside %lo() to make it happy.
Hopefully this won't break older versions.


# 1.53 10-Apr-2000 mrg

- fix a speeling error
- rename some numbered labels to be a bit less confusing.
- remove dead code
- fix a debug error message (argh!)


# 1.52 10-Apr-2000 pk

Get a kernel without DDB to build.


# 1.51 16-Mar-2000 eeh

Revamp interrupts again:

Fix a bug causing interrmittent panics in interrupt dispatch.
Use interrupt vectors for softints.
Add a new send_softint interface.
Improved D$ flushing.
Improve traptrace and other debugging enhancements.


Revision tags: chs-ubc2-newbase
# 1.50 16-Jan-2000 eeh

Interrupt handlers return zero if they didn't handle the interrupt.


# 1.49 10-Jan-2000 eeh

Add debugger single-stepping and fix interrupt dispatch bugs.


# 1.48 30-Dec-1999 eeh

Lots of changes:

remove ffs()
add bzero that uses block store insns
save %gsr to fpstate
revert to physical accesses for pmap_zero_page so we don't
have conflicting page mappings
general cleanup.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base fvdl-softdep-base
# 1.47 06-Nov-1999 eeh

Handle zero length properly in copyinstr() copyoutstr() and copystr().


Revision tags: comdex-fall-1999-base
# 1.46 11-Oct-1999 eeh

branches: 1.46.2; 1.46.4;
Update to post 1.4.


# 1.45 05-Oct-1999 eeh

branches: 1.45.2;
Make broken versions of gas happy by using sethi/or instead of set for
(negative) addresses.


# 1.44 17-Sep-1999 thorpej

Centralize the declaration and clearing of `cold'.


Revision tags: chs-ubc2-base
# 1.43 18-Jul-1999 eeh

More fun with pmap.


# 1.42 21-Jun-1999 eeh

Improve TRAPTRACE. Add FLTRACE that only tracks MMU faults.


# 1.41 05-Jun-1999 eeh

Make pbrobeget() and probeset() work for 64-bit values as well. To do this
the arguments are changed so the address is first and the ASI second so we
can have the address in %o0:%o1 and not worry about unused registers.

Also a bit of copyright cleanup.


# 1.40 05-Jun-1999 mrg

update a commit slightly.


# 1.39 30-May-1999 eeh

Add code to support using %tick as the system clock if no "counter-timer" node
is found.


# 1.38 09-May-1999 eeh

Fixup non-DEBUG kernels.


# 1.37 29-Apr-1999 christos

Add sunos_sigcode (32 bit only)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.36 26-Mar-1999 eeh

branches: 1.36.4;
COMPAT_SPARC32 -> COMPAT_NETBSD32


# 1.35 25-Mar-1999 mrg

clean and up make compile


# 1.34 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.33 22-Mar-1999 eeh

Need to set up the pointers properly for partial FPU register stores.


# 1.32 22-Mar-1999 eeh

Flush D$ on bypass accesses.


# 1.31 28-Feb-1999 eeh

Use block load/store in pmap_zero_page()/pmap_copy_page().


# 1.30 17-Feb-1999 eeh

Let's test out vectored interrupts.


# 1.29 15-Feb-1999 hubertf

RCS ID police


# 1.28 11-Feb-1999 mrg

fix a comment pasto.


# 1.27 11-Jan-1999 eeh

Finally fixed 64-bit signal trampoline.


# 1.26 10-Jan-1999 eeh

Handle the symbol table properly in a 32-bit kernel that was booted from a
64-bit bootloader.


# 1.25 09-Jan-1999 eeh

More signal fixup.


Revision tags: kenh-if-detach-base
# 1.24 26-Nov-1998 mycroft

Sync kcopy() with 32-bit SPARC version.


# 1.23 16-Nov-1998 eeh

Fixup the last broken bits of the signal handling code.


Revision tags: chs-ubc-base
# 1.22 08-Oct-1998 eeh

Fix more syscall32 and signal breakage.


# 1.21 22-Sep-1998 eeh

More fixup in the signal area.

64-bit syscall cleanup.

Add emulation for some new FPU insns: conversion to 64-bit long int and
conditional moves.


# 1.20 17-Sep-1998 thorpej

SYS_sigreturn -> SYS___sigreturn14.


# 1.19 13-Sep-1998 eeh

Fixup signal changes (hopefully). However SUN_COMPAT is likely broken by
this and I don't know how to fix it.

We can now exec a 64-bit init through a really ugly hack (don't ask.)


# 1.18 11-Sep-1998 eeh

Add labels for the compat_sparc32 signal trampoline and break -- er -- fix
suword and fuword.


# 1.17 09-Sep-1998 eeh

Don't use %tick for microtime on 32-bit kernels -- breaks gettimeofday.


# 1.16 09-Sep-1998 thorpej

Adjust for the new "reaper" kernel thread: do not free the vmspace and
u-area in machine-dependent code. Instead, call exit2() to schedule
the reaper to free them for us, once it is safe to do so (i.e. we are
no longer running on the dead proc's vmspace and stack).


# 1.15 07-Sep-1998 eeh

Fix data corruption problem caused by broken debug code.


# 1.14 07-Sep-1998 eeh

Add new 64-bit trap vectors.


# 1.13 06-Sep-1998 eeh

32-bit fixup.


# 1.12 06-Sep-1998 eeh

Disable some debug stuff.


# 1.11 05-Sep-1998 eeh

It slices. It dices. It does everything except exec a sparc32_compat init.


# 1.10 02-Sep-1998 eeh

Periodic update: now starts probing devices.


# 1.9 30-Aug-1998 eeh

Some more 64-bit cleanup. Now everything compiles.


# 1.8 29-Aug-1998 eeh

Some more 64-bit-ification.


# 1.7 27-Aug-1998 eeh

Add 64-bit pmap support:

Moved from a two level 512/1024 entry setup mapping 32 (9/10/13) bits
respectively to a three level 1024/1024/1024 entry setup mapping 43
(10/10/10/13) bits. In 32-bit mode we waste about 1/12 pages mapping the high
11 bits. We also only manage 43 of the possible 44 bits of virtual address
space, wasting half of it. Oh well, maybe we'll do better next revision.


Revision tags: PMAP32
# 1.6 26-Aug-1998 mrg

panicstack: is needed outside of DEBUG. use _C_LABEL, and printf not db_printf (incase no ddb!)


# 1.5 13-Aug-1998 eeh

Merge paddr_t changes into the main branch.


Revision tags: eeh-paddr_t-base
# 1.4 07-Jul-1998 eeh

branches: 1.4.2;
General update:

Added genassym.cf
Removed lderr which should never have gotten in
Removed lots of dead code from locore.s
Added some softint stuff to intr.c
Added support for halt -p
esp and le both use bus_dmamap_*() functions now
instead of kdvma_mapin()
groundwork for PCI (but we still have no drivers for
any sun4u PCI devices)


# 1.3 04-Jul-1998 jonathan

defopt DDB.


# 1.2 26-Jun-1998 thorpej

defopt COMPAT_SVR4


# 1.1 20-Jun-1998 eeh

branches: 1.1.1;
Initial revision


# 1.412 26-Aug-2017 palle

sun4v: Avoid touching the %tick_cmpr register which is not present on never systems (Oracle SPARC Architecture 2011 and beyond). Based on code from OpenBSD locore.s revision 1.177. Tested on both sun4u (qemu and USIII) and sun4v (qemu and T5-2). ok martin@


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2
# 1.411 06-May-2017 palle

sun4v: The %ver register is not available on sun4v - use GET_MAXCWP introduced in rev. 1.361. Verified using qemu (sun4u and sun4v) and on real sun4v hw (t2000)


Revision tags: prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.410 18-Apr-2017 palle

branches: 1.410.2;
sun4v: Add handling of trap 0x06c @ trap level 1 - based on code from OpenBSD, but slightly adapted to NetBSD. verified using qemu


Revision tags: jdolecek-ncq-base pgoyette-localcount-20170320
# 1.409 19-Feb-2017 palle

sun4v: rft_user needs special handling (a manual fill) since the restore instruction may cause the number of trap levels to exceed the maximum for sun4v - inspired by code from the the openbsd rft_user code path - verified using qemu for both sun4u and sun4v


# 1.408 10-Feb-2017 palle

sun4v: Added handling of trap type 0x034 (address alignment error) + fixed typo mmfsa -> mmufsa. Verified for both sun4u and sun4v using qemu.


Revision tags: nick-nhusb-base-20170204
# 1.407 30-Jan-2017 palle

sun4v: Hook up syscall handling to the trap table. Verified using qemu for both sun4u and sun4v.


# 1.406 27-Jan-2017 palle

sun4v: implement missing handling of itsb traps 0x008 and 0x009. Based on code from OpenBSD. Tested using qemu.


Revision tags: bouyer-socketcan-base
# 1.405 07-Jan-2017 palle

branches: 1.405.2;
sun4v: slowtrap() now selects normal globals properly on both sun4u and sun4v platforms. Verified using qemu for both sun4u and sun4v systems


Revision tags: pgoyette-localcount-20170107
# 1.404 05-Jan-2017 palle

sun4v: TRAP_SETUP() updated to set mmu context id properly for both sun4v and sun4u platforms. Verified using qemu for both sun4u and sun4v systems


# 1.403 04-Jan-2017 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x00-0x23 and 0x28-0x30


# 1.402 29-Dec-2016 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x32-0x7f


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.401 20-Sep-2016 nakayama

Fix RAS for 32-bit kernels. trapframe is always 64-bit.


Revision tags: localcount-20160914
# 1.400 23-Aug-2016 palle

sun4v: rework sun4v_datatrap so it works properly when running on a T2-based system like T5120 - for some reason %tl is 0 when entering sun4v_datatrap causing a crash (sir instruction), so ignore the %tl value for now upon entry to sun4v_datatrap - with this fix both T1 and T2 based systems reach the same point - hangs in rft_user after the init process is started


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726
# 1.399 18-Jul-2016 palle

sun4v: handle device interrupts properly - both legacy (sysino) and cookies


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 1.398 04-Jun-2016 palle

branches: 1.398.2;
sun4v: rtf_user now uses macros GET_MMU_CONTEXTID and SET_MMU_CONTEXTID. Tested on sun4u (QEMU) and sun4v (T2000). Parts from OpenBSD.


Revision tags: nick-nhusb-base-20160529
# 1.397 18-May-2016 nakayama

Decrement %tl in trap handler not to make it zero unconditionally
for the nested trap, and remove useless mov.


# 1.396 17-May-2016 palle

sun4v: Implement missng MMU protection trap handling - mostly from OpenBSD


# 1.395 16-May-2016 palle

Avoid assembler-specific defines by using the export keyword in genassym.cf instead


# 1.394 15-May-2016 nakayama

%g1 is not preserved across function call, so load it before
return_from_trap.


# 1.393 13-May-2016 palle

sun4v: add missing implementation of sun4v_datatrap_tl0 so data_access_fault() is called - mostly from OpenBSD


# 1.392 13-May-2016 nakayama

- ci_paddr is always 64-bit.
- intrlev is array of pointer.
- ih_ack is pointer.


# 1.391 10-May-2016 palle

sun4v: make device interrupts work. Introduce a new intrhand_alloc() function for allocation of interrupt handlers and adapt to this. Parts from OpenBSD. ok martin@


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.390 09-Mar-2016 nakayama

32-bit kernels use 32-bit stack.


# 1.389 03-Mar-2016 palle

sun4v: rft_kernel should pay attention to the number of register windows that can be restored. We cannot rely on fill traps to occur, since sun4v only has two trap levels available in privileged mode. Based on code from OpenBSD. ok martin@


# 1.388 14-Feb-2016 palle

sun4v: add breakpoint trap entry to the sun4v trap table


# 1.387 03-Feb-2016 palle

sun4v: extend dmmu_set_secondary_context() to handle both sun4u and sun4v. ok martin@


Revision tags: nick-nhusb-base-20151226
# 1.386 06-Nov-2015 martin

Basically revert r1.246 of locore.s and r1.73 of vm_machdep.c:

Remove special case handling for userland lwps from cpu_lwp_fork,
instead do it in lwp_trampoline when we first return to userland.

which was a stupid idea - since we did now set all fork child's %tstate
(and thus %pstate when back in userland) to the current kernel's userland
default. This meant we lost the address mask bit for 32bit processes and
all memory model details for 64bit ones.

Move it back to cpu_lwp_fork and fix the condition to only do it once when
forking init.


# 1.385 05-Nov-2015 martin

Most of the time return_from_trap already got called with tf->tf_tstate
loaded in register %g1 - make it so for two more callers and remove
the reload of that value.


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606 nick-nhusb-base-20150406
# 1.384 05-Apr-2015 palle

sun4v: Ensure that the TTEs CP and CV bits are the same (both set) for the primary cpu and secondary cpus INTSTACK mappings


# 1.383 01-Apr-2015 palle

sun4v: Implement handling of cpu_mondo trap - from OpenBSD - tested using the Legion simulator


# 1.382 04-Mar-2015 palle

sun4v: revert some of the logic introduced in revision 1.378 - flushw is not necessary on sun4v (OpenBSD patches the flushw instruction to a nop instruction) - with these changes the kernel reaches cpu_boot_secondary_processors() when running in the Legion simulator (crashes due to missing handling of cpu_mondo_trap)


# 1.381 02-Mar-2015 nakayama

prom_printf converts "\n" to "\r\n" internally, so omit "\r".


# 1.380 02-Mar-2015 nakayama

PANICSTACK is a pointer itself, not a pointer to pointer.


# 1.379 02-Mar-2015 nakayama

Use panic stack temporarily for calling prom_printf in a trap
handler.

It seems that openfirmware cannot handle over 4GB pointers, and
stack pointers may point to over 4GB since VA layout was rearranged
by rev 1.33 of vmparam.h. Therefore, use panic stack to avoid
panicking in OF_write used by prom_printf.


# 1.378 23-Feb-2015 palle

sun4v: sparc_interupt - ensure that the trap level and globals level are the same when the flushw instruction is issued - othwise warnings occur when using the sun4v Legion simulator.


Revision tags: nick-nhusb-base
# 1.377 26-Oct-2014 palle

branches: 1.377.2;
sun4v: Create CLEANWIN0 and CLEANWIN1 macros for handling clean window traps on both sun4u and sun4u (based on the original code inlined in the sun4u trap table). Update trap tables accordingly for both sun4u and sun4v. Ok martin@


# 1.376 24-Oct-2014 nakayama

Fix typo in comment.


# 1.375 18-Oct-2014 snj

src is too big these days to tolerate superfluous apostrophes. It's
"its", people!


# 1.374 15-Oct-2014 palle

sun4v: fixed bug causing the real address to be incorrectly calculated as zero


# 1.373 24-Sep-2014 palle

sun4v: add code to enable startup of secondary cpus on both sun4u and sun4v systems - ok martin@


# 1.372 04-Sep-2014 palle

sun4v: All cpus must be setup with a TSB descriptor, so pmap_setup_tsb_sun4v() must take a pointer to the TSB descriptor


# 1.371 31-Aug-2014 palle

sun4v: Split the NORMAL_GLOBALS and ALTERNATE_GLOBALS macros to _SUN4U and _SUN4V variants. Rework the return_from_trap logic to use the new variants so it is possible to use a global register as scratch register.


# 1.370 14-Aug-2014 nakayama

Add missing delay slot in DEBUG kernel.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.369 30-Jul-2014 palle

branches: 1.369.2;
Fix ALTERNATE_GLOBALS so it at least works on sun4u - using a scratch register is not a good idea...


# 1.368 27-Jul-2014 palle

sun4v: Introduce a new macro ALTERNATE_GLOBALS (matching NORMAL_GLOBALS). Two new helper macros ENABLE_INTERRUPTS and DISABLE_INTERRUPTS are also created. With these changes the GENERIC.UP kernel will reach rootmount on sun4v systems - ok martin@


# 1.367 26-Jul-2014 palle

Improved the NORMAL_GLOBALS macro in the sun4u case, so only the relevant bit (AG) in %pstate is affected - ok martin@


# 1.366 24-Jul-2014 palle

sun4v: add missing spill/fill handling for trap level 1 + cosmetic changes to comments for trap level 0 entries


# 1.365 19-Jul-2014 palle

sun4v: Introduce a NORMAL_GLOBALS macro - first used in sparc_interrupt - other relevant uses will be handled as the sun4v work is progressesing - ok martin@


# 1.364 16-Jul-2014 palle

sun4v: Introduce SET_MMU_CONTEXTID macro for setting the mmu context id on both sun4u and sun4v


# 1.363 13-Jul-2014 palle

sun4v: add interrupt handling to sun4v trap table


# 1.362 13-Jul-2014 palle

Bugfix: add missing cmp instruction to GET_MAXCWP macro


# 1.361 30-Jun-2014 palle

sun4v: The maximum number of register windows is a constant and thus not available via the %ver register (sun4u only). Introduce a macro GET_MAXCWP that handles this, so cpu_switchto() works properly on sun4v. Other relevant reference to %ver can be adapted to use GET_MAXCWP as the sun4v port progresses. OK martin@


# 1.360 31-May-2014 palle

sun4v: added missing dtsb miss handling for trap level 1 - with this update the kernel now reaches configure() on sun4v systems


# 1.359 30-May-2014 palle

Remove debugging code introduced by accident in locore.s revision 1.357


Revision tags: yamt-pagecache-base9 rmind-smpnet-nbase rmind-smpnet-base
# 1.358 05-May-2014 palle

sun4v: the trap base address should be assigned to %l1 so %tba is properly setup later in the code - now the kernel gets as far as printing the copyright disclaimer, kernel version and total and available memory before crashing


# 1.357 21-Apr-2014 palle

sun4v: Update comment: modified -> access


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.356 21-Feb-2014 palle

branches: 1.356.2;
sun4v: Rename TLB_ defines to SUN4U_TLB_ so entries created using TSB_DATA() are properly setup for sun4u and sun4v. Relocate the cputyp variable from autoconf.c to locore.s and make it const in param.h so optimized code can be generated. Parts from OpenBSD. Optimization suggested by nakayama@. OK martin@, mrg@, nakayama@


# 1.355 31-Jan-2014 tsutsui

defined(LKM) -> defined(MODULAR)


# 1.354 26-Jan-2014 palle

sun4v: Add handling of spill/fill and dtsb miss traps (with a XXX to be handled later)


# 1.353 07-Jan-2014 palle

sun4v: trap table setup - currently populated with dummy entries which will be properly implemented later - parts from OpenBSD - OK martin@


# 1.352 29-Dec-2013 nakayama

Make buildable w/o options SUN4V.


# 1.351 27-Dec-2013 palle

a) make the hunt through the cpus list more generic b) sun4v: ensure that the interrupt stack is mapped permanently and the TSB is setup properly - parts from OpenBSD. OK martin@


# 1.350 06-Dec-2013 nakayama

Increase an interrupt depth only in the case of hardware interrupts,
and remove the ci_idepth trick in softint_fastintr.

Fixes the following diagnostic panic reported in port-sparc64.

panic: kernel diagnostic assertion "!cpu_intr_p()" failed: file
"../../../../kern/subr_xcall.c", line 351


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 1.349 24-May-2013 nakayama

branches: 1.349.2;
Disable interrupts after calling data_access_error as with
data_access_fault.


# 1.348 28-Apr-2013 nakayama

Use macros in machine/asm.h instead of locally defined, and
introduce CASPTRA for casxa/casa.


Revision tags: agc-symver-base
# 1.347 23-Jan-2013 martin

Fix sparc64_ipi_ccall by adding proper trap setup.
Fixes xcall(9) problems, as exposed by pserialize(9). Noticed by
J. Hannken-Illjes, cause pointed out by Takeshi Nakayama.


# 1.346 23-Jan-2013 martin

Sligthly clean up the (by default unused) #ifdef TRAPS_USE_IG


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.345 10-Nov-2012 nakayama

Revise comment.


# 1.344 10-Nov-2012 nakayama

Use macro instead of magic number.


# 1.343 09-Nov-2012 nakayama

Make setstick() and getstick() to inline functions.


# 1.342 08-Nov-2012 macallan

use system tick timer instead of %tick on UltraSPARC-III-ish CPUs
review & fixes by Takeshi Nakayama


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.341 17-Mar-2012 mrg

branches: 1.341.2;
port the corrected ECC error handling code from freebsd. i noticed my U10
took one of these and then hang. it shouldn't hang, there's a 'sir' here that
doesn't seem to reset properly. oh well.

tested by simulated a trap via 'ta 0x10' and considering that the same, but
it hasn't been tested against a real ECC error yet.


Revision tags: jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base4
# 1.340 03-Mar-2012 nakayama

Fix the root cause of the hack "disable optimizations for uvm_bio.c
on 32 bit kernels".

gcc converts a division in the calculation of UBC_UMAP_ADDR macro
to multiplication (smul or combination of add/sll), and the
register of its result contains a garbage in upper 32 bits (the
upper 32 bits of smul/add/sll's result isn't zero cleared).

Then it passes to pseg_get{,_real} through pmap_extract without the
zero clear of upper 32 bits in the optimization case. So the
result of pseg_get and pmap_extact sometimes gets screwed up.


Revision tags: jmcneill-usbmp-base5 jmcneill-usbmp-base3
# 1.339 19-Feb-2012 rmind

Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.


Revision tags: jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.338 04-Sep-2011 nakayama

branches: 1.338.2; 1.338.6; 1.338.8;
ih_pil is an interrupt level, not an interrupt mask.


# 1.337 27-Jul-2011 nakayama

ivec is assigned to hardware, so count its event counter up in
interrupt_vector, not in softint, and do some optimization.


# 1.336 20-Jul-2011 macallan

add per ivec event counters


# 1.335 12-Jul-2011 mrg

rename sparc64 BLOCK_SIZE and BLOCK_ALIGN to have SPARC64_ prefixes.
for the assembler files, define the old names to the new names
since using the new names cause ugliness due to longer identifer
names, and reduces churn.

fixes build issues in dtv and vaguely makes <machine/psl.h> slightly
less name-space invasive.


# 1.334 18-Jun-2011 nakayama

Add fast softint(9) support for sparc64.

Reviewed on port-sparc64.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 1.333 12-May-2011 mrg

branches: 1.333.2;
first steps towards fujitsu SPARC64 support:

- SPARC64 systems have interrupts with upto 14 bits set, but we only look
at the first 11 bits. trim non IPI interrupts to 11 bits


Revision tags: uebayasi-xip-base7 bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 jym-xensuspend-nbase jym-xensuspend-base
# 1.332 20-Dec-2010 matt

branches: 1.332.2;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.


Revision tags: uebayasi-xip-base6 uebayasi-xip-base5 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 1.331 10-Jul-2010 nakayama

Clear the upper word explicitly before combining two 32-bit values to 64-bit
on 32-bit kernels.


# 1.330 23-May-2010 martin

Split copy related functions out of locore.s into copy.S, move functions
only needed on multiprocessors into mp_subr.S.


# 1.329 17-May-2010 martin

Simplify primary CPU startup slightly by using the fact that our cpuinfo's
curpcb pointer points to the uarea/pcb of lwp0 and by remembering the pointer
to this cpuinfo, thus avoiding a few CPUINFO_VA references.


Revision tags: uebayasi-xip-base1
# 1.328 20-Mar-2010 chs

fix copy{in,out}{,str}() to return the error returned by uvm_fault().
fixes PR 41813.


Revision tags: yamt-nfs-mp-base9
# 1.327 10-Mar-2010 mrg

branches: 1.327.2;
XXX: workaround we'd like to remove when pmap / uvm locking is cleaned up:

- rename pseg_get() and pseg_set() to pseg_get_real() and pseg_set_real().
- if USE_LOCKSAFE_PSEG_GETSET is defined, which it current is by default,
define pseg_[gs]et() in terms of functions that take a new pseg_lock
mutex at IPL_VM while calling into the real functions.

this seems to avoid the pseg_set() crashes we've seen:
1 - spare needed, when pseg_get() just worked for this pmap
2 - the 2rd ldxa via ASI_PHYS_CACHED in pseg_set() loads garbage
into %o4, and causes the 3rd ldxa to fault


# 1.326 08-Mar-2010 mrg

blast_dcache() SMP friendly:

- blast_dcache() becomes sp_blast_dcache(dcache_size, dcache_line_size)
- new smp_blast_dcache(sparc64_cpuset_t) that blasts the D$ on this cpuset
- sparc64_ipi_blast_dcache() to support the above
- in pmap_remove_all(), when freeing mmu contexts for this pmap, mark
the set of cpus to blast the d$ on as well and convert the
blast_dcache() call into smp_blast_dcache() on the cpus who ran this
pmap, or, sp_blast_dcache(dcache_size, dcache_line_size)
- convert the remaining blast_dcache() in machdep.c to sp_blast_dcache()
- in pmap_destroy()/pmap_remove_all() take the pmap_lock() always since
we assert it is held always.

with these changes, NFS builds on the U60 seem to be stable now, and
the USIII machines also can often complete a single build.sh run now,
diskful or diskless.


reviewed by mlelstv and partially by martin, tested by martin and myself,
with some ideas from chuq as well.


# 1.325 07-Mar-2010 mrg

need _ALIGN in locore.h as well, for DEBUG kernels.


# 1.324 07-Mar-2010 mrg

gas has supported SPARC ".empty" for a long while; get rid of an
ancient workaround.


# 1.323 06-Mar-2010 mrg

move the memcpy/memset implementations out into their own file, with the
block copy versions as well. move some of the definitions in locore.s
into a new locore.h.

locore.s is almost 2000 lines shorter with this change.


# 1.322 04-Mar-2010 mrg

- in _bus_dmamap_unload(), pmap_page_protect() and pmap_clear_reference()
switch the dcache_flush_page() into a dcache_flush_page_all()
- in both pmap_kremove()/pmap_remove(), remove the blast_dcache() call
and replace it with dcache_flush_page_all()
- in pmap_get_page() [used to allocate PTP's], always call pmap_zero_page(pa)
- flush the dcache of the dst page in pmap_{copy,zero}_page() by redirecting
throught a C function that calls the (renamed) asm. the old asm code had a
comment about needing to do this...
- add a couple of membar #Sync's that the USIII manual recommends


based on discussions with chuq@, skrll@ and martin@.


these help my SB2000 / SB2500 with both disk / nfs builds and other tasks,
sometimes lasting for several hours before failing or asserting.


# 1.321 24-Feb-2010 mrg

when handing back page table pages to UVM, flush them from the dcache
on all CPUs.

idea from skrll@, and makes my disk-based SB2000 stable.

tested on U60, SB2000 and SB2500.


# 1.320 24-Feb-2010 mrg

- re-introduce sp_tlb_flush_pte() and sp_tlb_flush_all() that call
the right USI/USIII version.
- define tlb_flush_pte() in terms of sp_tlb_flush_pte() for the
!MULTIPROCESSOR case

this centralises some CPU_IS_USIII_UP() tests.


# 1.319 22-Feb-2010 mrg

move {dump,print}_[id]tlb() into a separate file.


# 1.318 22-Feb-2010 mrg

- store the maximum [id]cache size / line size for each cpu

- remove patch_kernel() since it isn't necessary and has been patching
the wrong thing in general.

- implement USIII versions of blast_icache(), dcache_flush_page() and
cache_flush_phys(). use the newly recorded cache size/line sizes.

- in winfixsave, flush the D$ with the right size index and ops. this
kills one of the wrong tag->inval patches.

- for blast_dcache(), use the newly recorded dcache_size/line_size.

- for blast_icache(), use the newly recorded cache size/line sizes.
for the USIII verison, disable the I$ while writing to ASI_ICACHE_TAG.


these changes removed several hard coded cache sizes values, some very
wrong kernel patching, and seem to make the current failure modes for
USIII less common, but not gone.


# 1.317 15-Feb-2010 mrg

- don't flush 32-bit entries for 64-bit code, it does not seem to be
necessary. #define TLB_FLUSH_LOWVA to turn it back on.
- remove the #if 0'd code in sparc64_ipi_flush_pte_usiii(), i have
verified that it is not required.
- add a missing membar #Sync to sp_tlb_flush_pte_usiii().


# 1.316 15-Feb-2010 nakayama

Fix linker error of GENERIC32 kernel.


# 1.315 15-Feb-2010 mrg

use TLB_SIZE_SPITFIRE in a couple of places, and note that the
{print,dump}_[id]tlb() versions are currently spitfire specific.


# 1.314 15-Feb-2010 mrg

introduce a new patch_kernel() and call it from the end of bootstrap().
use it to patch up TLB flush instructions that don't match for USI/II
and later. we can also hopefully use this to make GENERIC.MP minimally
expensive on single CPU machines as well.

this is the last piece needed to get GENERIC/GENERIC.MP to boot on the
USIII* machines.

idea and some initial code from openbsd.


# 1.313 13-Feb-2010 mrg

remove KTR support. it's never been a working part of netbsd src tree.


# 1.312 09-Feb-2010 wiz

Fix typo in comment.


Revision tags: uebayasi-xip-base
# 1.311 06-Feb-2010 mrg

branches: 1.311.2;
- properly map the schizo interrupt registers, so we can use the normal
virtual mappings to access them.
- with the above fxied, kill SCHIZO_BUS_SPACE_BROKEN, and introduce
an options CHEETAH for now, that disables the SPITFIRE code in locore.
- merge schizo_init() into schizo_attach() and clean up the softc a bit.


with this we are only one more step away from GENERIC booting on USIII
machines.


# 1.310 02-Feb-2010 mrg

- split sp_tlb_flush_pte() and switchtoctx() into sp_tlb_flush_pte_us()/
sp_tlb_flush_pte_usiii() and switchtoctx_us()/switchtoctx_usiii() and
implement the latter while i'm here. it works ... sometimes i think,
but also sometimes panics/hangs.
- fix a comment in sparc64_ipi_flush_pte_usiii()


# 1.309 02-Feb-2010 mrg

for now, reduce a few #ifdef SPITFIRE cases by introducing a new
ASI_DCACHE_TAG_OR_INV that is either ASI_DCACHE_{TAG,_INVALIDATE}.

increase the common code in cache_flush_phys().


# 1.308 01-Feb-2010 mrg

- sp_tlb_flush_all() becomes sp_tlb_flush_all_us() and sp_tlb_flush_all_usiii()
- sparc64_ipi_flush_pte() becomes sparc64_ipi_flush_pte_us() and
sparc64_ipi_flush_pte_usiii()
- add some commented out code to disable interrupts and raise the traplevel
in sparc64_ipi_flush_pte_usiii()
- cache_flush_phys() was missing a little of code in the cheetah case


# 1.307 01-Feb-2010 mrg

for USIII, use the new "tlb demap all" operation in sp_tlb_flush_all()


# 1.306 01-Feb-2010 mrg

remove unused icache_flush_page() implementation.


# 1.305 23-Jan-2010 mrg

remove the final uses of DATA_START.

now we can remove the 16KB space reserved at the start of the data segment,
and i now understand why i wrote this now removed comment 3.5 years ago:
"this shouldn't be needed... but kernel usually hangs without it"


# 1.304 23-Jan-2010 mrg

remove most of the code that writes debugging info DATA_START + offset.


# 1.303 23-Jan-2010 mrg

remove CHKPT() macro and uses. it's likely wrong in SMP land and probably should
be replaced with KTR-style uses if necessary.


# 1.302 23-Jan-2010 mrg

fix a comment.


Revision tags: matt-premerge-20091211
# 1.301 10-Dec-2009 rmind

Rename L_ADDR to L_PCB and amend some comments accordingly.


# 1.300 05-Dec-2009 mrg

- adjust the PA mask to the 43 bits supported by USIII.
- rework the spitfire/cheetah cache_flush_phys() to avoid several #ifdefs
- add a membar #Sync after sparc64_ipi_drop_fpstate (probably unnecessary)


# 1.299 30-Nov-2009 nakayama

sp_tlb_flush_pte for cheetah:
- restore interrupts properly in case of %tl > 0.


# 1.298 30-Nov-2009 mrg

stablize UP USIII support by blocking interrupts around sp_tlb_flush_pte()
i was seeing stack corruption while taking an interrupt in this function.

get USIII SMP mostly working by implementing the cheetah version of
sparc64_ipi_flush_pte().


SMP support is still not entirely stable. i can reproducably get a:

panic: fpusave_lwp ipi didn't

while running build.sh, when an awk process is exiting. other simple
heavy work loads do not crash for me right now.


# 1.297 30-Nov-2009 mrg

delete some no longer used code:
- smp_tlb_flush_ctx()
- smp_tlb_flush_all()
- sparc64_ipi_flush_ctx()
- sparc64_ipi_flush_all()
- sp_tlb_flush_ctx()


# 1.296 29-Nov-2009 nakayama

- calculate end PA correctly.
- wrap more spitfire specific (flushing I$) code.
- fix inverted #if condition for flushing I$ (and restore ASI_ICACHE_TAG).


# 1.295 28-Nov-2009 mrg

implement enough code to get SB2000/SB2500 booting to multiuser. does
not last long if you use it, but an idle machine has stayed up 10 hours.

- for the !SPITFIRE case, use ASI_DCACHE_INVALIDATE instead of
ASI_DCACHE_TAG when clearing tlb entries. from openbsd.

- convert some comment "! Not yet" into "WRITEME", so that attempting
to build a USIII MULTIPROCESSOR kernel fails to build until the code
is written.

- add some more WRITEME's for the above.

- implement a !SPITFIRE version of sp_tlb_flush_all(). since there are
no spare regs, for now just always increase %tl around this call. (we
could maybe store a token in %o3 along with the saved %pstate info.)


# 1.294 26-Nov-2009 matt

Kill proc0paddr. Use lwp0.l_addr instead.


# 1.293 25-Nov-2009 mrg

s/L_ADDR/L_PCB/, requested by rmind.


# 1.292 17-Oct-2009 nakayama

Wrap unused code with #if 0 which is called from #if 0'ed code.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5
# 1.291 30-May-2009 martin

cpu_setfunc() can not use lwp_trampoline, as that has additional lwp startup
semantics. Use a simpler setfunc_trampoline instead.


# 1.290 18-May-2009 nakayama

Remove random() from locore.s since it is in libkern.


# 1.289 16-May-2009 nakayama

Remove clear %tick in locore.s since it is cleared at cpu_initclocks() in
clock.c.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 nick-hppapmap-base mjf-devfs2-base
# 1.288 15-Dec-2008 mrg

restore some old "intrdebug" code, but leave it under NOT_DEBUG. most
of it works, but one that prints func/arg for each handler is not very
stable...

for now, while schizo bus space pointer accesses aren't working, add
a SCHIZO_BUS_SPACE_BROKEN option so you can build a kernel with schizo.

with this, and the prior schizo interrupt fix, you can now fail to run
/sbin/init!


Revision tags: haad-dm-base2 haad-nbase2 haad-dm-base
# 1.287 09-Dec-2008 martin

Get rid of get_maxctx() - it doesn't work on newer cpus and we will have
to find a better way for (some) sun4v machines - all sun4u use 13 bit
contexts anyway.


Revision tags: netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 ad-audiomp2-base netbsd-5-base
# 1.286 30-Oct-2008 nakayama

branches: 1.286.2; 1.286.6;
Wrap more code specific to USE_BLOCK_STORE_LOAD.


Revision tags: matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4
# 1.285 05-Oct-2008 nakayama

branches: 1.285.2;
- in flushing cache, use 32 as increment/decrement value to match the
cache line size.
- remove useless restore of %asi.
- remove nop in delay slot if we can.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 1.284 10-Jul-2008 nakayama

Use proper CCR.


# 1.283 10-Jul-2008 nakayama

sparc64_ipi_save_fpstate:
- use primary MMU context for consistency with other trap/interrupt handlers.

sparc64_ipi_save_fpstate, savefpstate:
- avoid storing fp registers as we can.

sparc64_ipi_save_fpstate, savefpstate, loadfpstate:
- remove unaligned case since buffers allocated with pool_cache are ensured
64-byte aligned.

Ok by martin@.


# 1.282 02-Jul-2008 nakayama

branches: 1.282.2;
UltraSPARCs don't have floating point queue, and reading %fq regsiter
will cause illegal instruction trap. So remove the code handling them.


# 1.281 29-Jun-2008 nakayama

Wrap IPI calls with #ifdef MULTIPROCESSOR.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.280 14-Jun-2008 nakayama

Close unterminated comment.
Fix unexpected behavior in case of loadfpstate from unaligned buffer.


Revision tags: yamt-pf42-base3
# 1.279 31-May-2008 nakayama

branches: 1.279.2;
openfirmware_exit:
- disable interrupts with %pstate.
- prepare 64-bit stack and enable 64-bit addresses for 32-bit SMP kernels.


Revision tags: hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 yamt-nfs-mp-base yamt-pf42-base
# 1.278 16-Apr-2008 nakayama

branches: 1.278.2; 1.278.4; 1.278.6;
Disable TRAPSTATS which was accidentally enabled when yamt-idlelwp branch
was merged.

Ok by martin@.


# 1.277 14-Apr-2008 nakayama

Remove sparc64_ipi_sync_tick.

Since we can use counter-timer as timecounter instead of %tick on SMP kernel,
it is not necessary to sync all CPUs %tick registers.


# 1.276 14-Apr-2008 nakayama

Add workaround for BB_ERRATA_1 on writing to TICK_CMPR register in
next_tick(). If writing to TICK_CMPR fails, we lose hardclock interrupt
on secondary CPUs.

About BB_ERRATA_1 from comment in OpenSolaris:

/*
* Writes to the TICK_COMPARE register sometimes fail on blackbird modules.
* The failure occurs only when the following instruction decodes to wr or
* wrpr. The workaround is to immediately follow writes to TICK_COMPARE
* with a read, thus stalling the pipe and keeping following instructions
* from causing data corruption. Aligning to a quadword will ensure these
* two instructions are not split due to i$ misses.
*/


# 1.275 28-Mar-2008 nakayama

Don't read fplwp content in delay slot for considering the case fplwp was
modifiled.

Reported by Chris Ross on port-sparc64.


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.274 20-Mar-2008 nakayama

- remove disabling interrupt in IPI.
- unused VA bits in MMU demap is 13 bits, not 12 bits.


# 1.273 18-Mar-2008 nakayama

Fix a race when increment an interrupt level event counter.


# 1.272 17-Mar-2008 nakayama

Fix a race condition in IPI handlers of save/drop fpstate, from OpenBSD.
Reported and tested by martin@.


# 1.271 17-Mar-2008 nakayama

Make schedintr interrupt handler per-CPU.
While there rename tickintr interrupt handler and share initialization
code with schedintr.


# 1.270 14-Mar-2008 nakayama

Improve IPI handling:
- make IPI takes two arguments.
- add IPI event counters per-CPU.
- implement IPI functions which were missing or broken.
- insert DELAY while halting primary CPU in IPI handler.


# 1.269 02-Mar-2008 nakayama

- make interrupt pending list per-CPU.
- make tickintr() MP-safe.
- remove unused port-sparc derived interrupt code.

Ok by martin@.


# 1.268 02-Mar-2008 nakayama

Don't get IPI handler argument (from bogus address), and ack IRQ twice.


# 1.267 28-Feb-2008 martin

Make TSBs and MMU contexts per-cpu.


Revision tags: nick-net80211-sync-base mjf-devfs-base hpcarm-cleanup-base
# 1.266 26-Jan-2008 nakayama

branches: 1.266.2; 1.266.6;
Fix for 32-bit kernels.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.265 15-Jan-2008 skrll

Store a sensbile PCB_PC value in snapshot - the return point.

This helps gdb somewhat.

OK'd by martin.


# 1.264 14-Jan-2008 martin

Fix register name typo/copy&pasto - %g6 is not %o6/%sp.
From OpenBSD.


Revision tags: matt-armv6-base
# 1.263 06-Jan-2008 martin

Load the next cpu_info pointer with LDPTR instead of ld.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2
# 1.262 09-Dec-2007 martin

branches: 1.262.2;
Provide cpu_intr_p(), at least for non-MULTIPROCESSOR kernels.
Based on suggestions by Andrew Doran.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.261 22-Oct-2007 martin

branches: 1.261.2; 1.261.4; 1.261.6;
Remove an unused .globl declaration


Revision tags: yamt-x86pmap-base4
# 1.260 17-Oct-2007 garbled

Merge the ppcoea-renovation branch to HEAD.

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

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

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base ppcoea-renovation-base vmlocking-base
# 1.259 09-Sep-2007 martin

branches: 1.259.4;
Make cpufrequency and friends per cpu values.
Prepare a hz tick interrupt on secondary CPUs via %tick, but do not
enable it yet, as it breaks ddb.


# 1.258 09-Sep-2007 martin

Do not ACK IPIs before we finished loading all arguments.


# 1.257 06-Sep-2007 martin

Remove the (now unused) second 64k page mapped per CPU.
From matthew green, with small changes by me. All bugs are mine.


# 1.256 25-Aug-2007 martin

branches: 1.256.2;
Remove INITSTACK completely - at the time we used to switch to it, we
already have access to all of lwp0 and it's uarea - so we can switch
to the correct lwp0 stack easily before calling main.


# 1.255 25-Aug-2007 martin

When exiting to OF, use the interrupt stack instead of INITSTACK


# 1.254 25-Aug-2007 martin

Rework cpu_mp_startup slightly:
- temporarily use the cpu's interrupt stack untill we are ready
to access non-OF-based mappings, then directly switch to the cpu's
idlelwp's uarea stack
- disable interrupts untill we are ready to call C code


# 1.253 13-Aug-2007 macallan

remove two restore without matching save


Revision tags: nick-csl-alignment-base matt-mips64-base mjf-ufs-trans-base
# 1.252 06-Jul-2007 martin

branches: 1.252.4; 1.252.8;
A few nits for 32bit SMP kernels, noticed by mrg.
While there, simplify the fpstate IPIs a bit.


# 1.251 05-Jul-2007 martin

sparc64_ipi_save_fpstate is not a leaf function - create a full grown
stack frame.


# 1.250 28-May-2007 mrg

clean up cpu_switchto() a little - no need to flushw or membar
excessively. optimise an rdpr. tested by tnn.


# 1.249 23-May-2007 martin

Fix a stupid bug in the save_fpstate ipi, which caused overwriting of
struct lwp of the lwp owning the fpu. Fix clearing the fplwp - %o0 will
not survive the call to savefpstate - duh!


# 1.248 20-May-2007 martin

Simplify tf_tstate setting when leaving for userland initially - I seem
to have confused the if with the else case of the previous C code.
Funny that it worked at all.


# 1.247 20-May-2007 martin

cpu_switchto() has to return it's first arg, always. This differs from
my reading of the documentation, but helps in the real world and seems
to be what other ports do.


# 1.246 20-May-2007 martin

Remove special case handling for userland lwps from cpu_lwp_fork, instead
do it in lwp_trampoline when we first return to userland.


# 1.245 19-May-2007 martin

cpu_idle is a leaf function, so we better "return from leaf".
Use return value from cpu_switchto for previous lwp in lwp_trampoline.
Also shamelessly steal a comment from uwe written for sparc that explains
all this.
Thanks to tnn, mrg, and uwe for helping to debug this.


# 1.244 17-May-2007 yamt

merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base ad-audiomp-base
# 1.243 22-Feb-2007 martin

branches: 1.243.4; 1.243.6; 1.243.12;
uvm.page_idle_zero now is a bool, not a 32bit value any more.


# 1.242 21-Feb-2007 mrg

shave 9 insns off the tsb setup in cpu_initialize & cpu_mp_startup.


# 1.241 21-Feb-2007 martin

Get rid of unused (thus always zero) "curlwp" variable hidden in assembler
code (C code always uses a cpuinfo based macro).


# 1.240 18-Feb-2007 martin

Make use of another call delay slot, pointed out by uwe.


# 1.239 18-Feb-2007 martin

Make use of a call delay slot and avoid a bogus EMPTY.
Spotted by Juergen Hannken-Illjes, with input from Andrew Doran and
Valeriy E. Ushakov.


# 1.238 18-Feb-2007 martin

Whitespace cosmetics


# 1.237 18-Feb-2007 martin

Backout previous: EMPTY was misused


# 1.236 18-Feb-2007 martin

Make EMPTY expand to nop with gas, as it is used to mark empty branch
delay slots.


# 1.235 15-Feb-2007 martin

branches: 1.235.2;
Fix obvious copy&pasto in SCHED_DEBUG register usage.


Revision tags: post-newlock2-merge
# 1.234 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.233 25-Dec-2006 wiz

Spell "relevant" correctly. From Zafer Aydogan.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.232 25-Oct-2006 mrg

branches: 1.232.2; 1.232.4;
- note that __idle_u should go away but doing so breaks things
- fix several comments to reality
- clean up the #ifdef NO_VCACHE code slightly
- use call instead of set/jmpl
- remove a couple of unnecessary stores to curlwp


Revision tags: yamt-splraiseipl-base2
# 1.231 18-Oct-2006 rjs

Clean up some comments. Cosmetic change to use correct structure
offset names.

Optimize out two instructions from sparc64_ipi_save_fpstate and
sparc64_ipi_drop_fpstate.


# 1.230 17-Oct-2006 mrg

allocate 128KB (as opposed to 64KB) per-cpu, and place the interrupt
stack, cpu_info structure, panicstack, idle uarea and normal kernel
stack in here. the idle uarea and kernel stack are in the 2nd 64KB
page. the interrupt stack and cpu_info structure are as the same
place in the 1st 64KB page, and the panicstack grows down from the
top of this page. update comments in param.h to suit (XXX: a lot
of these constants should move to a header file that will not pollute
the name space so much.) map these pages identically between
cpu_initialise() and cpu_mp_startup(), and deal with the two 64KB
pages in pmap_extract(). keep an unmapped 64KB page between them.

don't initialise the unused "ci_eintstack" member of the cpu_info
structure

use constants to initialise many addresses in the cpu_info structure,
consolidating these assignments from cpu0 and cpu>0

delete u0/estack0/panicstack from locore.s

clean up some wrong comments in locore.s

fix a 32bit-only bug in cpu_mp_startup().

delete 'u0' entirely.


this fixes recent random lossage seen on port-sparc64: processes
stuck in RUN state, data faults, and hangs.


# 1.229 04-Oct-2006 mrg

use call instead of set/jmpl. add an entry point for idle that expects
sched_lock to be unlocked, and use this for non-boot cpu's. complete a
comment describing how registers in idle_switch are expected to be set.


# 1.228 03-Oct-2006 mrg

use the same SAVE_LOCALS_INS definition for 32 bit and 64 bit kernels.
refactor TRAP_SETUP() a little between these two versions to be more alike.


# 1.227 03-Oct-2006 mrg

use the correct size/type for MP variables (pointers and longs).

a 32 bit MULTIPROCESSOR kernel now builds (and crashes quickly.)


# 1.226 03-Oct-2006 mrg

in the 64bit version of SAVE_LOCAL_INS, s/BIAS/STKB/ to allow future
sharing of the 32 and 64 bit versions of the {TRAP,INTR}_SETUP macros.


# 1.225 19-Sep-2006 mrg

- remove some way old FP setup/teardown code
- put the block memcpy/memset inside #ifdef USE_BLOCK_STORE_LOAD which
is (now) defined.

no functional change, same .o is generated.


# 1.224 19-Sep-2006 mrg

re-order the changes in rev 1.217 to give registers a little bit of
time to settle between usage, like it was before hand.


# 1.223 19-Sep-2006 mrg

- remove a wrong comment.
- add a new entry point for idle called idle_switch that is called by
cpu_switch() in the MP case when sched_whichqs is zero, properly
setting up the idle stack. from petrov@ via martin@.


# 1.222 19-Sep-2006 mrg

rework interrupt_vector() slightly:
- for the IPI case, avoid loading the address of intrlev into %g3
- remove some NOT_DEBUG code
- load the interrupt argument #2 in the delay slot

this removes 2 nops during interrupt processing for the normal
case, and an additional 2 ALU instructions for IPIs


# 1.221 18-Sep-2006 mrg

- sparc64_ipi_halt(): we shouldn't return from sparc64_ipi_halt_thiscpu()
so replace a branch with a 'sir'
- in #if 0 code, in sparc64_ipi_flush_pte() and sparc64_ipi_flush_ctx()
save/restore the out registers that the sp_tlb_flush_xxx() versions
around calling them
- in sp_tlb_flush_pte() and sp_tlb_flush_ctx(), replace global register
usage with out registers so that we don't clobber the (alternate)
global registers when these are called from IPI context


# 1.220 18-Sep-2006 mrg

- remove an extra 'sir' that followed one in a macro
- add some named labels to some spill/fill handlers
- remove 2 unused strings


Revision tags: yamt-splraiseipl-base
# 1.219 18-Sep-2006 martin

branches: 1.219.2;
Lazy FPU handling for the MULTIPROCESSOR case


# 1.218 16-Sep-2006 nakayama

From OpenBSD:
- reload %fprs for checking it again.
- use symbolic names for checking in %fprs.

revision 1.51
date: 2005/07/18 14:50:11; author: deraadt; state: Exp; lines: +2 -1
cache a copy of the fprs so we know what fp restore we should do after

revision 1.50
date: 2005/07/14 01:46:13; author: deraadt; state: Exp; lines: +4 -4
use symbolic names for checking in %fprs, as above


# 1.217 16-Sep-2006 nakayama

Fix a couple of %y register save/restore errors, inspired from OpenBSD.

revision 1.44
date: 2004/04/23 04:18:17; author: marc; state: Exp; lines: +5 -4

fix a couple of %y register save/restore errors
1) don't save %y in a register that is later used before restoring %y
2) always restore %y after calling a signal handler
tested by drahn@, OK pval


# 1.216 15-Sep-2006 martin

Do not bother to save fpu state when we are about to get rid of it.


Revision tags: yamt-pdpolicy-base9
# 1.215 13-Sep-2006 mrg

SMP cleanup. provide support for multiple CPUs in DDB. (SMP itself
is still not working.)

cpu.h:
- add a pointer for DDB regs in SMP environment to struct cpu_info
- remove the #defines for mp_pause_cpus() and mp_resume_cpus()
cpuset.h:
- remove CPUSET_ALL() and rename CPUSET_ALL_BUT() to CPUSET_EXCEPT()
from petrov.
db_machdep.h:
- rename the members of db_regs_t to be the same as sparc
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- redo DDB_REGS to no longer be a pointer to a fixed data structure
but to one allocated per-cpu when ddb is entered
- move a bunch of prototypes in here
intr.h:
- remove SPARC64_IPI_* macros, no longer used
db_interface.c:
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- make "nil" a 64 bit entity
- change the ddb register access methods to work in multiprocessor
environment, it is now very much like sparc does it
- in kdb_trap() avoid accessing ddb_regp when it is NULL
- update several messages to include the cpu number
- unpause other cpus much later when resuming from ddb
- rename db_lock() to db_lock_cmd(), as the sparc-like code has
db_lock as a simple lock
- remove "mach cpus" command, and replace it with "mach cpu" (which
does the same) and also implement "mach cpu N" to switch to
another cpus saved trapframe
db_trace.c:
- update for the ddb_regs -> ddb_regp change
genassym.cf:
- add TF_KSTACK as offsetof(struct trapframe64, tf_kstack)
ipifuncs.c:
- overhaul extensively
- remove all normal interrupt handlers as IPI's, we now handle
them all specially in locore.s:interrupt_vector
- add a simplelock around all ipi functions - it's not safe for
multiple cpus to be sending IPI's to each other right now
- rename sparc64_ipi_pause() to sparc64_ipi_pause_thiscpu() and,
if DDB is configured, enable it to save the passed-in trapframe
to a db_regs_t for this cpu's saved DDB registers.
- remove the "ipimask" system (SPARC64_IPI_* macros) and instead
pass functions directly
- in sparc64_send_ipi() always set the interrupt arguments to 0,
the address and argument of the to be called function. (the
argument right now is the address of ipi_tlb_args variable, and
part of the reason why only one CPU can send IPI's at a time.)
don't wait forever for an IPI to complete. some of this is
from petrov.
- rename sparc64_ipi_{halt,pause,resume}_cpus() to
mp_{halt,pause,resume}_cpus()
- new function mp_cpu_is_paused() used to avoid access missing
saved DDB registers
- actually broadcast the flush in smp_tlb_flush_pte(),
smp_tlb_flush_ctx() and smp_tlb_flush_all(). the other end may
not do anything yet in the pte/ctx cases yet...
kgdb_machdep.c:
- rework for changed member names in db_regs_t.
locore.s:
- shave an instruction from syscall_setup() (set + ld -> sethi + ld)
- remove some old dead debug code
- add new sparc64_ipi_halt IPI entry point, it just calls the C
vector to shutdown.
- add new sparc64_ipi_pause IPI entry point, which just traps into
the debugger using the normal breakpoint trap. these cpus usually
lose the race in db_interface.c:db_suspend_others() and end up
calling the C vector sparc64_ipi_pause_thiscpu().
- add #if 0'ed code to sparc64_ipi_flush_{pte,ctx}() IPI entry
points to call the sp_ version of these functions.
- in rft_kernel (return from trap, kernel), check to see if the
%tpc is at the sparc64_ipi_pause_trap_point and if so, call
"done" not "retry"
- rework cpu_switch slightly: save the passed-in lwp instead of
using the one in curlwp
- in cpu_loadproc(), save the new lwp not the old lwp, to curlwp
- in cpu_initialize(), set %tl to zero as well. from petrov.
- in cpu_exit(), fix a load register confusion. from petrov.
- change some "set" in delay branch to "mov".
machdep.c:
- deal with function renames
pmap.c:
- remove a spurious space
trap.c:
- remove unused "trapstats" variable
- add cpu number to a couple of messages


# 1.214 09-Sep-2006 mrg

significant clean up effort, largely from petrov@ via martin@.

- fix a bunch of comments for proc->lwp
- remove old TRAPTRACE, NOT_DEBUG, etc. code that has bit-rotted
- put some older DEBUG code under NOT_DEBUG
- add a bunch of new debugging/tracing code ("KTR") that depends on
other changes not yet present.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base yamt-pdpolicy-base5 chap-midi-base simonb-timecounters-base rpaulo-netinet-merge-pcb-base
# 1.213 14-May-2006 elad

branches: 1.213.6; 1.213.8;
integrate kauth.


# 1.212 12-May-2006 skrll

Fix some comments.


Revision tags: elad-kernelauth-base
# 1.211 09-May-2006 rjs

Load CPCB in cpu_mp_startup.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.210 11-Feb-2006 cdi

branches: 1.210.2; 1.210.4; 1.210.6;
ANSIfication: u_intN_t -> uintN_t, use ANSI function declarations/definitions
instead of K&R ones.


# 1.209 27-Jan-2006 cdi

branches: 1.209.2; 1.209.4;
Alter sparc64 bootstrap, catch up to ofwboot v1.9:

- Accept bootinfo structure passed down from ofwboot v1.9
- Drop kernel re-mapping code
- Use permanent 4MB mappings provided by the loader instead
- Change kernel entry address to point directly at the code instead of pointing
at the trap table's first slot. This allows the bootloader to detect
those kernels which are aware of the new boot scheme
- Due to the changes in kernel mapping code, alter secondary CPU bootstrap
code to use trampoline just like FreeBSD does (some FreeBSD code is used
here as well)


# 1.208 12-Jan-2006 cdi

Fix a typo: %g0 should be used instead of %o0 when initializing FPU in dostart:
and cpu_mp_startup:, %o0 is not even initialized at this point.


# 1.207 11-Dec-2005 christos

branches: 1.207.2;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 1.206 10-Jul-2005 christos

Re-factor syscall, and make it use syscall_{plain,fancy}.


# 1.205 31-May-2005 chs

branches: 1.205.2;
remove vestigal {,e}intr{names,cnt} symbols now that vmstat doesn't need them.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.204 12-Feb-2005 chs

branches: 1.204.4; 1.204.6; 1.204.8;
in sparc_interrupt(), wait to enable interrupts until just before calling
the handler and disable them again right after the handler returns.
we don't want another hardware interrupt coming in while we're mucking
with the list pointers. also, clear the intrhand's ih_pending pointer
before calling the handler rather than after, so that if another interrupt
comes in while the handler is running, we can put the intrhand back on
the list so it will be called again.

in send_softint(), disable interrupts via %pstate instead of %pil, so that
hardware interrupts at higher levels are blocked while we manipulate the
intrpending list. also, if the intrhand already has ih_pending set,
don't bother poking the SET_SOFTINT register again, since being on the list
implies that there is already a softint pending in the hardware.

these appear to fix PR 21750 (the "sleep forever" problem).

while I'm here, remove more vestiges of the !INTRLIST softint stuff
(code and comments). and in sparc64_ipi_flush_all(), interrupts are
already disabled so we don't need to fiddle with %pstate.


Revision tags: yamt-km-base2
# 1.203 30-Jan-2005 martin

Remove the no long usefull variants selected by undefining INTRLIST and
INTR_INTERLOCK to improve readability. Same object code generated as before.


Revision tags: yamt-km-base
# 1.202 16-Jan-2005 chs

branches: 1.202.2;
use ENTRY_NOPROFILE() for various entry points,
stack traces work better that way.


Revision tags: kent-audio1-beforemerge kent-audio1-base
# 1.201 03-Dec-2004 chs

branches: 1.201.4;
remove cache_flush_virt() and PADDRT, they're no longer used.
allocate a stack frame for blast_dcache() when profiling so it shows up.
in dcache_flush_page(), use a stride of 32 instead of 16 to match the
cache line size. correct various comments.


# 1.200 08-Nov-2004 petrov

Don't compile sparc64_ipi functions when UP.


# 1.199 25-Oct-2004 martin

No need to clear %o1 when returning a 64 bit integer from pseg_get if we
are compiling for a 64 bit kernel.


# 1.198 24-Jul-2004 nakayama

Change interrupt pending list end value to -1, to avoid linking an
interrupt handler twice.

It may fix "sleep forever" bug.


# 1.197 09-Apr-2004 petrov

Clean-up unused defines and variables.


Revision tags: netbsd-2-0-base
# 1.196 26-Mar-2004 petrov

branches: 1.196.2;
Use want_resched from cpu_info area.


# 1.195 23-Mar-2004 martin

Replace intrcnts by evcnts. XXX - needs slight tweaking for MULTIPROCESSOR.


# 1.194 14-Mar-2004 chs

checkpoint of MP work from dennis and myself. includes cross-processor
interrupt framework, a sledgehammer TLB invalidation and misc MP fixes.
doesn't work at all yet.


# 1.193 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.192 19-Jan-2004 martin

Rename switchexit to cpu_exit and g/c the old C implementation of cpu_exit.


# 1.191 18-Jan-2004 martin

Support RAS for 32bit kernels too.


# 1.190 16-Jan-2004 martin

In proc_trampoline don't bother to clear condition codes in the trap
frame, since we no longer rely on this.
While there fix a few comments.


# 1.189 08-Jan-2004 martin

Minor cleanup


# 1.188 06-Jan-2004 martin

Implement restartable atomic sequences (RAS) for sparc64.


# 1.187 06-Jan-2004 petrov

Spinup secondary cpus. Based on codes sent to me by Dennis Chernoivanov
and Chuck Silvers.


# 1.186 04-Jan-2004 jdolecek

update to recent changes - exit2() doesn't exist anymore and the
exit path always calls lwp_exit2()
pointed out Martin Husemann


# 1.185 02-Dec-2003 martin

Minor cleanup: remove unused code, sync a comment with current reality.


# 1.184 25-Nov-2003 cdi

Use per-cpu pcb, curlwp and fplwp rather than global ones. This brings
GENERIC.MP configuration to a usable state.

Approved by petrov@.


# 1.183 24-Nov-2003 cdi

Call 'proc_trampoline_mp' from 'proc_trampoline' in a multiprocessor
configuration. Fix process locking. Approved by petrov@.


# 1.182 20-Nov-2003 petrov

Remove nwindows calculation, it's not used. Set l_cpu in cpu_switch.


# 1.181 09-Nov-2003 martin

Get rid of bcopy/bzero.


# 1.180 26-Oct-2003 christos

Initial siginfo support for sparc64 (untested). COMPAT_16 sigcontext signal
delivery tested.


# 1.179 24-Aug-2003 chs

add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default. the changes
fall into two basic catagories:

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

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

originally from openbsd, adapted for netbsd by me.


# 1.178 08-Jul-2003 cdi

traceit: don't use %g7 as it is to become curcpu() register. Add comments.


# 1.177 18-May-2003 martin

branches: 1.177.2;
Make kernels with options KGDB at least compile.
Still needs some work to make it working.


# 1.176 29-Apr-2003 nakayama

Use BLOCK_ALIGN rather than BLOCK_SIZE for aligning a pointer.


# 1.175 27-Apr-2003 ragge

Preserve the symbol table in the LKM || KSYMS cases also.


# 1.174 04-Apr-2003 petrov

use branch slot in pmap_copy_page.


# 1.173 24-Mar-2003 nakayama

Divide `set' instruction in delay slot (from OpenBSD change to rev 1.30).


# 1.172 10-Feb-2003 martin

Remove some #if 0 code and a few XXX marked membars w/o proper
justification for their existence.


# 1.171 09-Feb-2003 martin

Remove left over pieces from reusing the signal trampoline for upcalls.
This should fix signal delivery for 32bit kernels.


# 1.170 05-Feb-2003 nakayama

Switch to use cycle counter (%tick) based microtime().

This is derived from alpha/microtime.c and i386/tsc_microtime.c,
and will share with both ports.

This should fix PR port-sparc64/18452.
(approved by martin)


# 1.169 04-Feb-2003 martin

Fix return value of pseg_set, which I accidently broke in rev. 1.164.

Fix register names in comment and shave off another register (hint
from uwe).


# 1.168 01-Feb-2003 martin

Rearrange register usage in pseg_set a bit and shave off %g4.


# 1.167 01-Feb-2003 martin

Remove a few #ifdef _LP64 by using STPTR/LDPTR macros.
Thanks to Matthew Green for the pointer.


# 1.166 31-Jan-2003 martin

Apply leaf procedure optimization to pseg_set (again).


# 1.165 31-Jan-2003 martin

Make the pmap count resident/wired mappings on the fly instead of
walking the page tables whenever this information is needed.

Add an option PMAP_COUNT_DEBUG to assert the new counts and the
page table walk agree.

The old solution had very bad performance impact, for example
by the high CPU load when running top(1).

Thanks to Simon Burge for pointing at the cause of the problem and
to Valeriy E. Ushakov for optimizing my simple minded assembler code.


# 1.164 27-Jan-2003 martin

Remove unused function pseg_find (which looked quite similar to
pseg_get anyway).


# 1.163 18-Jan-2003 thorpej

Merge the nathanw_sa branch.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.162 16-Jan-2003 petrov

Move dump_dtlb back under DDB.


# 1.161 15-Jan-2003 chs

fix two bugs in my last pmap rework:
- in tlb_flush_all(), don't skip TLB entries with the high bit on,
I was confused about which MMU register it was using. it's also fine
to use the last hardware context.
- in pmap_create(), don't allocate a hardware context for the new pmap.
it's unnecessary, and when this would cause us to recycle all the contexts,
it would result in the current process's context being set to 0
(ie. the kernel's context). the current process could then return to
userspace without going through the context-switch code (and thus without
having a hardware context reallocated). this would lead to user mappings
being entered in the kernel's context later, causing all sorts of trouble.
add some assertions to catch this kind of thing.


Revision tags: fvdl_fs64_base
# 1.160 25-Dec-2002 petrov

new function dump_itlb.


Revision tags: gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.159 22-Sep-2002 chs

many improvements:
- use struct vm_page_md for attaching pv entries to struct vm_page
- change pseg_set()'s return value to indicate whether the spare page
was used as an L2 or L3 PTP.
- use a pool for pv entries instead of malloc().
- put PTPs on a list attached to the pmap so we can free them
more efficiently (by just walking the list) in pmap_destroy().
- use the new pmap_remove_all() interface to avoid flushing the cache and TLB
for each pmap_remove() that's done as we are tearing down an address space.
- in pmap_enter(), handle replacing an existing mapping more efficiently
than just calling pmap_remove() on it. also, skip flushing the
TSB and TLB if there was no previous mapping, since there can't be
anything we need to flush. also, preload the TSB if we're pre-setting
the mod/ref bits.
- allocate hardware contexts like the MIPS pmap:
allocate them all sequentially without reuse, then once we run out
just invalidate all user TLB entries and flush the entire L1 dcache.
- fix pmap_extract() for the case where the va is not page-aligned and
nothing is mapped there.
- fix calculation of TSB size. it was comparing physmem (which is
in units of pages) to constants that only make sense if they are
in units of bytes.
- avoid sleeping in pmap_enter(), instead let the caller do it.
- use pmap_kenter_pa() instead of pmap_enter() where appropriate.
- remove code to handle impossible cases in various functions.
- tweak asm code to pipeline a little better.
- remove many unnecessary spls and membars.
- lots of code cleanup.
- no doubt other stuff that I've forgotten.

the result of all this is that a fork+exit microbenchmark is 34% faster
and a fork+exec+exit microbenchmark is 28% faster.


Revision tags: gehenna-devsw-base
# 1.158 18-Jul-2002 wiz

Spell 'should' correctly.


# 1.157 07-Jun-2002 eeh

Shave 10% off the time needed to flush the D$ through a bit of instruction
reordering.


# 1.156 05-Jun-2002 eeh

Handle improperly aligned stack pointers more cleanly.


# 1.155 04-Jun-2002 eeh

Fix the fork trampoline to properly use the supplied tstate.


# 1.154 31-May-2002 thorpej

Make this work with an ISO C preprocessor.


Revision tags: netbsd-1-6-base
# 1.153 14-May-2002 eeh

branches: 1.153.2; 1.153.4;
Only save locals and ins in trapframes for DEBUG kernels.


# 1.152 04-May-2002 kleink

Add some comments to the CPP conditionals controlling the trap macro
definitions, to ease navigation somewhat.


# 1.151 16-Apr-2002 eeh

Make lots of routines profile-friendly and get rid of some cruft.


Revision tags: eeh-devprop-base
# 1.150 21-Mar-2002 petrov

Not needed debug stuff deleted.


# 1.149 16-Mar-2002 mrg

tell newer binutils that our use of %g2 and %g3 is OK here.


# 1.148 15-Mar-2002 eeh

Cleanup MMU initialization to prevent hangs.


Revision tags: newlock-base ifpoll-base
# 1.147 09-Feb-2002 eeh

branches: 1.147.4;
Fix microsecond calculation in microtime.


# 1.146 07-Feb-2002 eeh

Fix register allocation in microtime().


# 1.145 29-Jan-2002 eeh

Shift the UPAID in the correct direction.


# 1.144 17-Jan-2002 eeh

Be more tolerant of unaligned stack pointers.


# 1.143 17-Jan-2002 eeh

Enable block insns in bcopy and bzero.


# 1.142 16-Jan-2002 eeh

In bcopy use 32-bit comparisons in 32-bit kernels.


# 1.141 16-Jan-2002 eeh

Use correct calculation for the trapframe in softtrap for ILP32.


# 1.140 20-Nov-2001 lukem

- pull in opt_kgdb.h where necessary
- replace opt_kgdb_machdep.h with opt_kgdb.h
- defparam opt_kgdb.h:
KGDB_DEV KGDB_DEVNAME KGDB_DEVADDR KGDB_DEVRATE KGDB_DEVMODE
- move from opt_ddbparam.h to opt_ddb.h:
DDB_FROMCONSOLE DDB_ONPANIC DDB_HISTORY_SIZE DDB_BREAK_CHAR SYMTAB_SPACE
- replace KGDBDEV with KGDB_DEV
- replace KGDBADDR with KGDB_DEVADDR
- replace KGDBMODE with KGDB_DEVMODE
- replace KGDBRATE with KGDB_DEVRATE
- use `9600' instead of `0x2580' for 9600 baud rate
- use correct quotes for options KGDB_DEVNAME="\"com\""
- use correct quotes for options KGDB_DEV="17*256+0"
- remove unnecessary dependancy on Makefile for kgdb_stub.o
- minor whitespace cleanup


Revision tags: thorpej-mips-cache-base thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf
# 1.139 14-Sep-2001 thorpej

branches: 1.139.4;
Don't declare intrhand[] here -- that's taken care of in intr.c.


Revision tags: thorpej-devvp-base
# 1.138 30-Aug-2001 eeh

branches: 1.138.2;
Preliminary UltraSPARC III suport (not enabled yet).


# 1.137 13-Aug-2001 jdolecek

g/c _remque()/_insque(); use the C version in libkern


# 1.136 09-Aug-2001 eeh

Fix context masking lossage caused by last version.


# 1.135 08-Aug-2001 eeh

Clean up the trap code to handle the changes cause by supporting non-faulting
accesses. Also change the parameter order so trap frames are easy to find.


# 1.134 07-Aug-2001 eeh

Make sure C code always has ASI_PRIMARY_NOFAULT in the %asi register so
the compiler will be happy if it ever starts generating speculative loads.


# 1.133 05-Aug-2001 eeh

Add support for non-faulting loads and optimize MMU miss handling paths.


# 1.132 02-Aug-2001 eeh

Fix bcopy.


# 1.131 02-Aug-2001 eeh

Sync bzero w/libc version.


# 1.130 01-Aug-2001 eeh

Integrate fixes from userland memset.


# 1.129 31-Jul-2001 eeh

Code cleanup and optimization.


# 1.128 23-Jul-2001 eeh

Get rid of some debug code that really isn't all that useful any more.


# 1.127 19-Jul-2001 eeh

Do ignore unregistered interrupts instead of faulting.


# 1.126 16-Jul-2001 eeh

Make bcopy a 32-bit friendly.


# 1.125 11-Jul-2001 eeh

Fix problems booting 32-bit kernels and dispatching level-15 interrupts.


# 1.124 08-Jul-2001 eeh

branches: 1.124.2;
Code cleanup. Add block_disable to let you turn on block set/copy routines.


# 1.123 05-Jul-2001 eeh

New block bzero and bcopy.


# 1.122 04-Jul-2001 eeh

Replace old bcopy with a much faster version.


# 1.121 01-Jul-2001 martin

Disable axidently enabled debug code to make -current compile again.


# 1.120 30-Jun-2001 eeh

Use a newer version (still disabled) of block bcopy.


# 1.119 30-Jun-2001 eeh

Fixup fpu save restore, get rid of some unused copy functions, and add
a new bcopy.


# 1.118 21-Jun-2001 eeh

Allow multiple 4MB pages for both kernel text and kernel data.

Note: DEBUG checks will not allow accesses to the hole between
text and data segments, so you may need to update programs that
use libkvm before relocating the start of kernel data.


# 1.117 06-Jun-2001 mrg

extract the netbsd32, sunos, 32 bit svr4 and 64 bit svr4 sigcode out into
separate files, so that compat lkms can link with them as well.


# 1.116 30-May-2001 lukem

add missing #include "opt_kgdb.h"


Revision tags: thorpej_scsipi_beforemerge
# 1.115 25-Apr-2001 simonb

Spell occurred correctly.


Revision tags: thorpej_scsipi_nbase thorpej_scsipi_base
# 1.114 09-Apr-2001 eeh

Interrupt latency fix from sparc port. (Hm. One insn instead of 5).


# 1.113 07-Mar-2001 eeh

Fix inverted preprocessor logic. (Spotted by Charles.)


# 1.112 21-Feb-2001 eeh

branches: 1.112.2;
Add support for 64-bit SVR4 (Solaris 8) binaries.


# 1.111 10-Feb-2001 pk

Fix conditional for svr4 compat inclusion.


# 1.110 05-Feb-2001 eeh

Add signal trampoline for 64-bit svr4 emulations.


# 1.109 31-Dec-2000 eeh

Make INCR() atomic.


# 1.108 29-Dec-2000 eeh

pseg_get tells us whether it really needed that spare page after all.


# 1.107 07-Dec-2000 eeh

Fixup calculating where fpstate should be saved in the signal trampoline
code so it doesn't overwrite something important like the registers.


# 1.106 09-Nov-2000 eeh

Fix ILP32 bug in probe_get().


# 1.105 22-Oct-2000 pk

Restore revision 1.102.

I hope it sticks this time..


# 1.104 20-Oct-2000 eeh

Fix hang in 32-bit kernels caused by relocation of KERNBASE.


# 1.103 04-Oct-2000 eeh

Fix interrupt lossage problem and some cosmetic changes.


# 1.102 01-Oct-2000 pk

cpu_initialize: global registers aren't preserved across calls to
prom_printf(), so replace %g3 with %l7 (which isn't used despite
the `usage' comment).

Also, clean up white-space turds.


# 1.101 29-Sep-2000 eeh

This seems to fix the interrupt lossage of non-debug kernels.


# 1.100 28-Sep-2000 eeh

Fix INTR_SETUP() to properly distinguish kernel and user addresses.

Make microtime() return the correct time on %tick machines.

Re-enable debug stuff in dostart for now to detect kernel mapping issues.


# 1.99 25-Sep-2000 pk

Missing `#if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)'


# 1.98 17-Sep-2000 eeh

Make the improved %tick changes work with machines that use the counter-timer
for the clock.


# 1.97 12-Sep-2000 eeh

Fix new version of microtime.


# 1.96 11-Sep-2000 eeh

(Hopefully) fix clock skew on machines that us %tick for the clock (UIIi).


# 1.95 31-Aug-2000 eeh

Use casx instead of stx to change entries in the page table trees.


# 1.94 23-Aug-2000 eeh

Update the scheduler to the new locking scheme.


# 1.93 10-Aug-2000 eeh

Fix signal delivery.


# 1.92 02-Aug-2000 eeh

Get kernel profiling to work. Now if only gprof worked....


# 1.91 01-Aug-2000 eeh

Overhaul cache flush code and coredump code.


# 1.90 25-Jul-2000 pk

Re-instate a couple of delay slot NOPs marked `XXX spitfire bug?'


# 1.89 24-Jul-2000 mycroft

Optimization to pmap_zero_page(): we only need to use the first 16 FP regs,
as in bzero().


# 1.88 24-Jul-2000 mycroft

Fix a whitespace glitch.


# 1.87 24-Jul-2000 mycroft

Pull in the bzero() changes from libc for real, with a couple of kernel-
specific hacks:
* Make the bias handling depend on STKB, so it switches correctly for 32-bit
kernels.
* Use the 32-bit stw/ld for 32-bit kernels.
* Add a few `-STKB's that were missed in the previous change.


# 1.86 24-Jul-2000 pk

Cosmetic & readability:
- local label cleanup in interrupt handling code;
- in debugging sections when testing `intrdebug': use a unique
local label (97) to enhanced clarity;
- comment-out unused code;
- kill a bug as the satisfying result of doing all of the above.


# 1.85 24-Jul-2000 eeh

Fix stack issues in bzero.


# 1.84 24-Jul-2000 mycroft

Revert the previous change for now. I don't have time to debug it tonight.


# 1.83 23-Jul-2000 mycroft

Copy bzero change from libc.


# 1.82 20-Jul-2000 pk

Since `intrcnt' points to an array of long ints, reserve the appropriate
amount of space depending on _LP64. Provide macros to load/store signed
and unsigned long ints.

Also, make the `intrcnt' and `intrpending' arrays 16 entries long, as on
sparc/v9 interrupt #15 is just a regular interrupt.


# 1.81 19-Jul-2000 eeh

Fix merge problem.


# 1.80 19-Jul-2000 eeh

Disable interrupt interlock using ih->ih_pending field. Seems to cause
more problems than it solves.


# 1.79 19-Jul-2000 eeh

Miscellaneous cleanup.


# 1.78 18-Jul-2000 pk

Correct args usage comment in probeget.
Whitespace cleanup.


# 1.77 18-Jul-2000 pk

probeget: 9 -> 0x9


# 1.76 18-Jul-2000 pk

If `ih_pending' is set simply return from the trap, don't schedule another
soft interrupt.


Revision tags: mrg-merge-1-5-top
# 1.75 18-Jul-2000 pk

openfirmware: don't lower %pil


# 1.74 17-Jul-2000 pk

Kill typos in interrupt code.


# 1.73 17-Jul-2000 pk

probeget: do the same song and dance as ld*a() macros in ctlreg.h do.


# 1.72 14-Jul-2000 eeh

Move some macro definitions out of genassym and into locore.s


# 1.71 08-Jul-2000 mrg

backout part of previous: turn off intrdebug, and another debug message


# 1.70 07-Jul-2000 pk

Changes for readability:
- #define LP64 dependent STACKFRAME macro once
- use a LOAD_ASCIZ macro for setting up the format string
for debug messages.


# 1.69 07-Jul-2000 eeh

Temporary fix to prevent the clock from stopping on UIIi machines.


# 1.68 03-Jul-2000 eeh

Prevent interrupts from being posted if they are active and deprecate polled
interrupts. This seems to eliminate the spurious interrupts.


# 1.67 02-Jul-2000 eeh

Clean up interrupt handling some more.


# 1.66 30-Jun-2000 eeh

Fix interrupt delivery on UltraSPARC IIi machines.


# 1.65 24-Jun-2000 eeh

With these changes the kernel seems almost stable again.


# 1.64 24-Jun-2000 eeh

More VM cleanup:

Move the cpu_info structure above the interrupt stack so it won't
get corrupted if the stack overflows.

Flush the D$ before and after all MMU bypass accesses since the
D$ latches all of those.


# 1.63 23-Jun-2000 eeh

Make probeget() and probeset() really work for a change.


Revision tags: netbsd-1-5-base
# 1.62 19-Jun-2000 eeh

branches: 1.62.2;
Have separate data and text segments, make text read-only.


# 1.61 12-Jun-2000 eeh

Start reorganizing the kernel for MULTIPROCESSOR support.


# 1.60 31-May-2000 thorpej

Add a comment about needing to initialize p_cpu when multiple
processors are supported.


Revision tags: minoura-xpg4dl-base
# 1.59 26-May-2000 thorpej

branches: 1.59.2;
First sweep at scheduler state cleanup. Collect MI scheduler
state into global and per-CPU scheduler state:

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

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

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

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

Tested on i386 and Alpha. Changes are mostly mechanical, but apologies
in advance if it doesn't compile on a particular platform.


# 1.58 26-May-2000 thorpej

Don't set `runtime' here; it's done at the end of mi_switch().
cvS: ----------------------------------------------------------------------


# 1.57 26-May-2000 thorpej

Introduce a new process state distinct from SRUN called SONPROC
which indicates that the process is actually running on a
processor. Test against SONPROC as appropriate rather than
combinations of SRUN and curproc. Update all context switch code
to properly set SONPROC when the process becomes the current
process on the CPU.


# 1.56 22-Apr-2000 eeh

If we trap due to a bad kernel stack, try to switch to the interrupt strack
before breaking into the debugger.


# 1.55 18-Apr-2000 eeh

Prevent the system from getting watchdog reset by returning directly to user
mode if restoring the user window traps. Also reduce the time we run with
%tl>0.


# 1.54 13-Apr-2000 eeh

Apparently gas 2.9.5 (don't ask) does not like to add values to %lo()
directives so move the additions inside %lo() to make it happy.
Hopefully this won't break older versions.


# 1.53 10-Apr-2000 mrg

- fix a speeling error
- rename some numbered labels to be a bit less confusing.
- remove dead code
- fix a debug error message (argh!)


# 1.52 10-Apr-2000 pk

Get a kernel without DDB to build.


# 1.51 16-Mar-2000 eeh

Revamp interrupts again:

Fix a bug causing interrmittent panics in interrupt dispatch.
Use interrupt vectors for softints.
Add a new send_softint interface.
Improved D$ flushing.
Improve traptrace and other debugging enhancements.


Revision tags: chs-ubc2-newbase
# 1.50 16-Jan-2000 eeh

Interrupt handlers return zero if they didn't handle the interrupt.


# 1.49 10-Jan-2000 eeh

Add debugger single-stepping and fix interrupt dispatch bugs.


# 1.48 30-Dec-1999 eeh

Lots of changes:

remove ffs()
add bzero that uses block store insns
save %gsr to fpstate
revert to physical accesses for pmap_zero_page so we don't
have conflicting page mappings
general cleanup.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base fvdl-softdep-base
# 1.47 06-Nov-1999 eeh

Handle zero length properly in copyinstr() copyoutstr() and copystr().


Revision tags: comdex-fall-1999-base
# 1.46 11-Oct-1999 eeh

branches: 1.46.2; 1.46.4;
Update to post 1.4.


# 1.45 05-Oct-1999 eeh

branches: 1.45.2;
Make broken versions of gas happy by using sethi/or instead of set for
(negative) addresses.


# 1.44 17-Sep-1999 thorpej

Centralize the declaration and clearing of `cold'.


Revision tags: chs-ubc2-base
# 1.43 18-Jul-1999 eeh

More fun with pmap.


# 1.42 21-Jun-1999 eeh

Improve TRAPTRACE. Add FLTRACE that only tracks MMU faults.


# 1.41 05-Jun-1999 eeh

Make pbrobeget() and probeset() work for 64-bit values as well. To do this
the arguments are changed so the address is first and the ASI second so we
can have the address in %o0:%o1 and not worry about unused registers.

Also a bit of copyright cleanup.


# 1.40 05-Jun-1999 mrg

update a commit slightly.


# 1.39 30-May-1999 eeh

Add code to support using %tick as the system clock if no "counter-timer" node
is found.


# 1.38 09-May-1999 eeh

Fixup non-DEBUG kernels.


# 1.37 29-Apr-1999 christos

Add sunos_sigcode (32 bit only)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.36 26-Mar-1999 eeh

branches: 1.36.4;
COMPAT_SPARC32 -> COMPAT_NETBSD32


# 1.35 25-Mar-1999 mrg

clean and up make compile


# 1.34 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.33 22-Mar-1999 eeh

Need to set up the pointers properly for partial FPU register stores.


# 1.32 22-Mar-1999 eeh

Flush D$ on bypass accesses.


# 1.31 28-Feb-1999 eeh

Use block load/store in pmap_zero_page()/pmap_copy_page().


# 1.30 17-Feb-1999 eeh

Let's test out vectored interrupts.


# 1.29 15-Feb-1999 hubertf

RCS ID police


# 1.28 11-Feb-1999 mrg

fix a comment pasto.


# 1.27 11-Jan-1999 eeh

Finally fixed 64-bit signal trampoline.


# 1.26 10-Jan-1999 eeh

Handle the symbol table properly in a 32-bit kernel that was booted from a
64-bit bootloader.


# 1.25 09-Jan-1999 eeh

More signal fixup.


Revision tags: kenh-if-detach-base
# 1.24 26-Nov-1998 mycroft

Sync kcopy() with 32-bit SPARC version.


# 1.23 16-Nov-1998 eeh

Fixup the last broken bits of the signal handling code.


Revision tags: chs-ubc-base
# 1.22 08-Oct-1998 eeh

Fix more syscall32 and signal breakage.


# 1.21 22-Sep-1998 eeh

More fixup in the signal area.

64-bit syscall cleanup.

Add emulation for some new FPU insns: conversion to 64-bit long int and
conditional moves.


# 1.20 17-Sep-1998 thorpej

SYS_sigreturn -> SYS___sigreturn14.


# 1.19 13-Sep-1998 eeh

Fixup signal changes (hopefully). However SUN_COMPAT is likely broken by
this and I don't know how to fix it.

We can now exec a 64-bit init through a really ugly hack (don't ask.)


# 1.18 11-Sep-1998 eeh

Add labels for the compat_sparc32 signal trampoline and break -- er -- fix
suword and fuword.


# 1.17 09-Sep-1998 eeh

Don't use %tick for microtime on 32-bit kernels -- breaks gettimeofday.


# 1.16 09-Sep-1998 thorpej

Adjust for the new "reaper" kernel thread: do not free the vmspace and
u-area in machine-dependent code. Instead, call exit2() to schedule
the reaper to free them for us, once it is safe to do so (i.e. we are
no longer running on the dead proc's vmspace and stack).


# 1.15 07-Sep-1998 eeh

Fix data corruption problem caused by broken debug code.


# 1.14 07-Sep-1998 eeh

Add new 64-bit trap vectors.


# 1.13 06-Sep-1998 eeh

32-bit fixup.


# 1.12 06-Sep-1998 eeh

Disable some debug stuff.


# 1.11 05-Sep-1998 eeh

It slices. It dices. It does everything except exec a sparc32_compat init.


# 1.10 02-Sep-1998 eeh

Periodic update: now starts probing devices.


# 1.9 30-Aug-1998 eeh

Some more 64-bit cleanup. Now everything compiles.


# 1.8 29-Aug-1998 eeh

Some more 64-bit-ification.


# 1.7 27-Aug-1998 eeh

Add 64-bit pmap support:

Moved from a two level 512/1024 entry setup mapping 32 (9/10/13) bits
respectively to a three level 1024/1024/1024 entry setup mapping 43
(10/10/10/13) bits. In 32-bit mode we waste about 1/12 pages mapping the high
11 bits. We also only manage 43 of the possible 44 bits of virtual address
space, wasting half of it. Oh well, maybe we'll do better next revision.


Revision tags: PMAP32
# 1.6 26-Aug-1998 mrg

panicstack: is needed outside of DEBUG. use _C_LABEL, and printf not db_printf (incase no ddb!)


# 1.5 13-Aug-1998 eeh

Merge paddr_t changes into the main branch.


Revision tags: eeh-paddr_t-base
# 1.4 07-Jul-1998 eeh

branches: 1.4.2;
General update:

Added genassym.cf
Removed lderr which should never have gotten in
Removed lots of dead code from locore.s
Added some softint stuff to intr.c
Added support for halt -p
esp and le both use bus_dmamap_*() functions now
instead of kdvma_mapin()
groundwork for PCI (but we still have no drivers for
any sun4u PCI devices)


# 1.3 04-Jul-1998 jonathan

defopt DDB.


# 1.2 26-Jun-1998 thorpej

defopt COMPAT_SVR4


# 1.1 20-Jun-1998 eeh

branches: 1.1.1;
Initial revision


# 1.411 06-May-2017 palle

sun4v: The %ver register is not available on sun4v - use GET_MAXCWP introduced in rev. 1.361. Verified using qemu (sun4u and sun4v) and on real sun4v hw (t2000)


Revision tags: prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.410 18-Apr-2017 palle

sun4v: Add handling of trap 0x06c @ trap level 1 - based on code from OpenBSD, but slightly adapted to NetBSD. verified using qemu


Revision tags: jdolecek-ncq-base pgoyette-localcount-20170320
# 1.409 19-Feb-2017 palle

sun4v: rft_user needs special handling (a manual fill) since the restore instruction may cause the number of trap levels to exceed the maximum for sun4v - inspired by code from the the openbsd rft_user code path - verified using qemu for both sun4u and sun4v


# 1.408 10-Feb-2017 palle

sun4v: Added handling of trap type 0x034 (address alignment error) + fixed typo mmfsa -> mmufsa. Verified for both sun4u and sun4v using qemu.


Revision tags: nick-nhusb-base-20170204
# 1.407 30-Jan-2017 palle

sun4v: Hook up syscall handling to the trap table. Verified using qemu for both sun4u and sun4v.


# 1.406 27-Jan-2017 palle

sun4v: implement missing handling of itsb traps 0x008 and 0x009. Based on code from OpenBSD. Tested using qemu.


Revision tags: bouyer-socketcan-base
# 1.405 07-Jan-2017 palle

branches: 1.405.2;
sun4v: slowtrap() now selects normal globals properly on both sun4u and sun4v platforms. Verified using qemu for both sun4u and sun4v systems


Revision tags: pgoyette-localcount-20170107
# 1.404 05-Jan-2017 palle

sun4v: TRAP_SETUP() updated to set mmu context id properly for both sun4v and sun4u platforms. Verified using qemu for both sun4u and sun4v systems


# 1.403 04-Jan-2017 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x00-0x23 and 0x28-0x30


# 1.402 29-Dec-2016 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x32-0x7f


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.401 20-Sep-2016 nakayama

Fix RAS for 32-bit kernels. trapframe is always 64-bit.


Revision tags: localcount-20160914
# 1.400 23-Aug-2016 palle

sun4v: rework sun4v_datatrap so it works properly when running on a T2-based system like T5120 - for some reason %tl is 0 when entering sun4v_datatrap causing a crash (sir instruction), so ignore the %tl value for now upon entry to sun4v_datatrap - with this fix both T1 and T2 based systems reach the same point - hangs in rft_user after the init process is started


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726
# 1.399 18-Jul-2016 palle

sun4v: handle device interrupts properly - both legacy (sysino) and cookies


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 1.398 04-Jun-2016 palle

branches: 1.398.2;
sun4v: rtf_user now uses macros GET_MMU_CONTEXTID and SET_MMU_CONTEXTID. Tested on sun4u (QEMU) and sun4v (T2000). Parts from OpenBSD.


Revision tags: nick-nhusb-base-20160529
# 1.397 18-May-2016 nakayama

Decrement %tl in trap handler not to make it zero unconditionally
for the nested trap, and remove useless mov.


# 1.396 17-May-2016 palle

sun4v: Implement missng MMU protection trap handling - mostly from OpenBSD


# 1.395 16-May-2016 palle

Avoid assembler-specific defines by using the export keyword in genassym.cf instead


# 1.394 15-May-2016 nakayama

%g1 is not preserved across function call, so load it before
return_from_trap.


# 1.393 13-May-2016 palle

sun4v: add missing implementation of sun4v_datatrap_tl0 so data_access_fault() is called - mostly from OpenBSD


# 1.392 13-May-2016 nakayama

- ci_paddr is always 64-bit.
- intrlev is array of pointer.
- ih_ack is pointer.


# 1.391 10-May-2016 palle

sun4v: make device interrupts work. Introduce a new intrhand_alloc() function for allocation of interrupt handlers and adapt to this. Parts from OpenBSD. ok martin@


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.390 09-Mar-2016 nakayama

32-bit kernels use 32-bit stack.


# 1.389 03-Mar-2016 palle

sun4v: rft_kernel should pay attention to the number of register windows that can be restored. We cannot rely on fill traps to occur, since sun4v only has two trap levels available in privileged mode. Based on code from OpenBSD. ok martin@


# 1.388 14-Feb-2016 palle

sun4v: add breakpoint trap entry to the sun4v trap table


# 1.387 03-Feb-2016 palle

sun4v: extend dmmu_set_secondary_context() to handle both sun4u and sun4v. ok martin@


Revision tags: nick-nhusb-base-20151226
# 1.386 06-Nov-2015 martin

Basically revert r1.246 of locore.s and r1.73 of vm_machdep.c:

Remove special case handling for userland lwps from cpu_lwp_fork,
instead do it in lwp_trampoline when we first return to userland.

which was a stupid idea - since we did now set all fork child's %tstate
(and thus %pstate when back in userland) to the current kernel's userland
default. This meant we lost the address mask bit for 32bit processes and
all memory model details for 64bit ones.

Move it back to cpu_lwp_fork and fix the condition to only do it once when
forking init.


# 1.385 05-Nov-2015 martin

Most of the time return_from_trap already got called with tf->tf_tstate
loaded in register %g1 - make it so for two more callers and remove
the reload of that value.


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606 nick-nhusb-base-20150406
# 1.384 05-Apr-2015 palle

sun4v: Ensure that the TTEs CP and CV bits are the same (both set) for the primary cpu and secondary cpus INTSTACK mappings


# 1.383 01-Apr-2015 palle

sun4v: Implement handling of cpu_mondo trap - from OpenBSD - tested using the Legion simulator


# 1.382 04-Mar-2015 palle

sun4v: revert some of the logic introduced in revision 1.378 - flushw is not necessary on sun4v (OpenBSD patches the flushw instruction to a nop instruction) - with these changes the kernel reaches cpu_boot_secondary_processors() when running in the Legion simulator (crashes due to missing handling of cpu_mondo_trap)


# 1.381 02-Mar-2015 nakayama

prom_printf converts "\n" to "\r\n" internally, so omit "\r".


# 1.380 02-Mar-2015 nakayama

PANICSTACK is a pointer itself, not a pointer to pointer.


# 1.379 02-Mar-2015 nakayama

Use panic stack temporarily for calling prom_printf in a trap
handler.

It seems that openfirmware cannot handle over 4GB pointers, and
stack pointers may point to over 4GB since VA layout was rearranged
by rev 1.33 of vmparam.h. Therefore, use panic stack to avoid
panicking in OF_write used by prom_printf.


# 1.378 23-Feb-2015 palle

sun4v: sparc_interupt - ensure that the trap level and globals level are the same when the flushw instruction is issued - othwise warnings occur when using the sun4v Legion simulator.


Revision tags: nick-nhusb-base
# 1.377 26-Oct-2014 palle

branches: 1.377.2;
sun4v: Create CLEANWIN0 and CLEANWIN1 macros for handling clean window traps on both sun4u and sun4u (based on the original code inlined in the sun4u trap table). Update trap tables accordingly for both sun4u and sun4v. Ok martin@


# 1.376 24-Oct-2014 nakayama

Fix typo in comment.


# 1.375 18-Oct-2014 snj

src is too big these days to tolerate superfluous apostrophes. It's
"its", people!


# 1.374 15-Oct-2014 palle

sun4v: fixed bug causing the real address to be incorrectly calculated as zero


# 1.373 24-Sep-2014 palle

sun4v: add code to enable startup of secondary cpus on both sun4u and sun4v systems - ok martin@


# 1.372 04-Sep-2014 palle

sun4v: All cpus must be setup with a TSB descriptor, so pmap_setup_tsb_sun4v() must take a pointer to the TSB descriptor


# 1.371 31-Aug-2014 palle

sun4v: Split the NORMAL_GLOBALS and ALTERNATE_GLOBALS macros to _SUN4U and _SUN4V variants. Rework the return_from_trap logic to use the new variants so it is possible to use a global register as scratch register.


# 1.370 14-Aug-2014 nakayama

Add missing delay slot in DEBUG kernel.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.369 30-Jul-2014 palle

branches: 1.369.2;
Fix ALTERNATE_GLOBALS so it at least works on sun4u - using a scratch register is not a good idea...


# 1.368 27-Jul-2014 palle

sun4v: Introduce a new macro ALTERNATE_GLOBALS (matching NORMAL_GLOBALS). Two new helper macros ENABLE_INTERRUPTS and DISABLE_INTERRUPTS are also created. With these changes the GENERIC.UP kernel will reach rootmount on sun4v systems - ok martin@


# 1.367 26-Jul-2014 palle

Improved the NORMAL_GLOBALS macro in the sun4u case, so only the relevant bit (AG) in %pstate is affected - ok martin@


# 1.366 24-Jul-2014 palle

sun4v: add missing spill/fill handling for trap level 1 + cosmetic changes to comments for trap level 0 entries


# 1.365 19-Jul-2014 palle

sun4v: Introduce a NORMAL_GLOBALS macro - first used in sparc_interrupt - other relevant uses will be handled as the sun4v work is progressesing - ok martin@


# 1.364 16-Jul-2014 palle

sun4v: Introduce SET_MMU_CONTEXTID macro for setting the mmu context id on both sun4u and sun4v


# 1.363 13-Jul-2014 palle

sun4v: add interrupt handling to sun4v trap table


# 1.362 13-Jul-2014 palle

Bugfix: add missing cmp instruction to GET_MAXCWP macro


# 1.361 30-Jun-2014 palle

sun4v: The maximum number of register windows is a constant and thus not available via the %ver register (sun4u only). Introduce a macro GET_MAXCWP that handles this, so cpu_switchto() works properly on sun4v. Other relevant reference to %ver can be adapted to use GET_MAXCWP as the sun4v port progresses. OK martin@


# 1.360 31-May-2014 palle

sun4v: added missing dtsb miss handling for trap level 1 - with this update the kernel now reaches configure() on sun4v systems


# 1.359 30-May-2014 palle

Remove debugging code introduced by accident in locore.s revision 1.357


Revision tags: yamt-pagecache-base9 rmind-smpnet-nbase rmind-smpnet-base
# 1.358 05-May-2014 palle

sun4v: the trap base address should be assigned to %l1 so %tba is properly setup later in the code - now the kernel gets as far as printing the copyright disclaimer, kernel version and total and available memory before crashing


# 1.357 21-Apr-2014 palle

sun4v: Update comment: modified -> access


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.356 21-Feb-2014 palle

branches: 1.356.2;
sun4v: Rename TLB_ defines to SUN4U_TLB_ so entries created using TSB_DATA() are properly setup for sun4u and sun4v. Relocate the cputyp variable from autoconf.c to locore.s and make it const in param.h so optimized code can be generated. Parts from OpenBSD. Optimization suggested by nakayama@. OK martin@, mrg@, nakayama@


# 1.355 31-Jan-2014 tsutsui

defined(LKM) -> defined(MODULAR)


# 1.354 26-Jan-2014 palle

sun4v: Add handling of spill/fill and dtsb miss traps (with a XXX to be handled later)


# 1.353 07-Jan-2014 palle

sun4v: trap table setup - currently populated with dummy entries which will be properly implemented later - parts from OpenBSD - OK martin@


# 1.352 29-Dec-2013 nakayama

Make buildable w/o options SUN4V.


# 1.351 27-Dec-2013 palle

a) make the hunt through the cpus list more generic b) sun4v: ensure that the interrupt stack is mapped permanently and the TSB is setup properly - parts from OpenBSD. OK martin@


# 1.350 06-Dec-2013 nakayama

Increase an interrupt depth only in the case of hardware interrupts,
and remove the ci_idepth trick in softint_fastintr.

Fixes the following diagnostic panic reported in port-sparc64.

panic: kernel diagnostic assertion "!cpu_intr_p()" failed: file
"../../../../kern/subr_xcall.c", line 351


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 1.349 24-May-2013 nakayama

branches: 1.349.2;
Disable interrupts after calling data_access_error as with
data_access_fault.


# 1.348 28-Apr-2013 nakayama

Use macros in machine/asm.h instead of locally defined, and
introduce CASPTRA for casxa/casa.


Revision tags: agc-symver-base
# 1.347 23-Jan-2013 martin

Fix sparc64_ipi_ccall by adding proper trap setup.
Fixes xcall(9) problems, as exposed by pserialize(9). Noticed by
J. Hannken-Illjes, cause pointed out by Takeshi Nakayama.


# 1.346 23-Jan-2013 martin

Sligthly clean up the (by default unused) #ifdef TRAPS_USE_IG


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.345 10-Nov-2012 nakayama

Revise comment.


# 1.344 10-Nov-2012 nakayama

Use macro instead of magic number.


# 1.343 09-Nov-2012 nakayama

Make setstick() and getstick() to inline functions.


# 1.342 08-Nov-2012 macallan

use system tick timer instead of %tick on UltraSPARC-III-ish CPUs
review & fixes by Takeshi Nakayama


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.341 17-Mar-2012 mrg

branches: 1.341.2;
port the corrected ECC error handling code from freebsd. i noticed my U10
took one of these and then hang. it shouldn't hang, there's a 'sir' here that
doesn't seem to reset properly. oh well.

tested by simulated a trap via 'ta 0x10' and considering that the same, but
it hasn't been tested against a real ECC error yet.


Revision tags: jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base4
# 1.340 03-Mar-2012 nakayama

Fix the root cause of the hack "disable optimizations for uvm_bio.c
on 32 bit kernels".

gcc converts a division in the calculation of UBC_UMAP_ADDR macro
to multiplication (smul or combination of add/sll), and the
register of its result contains a garbage in upper 32 bits (the
upper 32 bits of smul/add/sll's result isn't zero cleared).

Then it passes to pseg_get{,_real} through pmap_extract without the
zero clear of upper 32 bits in the optimization case. So the
result of pseg_get and pmap_extact sometimes gets screwed up.


Revision tags: jmcneill-usbmp-base5 jmcneill-usbmp-base3
# 1.339 19-Feb-2012 rmind

Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.


Revision tags: jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.338 04-Sep-2011 nakayama

branches: 1.338.2; 1.338.6; 1.338.8;
ih_pil is an interrupt level, not an interrupt mask.


# 1.337 27-Jul-2011 nakayama

ivec is assigned to hardware, so count its event counter up in
interrupt_vector, not in softint, and do some optimization.


# 1.336 20-Jul-2011 macallan

add per ivec event counters


# 1.335 12-Jul-2011 mrg

rename sparc64 BLOCK_SIZE and BLOCK_ALIGN to have SPARC64_ prefixes.
for the assembler files, define the old names to the new names
since using the new names cause ugliness due to longer identifer
names, and reduces churn.

fixes build issues in dtv and vaguely makes <machine/psl.h> slightly
less name-space invasive.


# 1.334 18-Jun-2011 nakayama

Add fast softint(9) support for sparc64.

Reviewed on port-sparc64.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 1.333 12-May-2011 mrg

branches: 1.333.2;
first steps towards fujitsu SPARC64 support:

- SPARC64 systems have interrupts with upto 14 bits set, but we only look
at the first 11 bits. trim non IPI interrupts to 11 bits


Revision tags: uebayasi-xip-base7 bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 jym-xensuspend-nbase jym-xensuspend-base
# 1.332 20-Dec-2010 matt

branches: 1.332.2;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.


Revision tags: uebayasi-xip-base6 uebayasi-xip-base5 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 1.331 10-Jul-2010 nakayama

Clear the upper word explicitly before combining two 32-bit values to 64-bit
on 32-bit kernels.


# 1.330 23-May-2010 martin

Split copy related functions out of locore.s into copy.S, move functions
only needed on multiprocessors into mp_subr.S.


# 1.329 17-May-2010 martin

Simplify primary CPU startup slightly by using the fact that our cpuinfo's
curpcb pointer points to the uarea/pcb of lwp0 and by remembering the pointer
to this cpuinfo, thus avoiding a few CPUINFO_VA references.


Revision tags: uebayasi-xip-base1
# 1.328 20-Mar-2010 chs

fix copy{in,out}{,str}() to return the error returned by uvm_fault().
fixes PR 41813.


Revision tags: yamt-nfs-mp-base9
# 1.327 10-Mar-2010 mrg

branches: 1.327.2;
XXX: workaround we'd like to remove when pmap / uvm locking is cleaned up:

- rename pseg_get() and pseg_set() to pseg_get_real() and pseg_set_real().
- if USE_LOCKSAFE_PSEG_GETSET is defined, which it current is by default,
define pseg_[gs]et() in terms of functions that take a new pseg_lock
mutex at IPL_VM while calling into the real functions.

this seems to avoid the pseg_set() crashes we've seen:
1 - spare needed, when pseg_get() just worked for this pmap
2 - the 2rd ldxa via ASI_PHYS_CACHED in pseg_set() loads garbage
into %o4, and causes the 3rd ldxa to fault


# 1.326 08-Mar-2010 mrg

blast_dcache() SMP friendly:

- blast_dcache() becomes sp_blast_dcache(dcache_size, dcache_line_size)
- new smp_blast_dcache(sparc64_cpuset_t) that blasts the D$ on this cpuset
- sparc64_ipi_blast_dcache() to support the above
- in pmap_remove_all(), when freeing mmu contexts for this pmap, mark
the set of cpus to blast the d$ on as well and convert the
blast_dcache() call into smp_blast_dcache() on the cpus who ran this
pmap, or, sp_blast_dcache(dcache_size, dcache_line_size)
- convert the remaining blast_dcache() in machdep.c to sp_blast_dcache()
- in pmap_destroy()/pmap_remove_all() take the pmap_lock() always since
we assert it is held always.

with these changes, NFS builds on the U60 seem to be stable now, and
the USIII machines also can often complete a single build.sh run now,
diskful or diskless.


reviewed by mlelstv and partially by martin, tested by martin and myself,
with some ideas from chuq as well.


# 1.325 07-Mar-2010 mrg

need _ALIGN in locore.h as well, for DEBUG kernels.


# 1.324 07-Mar-2010 mrg

gas has supported SPARC ".empty" for a long while; get rid of an
ancient workaround.


# 1.323 06-Mar-2010 mrg

move the memcpy/memset implementations out into their own file, with the
block copy versions as well. move some of the definitions in locore.s
into a new locore.h.

locore.s is almost 2000 lines shorter with this change.


# 1.322 04-Mar-2010 mrg

- in _bus_dmamap_unload(), pmap_page_protect() and pmap_clear_reference()
switch the dcache_flush_page() into a dcache_flush_page_all()
- in both pmap_kremove()/pmap_remove(), remove the blast_dcache() call
and replace it with dcache_flush_page_all()
- in pmap_get_page() [used to allocate PTP's], always call pmap_zero_page(pa)
- flush the dcache of the dst page in pmap_{copy,zero}_page() by redirecting
throught a C function that calls the (renamed) asm. the old asm code had a
comment about needing to do this...
- add a couple of membar #Sync's that the USIII manual recommends


based on discussions with chuq@, skrll@ and martin@.


these help my SB2000 / SB2500 with both disk / nfs builds and other tasks,
sometimes lasting for several hours before failing or asserting.


# 1.321 24-Feb-2010 mrg

when handing back page table pages to UVM, flush them from the dcache
on all CPUs.

idea from skrll@, and makes my disk-based SB2000 stable.

tested on U60, SB2000 and SB2500.


# 1.320 24-Feb-2010 mrg

- re-introduce sp_tlb_flush_pte() and sp_tlb_flush_all() that call
the right USI/USIII version.
- define tlb_flush_pte() in terms of sp_tlb_flush_pte() for the
!MULTIPROCESSOR case

this centralises some CPU_IS_USIII_UP() tests.


# 1.319 22-Feb-2010 mrg

move {dump,print}_[id]tlb() into a separate file.


# 1.318 22-Feb-2010 mrg

- store the maximum [id]cache size / line size for each cpu

- remove patch_kernel() since it isn't necessary and has been patching
the wrong thing in general.

- implement USIII versions of blast_icache(), dcache_flush_page() and
cache_flush_phys(). use the newly recorded cache size/line sizes.

- in winfixsave, flush the D$ with the right size index and ops. this
kills one of the wrong tag->inval patches.

- for blast_dcache(), use the newly recorded dcache_size/line_size.

- for blast_icache(), use the newly recorded cache size/line sizes.
for the USIII verison, disable the I$ while writing to ASI_ICACHE_TAG.


these changes removed several hard coded cache sizes values, some very
wrong kernel patching, and seem to make the current failure modes for
USIII less common, but not gone.


# 1.317 15-Feb-2010 mrg

- don't flush 32-bit entries for 64-bit code, it does not seem to be
necessary. #define TLB_FLUSH_LOWVA to turn it back on.
- remove the #if 0'd code in sparc64_ipi_flush_pte_usiii(), i have
verified that it is not required.
- add a missing membar #Sync to sp_tlb_flush_pte_usiii().


# 1.316 15-Feb-2010 nakayama

Fix linker error of GENERIC32 kernel.


# 1.315 15-Feb-2010 mrg

use TLB_SIZE_SPITFIRE in a couple of places, and note that the
{print,dump}_[id]tlb() versions are currently spitfire specific.


# 1.314 15-Feb-2010 mrg

introduce a new patch_kernel() and call it from the end of bootstrap().
use it to patch up TLB flush instructions that don't match for USI/II
and later. we can also hopefully use this to make GENERIC.MP minimally
expensive on single CPU machines as well.

this is the last piece needed to get GENERIC/GENERIC.MP to boot on the
USIII* machines.

idea and some initial code from openbsd.


# 1.313 13-Feb-2010 mrg

remove KTR support. it's never been a working part of netbsd src tree.


# 1.312 09-Feb-2010 wiz

Fix typo in comment.


Revision tags: uebayasi-xip-base
# 1.311 06-Feb-2010 mrg

branches: 1.311.2;
- properly map the schizo interrupt registers, so we can use the normal
virtual mappings to access them.
- with the above fxied, kill SCHIZO_BUS_SPACE_BROKEN, and introduce
an options CHEETAH for now, that disables the SPITFIRE code in locore.
- merge schizo_init() into schizo_attach() and clean up the softc a bit.


with this we are only one more step away from GENERIC booting on USIII
machines.


# 1.310 02-Feb-2010 mrg

- split sp_tlb_flush_pte() and switchtoctx() into sp_tlb_flush_pte_us()/
sp_tlb_flush_pte_usiii() and switchtoctx_us()/switchtoctx_usiii() and
implement the latter while i'm here. it works ... sometimes i think,
but also sometimes panics/hangs.
- fix a comment in sparc64_ipi_flush_pte_usiii()


# 1.309 02-Feb-2010 mrg

for now, reduce a few #ifdef SPITFIRE cases by introducing a new
ASI_DCACHE_TAG_OR_INV that is either ASI_DCACHE_{TAG,_INVALIDATE}.

increase the common code in cache_flush_phys().


# 1.308 01-Feb-2010 mrg

- sp_tlb_flush_all() becomes sp_tlb_flush_all_us() and sp_tlb_flush_all_usiii()
- sparc64_ipi_flush_pte() becomes sparc64_ipi_flush_pte_us() and
sparc64_ipi_flush_pte_usiii()
- add some commented out code to disable interrupts and raise the traplevel
in sparc64_ipi_flush_pte_usiii()
- cache_flush_phys() was missing a little of code in the cheetah case


# 1.307 01-Feb-2010 mrg

for USIII, use the new "tlb demap all" operation in sp_tlb_flush_all()


# 1.306 01-Feb-2010 mrg

remove unused icache_flush_page() implementation.


# 1.305 23-Jan-2010 mrg

remove the final uses of DATA_START.

now we can remove the 16KB space reserved at the start of the data segment,
and i now understand why i wrote this now removed comment 3.5 years ago:
"this shouldn't be needed... but kernel usually hangs without it"


# 1.304 23-Jan-2010 mrg

remove most of the code that writes debugging info DATA_START + offset.


# 1.303 23-Jan-2010 mrg

remove CHKPT() macro and uses. it's likely wrong in SMP land and probably should
be replaced with KTR-style uses if necessary.


# 1.302 23-Jan-2010 mrg

fix a comment.


Revision tags: matt-premerge-20091211
# 1.301 10-Dec-2009 rmind

Rename L_ADDR to L_PCB and amend some comments accordingly.


# 1.300 05-Dec-2009 mrg

- adjust the PA mask to the 43 bits supported by USIII.
- rework the spitfire/cheetah cache_flush_phys() to avoid several #ifdefs
- add a membar #Sync after sparc64_ipi_drop_fpstate (probably unnecessary)


# 1.299 30-Nov-2009 nakayama

sp_tlb_flush_pte for cheetah:
- restore interrupts properly in case of %tl > 0.


# 1.298 30-Nov-2009 mrg

stablize UP USIII support by blocking interrupts around sp_tlb_flush_pte()
i was seeing stack corruption while taking an interrupt in this function.

get USIII SMP mostly working by implementing the cheetah version of
sparc64_ipi_flush_pte().


SMP support is still not entirely stable. i can reproducably get a:

panic: fpusave_lwp ipi didn't

while running build.sh, when an awk process is exiting. other simple
heavy work loads do not crash for me right now.


# 1.297 30-Nov-2009 mrg

delete some no longer used code:
- smp_tlb_flush_ctx()
- smp_tlb_flush_all()
- sparc64_ipi_flush_ctx()
- sparc64_ipi_flush_all()
- sp_tlb_flush_ctx()


# 1.296 29-Nov-2009 nakayama

- calculate end PA correctly.
- wrap more spitfire specific (flushing I$) code.
- fix inverted #if condition for flushing I$ (and restore ASI_ICACHE_TAG).


# 1.295 28-Nov-2009 mrg

implement enough code to get SB2000/SB2500 booting to multiuser. does
not last long if you use it, but an idle machine has stayed up 10 hours.

- for the !SPITFIRE case, use ASI_DCACHE_INVALIDATE instead of
ASI_DCACHE_TAG when clearing tlb entries. from openbsd.

- convert some comment "! Not yet" into "WRITEME", so that attempting
to build a USIII MULTIPROCESSOR kernel fails to build until the code
is written.

- add some more WRITEME's for the above.

- implement a !SPITFIRE version of sp_tlb_flush_all(). since there are
no spare regs, for now just always increase %tl around this call. (we
could maybe store a token in %o3 along with the saved %pstate info.)


# 1.294 26-Nov-2009 matt

Kill proc0paddr. Use lwp0.l_addr instead.


# 1.293 25-Nov-2009 mrg

s/L_ADDR/L_PCB/, requested by rmind.


# 1.292 17-Oct-2009 nakayama

Wrap unused code with #if 0 which is called from #if 0'ed code.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5
# 1.291 30-May-2009 martin

cpu_setfunc() can not use lwp_trampoline, as that has additional lwp startup
semantics. Use a simpler setfunc_trampoline instead.


# 1.290 18-May-2009 nakayama

Remove random() from locore.s since it is in libkern.


# 1.289 16-May-2009 nakayama

Remove clear %tick in locore.s since it is cleared at cpu_initclocks() in
clock.c.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 nick-hppapmap-base mjf-devfs2-base
# 1.288 15-Dec-2008 mrg

restore some old "intrdebug" code, but leave it under NOT_DEBUG. most
of it works, but one that prints func/arg for each handler is not very
stable...

for now, while schizo bus space pointer accesses aren't working, add
a SCHIZO_BUS_SPACE_BROKEN option so you can build a kernel with schizo.

with this, and the prior schizo interrupt fix, you can now fail to run
/sbin/init!


Revision tags: haad-dm-base2 haad-nbase2 haad-dm-base
# 1.287 09-Dec-2008 martin

Get rid of get_maxctx() - it doesn't work on newer cpus and we will have
to find a better way for (some) sun4v machines - all sun4u use 13 bit
contexts anyway.


Revision tags: netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 ad-audiomp2-base netbsd-5-base
# 1.286 30-Oct-2008 nakayama

branches: 1.286.2; 1.286.6;
Wrap more code specific to USE_BLOCK_STORE_LOAD.


Revision tags: matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4
# 1.285 05-Oct-2008 nakayama

branches: 1.285.2;
- in flushing cache, use 32 as increment/decrement value to match the
cache line size.
- remove useless restore of %asi.
- remove nop in delay slot if we can.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 1.284 10-Jul-2008 nakayama

Use proper CCR.


# 1.283 10-Jul-2008 nakayama

sparc64_ipi_save_fpstate:
- use primary MMU context for consistency with other trap/interrupt handlers.

sparc64_ipi_save_fpstate, savefpstate:
- avoid storing fp registers as we can.

sparc64_ipi_save_fpstate, savefpstate, loadfpstate:
- remove unaligned case since buffers allocated with pool_cache are ensured
64-byte aligned.

Ok by martin@.


# 1.282 02-Jul-2008 nakayama

branches: 1.282.2;
UltraSPARCs don't have floating point queue, and reading %fq regsiter
will cause illegal instruction trap. So remove the code handling them.


# 1.281 29-Jun-2008 nakayama

Wrap IPI calls with #ifdef MULTIPROCESSOR.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.280 14-Jun-2008 nakayama

Close unterminated comment.
Fix unexpected behavior in case of loadfpstate from unaligned buffer.


Revision tags: yamt-pf42-base3
# 1.279 31-May-2008 nakayama

branches: 1.279.2;
openfirmware_exit:
- disable interrupts with %pstate.
- prepare 64-bit stack and enable 64-bit addresses for 32-bit SMP kernels.


Revision tags: hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 yamt-nfs-mp-base yamt-pf42-base
# 1.278 16-Apr-2008 nakayama

branches: 1.278.2; 1.278.4; 1.278.6;
Disable TRAPSTATS which was accidentally enabled when yamt-idlelwp branch
was merged.

Ok by martin@.


# 1.277 14-Apr-2008 nakayama

Remove sparc64_ipi_sync_tick.

Since we can use counter-timer as timecounter instead of %tick on SMP kernel,
it is not necessary to sync all CPUs %tick registers.


# 1.276 14-Apr-2008 nakayama

Add workaround for BB_ERRATA_1 on writing to TICK_CMPR register in
next_tick(). If writing to TICK_CMPR fails, we lose hardclock interrupt
on secondary CPUs.

About BB_ERRATA_1 from comment in OpenSolaris:

/*
* Writes to the TICK_COMPARE register sometimes fail on blackbird modules.
* The failure occurs only when the following instruction decodes to wr or
* wrpr. The workaround is to immediately follow writes to TICK_COMPARE
* with a read, thus stalling the pipe and keeping following instructions
* from causing data corruption. Aligning to a quadword will ensure these
* two instructions are not split due to i$ misses.
*/


# 1.275 28-Mar-2008 nakayama

Don't read fplwp content in delay slot for considering the case fplwp was
modifiled.

Reported by Chris Ross on port-sparc64.


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.274 20-Mar-2008 nakayama

- remove disabling interrupt in IPI.
- unused VA bits in MMU demap is 13 bits, not 12 bits.


# 1.273 18-Mar-2008 nakayama

Fix a race when increment an interrupt level event counter.


# 1.272 17-Mar-2008 nakayama

Fix a race condition in IPI handlers of save/drop fpstate, from OpenBSD.
Reported and tested by martin@.


# 1.271 17-Mar-2008 nakayama

Make schedintr interrupt handler per-CPU.
While there rename tickintr interrupt handler and share initialization
code with schedintr.


# 1.270 14-Mar-2008 nakayama

Improve IPI handling:
- make IPI takes two arguments.
- add IPI event counters per-CPU.
- implement IPI functions which were missing or broken.
- insert DELAY while halting primary CPU in IPI handler.


# 1.269 02-Mar-2008 nakayama

- make interrupt pending list per-CPU.
- make tickintr() MP-safe.
- remove unused port-sparc derived interrupt code.

Ok by martin@.


# 1.268 02-Mar-2008 nakayama

Don't get IPI handler argument (from bogus address), and ack IRQ twice.


# 1.267 28-Feb-2008 martin

Make TSBs and MMU contexts per-cpu.


Revision tags: nick-net80211-sync-base mjf-devfs-base hpcarm-cleanup-base
# 1.266 26-Jan-2008 nakayama

branches: 1.266.2; 1.266.6;
Fix for 32-bit kernels.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.265 15-Jan-2008 skrll

Store a sensbile PCB_PC value in snapshot - the return point.

This helps gdb somewhat.

OK'd by martin.


# 1.264 14-Jan-2008 martin

Fix register name typo/copy&pasto - %g6 is not %o6/%sp.
From OpenBSD.


Revision tags: matt-armv6-base
# 1.263 06-Jan-2008 martin

Load the next cpu_info pointer with LDPTR instead of ld.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2
# 1.262 09-Dec-2007 martin

branches: 1.262.2;
Provide cpu_intr_p(), at least for non-MULTIPROCESSOR kernels.
Based on suggestions by Andrew Doran.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.261 22-Oct-2007 martin

branches: 1.261.2; 1.261.4; 1.261.6;
Remove an unused .globl declaration


Revision tags: yamt-x86pmap-base4
# 1.260 17-Oct-2007 garbled

Merge the ppcoea-renovation branch to HEAD.

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

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

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base ppcoea-renovation-base vmlocking-base
# 1.259 09-Sep-2007 martin

branches: 1.259.4;
Make cpufrequency and friends per cpu values.
Prepare a hz tick interrupt on secondary CPUs via %tick, but do not
enable it yet, as it breaks ddb.


# 1.258 09-Sep-2007 martin

Do not ACK IPIs before we finished loading all arguments.


# 1.257 06-Sep-2007 martin

Remove the (now unused) second 64k page mapped per CPU.
From matthew green, with small changes by me. All bugs are mine.


# 1.256 25-Aug-2007 martin

branches: 1.256.2;
Remove INITSTACK completely - at the time we used to switch to it, we
already have access to all of lwp0 and it's uarea - so we can switch
to the correct lwp0 stack easily before calling main.


# 1.255 25-Aug-2007 martin

When exiting to OF, use the interrupt stack instead of INITSTACK


# 1.254 25-Aug-2007 martin

Rework cpu_mp_startup slightly:
- temporarily use the cpu's interrupt stack untill we are ready
to access non-OF-based mappings, then directly switch to the cpu's
idlelwp's uarea stack
- disable interrupts untill we are ready to call C code


# 1.253 13-Aug-2007 macallan

remove two restore without matching save


Revision tags: nick-csl-alignment-base matt-mips64-base mjf-ufs-trans-base
# 1.252 06-Jul-2007 martin

branches: 1.252.4; 1.252.8;
A few nits for 32bit SMP kernels, noticed by mrg.
While there, simplify the fpstate IPIs a bit.


# 1.251 05-Jul-2007 martin

sparc64_ipi_save_fpstate is not a leaf function - create a full grown
stack frame.


# 1.250 28-May-2007 mrg

clean up cpu_switchto() a little - no need to flushw or membar
excessively. optimise an rdpr. tested by tnn.


# 1.249 23-May-2007 martin

Fix a stupid bug in the save_fpstate ipi, which caused overwriting of
struct lwp of the lwp owning the fpu. Fix clearing the fplwp - %o0 will
not survive the call to savefpstate - duh!


# 1.248 20-May-2007 martin

Simplify tf_tstate setting when leaving for userland initially - I seem
to have confused the if with the else case of the previous C code.
Funny that it worked at all.


# 1.247 20-May-2007 martin

cpu_switchto() has to return it's first arg, always. This differs from
my reading of the documentation, but helps in the real world and seems
to be what other ports do.


# 1.246 20-May-2007 martin

Remove special case handling for userland lwps from cpu_lwp_fork, instead
do it in lwp_trampoline when we first return to userland.


# 1.245 19-May-2007 martin

cpu_idle is a leaf function, so we better "return from leaf".
Use return value from cpu_switchto for previous lwp in lwp_trampoline.
Also shamelessly steal a comment from uwe written for sparc that explains
all this.
Thanks to tnn, mrg, and uwe for helping to debug this.


# 1.244 17-May-2007 yamt

merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base ad-audiomp-base
# 1.243 22-Feb-2007 martin

branches: 1.243.4; 1.243.6; 1.243.12;
uvm.page_idle_zero now is a bool, not a 32bit value any more.


# 1.242 21-Feb-2007 mrg

shave 9 insns off the tsb setup in cpu_initialize & cpu_mp_startup.


# 1.241 21-Feb-2007 martin

Get rid of unused (thus always zero) "curlwp" variable hidden in assembler
code (C code always uses a cpuinfo based macro).


# 1.240 18-Feb-2007 martin

Make use of another call delay slot, pointed out by uwe.


# 1.239 18-Feb-2007 martin

Make use of a call delay slot and avoid a bogus EMPTY.
Spotted by Juergen Hannken-Illjes, with input from Andrew Doran and
Valeriy E. Ushakov.


# 1.238 18-Feb-2007 martin

Whitespace cosmetics


# 1.237 18-Feb-2007 martin

Backout previous: EMPTY was misused


# 1.236 18-Feb-2007 martin

Make EMPTY expand to nop with gas, as it is used to mark empty branch
delay slots.


# 1.235 15-Feb-2007 martin

branches: 1.235.2;
Fix obvious copy&pasto in SCHED_DEBUG register usage.


Revision tags: post-newlock2-merge
# 1.234 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.233 25-Dec-2006 wiz

Spell "relevant" correctly. From Zafer Aydogan.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.232 25-Oct-2006 mrg

branches: 1.232.2; 1.232.4;
- note that __idle_u should go away but doing so breaks things
- fix several comments to reality
- clean up the #ifdef NO_VCACHE code slightly
- use call instead of set/jmpl
- remove a couple of unnecessary stores to curlwp


Revision tags: yamt-splraiseipl-base2
# 1.231 18-Oct-2006 rjs

Clean up some comments. Cosmetic change to use correct structure
offset names.

Optimize out two instructions from sparc64_ipi_save_fpstate and
sparc64_ipi_drop_fpstate.


# 1.230 17-Oct-2006 mrg

allocate 128KB (as opposed to 64KB) per-cpu, and place the interrupt
stack, cpu_info structure, panicstack, idle uarea and normal kernel
stack in here. the idle uarea and kernel stack are in the 2nd 64KB
page. the interrupt stack and cpu_info structure are as the same
place in the 1st 64KB page, and the panicstack grows down from the
top of this page. update comments in param.h to suit (XXX: a lot
of these constants should move to a header file that will not pollute
the name space so much.) map these pages identically between
cpu_initialise() and cpu_mp_startup(), and deal with the two 64KB
pages in pmap_extract(). keep an unmapped 64KB page between them.

don't initialise the unused "ci_eintstack" member of the cpu_info
structure

use constants to initialise many addresses in the cpu_info structure,
consolidating these assignments from cpu0 and cpu>0

delete u0/estack0/panicstack from locore.s

clean up some wrong comments in locore.s

fix a 32bit-only bug in cpu_mp_startup().

delete 'u0' entirely.


this fixes recent random lossage seen on port-sparc64: processes
stuck in RUN state, data faults, and hangs.


# 1.229 04-Oct-2006 mrg

use call instead of set/jmpl. add an entry point for idle that expects
sched_lock to be unlocked, and use this for non-boot cpu's. complete a
comment describing how registers in idle_switch are expected to be set.


# 1.228 03-Oct-2006 mrg

use the same SAVE_LOCALS_INS definition for 32 bit and 64 bit kernels.
refactor TRAP_SETUP() a little between these two versions to be more alike.


# 1.227 03-Oct-2006 mrg

use the correct size/type for MP variables (pointers and longs).

a 32 bit MULTIPROCESSOR kernel now builds (and crashes quickly.)


# 1.226 03-Oct-2006 mrg

in the 64bit version of SAVE_LOCAL_INS, s/BIAS/STKB/ to allow future
sharing of the 32 and 64 bit versions of the {TRAP,INTR}_SETUP macros.


# 1.225 19-Sep-2006 mrg

- remove some way old FP setup/teardown code
- put the block memcpy/memset inside #ifdef USE_BLOCK_STORE_LOAD which
is (now) defined.

no functional change, same .o is generated.


# 1.224 19-Sep-2006 mrg

re-order the changes in rev 1.217 to give registers a little bit of
time to settle between usage, like it was before hand.


# 1.223 19-Sep-2006 mrg

- remove a wrong comment.
- add a new entry point for idle called idle_switch that is called by
cpu_switch() in the MP case when sched_whichqs is zero, properly
setting up the idle stack. from petrov@ via martin@.


# 1.222 19-Sep-2006 mrg

rework interrupt_vector() slightly:
- for the IPI case, avoid loading the address of intrlev into %g3
- remove some NOT_DEBUG code
- load the interrupt argument #2 in the delay slot

this removes 2 nops during interrupt processing for the normal
case, and an additional 2 ALU instructions for IPIs


# 1.221 18-Sep-2006 mrg

- sparc64_ipi_halt(): we shouldn't return from sparc64_ipi_halt_thiscpu()
so replace a branch with a 'sir'
- in #if 0 code, in sparc64_ipi_flush_pte() and sparc64_ipi_flush_ctx()
save/restore the out registers that the sp_tlb_flush_xxx() versions
around calling them
- in sp_tlb_flush_pte() and sp_tlb_flush_ctx(), replace global register
usage with out registers so that we don't clobber the (alternate)
global registers when these are called from IPI context


# 1.220 18-Sep-2006 mrg

- remove an extra 'sir' that followed one in a macro
- add some named labels to some spill/fill handlers
- remove 2 unused strings


Revision tags: yamt-splraiseipl-base
# 1.219 18-Sep-2006 martin

branches: 1.219.2;
Lazy FPU handling for the MULTIPROCESSOR case


# 1.218 16-Sep-2006 nakayama

From OpenBSD:
- reload %fprs for checking it again.
- use symbolic names for checking in %fprs.

revision 1.51
date: 2005/07/18 14:50:11; author: deraadt; state: Exp; lines: +2 -1
cache a copy of the fprs so we know what fp restore we should do after

revision 1.50
date: 2005/07/14 01:46:13; author: deraadt; state: Exp; lines: +4 -4
use symbolic names for checking in %fprs, as above


# 1.217 16-Sep-2006 nakayama

Fix a couple of %y register save/restore errors, inspired from OpenBSD.

revision 1.44
date: 2004/04/23 04:18:17; author: marc; state: Exp; lines: +5 -4

fix a couple of %y register save/restore errors
1) don't save %y in a register that is later used before restoring %y
2) always restore %y after calling a signal handler
tested by drahn@, OK pval


# 1.216 15-Sep-2006 martin

Do not bother to save fpu state when we are about to get rid of it.


Revision tags: yamt-pdpolicy-base9
# 1.215 13-Sep-2006 mrg

SMP cleanup. provide support for multiple CPUs in DDB. (SMP itself
is still not working.)

cpu.h:
- add a pointer for DDB regs in SMP environment to struct cpu_info
- remove the #defines for mp_pause_cpus() and mp_resume_cpus()
cpuset.h:
- remove CPUSET_ALL() and rename CPUSET_ALL_BUT() to CPUSET_EXCEPT()
from petrov.
db_machdep.h:
- rename the members of db_regs_t to be the same as sparc
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- redo DDB_REGS to no longer be a pointer to a fixed data structure
but to one allocated per-cpu when ddb is entered
- move a bunch of prototypes in here
intr.h:
- remove SPARC64_IPI_* macros, no longer used
db_interface.c:
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- make "nil" a 64 bit entity
- change the ddb register access methods to work in multiprocessor
environment, it is now very much like sparc does it
- in kdb_trap() avoid accessing ddb_regp when it is NULL
- update several messages to include the cpu number
- unpause other cpus much later when resuming from ddb
- rename db_lock() to db_lock_cmd(), as the sparc-like code has
db_lock as a simple lock
- remove "mach cpus" command, and replace it with "mach cpu" (which
does the same) and also implement "mach cpu N" to switch to
another cpus saved trapframe
db_trace.c:
- update for the ddb_regs -> ddb_regp change
genassym.cf:
- add TF_KSTACK as offsetof(struct trapframe64, tf_kstack)
ipifuncs.c:
- overhaul extensively
- remove all normal interrupt handlers as IPI's, we now handle
them all specially in locore.s:interrupt_vector
- add a simplelock around all ipi functions - it's not safe for
multiple cpus to be sending IPI's to each other right now
- rename sparc64_ipi_pause() to sparc64_ipi_pause_thiscpu() and,
if DDB is configured, enable it to save the passed-in trapframe
to a db_regs_t for this cpu's saved DDB registers.
- remove the "ipimask" system (SPARC64_IPI_* macros) and instead
pass functions directly
- in sparc64_send_ipi() always set the interrupt arguments to 0,
the address and argument of the to be called function. (the
argument right now is the address of ipi_tlb_args variable, and
part of the reason why only one CPU can send IPI's at a time.)
don't wait forever for an IPI to complete. some of this is
from petrov.
- rename sparc64_ipi_{halt,pause,resume}_cpus() to
mp_{halt,pause,resume}_cpus()
- new function mp_cpu_is_paused() used to avoid access missing
saved DDB registers
- actually broadcast the flush in smp_tlb_flush_pte(),
smp_tlb_flush_ctx() and smp_tlb_flush_all(). the other end may
not do anything yet in the pte/ctx cases yet...
kgdb_machdep.c:
- rework for changed member names in db_regs_t.
locore.s:
- shave an instruction from syscall_setup() (set + ld -> sethi + ld)
- remove some old dead debug code
- add new sparc64_ipi_halt IPI entry point, it just calls the C
vector to shutdown.
- add new sparc64_ipi_pause IPI entry point, which just traps into
the debugger using the normal breakpoint trap. these cpus usually
lose the race in db_interface.c:db_suspend_others() and end up
calling the C vector sparc64_ipi_pause_thiscpu().
- add #if 0'ed code to sparc64_ipi_flush_{pte,ctx}() IPI entry
points to call the sp_ version of these functions.
- in rft_kernel (return from trap, kernel), check to see if the
%tpc is at the sparc64_ipi_pause_trap_point and if so, call
"done" not "retry"
- rework cpu_switch slightly: save the passed-in lwp instead of
using the one in curlwp
- in cpu_loadproc(), save the new lwp not the old lwp, to curlwp
- in cpu_initialize(), set %tl to zero as well. from petrov.
- in cpu_exit(), fix a load register confusion. from petrov.
- change some "set" in delay branch to "mov".
machdep.c:
- deal with function renames
pmap.c:
- remove a spurious space
trap.c:
- remove unused "trapstats" variable
- add cpu number to a couple of messages


# 1.214 09-Sep-2006 mrg

significant clean up effort, largely from petrov@ via martin@.

- fix a bunch of comments for proc->lwp
- remove old TRAPTRACE, NOT_DEBUG, etc. code that has bit-rotted
- put some older DEBUG code under NOT_DEBUG
- add a bunch of new debugging/tracing code ("KTR") that depends on
other changes not yet present.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base yamt-pdpolicy-base5 chap-midi-base simonb-timecounters-base rpaulo-netinet-merge-pcb-base
# 1.213 14-May-2006 elad

branches: 1.213.6; 1.213.8;
integrate kauth.


# 1.212 12-May-2006 skrll

Fix some comments.


Revision tags: elad-kernelauth-base
# 1.211 09-May-2006 rjs

Load CPCB in cpu_mp_startup.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.210 11-Feb-2006 cdi

branches: 1.210.2; 1.210.4; 1.210.6;
ANSIfication: u_intN_t -> uintN_t, use ANSI function declarations/definitions
instead of K&R ones.


# 1.209 27-Jan-2006 cdi

branches: 1.209.2; 1.209.4;
Alter sparc64 bootstrap, catch up to ofwboot v1.9:

- Accept bootinfo structure passed down from ofwboot v1.9
- Drop kernel re-mapping code
- Use permanent 4MB mappings provided by the loader instead
- Change kernel entry address to point directly at the code instead of pointing
at the trap table's first slot. This allows the bootloader to detect
those kernels which are aware of the new boot scheme
- Due to the changes in kernel mapping code, alter secondary CPU bootstrap
code to use trampoline just like FreeBSD does (some FreeBSD code is used
here as well)


# 1.208 12-Jan-2006 cdi

Fix a typo: %g0 should be used instead of %o0 when initializing FPU in dostart:
and cpu_mp_startup:, %o0 is not even initialized at this point.


# 1.207 11-Dec-2005 christos

branches: 1.207.2;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 1.206 10-Jul-2005 christos

Re-factor syscall, and make it use syscall_{plain,fancy}.


# 1.205 31-May-2005 chs

branches: 1.205.2;
remove vestigal {,e}intr{names,cnt} symbols now that vmstat doesn't need them.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.204 12-Feb-2005 chs

branches: 1.204.4; 1.204.6; 1.204.8;
in sparc_interrupt(), wait to enable interrupts until just before calling
the handler and disable them again right after the handler returns.
we don't want another hardware interrupt coming in while we're mucking
with the list pointers. also, clear the intrhand's ih_pending pointer
before calling the handler rather than after, so that if another interrupt
comes in while the handler is running, we can put the intrhand back on
the list so it will be called again.

in send_softint(), disable interrupts via %pstate instead of %pil, so that
hardware interrupts at higher levels are blocked while we manipulate the
intrpending list. also, if the intrhand already has ih_pending set,
don't bother poking the SET_SOFTINT register again, since being on the list
implies that there is already a softint pending in the hardware.

these appear to fix PR 21750 (the "sleep forever" problem).

while I'm here, remove more vestiges of the !INTRLIST softint stuff
(code and comments). and in sparc64_ipi_flush_all(), interrupts are
already disabled so we don't need to fiddle with %pstate.


Revision tags: yamt-km-base2
# 1.203 30-Jan-2005 martin

Remove the no long usefull variants selected by undefining INTRLIST and
INTR_INTERLOCK to improve readability. Same object code generated as before.


Revision tags: yamt-km-base
# 1.202 16-Jan-2005 chs

branches: 1.202.2;
use ENTRY_NOPROFILE() for various entry points,
stack traces work better that way.


Revision tags: kent-audio1-beforemerge kent-audio1-base
# 1.201 03-Dec-2004 chs

branches: 1.201.4;
remove cache_flush_virt() and PADDRT, they're no longer used.
allocate a stack frame for blast_dcache() when profiling so it shows up.
in dcache_flush_page(), use a stride of 32 instead of 16 to match the
cache line size. correct various comments.


# 1.200 08-Nov-2004 petrov

Don't compile sparc64_ipi functions when UP.


# 1.199 25-Oct-2004 martin

No need to clear %o1 when returning a 64 bit integer from pseg_get if we
are compiling for a 64 bit kernel.


# 1.198 24-Jul-2004 nakayama

Change interrupt pending list end value to -1, to avoid linking an
interrupt handler twice.

It may fix "sleep forever" bug.


# 1.197 09-Apr-2004 petrov

Clean-up unused defines and variables.


Revision tags: netbsd-2-0-base
# 1.196 26-Mar-2004 petrov

branches: 1.196.2;
Use want_resched from cpu_info area.


# 1.195 23-Mar-2004 martin

Replace intrcnts by evcnts. XXX - needs slight tweaking for MULTIPROCESSOR.


# 1.194 14-Mar-2004 chs

checkpoint of MP work from dennis and myself. includes cross-processor
interrupt framework, a sledgehammer TLB invalidation and misc MP fixes.
doesn't work at all yet.


# 1.193 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.192 19-Jan-2004 martin

Rename switchexit to cpu_exit and g/c the old C implementation of cpu_exit.


# 1.191 18-Jan-2004 martin

Support RAS for 32bit kernels too.


# 1.190 16-Jan-2004 martin

In proc_trampoline don't bother to clear condition codes in the trap
frame, since we no longer rely on this.
While there fix a few comments.


# 1.189 08-Jan-2004 martin

Minor cleanup


# 1.188 06-Jan-2004 martin

Implement restartable atomic sequences (RAS) for sparc64.


# 1.187 06-Jan-2004 petrov

Spinup secondary cpus. Based on codes sent to me by Dennis Chernoivanov
and Chuck Silvers.


# 1.186 04-Jan-2004 jdolecek

update to recent changes - exit2() doesn't exist anymore and the
exit path always calls lwp_exit2()
pointed out Martin Husemann


# 1.185 02-Dec-2003 martin

Minor cleanup: remove unused code, sync a comment with current reality.


# 1.184 25-Nov-2003 cdi

Use per-cpu pcb, curlwp and fplwp rather than global ones. This brings
GENERIC.MP configuration to a usable state.

Approved by petrov@.


# 1.183 24-Nov-2003 cdi

Call 'proc_trampoline_mp' from 'proc_trampoline' in a multiprocessor
configuration. Fix process locking. Approved by petrov@.


# 1.182 20-Nov-2003 petrov

Remove nwindows calculation, it's not used. Set l_cpu in cpu_switch.


# 1.181 09-Nov-2003 martin

Get rid of bcopy/bzero.


# 1.180 26-Oct-2003 christos

Initial siginfo support for sparc64 (untested). COMPAT_16 sigcontext signal
delivery tested.


# 1.179 24-Aug-2003 chs

add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default. the changes
fall into two basic catagories:

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

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

originally from openbsd, adapted for netbsd by me.


# 1.178 08-Jul-2003 cdi

traceit: don't use %g7 as it is to become curcpu() register. Add comments.


# 1.177 18-May-2003 martin

branches: 1.177.2;
Make kernels with options KGDB at least compile.
Still needs some work to make it working.


# 1.176 29-Apr-2003 nakayama

Use BLOCK_ALIGN rather than BLOCK_SIZE for aligning a pointer.


# 1.175 27-Apr-2003 ragge

Preserve the symbol table in the LKM || KSYMS cases also.


# 1.174 04-Apr-2003 petrov

use branch slot in pmap_copy_page.


# 1.173 24-Mar-2003 nakayama

Divide `set' instruction in delay slot (from OpenBSD change to rev 1.30).


# 1.172 10-Feb-2003 martin

Remove some #if 0 code and a few XXX marked membars w/o proper
justification for their existence.


# 1.171 09-Feb-2003 martin

Remove left over pieces from reusing the signal trampoline for upcalls.
This should fix signal delivery for 32bit kernels.


# 1.170 05-Feb-2003 nakayama

Switch to use cycle counter (%tick) based microtime().

This is derived from alpha/microtime.c and i386/tsc_microtime.c,
and will share with both ports.

This should fix PR port-sparc64/18452.
(approved by martin)


# 1.169 04-Feb-2003 martin

Fix return value of pseg_set, which I accidently broke in rev. 1.164.

Fix register names in comment and shave off another register (hint
from uwe).


# 1.168 01-Feb-2003 martin

Rearrange register usage in pseg_set a bit and shave off %g4.


# 1.167 01-Feb-2003 martin

Remove a few #ifdef _LP64 by using STPTR/LDPTR macros.
Thanks to Matthew Green for the pointer.


# 1.166 31-Jan-2003 martin

Apply leaf procedure optimization to pseg_set (again).


# 1.165 31-Jan-2003 martin

Make the pmap count resident/wired mappings on the fly instead of
walking the page tables whenever this information is needed.

Add an option PMAP_COUNT_DEBUG to assert the new counts and the
page table walk agree.

The old solution had very bad performance impact, for example
by the high CPU load when running top(1).

Thanks to Simon Burge for pointing at the cause of the problem and
to Valeriy E. Ushakov for optimizing my simple minded assembler code.


# 1.164 27-Jan-2003 martin

Remove unused function pseg_find (which looked quite similar to
pseg_get anyway).


# 1.163 18-Jan-2003 thorpej

Merge the nathanw_sa branch.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.162 16-Jan-2003 petrov

Move dump_dtlb back under DDB.


# 1.161 15-Jan-2003 chs

fix two bugs in my last pmap rework:
- in tlb_flush_all(), don't skip TLB entries with the high bit on,
I was confused about which MMU register it was using. it's also fine
to use the last hardware context.
- in pmap_create(), don't allocate a hardware context for the new pmap.
it's unnecessary, and when this would cause us to recycle all the contexts,
it would result in the current process's context being set to 0
(ie. the kernel's context). the current process could then return to
userspace without going through the context-switch code (and thus without
having a hardware context reallocated). this would lead to user mappings
being entered in the kernel's context later, causing all sorts of trouble.
add some assertions to catch this kind of thing.


Revision tags: fvdl_fs64_base
# 1.160 25-Dec-2002 petrov

new function dump_itlb.


Revision tags: gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.159 22-Sep-2002 chs

many improvements:
- use struct vm_page_md for attaching pv entries to struct vm_page
- change pseg_set()'s return value to indicate whether the spare page
was used as an L2 or L3 PTP.
- use a pool for pv entries instead of malloc().
- put PTPs on a list attached to the pmap so we can free them
more efficiently (by just walking the list) in pmap_destroy().
- use the new pmap_remove_all() interface to avoid flushing the cache and TLB
for each pmap_remove() that's done as we are tearing down an address space.
- in pmap_enter(), handle replacing an existing mapping more efficiently
than just calling pmap_remove() on it. also, skip flushing the
TSB and TLB if there was no previous mapping, since there can't be
anything we need to flush. also, preload the TSB if we're pre-setting
the mod/ref bits.
- allocate hardware contexts like the MIPS pmap:
allocate them all sequentially without reuse, then once we run out
just invalidate all user TLB entries and flush the entire L1 dcache.
- fix pmap_extract() for the case where the va is not page-aligned and
nothing is mapped there.
- fix calculation of TSB size. it was comparing physmem (which is
in units of pages) to constants that only make sense if they are
in units of bytes.
- avoid sleeping in pmap_enter(), instead let the caller do it.
- use pmap_kenter_pa() instead of pmap_enter() where appropriate.
- remove code to handle impossible cases in various functions.
- tweak asm code to pipeline a little better.
- remove many unnecessary spls and membars.
- lots of code cleanup.
- no doubt other stuff that I've forgotten.

the result of all this is that a fork+exit microbenchmark is 34% faster
and a fork+exec+exit microbenchmark is 28% faster.


Revision tags: gehenna-devsw-base
# 1.158 18-Jul-2002 wiz

Spell 'should' correctly.


# 1.157 07-Jun-2002 eeh

Shave 10% off the time needed to flush the D$ through a bit of instruction
reordering.


# 1.156 05-Jun-2002 eeh

Handle improperly aligned stack pointers more cleanly.


# 1.155 04-Jun-2002 eeh

Fix the fork trampoline to properly use the supplied tstate.


# 1.154 31-May-2002 thorpej

Make this work with an ISO C preprocessor.


Revision tags: netbsd-1-6-base
# 1.153 14-May-2002 eeh

branches: 1.153.2; 1.153.4;
Only save locals and ins in trapframes for DEBUG kernels.


# 1.152 04-May-2002 kleink

Add some comments to the CPP conditionals controlling the trap macro
definitions, to ease navigation somewhat.


# 1.151 16-Apr-2002 eeh

Make lots of routines profile-friendly and get rid of some cruft.


Revision tags: eeh-devprop-base
# 1.150 21-Mar-2002 petrov

Not needed debug stuff deleted.


# 1.149 16-Mar-2002 mrg

tell newer binutils that our use of %g2 and %g3 is OK here.


# 1.148 15-Mar-2002 eeh

Cleanup MMU initialization to prevent hangs.


Revision tags: newlock-base ifpoll-base
# 1.147 09-Feb-2002 eeh

branches: 1.147.4;
Fix microsecond calculation in microtime.


# 1.146 07-Feb-2002 eeh

Fix register allocation in microtime().


# 1.145 29-Jan-2002 eeh

Shift the UPAID in the correct direction.


# 1.144 17-Jan-2002 eeh

Be more tolerant of unaligned stack pointers.


# 1.143 17-Jan-2002 eeh

Enable block insns in bcopy and bzero.


# 1.142 16-Jan-2002 eeh

In bcopy use 32-bit comparisons in 32-bit kernels.


# 1.141 16-Jan-2002 eeh

Use correct calculation for the trapframe in softtrap for ILP32.


# 1.140 20-Nov-2001 lukem

- pull in opt_kgdb.h where necessary
- replace opt_kgdb_machdep.h with opt_kgdb.h
- defparam opt_kgdb.h:
KGDB_DEV KGDB_DEVNAME KGDB_DEVADDR KGDB_DEVRATE KGDB_DEVMODE
- move from opt_ddbparam.h to opt_ddb.h:
DDB_FROMCONSOLE DDB_ONPANIC DDB_HISTORY_SIZE DDB_BREAK_CHAR SYMTAB_SPACE
- replace KGDBDEV with KGDB_DEV
- replace KGDBADDR with KGDB_DEVADDR
- replace KGDBMODE with KGDB_DEVMODE
- replace KGDBRATE with KGDB_DEVRATE
- use `9600' instead of `0x2580' for 9600 baud rate
- use correct quotes for options KGDB_DEVNAME="\"com\""
- use correct quotes for options KGDB_DEV="17*256+0"
- remove unnecessary dependancy on Makefile for kgdb_stub.o
- minor whitespace cleanup


Revision tags: thorpej-mips-cache-base thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf
# 1.139 14-Sep-2001 thorpej

branches: 1.139.4;
Don't declare intrhand[] here -- that's taken care of in intr.c.


Revision tags: thorpej-devvp-base
# 1.138 30-Aug-2001 eeh

branches: 1.138.2;
Preliminary UltraSPARC III suport (not enabled yet).


# 1.137 13-Aug-2001 jdolecek

g/c _remque()/_insque(); use the C version in libkern


# 1.136 09-Aug-2001 eeh

Fix context masking lossage caused by last version.


# 1.135 08-Aug-2001 eeh

Clean up the trap code to handle the changes cause by supporting non-faulting
accesses. Also change the parameter order so trap frames are easy to find.


# 1.134 07-Aug-2001 eeh

Make sure C code always has ASI_PRIMARY_NOFAULT in the %asi register so
the compiler will be happy if it ever starts generating speculative loads.


# 1.133 05-Aug-2001 eeh

Add support for non-faulting loads and optimize MMU miss handling paths.


# 1.132 02-Aug-2001 eeh

Fix bcopy.


# 1.131 02-Aug-2001 eeh

Sync bzero w/libc version.


# 1.130 01-Aug-2001 eeh

Integrate fixes from userland memset.


# 1.129 31-Jul-2001 eeh

Code cleanup and optimization.


# 1.128 23-Jul-2001 eeh

Get rid of some debug code that really isn't all that useful any more.


# 1.127 19-Jul-2001 eeh

Do ignore unregistered interrupts instead of faulting.


# 1.126 16-Jul-2001 eeh

Make bcopy a 32-bit friendly.


# 1.125 11-Jul-2001 eeh

Fix problems booting 32-bit kernels and dispatching level-15 interrupts.


# 1.124 08-Jul-2001 eeh

branches: 1.124.2;
Code cleanup. Add block_disable to let you turn on block set/copy routines.


# 1.123 05-Jul-2001 eeh

New block bzero and bcopy.


# 1.122 04-Jul-2001 eeh

Replace old bcopy with a much faster version.


# 1.121 01-Jul-2001 martin

Disable axidently enabled debug code to make -current compile again.


# 1.120 30-Jun-2001 eeh

Use a newer version (still disabled) of block bcopy.


# 1.119 30-Jun-2001 eeh

Fixup fpu save restore, get rid of some unused copy functions, and add
a new bcopy.


# 1.118 21-Jun-2001 eeh

Allow multiple 4MB pages for both kernel text and kernel data.

Note: DEBUG checks will not allow accesses to the hole between
text and data segments, so you may need to update programs that
use libkvm before relocating the start of kernel data.


# 1.117 06-Jun-2001 mrg

extract the netbsd32, sunos, 32 bit svr4 and 64 bit svr4 sigcode out into
separate files, so that compat lkms can link with them as well.


# 1.116 30-May-2001 lukem

add missing #include "opt_kgdb.h"


Revision tags: thorpej_scsipi_beforemerge
# 1.115 25-Apr-2001 simonb

Spell occurred correctly.


Revision tags: thorpej_scsipi_nbase thorpej_scsipi_base
# 1.114 09-Apr-2001 eeh

Interrupt latency fix from sparc port. (Hm. One insn instead of 5).


# 1.113 07-Mar-2001 eeh

Fix inverted preprocessor logic. (Spotted by Charles.)


# 1.112 21-Feb-2001 eeh

branches: 1.112.2;
Add support for 64-bit SVR4 (Solaris 8) binaries.


# 1.111 10-Feb-2001 pk

Fix conditional for svr4 compat inclusion.


# 1.110 05-Feb-2001 eeh

Add signal trampoline for 64-bit svr4 emulations.


# 1.109 31-Dec-2000 eeh

Make INCR() atomic.


# 1.108 29-Dec-2000 eeh

pseg_get tells us whether it really needed that spare page after all.


# 1.107 07-Dec-2000 eeh

Fixup calculating where fpstate should be saved in the signal trampoline
code so it doesn't overwrite something important like the registers.


# 1.106 09-Nov-2000 eeh

Fix ILP32 bug in probe_get().


# 1.105 22-Oct-2000 pk

Restore revision 1.102.

I hope it sticks this time..


# 1.104 20-Oct-2000 eeh

Fix hang in 32-bit kernels caused by relocation of KERNBASE.


# 1.103 04-Oct-2000 eeh

Fix interrupt lossage problem and some cosmetic changes.


# 1.102 01-Oct-2000 pk

cpu_initialize: global registers aren't preserved across calls to
prom_printf(), so replace %g3 with %l7 (which isn't used despite
the `usage' comment).

Also, clean up white-space turds.


# 1.101 29-Sep-2000 eeh

This seems to fix the interrupt lossage of non-debug kernels.


# 1.100 28-Sep-2000 eeh

Fix INTR_SETUP() to properly distinguish kernel and user addresses.

Make microtime() return the correct time on %tick machines.

Re-enable debug stuff in dostart for now to detect kernel mapping issues.


# 1.99 25-Sep-2000 pk

Missing `#if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)'


# 1.98 17-Sep-2000 eeh

Make the improved %tick changes work with machines that use the counter-timer
for the clock.


# 1.97 12-Sep-2000 eeh

Fix new version of microtime.


# 1.96 11-Sep-2000 eeh

(Hopefully) fix clock skew on machines that us %tick for the clock (UIIi).


# 1.95 31-Aug-2000 eeh

Use casx instead of stx to change entries in the page table trees.


# 1.94 23-Aug-2000 eeh

Update the scheduler to the new locking scheme.


# 1.93 10-Aug-2000 eeh

Fix signal delivery.


# 1.92 02-Aug-2000 eeh

Get kernel profiling to work. Now if only gprof worked....


# 1.91 01-Aug-2000 eeh

Overhaul cache flush code and coredump code.


# 1.90 25-Jul-2000 pk

Re-instate a couple of delay slot NOPs marked `XXX spitfire bug?'


# 1.89 24-Jul-2000 mycroft

Optimization to pmap_zero_page(): we only need to use the first 16 FP regs,
as in bzero().


# 1.88 24-Jul-2000 mycroft

Fix a whitespace glitch.


# 1.87 24-Jul-2000 mycroft

Pull in the bzero() changes from libc for real, with a couple of kernel-
specific hacks:
* Make the bias handling depend on STKB, so it switches correctly for 32-bit
kernels.
* Use the 32-bit stw/ld for 32-bit kernels.
* Add a few `-STKB's that were missed in the previous change.


# 1.86 24-Jul-2000 pk

Cosmetic & readability:
- local label cleanup in interrupt handling code;
- in debugging sections when testing `intrdebug': use a unique
local label (97) to enhanced clarity;
- comment-out unused code;
- kill a bug as the satisfying result of doing all of the above.


# 1.85 24-Jul-2000 eeh

Fix stack issues in bzero.


# 1.84 24-Jul-2000 mycroft

Revert the previous change for now. I don't have time to debug it tonight.


# 1.83 23-Jul-2000 mycroft

Copy bzero change from libc.


# 1.82 20-Jul-2000 pk

Since `intrcnt' points to an array of long ints, reserve the appropriate
amount of space depending on _LP64. Provide macros to load/store signed
and unsigned long ints.

Also, make the `intrcnt' and `intrpending' arrays 16 entries long, as on
sparc/v9 interrupt #15 is just a regular interrupt.


# 1.81 19-Jul-2000 eeh

Fix merge problem.


# 1.80 19-Jul-2000 eeh

Disable interrupt interlock using ih->ih_pending field. Seems to cause
more problems than it solves.


# 1.79 19-Jul-2000 eeh

Miscellaneous cleanup.


# 1.78 18-Jul-2000 pk

Correct args usage comment in probeget.
Whitespace cleanup.


# 1.77 18-Jul-2000 pk

probeget: 9 -> 0x9


# 1.76 18-Jul-2000 pk

If `ih_pending' is set simply return from the trap, don't schedule another
soft interrupt.


Revision tags: mrg-merge-1-5-top
# 1.75 18-Jul-2000 pk

openfirmware: don't lower %pil


# 1.74 17-Jul-2000 pk

Kill typos in interrupt code.


# 1.73 17-Jul-2000 pk

probeget: do the same song and dance as ld*a() macros in ctlreg.h do.


# 1.72 14-Jul-2000 eeh

Move some macro definitions out of genassym and into locore.s


# 1.71 08-Jul-2000 mrg

backout part of previous: turn off intrdebug, and another debug message


# 1.70 07-Jul-2000 pk

Changes for readability:
- #define LP64 dependent STACKFRAME macro once
- use a LOAD_ASCIZ macro for setting up the format string
for debug messages.


# 1.69 07-Jul-2000 eeh

Temporary fix to prevent the clock from stopping on UIIi machines.


# 1.68 03-Jul-2000 eeh

Prevent interrupts from being posted if they are active and deprecate polled
interrupts. This seems to eliminate the spurious interrupts.


# 1.67 02-Jul-2000 eeh

Clean up interrupt handling some more.


# 1.66 30-Jun-2000 eeh

Fix interrupt delivery on UltraSPARC IIi machines.


# 1.65 24-Jun-2000 eeh

With these changes the kernel seems almost stable again.


# 1.64 24-Jun-2000 eeh

More VM cleanup:

Move the cpu_info structure above the interrupt stack so it won't
get corrupted if the stack overflows.

Flush the D$ before and after all MMU bypass accesses since the
D$ latches all of those.


# 1.63 23-Jun-2000 eeh

Make probeget() and probeset() really work for a change.


Revision tags: netbsd-1-5-base
# 1.62 19-Jun-2000 eeh

branches: 1.62.2;
Have separate data and text segments, make text read-only.


# 1.61 12-Jun-2000 eeh

Start reorganizing the kernel for MULTIPROCESSOR support.


# 1.60 31-May-2000 thorpej

Add a comment about needing to initialize p_cpu when multiple
processors are supported.


Revision tags: minoura-xpg4dl-base
# 1.59 26-May-2000 thorpej

branches: 1.59.2;
First sweep at scheduler state cleanup. Collect MI scheduler
state into global and per-CPU scheduler state:

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

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

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

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

Tested on i386 and Alpha. Changes are mostly mechanical, but apologies
in advance if it doesn't compile on a particular platform.


# 1.58 26-May-2000 thorpej

Don't set `runtime' here; it's done at the end of mi_switch().
cvS: ----------------------------------------------------------------------


# 1.57 26-May-2000 thorpej

Introduce a new process state distinct from SRUN called SONPROC
which indicates that the process is actually running on a
processor. Test against SONPROC as appropriate rather than
combinations of SRUN and curproc. Update all context switch code
to properly set SONPROC when the process becomes the current
process on the CPU.


# 1.56 22-Apr-2000 eeh

If we trap due to a bad kernel stack, try to switch to the interrupt strack
before breaking into the debugger.


# 1.55 18-Apr-2000 eeh

Prevent the system from getting watchdog reset by returning directly to user
mode if restoring the user window traps. Also reduce the time we run with
%tl>0.


# 1.54 13-Apr-2000 eeh

Apparently gas 2.9.5 (don't ask) does not like to add values to %lo()
directives so move the additions inside %lo() to make it happy.
Hopefully this won't break older versions.


# 1.53 10-Apr-2000 mrg

- fix a speeling error
- rename some numbered labels to be a bit less confusing.
- remove dead code
- fix a debug error message (argh!)


# 1.52 10-Apr-2000 pk

Get a kernel without DDB to build.


# 1.51 16-Mar-2000 eeh

Revamp interrupts again:

Fix a bug causing interrmittent panics in interrupt dispatch.
Use interrupt vectors for softints.
Add a new send_softint interface.
Improved D$ flushing.
Improve traptrace and other debugging enhancements.


Revision tags: chs-ubc2-newbase
# 1.50 16-Jan-2000 eeh

Interrupt handlers return zero if they didn't handle the interrupt.


# 1.49 10-Jan-2000 eeh

Add debugger single-stepping and fix interrupt dispatch bugs.


# 1.48 30-Dec-1999 eeh

Lots of changes:

remove ffs()
add bzero that uses block store insns
save %gsr to fpstate
revert to physical accesses for pmap_zero_page so we don't
have conflicting page mappings
general cleanup.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base fvdl-softdep-base
# 1.47 06-Nov-1999 eeh

Handle zero length properly in copyinstr() copyoutstr() and copystr().


Revision tags: comdex-fall-1999-base
# 1.46 11-Oct-1999 eeh

branches: 1.46.2; 1.46.4;
Update to post 1.4.


# 1.45 05-Oct-1999 eeh

branches: 1.45.2;
Make broken versions of gas happy by using sethi/or instead of set for
(negative) addresses.


# 1.44 17-Sep-1999 thorpej

Centralize the declaration and clearing of `cold'.


Revision tags: chs-ubc2-base
# 1.43 18-Jul-1999 eeh

More fun with pmap.


# 1.42 21-Jun-1999 eeh

Improve TRAPTRACE. Add FLTRACE that only tracks MMU faults.


# 1.41 05-Jun-1999 eeh

Make pbrobeget() and probeset() work for 64-bit values as well. To do this
the arguments are changed so the address is first and the ASI second so we
can have the address in %o0:%o1 and not worry about unused registers.

Also a bit of copyright cleanup.


# 1.40 05-Jun-1999 mrg

update a commit slightly.


# 1.39 30-May-1999 eeh

Add code to support using %tick as the system clock if no "counter-timer" node
is found.


# 1.38 09-May-1999 eeh

Fixup non-DEBUG kernels.


# 1.37 29-Apr-1999 christos

Add sunos_sigcode (32 bit only)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.36 26-Mar-1999 eeh

branches: 1.36.4;
COMPAT_SPARC32 -> COMPAT_NETBSD32


# 1.35 25-Mar-1999 mrg

clean and up make compile


# 1.34 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.33 22-Mar-1999 eeh

Need to set up the pointers properly for partial FPU register stores.


# 1.32 22-Mar-1999 eeh

Flush D$ on bypass accesses.


# 1.31 28-Feb-1999 eeh

Use block load/store in pmap_zero_page()/pmap_copy_page().


# 1.30 17-Feb-1999 eeh

Let's test out vectored interrupts.


# 1.29 15-Feb-1999 hubertf

RCS ID police


# 1.28 11-Feb-1999 mrg

fix a comment pasto.


# 1.27 11-Jan-1999 eeh

Finally fixed 64-bit signal trampoline.


# 1.26 10-Jan-1999 eeh

Handle the symbol table properly in a 32-bit kernel that was booted from a
64-bit bootloader.


# 1.25 09-Jan-1999 eeh

More signal fixup.


Revision tags: kenh-if-detach-base
# 1.24 26-Nov-1998 mycroft

Sync kcopy() with 32-bit SPARC version.


# 1.23 16-Nov-1998 eeh

Fixup the last broken bits of the signal handling code.


Revision tags: chs-ubc-base
# 1.22 08-Oct-1998 eeh

Fix more syscall32 and signal breakage.


# 1.21 22-Sep-1998 eeh

More fixup in the signal area.

64-bit syscall cleanup.

Add emulation for some new FPU insns: conversion to 64-bit long int and
conditional moves.


# 1.20 17-Sep-1998 thorpej

SYS_sigreturn -> SYS___sigreturn14.


# 1.19 13-Sep-1998 eeh

Fixup signal changes (hopefully). However SUN_COMPAT is likely broken by
this and I don't know how to fix it.

We can now exec a 64-bit init through a really ugly hack (don't ask.)


# 1.18 11-Sep-1998 eeh

Add labels for the compat_sparc32 signal trampoline and break -- er -- fix
suword and fuword.


# 1.17 09-Sep-1998 eeh

Don't use %tick for microtime on 32-bit kernels -- breaks gettimeofday.


# 1.16 09-Sep-1998 thorpej

Adjust for the new "reaper" kernel thread: do not free the vmspace and
u-area in machine-dependent code. Instead, call exit2() to schedule
the reaper to free them for us, once it is safe to do so (i.e. we are
no longer running on the dead proc's vmspace and stack).


# 1.15 07-Sep-1998 eeh

Fix data corruption problem caused by broken debug code.


# 1.14 07-Sep-1998 eeh

Add new 64-bit trap vectors.


# 1.13 06-Sep-1998 eeh

32-bit fixup.


# 1.12 06-Sep-1998 eeh

Disable some debug stuff.


# 1.11 05-Sep-1998 eeh

It slices. It dices. It does everything except exec a sparc32_compat init.


# 1.10 02-Sep-1998 eeh

Periodic update: now starts probing devices.


# 1.9 30-Aug-1998 eeh

Some more 64-bit cleanup. Now everything compiles.


# 1.8 29-Aug-1998 eeh

Some more 64-bit-ification.


# 1.7 27-Aug-1998 eeh

Add 64-bit pmap support:

Moved from a two level 512/1024 entry setup mapping 32 (9/10/13) bits
respectively to a three level 1024/1024/1024 entry setup mapping 43
(10/10/10/13) bits. In 32-bit mode we waste about 1/12 pages mapping the high
11 bits. We also only manage 43 of the possible 44 bits of virtual address
space, wasting half of it. Oh well, maybe we'll do better next revision.


Revision tags: PMAP32
# 1.6 26-Aug-1998 mrg

panicstack: is needed outside of DEBUG. use _C_LABEL, and printf not db_printf (incase no ddb!)


# 1.5 13-Aug-1998 eeh

Merge paddr_t changes into the main branch.


Revision tags: eeh-paddr_t-base
# 1.4 07-Jul-1998 eeh

branches: 1.4.2;
General update:

Added genassym.cf
Removed lderr which should never have gotten in
Removed lots of dead code from locore.s
Added some softint stuff to intr.c
Added support for halt -p
esp and le both use bus_dmamap_*() functions now
instead of kdvma_mapin()
groundwork for PCI (but we still have no drivers for
any sun4u PCI devices)


# 1.3 04-Jul-1998 jonathan

defopt DDB.


# 1.2 26-Jun-1998 thorpej

defopt COMPAT_SVR4


# 1.1 20-Jun-1998 eeh

branches: 1.1.1;
Initial revision


Revision tags: prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1
# 1.410 18-Apr-2017 palle

sun4v: Add handling of trap 0x06c @ trap level 1 - based on code from OpenBSD, but slightly adapted to NetBSD. verified using qemu


Revision tags: jdolecek-ncq-base pgoyette-localcount-20170320
# 1.409 19-Feb-2017 palle

sun4v: rft_user needs special handling (a manual fill) since the restore instruction may cause the number of trap levels to exceed the maximum for sun4v - inspired by code from the the openbsd rft_user code path - verified using qemu for both sun4u and sun4v


# 1.408 10-Feb-2017 palle

sun4v: Added handling of trap type 0x034 (address alignment error) + fixed typo mmfsa -> mmufsa. Verified for both sun4u and sun4v using qemu.


Revision tags: nick-nhusb-base-20170204
# 1.407 30-Jan-2017 palle

sun4v: Hook up syscall handling to the trap table. Verified using qemu for both sun4u and sun4v.


# 1.406 27-Jan-2017 palle

sun4v: implement missing handling of itsb traps 0x008 and 0x009. Based on code from OpenBSD. Tested using qemu.


Revision tags: bouyer-socketcan-base
# 1.405 07-Jan-2017 palle

branches: 1.405.2;
sun4v: slowtrap() now selects normal globals properly on both sun4u and sun4v platforms. Verified using qemu for both sun4u and sun4v systems


Revision tags: pgoyette-localcount-20170107
# 1.404 05-Jan-2017 palle

sun4v: TRAP_SETUP() updated to set mmu context id properly for both sun4v and sun4u platforms. Verified using qemu for both sun4u and sun4v systems


# 1.403 04-Jan-2017 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x00-0x23 and 0x28-0x30


# 1.402 29-Dec-2016 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x32-0x7f


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.401 20-Sep-2016 nakayama

Fix RAS for 32-bit kernels. trapframe is always 64-bit.


Revision tags: localcount-20160914
# 1.400 23-Aug-2016 palle

sun4v: rework sun4v_datatrap so it works properly when running on a T2-based system like T5120 - for some reason %tl is 0 when entering sun4v_datatrap causing a crash (sir instruction), so ignore the %tl value for now upon entry to sun4v_datatrap - with this fix both T1 and T2 based systems reach the same point - hangs in rft_user after the init process is started


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726
# 1.399 18-Jul-2016 palle

sun4v: handle device interrupts properly - both legacy (sysino) and cookies


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 1.398 04-Jun-2016 palle

branches: 1.398.2;
sun4v: rtf_user now uses macros GET_MMU_CONTEXTID and SET_MMU_CONTEXTID. Tested on sun4u (QEMU) and sun4v (T2000). Parts from OpenBSD.


Revision tags: nick-nhusb-base-20160529
# 1.397 18-May-2016 nakayama

Decrement %tl in trap handler not to make it zero unconditionally
for the nested trap, and remove useless mov.


# 1.396 17-May-2016 palle

sun4v: Implement missng MMU protection trap handling - mostly from OpenBSD


# 1.395 16-May-2016 palle

Avoid assembler-specific defines by using the export keyword in genassym.cf instead


# 1.394 15-May-2016 nakayama

%g1 is not preserved across function call, so load it before
return_from_trap.


# 1.393 13-May-2016 palle

sun4v: add missing implementation of sun4v_datatrap_tl0 so data_access_fault() is called - mostly from OpenBSD


# 1.392 13-May-2016 nakayama

- ci_paddr is always 64-bit.
- intrlev is array of pointer.
- ih_ack is pointer.


# 1.391 10-May-2016 palle

sun4v: make device interrupts work. Introduce a new intrhand_alloc() function for allocation of interrupt handlers and adapt to this. Parts from OpenBSD. ok martin@


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.390 09-Mar-2016 nakayama

32-bit kernels use 32-bit stack.


# 1.389 03-Mar-2016 palle

sun4v: rft_kernel should pay attention to the number of register windows that can be restored. We cannot rely on fill traps to occur, since sun4v only has two trap levels available in privileged mode. Based on code from OpenBSD. ok martin@


# 1.388 14-Feb-2016 palle

sun4v: add breakpoint trap entry to the sun4v trap table


# 1.387 03-Feb-2016 palle

sun4v: extend dmmu_set_secondary_context() to handle both sun4u and sun4v. ok martin@


Revision tags: nick-nhusb-base-20151226
# 1.386 06-Nov-2015 martin

Basically revert r1.246 of locore.s and r1.73 of vm_machdep.c:

Remove special case handling for userland lwps from cpu_lwp_fork,
instead do it in lwp_trampoline when we first return to userland.

which was a stupid idea - since we did now set all fork child's %tstate
(and thus %pstate when back in userland) to the current kernel's userland
default. This meant we lost the address mask bit for 32bit processes and
all memory model details for 64bit ones.

Move it back to cpu_lwp_fork and fix the condition to only do it once when
forking init.


# 1.385 05-Nov-2015 martin

Most of the time return_from_trap already got called with tf->tf_tstate
loaded in register %g1 - make it so for two more callers and remove
the reload of that value.


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606 nick-nhusb-base-20150406
# 1.384 05-Apr-2015 palle

sun4v: Ensure that the TTEs CP and CV bits are the same (both set) for the primary cpu and secondary cpus INTSTACK mappings


# 1.383 01-Apr-2015 palle

sun4v: Implement handling of cpu_mondo trap - from OpenBSD - tested using the Legion simulator


# 1.382 04-Mar-2015 palle

sun4v: revert some of the logic introduced in revision 1.378 - flushw is not necessary on sun4v (OpenBSD patches the flushw instruction to a nop instruction) - with these changes the kernel reaches cpu_boot_secondary_processors() when running in the Legion simulator (crashes due to missing handling of cpu_mondo_trap)


# 1.381 02-Mar-2015 nakayama

prom_printf converts "\n" to "\r\n" internally, so omit "\r".


# 1.380 02-Mar-2015 nakayama

PANICSTACK is a pointer itself, not a pointer to pointer.


# 1.379 02-Mar-2015 nakayama

Use panic stack temporarily for calling prom_printf in a trap
handler.

It seems that openfirmware cannot handle over 4GB pointers, and
stack pointers may point to over 4GB since VA layout was rearranged
by rev 1.33 of vmparam.h. Therefore, use panic stack to avoid
panicking in OF_write used by prom_printf.


# 1.378 23-Feb-2015 palle

sun4v: sparc_interupt - ensure that the trap level and globals level are the same when the flushw instruction is issued - othwise warnings occur when using the sun4v Legion simulator.


Revision tags: nick-nhusb-base
# 1.377 26-Oct-2014 palle

branches: 1.377.2;
sun4v: Create CLEANWIN0 and CLEANWIN1 macros for handling clean window traps on both sun4u and sun4u (based on the original code inlined in the sun4u trap table). Update trap tables accordingly for both sun4u and sun4v. Ok martin@


# 1.376 24-Oct-2014 nakayama

Fix typo in comment.


# 1.375 18-Oct-2014 snj

src is too big these days to tolerate superfluous apostrophes. It's
"its", people!


# 1.374 15-Oct-2014 palle

sun4v: fixed bug causing the real address to be incorrectly calculated as zero


# 1.373 24-Sep-2014 palle

sun4v: add code to enable startup of secondary cpus on both sun4u and sun4v systems - ok martin@


# 1.372 04-Sep-2014 palle

sun4v: All cpus must be setup with a TSB descriptor, so pmap_setup_tsb_sun4v() must take a pointer to the TSB descriptor


# 1.371 31-Aug-2014 palle

sun4v: Split the NORMAL_GLOBALS and ALTERNATE_GLOBALS macros to _SUN4U and _SUN4V variants. Rework the return_from_trap logic to use the new variants so it is possible to use a global register as scratch register.


# 1.370 14-Aug-2014 nakayama

Add missing delay slot in DEBUG kernel.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.369 30-Jul-2014 palle

branches: 1.369.2;
Fix ALTERNATE_GLOBALS so it at least works on sun4u - using a scratch register is not a good idea...


# 1.368 27-Jul-2014 palle

sun4v: Introduce a new macro ALTERNATE_GLOBALS (matching NORMAL_GLOBALS). Two new helper macros ENABLE_INTERRUPTS and DISABLE_INTERRUPTS are also created. With these changes the GENERIC.UP kernel will reach rootmount on sun4v systems - ok martin@


# 1.367 26-Jul-2014 palle

Improved the NORMAL_GLOBALS macro in the sun4u case, so only the relevant bit (AG) in %pstate is affected - ok martin@


# 1.366 24-Jul-2014 palle

sun4v: add missing spill/fill handling for trap level 1 + cosmetic changes to comments for trap level 0 entries


# 1.365 19-Jul-2014 palle

sun4v: Introduce a NORMAL_GLOBALS macro - first used in sparc_interrupt - other relevant uses will be handled as the sun4v work is progressesing - ok martin@


# 1.364 16-Jul-2014 palle

sun4v: Introduce SET_MMU_CONTEXTID macro for setting the mmu context id on both sun4u and sun4v


# 1.363 13-Jul-2014 palle

sun4v: add interrupt handling to sun4v trap table


# 1.362 13-Jul-2014 palle

Bugfix: add missing cmp instruction to GET_MAXCWP macro


# 1.361 30-Jun-2014 palle

sun4v: The maximum number of register windows is a constant and thus not available via the %ver register (sun4u only). Introduce a macro GET_MAXCWP that handles this, so cpu_switchto() works properly on sun4v. Other relevant reference to %ver can be adapted to use GET_MAXCWP as the sun4v port progresses. OK martin@


# 1.360 31-May-2014 palle

sun4v: added missing dtsb miss handling for trap level 1 - with this update the kernel now reaches configure() on sun4v systems


# 1.359 30-May-2014 palle

Remove debugging code introduced by accident in locore.s revision 1.357


Revision tags: yamt-pagecache-base9 rmind-smpnet-nbase rmind-smpnet-base
# 1.358 05-May-2014 palle

sun4v: the trap base address should be assigned to %l1 so %tba is properly setup later in the code - now the kernel gets as far as printing the copyright disclaimer, kernel version and total and available memory before crashing


# 1.357 21-Apr-2014 palle

sun4v: Update comment: modified -> access


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.356 21-Feb-2014 palle

branches: 1.356.2;
sun4v: Rename TLB_ defines to SUN4U_TLB_ so entries created using TSB_DATA() are properly setup for sun4u and sun4v. Relocate the cputyp variable from autoconf.c to locore.s and make it const in param.h so optimized code can be generated. Parts from OpenBSD. Optimization suggested by nakayama@. OK martin@, mrg@, nakayama@


# 1.355 31-Jan-2014 tsutsui

defined(LKM) -> defined(MODULAR)


# 1.354 26-Jan-2014 palle

sun4v: Add handling of spill/fill and dtsb miss traps (with a XXX to be handled later)


# 1.353 07-Jan-2014 palle

sun4v: trap table setup - currently populated with dummy entries which will be properly implemented later - parts from OpenBSD - OK martin@


# 1.352 29-Dec-2013 nakayama

Make buildable w/o options SUN4V.


# 1.351 27-Dec-2013 palle

a) make the hunt through the cpus list more generic b) sun4v: ensure that the interrupt stack is mapped permanently and the TSB is setup properly - parts from OpenBSD. OK martin@


# 1.350 06-Dec-2013 nakayama

Increase an interrupt depth only in the case of hardware interrupts,
and remove the ci_idepth trick in softint_fastintr.

Fixes the following diagnostic panic reported in port-sparc64.

panic: kernel diagnostic assertion "!cpu_intr_p()" failed: file
"../../../../kern/subr_xcall.c", line 351


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 1.349 24-May-2013 nakayama

branches: 1.349.2;
Disable interrupts after calling data_access_error as with
data_access_fault.


# 1.348 28-Apr-2013 nakayama

Use macros in machine/asm.h instead of locally defined, and
introduce CASPTRA for casxa/casa.


Revision tags: agc-symver-base
# 1.347 23-Jan-2013 martin

Fix sparc64_ipi_ccall by adding proper trap setup.
Fixes xcall(9) problems, as exposed by pserialize(9). Noticed by
J. Hannken-Illjes, cause pointed out by Takeshi Nakayama.


# 1.346 23-Jan-2013 martin

Sligthly clean up the (by default unused) #ifdef TRAPS_USE_IG


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.345 10-Nov-2012 nakayama

Revise comment.


# 1.344 10-Nov-2012 nakayama

Use macro instead of magic number.


# 1.343 09-Nov-2012 nakayama

Make setstick() and getstick() to inline functions.


# 1.342 08-Nov-2012 macallan

use system tick timer instead of %tick on UltraSPARC-III-ish CPUs
review & fixes by Takeshi Nakayama


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.341 17-Mar-2012 mrg

branches: 1.341.2;
port the corrected ECC error handling code from freebsd. i noticed my U10
took one of these and then hang. it shouldn't hang, there's a 'sir' here that
doesn't seem to reset properly. oh well.

tested by simulated a trap via 'ta 0x10' and considering that the same, but
it hasn't been tested against a real ECC error yet.


Revision tags: jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base4
# 1.340 03-Mar-2012 nakayama

Fix the root cause of the hack "disable optimizations for uvm_bio.c
on 32 bit kernels".

gcc converts a division in the calculation of UBC_UMAP_ADDR macro
to multiplication (smul or combination of add/sll), and the
register of its result contains a garbage in upper 32 bits (the
upper 32 bits of smul/add/sll's result isn't zero cleared).

Then it passes to pseg_get{,_real} through pmap_extract without the
zero clear of upper 32 bits in the optimization case. So the
result of pseg_get and pmap_extact sometimes gets screwed up.


Revision tags: jmcneill-usbmp-base5 jmcneill-usbmp-base3
# 1.339 19-Feb-2012 rmind

Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.


Revision tags: jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.338 04-Sep-2011 nakayama

branches: 1.338.2; 1.338.6; 1.338.8;
ih_pil is an interrupt level, not an interrupt mask.


# 1.337 27-Jul-2011 nakayama

ivec is assigned to hardware, so count its event counter up in
interrupt_vector, not in softint, and do some optimization.


# 1.336 20-Jul-2011 macallan

add per ivec event counters


# 1.335 12-Jul-2011 mrg

rename sparc64 BLOCK_SIZE and BLOCK_ALIGN to have SPARC64_ prefixes.
for the assembler files, define the old names to the new names
since using the new names cause ugliness due to longer identifer
names, and reduces churn.

fixes build issues in dtv and vaguely makes <machine/psl.h> slightly
less name-space invasive.


# 1.334 18-Jun-2011 nakayama

Add fast softint(9) support for sparc64.

Reviewed on port-sparc64.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 1.333 12-May-2011 mrg

branches: 1.333.2;
first steps towards fujitsu SPARC64 support:

- SPARC64 systems have interrupts with upto 14 bits set, but we only look
at the first 11 bits. trim non IPI interrupts to 11 bits


Revision tags: uebayasi-xip-base7 bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 jym-xensuspend-nbase jym-xensuspend-base
# 1.332 20-Dec-2010 matt

branches: 1.332.2;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.


Revision tags: uebayasi-xip-base6 uebayasi-xip-base5 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 1.331 10-Jul-2010 nakayama

Clear the upper word explicitly before combining two 32-bit values to 64-bit
on 32-bit kernels.


# 1.330 23-May-2010 martin

Split copy related functions out of locore.s into copy.S, move functions
only needed on multiprocessors into mp_subr.S.


# 1.329 17-May-2010 martin

Simplify primary CPU startup slightly by using the fact that our cpuinfo's
curpcb pointer points to the uarea/pcb of lwp0 and by remembering the pointer
to this cpuinfo, thus avoiding a few CPUINFO_VA references.


Revision tags: uebayasi-xip-base1
# 1.328 20-Mar-2010 chs

fix copy{in,out}{,str}() to return the error returned by uvm_fault().
fixes PR 41813.


Revision tags: yamt-nfs-mp-base9
# 1.327 10-Mar-2010 mrg

branches: 1.327.2;
XXX: workaround we'd like to remove when pmap / uvm locking is cleaned up:

- rename pseg_get() and pseg_set() to pseg_get_real() and pseg_set_real().
- if USE_LOCKSAFE_PSEG_GETSET is defined, which it current is by default,
define pseg_[gs]et() in terms of functions that take a new pseg_lock
mutex at IPL_VM while calling into the real functions.

this seems to avoid the pseg_set() crashes we've seen:
1 - spare needed, when pseg_get() just worked for this pmap
2 - the 2rd ldxa via ASI_PHYS_CACHED in pseg_set() loads garbage
into %o4, and causes the 3rd ldxa to fault


# 1.326 08-Mar-2010 mrg

blast_dcache() SMP friendly:

- blast_dcache() becomes sp_blast_dcache(dcache_size, dcache_line_size)
- new smp_blast_dcache(sparc64_cpuset_t) that blasts the D$ on this cpuset
- sparc64_ipi_blast_dcache() to support the above
- in pmap_remove_all(), when freeing mmu contexts for this pmap, mark
the set of cpus to blast the d$ on as well and convert the
blast_dcache() call into smp_blast_dcache() on the cpus who ran this
pmap, or, sp_blast_dcache(dcache_size, dcache_line_size)
- convert the remaining blast_dcache() in machdep.c to sp_blast_dcache()
- in pmap_destroy()/pmap_remove_all() take the pmap_lock() always since
we assert it is held always.

with these changes, NFS builds on the U60 seem to be stable now, and
the USIII machines also can often complete a single build.sh run now,
diskful or diskless.


reviewed by mlelstv and partially by martin, tested by martin and myself,
with some ideas from chuq as well.


# 1.325 07-Mar-2010 mrg

need _ALIGN in locore.h as well, for DEBUG kernels.


# 1.324 07-Mar-2010 mrg

gas has supported SPARC ".empty" for a long while; get rid of an
ancient workaround.


# 1.323 06-Mar-2010 mrg

move the memcpy/memset implementations out into their own file, with the
block copy versions as well. move some of the definitions in locore.s
into a new locore.h.

locore.s is almost 2000 lines shorter with this change.


# 1.322 04-Mar-2010 mrg

- in _bus_dmamap_unload(), pmap_page_protect() and pmap_clear_reference()
switch the dcache_flush_page() into a dcache_flush_page_all()
- in both pmap_kremove()/pmap_remove(), remove the blast_dcache() call
and replace it with dcache_flush_page_all()
- in pmap_get_page() [used to allocate PTP's], always call pmap_zero_page(pa)
- flush the dcache of the dst page in pmap_{copy,zero}_page() by redirecting
throught a C function that calls the (renamed) asm. the old asm code had a
comment about needing to do this...
- add a couple of membar #Sync's that the USIII manual recommends


based on discussions with chuq@, skrll@ and martin@.


these help my SB2000 / SB2500 with both disk / nfs builds and other tasks,
sometimes lasting for several hours before failing or asserting.


# 1.321 24-Feb-2010 mrg

when handing back page table pages to UVM, flush them from the dcache
on all CPUs.

idea from skrll@, and makes my disk-based SB2000 stable.

tested on U60, SB2000 and SB2500.


# 1.320 24-Feb-2010 mrg

- re-introduce sp_tlb_flush_pte() and sp_tlb_flush_all() that call
the right USI/USIII version.
- define tlb_flush_pte() in terms of sp_tlb_flush_pte() for the
!MULTIPROCESSOR case

this centralises some CPU_IS_USIII_UP() tests.


# 1.319 22-Feb-2010 mrg

move {dump,print}_[id]tlb() into a separate file.


# 1.318 22-Feb-2010 mrg

- store the maximum [id]cache size / line size for each cpu

- remove patch_kernel() since it isn't necessary and has been patching
the wrong thing in general.

- implement USIII versions of blast_icache(), dcache_flush_page() and
cache_flush_phys(). use the newly recorded cache size/line sizes.

- in winfixsave, flush the D$ with the right size index and ops. this
kills one of the wrong tag->inval patches.

- for blast_dcache(), use the newly recorded dcache_size/line_size.

- for blast_icache(), use the newly recorded cache size/line sizes.
for the USIII verison, disable the I$ while writing to ASI_ICACHE_TAG.


these changes removed several hard coded cache sizes values, some very
wrong kernel patching, and seem to make the current failure modes for
USIII less common, but not gone.


# 1.317 15-Feb-2010 mrg

- don't flush 32-bit entries for 64-bit code, it does not seem to be
necessary. #define TLB_FLUSH_LOWVA to turn it back on.
- remove the #if 0'd code in sparc64_ipi_flush_pte_usiii(), i have
verified that it is not required.
- add a missing membar #Sync to sp_tlb_flush_pte_usiii().


# 1.316 15-Feb-2010 nakayama

Fix linker error of GENERIC32 kernel.


# 1.315 15-Feb-2010 mrg

use TLB_SIZE_SPITFIRE in a couple of places, and note that the
{print,dump}_[id]tlb() versions are currently spitfire specific.


# 1.314 15-Feb-2010 mrg

introduce a new patch_kernel() and call it from the end of bootstrap().
use it to patch up TLB flush instructions that don't match for USI/II
and later. we can also hopefully use this to make GENERIC.MP minimally
expensive on single CPU machines as well.

this is the last piece needed to get GENERIC/GENERIC.MP to boot on the
USIII* machines.

idea and some initial code from openbsd.


# 1.313 13-Feb-2010 mrg

remove KTR support. it's never been a working part of netbsd src tree.


# 1.312 09-Feb-2010 wiz

Fix typo in comment.


Revision tags: uebayasi-xip-base
# 1.311 06-Feb-2010 mrg

branches: 1.311.2;
- properly map the schizo interrupt registers, so we can use the normal
virtual mappings to access them.
- with the above fxied, kill SCHIZO_BUS_SPACE_BROKEN, and introduce
an options CHEETAH for now, that disables the SPITFIRE code in locore.
- merge schizo_init() into schizo_attach() and clean up the softc a bit.


with this we are only one more step away from GENERIC booting on USIII
machines.


# 1.310 02-Feb-2010 mrg

- split sp_tlb_flush_pte() and switchtoctx() into sp_tlb_flush_pte_us()/
sp_tlb_flush_pte_usiii() and switchtoctx_us()/switchtoctx_usiii() and
implement the latter while i'm here. it works ... sometimes i think,
but also sometimes panics/hangs.
- fix a comment in sparc64_ipi_flush_pte_usiii()


# 1.309 02-Feb-2010 mrg

for now, reduce a few #ifdef SPITFIRE cases by introducing a new
ASI_DCACHE_TAG_OR_INV that is either ASI_DCACHE_{TAG,_INVALIDATE}.

increase the common code in cache_flush_phys().


# 1.308 01-Feb-2010 mrg

- sp_tlb_flush_all() becomes sp_tlb_flush_all_us() and sp_tlb_flush_all_usiii()
- sparc64_ipi_flush_pte() becomes sparc64_ipi_flush_pte_us() and
sparc64_ipi_flush_pte_usiii()
- add some commented out code to disable interrupts and raise the traplevel
in sparc64_ipi_flush_pte_usiii()
- cache_flush_phys() was missing a little of code in the cheetah case


# 1.307 01-Feb-2010 mrg

for USIII, use the new "tlb demap all" operation in sp_tlb_flush_all()


# 1.306 01-Feb-2010 mrg

remove unused icache_flush_page() implementation.


# 1.305 23-Jan-2010 mrg

remove the final uses of DATA_START.

now we can remove the 16KB space reserved at the start of the data segment,
and i now understand why i wrote this now removed comment 3.5 years ago:
"this shouldn't be needed... but kernel usually hangs without it"


# 1.304 23-Jan-2010 mrg

remove most of the code that writes debugging info DATA_START + offset.


# 1.303 23-Jan-2010 mrg

remove CHKPT() macro and uses. it's likely wrong in SMP land and probably should
be replaced with KTR-style uses if necessary.


# 1.302 23-Jan-2010 mrg

fix a comment.


Revision tags: matt-premerge-20091211
# 1.301 10-Dec-2009 rmind

Rename L_ADDR to L_PCB and amend some comments accordingly.


# 1.300 05-Dec-2009 mrg

- adjust the PA mask to the 43 bits supported by USIII.
- rework the spitfire/cheetah cache_flush_phys() to avoid several #ifdefs
- add a membar #Sync after sparc64_ipi_drop_fpstate (probably unnecessary)


# 1.299 30-Nov-2009 nakayama

sp_tlb_flush_pte for cheetah:
- restore interrupts properly in case of %tl > 0.


# 1.298 30-Nov-2009 mrg

stablize UP USIII support by blocking interrupts around sp_tlb_flush_pte()
i was seeing stack corruption while taking an interrupt in this function.

get USIII SMP mostly working by implementing the cheetah version of
sparc64_ipi_flush_pte().


SMP support is still not entirely stable. i can reproducably get a:

panic: fpusave_lwp ipi didn't

while running build.sh, when an awk process is exiting. other simple
heavy work loads do not crash for me right now.


# 1.297 30-Nov-2009 mrg

delete some no longer used code:
- smp_tlb_flush_ctx()
- smp_tlb_flush_all()
- sparc64_ipi_flush_ctx()
- sparc64_ipi_flush_all()
- sp_tlb_flush_ctx()


# 1.296 29-Nov-2009 nakayama

- calculate end PA correctly.
- wrap more spitfire specific (flushing I$) code.
- fix inverted #if condition for flushing I$ (and restore ASI_ICACHE_TAG).


# 1.295 28-Nov-2009 mrg

implement enough code to get SB2000/SB2500 booting to multiuser. does
not last long if you use it, but an idle machine has stayed up 10 hours.

- for the !SPITFIRE case, use ASI_DCACHE_INVALIDATE instead of
ASI_DCACHE_TAG when clearing tlb entries. from openbsd.

- convert some comment "! Not yet" into "WRITEME", so that attempting
to build a USIII MULTIPROCESSOR kernel fails to build until the code
is written.

- add some more WRITEME's for the above.

- implement a !SPITFIRE version of sp_tlb_flush_all(). since there are
no spare regs, for now just always increase %tl around this call. (we
could maybe store a token in %o3 along with the saved %pstate info.)


# 1.294 26-Nov-2009 matt

Kill proc0paddr. Use lwp0.l_addr instead.


# 1.293 25-Nov-2009 mrg

s/L_ADDR/L_PCB/, requested by rmind.


# 1.292 17-Oct-2009 nakayama

Wrap unused code with #if 0 which is called from #if 0'ed code.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5
# 1.291 30-May-2009 martin

cpu_setfunc() can not use lwp_trampoline, as that has additional lwp startup
semantics. Use a simpler setfunc_trampoline instead.


# 1.290 18-May-2009 nakayama

Remove random() from locore.s since it is in libkern.


# 1.289 16-May-2009 nakayama

Remove clear %tick in locore.s since it is cleared at cpu_initclocks() in
clock.c.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 nick-hppapmap-base mjf-devfs2-base
# 1.288 15-Dec-2008 mrg

restore some old "intrdebug" code, but leave it under NOT_DEBUG. most
of it works, but one that prints func/arg for each handler is not very
stable...

for now, while schizo bus space pointer accesses aren't working, add
a SCHIZO_BUS_SPACE_BROKEN option so you can build a kernel with schizo.

with this, and the prior schizo interrupt fix, you can now fail to run
/sbin/init!


Revision tags: haad-dm-base2 haad-nbase2 haad-dm-base
# 1.287 09-Dec-2008 martin

Get rid of get_maxctx() - it doesn't work on newer cpus and we will have
to find a better way for (some) sun4v machines - all sun4u use 13 bit
contexts anyway.


Revision tags: netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 ad-audiomp2-base netbsd-5-base
# 1.286 30-Oct-2008 nakayama

branches: 1.286.2; 1.286.6;
Wrap more code specific to USE_BLOCK_STORE_LOAD.


Revision tags: matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4
# 1.285 05-Oct-2008 nakayama

branches: 1.285.2;
- in flushing cache, use 32 as increment/decrement value to match the
cache line size.
- remove useless restore of %asi.
- remove nop in delay slot if we can.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 1.284 10-Jul-2008 nakayama

Use proper CCR.


# 1.283 10-Jul-2008 nakayama

sparc64_ipi_save_fpstate:
- use primary MMU context for consistency with other trap/interrupt handlers.

sparc64_ipi_save_fpstate, savefpstate:
- avoid storing fp registers as we can.

sparc64_ipi_save_fpstate, savefpstate, loadfpstate:
- remove unaligned case since buffers allocated with pool_cache are ensured
64-byte aligned.

Ok by martin@.


# 1.282 02-Jul-2008 nakayama

branches: 1.282.2;
UltraSPARCs don't have floating point queue, and reading %fq regsiter
will cause illegal instruction trap. So remove the code handling them.


# 1.281 29-Jun-2008 nakayama

Wrap IPI calls with #ifdef MULTIPROCESSOR.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.280 14-Jun-2008 nakayama

Close unterminated comment.
Fix unexpected behavior in case of loadfpstate from unaligned buffer.


Revision tags: yamt-pf42-base3
# 1.279 31-May-2008 nakayama

branches: 1.279.2;
openfirmware_exit:
- disable interrupts with %pstate.
- prepare 64-bit stack and enable 64-bit addresses for 32-bit SMP kernels.


Revision tags: hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 yamt-nfs-mp-base yamt-pf42-base
# 1.278 16-Apr-2008 nakayama

branches: 1.278.2; 1.278.4; 1.278.6;
Disable TRAPSTATS which was accidentally enabled when yamt-idlelwp branch
was merged.

Ok by martin@.


# 1.277 14-Apr-2008 nakayama

Remove sparc64_ipi_sync_tick.

Since we can use counter-timer as timecounter instead of %tick on SMP kernel,
it is not necessary to sync all CPUs %tick registers.


# 1.276 14-Apr-2008 nakayama

Add workaround for BB_ERRATA_1 on writing to TICK_CMPR register in
next_tick(). If writing to TICK_CMPR fails, we lose hardclock interrupt
on secondary CPUs.

About BB_ERRATA_1 from comment in OpenSolaris:

/*
* Writes to the TICK_COMPARE register sometimes fail on blackbird modules.
* The failure occurs only when the following instruction decodes to wr or
* wrpr. The workaround is to immediately follow writes to TICK_COMPARE
* with a read, thus stalling the pipe and keeping following instructions
* from causing data corruption. Aligning to a quadword will ensure these
* two instructions are not split due to i$ misses.
*/


# 1.275 28-Mar-2008 nakayama

Don't read fplwp content in delay slot for considering the case fplwp was
modifiled.

Reported by Chris Ross on port-sparc64.


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.274 20-Mar-2008 nakayama

- remove disabling interrupt in IPI.
- unused VA bits in MMU demap is 13 bits, not 12 bits.


# 1.273 18-Mar-2008 nakayama

Fix a race when increment an interrupt level event counter.


# 1.272 17-Mar-2008 nakayama

Fix a race condition in IPI handlers of save/drop fpstate, from OpenBSD.
Reported and tested by martin@.


# 1.271 17-Mar-2008 nakayama

Make schedintr interrupt handler per-CPU.
While there rename tickintr interrupt handler and share initialization
code with schedintr.


# 1.270 14-Mar-2008 nakayama

Improve IPI handling:
- make IPI takes two arguments.
- add IPI event counters per-CPU.
- implement IPI functions which were missing or broken.
- insert DELAY while halting primary CPU in IPI handler.


# 1.269 02-Mar-2008 nakayama

- make interrupt pending list per-CPU.
- make tickintr() MP-safe.
- remove unused port-sparc derived interrupt code.

Ok by martin@.


# 1.268 02-Mar-2008 nakayama

Don't get IPI handler argument (from bogus address), and ack IRQ twice.


# 1.267 28-Feb-2008 martin

Make TSBs and MMU contexts per-cpu.


Revision tags: nick-net80211-sync-base mjf-devfs-base hpcarm-cleanup-base
# 1.266 26-Jan-2008 nakayama

branches: 1.266.2; 1.266.6;
Fix for 32-bit kernels.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.265 15-Jan-2008 skrll

Store a sensbile PCB_PC value in snapshot - the return point.

This helps gdb somewhat.

OK'd by martin.


# 1.264 14-Jan-2008 martin

Fix register name typo/copy&pasto - %g6 is not %o6/%sp.
From OpenBSD.


Revision tags: matt-armv6-base
# 1.263 06-Jan-2008 martin

Load the next cpu_info pointer with LDPTR instead of ld.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2
# 1.262 09-Dec-2007 martin

branches: 1.262.2;
Provide cpu_intr_p(), at least for non-MULTIPROCESSOR kernels.
Based on suggestions by Andrew Doran.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.261 22-Oct-2007 martin

branches: 1.261.2; 1.261.4; 1.261.6;
Remove an unused .globl declaration


Revision tags: yamt-x86pmap-base4
# 1.260 17-Oct-2007 garbled

Merge the ppcoea-renovation branch to HEAD.

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

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

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base ppcoea-renovation-base vmlocking-base
# 1.259 09-Sep-2007 martin

branches: 1.259.4;
Make cpufrequency and friends per cpu values.
Prepare a hz tick interrupt on secondary CPUs via %tick, but do not
enable it yet, as it breaks ddb.


# 1.258 09-Sep-2007 martin

Do not ACK IPIs before we finished loading all arguments.


# 1.257 06-Sep-2007 martin

Remove the (now unused) second 64k page mapped per CPU.
From matthew green, with small changes by me. All bugs are mine.


# 1.256 25-Aug-2007 martin

branches: 1.256.2;
Remove INITSTACK completely - at the time we used to switch to it, we
already have access to all of lwp0 and it's uarea - so we can switch
to the correct lwp0 stack easily before calling main.


# 1.255 25-Aug-2007 martin

When exiting to OF, use the interrupt stack instead of INITSTACK


# 1.254 25-Aug-2007 martin

Rework cpu_mp_startup slightly:
- temporarily use the cpu's interrupt stack untill we are ready
to access non-OF-based mappings, then directly switch to the cpu's
idlelwp's uarea stack
- disable interrupts untill we are ready to call C code


# 1.253 13-Aug-2007 macallan

remove two restore without matching save


Revision tags: nick-csl-alignment-base matt-mips64-base mjf-ufs-trans-base
# 1.252 06-Jul-2007 martin

branches: 1.252.4; 1.252.8;
A few nits for 32bit SMP kernels, noticed by mrg.
While there, simplify the fpstate IPIs a bit.


# 1.251 05-Jul-2007 martin

sparc64_ipi_save_fpstate is not a leaf function - create a full grown
stack frame.


# 1.250 28-May-2007 mrg

clean up cpu_switchto() a little - no need to flushw or membar
excessively. optimise an rdpr. tested by tnn.


# 1.249 23-May-2007 martin

Fix a stupid bug in the save_fpstate ipi, which caused overwriting of
struct lwp of the lwp owning the fpu. Fix clearing the fplwp - %o0 will
not survive the call to savefpstate - duh!


# 1.248 20-May-2007 martin

Simplify tf_tstate setting when leaving for userland initially - I seem
to have confused the if with the else case of the previous C code.
Funny that it worked at all.


# 1.247 20-May-2007 martin

cpu_switchto() has to return it's first arg, always. This differs from
my reading of the documentation, but helps in the real world and seems
to be what other ports do.


# 1.246 20-May-2007 martin

Remove special case handling for userland lwps from cpu_lwp_fork, instead
do it in lwp_trampoline when we first return to userland.


# 1.245 19-May-2007 martin

cpu_idle is a leaf function, so we better "return from leaf".
Use return value from cpu_switchto for previous lwp in lwp_trampoline.
Also shamelessly steal a comment from uwe written for sparc that explains
all this.
Thanks to tnn, mrg, and uwe for helping to debug this.


# 1.244 17-May-2007 yamt

merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base ad-audiomp-base
# 1.243 22-Feb-2007 martin

branches: 1.243.4; 1.243.6; 1.243.12;
uvm.page_idle_zero now is a bool, not a 32bit value any more.


# 1.242 21-Feb-2007 mrg

shave 9 insns off the tsb setup in cpu_initialize & cpu_mp_startup.


# 1.241 21-Feb-2007 martin

Get rid of unused (thus always zero) "curlwp" variable hidden in assembler
code (C code always uses a cpuinfo based macro).


# 1.240 18-Feb-2007 martin

Make use of another call delay slot, pointed out by uwe.


# 1.239 18-Feb-2007 martin

Make use of a call delay slot and avoid a bogus EMPTY.
Spotted by Juergen Hannken-Illjes, with input from Andrew Doran and
Valeriy E. Ushakov.


# 1.238 18-Feb-2007 martin

Whitespace cosmetics


# 1.237 18-Feb-2007 martin

Backout previous: EMPTY was misused


# 1.236 18-Feb-2007 martin

Make EMPTY expand to nop with gas, as it is used to mark empty branch
delay slots.


# 1.235 15-Feb-2007 martin

branches: 1.235.2;
Fix obvious copy&pasto in SCHED_DEBUG register usage.


Revision tags: post-newlock2-merge
# 1.234 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.233 25-Dec-2006 wiz

Spell "relevant" correctly. From Zafer Aydogan.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.232 25-Oct-2006 mrg

branches: 1.232.2; 1.232.4;
- note that __idle_u should go away but doing so breaks things
- fix several comments to reality
- clean up the #ifdef NO_VCACHE code slightly
- use call instead of set/jmpl
- remove a couple of unnecessary stores to curlwp


Revision tags: yamt-splraiseipl-base2
# 1.231 18-Oct-2006 rjs

Clean up some comments. Cosmetic change to use correct structure
offset names.

Optimize out two instructions from sparc64_ipi_save_fpstate and
sparc64_ipi_drop_fpstate.


# 1.230 17-Oct-2006 mrg

allocate 128KB (as opposed to 64KB) per-cpu, and place the interrupt
stack, cpu_info structure, panicstack, idle uarea and normal kernel
stack in here. the idle uarea and kernel stack are in the 2nd 64KB
page. the interrupt stack and cpu_info structure are as the same
place in the 1st 64KB page, and the panicstack grows down from the
top of this page. update comments in param.h to suit (XXX: a lot
of these constants should move to a header file that will not pollute
the name space so much.) map these pages identically between
cpu_initialise() and cpu_mp_startup(), and deal with the two 64KB
pages in pmap_extract(). keep an unmapped 64KB page between them.

don't initialise the unused "ci_eintstack" member of the cpu_info
structure

use constants to initialise many addresses in the cpu_info structure,
consolidating these assignments from cpu0 and cpu>0

delete u0/estack0/panicstack from locore.s

clean up some wrong comments in locore.s

fix a 32bit-only bug in cpu_mp_startup().

delete 'u0' entirely.


this fixes recent random lossage seen on port-sparc64: processes
stuck in RUN state, data faults, and hangs.


# 1.229 04-Oct-2006 mrg

use call instead of set/jmpl. add an entry point for idle that expects
sched_lock to be unlocked, and use this for non-boot cpu's. complete a
comment describing how registers in idle_switch are expected to be set.


# 1.228 03-Oct-2006 mrg

use the same SAVE_LOCALS_INS definition for 32 bit and 64 bit kernels.
refactor TRAP_SETUP() a little between these two versions to be more alike.


# 1.227 03-Oct-2006 mrg

use the correct size/type for MP variables (pointers and longs).

a 32 bit MULTIPROCESSOR kernel now builds (and crashes quickly.)


# 1.226 03-Oct-2006 mrg

in the 64bit version of SAVE_LOCAL_INS, s/BIAS/STKB/ to allow future
sharing of the 32 and 64 bit versions of the {TRAP,INTR}_SETUP macros.


# 1.225 19-Sep-2006 mrg

- remove some way old FP setup/teardown code
- put the block memcpy/memset inside #ifdef USE_BLOCK_STORE_LOAD which
is (now) defined.

no functional change, same .o is generated.


# 1.224 19-Sep-2006 mrg

re-order the changes in rev 1.217 to give registers a little bit of
time to settle between usage, like it was before hand.


# 1.223 19-Sep-2006 mrg

- remove a wrong comment.
- add a new entry point for idle called idle_switch that is called by
cpu_switch() in the MP case when sched_whichqs is zero, properly
setting up the idle stack. from petrov@ via martin@.


# 1.222 19-Sep-2006 mrg

rework interrupt_vector() slightly:
- for the IPI case, avoid loading the address of intrlev into %g3
- remove some NOT_DEBUG code
- load the interrupt argument #2 in the delay slot

this removes 2 nops during interrupt processing for the normal
case, and an additional 2 ALU instructions for IPIs


# 1.221 18-Sep-2006 mrg

- sparc64_ipi_halt(): we shouldn't return from sparc64_ipi_halt_thiscpu()
so replace a branch with a 'sir'
- in #if 0 code, in sparc64_ipi_flush_pte() and sparc64_ipi_flush_ctx()
save/restore the out registers that the sp_tlb_flush_xxx() versions
around calling them
- in sp_tlb_flush_pte() and sp_tlb_flush_ctx(), replace global register
usage with out registers so that we don't clobber the (alternate)
global registers when these are called from IPI context


# 1.220 18-Sep-2006 mrg

- remove an extra 'sir' that followed one in a macro
- add some named labels to some spill/fill handlers
- remove 2 unused strings


Revision tags: yamt-splraiseipl-base
# 1.219 18-Sep-2006 martin

branches: 1.219.2;
Lazy FPU handling for the MULTIPROCESSOR case


# 1.218 16-Sep-2006 nakayama

From OpenBSD:
- reload %fprs for checking it again.
- use symbolic names for checking in %fprs.

revision 1.51
date: 2005/07/18 14:50:11; author: deraadt; state: Exp; lines: +2 -1
cache a copy of the fprs so we know what fp restore we should do after

revision 1.50
date: 2005/07/14 01:46:13; author: deraadt; state: Exp; lines: +4 -4
use symbolic names for checking in %fprs, as above


# 1.217 16-Sep-2006 nakayama

Fix a couple of %y register save/restore errors, inspired from OpenBSD.

revision 1.44
date: 2004/04/23 04:18:17; author: marc; state: Exp; lines: +5 -4

fix a couple of %y register save/restore errors
1) don't save %y in a register that is later used before restoring %y
2) always restore %y after calling a signal handler
tested by drahn@, OK pval


# 1.216 15-Sep-2006 martin

Do not bother to save fpu state when we are about to get rid of it.


Revision tags: yamt-pdpolicy-base9
# 1.215 13-Sep-2006 mrg

SMP cleanup. provide support for multiple CPUs in DDB. (SMP itself
is still not working.)

cpu.h:
- add a pointer for DDB regs in SMP environment to struct cpu_info
- remove the #defines for mp_pause_cpus() and mp_resume_cpus()
cpuset.h:
- remove CPUSET_ALL() and rename CPUSET_ALL_BUT() to CPUSET_EXCEPT()
from petrov.
db_machdep.h:
- rename the members of db_regs_t to be the same as sparc
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- redo DDB_REGS to no longer be a pointer to a fixed data structure
but to one allocated per-cpu when ddb is entered
- move a bunch of prototypes in here
intr.h:
- remove SPARC64_IPI_* macros, no longer used
db_interface.c:
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- make "nil" a 64 bit entity
- change the ddb register access methods to work in multiprocessor
environment, it is now very much like sparc does it
- in kdb_trap() avoid accessing ddb_regp when it is NULL
- update several messages to include the cpu number
- unpause other cpus much later when resuming from ddb
- rename db_lock() to db_lock_cmd(), as the sparc-like code has
db_lock as a simple lock
- remove "mach cpus" command, and replace it with "mach cpu" (which
does the same) and also implement "mach cpu N" to switch to
another cpus saved trapframe
db_trace.c:
- update for the ddb_regs -> ddb_regp change
genassym.cf:
- add TF_KSTACK as offsetof(struct trapframe64, tf_kstack)
ipifuncs.c:
- overhaul extensively
- remove all normal interrupt handlers as IPI's, we now handle
them all specially in locore.s:interrupt_vector
- add a simplelock around all ipi functions - it's not safe for
multiple cpus to be sending IPI's to each other right now
- rename sparc64_ipi_pause() to sparc64_ipi_pause_thiscpu() and,
if DDB is configured, enable it to save the passed-in trapframe
to a db_regs_t for this cpu's saved DDB registers.
- remove the "ipimask" system (SPARC64_IPI_* macros) and instead
pass functions directly
- in sparc64_send_ipi() always set the interrupt arguments to 0,
the address and argument of the to be called function. (the
argument right now is the address of ipi_tlb_args variable, and
part of the reason why only one CPU can send IPI's at a time.)
don't wait forever for an IPI to complete. some of this is
from petrov.
- rename sparc64_ipi_{halt,pause,resume}_cpus() to
mp_{halt,pause,resume}_cpus()
- new function mp_cpu_is_paused() used to avoid access missing
saved DDB registers
- actually broadcast the flush in smp_tlb_flush_pte(),
smp_tlb_flush_ctx() and smp_tlb_flush_all(). the other end may
not do anything yet in the pte/ctx cases yet...
kgdb_machdep.c:
- rework for changed member names in db_regs_t.
locore.s:
- shave an instruction from syscall_setup() (set + ld -> sethi + ld)
- remove some old dead debug code
- add new sparc64_ipi_halt IPI entry point, it just calls the C
vector to shutdown.
- add new sparc64_ipi_pause IPI entry point, which just traps into
the debugger using the normal breakpoint trap. these cpus usually
lose the race in db_interface.c:db_suspend_others() and end up
calling the C vector sparc64_ipi_pause_thiscpu().
- add #if 0'ed code to sparc64_ipi_flush_{pte,ctx}() IPI entry
points to call the sp_ version of these functions.
- in rft_kernel (return from trap, kernel), check to see if the
%tpc is at the sparc64_ipi_pause_trap_point and if so, call
"done" not "retry"
- rework cpu_switch slightly: save the passed-in lwp instead of
using the one in curlwp
- in cpu_loadproc(), save the new lwp not the old lwp, to curlwp
- in cpu_initialize(), set %tl to zero as well. from petrov.
- in cpu_exit(), fix a load register confusion. from petrov.
- change some "set" in delay branch to "mov".
machdep.c:
- deal with function renames
pmap.c:
- remove a spurious space
trap.c:
- remove unused "trapstats" variable
- add cpu number to a couple of messages


# 1.214 09-Sep-2006 mrg

significant clean up effort, largely from petrov@ via martin@.

- fix a bunch of comments for proc->lwp
- remove old TRAPTRACE, NOT_DEBUG, etc. code that has bit-rotted
- put some older DEBUG code under NOT_DEBUG
- add a bunch of new debugging/tracing code ("KTR") that depends on
other changes not yet present.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base yamt-pdpolicy-base5 chap-midi-base simonb-timecounters-base rpaulo-netinet-merge-pcb-base
# 1.213 14-May-2006 elad

branches: 1.213.6; 1.213.8;
integrate kauth.


# 1.212 12-May-2006 skrll

Fix some comments.


Revision tags: elad-kernelauth-base
# 1.211 09-May-2006 rjs

Load CPCB in cpu_mp_startup.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.210 11-Feb-2006 cdi

branches: 1.210.2; 1.210.4; 1.210.6;
ANSIfication: u_intN_t -> uintN_t, use ANSI function declarations/definitions
instead of K&R ones.


# 1.209 27-Jan-2006 cdi

branches: 1.209.2; 1.209.4;
Alter sparc64 bootstrap, catch up to ofwboot v1.9:

- Accept bootinfo structure passed down from ofwboot v1.9
- Drop kernel re-mapping code
- Use permanent 4MB mappings provided by the loader instead
- Change kernel entry address to point directly at the code instead of pointing
at the trap table's first slot. This allows the bootloader to detect
those kernels which are aware of the new boot scheme
- Due to the changes in kernel mapping code, alter secondary CPU bootstrap
code to use trampoline just like FreeBSD does (some FreeBSD code is used
here as well)


# 1.208 12-Jan-2006 cdi

Fix a typo: %g0 should be used instead of %o0 when initializing FPU in dostart:
and cpu_mp_startup:, %o0 is not even initialized at this point.


# 1.207 11-Dec-2005 christos

branches: 1.207.2;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 1.206 10-Jul-2005 christos

Re-factor syscall, and make it use syscall_{plain,fancy}.


# 1.205 31-May-2005 chs

branches: 1.205.2;
remove vestigal {,e}intr{names,cnt} symbols now that vmstat doesn't need them.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.204 12-Feb-2005 chs

branches: 1.204.4; 1.204.6; 1.204.8;
in sparc_interrupt(), wait to enable interrupts until just before calling
the handler and disable them again right after the handler returns.
we don't want another hardware interrupt coming in while we're mucking
with the list pointers. also, clear the intrhand's ih_pending pointer
before calling the handler rather than after, so that if another interrupt
comes in while the handler is running, we can put the intrhand back on
the list so it will be called again.

in send_softint(), disable interrupts via %pstate instead of %pil, so that
hardware interrupts at higher levels are blocked while we manipulate the
intrpending list. also, if the intrhand already has ih_pending set,
don't bother poking the SET_SOFTINT register again, since being on the list
implies that there is already a softint pending in the hardware.

these appear to fix PR 21750 (the "sleep forever" problem).

while I'm here, remove more vestiges of the !INTRLIST softint stuff
(code and comments). and in sparc64_ipi_flush_all(), interrupts are
already disabled so we don't need to fiddle with %pstate.


Revision tags: yamt-km-base2
# 1.203 30-Jan-2005 martin

Remove the no long usefull variants selected by undefining INTRLIST and
INTR_INTERLOCK to improve readability. Same object code generated as before.


Revision tags: yamt-km-base
# 1.202 16-Jan-2005 chs

branches: 1.202.2;
use ENTRY_NOPROFILE() for various entry points,
stack traces work better that way.


Revision tags: kent-audio1-beforemerge kent-audio1-base
# 1.201 03-Dec-2004 chs

branches: 1.201.4;
remove cache_flush_virt() and PADDRT, they're no longer used.
allocate a stack frame for blast_dcache() when profiling so it shows up.
in dcache_flush_page(), use a stride of 32 instead of 16 to match the
cache line size. correct various comments.


# 1.200 08-Nov-2004 petrov

Don't compile sparc64_ipi functions when UP.


# 1.199 25-Oct-2004 martin

No need to clear %o1 when returning a 64 bit integer from pseg_get if we
are compiling for a 64 bit kernel.


# 1.198 24-Jul-2004 nakayama

Change interrupt pending list end value to -1, to avoid linking an
interrupt handler twice.

It may fix "sleep forever" bug.


# 1.197 09-Apr-2004 petrov

Clean-up unused defines and variables.


Revision tags: netbsd-2-0-base
# 1.196 26-Mar-2004 petrov

branches: 1.196.2;
Use want_resched from cpu_info area.


# 1.195 23-Mar-2004 martin

Replace intrcnts by evcnts. XXX - needs slight tweaking for MULTIPROCESSOR.


# 1.194 14-Mar-2004 chs

checkpoint of MP work from dennis and myself. includes cross-processor
interrupt framework, a sledgehammer TLB invalidation and misc MP fixes.
doesn't work at all yet.


# 1.193 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.192 19-Jan-2004 martin

Rename switchexit to cpu_exit and g/c the old C implementation of cpu_exit.


# 1.191 18-Jan-2004 martin

Support RAS for 32bit kernels too.


# 1.190 16-Jan-2004 martin

In proc_trampoline don't bother to clear condition codes in the trap
frame, since we no longer rely on this.
While there fix a few comments.


# 1.189 08-Jan-2004 martin

Minor cleanup


# 1.188 06-Jan-2004 martin

Implement restartable atomic sequences (RAS) for sparc64.


# 1.187 06-Jan-2004 petrov

Spinup secondary cpus. Based on codes sent to me by Dennis Chernoivanov
and Chuck Silvers.


# 1.186 04-Jan-2004 jdolecek

update to recent changes - exit2() doesn't exist anymore and the
exit path always calls lwp_exit2()
pointed out Martin Husemann


# 1.185 02-Dec-2003 martin

Minor cleanup: remove unused code, sync a comment with current reality.


# 1.184 25-Nov-2003 cdi

Use per-cpu pcb, curlwp and fplwp rather than global ones. This brings
GENERIC.MP configuration to a usable state.

Approved by petrov@.


# 1.183 24-Nov-2003 cdi

Call 'proc_trampoline_mp' from 'proc_trampoline' in a multiprocessor
configuration. Fix process locking. Approved by petrov@.


# 1.182 20-Nov-2003 petrov

Remove nwindows calculation, it's not used. Set l_cpu in cpu_switch.


# 1.181 09-Nov-2003 martin

Get rid of bcopy/bzero.


# 1.180 26-Oct-2003 christos

Initial siginfo support for sparc64 (untested). COMPAT_16 sigcontext signal
delivery tested.


# 1.179 24-Aug-2003 chs

add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default. the changes
fall into two basic catagories:

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

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

originally from openbsd, adapted for netbsd by me.


# 1.178 08-Jul-2003 cdi

traceit: don't use %g7 as it is to become curcpu() register. Add comments.


# 1.177 18-May-2003 martin

branches: 1.177.2;
Make kernels with options KGDB at least compile.
Still needs some work to make it working.


# 1.176 29-Apr-2003 nakayama

Use BLOCK_ALIGN rather than BLOCK_SIZE for aligning a pointer.


# 1.175 27-Apr-2003 ragge

Preserve the symbol table in the LKM || KSYMS cases also.


# 1.174 04-Apr-2003 petrov

use branch slot in pmap_copy_page.


# 1.173 24-Mar-2003 nakayama

Divide `set' instruction in delay slot (from OpenBSD change to rev 1.30).


# 1.172 10-Feb-2003 martin

Remove some #if 0 code and a few XXX marked membars w/o proper
justification for their existence.


# 1.171 09-Feb-2003 martin

Remove left over pieces from reusing the signal trampoline for upcalls.
This should fix signal delivery for 32bit kernels.


# 1.170 05-Feb-2003 nakayama

Switch to use cycle counter (%tick) based microtime().

This is derived from alpha/microtime.c and i386/tsc_microtime.c,
and will share with both ports.

This should fix PR port-sparc64/18452.
(approved by martin)


# 1.169 04-Feb-2003 martin

Fix return value of pseg_set, which I accidently broke in rev. 1.164.

Fix register names in comment and shave off another register (hint
from uwe).


# 1.168 01-Feb-2003 martin

Rearrange register usage in pseg_set a bit and shave off %g4.


# 1.167 01-Feb-2003 martin

Remove a few #ifdef _LP64 by using STPTR/LDPTR macros.
Thanks to Matthew Green for the pointer.


# 1.166 31-Jan-2003 martin

Apply leaf procedure optimization to pseg_set (again).


# 1.165 31-Jan-2003 martin

Make the pmap count resident/wired mappings on the fly instead of
walking the page tables whenever this information is needed.

Add an option PMAP_COUNT_DEBUG to assert the new counts and the
page table walk agree.

The old solution had very bad performance impact, for example
by the high CPU load when running top(1).

Thanks to Simon Burge for pointing at the cause of the problem and
to Valeriy E. Ushakov for optimizing my simple minded assembler code.


# 1.164 27-Jan-2003 martin

Remove unused function pseg_find (which looked quite similar to
pseg_get anyway).


# 1.163 18-Jan-2003 thorpej

Merge the nathanw_sa branch.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.162 16-Jan-2003 petrov

Move dump_dtlb back under DDB.


# 1.161 15-Jan-2003 chs

fix two bugs in my last pmap rework:
- in tlb_flush_all(), don't skip TLB entries with the high bit on,
I was confused about which MMU register it was using. it's also fine
to use the last hardware context.
- in pmap_create(), don't allocate a hardware context for the new pmap.
it's unnecessary, and when this would cause us to recycle all the contexts,
it would result in the current process's context being set to 0
(ie. the kernel's context). the current process could then return to
userspace without going through the context-switch code (and thus without
having a hardware context reallocated). this would lead to user mappings
being entered in the kernel's context later, causing all sorts of trouble.
add some assertions to catch this kind of thing.


Revision tags: fvdl_fs64_base
# 1.160 25-Dec-2002 petrov

new function dump_itlb.


Revision tags: gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.159 22-Sep-2002 chs

many improvements:
- use struct vm_page_md for attaching pv entries to struct vm_page
- change pseg_set()'s return value to indicate whether the spare page
was used as an L2 or L3 PTP.
- use a pool for pv entries instead of malloc().
- put PTPs on a list attached to the pmap so we can free them
more efficiently (by just walking the list) in pmap_destroy().
- use the new pmap_remove_all() interface to avoid flushing the cache and TLB
for each pmap_remove() that's done as we are tearing down an address space.
- in pmap_enter(), handle replacing an existing mapping more efficiently
than just calling pmap_remove() on it. also, skip flushing the
TSB and TLB if there was no previous mapping, since there can't be
anything we need to flush. also, preload the TSB if we're pre-setting
the mod/ref bits.
- allocate hardware contexts like the MIPS pmap:
allocate them all sequentially without reuse, then once we run out
just invalidate all user TLB entries and flush the entire L1 dcache.
- fix pmap_extract() for the case where the va is not page-aligned and
nothing is mapped there.
- fix calculation of TSB size. it was comparing physmem (which is
in units of pages) to constants that only make sense if they are
in units of bytes.
- avoid sleeping in pmap_enter(), instead let the caller do it.
- use pmap_kenter_pa() instead of pmap_enter() where appropriate.
- remove code to handle impossible cases in various functions.
- tweak asm code to pipeline a little better.
- remove many unnecessary spls and membars.
- lots of code cleanup.
- no doubt other stuff that I've forgotten.

the result of all this is that a fork+exit microbenchmark is 34% faster
and a fork+exec+exit microbenchmark is 28% faster.


Revision tags: gehenna-devsw-base
# 1.158 18-Jul-2002 wiz

Spell 'should' correctly.


# 1.157 07-Jun-2002 eeh

Shave 10% off the time needed to flush the D$ through a bit of instruction
reordering.


# 1.156 05-Jun-2002 eeh

Handle improperly aligned stack pointers more cleanly.


# 1.155 04-Jun-2002 eeh

Fix the fork trampoline to properly use the supplied tstate.


# 1.154 31-May-2002 thorpej

Make this work with an ISO C preprocessor.


Revision tags: netbsd-1-6-base
# 1.153 14-May-2002 eeh

branches: 1.153.2; 1.153.4;
Only save locals and ins in trapframes for DEBUG kernels.


# 1.152 04-May-2002 kleink

Add some comments to the CPP conditionals controlling the trap macro
definitions, to ease navigation somewhat.


# 1.151 16-Apr-2002 eeh

Make lots of routines profile-friendly and get rid of some cruft.


Revision tags: eeh-devprop-base
# 1.150 21-Mar-2002 petrov

Not needed debug stuff deleted.


# 1.149 16-Mar-2002 mrg

tell newer binutils that our use of %g2 and %g3 is OK here.


# 1.148 15-Mar-2002 eeh

Cleanup MMU initialization to prevent hangs.


Revision tags: newlock-base ifpoll-base
# 1.147 09-Feb-2002 eeh

branches: 1.147.4;
Fix microsecond calculation in microtime.


# 1.146 07-Feb-2002 eeh

Fix register allocation in microtime().


# 1.145 29-Jan-2002 eeh

Shift the UPAID in the correct direction.


# 1.144 17-Jan-2002 eeh

Be more tolerant of unaligned stack pointers.


# 1.143 17-Jan-2002 eeh

Enable block insns in bcopy and bzero.


# 1.142 16-Jan-2002 eeh

In bcopy use 32-bit comparisons in 32-bit kernels.


# 1.141 16-Jan-2002 eeh

Use correct calculation for the trapframe in softtrap for ILP32.


# 1.140 20-Nov-2001 lukem

- pull in opt_kgdb.h where necessary
- replace opt_kgdb_machdep.h with opt_kgdb.h
- defparam opt_kgdb.h:
KGDB_DEV KGDB_DEVNAME KGDB_DEVADDR KGDB_DEVRATE KGDB_DEVMODE
- move from opt_ddbparam.h to opt_ddb.h:
DDB_FROMCONSOLE DDB_ONPANIC DDB_HISTORY_SIZE DDB_BREAK_CHAR SYMTAB_SPACE
- replace KGDBDEV with KGDB_DEV
- replace KGDBADDR with KGDB_DEVADDR
- replace KGDBMODE with KGDB_DEVMODE
- replace KGDBRATE with KGDB_DEVRATE
- use `9600' instead of `0x2580' for 9600 baud rate
- use correct quotes for options KGDB_DEVNAME="\"com\""
- use correct quotes for options KGDB_DEV="17*256+0"
- remove unnecessary dependancy on Makefile for kgdb_stub.o
- minor whitespace cleanup


Revision tags: thorpej-mips-cache-base thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf
# 1.139 14-Sep-2001 thorpej

branches: 1.139.4;
Don't declare intrhand[] here -- that's taken care of in intr.c.


Revision tags: thorpej-devvp-base
# 1.138 30-Aug-2001 eeh

branches: 1.138.2;
Preliminary UltraSPARC III suport (not enabled yet).


# 1.137 13-Aug-2001 jdolecek

g/c _remque()/_insque(); use the C version in libkern


# 1.136 09-Aug-2001 eeh

Fix context masking lossage caused by last version.


# 1.135 08-Aug-2001 eeh

Clean up the trap code to handle the changes cause by supporting non-faulting
accesses. Also change the parameter order so trap frames are easy to find.


# 1.134 07-Aug-2001 eeh

Make sure C code always has ASI_PRIMARY_NOFAULT in the %asi register so
the compiler will be happy if it ever starts generating speculative loads.


# 1.133 05-Aug-2001 eeh

Add support for non-faulting loads and optimize MMU miss handling paths.


# 1.132 02-Aug-2001 eeh

Fix bcopy.


# 1.131 02-Aug-2001 eeh

Sync bzero w/libc version.


# 1.130 01-Aug-2001 eeh

Integrate fixes from userland memset.


# 1.129 31-Jul-2001 eeh

Code cleanup and optimization.


# 1.128 23-Jul-2001 eeh

Get rid of some debug code that really isn't all that useful any more.


# 1.127 19-Jul-2001 eeh

Do ignore unregistered interrupts instead of faulting.


# 1.126 16-Jul-2001 eeh

Make bcopy a 32-bit friendly.


# 1.125 11-Jul-2001 eeh

Fix problems booting 32-bit kernels and dispatching level-15 interrupts.


# 1.124 08-Jul-2001 eeh

branches: 1.124.2;
Code cleanup. Add block_disable to let you turn on block set/copy routines.


# 1.123 05-Jul-2001 eeh

New block bzero and bcopy.


# 1.122 04-Jul-2001 eeh

Replace old bcopy with a much faster version.


# 1.121 01-Jul-2001 martin

Disable axidently enabled debug code to make -current compile again.


# 1.120 30-Jun-2001 eeh

Use a newer version (still disabled) of block bcopy.


# 1.119 30-Jun-2001 eeh

Fixup fpu save restore, get rid of some unused copy functions, and add
a new bcopy.


# 1.118 21-Jun-2001 eeh

Allow multiple 4MB pages for both kernel text and kernel data.

Note: DEBUG checks will not allow accesses to the hole between
text and data segments, so you may need to update programs that
use libkvm before relocating the start of kernel data.


# 1.117 06-Jun-2001 mrg

extract the netbsd32, sunos, 32 bit svr4 and 64 bit svr4 sigcode out into
separate files, so that compat lkms can link with them as well.


# 1.116 30-May-2001 lukem

add missing #include "opt_kgdb.h"


Revision tags: thorpej_scsipi_beforemerge
# 1.115 25-Apr-2001 simonb

Spell occurred correctly.


Revision tags: thorpej_scsipi_nbase thorpej_scsipi_base
# 1.114 09-Apr-2001 eeh

Interrupt latency fix from sparc port. (Hm. One insn instead of 5).


# 1.113 07-Mar-2001 eeh

Fix inverted preprocessor logic. (Spotted by Charles.)


# 1.112 21-Feb-2001 eeh

branches: 1.112.2;
Add support for 64-bit SVR4 (Solaris 8) binaries.


# 1.111 10-Feb-2001 pk

Fix conditional for svr4 compat inclusion.


# 1.110 05-Feb-2001 eeh

Add signal trampoline for 64-bit svr4 emulations.


# 1.109 31-Dec-2000 eeh

Make INCR() atomic.


# 1.108 29-Dec-2000 eeh

pseg_get tells us whether it really needed that spare page after all.


# 1.107 07-Dec-2000 eeh

Fixup calculating where fpstate should be saved in the signal trampoline
code so it doesn't overwrite something important like the registers.


# 1.106 09-Nov-2000 eeh

Fix ILP32 bug in probe_get().


# 1.105 22-Oct-2000 pk

Restore revision 1.102.

I hope it sticks this time..


# 1.104 20-Oct-2000 eeh

Fix hang in 32-bit kernels caused by relocation of KERNBASE.


# 1.103 04-Oct-2000 eeh

Fix interrupt lossage problem and some cosmetic changes.


# 1.102 01-Oct-2000 pk

cpu_initialize: global registers aren't preserved across calls to
prom_printf(), so replace %g3 with %l7 (which isn't used despite
the `usage' comment).

Also, clean up white-space turds.


# 1.101 29-Sep-2000 eeh

This seems to fix the interrupt lossage of non-debug kernels.


# 1.100 28-Sep-2000 eeh

Fix INTR_SETUP() to properly distinguish kernel and user addresses.

Make microtime() return the correct time on %tick machines.

Re-enable debug stuff in dostart for now to detect kernel mapping issues.


# 1.99 25-Sep-2000 pk

Missing `#if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)'


# 1.98 17-Sep-2000 eeh

Make the improved %tick changes work with machines that use the counter-timer
for the clock.


# 1.97 12-Sep-2000 eeh

Fix new version of microtime.


# 1.96 11-Sep-2000 eeh

(Hopefully) fix clock skew on machines that us %tick for the clock (UIIi).


# 1.95 31-Aug-2000 eeh

Use casx instead of stx to change entries in the page table trees.


# 1.94 23-Aug-2000 eeh

Update the scheduler to the new locking scheme.


# 1.93 10-Aug-2000 eeh

Fix signal delivery.


# 1.92 02-Aug-2000 eeh

Get kernel profiling to work. Now if only gprof worked....


# 1.91 01-Aug-2000 eeh

Overhaul cache flush code and coredump code.


# 1.90 25-Jul-2000 pk

Re-instate a couple of delay slot NOPs marked `XXX spitfire bug?'


# 1.89 24-Jul-2000 mycroft

Optimization to pmap_zero_page(): we only need to use the first 16 FP regs,
as in bzero().


# 1.88 24-Jul-2000 mycroft

Fix a whitespace glitch.


# 1.87 24-Jul-2000 mycroft

Pull in the bzero() changes from libc for real, with a couple of kernel-
specific hacks:
* Make the bias handling depend on STKB, so it switches correctly for 32-bit
kernels.
* Use the 32-bit stw/ld for 32-bit kernels.
* Add a few `-STKB's that were missed in the previous change.


# 1.86 24-Jul-2000 pk

Cosmetic & readability:
- local label cleanup in interrupt handling code;
- in debugging sections when testing `intrdebug': use a unique
local label (97) to enhanced clarity;
- comment-out unused code;
- kill a bug as the satisfying result of doing all of the above.


# 1.85 24-Jul-2000 eeh

Fix stack issues in bzero.


# 1.84 24-Jul-2000 mycroft

Revert the previous change for now. I don't have time to debug it tonight.


# 1.83 23-Jul-2000 mycroft

Copy bzero change from libc.


# 1.82 20-Jul-2000 pk

Since `intrcnt' points to an array of long ints, reserve the appropriate
amount of space depending on _LP64. Provide macros to load/store signed
and unsigned long ints.

Also, make the `intrcnt' and `intrpending' arrays 16 entries long, as on
sparc/v9 interrupt #15 is just a regular interrupt.


# 1.81 19-Jul-2000 eeh

Fix merge problem.


# 1.80 19-Jul-2000 eeh

Disable interrupt interlock using ih->ih_pending field. Seems to cause
more problems than it solves.


# 1.79 19-Jul-2000 eeh

Miscellaneous cleanup.


# 1.78 18-Jul-2000 pk

Correct args usage comment in probeget.
Whitespace cleanup.


# 1.77 18-Jul-2000 pk

probeget: 9 -> 0x9


# 1.76 18-Jul-2000 pk

If `ih_pending' is set simply return from the trap, don't schedule another
soft interrupt.


Revision tags: mrg-merge-1-5-top
# 1.75 18-Jul-2000 pk

openfirmware: don't lower %pil


# 1.74 17-Jul-2000 pk

Kill typos in interrupt code.


# 1.73 17-Jul-2000 pk

probeget: do the same song and dance as ld*a() macros in ctlreg.h do.


# 1.72 14-Jul-2000 eeh

Move some macro definitions out of genassym and into locore.s


# 1.71 08-Jul-2000 mrg

backout part of previous: turn off intrdebug, and another debug message


# 1.70 07-Jul-2000 pk

Changes for readability:
- #define LP64 dependent STACKFRAME macro once
- use a LOAD_ASCIZ macro for setting up the format string
for debug messages.


# 1.69 07-Jul-2000 eeh

Temporary fix to prevent the clock from stopping on UIIi machines.


# 1.68 03-Jul-2000 eeh

Prevent interrupts from being posted if they are active and deprecate polled
interrupts. This seems to eliminate the spurious interrupts.


# 1.67 02-Jul-2000 eeh

Clean up interrupt handling some more.


# 1.66 30-Jun-2000 eeh

Fix interrupt delivery on UltraSPARC IIi machines.


# 1.65 24-Jun-2000 eeh

With these changes the kernel seems almost stable again.


# 1.64 24-Jun-2000 eeh

More VM cleanup:

Move the cpu_info structure above the interrupt stack so it won't
get corrupted if the stack overflows.

Flush the D$ before and after all MMU bypass accesses since the
D$ latches all of those.


# 1.63 23-Jun-2000 eeh

Make probeget() and probeset() really work for a change.


Revision tags: netbsd-1-5-base
# 1.62 19-Jun-2000 eeh

branches: 1.62.2;
Have separate data and text segments, make text read-only.


# 1.61 12-Jun-2000 eeh

Start reorganizing the kernel for MULTIPROCESSOR support.


# 1.60 31-May-2000 thorpej

Add a comment about needing to initialize p_cpu when multiple
processors are supported.


Revision tags: minoura-xpg4dl-base
# 1.59 26-May-2000 thorpej

branches: 1.59.2;
First sweep at scheduler state cleanup. Collect MI scheduler
state into global and per-CPU scheduler state:

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

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

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

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

Tested on i386 and Alpha. Changes are mostly mechanical, but apologies
in advance if it doesn't compile on a particular platform.


# 1.58 26-May-2000 thorpej

Don't set `runtime' here; it's done at the end of mi_switch().
cvS: ----------------------------------------------------------------------


# 1.57 26-May-2000 thorpej

Introduce a new process state distinct from SRUN called SONPROC
which indicates that the process is actually running on a
processor. Test against SONPROC as appropriate rather than
combinations of SRUN and curproc. Update all context switch code
to properly set SONPROC when the process becomes the current
process on the CPU.


# 1.56 22-Apr-2000 eeh

If we trap due to a bad kernel stack, try to switch to the interrupt strack
before breaking into the debugger.


# 1.55 18-Apr-2000 eeh

Prevent the system from getting watchdog reset by returning directly to user
mode if restoring the user window traps. Also reduce the time we run with
%tl>0.


# 1.54 13-Apr-2000 eeh

Apparently gas 2.9.5 (don't ask) does not like to add values to %lo()
directives so move the additions inside %lo() to make it happy.
Hopefully this won't break older versions.


# 1.53 10-Apr-2000 mrg

- fix a speeling error
- rename some numbered labels to be a bit less confusing.
- remove dead code
- fix a debug error message (argh!)


# 1.52 10-Apr-2000 pk

Get a kernel without DDB to build.


# 1.51 16-Mar-2000 eeh

Revamp interrupts again:

Fix a bug causing interrmittent panics in interrupt dispatch.
Use interrupt vectors for softints.
Add a new send_softint interface.
Improved D$ flushing.
Improve traptrace and other debugging enhancements.


Revision tags: chs-ubc2-newbase
# 1.50 16-Jan-2000 eeh

Interrupt handlers return zero if they didn't handle the interrupt.


# 1.49 10-Jan-2000 eeh

Add debugger single-stepping and fix interrupt dispatch bugs.


# 1.48 30-Dec-1999 eeh

Lots of changes:

remove ffs()
add bzero that uses block store insns
save %gsr to fpstate
revert to physical accesses for pmap_zero_page so we don't
have conflicting page mappings
general cleanup.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base fvdl-softdep-base
# 1.47 06-Nov-1999 eeh

Handle zero length properly in copyinstr() copyoutstr() and copystr().


Revision tags: comdex-fall-1999-base
# 1.46 11-Oct-1999 eeh

branches: 1.46.2; 1.46.4;
Update to post 1.4.


# 1.45 05-Oct-1999 eeh

branches: 1.45.2;
Make broken versions of gas happy by using sethi/or instead of set for
(negative) addresses.


# 1.44 17-Sep-1999 thorpej

Centralize the declaration and clearing of `cold'.


Revision tags: chs-ubc2-base
# 1.43 18-Jul-1999 eeh

More fun with pmap.


# 1.42 21-Jun-1999 eeh

Improve TRAPTRACE. Add FLTRACE that only tracks MMU faults.


# 1.41 05-Jun-1999 eeh

Make pbrobeget() and probeset() work for 64-bit values as well. To do this
the arguments are changed so the address is first and the ASI second so we
can have the address in %o0:%o1 and not worry about unused registers.

Also a bit of copyright cleanup.


# 1.40 05-Jun-1999 mrg

update a commit slightly.


# 1.39 30-May-1999 eeh

Add code to support using %tick as the system clock if no "counter-timer" node
is found.


# 1.38 09-May-1999 eeh

Fixup non-DEBUG kernels.


# 1.37 29-Apr-1999 christos

Add sunos_sigcode (32 bit only)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.36 26-Mar-1999 eeh

branches: 1.36.4;
COMPAT_SPARC32 -> COMPAT_NETBSD32


# 1.35 25-Mar-1999 mrg

clean and up make compile


# 1.34 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.33 22-Mar-1999 eeh

Need to set up the pointers properly for partial FPU register stores.


# 1.32 22-Mar-1999 eeh

Flush D$ on bypass accesses.


# 1.31 28-Feb-1999 eeh

Use block load/store in pmap_zero_page()/pmap_copy_page().


# 1.30 17-Feb-1999 eeh

Let's test out vectored interrupts.


# 1.29 15-Feb-1999 hubertf

RCS ID police


# 1.28 11-Feb-1999 mrg

fix a comment pasto.


# 1.27 11-Jan-1999 eeh

Finally fixed 64-bit signal trampoline.


# 1.26 10-Jan-1999 eeh

Handle the symbol table properly in a 32-bit kernel that was booted from a
64-bit bootloader.


# 1.25 09-Jan-1999 eeh

More signal fixup.


Revision tags: kenh-if-detach-base
# 1.24 26-Nov-1998 mycroft

Sync kcopy() with 32-bit SPARC version.


# 1.23 16-Nov-1998 eeh

Fixup the last broken bits of the signal handling code.


Revision tags: chs-ubc-base
# 1.22 08-Oct-1998 eeh

Fix more syscall32 and signal breakage.


# 1.21 22-Sep-1998 eeh

More fixup in the signal area.

64-bit syscall cleanup.

Add emulation for some new FPU insns: conversion to 64-bit long int and
conditional moves.


# 1.20 17-Sep-1998 thorpej

SYS_sigreturn -> SYS___sigreturn14.


# 1.19 13-Sep-1998 eeh

Fixup signal changes (hopefully). However SUN_COMPAT is likely broken by
this and I don't know how to fix it.

We can now exec a 64-bit init through a really ugly hack (don't ask.)


# 1.18 11-Sep-1998 eeh

Add labels for the compat_sparc32 signal trampoline and break -- er -- fix
suword and fuword.


# 1.17 09-Sep-1998 eeh

Don't use %tick for microtime on 32-bit kernels -- breaks gettimeofday.


# 1.16 09-Sep-1998 thorpej

Adjust for the new "reaper" kernel thread: do not free the vmspace and
u-area in machine-dependent code. Instead, call exit2() to schedule
the reaper to free them for us, once it is safe to do so (i.e. we are
no longer running on the dead proc's vmspace and stack).


# 1.15 07-Sep-1998 eeh

Fix data corruption problem caused by broken debug code.


# 1.14 07-Sep-1998 eeh

Add new 64-bit trap vectors.


# 1.13 06-Sep-1998 eeh

32-bit fixup.


# 1.12 06-Sep-1998 eeh

Disable some debug stuff.


# 1.11 05-Sep-1998 eeh

It slices. It dices. It does everything except exec a sparc32_compat init.


# 1.10 02-Sep-1998 eeh

Periodic update: now starts probing devices.


# 1.9 30-Aug-1998 eeh

Some more 64-bit cleanup. Now everything compiles.


# 1.8 29-Aug-1998 eeh

Some more 64-bit-ification.


# 1.7 27-Aug-1998 eeh

Add 64-bit pmap support:

Moved from a two level 512/1024 entry setup mapping 32 (9/10/13) bits
respectively to a three level 1024/1024/1024 entry setup mapping 43
(10/10/10/13) bits. In 32-bit mode we waste about 1/12 pages mapping the high
11 bits. We also only manage 43 of the possible 44 bits of virtual address
space, wasting half of it. Oh well, maybe we'll do better next revision.


Revision tags: PMAP32
# 1.6 26-Aug-1998 mrg

panicstack: is needed outside of DEBUG. use _C_LABEL, and printf not db_printf (incase no ddb!)


# 1.5 13-Aug-1998 eeh

Merge paddr_t changes into the main branch.


Revision tags: eeh-paddr_t-base
# 1.4 07-Jul-1998 eeh

branches: 1.4.2;
General update:

Added genassym.cf
Removed lderr which should never have gotten in
Removed lots of dead code from locore.s
Added some softint stuff to intr.c
Added support for halt -p
esp and le both use bus_dmamap_*() functions now
instead of kdvma_mapin()
groundwork for PCI (but we still have no drivers for
any sun4u PCI devices)


# 1.3 04-Jul-1998 jonathan

defopt DDB.


# 1.2 26-Jun-1998 thorpej

defopt COMPAT_SVR4


# 1.1 20-Jun-1998 eeh

branches: 1.1.1;
Initial revision


# 1.409 19-Feb-2017 palle

sun4v: rft_user needs special handling (a manual fill) since the restore instruction may cause the number of trap levels to exceed the maximum for sun4v - inspired by code from the the openbsd rft_user code path - verified using qemu for both sun4u and sun4v


# 1.408 10-Feb-2017 palle

sun4v: Added handling of trap type 0x034 (address alignment error) + fixed typo mmfsa -> mmufsa. Verified for both sun4u and sun4v using qemu.


Revision tags: nick-nhusb-base-20170204
# 1.407 30-Jan-2017 palle

sun4v: Hook up syscall handling to the trap table. Verified using qemu for both sun4u and sun4v.


# 1.406 27-Jan-2017 palle

sun4v: implement missing handling of itsb traps 0x008 and 0x009. Based on code from OpenBSD. Tested using qemu.


Revision tags: bouyer-socketcan-base
# 1.405 07-Jan-2017 palle

sun4v: slowtrap() now selects normal globals properly on both sun4u and sun4v platforms. Verified using qemu for both sun4u and sun4v systems


Revision tags: pgoyette-localcount-20170107
# 1.404 05-Jan-2017 palle

sun4v: TRAP_SETUP() updated to set mmu context id properly for both sun4v and sun4u platforms. Verified using qemu for both sun4u and sun4v systems


# 1.403 04-Jan-2017 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x00-0x23 and 0x28-0x30


# 1.402 29-Dec-2016 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x32-0x7f


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.401 20-Sep-2016 nakayama

Fix RAS for 32-bit kernels. trapframe is always 64-bit.


Revision tags: localcount-20160914
# 1.400 23-Aug-2016 palle

sun4v: rework sun4v_datatrap so it works properly when running on a T2-based system like T5120 - for some reason %tl is 0 when entering sun4v_datatrap causing a crash (sir instruction), so ignore the %tl value for now upon entry to sun4v_datatrap - with this fix both T1 and T2 based systems reach the same point - hangs in rft_user after the init process is started


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726
# 1.399 18-Jul-2016 palle

sun4v: handle device interrupts properly - both legacy (sysino) and cookies


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 1.398 04-Jun-2016 palle

branches: 1.398.2;
sun4v: rtf_user now uses macros GET_MMU_CONTEXTID and SET_MMU_CONTEXTID. Tested on sun4u (QEMU) and sun4v (T2000). Parts from OpenBSD.


Revision tags: nick-nhusb-base-20160529
# 1.397 18-May-2016 nakayama

Decrement %tl in trap handler not to make it zero unconditionally
for the nested trap, and remove useless mov.


# 1.396 17-May-2016 palle

sun4v: Implement missng MMU protection trap handling - mostly from OpenBSD


# 1.395 16-May-2016 palle

Avoid assembler-specific defines by using the export keyword in genassym.cf instead


# 1.394 15-May-2016 nakayama

%g1 is not preserved across function call, so load it before
return_from_trap.


# 1.393 13-May-2016 palle

sun4v: add missing implementation of sun4v_datatrap_tl0 so data_access_fault() is called - mostly from OpenBSD


# 1.392 13-May-2016 nakayama

- ci_paddr is always 64-bit.
- intrlev is array of pointer.
- ih_ack is pointer.


# 1.391 10-May-2016 palle

sun4v: make device interrupts work. Introduce a new intrhand_alloc() function for allocation of interrupt handlers and adapt to this. Parts from OpenBSD. ok martin@


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.390 09-Mar-2016 nakayama

32-bit kernels use 32-bit stack.


# 1.389 03-Mar-2016 palle

sun4v: rft_kernel should pay attention to the number of register windows that can be restored. We cannot rely on fill traps to occur, since sun4v only has two trap levels available in privileged mode. Based on code from OpenBSD. ok martin@


# 1.388 14-Feb-2016 palle

sun4v: add breakpoint trap entry to the sun4v trap table


# 1.387 03-Feb-2016 palle

sun4v: extend dmmu_set_secondary_context() to handle both sun4u and sun4v. ok martin@


Revision tags: nick-nhusb-base-20151226
# 1.386 06-Nov-2015 martin

Basically revert r1.246 of locore.s and r1.73 of vm_machdep.c:

Remove special case handling for userland lwps from cpu_lwp_fork,
instead do it in lwp_trampoline when we first return to userland.

which was a stupid idea - since we did now set all fork child's %tstate
(and thus %pstate when back in userland) to the current kernel's userland
default. This meant we lost the address mask bit for 32bit processes and
all memory model details for 64bit ones.

Move it back to cpu_lwp_fork and fix the condition to only do it once when
forking init.


# 1.385 05-Nov-2015 martin

Most of the time return_from_trap already got called with tf->tf_tstate
loaded in register %g1 - make it so for two more callers and remove
the reload of that value.


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606 nick-nhusb-base-20150406
# 1.384 05-Apr-2015 palle

sun4v: Ensure that the TTEs CP and CV bits are the same (both set) for the primary cpu and secondary cpus INTSTACK mappings


# 1.383 01-Apr-2015 palle

sun4v: Implement handling of cpu_mondo trap - from OpenBSD - tested using the Legion simulator


# 1.382 04-Mar-2015 palle

sun4v: revert some of the logic introduced in revision 1.378 - flushw is not necessary on sun4v (OpenBSD patches the flushw instruction to a nop instruction) - with these changes the kernel reaches cpu_boot_secondary_processors() when running in the Legion simulator (crashes due to missing handling of cpu_mondo_trap)


# 1.381 02-Mar-2015 nakayama

prom_printf converts "\n" to "\r\n" internally, so omit "\r".


# 1.380 02-Mar-2015 nakayama

PANICSTACK is a pointer itself, not a pointer to pointer.


# 1.379 02-Mar-2015 nakayama

Use panic stack temporarily for calling prom_printf in a trap
handler.

It seems that openfirmware cannot handle over 4GB pointers, and
stack pointers may point to over 4GB since VA layout was rearranged
by rev 1.33 of vmparam.h. Therefore, use panic stack to avoid
panicking in OF_write used by prom_printf.


# 1.378 23-Feb-2015 palle

sun4v: sparc_interupt - ensure that the trap level and globals level are the same when the flushw instruction is issued - othwise warnings occur when using the sun4v Legion simulator.


Revision tags: nick-nhusb-base
# 1.377 26-Oct-2014 palle

branches: 1.377.2;
sun4v: Create CLEANWIN0 and CLEANWIN1 macros for handling clean window traps on both sun4u and sun4u (based on the original code inlined in the sun4u trap table). Update trap tables accordingly for both sun4u and sun4v. Ok martin@


# 1.376 24-Oct-2014 nakayama

Fix typo in comment.


# 1.375 18-Oct-2014 snj

src is too big these days to tolerate superfluous apostrophes. It's
"its", people!


# 1.374 15-Oct-2014 palle

sun4v: fixed bug causing the real address to be incorrectly calculated as zero


# 1.373 24-Sep-2014 palle

sun4v: add code to enable startup of secondary cpus on both sun4u and sun4v systems - ok martin@


# 1.372 04-Sep-2014 palle

sun4v: All cpus must be setup with a TSB descriptor, so pmap_setup_tsb_sun4v() must take a pointer to the TSB descriptor


# 1.371 31-Aug-2014 palle

sun4v: Split the NORMAL_GLOBALS and ALTERNATE_GLOBALS macros to _SUN4U and _SUN4V variants. Rework the return_from_trap logic to use the new variants so it is possible to use a global register as scratch register.


# 1.370 14-Aug-2014 nakayama

Add missing delay slot in DEBUG kernel.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.369 30-Jul-2014 palle

branches: 1.369.2;
Fix ALTERNATE_GLOBALS so it at least works on sun4u - using a scratch register is not a good idea...


# 1.368 27-Jul-2014 palle

sun4v: Introduce a new macro ALTERNATE_GLOBALS (matching NORMAL_GLOBALS). Two new helper macros ENABLE_INTERRUPTS and DISABLE_INTERRUPTS are also created. With these changes the GENERIC.UP kernel will reach rootmount on sun4v systems - ok martin@


# 1.367 26-Jul-2014 palle

Improved the NORMAL_GLOBALS macro in the sun4u case, so only the relevant bit (AG) in %pstate is affected - ok martin@


# 1.366 24-Jul-2014 palle

sun4v: add missing spill/fill handling for trap level 1 + cosmetic changes to comments for trap level 0 entries


# 1.365 19-Jul-2014 palle

sun4v: Introduce a NORMAL_GLOBALS macro - first used in sparc_interrupt - other relevant uses will be handled as the sun4v work is progressesing - ok martin@


# 1.364 16-Jul-2014 palle

sun4v: Introduce SET_MMU_CONTEXTID macro for setting the mmu context id on both sun4u and sun4v


# 1.363 13-Jul-2014 palle

sun4v: add interrupt handling to sun4v trap table


# 1.362 13-Jul-2014 palle

Bugfix: add missing cmp instruction to GET_MAXCWP macro


# 1.361 30-Jun-2014 palle

sun4v: The maximum number of register windows is a constant and thus not available via the %ver register (sun4u only). Introduce a macro GET_MAXCWP that handles this, so cpu_switchto() works properly on sun4v. Other relevant reference to %ver can be adapted to use GET_MAXCWP as the sun4v port progresses. OK martin@


# 1.360 31-May-2014 palle

sun4v: added missing dtsb miss handling for trap level 1 - with this update the kernel now reaches configure() on sun4v systems


# 1.359 30-May-2014 palle

Remove debugging code introduced by accident in locore.s revision 1.357


Revision tags: yamt-pagecache-base9 rmind-smpnet-nbase rmind-smpnet-base
# 1.358 05-May-2014 palle

sun4v: the trap base address should be assigned to %l1 so %tba is properly setup later in the code - now the kernel gets as far as printing the copyright disclaimer, kernel version and total and available memory before crashing


# 1.357 21-Apr-2014 palle

sun4v: Update comment: modified -> access


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.356 21-Feb-2014 palle

branches: 1.356.2;
sun4v: Rename TLB_ defines to SUN4U_TLB_ so entries created using TSB_DATA() are properly setup for sun4u and sun4v. Relocate the cputyp variable from autoconf.c to locore.s and make it const in param.h so optimized code can be generated. Parts from OpenBSD. Optimization suggested by nakayama@. OK martin@, mrg@, nakayama@


# 1.355 31-Jan-2014 tsutsui

defined(LKM) -> defined(MODULAR)


# 1.354 26-Jan-2014 palle

sun4v: Add handling of spill/fill and dtsb miss traps (with a XXX to be handled later)


# 1.353 07-Jan-2014 palle

sun4v: trap table setup - currently populated with dummy entries which will be properly implemented later - parts from OpenBSD - OK martin@


# 1.352 29-Dec-2013 nakayama

Make buildable w/o options SUN4V.


# 1.351 27-Dec-2013 palle

a) make the hunt through the cpus list more generic b) sun4v: ensure that the interrupt stack is mapped permanently and the TSB is setup properly - parts from OpenBSD. OK martin@


# 1.350 06-Dec-2013 nakayama

Increase an interrupt depth only in the case of hardware interrupts,
and remove the ci_idepth trick in softint_fastintr.

Fixes the following diagnostic panic reported in port-sparc64.

panic: kernel diagnostic assertion "!cpu_intr_p()" failed: file
"../../../../kern/subr_xcall.c", line 351


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 1.349 24-May-2013 nakayama

branches: 1.349.2;
Disable interrupts after calling data_access_error as with
data_access_fault.


# 1.348 28-Apr-2013 nakayama

Use macros in machine/asm.h instead of locally defined, and
introduce CASPTRA for casxa/casa.


Revision tags: agc-symver-base
# 1.347 23-Jan-2013 martin

Fix sparc64_ipi_ccall by adding proper trap setup.
Fixes xcall(9) problems, as exposed by pserialize(9). Noticed by
J. Hannken-Illjes, cause pointed out by Takeshi Nakayama.


# 1.346 23-Jan-2013 martin

Sligthly clean up the (by default unused) #ifdef TRAPS_USE_IG


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.345 10-Nov-2012 nakayama

Revise comment.


# 1.344 10-Nov-2012 nakayama

Use macro instead of magic number.


# 1.343 09-Nov-2012 nakayama

Make setstick() and getstick() to inline functions.


# 1.342 08-Nov-2012 macallan

use system tick timer instead of %tick on UltraSPARC-III-ish CPUs
review & fixes by Takeshi Nakayama


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.341 17-Mar-2012 mrg

branches: 1.341.2;
port the corrected ECC error handling code from freebsd. i noticed my U10
took one of these and then hang. it shouldn't hang, there's a 'sir' here that
doesn't seem to reset properly. oh well.

tested by simulated a trap via 'ta 0x10' and considering that the same, but
it hasn't been tested against a real ECC error yet.


Revision tags: jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base4
# 1.340 03-Mar-2012 nakayama

Fix the root cause of the hack "disable optimizations for uvm_bio.c
on 32 bit kernels".

gcc converts a division in the calculation of UBC_UMAP_ADDR macro
to multiplication (smul or combination of add/sll), and the
register of its result contains a garbage in upper 32 bits (the
upper 32 bits of smul/add/sll's result isn't zero cleared).

Then it passes to pseg_get{,_real} through pmap_extract without the
zero clear of upper 32 bits in the optimization case. So the
result of pseg_get and pmap_extact sometimes gets screwed up.


Revision tags: jmcneill-usbmp-base5 jmcneill-usbmp-base3
# 1.339 19-Feb-2012 rmind

Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.


Revision tags: jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.338 04-Sep-2011 nakayama

branches: 1.338.2; 1.338.6; 1.338.8;
ih_pil is an interrupt level, not an interrupt mask.


# 1.337 27-Jul-2011 nakayama

ivec is assigned to hardware, so count its event counter up in
interrupt_vector, not in softint, and do some optimization.


# 1.336 20-Jul-2011 macallan

add per ivec event counters


# 1.335 12-Jul-2011 mrg

rename sparc64 BLOCK_SIZE and BLOCK_ALIGN to have SPARC64_ prefixes.
for the assembler files, define the old names to the new names
since using the new names cause ugliness due to longer identifer
names, and reduces churn.

fixes build issues in dtv and vaguely makes <machine/psl.h> slightly
less name-space invasive.


# 1.334 18-Jun-2011 nakayama

Add fast softint(9) support for sparc64.

Reviewed on port-sparc64.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 1.333 12-May-2011 mrg

branches: 1.333.2;
first steps towards fujitsu SPARC64 support:

- SPARC64 systems have interrupts with upto 14 bits set, but we only look
at the first 11 bits. trim non IPI interrupts to 11 bits


Revision tags: uebayasi-xip-base7 bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 jym-xensuspend-nbase jym-xensuspend-base
# 1.332 20-Dec-2010 matt

branches: 1.332.2;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.


Revision tags: uebayasi-xip-base6 uebayasi-xip-base5 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 1.331 10-Jul-2010 nakayama

Clear the upper word explicitly before combining two 32-bit values to 64-bit
on 32-bit kernels.


# 1.330 23-May-2010 martin

Split copy related functions out of locore.s into copy.S, move functions
only needed on multiprocessors into mp_subr.S.


# 1.329 17-May-2010 martin

Simplify primary CPU startup slightly by using the fact that our cpuinfo's
curpcb pointer points to the uarea/pcb of lwp0 and by remembering the pointer
to this cpuinfo, thus avoiding a few CPUINFO_VA references.


Revision tags: uebayasi-xip-base1
# 1.328 20-Mar-2010 chs

fix copy{in,out}{,str}() to return the error returned by uvm_fault().
fixes PR 41813.


Revision tags: yamt-nfs-mp-base9
# 1.327 10-Mar-2010 mrg

branches: 1.327.2;
XXX: workaround we'd like to remove when pmap / uvm locking is cleaned up:

- rename pseg_get() and pseg_set() to pseg_get_real() and pseg_set_real().
- if USE_LOCKSAFE_PSEG_GETSET is defined, which it current is by default,
define pseg_[gs]et() in terms of functions that take a new pseg_lock
mutex at IPL_VM while calling into the real functions.

this seems to avoid the pseg_set() crashes we've seen:
1 - spare needed, when pseg_get() just worked for this pmap
2 - the 2rd ldxa via ASI_PHYS_CACHED in pseg_set() loads garbage
into %o4, and causes the 3rd ldxa to fault


# 1.326 08-Mar-2010 mrg

blast_dcache() SMP friendly:

- blast_dcache() becomes sp_blast_dcache(dcache_size, dcache_line_size)
- new smp_blast_dcache(sparc64_cpuset_t) that blasts the D$ on this cpuset
- sparc64_ipi_blast_dcache() to support the above
- in pmap_remove_all(), when freeing mmu contexts for this pmap, mark
the set of cpus to blast the d$ on as well and convert the
blast_dcache() call into smp_blast_dcache() on the cpus who ran this
pmap, or, sp_blast_dcache(dcache_size, dcache_line_size)
- convert the remaining blast_dcache() in machdep.c to sp_blast_dcache()
- in pmap_destroy()/pmap_remove_all() take the pmap_lock() always since
we assert it is held always.

with these changes, NFS builds on the U60 seem to be stable now, and
the USIII machines also can often complete a single build.sh run now,
diskful or diskless.


reviewed by mlelstv and partially by martin, tested by martin and myself,
with some ideas from chuq as well.


# 1.325 07-Mar-2010 mrg

need _ALIGN in locore.h as well, for DEBUG kernels.


# 1.324 07-Mar-2010 mrg

gas has supported SPARC ".empty" for a long while; get rid of an
ancient workaround.


# 1.323 06-Mar-2010 mrg

move the memcpy/memset implementations out into their own file, with the
block copy versions as well. move some of the definitions in locore.s
into a new locore.h.

locore.s is almost 2000 lines shorter with this change.


# 1.322 04-Mar-2010 mrg

- in _bus_dmamap_unload(), pmap_page_protect() and pmap_clear_reference()
switch the dcache_flush_page() into a dcache_flush_page_all()
- in both pmap_kremove()/pmap_remove(), remove the blast_dcache() call
and replace it with dcache_flush_page_all()
- in pmap_get_page() [used to allocate PTP's], always call pmap_zero_page(pa)
- flush the dcache of the dst page in pmap_{copy,zero}_page() by redirecting
throught a C function that calls the (renamed) asm. the old asm code had a
comment about needing to do this...
- add a couple of membar #Sync's that the USIII manual recommends


based on discussions with chuq@, skrll@ and martin@.


these help my SB2000 / SB2500 with both disk / nfs builds and other tasks,
sometimes lasting for several hours before failing or asserting.


# 1.321 24-Feb-2010 mrg

when handing back page table pages to UVM, flush them from the dcache
on all CPUs.

idea from skrll@, and makes my disk-based SB2000 stable.

tested on U60, SB2000 and SB2500.


# 1.320 24-Feb-2010 mrg

- re-introduce sp_tlb_flush_pte() and sp_tlb_flush_all() that call
the right USI/USIII version.
- define tlb_flush_pte() in terms of sp_tlb_flush_pte() for the
!MULTIPROCESSOR case

this centralises some CPU_IS_USIII_UP() tests.


# 1.319 22-Feb-2010 mrg

move {dump,print}_[id]tlb() into a separate file.


# 1.318 22-Feb-2010 mrg

- store the maximum [id]cache size / line size for each cpu

- remove patch_kernel() since it isn't necessary and has been patching
the wrong thing in general.

- implement USIII versions of blast_icache(), dcache_flush_page() and
cache_flush_phys(). use the newly recorded cache size/line sizes.

- in winfixsave, flush the D$ with the right size index and ops. this
kills one of the wrong tag->inval patches.

- for blast_dcache(), use the newly recorded dcache_size/line_size.

- for blast_icache(), use the newly recorded cache size/line sizes.
for the USIII verison, disable the I$ while writing to ASI_ICACHE_TAG.


these changes removed several hard coded cache sizes values, some very
wrong kernel patching, and seem to make the current failure modes for
USIII less common, but not gone.


# 1.317 15-Feb-2010 mrg

- don't flush 32-bit entries for 64-bit code, it does not seem to be
necessary. #define TLB_FLUSH_LOWVA to turn it back on.
- remove the #if 0'd code in sparc64_ipi_flush_pte_usiii(), i have
verified that it is not required.
- add a missing membar #Sync to sp_tlb_flush_pte_usiii().


# 1.316 15-Feb-2010 nakayama

Fix linker error of GENERIC32 kernel.


# 1.315 15-Feb-2010 mrg

use TLB_SIZE_SPITFIRE in a couple of places, and note that the
{print,dump}_[id]tlb() versions are currently spitfire specific.


# 1.314 15-Feb-2010 mrg

introduce a new patch_kernel() and call it from the end of bootstrap().
use it to patch up TLB flush instructions that don't match for USI/II
and later. we can also hopefully use this to make GENERIC.MP minimally
expensive on single CPU machines as well.

this is the last piece needed to get GENERIC/GENERIC.MP to boot on the
USIII* machines.

idea and some initial code from openbsd.


# 1.313 13-Feb-2010 mrg

remove KTR support. it's never been a working part of netbsd src tree.


# 1.312 09-Feb-2010 wiz

Fix typo in comment.


Revision tags: uebayasi-xip-base
# 1.311 06-Feb-2010 mrg

branches: 1.311.2;
- properly map the schizo interrupt registers, so we can use the normal
virtual mappings to access them.
- with the above fxied, kill SCHIZO_BUS_SPACE_BROKEN, and introduce
an options CHEETAH for now, that disables the SPITFIRE code in locore.
- merge schizo_init() into schizo_attach() and clean up the softc a bit.


with this we are only one more step away from GENERIC booting on USIII
machines.


# 1.310 02-Feb-2010 mrg

- split sp_tlb_flush_pte() and switchtoctx() into sp_tlb_flush_pte_us()/
sp_tlb_flush_pte_usiii() and switchtoctx_us()/switchtoctx_usiii() and
implement the latter while i'm here. it works ... sometimes i think,
but also sometimes panics/hangs.
- fix a comment in sparc64_ipi_flush_pte_usiii()


# 1.309 02-Feb-2010 mrg

for now, reduce a few #ifdef SPITFIRE cases by introducing a new
ASI_DCACHE_TAG_OR_INV that is either ASI_DCACHE_{TAG,_INVALIDATE}.

increase the common code in cache_flush_phys().


# 1.308 01-Feb-2010 mrg

- sp_tlb_flush_all() becomes sp_tlb_flush_all_us() and sp_tlb_flush_all_usiii()
- sparc64_ipi_flush_pte() becomes sparc64_ipi_flush_pte_us() and
sparc64_ipi_flush_pte_usiii()
- add some commented out code to disable interrupts and raise the traplevel
in sparc64_ipi_flush_pte_usiii()
- cache_flush_phys() was missing a little of code in the cheetah case


# 1.307 01-Feb-2010 mrg

for USIII, use the new "tlb demap all" operation in sp_tlb_flush_all()


# 1.306 01-Feb-2010 mrg

remove unused icache_flush_page() implementation.


# 1.305 23-Jan-2010 mrg

remove the final uses of DATA_START.

now we can remove the 16KB space reserved at the start of the data segment,
and i now understand why i wrote this now removed comment 3.5 years ago:
"this shouldn't be needed... but kernel usually hangs without it"


# 1.304 23-Jan-2010 mrg

remove most of the code that writes debugging info DATA_START + offset.


# 1.303 23-Jan-2010 mrg

remove CHKPT() macro and uses. it's likely wrong in SMP land and probably should
be replaced with KTR-style uses if necessary.


# 1.302 23-Jan-2010 mrg

fix a comment.


Revision tags: matt-premerge-20091211
# 1.301 10-Dec-2009 rmind

Rename L_ADDR to L_PCB and amend some comments accordingly.


# 1.300 05-Dec-2009 mrg

- adjust the PA mask to the 43 bits supported by USIII.
- rework the spitfire/cheetah cache_flush_phys() to avoid several #ifdefs
- add a membar #Sync after sparc64_ipi_drop_fpstate (probably unnecessary)


# 1.299 30-Nov-2009 nakayama

sp_tlb_flush_pte for cheetah:
- restore interrupts properly in case of %tl > 0.


# 1.298 30-Nov-2009 mrg

stablize UP USIII support by blocking interrupts around sp_tlb_flush_pte()
i was seeing stack corruption while taking an interrupt in this function.

get USIII SMP mostly working by implementing the cheetah version of
sparc64_ipi_flush_pte().


SMP support is still not entirely stable. i can reproducably get a:

panic: fpusave_lwp ipi didn't

while running build.sh, when an awk process is exiting. other simple
heavy work loads do not crash for me right now.


# 1.297 30-Nov-2009 mrg

delete some no longer used code:
- smp_tlb_flush_ctx()
- smp_tlb_flush_all()
- sparc64_ipi_flush_ctx()
- sparc64_ipi_flush_all()
- sp_tlb_flush_ctx()


# 1.296 29-Nov-2009 nakayama

- calculate end PA correctly.
- wrap more spitfire specific (flushing I$) code.
- fix inverted #if condition for flushing I$ (and restore ASI_ICACHE_TAG).


# 1.295 28-Nov-2009 mrg

implement enough code to get SB2000/SB2500 booting to multiuser. does
not last long if you use it, but an idle machine has stayed up 10 hours.

- for the !SPITFIRE case, use ASI_DCACHE_INVALIDATE instead of
ASI_DCACHE_TAG when clearing tlb entries. from openbsd.

- convert some comment "! Not yet" into "WRITEME", so that attempting
to build a USIII MULTIPROCESSOR kernel fails to build until the code
is written.

- add some more WRITEME's for the above.

- implement a !SPITFIRE version of sp_tlb_flush_all(). since there are
no spare regs, for now just always increase %tl around this call. (we
could maybe store a token in %o3 along with the saved %pstate info.)


# 1.294 26-Nov-2009 matt

Kill proc0paddr. Use lwp0.l_addr instead.


# 1.293 25-Nov-2009 mrg

s/L_ADDR/L_PCB/, requested by rmind.


# 1.292 17-Oct-2009 nakayama

Wrap unused code with #if 0 which is called from #if 0'ed code.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5
# 1.291 30-May-2009 martin

cpu_setfunc() can not use lwp_trampoline, as that has additional lwp startup
semantics. Use a simpler setfunc_trampoline instead.


# 1.290 18-May-2009 nakayama

Remove random() from locore.s since it is in libkern.


# 1.289 16-May-2009 nakayama

Remove clear %tick in locore.s since it is cleared at cpu_initclocks() in
clock.c.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 nick-hppapmap-base mjf-devfs2-base
# 1.288 15-Dec-2008 mrg

restore some old "intrdebug" code, but leave it under NOT_DEBUG. most
of it works, but one that prints func/arg for each handler is not very
stable...

for now, while schizo bus space pointer accesses aren't working, add
a SCHIZO_BUS_SPACE_BROKEN option so you can build a kernel with schizo.

with this, and the prior schizo interrupt fix, you can now fail to run
/sbin/init!


Revision tags: haad-dm-base2 haad-nbase2 haad-dm-base
# 1.287 09-Dec-2008 martin

Get rid of get_maxctx() - it doesn't work on newer cpus and we will have
to find a better way for (some) sun4v machines - all sun4u use 13 bit
contexts anyway.


Revision tags: netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 ad-audiomp2-base netbsd-5-base
# 1.286 30-Oct-2008 nakayama

branches: 1.286.2; 1.286.6;
Wrap more code specific to USE_BLOCK_STORE_LOAD.


Revision tags: matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4
# 1.285 05-Oct-2008 nakayama

branches: 1.285.2;
- in flushing cache, use 32 as increment/decrement value to match the
cache line size.
- remove useless restore of %asi.
- remove nop in delay slot if we can.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 1.284 10-Jul-2008 nakayama

Use proper CCR.


# 1.283 10-Jul-2008 nakayama

sparc64_ipi_save_fpstate:
- use primary MMU context for consistency with other trap/interrupt handlers.

sparc64_ipi_save_fpstate, savefpstate:
- avoid storing fp registers as we can.

sparc64_ipi_save_fpstate, savefpstate, loadfpstate:
- remove unaligned case since buffers allocated with pool_cache are ensured
64-byte aligned.

Ok by martin@.


# 1.282 02-Jul-2008 nakayama

branches: 1.282.2;
UltraSPARCs don't have floating point queue, and reading %fq regsiter
will cause illegal instruction trap. So remove the code handling them.


# 1.281 29-Jun-2008 nakayama

Wrap IPI calls with #ifdef MULTIPROCESSOR.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.280 14-Jun-2008 nakayama

Close unterminated comment.
Fix unexpected behavior in case of loadfpstate from unaligned buffer.


Revision tags: yamt-pf42-base3
# 1.279 31-May-2008 nakayama

branches: 1.279.2;
openfirmware_exit:
- disable interrupts with %pstate.
- prepare 64-bit stack and enable 64-bit addresses for 32-bit SMP kernels.


Revision tags: hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 yamt-nfs-mp-base yamt-pf42-base
# 1.278 16-Apr-2008 nakayama

branches: 1.278.2; 1.278.4; 1.278.6;
Disable TRAPSTATS which was accidentally enabled when yamt-idlelwp branch
was merged.

Ok by martin@.


# 1.277 14-Apr-2008 nakayama

Remove sparc64_ipi_sync_tick.

Since we can use counter-timer as timecounter instead of %tick on SMP kernel,
it is not necessary to sync all CPUs %tick registers.


# 1.276 14-Apr-2008 nakayama

Add workaround for BB_ERRATA_1 on writing to TICK_CMPR register in
next_tick(). If writing to TICK_CMPR fails, we lose hardclock interrupt
on secondary CPUs.

About BB_ERRATA_1 from comment in OpenSolaris:

/*
* Writes to the TICK_COMPARE register sometimes fail on blackbird modules.
* The failure occurs only when the following instruction decodes to wr or
* wrpr. The workaround is to immediately follow writes to TICK_COMPARE
* with a read, thus stalling the pipe and keeping following instructions
* from causing data corruption. Aligning to a quadword will ensure these
* two instructions are not split due to i$ misses.
*/


# 1.275 28-Mar-2008 nakayama

Don't read fplwp content in delay slot for considering the case fplwp was
modifiled.

Reported by Chris Ross on port-sparc64.


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.274 20-Mar-2008 nakayama

- remove disabling interrupt in IPI.
- unused VA bits in MMU demap is 13 bits, not 12 bits.


# 1.273 18-Mar-2008 nakayama

Fix a race when increment an interrupt level event counter.


# 1.272 17-Mar-2008 nakayama

Fix a race condition in IPI handlers of save/drop fpstate, from OpenBSD.
Reported and tested by martin@.


# 1.271 17-Mar-2008 nakayama

Make schedintr interrupt handler per-CPU.
While there rename tickintr interrupt handler and share initialization
code with schedintr.


# 1.270 14-Mar-2008 nakayama

Improve IPI handling:
- make IPI takes two arguments.
- add IPI event counters per-CPU.
- implement IPI functions which were missing or broken.
- insert DELAY while halting primary CPU in IPI handler.


# 1.269 02-Mar-2008 nakayama

- make interrupt pending list per-CPU.
- make tickintr() MP-safe.
- remove unused port-sparc derived interrupt code.

Ok by martin@.


# 1.268 02-Mar-2008 nakayama

Don't get IPI handler argument (from bogus address), and ack IRQ twice.


# 1.267 28-Feb-2008 martin

Make TSBs and MMU contexts per-cpu.


Revision tags: nick-net80211-sync-base mjf-devfs-base hpcarm-cleanup-base
# 1.266 26-Jan-2008 nakayama

branches: 1.266.2; 1.266.6;
Fix for 32-bit kernels.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.265 15-Jan-2008 skrll

Store a sensbile PCB_PC value in snapshot - the return point.

This helps gdb somewhat.

OK'd by martin.


# 1.264 14-Jan-2008 martin

Fix register name typo/copy&pasto - %g6 is not %o6/%sp.
From OpenBSD.


Revision tags: matt-armv6-base
# 1.263 06-Jan-2008 martin

Load the next cpu_info pointer with LDPTR instead of ld.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2
# 1.262 09-Dec-2007 martin

branches: 1.262.2;
Provide cpu_intr_p(), at least for non-MULTIPROCESSOR kernels.
Based on suggestions by Andrew Doran.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.261 22-Oct-2007 martin

branches: 1.261.2; 1.261.4; 1.261.6;
Remove an unused .globl declaration


Revision tags: yamt-x86pmap-base4
# 1.260 17-Oct-2007 garbled

Merge the ppcoea-renovation branch to HEAD.

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

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

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base ppcoea-renovation-base vmlocking-base
# 1.259 09-Sep-2007 martin

branches: 1.259.4;
Make cpufrequency and friends per cpu values.
Prepare a hz tick interrupt on secondary CPUs via %tick, but do not
enable it yet, as it breaks ddb.


# 1.258 09-Sep-2007 martin

Do not ACK IPIs before we finished loading all arguments.


# 1.257 06-Sep-2007 martin

Remove the (now unused) second 64k page mapped per CPU.
From matthew green, with small changes by me. All bugs are mine.


# 1.256 25-Aug-2007 martin

branches: 1.256.2;
Remove INITSTACK completely - at the time we used to switch to it, we
already have access to all of lwp0 and it's uarea - so we can switch
to the correct lwp0 stack easily before calling main.


# 1.255 25-Aug-2007 martin

When exiting to OF, use the interrupt stack instead of INITSTACK


# 1.254 25-Aug-2007 martin

Rework cpu_mp_startup slightly:
- temporarily use the cpu's interrupt stack untill we are ready
to access non-OF-based mappings, then directly switch to the cpu's
idlelwp's uarea stack
- disable interrupts untill we are ready to call C code


# 1.253 13-Aug-2007 macallan

remove two restore without matching save


Revision tags: nick-csl-alignment-base matt-mips64-base mjf-ufs-trans-base
# 1.252 06-Jul-2007 martin

branches: 1.252.4; 1.252.8;
A few nits for 32bit SMP kernels, noticed by mrg.
While there, simplify the fpstate IPIs a bit.


# 1.251 05-Jul-2007 martin

sparc64_ipi_save_fpstate is not a leaf function - create a full grown
stack frame.


# 1.250 28-May-2007 mrg

clean up cpu_switchto() a little - no need to flushw or membar
excessively. optimise an rdpr. tested by tnn.


# 1.249 23-May-2007 martin

Fix a stupid bug in the save_fpstate ipi, which caused overwriting of
struct lwp of the lwp owning the fpu. Fix clearing the fplwp - %o0 will
not survive the call to savefpstate - duh!


# 1.248 20-May-2007 martin

Simplify tf_tstate setting when leaving for userland initially - I seem
to have confused the if with the else case of the previous C code.
Funny that it worked at all.


# 1.247 20-May-2007 martin

cpu_switchto() has to return it's first arg, always. This differs from
my reading of the documentation, but helps in the real world and seems
to be what other ports do.


# 1.246 20-May-2007 martin

Remove special case handling for userland lwps from cpu_lwp_fork, instead
do it in lwp_trampoline when we first return to userland.


# 1.245 19-May-2007 martin

cpu_idle is a leaf function, so we better "return from leaf".
Use return value from cpu_switchto for previous lwp in lwp_trampoline.
Also shamelessly steal a comment from uwe written for sparc that explains
all this.
Thanks to tnn, mrg, and uwe for helping to debug this.


# 1.244 17-May-2007 yamt

merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base ad-audiomp-base
# 1.243 22-Feb-2007 martin

branches: 1.243.4; 1.243.6; 1.243.12;
uvm.page_idle_zero now is a bool, not a 32bit value any more.


# 1.242 21-Feb-2007 mrg

shave 9 insns off the tsb setup in cpu_initialize & cpu_mp_startup.


# 1.241 21-Feb-2007 martin

Get rid of unused (thus always zero) "curlwp" variable hidden in assembler
code (C code always uses a cpuinfo based macro).


# 1.240 18-Feb-2007 martin

Make use of another call delay slot, pointed out by uwe.


# 1.239 18-Feb-2007 martin

Make use of a call delay slot and avoid a bogus EMPTY.
Spotted by Juergen Hannken-Illjes, with input from Andrew Doran and
Valeriy E. Ushakov.


# 1.238 18-Feb-2007 martin

Whitespace cosmetics


# 1.237 18-Feb-2007 martin

Backout previous: EMPTY was misused


# 1.236 18-Feb-2007 martin

Make EMPTY expand to nop with gas, as it is used to mark empty branch
delay slots.


# 1.235 15-Feb-2007 martin

branches: 1.235.2;
Fix obvious copy&pasto in SCHED_DEBUG register usage.


Revision tags: post-newlock2-merge
# 1.234 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.233 25-Dec-2006 wiz

Spell "relevant" correctly. From Zafer Aydogan.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.232 25-Oct-2006 mrg

branches: 1.232.2; 1.232.4;
- note that __idle_u should go away but doing so breaks things
- fix several comments to reality
- clean up the #ifdef NO_VCACHE code slightly
- use call instead of set/jmpl
- remove a couple of unnecessary stores to curlwp


Revision tags: yamt-splraiseipl-base2
# 1.231 18-Oct-2006 rjs

Clean up some comments. Cosmetic change to use correct structure
offset names.

Optimize out two instructions from sparc64_ipi_save_fpstate and
sparc64_ipi_drop_fpstate.


# 1.230 17-Oct-2006 mrg

allocate 128KB (as opposed to 64KB) per-cpu, and place the interrupt
stack, cpu_info structure, panicstack, idle uarea and normal kernel
stack in here. the idle uarea and kernel stack are in the 2nd 64KB
page. the interrupt stack and cpu_info structure are as the same
place in the 1st 64KB page, and the panicstack grows down from the
top of this page. update comments in param.h to suit (XXX: a lot
of these constants should move to a header file that will not pollute
the name space so much.) map these pages identically between
cpu_initialise() and cpu_mp_startup(), and deal with the two 64KB
pages in pmap_extract(). keep an unmapped 64KB page between them.

don't initialise the unused "ci_eintstack" member of the cpu_info
structure

use constants to initialise many addresses in the cpu_info structure,
consolidating these assignments from cpu0 and cpu>0

delete u0/estack0/panicstack from locore.s

clean up some wrong comments in locore.s

fix a 32bit-only bug in cpu_mp_startup().

delete 'u0' entirely.


this fixes recent random lossage seen on port-sparc64: processes
stuck in RUN state, data faults, and hangs.


# 1.229 04-Oct-2006 mrg

use call instead of set/jmpl. add an entry point for idle that expects
sched_lock to be unlocked, and use this for non-boot cpu's. complete a
comment describing how registers in idle_switch are expected to be set.


# 1.228 03-Oct-2006 mrg

use the same SAVE_LOCALS_INS definition for 32 bit and 64 bit kernels.
refactor TRAP_SETUP() a little between these two versions to be more alike.


# 1.227 03-Oct-2006 mrg

use the correct size/type for MP variables (pointers and longs).

a 32 bit MULTIPROCESSOR kernel now builds (and crashes quickly.)


# 1.226 03-Oct-2006 mrg

in the 64bit version of SAVE_LOCAL_INS, s/BIAS/STKB/ to allow future
sharing of the 32 and 64 bit versions of the {TRAP,INTR}_SETUP macros.


# 1.225 19-Sep-2006 mrg

- remove some way old FP setup/teardown code
- put the block memcpy/memset inside #ifdef USE_BLOCK_STORE_LOAD which
is (now) defined.

no functional change, same .o is generated.


# 1.224 19-Sep-2006 mrg

re-order the changes in rev 1.217 to give registers a little bit of
time to settle between usage, like it was before hand.


# 1.223 19-Sep-2006 mrg

- remove a wrong comment.
- add a new entry point for idle called idle_switch that is called by
cpu_switch() in the MP case when sched_whichqs is zero, properly
setting up the idle stack. from petrov@ via martin@.


# 1.222 19-Sep-2006 mrg

rework interrupt_vector() slightly:
- for the IPI case, avoid loading the address of intrlev into %g3
- remove some NOT_DEBUG code
- load the interrupt argument #2 in the delay slot

this removes 2 nops during interrupt processing for the normal
case, and an additional 2 ALU instructions for IPIs


# 1.221 18-Sep-2006 mrg

- sparc64_ipi_halt(): we shouldn't return from sparc64_ipi_halt_thiscpu()
so replace a branch with a 'sir'
- in #if 0 code, in sparc64_ipi_flush_pte() and sparc64_ipi_flush_ctx()
save/restore the out registers that the sp_tlb_flush_xxx() versions
around calling them
- in sp_tlb_flush_pte() and sp_tlb_flush_ctx(), replace global register
usage with out registers so that we don't clobber the (alternate)
global registers when these are called from IPI context


# 1.220 18-Sep-2006 mrg

- remove an extra 'sir' that followed one in a macro
- add some named labels to some spill/fill handlers
- remove 2 unused strings


Revision tags: yamt-splraiseipl-base
# 1.219 18-Sep-2006 martin

branches: 1.219.2;
Lazy FPU handling for the MULTIPROCESSOR case


# 1.218 16-Sep-2006 nakayama

From OpenBSD:
- reload %fprs for checking it again.
- use symbolic names for checking in %fprs.

revision 1.51
date: 2005/07/18 14:50:11; author: deraadt; state: Exp; lines: +2 -1
cache a copy of the fprs so we know what fp restore we should do after

revision 1.50
date: 2005/07/14 01:46:13; author: deraadt; state: Exp; lines: +4 -4
use symbolic names for checking in %fprs, as above


# 1.217 16-Sep-2006 nakayama

Fix a couple of %y register save/restore errors, inspired from OpenBSD.

revision 1.44
date: 2004/04/23 04:18:17; author: marc; state: Exp; lines: +5 -4

fix a couple of %y register save/restore errors
1) don't save %y in a register that is later used before restoring %y
2) always restore %y after calling a signal handler
tested by drahn@, OK pval


# 1.216 15-Sep-2006 martin

Do not bother to save fpu state when we are about to get rid of it.


Revision tags: yamt-pdpolicy-base9
# 1.215 13-Sep-2006 mrg

SMP cleanup. provide support for multiple CPUs in DDB. (SMP itself
is still not working.)

cpu.h:
- add a pointer for DDB regs in SMP environment to struct cpu_info
- remove the #defines for mp_pause_cpus() and mp_resume_cpus()
cpuset.h:
- remove CPUSET_ALL() and rename CPUSET_ALL_BUT() to CPUSET_EXCEPT()
from petrov.
db_machdep.h:
- rename the members of db_regs_t to be the same as sparc
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- redo DDB_REGS to no longer be a pointer to a fixed data structure
but to one allocated per-cpu when ddb is entered
- move a bunch of prototypes in here
intr.h:
- remove SPARC64_IPI_* macros, no longer used
db_interface.c:
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- make "nil" a 64 bit entity
- change the ddb register access methods to work in multiprocessor
environment, it is now very much like sparc does it
- in kdb_trap() avoid accessing ddb_regp when it is NULL
- update several messages to include the cpu number
- unpause other cpus much later when resuming from ddb
- rename db_lock() to db_lock_cmd(), as the sparc-like code has
db_lock as a simple lock
- remove "mach cpus" command, and replace it with "mach cpu" (which
does the same) and also implement "mach cpu N" to switch to
another cpus saved trapframe
db_trace.c:
- update for the ddb_regs -> ddb_regp change
genassym.cf:
- add TF_KSTACK as offsetof(struct trapframe64, tf_kstack)
ipifuncs.c:
- overhaul extensively
- remove all normal interrupt handlers as IPI's, we now handle
them all specially in locore.s:interrupt_vector
- add a simplelock around all ipi functions - it's not safe for
multiple cpus to be sending IPI's to each other right now
- rename sparc64_ipi_pause() to sparc64_ipi_pause_thiscpu() and,
if DDB is configured, enable it to save the passed-in trapframe
to a db_regs_t for this cpu's saved DDB registers.
- remove the "ipimask" system (SPARC64_IPI_* macros) and instead
pass functions directly
- in sparc64_send_ipi() always set the interrupt arguments to 0,
the address and argument of the to be called function. (the
argument right now is the address of ipi_tlb_args variable, and
part of the reason why only one CPU can send IPI's at a time.)
don't wait forever for an IPI to complete. some of this is
from petrov.
- rename sparc64_ipi_{halt,pause,resume}_cpus() to
mp_{halt,pause,resume}_cpus()
- new function mp_cpu_is_paused() used to avoid access missing
saved DDB registers
- actually broadcast the flush in smp_tlb_flush_pte(),
smp_tlb_flush_ctx() and smp_tlb_flush_all(). the other end may
not do anything yet in the pte/ctx cases yet...
kgdb_machdep.c:
- rework for changed member names in db_regs_t.
locore.s:
- shave an instruction from syscall_setup() (set + ld -> sethi + ld)
- remove some old dead debug code
- add new sparc64_ipi_halt IPI entry point, it just calls the C
vector to shutdown.
- add new sparc64_ipi_pause IPI entry point, which just traps into
the debugger using the normal breakpoint trap. these cpus usually
lose the race in db_interface.c:db_suspend_others() and end up
calling the C vector sparc64_ipi_pause_thiscpu().
- add #if 0'ed code to sparc64_ipi_flush_{pte,ctx}() IPI entry
points to call the sp_ version of these functions.
- in rft_kernel (return from trap, kernel), check to see if the
%tpc is at the sparc64_ipi_pause_trap_point and if so, call
"done" not "retry"
- rework cpu_switch slightly: save the passed-in lwp instead of
using the one in curlwp
- in cpu_loadproc(), save the new lwp not the old lwp, to curlwp
- in cpu_initialize(), set %tl to zero as well. from petrov.
- in cpu_exit(), fix a load register confusion. from petrov.
- change some "set" in delay branch to "mov".
machdep.c:
- deal with function renames
pmap.c:
- remove a spurious space
trap.c:
- remove unused "trapstats" variable
- add cpu number to a couple of messages


# 1.214 09-Sep-2006 mrg

significant clean up effort, largely from petrov@ via martin@.

- fix a bunch of comments for proc->lwp
- remove old TRAPTRACE, NOT_DEBUG, etc. code that has bit-rotted
- put some older DEBUG code under NOT_DEBUG
- add a bunch of new debugging/tracing code ("KTR") that depends on
other changes not yet present.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base yamt-pdpolicy-base5 chap-midi-base simonb-timecounters-base rpaulo-netinet-merge-pcb-base
# 1.213 14-May-2006 elad

branches: 1.213.6; 1.213.8;
integrate kauth.


# 1.212 12-May-2006 skrll

Fix some comments.


Revision tags: elad-kernelauth-base
# 1.211 09-May-2006 rjs

Load CPCB in cpu_mp_startup.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.210 11-Feb-2006 cdi

branches: 1.210.2; 1.210.4; 1.210.6;
ANSIfication: u_intN_t -> uintN_t, use ANSI function declarations/definitions
instead of K&R ones.


# 1.209 27-Jan-2006 cdi

branches: 1.209.2; 1.209.4;
Alter sparc64 bootstrap, catch up to ofwboot v1.9:

- Accept bootinfo structure passed down from ofwboot v1.9
- Drop kernel re-mapping code
- Use permanent 4MB mappings provided by the loader instead
- Change kernel entry address to point directly at the code instead of pointing
at the trap table's first slot. This allows the bootloader to detect
those kernels which are aware of the new boot scheme
- Due to the changes in kernel mapping code, alter secondary CPU bootstrap
code to use trampoline just like FreeBSD does (some FreeBSD code is used
here as well)


# 1.208 12-Jan-2006 cdi

Fix a typo: %g0 should be used instead of %o0 when initializing FPU in dostart:
and cpu_mp_startup:, %o0 is not even initialized at this point.


# 1.207 11-Dec-2005 christos

branches: 1.207.2;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 1.206 10-Jul-2005 christos

Re-factor syscall, and make it use syscall_{plain,fancy}.


# 1.205 31-May-2005 chs

branches: 1.205.2;
remove vestigal {,e}intr{names,cnt} symbols now that vmstat doesn't need them.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.204 12-Feb-2005 chs

branches: 1.204.4; 1.204.6; 1.204.8;
in sparc_interrupt(), wait to enable interrupts until just before calling
the handler and disable them again right after the handler returns.
we don't want another hardware interrupt coming in while we're mucking
with the list pointers. also, clear the intrhand's ih_pending pointer
before calling the handler rather than after, so that if another interrupt
comes in while the handler is running, we can put the intrhand back on
the list so it will be called again.

in send_softint(), disable interrupts via %pstate instead of %pil, so that
hardware interrupts at higher levels are blocked while we manipulate the
intrpending list. also, if the intrhand already has ih_pending set,
don't bother poking the SET_SOFTINT register again, since being on the list
implies that there is already a softint pending in the hardware.

these appear to fix PR 21750 (the "sleep forever" problem).

while I'm here, remove more vestiges of the !INTRLIST softint stuff
(code and comments). and in sparc64_ipi_flush_all(), interrupts are
already disabled so we don't need to fiddle with %pstate.


Revision tags: yamt-km-base2
# 1.203 30-Jan-2005 martin

Remove the no long usefull variants selected by undefining INTRLIST and
INTR_INTERLOCK to improve readability. Same object code generated as before.


Revision tags: yamt-km-base
# 1.202 16-Jan-2005 chs

branches: 1.202.2;
use ENTRY_NOPROFILE() for various entry points,
stack traces work better that way.


Revision tags: kent-audio1-beforemerge kent-audio1-base
# 1.201 03-Dec-2004 chs

branches: 1.201.4;
remove cache_flush_virt() and PADDRT, they're no longer used.
allocate a stack frame for blast_dcache() when profiling so it shows up.
in dcache_flush_page(), use a stride of 32 instead of 16 to match the
cache line size. correct various comments.


# 1.200 08-Nov-2004 petrov

Don't compile sparc64_ipi functions when UP.


# 1.199 25-Oct-2004 martin

No need to clear %o1 when returning a 64 bit integer from pseg_get if we
are compiling for a 64 bit kernel.


# 1.198 24-Jul-2004 nakayama

Change interrupt pending list end value to -1, to avoid linking an
interrupt handler twice.

It may fix "sleep forever" bug.


# 1.197 09-Apr-2004 petrov

Clean-up unused defines and variables.


Revision tags: netbsd-2-0-base
# 1.196 26-Mar-2004 petrov

branches: 1.196.2;
Use want_resched from cpu_info area.


# 1.195 23-Mar-2004 martin

Replace intrcnts by evcnts. XXX - needs slight tweaking for MULTIPROCESSOR.


# 1.194 14-Mar-2004 chs

checkpoint of MP work from dennis and myself. includes cross-processor
interrupt framework, a sledgehammer TLB invalidation and misc MP fixes.
doesn't work at all yet.


# 1.193 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.192 19-Jan-2004 martin

Rename switchexit to cpu_exit and g/c the old C implementation of cpu_exit.


# 1.191 18-Jan-2004 martin

Support RAS for 32bit kernels too.


# 1.190 16-Jan-2004 martin

In proc_trampoline don't bother to clear condition codes in the trap
frame, since we no longer rely on this.
While there fix a few comments.


# 1.189 08-Jan-2004 martin

Minor cleanup


# 1.188 06-Jan-2004 martin

Implement restartable atomic sequences (RAS) for sparc64.


# 1.187 06-Jan-2004 petrov

Spinup secondary cpus. Based on codes sent to me by Dennis Chernoivanov
and Chuck Silvers.


# 1.186 04-Jan-2004 jdolecek

update to recent changes - exit2() doesn't exist anymore and the
exit path always calls lwp_exit2()
pointed out Martin Husemann


# 1.185 02-Dec-2003 martin

Minor cleanup: remove unused code, sync a comment with current reality.


# 1.184 25-Nov-2003 cdi

Use per-cpu pcb, curlwp and fplwp rather than global ones. This brings
GENERIC.MP configuration to a usable state.

Approved by petrov@.


# 1.183 24-Nov-2003 cdi

Call 'proc_trampoline_mp' from 'proc_trampoline' in a multiprocessor
configuration. Fix process locking. Approved by petrov@.


# 1.182 20-Nov-2003 petrov

Remove nwindows calculation, it's not used. Set l_cpu in cpu_switch.


# 1.181 09-Nov-2003 martin

Get rid of bcopy/bzero.


# 1.180 26-Oct-2003 christos

Initial siginfo support for sparc64 (untested). COMPAT_16 sigcontext signal
delivery tested.


# 1.179 24-Aug-2003 chs

add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default. the changes
fall into two basic catagories:

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

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

originally from openbsd, adapted for netbsd by me.


# 1.178 08-Jul-2003 cdi

traceit: don't use %g7 as it is to become curcpu() register. Add comments.


# 1.177 18-May-2003 martin

branches: 1.177.2;
Make kernels with options KGDB at least compile.
Still needs some work to make it working.


# 1.176 29-Apr-2003 nakayama

Use BLOCK_ALIGN rather than BLOCK_SIZE for aligning a pointer.


# 1.175 27-Apr-2003 ragge

Preserve the symbol table in the LKM || KSYMS cases also.


# 1.174 04-Apr-2003 petrov

use branch slot in pmap_copy_page.


# 1.173 24-Mar-2003 nakayama

Divide `set' instruction in delay slot (from OpenBSD change to rev 1.30).


# 1.172 10-Feb-2003 martin

Remove some #if 0 code and a few XXX marked membars w/o proper
justification for their existence.


# 1.171 09-Feb-2003 martin

Remove left over pieces from reusing the signal trampoline for upcalls.
This should fix signal delivery for 32bit kernels.


# 1.170 05-Feb-2003 nakayama

Switch to use cycle counter (%tick) based microtime().

This is derived from alpha/microtime.c and i386/tsc_microtime.c,
and will share with both ports.

This should fix PR port-sparc64/18452.
(approved by martin)


# 1.169 04-Feb-2003 martin

Fix return value of pseg_set, which I accidently broke in rev. 1.164.

Fix register names in comment and shave off another register (hint
from uwe).


# 1.168 01-Feb-2003 martin

Rearrange register usage in pseg_set a bit and shave off %g4.


# 1.167 01-Feb-2003 martin

Remove a few #ifdef _LP64 by using STPTR/LDPTR macros.
Thanks to Matthew Green for the pointer.


# 1.166 31-Jan-2003 martin

Apply leaf procedure optimization to pseg_set (again).


# 1.165 31-Jan-2003 martin

Make the pmap count resident/wired mappings on the fly instead of
walking the page tables whenever this information is needed.

Add an option PMAP_COUNT_DEBUG to assert the new counts and the
page table walk agree.

The old solution had very bad performance impact, for example
by the high CPU load when running top(1).

Thanks to Simon Burge for pointing at the cause of the problem and
to Valeriy E. Ushakov for optimizing my simple minded assembler code.


# 1.164 27-Jan-2003 martin

Remove unused function pseg_find (which looked quite similar to
pseg_get anyway).


# 1.163 18-Jan-2003 thorpej

Merge the nathanw_sa branch.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.162 16-Jan-2003 petrov

Move dump_dtlb back under DDB.


# 1.161 15-Jan-2003 chs

fix two bugs in my last pmap rework:
- in tlb_flush_all(), don't skip TLB entries with the high bit on,
I was confused about which MMU register it was using. it's also fine
to use the last hardware context.
- in pmap_create(), don't allocate a hardware context for the new pmap.
it's unnecessary, and when this would cause us to recycle all the contexts,
it would result in the current process's context being set to 0
(ie. the kernel's context). the current process could then return to
userspace without going through the context-switch code (and thus without
having a hardware context reallocated). this would lead to user mappings
being entered in the kernel's context later, causing all sorts of trouble.
add some assertions to catch this kind of thing.


Revision tags: fvdl_fs64_base
# 1.160 25-Dec-2002 petrov

new function dump_itlb.


Revision tags: gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.159 22-Sep-2002 chs

many improvements:
- use struct vm_page_md for attaching pv entries to struct vm_page
- change pseg_set()'s return value to indicate whether the spare page
was used as an L2 or L3 PTP.
- use a pool for pv entries instead of malloc().
- put PTPs on a list attached to the pmap so we can free them
more efficiently (by just walking the list) in pmap_destroy().
- use the new pmap_remove_all() interface to avoid flushing the cache and TLB
for each pmap_remove() that's done as we are tearing down an address space.
- in pmap_enter(), handle replacing an existing mapping more efficiently
than just calling pmap_remove() on it. also, skip flushing the
TSB and TLB if there was no previous mapping, since there can't be
anything we need to flush. also, preload the TSB if we're pre-setting
the mod/ref bits.
- allocate hardware contexts like the MIPS pmap:
allocate them all sequentially without reuse, then once we run out
just invalidate all user TLB entries and flush the entire L1 dcache.
- fix pmap_extract() for the case where the va is not page-aligned and
nothing is mapped there.
- fix calculation of TSB size. it was comparing physmem (which is
in units of pages) to constants that only make sense if they are
in units of bytes.
- avoid sleeping in pmap_enter(), instead let the caller do it.
- use pmap_kenter_pa() instead of pmap_enter() where appropriate.
- remove code to handle impossible cases in various functions.
- tweak asm code to pipeline a little better.
- remove many unnecessary spls and membars.
- lots of code cleanup.
- no doubt other stuff that I've forgotten.

the result of all this is that a fork+exit microbenchmark is 34% faster
and a fork+exec+exit microbenchmark is 28% faster.


Revision tags: gehenna-devsw-base
# 1.158 18-Jul-2002 wiz

Spell 'should' correctly.


# 1.157 07-Jun-2002 eeh

Shave 10% off the time needed to flush the D$ through a bit of instruction
reordering.


# 1.156 05-Jun-2002 eeh

Handle improperly aligned stack pointers more cleanly.


# 1.155 04-Jun-2002 eeh

Fix the fork trampoline to properly use the supplied tstate.


# 1.154 31-May-2002 thorpej

Make this work with an ISO C preprocessor.


Revision tags: netbsd-1-6-base
# 1.153 14-May-2002 eeh

branches: 1.153.2; 1.153.4;
Only save locals and ins in trapframes for DEBUG kernels.


# 1.152 04-May-2002 kleink

Add some comments to the CPP conditionals controlling the trap macro
definitions, to ease navigation somewhat.


# 1.151 16-Apr-2002 eeh

Make lots of routines profile-friendly and get rid of some cruft.


Revision tags: eeh-devprop-base
# 1.150 21-Mar-2002 petrov

Not needed debug stuff deleted.


# 1.149 16-Mar-2002 mrg

tell newer binutils that our use of %g2 and %g3 is OK here.


# 1.148 15-Mar-2002 eeh

Cleanup MMU initialization to prevent hangs.


Revision tags: newlock-base ifpoll-base
# 1.147 09-Feb-2002 eeh

branches: 1.147.4;
Fix microsecond calculation in microtime.


# 1.146 07-Feb-2002 eeh

Fix register allocation in microtime().


# 1.145 29-Jan-2002 eeh

Shift the UPAID in the correct direction.


# 1.144 17-Jan-2002 eeh

Be more tolerant of unaligned stack pointers.


# 1.143 17-Jan-2002 eeh

Enable block insns in bcopy and bzero.


# 1.142 16-Jan-2002 eeh

In bcopy use 32-bit comparisons in 32-bit kernels.


# 1.141 16-Jan-2002 eeh

Use correct calculation for the trapframe in softtrap for ILP32.


# 1.140 20-Nov-2001 lukem

- pull in opt_kgdb.h where necessary
- replace opt_kgdb_machdep.h with opt_kgdb.h
- defparam opt_kgdb.h:
KGDB_DEV KGDB_DEVNAME KGDB_DEVADDR KGDB_DEVRATE KGDB_DEVMODE
- move from opt_ddbparam.h to opt_ddb.h:
DDB_FROMCONSOLE DDB_ONPANIC DDB_HISTORY_SIZE DDB_BREAK_CHAR SYMTAB_SPACE
- replace KGDBDEV with KGDB_DEV
- replace KGDBADDR with KGDB_DEVADDR
- replace KGDBMODE with KGDB_DEVMODE
- replace KGDBRATE with KGDB_DEVRATE
- use `9600' instead of `0x2580' for 9600 baud rate
- use correct quotes for options KGDB_DEVNAME="\"com\""
- use correct quotes for options KGDB_DEV="17*256+0"
- remove unnecessary dependancy on Makefile for kgdb_stub.o
- minor whitespace cleanup


Revision tags: thorpej-mips-cache-base thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf
# 1.139 14-Sep-2001 thorpej

branches: 1.139.4;
Don't declare intrhand[] here -- that's taken care of in intr.c.


Revision tags: thorpej-devvp-base
# 1.138 30-Aug-2001 eeh

branches: 1.138.2;
Preliminary UltraSPARC III suport (not enabled yet).


# 1.137 13-Aug-2001 jdolecek

g/c _remque()/_insque(); use the C version in libkern


# 1.136 09-Aug-2001 eeh

Fix context masking lossage caused by last version.


# 1.135 08-Aug-2001 eeh

Clean up the trap code to handle the changes cause by supporting non-faulting
accesses. Also change the parameter order so trap frames are easy to find.


# 1.134 07-Aug-2001 eeh

Make sure C code always has ASI_PRIMARY_NOFAULT in the %asi register so
the compiler will be happy if it ever starts generating speculative loads.


# 1.133 05-Aug-2001 eeh

Add support for non-faulting loads and optimize MMU miss handling paths.


# 1.132 02-Aug-2001 eeh

Fix bcopy.


# 1.131 02-Aug-2001 eeh

Sync bzero w/libc version.


# 1.130 01-Aug-2001 eeh

Integrate fixes from userland memset.


# 1.129 31-Jul-2001 eeh

Code cleanup and optimization.


# 1.128 23-Jul-2001 eeh

Get rid of some debug code that really isn't all that useful any more.


# 1.127 19-Jul-2001 eeh

Do ignore unregistered interrupts instead of faulting.


# 1.126 16-Jul-2001 eeh

Make bcopy a 32-bit friendly.


# 1.125 11-Jul-2001 eeh

Fix problems booting 32-bit kernels and dispatching level-15 interrupts.


# 1.124 08-Jul-2001 eeh

branches: 1.124.2;
Code cleanup. Add block_disable to let you turn on block set/copy routines.


# 1.123 05-Jul-2001 eeh

New block bzero and bcopy.


# 1.122 04-Jul-2001 eeh

Replace old bcopy with a much faster version.


# 1.121 01-Jul-2001 martin

Disable axidently enabled debug code to make -current compile again.


# 1.120 30-Jun-2001 eeh

Use a newer version (still disabled) of block bcopy.


# 1.119 30-Jun-2001 eeh

Fixup fpu save restore, get rid of some unused copy functions, and add
a new bcopy.


# 1.118 21-Jun-2001 eeh

Allow multiple 4MB pages for both kernel text and kernel data.

Note: DEBUG checks will not allow accesses to the hole between
text and data segments, so you may need to update programs that
use libkvm before relocating the start of kernel data.


# 1.117 06-Jun-2001 mrg

extract the netbsd32, sunos, 32 bit svr4 and 64 bit svr4 sigcode out into
separate files, so that compat lkms can link with them as well.


# 1.116 30-May-2001 lukem

add missing #include "opt_kgdb.h"


Revision tags: thorpej_scsipi_beforemerge
# 1.115 25-Apr-2001 simonb

Spell occurred correctly.


Revision tags: thorpej_scsipi_nbase thorpej_scsipi_base
# 1.114 09-Apr-2001 eeh

Interrupt latency fix from sparc port. (Hm. One insn instead of 5).


# 1.113 07-Mar-2001 eeh

Fix inverted preprocessor logic. (Spotted by Charles.)


# 1.112 21-Feb-2001 eeh

branches: 1.112.2;
Add support for 64-bit SVR4 (Solaris 8) binaries.


# 1.111 10-Feb-2001 pk

Fix conditional for svr4 compat inclusion.


# 1.110 05-Feb-2001 eeh

Add signal trampoline for 64-bit svr4 emulations.


# 1.109 31-Dec-2000 eeh

Make INCR() atomic.


# 1.108 29-Dec-2000 eeh

pseg_get tells us whether it really needed that spare page after all.


# 1.107 07-Dec-2000 eeh

Fixup calculating where fpstate should be saved in the signal trampoline
code so it doesn't overwrite something important like the registers.


# 1.106 09-Nov-2000 eeh

Fix ILP32 bug in probe_get().


# 1.105 22-Oct-2000 pk

Restore revision 1.102.

I hope it sticks this time..


# 1.104 20-Oct-2000 eeh

Fix hang in 32-bit kernels caused by relocation of KERNBASE.


# 1.103 04-Oct-2000 eeh

Fix interrupt lossage problem and some cosmetic changes.


# 1.102 01-Oct-2000 pk

cpu_initialize: global registers aren't preserved across calls to
prom_printf(), so replace %g3 with %l7 (which isn't used despite
the `usage' comment).

Also, clean up white-space turds.


# 1.101 29-Sep-2000 eeh

This seems to fix the interrupt lossage of non-debug kernels.


# 1.100 28-Sep-2000 eeh

Fix INTR_SETUP() to properly distinguish kernel and user addresses.

Make microtime() return the correct time on %tick machines.

Re-enable debug stuff in dostart for now to detect kernel mapping issues.


# 1.99 25-Sep-2000 pk

Missing `#if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)'


# 1.98 17-Sep-2000 eeh

Make the improved %tick changes work with machines that use the counter-timer
for the clock.


# 1.97 12-Sep-2000 eeh

Fix new version of microtime.


# 1.96 11-Sep-2000 eeh

(Hopefully) fix clock skew on machines that us %tick for the clock (UIIi).


# 1.95 31-Aug-2000 eeh

Use casx instead of stx to change entries in the page table trees.


# 1.94 23-Aug-2000 eeh

Update the scheduler to the new locking scheme.


# 1.93 10-Aug-2000 eeh

Fix signal delivery.


# 1.92 02-Aug-2000 eeh

Get kernel profiling to work. Now if only gprof worked....


# 1.91 01-Aug-2000 eeh

Overhaul cache flush code and coredump code.


# 1.90 25-Jul-2000 pk

Re-instate a couple of delay slot NOPs marked `XXX spitfire bug?'


# 1.89 24-Jul-2000 mycroft

Optimization to pmap_zero_page(): we only need to use the first 16 FP regs,
as in bzero().


# 1.88 24-Jul-2000 mycroft

Fix a whitespace glitch.


# 1.87 24-Jul-2000 mycroft

Pull in the bzero() changes from libc for real, with a couple of kernel-
specific hacks:
* Make the bias handling depend on STKB, so it switches correctly for 32-bit
kernels.
* Use the 32-bit stw/ld for 32-bit kernels.
* Add a few `-STKB's that were missed in the previous change.


# 1.86 24-Jul-2000 pk

Cosmetic & readability:
- local label cleanup in interrupt handling code;
- in debugging sections when testing `intrdebug': use a unique
local label (97) to enhanced clarity;
- comment-out unused code;
- kill a bug as the satisfying result of doing all of the above.


# 1.85 24-Jul-2000 eeh

Fix stack issues in bzero.


# 1.84 24-Jul-2000 mycroft

Revert the previous change for now. I don't have time to debug it tonight.


# 1.83 23-Jul-2000 mycroft

Copy bzero change from libc.


# 1.82 20-Jul-2000 pk

Since `intrcnt' points to an array of long ints, reserve the appropriate
amount of space depending on _LP64. Provide macros to load/store signed
and unsigned long ints.

Also, make the `intrcnt' and `intrpending' arrays 16 entries long, as on
sparc/v9 interrupt #15 is just a regular interrupt.


# 1.81 19-Jul-2000 eeh

Fix merge problem.


# 1.80 19-Jul-2000 eeh

Disable interrupt interlock using ih->ih_pending field. Seems to cause
more problems than it solves.


# 1.79 19-Jul-2000 eeh

Miscellaneous cleanup.


# 1.78 18-Jul-2000 pk

Correct args usage comment in probeget.
Whitespace cleanup.


# 1.77 18-Jul-2000 pk

probeget: 9 -> 0x9


# 1.76 18-Jul-2000 pk

If `ih_pending' is set simply return from the trap, don't schedule another
soft interrupt.


Revision tags: mrg-merge-1-5-top
# 1.75 18-Jul-2000 pk

openfirmware: don't lower %pil


# 1.74 17-Jul-2000 pk

Kill typos in interrupt code.


# 1.73 17-Jul-2000 pk

probeget: do the same song and dance as ld*a() macros in ctlreg.h do.


# 1.72 14-Jul-2000 eeh

Move some macro definitions out of genassym and into locore.s


# 1.71 08-Jul-2000 mrg

backout part of previous: turn off intrdebug, and another debug message


# 1.70 07-Jul-2000 pk

Changes for readability:
- #define LP64 dependent STACKFRAME macro once
- use a LOAD_ASCIZ macro for setting up the format string
for debug messages.


# 1.69 07-Jul-2000 eeh

Temporary fix to prevent the clock from stopping on UIIi machines.


# 1.68 03-Jul-2000 eeh

Prevent interrupts from being posted if they are active and deprecate polled
interrupts. This seems to eliminate the spurious interrupts.


# 1.67 02-Jul-2000 eeh

Clean up interrupt handling some more.


# 1.66 30-Jun-2000 eeh

Fix interrupt delivery on UltraSPARC IIi machines.


# 1.65 24-Jun-2000 eeh

With these changes the kernel seems almost stable again.


# 1.64 24-Jun-2000 eeh

More VM cleanup:

Move the cpu_info structure above the interrupt stack so it won't
get corrupted if the stack overflows.

Flush the D$ before and after all MMU bypass accesses since the
D$ latches all of those.


# 1.63 23-Jun-2000 eeh

Make probeget() and probeset() really work for a change.


Revision tags: netbsd-1-5-base
# 1.62 19-Jun-2000 eeh

branches: 1.62.2;
Have separate data and text segments, make text read-only.


# 1.61 12-Jun-2000 eeh

Start reorganizing the kernel for MULTIPROCESSOR support.


# 1.60 31-May-2000 thorpej

Add a comment about needing to initialize p_cpu when multiple
processors are supported.


Revision tags: minoura-xpg4dl-base
# 1.59 26-May-2000 thorpej

branches: 1.59.2;
First sweep at scheduler state cleanup. Collect MI scheduler
state into global and per-CPU scheduler state:

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

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

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

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

Tested on i386 and Alpha. Changes are mostly mechanical, but apologies
in advance if it doesn't compile on a particular platform.


# 1.58 26-May-2000 thorpej

Don't set `runtime' here; it's done at the end of mi_switch().
cvS: ----------------------------------------------------------------------


# 1.57 26-May-2000 thorpej

Introduce a new process state distinct from SRUN called SONPROC
which indicates that the process is actually running on a
processor. Test against SONPROC as appropriate rather than
combinations of SRUN and curproc. Update all context switch code
to properly set SONPROC when the process becomes the current
process on the CPU.


# 1.56 22-Apr-2000 eeh

If we trap due to a bad kernel stack, try to switch to the interrupt strack
before breaking into the debugger.


# 1.55 18-Apr-2000 eeh

Prevent the system from getting watchdog reset by returning directly to user
mode if restoring the user window traps. Also reduce the time we run with
%tl>0.


# 1.54 13-Apr-2000 eeh

Apparently gas 2.9.5 (don't ask) does not like to add values to %lo()
directives so move the additions inside %lo() to make it happy.
Hopefully this won't break older versions.


# 1.53 10-Apr-2000 mrg

- fix a speeling error
- rename some numbered labels to be a bit less confusing.
- remove dead code
- fix a debug error message (argh!)


# 1.52 10-Apr-2000 pk

Get a kernel without DDB to build.


# 1.51 16-Mar-2000 eeh

Revamp interrupts again:

Fix a bug causing interrmittent panics in interrupt dispatch.
Use interrupt vectors for softints.
Add a new send_softint interface.
Improved D$ flushing.
Improve traptrace and other debugging enhancements.


Revision tags: chs-ubc2-newbase
# 1.50 16-Jan-2000 eeh

Interrupt handlers return zero if they didn't handle the interrupt.


# 1.49 10-Jan-2000 eeh

Add debugger single-stepping and fix interrupt dispatch bugs.


# 1.48 30-Dec-1999 eeh

Lots of changes:

remove ffs()
add bzero that uses block store insns
save %gsr to fpstate
revert to physical accesses for pmap_zero_page so we don't
have conflicting page mappings
general cleanup.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base fvdl-softdep-base
# 1.47 06-Nov-1999 eeh

Handle zero length properly in copyinstr() copyoutstr() and copystr().


Revision tags: comdex-fall-1999-base
# 1.46 11-Oct-1999 eeh

branches: 1.46.2; 1.46.4;
Update to post 1.4.


# 1.45 05-Oct-1999 eeh

branches: 1.45.2;
Make broken versions of gas happy by using sethi/or instead of set for
(negative) addresses.


# 1.44 17-Sep-1999 thorpej

Centralize the declaration and clearing of `cold'.


Revision tags: chs-ubc2-base
# 1.43 18-Jul-1999 eeh

More fun with pmap.


# 1.42 21-Jun-1999 eeh

Improve TRAPTRACE. Add FLTRACE that only tracks MMU faults.


# 1.41 05-Jun-1999 eeh

Make pbrobeget() and probeset() work for 64-bit values as well. To do this
the arguments are changed so the address is first and the ASI second so we
can have the address in %o0:%o1 and not worry about unused registers.

Also a bit of copyright cleanup.


# 1.40 05-Jun-1999 mrg

update a commit slightly.


# 1.39 30-May-1999 eeh

Add code to support using %tick as the system clock if no "counter-timer" node
is found.


# 1.38 09-May-1999 eeh

Fixup non-DEBUG kernels.


# 1.37 29-Apr-1999 christos

Add sunos_sigcode (32 bit only)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.36 26-Mar-1999 eeh

branches: 1.36.4;
COMPAT_SPARC32 -> COMPAT_NETBSD32


# 1.35 25-Mar-1999 mrg

clean and up make compile


# 1.34 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.33 22-Mar-1999 eeh

Need to set up the pointers properly for partial FPU register stores.


# 1.32 22-Mar-1999 eeh

Flush D$ on bypass accesses.


# 1.31 28-Feb-1999 eeh

Use block load/store in pmap_zero_page()/pmap_copy_page().


# 1.30 17-Feb-1999 eeh

Let's test out vectored interrupts.


# 1.29 15-Feb-1999 hubertf

RCS ID police


# 1.28 11-Feb-1999 mrg

fix a comment pasto.


# 1.27 11-Jan-1999 eeh

Finally fixed 64-bit signal trampoline.


# 1.26 10-Jan-1999 eeh

Handle the symbol table properly in a 32-bit kernel that was booted from a
64-bit bootloader.


# 1.25 09-Jan-1999 eeh

More signal fixup.


Revision tags: kenh-if-detach-base
# 1.24 26-Nov-1998 mycroft

Sync kcopy() with 32-bit SPARC version.


# 1.23 16-Nov-1998 eeh

Fixup the last broken bits of the signal handling code.


Revision tags: chs-ubc-base
# 1.22 08-Oct-1998 eeh

Fix more syscall32 and signal breakage.


# 1.21 22-Sep-1998 eeh

More fixup in the signal area.

64-bit syscall cleanup.

Add emulation for some new FPU insns: conversion to 64-bit long int and
conditional moves.


# 1.20 17-Sep-1998 thorpej

SYS_sigreturn -> SYS___sigreturn14.


# 1.19 13-Sep-1998 eeh

Fixup signal changes (hopefully). However SUN_COMPAT is likely broken by
this and I don't know how to fix it.

We can now exec a 64-bit init through a really ugly hack (don't ask.)


# 1.18 11-Sep-1998 eeh

Add labels for the compat_sparc32 signal trampoline and break -- er -- fix
suword and fuword.


# 1.17 09-Sep-1998 eeh

Don't use %tick for microtime on 32-bit kernels -- breaks gettimeofday.


# 1.16 09-Sep-1998 thorpej

Adjust for the new "reaper" kernel thread: do not free the vmspace and
u-area in machine-dependent code. Instead, call exit2() to schedule
the reaper to free them for us, once it is safe to do so (i.e. we are
no longer running on the dead proc's vmspace and stack).


# 1.15 07-Sep-1998 eeh

Fix data corruption problem caused by broken debug code.


# 1.14 07-Sep-1998 eeh

Add new 64-bit trap vectors.


# 1.13 06-Sep-1998 eeh

32-bit fixup.


# 1.12 06-Sep-1998 eeh

Disable some debug stuff.


# 1.11 05-Sep-1998 eeh

It slices. It dices. It does everything except exec a sparc32_compat init.


# 1.10 02-Sep-1998 eeh

Periodic update: now starts probing devices.


# 1.9 30-Aug-1998 eeh

Some more 64-bit cleanup. Now everything compiles.


# 1.8 29-Aug-1998 eeh

Some more 64-bit-ification.


# 1.7 27-Aug-1998 eeh

Add 64-bit pmap support:

Moved from a two level 512/1024 entry setup mapping 32 (9/10/13) bits
respectively to a three level 1024/1024/1024 entry setup mapping 43
(10/10/10/13) bits. In 32-bit mode we waste about 1/12 pages mapping the high
11 bits. We also only manage 43 of the possible 44 bits of virtual address
space, wasting half of it. Oh well, maybe we'll do better next revision.


Revision tags: PMAP32
# 1.6 26-Aug-1998 mrg

panicstack: is needed outside of DEBUG. use _C_LABEL, and printf not db_printf (incase no ddb!)


# 1.5 13-Aug-1998 eeh

Merge paddr_t changes into the main branch.


Revision tags: eeh-paddr_t-base
# 1.4 07-Jul-1998 eeh

branches: 1.4.2;
General update:

Added genassym.cf
Removed lderr which should never have gotten in
Removed lots of dead code from locore.s
Added some softint stuff to intr.c
Added support for halt -p
esp and le both use bus_dmamap_*() functions now
instead of kdvma_mapin()
groundwork for PCI (but we still have no drivers for
any sun4u PCI devices)


# 1.3 04-Jul-1998 jonathan

defopt DDB.


# 1.2 26-Jun-1998 thorpej

defopt COMPAT_SVR4


# 1.1 20-Jun-1998 eeh

branches: 1.1.1;
Initial revision


# 1.408 10-Feb-2017 palle

sun4v: Added handling of trap type 0x034 (address alignment error) + fixed typo mmfsa -> mmufsa. Verified for both sun4u and sun4v using qemu.


Revision tags: nick-nhusb-base-20170204
# 1.407 30-Jan-2017 palle

sun4v: Hook up syscall handling to the trap table. Verified using qemu for both sun4u and sun4v.


# 1.406 27-Jan-2017 palle

sun4v: implement missing handling of itsb traps 0x008 and 0x009. Based on code from OpenBSD. Tested using qemu.


Revision tags: bouyer-socketcan-base
# 1.405 07-Jan-2017 palle

sun4v: slowtrap() now selects normal globals properly on both sun4u and sun4v platforms. Verified using qemu for both sun4u and sun4v systems


Revision tags: pgoyette-localcount-20170107
# 1.404 05-Jan-2017 palle

sun4v: TRAP_SETUP() updated to set mmu context id properly for both sun4v and sun4u platforms. Verified using qemu for both sun4u and sun4v systems


# 1.403 04-Jan-2017 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x00-0x23 and 0x28-0x30


# 1.402 29-Dec-2016 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x32-0x7f


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.401 20-Sep-2016 nakayama

Fix RAS for 32-bit kernels. trapframe is always 64-bit.


Revision tags: localcount-20160914
# 1.400 23-Aug-2016 palle

sun4v: rework sun4v_datatrap so it works properly when running on a T2-based system like T5120 - for some reason %tl is 0 when entering sun4v_datatrap causing a crash (sir instruction), so ignore the %tl value for now upon entry to sun4v_datatrap - with this fix both T1 and T2 based systems reach the same point - hangs in rft_user after the init process is started


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726
# 1.399 18-Jul-2016 palle

sun4v: handle device interrupts properly - both legacy (sysino) and cookies


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 1.398 04-Jun-2016 palle

branches: 1.398.2;
sun4v: rtf_user now uses macros GET_MMU_CONTEXTID and SET_MMU_CONTEXTID. Tested on sun4u (QEMU) and sun4v (T2000). Parts from OpenBSD.


Revision tags: nick-nhusb-base-20160529
# 1.397 18-May-2016 nakayama

Decrement %tl in trap handler not to make it zero unconditionally
for the nested trap, and remove useless mov.


# 1.396 17-May-2016 palle

sun4v: Implement missng MMU protection trap handling - mostly from OpenBSD


# 1.395 16-May-2016 palle

Avoid assembler-specific defines by using the export keyword in genassym.cf instead


# 1.394 15-May-2016 nakayama

%g1 is not preserved across function call, so load it before
return_from_trap.


# 1.393 13-May-2016 palle

sun4v: add missing implementation of sun4v_datatrap_tl0 so data_access_fault() is called - mostly from OpenBSD


# 1.392 13-May-2016 nakayama

- ci_paddr is always 64-bit.
- intrlev is array of pointer.
- ih_ack is pointer.


# 1.391 10-May-2016 palle

sun4v: make device interrupts work. Introduce a new intrhand_alloc() function for allocation of interrupt handlers and adapt to this. Parts from OpenBSD. ok martin@


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.390 09-Mar-2016 nakayama

32-bit kernels use 32-bit stack.


# 1.389 03-Mar-2016 palle

sun4v: rft_kernel should pay attention to the number of register windows that can be restored. We cannot rely on fill traps to occur, since sun4v only has two trap levels available in privileged mode. Based on code from OpenBSD. ok martin@


# 1.388 14-Feb-2016 palle

sun4v: add breakpoint trap entry to the sun4v trap table


# 1.387 03-Feb-2016 palle

sun4v: extend dmmu_set_secondary_context() to handle both sun4u and sun4v. ok martin@


Revision tags: nick-nhusb-base-20151226
# 1.386 06-Nov-2015 martin

Basically revert r1.246 of locore.s and r1.73 of vm_machdep.c:

Remove special case handling for userland lwps from cpu_lwp_fork,
instead do it in lwp_trampoline when we first return to userland.

which was a stupid idea - since we did now set all fork child's %tstate
(and thus %pstate when back in userland) to the current kernel's userland
default. This meant we lost the address mask bit for 32bit processes and
all memory model details for 64bit ones.

Move it back to cpu_lwp_fork and fix the condition to only do it once when
forking init.


# 1.385 05-Nov-2015 martin

Most of the time return_from_trap already got called with tf->tf_tstate
loaded in register %g1 - make it so for two more callers and remove
the reload of that value.


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606 nick-nhusb-base-20150406
# 1.384 05-Apr-2015 palle

sun4v: Ensure that the TTEs CP and CV bits are the same (both set) for the primary cpu and secondary cpus INTSTACK mappings


# 1.383 01-Apr-2015 palle

sun4v: Implement handling of cpu_mondo trap - from OpenBSD - tested using the Legion simulator


# 1.382 04-Mar-2015 palle

sun4v: revert some of the logic introduced in revision 1.378 - flushw is not necessary on sun4v (OpenBSD patches the flushw instruction to a nop instruction) - with these changes the kernel reaches cpu_boot_secondary_processors() when running in the Legion simulator (crashes due to missing handling of cpu_mondo_trap)


# 1.381 02-Mar-2015 nakayama

prom_printf converts "\n" to "\r\n" internally, so omit "\r".


# 1.380 02-Mar-2015 nakayama

PANICSTACK is a pointer itself, not a pointer to pointer.


# 1.379 02-Mar-2015 nakayama

Use panic stack temporarily for calling prom_printf in a trap
handler.

It seems that openfirmware cannot handle over 4GB pointers, and
stack pointers may point to over 4GB since VA layout was rearranged
by rev 1.33 of vmparam.h. Therefore, use panic stack to avoid
panicking in OF_write used by prom_printf.


# 1.378 23-Feb-2015 palle

sun4v: sparc_interupt - ensure that the trap level and globals level are the same when the flushw instruction is issued - othwise warnings occur when using the sun4v Legion simulator.


Revision tags: nick-nhusb-base
# 1.377 26-Oct-2014 palle

branches: 1.377.2;
sun4v: Create CLEANWIN0 and CLEANWIN1 macros for handling clean window traps on both sun4u and sun4u (based on the original code inlined in the sun4u trap table). Update trap tables accordingly for both sun4u and sun4v. Ok martin@


# 1.376 24-Oct-2014 nakayama

Fix typo in comment.


# 1.375 18-Oct-2014 snj

src is too big these days to tolerate superfluous apostrophes. It's
"its", people!


# 1.374 15-Oct-2014 palle

sun4v: fixed bug causing the real address to be incorrectly calculated as zero


# 1.373 24-Sep-2014 palle

sun4v: add code to enable startup of secondary cpus on both sun4u and sun4v systems - ok martin@


# 1.372 04-Sep-2014 palle

sun4v: All cpus must be setup with a TSB descriptor, so pmap_setup_tsb_sun4v() must take a pointer to the TSB descriptor


# 1.371 31-Aug-2014 palle

sun4v: Split the NORMAL_GLOBALS and ALTERNATE_GLOBALS macros to _SUN4U and _SUN4V variants. Rework the return_from_trap logic to use the new variants so it is possible to use a global register as scratch register.


# 1.370 14-Aug-2014 nakayama

Add missing delay slot in DEBUG kernel.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.369 30-Jul-2014 palle

branches: 1.369.2;
Fix ALTERNATE_GLOBALS so it at least works on sun4u - using a scratch register is not a good idea...


# 1.368 27-Jul-2014 palle

sun4v: Introduce a new macro ALTERNATE_GLOBALS (matching NORMAL_GLOBALS). Two new helper macros ENABLE_INTERRUPTS and DISABLE_INTERRUPTS are also created. With these changes the GENERIC.UP kernel will reach rootmount on sun4v systems - ok martin@


# 1.367 26-Jul-2014 palle

Improved the NORMAL_GLOBALS macro in the sun4u case, so only the relevant bit (AG) in %pstate is affected - ok martin@


# 1.366 24-Jul-2014 palle

sun4v: add missing spill/fill handling for trap level 1 + cosmetic changes to comments for trap level 0 entries


# 1.365 19-Jul-2014 palle

sun4v: Introduce a NORMAL_GLOBALS macro - first used in sparc_interrupt - other relevant uses will be handled as the sun4v work is progressesing - ok martin@


# 1.364 16-Jul-2014 palle

sun4v: Introduce SET_MMU_CONTEXTID macro for setting the mmu context id on both sun4u and sun4v


# 1.363 13-Jul-2014 palle

sun4v: add interrupt handling to sun4v trap table


# 1.362 13-Jul-2014 palle

Bugfix: add missing cmp instruction to GET_MAXCWP macro


# 1.361 30-Jun-2014 palle

sun4v: The maximum number of register windows is a constant and thus not available via the %ver register (sun4u only). Introduce a macro GET_MAXCWP that handles this, so cpu_switchto() works properly on sun4v. Other relevant reference to %ver can be adapted to use GET_MAXCWP as the sun4v port progresses. OK martin@


# 1.360 31-May-2014 palle

sun4v: added missing dtsb miss handling for trap level 1 - with this update the kernel now reaches configure() on sun4v systems


# 1.359 30-May-2014 palle

Remove debugging code introduced by accident in locore.s revision 1.357


Revision tags: yamt-pagecache-base9 rmind-smpnet-nbase rmind-smpnet-base
# 1.358 05-May-2014 palle

sun4v: the trap base address should be assigned to %l1 so %tba is properly setup later in the code - now the kernel gets as far as printing the copyright disclaimer, kernel version and total and available memory before crashing


# 1.357 21-Apr-2014 palle

sun4v: Update comment: modified -> access


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.356 21-Feb-2014 palle

branches: 1.356.2;
sun4v: Rename TLB_ defines to SUN4U_TLB_ so entries created using TSB_DATA() are properly setup for sun4u and sun4v. Relocate the cputyp variable from autoconf.c to locore.s and make it const in param.h so optimized code can be generated. Parts from OpenBSD. Optimization suggested by nakayama@. OK martin@, mrg@, nakayama@


# 1.355 31-Jan-2014 tsutsui

defined(LKM) -> defined(MODULAR)


# 1.354 26-Jan-2014 palle

sun4v: Add handling of spill/fill and dtsb miss traps (with a XXX to be handled later)


# 1.353 07-Jan-2014 palle

sun4v: trap table setup - currently populated with dummy entries which will be properly implemented later - parts from OpenBSD - OK martin@


# 1.352 29-Dec-2013 nakayama

Make buildable w/o options SUN4V.


# 1.351 27-Dec-2013 palle

a) make the hunt through the cpus list more generic b) sun4v: ensure that the interrupt stack is mapped permanently and the TSB is setup properly - parts from OpenBSD. OK martin@


# 1.350 06-Dec-2013 nakayama

Increase an interrupt depth only in the case of hardware interrupts,
and remove the ci_idepth trick in softint_fastintr.

Fixes the following diagnostic panic reported in port-sparc64.

panic: kernel diagnostic assertion "!cpu_intr_p()" failed: file
"../../../../kern/subr_xcall.c", line 351


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 1.349 24-May-2013 nakayama

branches: 1.349.2;
Disable interrupts after calling data_access_error as with
data_access_fault.


# 1.348 28-Apr-2013 nakayama

Use macros in machine/asm.h instead of locally defined, and
introduce CASPTRA for casxa/casa.


Revision tags: agc-symver-base
# 1.347 23-Jan-2013 martin

Fix sparc64_ipi_ccall by adding proper trap setup.
Fixes xcall(9) problems, as exposed by pserialize(9). Noticed by
J. Hannken-Illjes, cause pointed out by Takeshi Nakayama.


# 1.346 23-Jan-2013 martin

Sligthly clean up the (by default unused) #ifdef TRAPS_USE_IG


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.345 10-Nov-2012 nakayama

Revise comment.


# 1.344 10-Nov-2012 nakayama

Use macro instead of magic number.


# 1.343 09-Nov-2012 nakayama

Make setstick() and getstick() to inline functions.


# 1.342 08-Nov-2012 macallan

use system tick timer instead of %tick on UltraSPARC-III-ish CPUs
review & fixes by Takeshi Nakayama


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.341 17-Mar-2012 mrg

branches: 1.341.2;
port the corrected ECC error handling code from freebsd. i noticed my U10
took one of these and then hang. it shouldn't hang, there's a 'sir' here that
doesn't seem to reset properly. oh well.

tested by simulated a trap via 'ta 0x10' and considering that the same, but
it hasn't been tested against a real ECC error yet.


Revision tags: jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base4
# 1.340 03-Mar-2012 nakayama

Fix the root cause of the hack "disable optimizations for uvm_bio.c
on 32 bit kernels".

gcc converts a division in the calculation of UBC_UMAP_ADDR macro
to multiplication (smul or combination of add/sll), and the
register of its result contains a garbage in upper 32 bits (the
upper 32 bits of smul/add/sll's result isn't zero cleared).

Then it passes to pseg_get{,_real} through pmap_extract without the
zero clear of upper 32 bits in the optimization case. So the
result of pseg_get and pmap_extact sometimes gets screwed up.


Revision tags: jmcneill-usbmp-base5 jmcneill-usbmp-base3
# 1.339 19-Feb-2012 rmind

Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.


Revision tags: jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.338 04-Sep-2011 nakayama

branches: 1.338.2; 1.338.6; 1.338.8;
ih_pil is an interrupt level, not an interrupt mask.


# 1.337 27-Jul-2011 nakayama

ivec is assigned to hardware, so count its event counter up in
interrupt_vector, not in softint, and do some optimization.


# 1.336 20-Jul-2011 macallan

add per ivec event counters


# 1.335 12-Jul-2011 mrg

rename sparc64 BLOCK_SIZE and BLOCK_ALIGN to have SPARC64_ prefixes.
for the assembler files, define the old names to the new names
since using the new names cause ugliness due to longer identifer
names, and reduces churn.

fixes build issues in dtv and vaguely makes <machine/psl.h> slightly
less name-space invasive.


# 1.334 18-Jun-2011 nakayama

Add fast softint(9) support for sparc64.

Reviewed on port-sparc64.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 1.333 12-May-2011 mrg

branches: 1.333.2;
first steps towards fujitsu SPARC64 support:

- SPARC64 systems have interrupts with upto 14 bits set, but we only look
at the first 11 bits. trim non IPI interrupts to 11 bits


Revision tags: uebayasi-xip-base7 bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 jym-xensuspend-nbase jym-xensuspend-base
# 1.332 20-Dec-2010 matt

branches: 1.332.2;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.


Revision tags: uebayasi-xip-base6 uebayasi-xip-base5 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 1.331 10-Jul-2010 nakayama

Clear the upper word explicitly before combining two 32-bit values to 64-bit
on 32-bit kernels.


# 1.330 23-May-2010 martin

Split copy related functions out of locore.s into copy.S, move functions
only needed on multiprocessors into mp_subr.S.


# 1.329 17-May-2010 martin

Simplify primary CPU startup slightly by using the fact that our cpuinfo's
curpcb pointer points to the uarea/pcb of lwp0 and by remembering the pointer
to this cpuinfo, thus avoiding a few CPUINFO_VA references.


Revision tags: uebayasi-xip-base1
# 1.328 20-Mar-2010 chs

fix copy{in,out}{,str}() to return the error returned by uvm_fault().
fixes PR 41813.


Revision tags: yamt-nfs-mp-base9
# 1.327 10-Mar-2010 mrg

branches: 1.327.2;
XXX: workaround we'd like to remove when pmap / uvm locking is cleaned up:

- rename pseg_get() and pseg_set() to pseg_get_real() and pseg_set_real().
- if USE_LOCKSAFE_PSEG_GETSET is defined, which it current is by default,
define pseg_[gs]et() in terms of functions that take a new pseg_lock
mutex at IPL_VM while calling into the real functions.

this seems to avoid the pseg_set() crashes we've seen:
1 - spare needed, when pseg_get() just worked for this pmap
2 - the 2rd ldxa via ASI_PHYS_CACHED in pseg_set() loads garbage
into %o4, and causes the 3rd ldxa to fault


# 1.326 08-Mar-2010 mrg

blast_dcache() SMP friendly:

- blast_dcache() becomes sp_blast_dcache(dcache_size, dcache_line_size)
- new smp_blast_dcache(sparc64_cpuset_t) that blasts the D$ on this cpuset
- sparc64_ipi_blast_dcache() to support the above
- in pmap_remove_all(), when freeing mmu contexts for this pmap, mark
the set of cpus to blast the d$ on as well and convert the
blast_dcache() call into smp_blast_dcache() on the cpus who ran this
pmap, or, sp_blast_dcache(dcache_size, dcache_line_size)
- convert the remaining blast_dcache() in machdep.c to sp_blast_dcache()
- in pmap_destroy()/pmap_remove_all() take the pmap_lock() always since
we assert it is held always.

with these changes, NFS builds on the U60 seem to be stable now, and
the USIII machines also can often complete a single build.sh run now,
diskful or diskless.


reviewed by mlelstv and partially by martin, tested by martin and myself,
with some ideas from chuq as well.


# 1.325 07-Mar-2010 mrg

need _ALIGN in locore.h as well, for DEBUG kernels.


# 1.324 07-Mar-2010 mrg

gas has supported SPARC ".empty" for a long while; get rid of an
ancient workaround.


# 1.323 06-Mar-2010 mrg

move the memcpy/memset implementations out into their own file, with the
block copy versions as well. move some of the definitions in locore.s
into a new locore.h.

locore.s is almost 2000 lines shorter with this change.


# 1.322 04-Mar-2010 mrg

- in _bus_dmamap_unload(), pmap_page_protect() and pmap_clear_reference()
switch the dcache_flush_page() into a dcache_flush_page_all()
- in both pmap_kremove()/pmap_remove(), remove the blast_dcache() call
and replace it with dcache_flush_page_all()
- in pmap_get_page() [used to allocate PTP's], always call pmap_zero_page(pa)
- flush the dcache of the dst page in pmap_{copy,zero}_page() by redirecting
throught a C function that calls the (renamed) asm. the old asm code had a
comment about needing to do this...
- add a couple of membar #Sync's that the USIII manual recommends


based on discussions with chuq@, skrll@ and martin@.


these help my SB2000 / SB2500 with both disk / nfs builds and other tasks,
sometimes lasting for several hours before failing or asserting.


# 1.321 24-Feb-2010 mrg

when handing back page table pages to UVM, flush them from the dcache
on all CPUs.

idea from skrll@, and makes my disk-based SB2000 stable.

tested on U60, SB2000 and SB2500.


# 1.320 24-Feb-2010 mrg

- re-introduce sp_tlb_flush_pte() and sp_tlb_flush_all() that call
the right USI/USIII version.
- define tlb_flush_pte() in terms of sp_tlb_flush_pte() for the
!MULTIPROCESSOR case

this centralises some CPU_IS_USIII_UP() tests.


# 1.319 22-Feb-2010 mrg

move {dump,print}_[id]tlb() into a separate file.


# 1.318 22-Feb-2010 mrg

- store the maximum [id]cache size / line size for each cpu

- remove patch_kernel() since it isn't necessary and has been patching
the wrong thing in general.

- implement USIII versions of blast_icache(), dcache_flush_page() and
cache_flush_phys(). use the newly recorded cache size/line sizes.

- in winfixsave, flush the D$ with the right size index and ops. this
kills one of the wrong tag->inval patches.

- for blast_dcache(), use the newly recorded dcache_size/line_size.

- for blast_icache(), use the newly recorded cache size/line sizes.
for the USIII verison, disable the I$ while writing to ASI_ICACHE_TAG.


these changes removed several hard coded cache sizes values, some very
wrong kernel patching, and seem to make the current failure modes for
USIII less common, but not gone.


# 1.317 15-Feb-2010 mrg

- don't flush 32-bit entries for 64-bit code, it does not seem to be
necessary. #define TLB_FLUSH_LOWVA to turn it back on.
- remove the #if 0'd code in sparc64_ipi_flush_pte_usiii(), i have
verified that it is not required.
- add a missing membar #Sync to sp_tlb_flush_pte_usiii().


# 1.316 15-Feb-2010 nakayama

Fix linker error of GENERIC32 kernel.


# 1.315 15-Feb-2010 mrg

use TLB_SIZE_SPITFIRE in a couple of places, and note that the
{print,dump}_[id]tlb() versions are currently spitfire specific.


# 1.314 15-Feb-2010 mrg

introduce a new patch_kernel() and call it from the end of bootstrap().
use it to patch up TLB flush instructions that don't match for USI/II
and later. we can also hopefully use this to make GENERIC.MP minimally
expensive on single CPU machines as well.

this is the last piece needed to get GENERIC/GENERIC.MP to boot on the
USIII* machines.

idea and some initial code from openbsd.


# 1.313 13-Feb-2010 mrg

remove KTR support. it's never been a working part of netbsd src tree.


# 1.312 09-Feb-2010 wiz

Fix typo in comment.


Revision tags: uebayasi-xip-base
# 1.311 06-Feb-2010 mrg

branches: 1.311.2;
- properly map the schizo interrupt registers, so we can use the normal
virtual mappings to access them.
- with the above fxied, kill SCHIZO_BUS_SPACE_BROKEN, and introduce
an options CHEETAH for now, that disables the SPITFIRE code in locore.
- merge schizo_init() into schizo_attach() and clean up the softc a bit.


with this we are only one more step away from GENERIC booting on USIII
machines.


# 1.310 02-Feb-2010 mrg

- split sp_tlb_flush_pte() and switchtoctx() into sp_tlb_flush_pte_us()/
sp_tlb_flush_pte_usiii() and switchtoctx_us()/switchtoctx_usiii() and
implement the latter while i'm here. it works ... sometimes i think,
but also sometimes panics/hangs.
- fix a comment in sparc64_ipi_flush_pte_usiii()


# 1.309 02-Feb-2010 mrg

for now, reduce a few #ifdef SPITFIRE cases by introducing a new
ASI_DCACHE_TAG_OR_INV that is either ASI_DCACHE_{TAG,_INVALIDATE}.

increase the common code in cache_flush_phys().


# 1.308 01-Feb-2010 mrg

- sp_tlb_flush_all() becomes sp_tlb_flush_all_us() and sp_tlb_flush_all_usiii()
- sparc64_ipi_flush_pte() becomes sparc64_ipi_flush_pte_us() and
sparc64_ipi_flush_pte_usiii()
- add some commented out code to disable interrupts and raise the traplevel
in sparc64_ipi_flush_pte_usiii()
- cache_flush_phys() was missing a little of code in the cheetah case


# 1.307 01-Feb-2010 mrg

for USIII, use the new "tlb demap all" operation in sp_tlb_flush_all()


# 1.306 01-Feb-2010 mrg

remove unused icache_flush_page() implementation.


# 1.305 23-Jan-2010 mrg

remove the final uses of DATA_START.

now we can remove the 16KB space reserved at the start of the data segment,
and i now understand why i wrote this now removed comment 3.5 years ago:
"this shouldn't be needed... but kernel usually hangs without it"


# 1.304 23-Jan-2010 mrg

remove most of the code that writes debugging info DATA_START + offset.


# 1.303 23-Jan-2010 mrg

remove CHKPT() macro and uses. it's likely wrong in SMP land and probably should
be replaced with KTR-style uses if necessary.


# 1.302 23-Jan-2010 mrg

fix a comment.


Revision tags: matt-premerge-20091211
# 1.301 10-Dec-2009 rmind

Rename L_ADDR to L_PCB and amend some comments accordingly.


# 1.300 05-Dec-2009 mrg

- adjust the PA mask to the 43 bits supported by USIII.
- rework the spitfire/cheetah cache_flush_phys() to avoid several #ifdefs
- add a membar #Sync after sparc64_ipi_drop_fpstate (probably unnecessary)


# 1.299 30-Nov-2009 nakayama

sp_tlb_flush_pte for cheetah:
- restore interrupts properly in case of %tl > 0.


# 1.298 30-Nov-2009 mrg

stablize UP USIII support by blocking interrupts around sp_tlb_flush_pte()
i was seeing stack corruption while taking an interrupt in this function.

get USIII SMP mostly working by implementing the cheetah version of
sparc64_ipi_flush_pte().


SMP support is still not entirely stable. i can reproducably get a:

panic: fpusave_lwp ipi didn't

while running build.sh, when an awk process is exiting. other simple
heavy work loads do not crash for me right now.


# 1.297 30-Nov-2009 mrg

delete some no longer used code:
- smp_tlb_flush_ctx()
- smp_tlb_flush_all()
- sparc64_ipi_flush_ctx()
- sparc64_ipi_flush_all()
- sp_tlb_flush_ctx()


# 1.296 29-Nov-2009 nakayama

- calculate end PA correctly.
- wrap more spitfire specific (flushing I$) code.
- fix inverted #if condition for flushing I$ (and restore ASI_ICACHE_TAG).


# 1.295 28-Nov-2009 mrg

implement enough code to get SB2000/SB2500 booting to multiuser. does
not last long if you use it, but an idle machine has stayed up 10 hours.

- for the !SPITFIRE case, use ASI_DCACHE_INVALIDATE instead of
ASI_DCACHE_TAG when clearing tlb entries. from openbsd.

- convert some comment "! Not yet" into "WRITEME", so that attempting
to build a USIII MULTIPROCESSOR kernel fails to build until the code
is written.

- add some more WRITEME's for the above.

- implement a !SPITFIRE version of sp_tlb_flush_all(). since there are
no spare regs, for now just always increase %tl around this call. (we
could maybe store a token in %o3 along with the saved %pstate info.)


# 1.294 26-Nov-2009 matt

Kill proc0paddr. Use lwp0.l_addr instead.


# 1.293 25-Nov-2009 mrg

s/L_ADDR/L_PCB/, requested by rmind.


# 1.292 17-Oct-2009 nakayama

Wrap unused code with #if 0 which is called from #if 0'ed code.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5
# 1.291 30-May-2009 martin

cpu_setfunc() can not use lwp_trampoline, as that has additional lwp startup
semantics. Use a simpler setfunc_trampoline instead.


# 1.290 18-May-2009 nakayama

Remove random() from locore.s since it is in libkern.


# 1.289 16-May-2009 nakayama

Remove clear %tick in locore.s since it is cleared at cpu_initclocks() in
clock.c.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 nick-hppapmap-base mjf-devfs2-base
# 1.288 15-Dec-2008 mrg

restore some old "intrdebug" code, but leave it under NOT_DEBUG. most
of it works, but one that prints func/arg for each handler is not very
stable...

for now, while schizo bus space pointer accesses aren't working, add
a SCHIZO_BUS_SPACE_BROKEN option so you can build a kernel with schizo.

with this, and the prior schizo interrupt fix, you can now fail to run
/sbin/init!


Revision tags: haad-dm-base2 haad-nbase2 haad-dm-base
# 1.287 09-Dec-2008 martin

Get rid of get_maxctx() - it doesn't work on newer cpus and we will have
to find a better way for (some) sun4v machines - all sun4u use 13 bit
contexts anyway.


Revision tags: netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 ad-audiomp2-base netbsd-5-base
# 1.286 30-Oct-2008 nakayama

branches: 1.286.2; 1.286.6;
Wrap more code specific to USE_BLOCK_STORE_LOAD.


Revision tags: matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4
# 1.285 05-Oct-2008 nakayama

branches: 1.285.2;
- in flushing cache, use 32 as increment/decrement value to match the
cache line size.
- remove useless restore of %asi.
- remove nop in delay slot if we can.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 1.284 10-Jul-2008 nakayama

Use proper CCR.


# 1.283 10-Jul-2008 nakayama

sparc64_ipi_save_fpstate:
- use primary MMU context for consistency with other trap/interrupt handlers.

sparc64_ipi_save_fpstate, savefpstate:
- avoid storing fp registers as we can.

sparc64_ipi_save_fpstate, savefpstate, loadfpstate:
- remove unaligned case since buffers allocated with pool_cache are ensured
64-byte aligned.

Ok by martin@.


# 1.282 02-Jul-2008 nakayama

branches: 1.282.2;
UltraSPARCs don't have floating point queue, and reading %fq regsiter
will cause illegal instruction trap. So remove the code handling them.


# 1.281 29-Jun-2008 nakayama

Wrap IPI calls with #ifdef MULTIPROCESSOR.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.280 14-Jun-2008 nakayama

Close unterminated comment.
Fix unexpected behavior in case of loadfpstate from unaligned buffer.


Revision tags: yamt-pf42-base3
# 1.279 31-May-2008 nakayama

branches: 1.279.2;
openfirmware_exit:
- disable interrupts with %pstate.
- prepare 64-bit stack and enable 64-bit addresses for 32-bit SMP kernels.


Revision tags: hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 yamt-nfs-mp-base yamt-pf42-base
# 1.278 16-Apr-2008 nakayama

branches: 1.278.2; 1.278.4; 1.278.6;
Disable TRAPSTATS which was accidentally enabled when yamt-idlelwp branch
was merged.

Ok by martin@.


# 1.277 14-Apr-2008 nakayama

Remove sparc64_ipi_sync_tick.

Since we can use counter-timer as timecounter instead of %tick on SMP kernel,
it is not necessary to sync all CPUs %tick registers.


# 1.276 14-Apr-2008 nakayama

Add workaround for BB_ERRATA_1 on writing to TICK_CMPR register in
next_tick(). If writing to TICK_CMPR fails, we lose hardclock interrupt
on secondary CPUs.

About BB_ERRATA_1 from comment in OpenSolaris:

/*
* Writes to the TICK_COMPARE register sometimes fail on blackbird modules.
* The failure occurs only when the following instruction decodes to wr or
* wrpr. The workaround is to immediately follow writes to TICK_COMPARE
* with a read, thus stalling the pipe and keeping following instructions
* from causing data corruption. Aligning to a quadword will ensure these
* two instructions are not split due to i$ misses.
*/


# 1.275 28-Mar-2008 nakayama

Don't read fplwp content in delay slot for considering the case fplwp was
modifiled.

Reported by Chris Ross on port-sparc64.


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.274 20-Mar-2008 nakayama

- remove disabling interrupt in IPI.
- unused VA bits in MMU demap is 13 bits, not 12 bits.


# 1.273 18-Mar-2008 nakayama

Fix a race when increment an interrupt level event counter.


# 1.272 17-Mar-2008 nakayama

Fix a race condition in IPI handlers of save/drop fpstate, from OpenBSD.
Reported and tested by martin@.


# 1.271 17-Mar-2008 nakayama

Make schedintr interrupt handler per-CPU.
While there rename tickintr interrupt handler and share initialization
code with schedintr.


# 1.270 14-Mar-2008 nakayama

Improve IPI handling:
- make IPI takes two arguments.
- add IPI event counters per-CPU.
- implement IPI functions which were missing or broken.
- insert DELAY while halting primary CPU in IPI handler.


# 1.269 02-Mar-2008 nakayama

- make interrupt pending list per-CPU.
- make tickintr() MP-safe.
- remove unused port-sparc derived interrupt code.

Ok by martin@.


# 1.268 02-Mar-2008 nakayama

Don't get IPI handler argument (from bogus address), and ack IRQ twice.


# 1.267 28-Feb-2008 martin

Make TSBs and MMU contexts per-cpu.


Revision tags: nick-net80211-sync-base mjf-devfs-base hpcarm-cleanup-base
# 1.266 26-Jan-2008 nakayama

branches: 1.266.2; 1.266.6;
Fix for 32-bit kernels.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.265 15-Jan-2008 skrll

Store a sensbile PCB_PC value in snapshot - the return point.

This helps gdb somewhat.

OK'd by martin.


# 1.264 14-Jan-2008 martin

Fix register name typo/copy&pasto - %g6 is not %o6/%sp.
From OpenBSD.


Revision tags: matt-armv6-base
# 1.263 06-Jan-2008 martin

Load the next cpu_info pointer with LDPTR instead of ld.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2
# 1.262 09-Dec-2007 martin

branches: 1.262.2;
Provide cpu_intr_p(), at least for non-MULTIPROCESSOR kernels.
Based on suggestions by Andrew Doran.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.261 22-Oct-2007 martin

branches: 1.261.2; 1.261.4; 1.261.6;
Remove an unused .globl declaration


Revision tags: yamt-x86pmap-base4
# 1.260 17-Oct-2007 garbled

Merge the ppcoea-renovation branch to HEAD.

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

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

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base ppcoea-renovation-base vmlocking-base
# 1.259 09-Sep-2007 martin

branches: 1.259.4;
Make cpufrequency and friends per cpu values.
Prepare a hz tick interrupt on secondary CPUs via %tick, but do not
enable it yet, as it breaks ddb.


# 1.258 09-Sep-2007 martin

Do not ACK IPIs before we finished loading all arguments.


# 1.257 06-Sep-2007 martin

Remove the (now unused) second 64k page mapped per CPU.
From matthew green, with small changes by me. All bugs are mine.


# 1.256 25-Aug-2007 martin

branches: 1.256.2;
Remove INITSTACK completely - at the time we used to switch to it, we
already have access to all of lwp0 and it's uarea - so we can switch
to the correct lwp0 stack easily before calling main.


# 1.255 25-Aug-2007 martin

When exiting to OF, use the interrupt stack instead of INITSTACK


# 1.254 25-Aug-2007 martin

Rework cpu_mp_startup slightly:
- temporarily use the cpu's interrupt stack untill we are ready
to access non-OF-based mappings, then directly switch to the cpu's
idlelwp's uarea stack
- disable interrupts untill we are ready to call C code


# 1.253 13-Aug-2007 macallan

remove two restore without matching save


Revision tags: nick-csl-alignment-base matt-mips64-base mjf-ufs-trans-base
# 1.252 06-Jul-2007 martin

branches: 1.252.4; 1.252.8;
A few nits for 32bit SMP kernels, noticed by mrg.
While there, simplify the fpstate IPIs a bit.


# 1.251 05-Jul-2007 martin

sparc64_ipi_save_fpstate is not a leaf function - create a full grown
stack frame.


# 1.250 28-May-2007 mrg

clean up cpu_switchto() a little - no need to flushw or membar
excessively. optimise an rdpr. tested by tnn.


# 1.249 23-May-2007 martin

Fix a stupid bug in the save_fpstate ipi, which caused overwriting of
struct lwp of the lwp owning the fpu. Fix clearing the fplwp - %o0 will
not survive the call to savefpstate - duh!


# 1.248 20-May-2007 martin

Simplify tf_tstate setting when leaving for userland initially - I seem
to have confused the if with the else case of the previous C code.
Funny that it worked at all.


# 1.247 20-May-2007 martin

cpu_switchto() has to return it's first arg, always. This differs from
my reading of the documentation, but helps in the real world and seems
to be what other ports do.


# 1.246 20-May-2007 martin

Remove special case handling for userland lwps from cpu_lwp_fork, instead
do it in lwp_trampoline when we first return to userland.


# 1.245 19-May-2007 martin

cpu_idle is a leaf function, so we better "return from leaf".
Use return value from cpu_switchto for previous lwp in lwp_trampoline.
Also shamelessly steal a comment from uwe written for sparc that explains
all this.
Thanks to tnn, mrg, and uwe for helping to debug this.


# 1.244 17-May-2007 yamt

merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base ad-audiomp-base
# 1.243 22-Feb-2007 martin

branches: 1.243.4; 1.243.6; 1.243.12;
uvm.page_idle_zero now is a bool, not a 32bit value any more.


# 1.242 21-Feb-2007 mrg

shave 9 insns off the tsb setup in cpu_initialize & cpu_mp_startup.


# 1.241 21-Feb-2007 martin

Get rid of unused (thus always zero) "curlwp" variable hidden in assembler
code (C code always uses a cpuinfo based macro).


# 1.240 18-Feb-2007 martin

Make use of another call delay slot, pointed out by uwe.


# 1.239 18-Feb-2007 martin

Make use of a call delay slot and avoid a bogus EMPTY.
Spotted by Juergen Hannken-Illjes, with input from Andrew Doran and
Valeriy E. Ushakov.


# 1.238 18-Feb-2007 martin

Whitespace cosmetics


# 1.237 18-Feb-2007 martin

Backout previous: EMPTY was misused


# 1.236 18-Feb-2007 martin

Make EMPTY expand to nop with gas, as it is used to mark empty branch
delay slots.


# 1.235 15-Feb-2007 martin

branches: 1.235.2;
Fix obvious copy&pasto in SCHED_DEBUG register usage.


Revision tags: post-newlock2-merge
# 1.234 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.233 25-Dec-2006 wiz

Spell "relevant" correctly. From Zafer Aydogan.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.232 25-Oct-2006 mrg

branches: 1.232.2; 1.232.4;
- note that __idle_u should go away but doing so breaks things
- fix several comments to reality
- clean up the #ifdef NO_VCACHE code slightly
- use call instead of set/jmpl
- remove a couple of unnecessary stores to curlwp


Revision tags: yamt-splraiseipl-base2
# 1.231 18-Oct-2006 rjs

Clean up some comments. Cosmetic change to use correct structure
offset names.

Optimize out two instructions from sparc64_ipi_save_fpstate and
sparc64_ipi_drop_fpstate.


# 1.230 17-Oct-2006 mrg

allocate 128KB (as opposed to 64KB) per-cpu, and place the interrupt
stack, cpu_info structure, panicstack, idle uarea and normal kernel
stack in here. the idle uarea and kernel stack are in the 2nd 64KB
page. the interrupt stack and cpu_info structure are as the same
place in the 1st 64KB page, and the panicstack grows down from the
top of this page. update comments in param.h to suit (XXX: a lot
of these constants should move to a header file that will not pollute
the name space so much.) map these pages identically between
cpu_initialise() and cpu_mp_startup(), and deal with the two 64KB
pages in pmap_extract(). keep an unmapped 64KB page between them.

don't initialise the unused "ci_eintstack" member of the cpu_info
structure

use constants to initialise many addresses in the cpu_info structure,
consolidating these assignments from cpu0 and cpu>0

delete u0/estack0/panicstack from locore.s

clean up some wrong comments in locore.s

fix a 32bit-only bug in cpu_mp_startup().

delete 'u0' entirely.


this fixes recent random lossage seen on port-sparc64: processes
stuck in RUN state, data faults, and hangs.


# 1.229 04-Oct-2006 mrg

use call instead of set/jmpl. add an entry point for idle that expects
sched_lock to be unlocked, and use this for non-boot cpu's. complete a
comment describing how registers in idle_switch are expected to be set.


# 1.228 03-Oct-2006 mrg

use the same SAVE_LOCALS_INS definition for 32 bit and 64 bit kernels.
refactor TRAP_SETUP() a little between these two versions to be more alike.


# 1.227 03-Oct-2006 mrg

use the correct size/type for MP variables (pointers and longs).

a 32 bit MULTIPROCESSOR kernel now builds (and crashes quickly.)


# 1.226 03-Oct-2006 mrg

in the 64bit version of SAVE_LOCAL_INS, s/BIAS/STKB/ to allow future
sharing of the 32 and 64 bit versions of the {TRAP,INTR}_SETUP macros.


# 1.225 19-Sep-2006 mrg

- remove some way old FP setup/teardown code
- put the block memcpy/memset inside #ifdef USE_BLOCK_STORE_LOAD which
is (now) defined.

no functional change, same .o is generated.


# 1.224 19-Sep-2006 mrg

re-order the changes in rev 1.217 to give registers a little bit of
time to settle between usage, like it was before hand.


# 1.223 19-Sep-2006 mrg

- remove a wrong comment.
- add a new entry point for idle called idle_switch that is called by
cpu_switch() in the MP case when sched_whichqs is zero, properly
setting up the idle stack. from petrov@ via martin@.


# 1.222 19-Sep-2006 mrg

rework interrupt_vector() slightly:
- for the IPI case, avoid loading the address of intrlev into %g3
- remove some NOT_DEBUG code
- load the interrupt argument #2 in the delay slot

this removes 2 nops during interrupt processing for the normal
case, and an additional 2 ALU instructions for IPIs


# 1.221 18-Sep-2006 mrg

- sparc64_ipi_halt(): we shouldn't return from sparc64_ipi_halt_thiscpu()
so replace a branch with a 'sir'
- in #if 0 code, in sparc64_ipi_flush_pte() and sparc64_ipi_flush_ctx()
save/restore the out registers that the sp_tlb_flush_xxx() versions
around calling them
- in sp_tlb_flush_pte() and sp_tlb_flush_ctx(), replace global register
usage with out registers so that we don't clobber the (alternate)
global registers when these are called from IPI context


# 1.220 18-Sep-2006 mrg

- remove an extra 'sir' that followed one in a macro
- add some named labels to some spill/fill handlers
- remove 2 unused strings


Revision tags: yamt-splraiseipl-base
# 1.219 18-Sep-2006 martin

branches: 1.219.2;
Lazy FPU handling for the MULTIPROCESSOR case


# 1.218 16-Sep-2006 nakayama

From OpenBSD:
- reload %fprs for checking it again.
- use symbolic names for checking in %fprs.

revision 1.51
date: 2005/07/18 14:50:11; author: deraadt; state: Exp; lines: +2 -1
cache a copy of the fprs so we know what fp restore we should do after

revision 1.50
date: 2005/07/14 01:46:13; author: deraadt; state: Exp; lines: +4 -4
use symbolic names for checking in %fprs, as above


# 1.217 16-Sep-2006 nakayama

Fix a couple of %y register save/restore errors, inspired from OpenBSD.

revision 1.44
date: 2004/04/23 04:18:17; author: marc; state: Exp; lines: +5 -4

fix a couple of %y register save/restore errors
1) don't save %y in a register that is later used before restoring %y
2) always restore %y after calling a signal handler
tested by drahn@, OK pval


# 1.216 15-Sep-2006 martin

Do not bother to save fpu state when we are about to get rid of it.


Revision tags: yamt-pdpolicy-base9
# 1.215 13-Sep-2006 mrg

SMP cleanup. provide support for multiple CPUs in DDB. (SMP itself
is still not working.)

cpu.h:
- add a pointer for DDB regs in SMP environment to struct cpu_info
- remove the #defines for mp_pause_cpus() and mp_resume_cpus()
cpuset.h:
- remove CPUSET_ALL() and rename CPUSET_ALL_BUT() to CPUSET_EXCEPT()
from petrov.
db_machdep.h:
- rename the members of db_regs_t to be the same as sparc
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- redo DDB_REGS to no longer be a pointer to a fixed data structure
but to one allocated per-cpu when ddb is entered
- move a bunch of prototypes in here
intr.h:
- remove SPARC64_IPI_* macros, no longer used
db_interface.c:
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- make "nil" a 64 bit entity
- change the ddb register access methods to work in multiprocessor
environment, it is now very much like sparc does it
- in kdb_trap() avoid accessing ddb_regp when it is NULL
- update several messages to include the cpu number
- unpause other cpus much later when resuming from ddb
- rename db_lock() to db_lock_cmd(), as the sparc-like code has
db_lock as a simple lock
- remove "mach cpus" command, and replace it with "mach cpu" (which
does the same) and also implement "mach cpu N" to switch to
another cpus saved trapframe
db_trace.c:
- update for the ddb_regs -> ddb_regp change
genassym.cf:
- add TF_KSTACK as offsetof(struct trapframe64, tf_kstack)
ipifuncs.c:
- overhaul extensively
- remove all normal interrupt handlers as IPI's, we now handle
them all specially in locore.s:interrupt_vector
- add a simplelock around all ipi functions - it's not safe for
multiple cpus to be sending IPI's to each other right now
- rename sparc64_ipi_pause() to sparc64_ipi_pause_thiscpu() and,
if DDB is configured, enable it to save the passed-in trapframe
to a db_regs_t for this cpu's saved DDB registers.
- remove the "ipimask" system (SPARC64_IPI_* macros) and instead
pass functions directly
- in sparc64_send_ipi() always set the interrupt arguments to 0,
the address and argument of the to be called function. (the
argument right now is the address of ipi_tlb_args variable, and
part of the reason why only one CPU can send IPI's at a time.)
don't wait forever for an IPI to complete. some of this is
from petrov.
- rename sparc64_ipi_{halt,pause,resume}_cpus() to
mp_{halt,pause,resume}_cpus()
- new function mp_cpu_is_paused() used to avoid access missing
saved DDB registers
- actually broadcast the flush in smp_tlb_flush_pte(),
smp_tlb_flush_ctx() and smp_tlb_flush_all(). the other end may
not do anything yet in the pte/ctx cases yet...
kgdb_machdep.c:
- rework for changed member names in db_regs_t.
locore.s:
- shave an instruction from syscall_setup() (set + ld -> sethi + ld)
- remove some old dead debug code
- add new sparc64_ipi_halt IPI entry point, it just calls the C
vector to shutdown.
- add new sparc64_ipi_pause IPI entry point, which just traps into
the debugger using the normal breakpoint trap. these cpus usually
lose the race in db_interface.c:db_suspend_others() and end up
calling the C vector sparc64_ipi_pause_thiscpu().
- add #if 0'ed code to sparc64_ipi_flush_{pte,ctx}() IPI entry
points to call the sp_ version of these functions.
- in rft_kernel (return from trap, kernel), check to see if the
%tpc is at the sparc64_ipi_pause_trap_point and if so, call
"done" not "retry"
- rework cpu_switch slightly: save the passed-in lwp instead of
using the one in curlwp
- in cpu_loadproc(), save the new lwp not the old lwp, to curlwp
- in cpu_initialize(), set %tl to zero as well. from petrov.
- in cpu_exit(), fix a load register confusion. from petrov.
- change some "set" in delay branch to "mov".
machdep.c:
- deal with function renames
pmap.c:
- remove a spurious space
trap.c:
- remove unused "trapstats" variable
- add cpu number to a couple of messages


# 1.214 09-Sep-2006 mrg

significant clean up effort, largely from petrov@ via martin@.

- fix a bunch of comments for proc->lwp
- remove old TRAPTRACE, NOT_DEBUG, etc. code that has bit-rotted
- put some older DEBUG code under NOT_DEBUG
- add a bunch of new debugging/tracing code ("KTR") that depends on
other changes not yet present.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base yamt-pdpolicy-base5 chap-midi-base simonb-timecounters-base rpaulo-netinet-merge-pcb-base
# 1.213 14-May-2006 elad

branches: 1.213.6; 1.213.8;
integrate kauth.


# 1.212 12-May-2006 skrll

Fix some comments.


Revision tags: elad-kernelauth-base
# 1.211 09-May-2006 rjs

Load CPCB in cpu_mp_startup.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.210 11-Feb-2006 cdi

branches: 1.210.2; 1.210.4; 1.210.6;
ANSIfication: u_intN_t -> uintN_t, use ANSI function declarations/definitions
instead of K&R ones.


# 1.209 27-Jan-2006 cdi

branches: 1.209.2; 1.209.4;
Alter sparc64 bootstrap, catch up to ofwboot v1.9:

- Accept bootinfo structure passed down from ofwboot v1.9
- Drop kernel re-mapping code
- Use permanent 4MB mappings provided by the loader instead
- Change kernel entry address to point directly at the code instead of pointing
at the trap table's first slot. This allows the bootloader to detect
those kernels which are aware of the new boot scheme
- Due to the changes in kernel mapping code, alter secondary CPU bootstrap
code to use trampoline just like FreeBSD does (some FreeBSD code is used
here as well)


# 1.208 12-Jan-2006 cdi

Fix a typo: %g0 should be used instead of %o0 when initializing FPU in dostart:
and cpu_mp_startup:, %o0 is not even initialized at this point.


# 1.207 11-Dec-2005 christos

branches: 1.207.2;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 1.206 10-Jul-2005 christos

Re-factor syscall, and make it use syscall_{plain,fancy}.


# 1.205 31-May-2005 chs

branches: 1.205.2;
remove vestigal {,e}intr{names,cnt} symbols now that vmstat doesn't need them.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.204 12-Feb-2005 chs

branches: 1.204.4; 1.204.6; 1.204.8;
in sparc_interrupt(), wait to enable interrupts until just before calling
the handler and disable them again right after the handler returns.
we don't want another hardware interrupt coming in while we're mucking
with the list pointers. also, clear the intrhand's ih_pending pointer
before calling the handler rather than after, so that if another interrupt
comes in while the handler is running, we can put the intrhand back on
the list so it will be called again.

in send_softint(), disable interrupts via %pstate instead of %pil, so that
hardware interrupts at higher levels are blocked while we manipulate the
intrpending list. also, if the intrhand already has ih_pending set,
don't bother poking the SET_SOFTINT register again, since being on the list
implies that there is already a softint pending in the hardware.

these appear to fix PR 21750 (the "sleep forever" problem).

while I'm here, remove more vestiges of the !INTRLIST softint stuff
(code and comments). and in sparc64_ipi_flush_all(), interrupts are
already disabled so we don't need to fiddle with %pstate.


Revision tags: yamt-km-base2
# 1.203 30-Jan-2005 martin

Remove the no long usefull variants selected by undefining INTRLIST and
INTR_INTERLOCK to improve readability. Same object code generated as before.


Revision tags: yamt-km-base
# 1.202 16-Jan-2005 chs

branches: 1.202.2;
use ENTRY_NOPROFILE() for various entry points,
stack traces work better that way.


Revision tags: kent-audio1-beforemerge kent-audio1-base
# 1.201 03-Dec-2004 chs

branches: 1.201.4;
remove cache_flush_virt() and PADDRT, they're no longer used.
allocate a stack frame for blast_dcache() when profiling so it shows up.
in dcache_flush_page(), use a stride of 32 instead of 16 to match the
cache line size. correct various comments.


# 1.200 08-Nov-2004 petrov

Don't compile sparc64_ipi functions when UP.


# 1.199 25-Oct-2004 martin

No need to clear %o1 when returning a 64 bit integer from pseg_get if we
are compiling for a 64 bit kernel.


# 1.198 24-Jul-2004 nakayama

Change interrupt pending list end value to -1, to avoid linking an
interrupt handler twice.

It may fix "sleep forever" bug.


# 1.197 09-Apr-2004 petrov

Clean-up unused defines and variables.


Revision tags: netbsd-2-0-base
# 1.196 26-Mar-2004 petrov

branches: 1.196.2;
Use want_resched from cpu_info area.


# 1.195 23-Mar-2004 martin

Replace intrcnts by evcnts. XXX - needs slight tweaking for MULTIPROCESSOR.


# 1.194 14-Mar-2004 chs

checkpoint of MP work from dennis and myself. includes cross-processor
interrupt framework, a sledgehammer TLB invalidation and misc MP fixes.
doesn't work at all yet.


# 1.193 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.192 19-Jan-2004 martin

Rename switchexit to cpu_exit and g/c the old C implementation of cpu_exit.


# 1.191 18-Jan-2004 martin

Support RAS for 32bit kernels too.


# 1.190 16-Jan-2004 martin

In proc_trampoline don't bother to clear condition codes in the trap
frame, since we no longer rely on this.
While there fix a few comments.


# 1.189 08-Jan-2004 martin

Minor cleanup


# 1.188 06-Jan-2004 martin

Implement restartable atomic sequences (RAS) for sparc64.


# 1.187 06-Jan-2004 petrov

Spinup secondary cpus. Based on codes sent to me by Dennis Chernoivanov
and Chuck Silvers.


# 1.186 04-Jan-2004 jdolecek

update to recent changes - exit2() doesn't exist anymore and the
exit path always calls lwp_exit2()
pointed out Martin Husemann


# 1.185 02-Dec-2003 martin

Minor cleanup: remove unused code, sync a comment with current reality.


# 1.184 25-Nov-2003 cdi

Use per-cpu pcb, curlwp and fplwp rather than global ones. This brings
GENERIC.MP configuration to a usable state.

Approved by petrov@.


# 1.183 24-Nov-2003 cdi

Call 'proc_trampoline_mp' from 'proc_trampoline' in a multiprocessor
configuration. Fix process locking. Approved by petrov@.


# 1.182 20-Nov-2003 petrov

Remove nwindows calculation, it's not used. Set l_cpu in cpu_switch.


# 1.181 09-Nov-2003 martin

Get rid of bcopy/bzero.


# 1.180 26-Oct-2003 christos

Initial siginfo support for sparc64 (untested). COMPAT_16 sigcontext signal
delivery tested.


# 1.179 24-Aug-2003 chs

add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default. the changes
fall into two basic catagories:

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

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

originally from openbsd, adapted for netbsd by me.


# 1.178 08-Jul-2003 cdi

traceit: don't use %g7 as it is to become curcpu() register. Add comments.


# 1.177 18-May-2003 martin

branches: 1.177.2;
Make kernels with options KGDB at least compile.
Still needs some work to make it working.


# 1.176 29-Apr-2003 nakayama

Use BLOCK_ALIGN rather than BLOCK_SIZE for aligning a pointer.


# 1.175 27-Apr-2003 ragge

Preserve the symbol table in the LKM || KSYMS cases also.


# 1.174 04-Apr-2003 petrov

use branch slot in pmap_copy_page.


# 1.173 24-Mar-2003 nakayama

Divide `set' instruction in delay slot (from OpenBSD change to rev 1.30).


# 1.172 10-Feb-2003 martin

Remove some #if 0 code and a few XXX marked membars w/o proper
justification for their existence.


# 1.171 09-Feb-2003 martin

Remove left over pieces from reusing the signal trampoline for upcalls.
This should fix signal delivery for 32bit kernels.


# 1.170 05-Feb-2003 nakayama

Switch to use cycle counter (%tick) based microtime().

This is derived from alpha/microtime.c and i386/tsc_microtime.c,
and will share with both ports.

This should fix PR port-sparc64/18452.
(approved by martin)


# 1.169 04-Feb-2003 martin

Fix return value of pseg_set, which I accidently broke in rev. 1.164.

Fix register names in comment and shave off another register (hint
from uwe).


# 1.168 01-Feb-2003 martin

Rearrange register usage in pseg_set a bit and shave off %g4.


# 1.167 01-Feb-2003 martin

Remove a few #ifdef _LP64 by using STPTR/LDPTR macros.
Thanks to Matthew Green for the pointer.


# 1.166 31-Jan-2003 martin

Apply leaf procedure optimization to pseg_set (again).


# 1.165 31-Jan-2003 martin

Make the pmap count resident/wired mappings on the fly instead of
walking the page tables whenever this information is needed.

Add an option PMAP_COUNT_DEBUG to assert the new counts and the
page table walk agree.

The old solution had very bad performance impact, for example
by the high CPU load when running top(1).

Thanks to Simon Burge for pointing at the cause of the problem and
to Valeriy E. Ushakov for optimizing my simple minded assembler code.


# 1.164 27-Jan-2003 martin

Remove unused function pseg_find (which looked quite similar to
pseg_get anyway).


# 1.163 18-Jan-2003 thorpej

Merge the nathanw_sa branch.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.162 16-Jan-2003 petrov

Move dump_dtlb back under DDB.


# 1.161 15-Jan-2003 chs

fix two bugs in my last pmap rework:
- in tlb_flush_all(), don't skip TLB entries with the high bit on,
I was confused about which MMU register it was using. it's also fine
to use the last hardware context.
- in pmap_create(), don't allocate a hardware context for the new pmap.
it's unnecessary, and when this would cause us to recycle all the contexts,
it would result in the current process's context being set to 0
(ie. the kernel's context). the current process could then return to
userspace without going through the context-switch code (and thus without
having a hardware context reallocated). this would lead to user mappings
being entered in the kernel's context later, causing all sorts of trouble.
add some assertions to catch this kind of thing.


Revision tags: fvdl_fs64_base
# 1.160 25-Dec-2002 petrov

new function dump_itlb.


Revision tags: gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.159 22-Sep-2002 chs

many improvements:
- use struct vm_page_md for attaching pv entries to struct vm_page
- change pseg_set()'s return value to indicate whether the spare page
was used as an L2 or L3 PTP.
- use a pool for pv entries instead of malloc().
- put PTPs on a list attached to the pmap so we can free them
more efficiently (by just walking the list) in pmap_destroy().
- use the new pmap_remove_all() interface to avoid flushing the cache and TLB
for each pmap_remove() that's done as we are tearing down an address space.
- in pmap_enter(), handle replacing an existing mapping more efficiently
than just calling pmap_remove() on it. also, skip flushing the
TSB and TLB if there was no previous mapping, since there can't be
anything we need to flush. also, preload the TSB if we're pre-setting
the mod/ref bits.
- allocate hardware contexts like the MIPS pmap:
allocate them all sequentially without reuse, then once we run out
just invalidate all user TLB entries and flush the entire L1 dcache.
- fix pmap_extract() for the case where the va is not page-aligned and
nothing is mapped there.
- fix calculation of TSB size. it was comparing physmem (which is
in units of pages) to constants that only make sense if they are
in units of bytes.
- avoid sleeping in pmap_enter(), instead let the caller do it.
- use pmap_kenter_pa() instead of pmap_enter() where appropriate.
- remove code to handle impossible cases in various functions.
- tweak asm code to pipeline a little better.
- remove many unnecessary spls and membars.
- lots of code cleanup.
- no doubt other stuff that I've forgotten.

the result of all this is that a fork+exit microbenchmark is 34% faster
and a fork+exec+exit microbenchmark is 28% faster.


Revision tags: gehenna-devsw-base
# 1.158 18-Jul-2002 wiz

Spell 'should' correctly.


# 1.157 07-Jun-2002 eeh

Shave 10% off the time needed to flush the D$ through a bit of instruction
reordering.


# 1.156 05-Jun-2002 eeh

Handle improperly aligned stack pointers more cleanly.


# 1.155 04-Jun-2002 eeh

Fix the fork trampoline to properly use the supplied tstate.


# 1.154 31-May-2002 thorpej

Make this work with an ISO C preprocessor.


Revision tags: netbsd-1-6-base
# 1.153 14-May-2002 eeh

branches: 1.153.2; 1.153.4;
Only save locals and ins in trapframes for DEBUG kernels.


# 1.152 04-May-2002 kleink

Add some comments to the CPP conditionals controlling the trap macro
definitions, to ease navigation somewhat.


# 1.151 16-Apr-2002 eeh

Make lots of routines profile-friendly and get rid of some cruft.


Revision tags: eeh-devprop-base
# 1.150 21-Mar-2002 petrov

Not needed debug stuff deleted.


# 1.149 16-Mar-2002 mrg

tell newer binutils that our use of %g2 and %g3 is OK here.


# 1.148 15-Mar-2002 eeh

Cleanup MMU initialization to prevent hangs.


Revision tags: newlock-base ifpoll-base
# 1.147 09-Feb-2002 eeh

branches: 1.147.4;
Fix microsecond calculation in microtime.


# 1.146 07-Feb-2002 eeh

Fix register allocation in microtime().


# 1.145 29-Jan-2002 eeh

Shift the UPAID in the correct direction.


# 1.144 17-Jan-2002 eeh

Be more tolerant of unaligned stack pointers.


# 1.143 17-Jan-2002 eeh

Enable block insns in bcopy and bzero.


# 1.142 16-Jan-2002 eeh

In bcopy use 32-bit comparisons in 32-bit kernels.


# 1.141 16-Jan-2002 eeh

Use correct calculation for the trapframe in softtrap for ILP32.


# 1.140 20-Nov-2001 lukem

- pull in opt_kgdb.h where necessary
- replace opt_kgdb_machdep.h with opt_kgdb.h
- defparam opt_kgdb.h:
KGDB_DEV KGDB_DEVNAME KGDB_DEVADDR KGDB_DEVRATE KGDB_DEVMODE
- move from opt_ddbparam.h to opt_ddb.h:
DDB_FROMCONSOLE DDB_ONPANIC DDB_HISTORY_SIZE DDB_BREAK_CHAR SYMTAB_SPACE
- replace KGDBDEV with KGDB_DEV
- replace KGDBADDR with KGDB_DEVADDR
- replace KGDBMODE with KGDB_DEVMODE
- replace KGDBRATE with KGDB_DEVRATE
- use `9600' instead of `0x2580' for 9600 baud rate
- use correct quotes for options KGDB_DEVNAME="\"com\""
- use correct quotes for options KGDB_DEV="17*256+0"
- remove unnecessary dependancy on Makefile for kgdb_stub.o
- minor whitespace cleanup


Revision tags: thorpej-mips-cache-base thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf
# 1.139 14-Sep-2001 thorpej

branches: 1.139.4;
Don't declare intrhand[] here -- that's taken care of in intr.c.


Revision tags: thorpej-devvp-base
# 1.138 30-Aug-2001 eeh

branches: 1.138.2;
Preliminary UltraSPARC III suport (not enabled yet).


# 1.137 13-Aug-2001 jdolecek

g/c _remque()/_insque(); use the C version in libkern


# 1.136 09-Aug-2001 eeh

Fix context masking lossage caused by last version.


# 1.135 08-Aug-2001 eeh

Clean up the trap code to handle the changes cause by supporting non-faulting
accesses. Also change the parameter order so trap frames are easy to find.


# 1.134 07-Aug-2001 eeh

Make sure C code always has ASI_PRIMARY_NOFAULT in the %asi register so
the compiler will be happy if it ever starts generating speculative loads.


# 1.133 05-Aug-2001 eeh

Add support for non-faulting loads and optimize MMU miss handling paths.


# 1.132 02-Aug-2001 eeh

Fix bcopy.


# 1.131 02-Aug-2001 eeh

Sync bzero w/libc version.


# 1.130 01-Aug-2001 eeh

Integrate fixes from userland memset.


# 1.129 31-Jul-2001 eeh

Code cleanup and optimization.


# 1.128 23-Jul-2001 eeh

Get rid of some debug code that really isn't all that useful any more.


# 1.127 19-Jul-2001 eeh

Do ignore unregistered interrupts instead of faulting.


# 1.126 16-Jul-2001 eeh

Make bcopy a 32-bit friendly.


# 1.125 11-Jul-2001 eeh

Fix problems booting 32-bit kernels and dispatching level-15 interrupts.


# 1.124 08-Jul-2001 eeh

branches: 1.124.2;
Code cleanup. Add block_disable to let you turn on block set/copy routines.


# 1.123 05-Jul-2001 eeh

New block bzero and bcopy.


# 1.122 04-Jul-2001 eeh

Replace old bcopy with a much faster version.


# 1.121 01-Jul-2001 martin

Disable axidently enabled debug code to make -current compile again.


# 1.120 30-Jun-2001 eeh

Use a newer version (still disabled) of block bcopy.


# 1.119 30-Jun-2001 eeh

Fixup fpu save restore, get rid of some unused copy functions, and add
a new bcopy.


# 1.118 21-Jun-2001 eeh

Allow multiple 4MB pages for both kernel text and kernel data.

Note: DEBUG checks will not allow accesses to the hole between
text and data segments, so you may need to update programs that
use libkvm before relocating the start of kernel data.


# 1.117 06-Jun-2001 mrg

extract the netbsd32, sunos, 32 bit svr4 and 64 bit svr4 sigcode out into
separate files, so that compat lkms can link with them as well.


# 1.116 30-May-2001 lukem

add missing #include "opt_kgdb.h"


Revision tags: thorpej_scsipi_beforemerge
# 1.115 25-Apr-2001 simonb

Spell occurred correctly.


Revision tags: thorpej_scsipi_nbase thorpej_scsipi_base
# 1.114 09-Apr-2001 eeh

Interrupt latency fix from sparc port. (Hm. One insn instead of 5).


# 1.113 07-Mar-2001 eeh

Fix inverted preprocessor logic. (Spotted by Charles.)


# 1.112 21-Feb-2001 eeh

branches: 1.112.2;
Add support for 64-bit SVR4 (Solaris 8) binaries.


# 1.111 10-Feb-2001 pk

Fix conditional for svr4 compat inclusion.


# 1.110 05-Feb-2001 eeh

Add signal trampoline for 64-bit svr4 emulations.


# 1.109 31-Dec-2000 eeh

Make INCR() atomic.


# 1.108 29-Dec-2000 eeh

pseg_get tells us whether it really needed that spare page after all.


# 1.107 07-Dec-2000 eeh

Fixup calculating where fpstate should be saved in the signal trampoline
code so it doesn't overwrite something important like the registers.


# 1.106 09-Nov-2000 eeh

Fix ILP32 bug in probe_get().


# 1.105 22-Oct-2000 pk

Restore revision 1.102.

I hope it sticks this time..


# 1.104 20-Oct-2000 eeh

Fix hang in 32-bit kernels caused by relocation of KERNBASE.


# 1.103 04-Oct-2000 eeh

Fix interrupt lossage problem and some cosmetic changes.


# 1.102 01-Oct-2000 pk

cpu_initialize: global registers aren't preserved across calls to
prom_printf(), so replace %g3 with %l7 (which isn't used despite
the `usage' comment).

Also, clean up white-space turds.


# 1.101 29-Sep-2000 eeh

This seems to fix the interrupt lossage of non-debug kernels.


# 1.100 28-Sep-2000 eeh

Fix INTR_SETUP() to properly distinguish kernel and user addresses.

Make microtime() return the correct time on %tick machines.

Re-enable debug stuff in dostart for now to detect kernel mapping issues.


# 1.99 25-Sep-2000 pk

Missing `#if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)'


# 1.98 17-Sep-2000 eeh

Make the improved %tick changes work with machines that use the counter-timer
for the clock.


# 1.97 12-Sep-2000 eeh

Fix new version of microtime.


# 1.96 11-Sep-2000 eeh

(Hopefully) fix clock skew on machines that us %tick for the clock (UIIi).


# 1.95 31-Aug-2000 eeh

Use casx instead of stx to change entries in the page table trees.


# 1.94 23-Aug-2000 eeh

Update the scheduler to the new locking scheme.


# 1.93 10-Aug-2000 eeh

Fix signal delivery.


# 1.92 02-Aug-2000 eeh

Get kernel profiling to work. Now if only gprof worked....


# 1.91 01-Aug-2000 eeh

Overhaul cache flush code and coredump code.


# 1.90 25-Jul-2000 pk

Re-instate a couple of delay slot NOPs marked `XXX spitfire bug?'


# 1.89 24-Jul-2000 mycroft

Optimization to pmap_zero_page(): we only need to use the first 16 FP regs,
as in bzero().


# 1.88 24-Jul-2000 mycroft

Fix a whitespace glitch.


# 1.87 24-Jul-2000 mycroft

Pull in the bzero() changes from libc for real, with a couple of kernel-
specific hacks:
* Make the bias handling depend on STKB, so it switches correctly for 32-bit
kernels.
* Use the 32-bit stw/ld for 32-bit kernels.
* Add a few `-STKB's that were missed in the previous change.


# 1.86 24-Jul-2000 pk

Cosmetic & readability:
- local label cleanup in interrupt handling code;
- in debugging sections when testing `intrdebug': use a unique
local label (97) to enhanced clarity;
- comment-out unused code;
- kill a bug as the satisfying result of doing all of the above.


# 1.85 24-Jul-2000 eeh

Fix stack issues in bzero.


# 1.84 24-Jul-2000 mycroft

Revert the previous change for now. I don't have time to debug it tonight.


# 1.83 23-Jul-2000 mycroft

Copy bzero change from libc.


# 1.82 20-Jul-2000 pk

Since `intrcnt' points to an array of long ints, reserve the appropriate
amount of space depending on _LP64. Provide macros to load/store signed
and unsigned long ints.

Also, make the `intrcnt' and `intrpending' arrays 16 entries long, as on
sparc/v9 interrupt #15 is just a regular interrupt.


# 1.81 19-Jul-2000 eeh

Fix merge problem.


# 1.80 19-Jul-2000 eeh

Disable interrupt interlock using ih->ih_pending field. Seems to cause
more problems than it solves.


# 1.79 19-Jul-2000 eeh

Miscellaneous cleanup.


# 1.78 18-Jul-2000 pk

Correct args usage comment in probeget.
Whitespace cleanup.


# 1.77 18-Jul-2000 pk

probeget: 9 -> 0x9


# 1.76 18-Jul-2000 pk

If `ih_pending' is set simply return from the trap, don't schedule another
soft interrupt.


Revision tags: mrg-merge-1-5-top
# 1.75 18-Jul-2000 pk

openfirmware: don't lower %pil


# 1.74 17-Jul-2000 pk

Kill typos in interrupt code.


# 1.73 17-Jul-2000 pk

probeget: do the same song and dance as ld*a() macros in ctlreg.h do.


# 1.72 14-Jul-2000 eeh

Move some macro definitions out of genassym and into locore.s


# 1.71 08-Jul-2000 mrg

backout part of previous: turn off intrdebug, and another debug message


# 1.70 07-Jul-2000 pk

Changes for readability:
- #define LP64 dependent STACKFRAME macro once
- use a LOAD_ASCIZ macro for setting up the format string
for debug messages.


# 1.69 07-Jul-2000 eeh

Temporary fix to prevent the clock from stopping on UIIi machines.


# 1.68 03-Jul-2000 eeh

Prevent interrupts from being posted if they are active and deprecate polled
interrupts. This seems to eliminate the spurious interrupts.


# 1.67 02-Jul-2000 eeh

Clean up interrupt handling some more.


# 1.66 30-Jun-2000 eeh

Fix interrupt delivery on UltraSPARC IIi machines.


# 1.65 24-Jun-2000 eeh

With these changes the kernel seems almost stable again.


# 1.64 24-Jun-2000 eeh

More VM cleanup:

Move the cpu_info structure above the interrupt stack so it won't
get corrupted if the stack overflows.

Flush the D$ before and after all MMU bypass accesses since the
D$ latches all of those.


# 1.63 23-Jun-2000 eeh

Make probeget() and probeset() really work for a change.


Revision tags: netbsd-1-5-base
# 1.62 19-Jun-2000 eeh

branches: 1.62.2;
Have separate data and text segments, make text read-only.


# 1.61 12-Jun-2000 eeh

Start reorganizing the kernel for MULTIPROCESSOR support.


# 1.60 31-May-2000 thorpej

Add a comment about needing to initialize p_cpu when multiple
processors are supported.


Revision tags: minoura-xpg4dl-base
# 1.59 26-May-2000 thorpej

branches: 1.59.2;
First sweep at scheduler state cleanup. Collect MI scheduler
state into global and per-CPU scheduler state:

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

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

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

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

Tested on i386 and Alpha. Changes are mostly mechanical, but apologies
in advance if it doesn't compile on a particular platform.


# 1.58 26-May-2000 thorpej

Don't set `runtime' here; it's done at the end of mi_switch().
cvS: ----------------------------------------------------------------------


# 1.57 26-May-2000 thorpej

Introduce a new process state distinct from SRUN called SONPROC
which indicates that the process is actually running on a
processor. Test against SONPROC as appropriate rather than
combinations of SRUN and curproc. Update all context switch code
to properly set SONPROC when the process becomes the current
process on the CPU.


# 1.56 22-Apr-2000 eeh

If we trap due to a bad kernel stack, try to switch to the interrupt strack
before breaking into the debugger.


# 1.55 18-Apr-2000 eeh

Prevent the system from getting watchdog reset by returning directly to user
mode if restoring the user window traps. Also reduce the time we run with
%tl>0.


# 1.54 13-Apr-2000 eeh

Apparently gas 2.9.5 (don't ask) does not like to add values to %lo()
directives so move the additions inside %lo() to make it happy.
Hopefully this won't break older versions.


# 1.53 10-Apr-2000 mrg

- fix a speeling error
- rename some numbered labels to be a bit less confusing.
- remove dead code
- fix a debug error message (argh!)


# 1.52 10-Apr-2000 pk

Get a kernel without DDB to build.


# 1.51 16-Mar-2000 eeh

Revamp interrupts again:

Fix a bug causing interrmittent panics in interrupt dispatch.
Use interrupt vectors for softints.
Add a new send_softint interface.
Improved D$ flushing.
Improve traptrace and other debugging enhancements.


Revision tags: chs-ubc2-newbase
# 1.50 16-Jan-2000 eeh

Interrupt handlers return zero if they didn't handle the interrupt.


# 1.49 10-Jan-2000 eeh

Add debugger single-stepping and fix interrupt dispatch bugs.


# 1.48 30-Dec-1999 eeh

Lots of changes:

remove ffs()
add bzero that uses block store insns
save %gsr to fpstate
revert to physical accesses for pmap_zero_page so we don't
have conflicting page mappings
general cleanup.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base fvdl-softdep-base
# 1.47 06-Nov-1999 eeh

Handle zero length properly in copyinstr() copyoutstr() and copystr().


Revision tags: comdex-fall-1999-base
# 1.46 11-Oct-1999 eeh

branches: 1.46.2; 1.46.4;
Update to post 1.4.


# 1.45 05-Oct-1999 eeh

branches: 1.45.2;
Make broken versions of gas happy by using sethi/or instead of set for
(negative) addresses.


# 1.44 17-Sep-1999 thorpej

Centralize the declaration and clearing of `cold'.


Revision tags: chs-ubc2-base
# 1.43 18-Jul-1999 eeh

More fun with pmap.


# 1.42 21-Jun-1999 eeh

Improve TRAPTRACE. Add FLTRACE that only tracks MMU faults.


# 1.41 05-Jun-1999 eeh

Make pbrobeget() and probeset() work for 64-bit values as well. To do this
the arguments are changed so the address is first and the ASI second so we
can have the address in %o0:%o1 and not worry about unused registers.

Also a bit of copyright cleanup.


# 1.40 05-Jun-1999 mrg

update a commit slightly.


# 1.39 30-May-1999 eeh

Add code to support using %tick as the system clock if no "counter-timer" node
is found.


# 1.38 09-May-1999 eeh

Fixup non-DEBUG kernels.


# 1.37 29-Apr-1999 christos

Add sunos_sigcode (32 bit only)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.36 26-Mar-1999 eeh

branches: 1.36.4;
COMPAT_SPARC32 -> COMPAT_NETBSD32


# 1.35 25-Mar-1999 mrg

clean and up make compile


# 1.34 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.33 22-Mar-1999 eeh

Need to set up the pointers properly for partial FPU register stores.


# 1.32 22-Mar-1999 eeh

Flush D$ on bypass accesses.


# 1.31 28-Feb-1999 eeh

Use block load/store in pmap_zero_page()/pmap_copy_page().


# 1.30 17-Feb-1999 eeh

Let's test out vectored interrupts.


# 1.29 15-Feb-1999 hubertf

RCS ID police


# 1.28 11-Feb-1999 mrg

fix a comment pasto.


# 1.27 11-Jan-1999 eeh

Finally fixed 64-bit signal trampoline.


# 1.26 10-Jan-1999 eeh

Handle the symbol table properly in a 32-bit kernel that was booted from a
64-bit bootloader.


# 1.25 09-Jan-1999 eeh

More signal fixup.


Revision tags: kenh-if-detach-base
# 1.24 26-Nov-1998 mycroft

Sync kcopy() with 32-bit SPARC version.


# 1.23 16-Nov-1998 eeh

Fixup the last broken bits of the signal handling code.


Revision tags: chs-ubc-base
# 1.22 08-Oct-1998 eeh

Fix more syscall32 and signal breakage.


# 1.21 22-Sep-1998 eeh

More fixup in the signal area.

64-bit syscall cleanup.

Add emulation for some new FPU insns: conversion to 64-bit long int and
conditional moves.


# 1.20 17-Sep-1998 thorpej

SYS_sigreturn -> SYS___sigreturn14.


# 1.19 13-Sep-1998 eeh

Fixup signal changes (hopefully). However SUN_COMPAT is likely broken by
this and I don't know how to fix it.

We can now exec a 64-bit init through a really ugly hack (don't ask.)


# 1.18 11-Sep-1998 eeh

Add labels for the compat_sparc32 signal trampoline and break -- er -- fix
suword and fuword.


# 1.17 09-Sep-1998 eeh

Don't use %tick for microtime on 32-bit kernels -- breaks gettimeofday.


# 1.16 09-Sep-1998 thorpej

Adjust for the new "reaper" kernel thread: do not free the vmspace and
u-area in machine-dependent code. Instead, call exit2() to schedule
the reaper to free them for us, once it is safe to do so (i.e. we are
no longer running on the dead proc's vmspace and stack).


# 1.15 07-Sep-1998 eeh

Fix data corruption problem caused by broken debug code.


# 1.14 07-Sep-1998 eeh

Add new 64-bit trap vectors.


# 1.13 06-Sep-1998 eeh

32-bit fixup.


# 1.12 06-Sep-1998 eeh

Disable some debug stuff.


# 1.11 05-Sep-1998 eeh

It slices. It dices. It does everything except exec a sparc32_compat init.


# 1.10 02-Sep-1998 eeh

Periodic update: now starts probing devices.


# 1.9 30-Aug-1998 eeh

Some more 64-bit cleanup. Now everything compiles.


# 1.8 29-Aug-1998 eeh

Some more 64-bit-ification.


# 1.7 27-Aug-1998 eeh

Add 64-bit pmap support:

Moved from a two level 512/1024 entry setup mapping 32 (9/10/13) bits
respectively to a three level 1024/1024/1024 entry setup mapping 43
(10/10/10/13) bits. In 32-bit mode we waste about 1/12 pages mapping the high
11 bits. We also only manage 43 of the possible 44 bits of virtual address
space, wasting half of it. Oh well, maybe we'll do better next revision.


Revision tags: PMAP32
# 1.6 26-Aug-1998 mrg

panicstack: is needed outside of DEBUG. use _C_LABEL, and printf not db_printf (incase no ddb!)


# 1.5 13-Aug-1998 eeh

Merge paddr_t changes into the main branch.


Revision tags: eeh-paddr_t-base
# 1.4 07-Jul-1998 eeh

branches: 1.4.2;
General update:

Added genassym.cf
Removed lderr which should never have gotten in
Removed lots of dead code from locore.s
Added some softint stuff to intr.c
Added support for halt -p
esp and le both use bus_dmamap_*() functions now
instead of kdvma_mapin()
groundwork for PCI (but we still have no drivers for
any sun4u PCI devices)


# 1.3 04-Jul-1998 jonathan

defopt DDB.


# 1.2 26-Jun-1998 thorpej

defopt COMPAT_SVR4


# 1.1 20-Jun-1998 eeh

branches: 1.1.1;
Initial revision


# 1.407 30-Jan-2017 palle

sun4v: Hook up syscall handling to the trap table. Verified using qemu for both sun4u and sun4v.


# 1.406 27-Jan-2017 palle

sun4v: implement missing handling of itsb traps 0x008 and 0x009. Based on code from OpenBSD. Tested using qemu.


Revision tags: bouyer-socketcan-base
# 1.405 07-Jan-2017 palle

sun4v: slowtrap() now selects normal globals properly on both sun4u and sun4v platforms. Verified using qemu for both sun4u and sun4v systems


Revision tags: pgoyette-localcount-20170107
# 1.404 05-Jan-2017 palle

sun4v: TRAP_SETUP() updated to set mmu context id properly for both sun4v and sun4u platforms. Verified using qemu for both sun4u and sun4v systems


# 1.403 04-Jan-2017 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x00-0x23 and 0x28-0x30


# 1.402 29-Dec-2016 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x32-0x7f


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.401 20-Sep-2016 nakayama

Fix RAS for 32-bit kernels. trapframe is always 64-bit.


Revision tags: localcount-20160914
# 1.400 23-Aug-2016 palle

sun4v: rework sun4v_datatrap so it works properly when running on a T2-based system like T5120 - for some reason %tl is 0 when entering sun4v_datatrap causing a crash (sir instruction), so ignore the %tl value for now upon entry to sun4v_datatrap - with this fix both T1 and T2 based systems reach the same point - hangs in rft_user after the init process is started


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726
# 1.399 18-Jul-2016 palle

sun4v: handle device interrupts properly - both legacy (sysino) and cookies


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 1.398 04-Jun-2016 palle

branches: 1.398.2;
sun4v: rtf_user now uses macros GET_MMU_CONTEXTID and SET_MMU_CONTEXTID. Tested on sun4u (QEMU) and sun4v (T2000). Parts from OpenBSD.


Revision tags: nick-nhusb-base-20160529
# 1.397 18-May-2016 nakayama

Decrement %tl in trap handler not to make it zero unconditionally
for the nested trap, and remove useless mov.


# 1.396 17-May-2016 palle

sun4v: Implement missng MMU protection trap handling - mostly from OpenBSD


# 1.395 16-May-2016 palle

Avoid assembler-specific defines by using the export keyword in genassym.cf instead


# 1.394 15-May-2016 nakayama

%g1 is not preserved across function call, so load it before
return_from_trap.


# 1.393 13-May-2016 palle

sun4v: add missing implementation of sun4v_datatrap_tl0 so data_access_fault() is called - mostly from OpenBSD


# 1.392 13-May-2016 nakayama

- ci_paddr is always 64-bit.
- intrlev is array of pointer.
- ih_ack is pointer.


# 1.391 10-May-2016 palle

sun4v: make device interrupts work. Introduce a new intrhand_alloc() function for allocation of interrupt handlers and adapt to this. Parts from OpenBSD. ok martin@


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.390 09-Mar-2016 nakayama

32-bit kernels use 32-bit stack.


# 1.389 03-Mar-2016 palle

sun4v: rft_kernel should pay attention to the number of register windows that can be restored. We cannot rely on fill traps to occur, since sun4v only has two trap levels available in privileged mode. Based on code from OpenBSD. ok martin@


# 1.388 14-Feb-2016 palle

sun4v: add breakpoint trap entry to the sun4v trap table


# 1.387 03-Feb-2016 palle

sun4v: extend dmmu_set_secondary_context() to handle both sun4u and sun4v. ok martin@


Revision tags: nick-nhusb-base-20151226
# 1.386 06-Nov-2015 martin

Basically revert r1.246 of locore.s and r1.73 of vm_machdep.c:

Remove special case handling for userland lwps from cpu_lwp_fork,
instead do it in lwp_trampoline when we first return to userland.

which was a stupid idea - since we did now set all fork child's %tstate
(and thus %pstate when back in userland) to the current kernel's userland
default. This meant we lost the address mask bit for 32bit processes and
all memory model details for 64bit ones.

Move it back to cpu_lwp_fork and fix the condition to only do it once when
forking init.


# 1.385 05-Nov-2015 martin

Most of the time return_from_trap already got called with tf->tf_tstate
loaded in register %g1 - make it so for two more callers and remove
the reload of that value.


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606 nick-nhusb-base-20150406
# 1.384 05-Apr-2015 palle

sun4v: Ensure that the TTEs CP and CV bits are the same (both set) for the primary cpu and secondary cpus INTSTACK mappings


# 1.383 01-Apr-2015 palle

sun4v: Implement handling of cpu_mondo trap - from OpenBSD - tested using the Legion simulator


# 1.382 04-Mar-2015 palle

sun4v: revert some of the logic introduced in revision 1.378 - flushw is not necessary on sun4v (OpenBSD patches the flushw instruction to a nop instruction) - with these changes the kernel reaches cpu_boot_secondary_processors() when running in the Legion simulator (crashes due to missing handling of cpu_mondo_trap)


# 1.381 02-Mar-2015 nakayama

prom_printf converts "\n" to "\r\n" internally, so omit "\r".


# 1.380 02-Mar-2015 nakayama

PANICSTACK is a pointer itself, not a pointer to pointer.


# 1.379 02-Mar-2015 nakayama

Use panic stack temporarily for calling prom_printf in a trap
handler.

It seems that openfirmware cannot handle over 4GB pointers, and
stack pointers may point to over 4GB since VA layout was rearranged
by rev 1.33 of vmparam.h. Therefore, use panic stack to avoid
panicking in OF_write used by prom_printf.


# 1.378 23-Feb-2015 palle

sun4v: sparc_interupt - ensure that the trap level and globals level are the same when the flushw instruction is issued - othwise warnings occur when using the sun4v Legion simulator.


Revision tags: nick-nhusb-base
# 1.377 26-Oct-2014 palle

branches: 1.377.2;
sun4v: Create CLEANWIN0 and CLEANWIN1 macros for handling clean window traps on both sun4u and sun4u (based on the original code inlined in the sun4u trap table). Update trap tables accordingly for both sun4u and sun4v. Ok martin@


# 1.376 24-Oct-2014 nakayama

Fix typo in comment.


# 1.375 18-Oct-2014 snj

src is too big these days to tolerate superfluous apostrophes. It's
"its", people!


# 1.374 15-Oct-2014 palle

sun4v: fixed bug causing the real address to be incorrectly calculated as zero


# 1.373 24-Sep-2014 palle

sun4v: add code to enable startup of secondary cpus on both sun4u and sun4v systems - ok martin@


# 1.372 04-Sep-2014 palle

sun4v: All cpus must be setup with a TSB descriptor, so pmap_setup_tsb_sun4v() must take a pointer to the TSB descriptor


# 1.371 31-Aug-2014 palle

sun4v: Split the NORMAL_GLOBALS and ALTERNATE_GLOBALS macros to _SUN4U and _SUN4V variants. Rework the return_from_trap logic to use the new variants so it is possible to use a global register as scratch register.


# 1.370 14-Aug-2014 nakayama

Add missing delay slot in DEBUG kernel.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.369 30-Jul-2014 palle

branches: 1.369.2;
Fix ALTERNATE_GLOBALS so it at least works on sun4u - using a scratch register is not a good idea...


# 1.368 27-Jul-2014 palle

sun4v: Introduce a new macro ALTERNATE_GLOBALS (matching NORMAL_GLOBALS). Two new helper macros ENABLE_INTERRUPTS and DISABLE_INTERRUPTS are also created. With these changes the GENERIC.UP kernel will reach rootmount on sun4v systems - ok martin@


# 1.367 26-Jul-2014 palle

Improved the NORMAL_GLOBALS macro in the sun4u case, so only the relevant bit (AG) in %pstate is affected - ok martin@


# 1.366 24-Jul-2014 palle

sun4v: add missing spill/fill handling for trap level 1 + cosmetic changes to comments for trap level 0 entries


# 1.365 19-Jul-2014 palle

sun4v: Introduce a NORMAL_GLOBALS macro - first used in sparc_interrupt - other relevant uses will be handled as the sun4v work is progressesing - ok martin@


# 1.364 16-Jul-2014 palle

sun4v: Introduce SET_MMU_CONTEXTID macro for setting the mmu context id on both sun4u and sun4v


# 1.363 13-Jul-2014 palle

sun4v: add interrupt handling to sun4v trap table


# 1.362 13-Jul-2014 palle

Bugfix: add missing cmp instruction to GET_MAXCWP macro


# 1.361 30-Jun-2014 palle

sun4v: The maximum number of register windows is a constant and thus not available via the %ver register (sun4u only). Introduce a macro GET_MAXCWP that handles this, so cpu_switchto() works properly on sun4v. Other relevant reference to %ver can be adapted to use GET_MAXCWP as the sun4v port progresses. OK martin@


# 1.360 31-May-2014 palle

sun4v: added missing dtsb miss handling for trap level 1 - with this update the kernel now reaches configure() on sun4v systems


# 1.359 30-May-2014 palle

Remove debugging code introduced by accident in locore.s revision 1.357


Revision tags: yamt-pagecache-base9 rmind-smpnet-nbase rmind-smpnet-base
# 1.358 05-May-2014 palle

sun4v: the trap base address should be assigned to %l1 so %tba is properly setup later in the code - now the kernel gets as far as printing the copyright disclaimer, kernel version and total and available memory before crashing


# 1.357 21-Apr-2014 palle

sun4v: Update comment: modified -> access


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.356 21-Feb-2014 palle

branches: 1.356.2;
sun4v: Rename TLB_ defines to SUN4U_TLB_ so entries created using TSB_DATA() are properly setup for sun4u and sun4v. Relocate the cputyp variable from autoconf.c to locore.s and make it const in param.h so optimized code can be generated. Parts from OpenBSD. Optimization suggested by nakayama@. OK martin@, mrg@, nakayama@


# 1.355 31-Jan-2014 tsutsui

defined(LKM) -> defined(MODULAR)


# 1.354 26-Jan-2014 palle

sun4v: Add handling of spill/fill and dtsb miss traps (with a XXX to be handled later)


# 1.353 07-Jan-2014 palle

sun4v: trap table setup - currently populated with dummy entries which will be properly implemented later - parts from OpenBSD - OK martin@


# 1.352 29-Dec-2013 nakayama

Make buildable w/o options SUN4V.


# 1.351 27-Dec-2013 palle

a) make the hunt through the cpus list more generic b) sun4v: ensure that the interrupt stack is mapped permanently and the TSB is setup properly - parts from OpenBSD. OK martin@


# 1.350 06-Dec-2013 nakayama

Increase an interrupt depth only in the case of hardware interrupts,
and remove the ci_idepth trick in softint_fastintr.

Fixes the following diagnostic panic reported in port-sparc64.

panic: kernel diagnostic assertion "!cpu_intr_p()" failed: file
"../../../../kern/subr_xcall.c", line 351


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 1.349 24-May-2013 nakayama

branches: 1.349.2;
Disable interrupts after calling data_access_error as with
data_access_fault.


# 1.348 28-Apr-2013 nakayama

Use macros in machine/asm.h instead of locally defined, and
introduce CASPTRA for casxa/casa.


Revision tags: agc-symver-base
# 1.347 23-Jan-2013 martin

Fix sparc64_ipi_ccall by adding proper trap setup.
Fixes xcall(9) problems, as exposed by pserialize(9). Noticed by
J. Hannken-Illjes, cause pointed out by Takeshi Nakayama.


# 1.346 23-Jan-2013 martin

Sligthly clean up the (by default unused) #ifdef TRAPS_USE_IG


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.345 10-Nov-2012 nakayama

Revise comment.


# 1.344 10-Nov-2012 nakayama

Use macro instead of magic number.


# 1.343 09-Nov-2012 nakayama

Make setstick() and getstick() to inline functions.


# 1.342 08-Nov-2012 macallan

use system tick timer instead of %tick on UltraSPARC-III-ish CPUs
review & fixes by Takeshi Nakayama


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.341 17-Mar-2012 mrg

branches: 1.341.2;
port the corrected ECC error handling code from freebsd. i noticed my U10
took one of these and then hang. it shouldn't hang, there's a 'sir' here that
doesn't seem to reset properly. oh well.

tested by simulated a trap via 'ta 0x10' and considering that the same, but
it hasn't been tested against a real ECC error yet.


Revision tags: jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base4
# 1.340 03-Mar-2012 nakayama

Fix the root cause of the hack "disable optimizations for uvm_bio.c
on 32 bit kernels".

gcc converts a division in the calculation of UBC_UMAP_ADDR macro
to multiplication (smul or combination of add/sll), and the
register of its result contains a garbage in upper 32 bits (the
upper 32 bits of smul/add/sll's result isn't zero cleared).

Then it passes to pseg_get{,_real} through pmap_extract without the
zero clear of upper 32 bits in the optimization case. So the
result of pseg_get and pmap_extact sometimes gets screwed up.


Revision tags: jmcneill-usbmp-base5 jmcneill-usbmp-base3
# 1.339 19-Feb-2012 rmind

Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.


Revision tags: jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.338 04-Sep-2011 nakayama

branches: 1.338.2; 1.338.6; 1.338.8;
ih_pil is an interrupt level, not an interrupt mask.


# 1.337 27-Jul-2011 nakayama

ivec is assigned to hardware, so count its event counter up in
interrupt_vector, not in softint, and do some optimization.


# 1.336 20-Jul-2011 macallan

add per ivec event counters


# 1.335 12-Jul-2011 mrg

rename sparc64 BLOCK_SIZE and BLOCK_ALIGN to have SPARC64_ prefixes.
for the assembler files, define the old names to the new names
since using the new names cause ugliness due to longer identifer
names, and reduces churn.

fixes build issues in dtv and vaguely makes <machine/psl.h> slightly
less name-space invasive.


# 1.334 18-Jun-2011 nakayama

Add fast softint(9) support for sparc64.

Reviewed on port-sparc64.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 1.333 12-May-2011 mrg

branches: 1.333.2;
first steps towards fujitsu SPARC64 support:

- SPARC64 systems have interrupts with upto 14 bits set, but we only look
at the first 11 bits. trim non IPI interrupts to 11 bits


Revision tags: uebayasi-xip-base7 bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 jym-xensuspend-nbase jym-xensuspend-base
# 1.332 20-Dec-2010 matt

branches: 1.332.2;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.


Revision tags: uebayasi-xip-base6 uebayasi-xip-base5 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 1.331 10-Jul-2010 nakayama

Clear the upper word explicitly before combining two 32-bit values to 64-bit
on 32-bit kernels.


# 1.330 23-May-2010 martin

Split copy related functions out of locore.s into copy.S, move functions
only needed on multiprocessors into mp_subr.S.


# 1.329 17-May-2010 martin

Simplify primary CPU startup slightly by using the fact that our cpuinfo's
curpcb pointer points to the uarea/pcb of lwp0 and by remembering the pointer
to this cpuinfo, thus avoiding a few CPUINFO_VA references.


Revision tags: uebayasi-xip-base1
# 1.328 20-Mar-2010 chs

fix copy{in,out}{,str}() to return the error returned by uvm_fault().
fixes PR 41813.


Revision tags: yamt-nfs-mp-base9
# 1.327 10-Mar-2010 mrg

branches: 1.327.2;
XXX: workaround we'd like to remove when pmap / uvm locking is cleaned up:

- rename pseg_get() and pseg_set() to pseg_get_real() and pseg_set_real().
- if USE_LOCKSAFE_PSEG_GETSET is defined, which it current is by default,
define pseg_[gs]et() in terms of functions that take a new pseg_lock
mutex at IPL_VM while calling into the real functions.

this seems to avoid the pseg_set() crashes we've seen:
1 - spare needed, when pseg_get() just worked for this pmap
2 - the 2rd ldxa via ASI_PHYS_CACHED in pseg_set() loads garbage
into %o4, and causes the 3rd ldxa to fault


# 1.326 08-Mar-2010 mrg

blast_dcache() SMP friendly:

- blast_dcache() becomes sp_blast_dcache(dcache_size, dcache_line_size)
- new smp_blast_dcache(sparc64_cpuset_t) that blasts the D$ on this cpuset
- sparc64_ipi_blast_dcache() to support the above
- in pmap_remove_all(), when freeing mmu contexts for this pmap, mark
the set of cpus to blast the d$ on as well and convert the
blast_dcache() call into smp_blast_dcache() on the cpus who ran this
pmap, or, sp_blast_dcache(dcache_size, dcache_line_size)
- convert the remaining blast_dcache() in machdep.c to sp_blast_dcache()
- in pmap_destroy()/pmap_remove_all() take the pmap_lock() always since
we assert it is held always.

with these changes, NFS builds on the U60 seem to be stable now, and
the USIII machines also can often complete a single build.sh run now,
diskful or diskless.


reviewed by mlelstv and partially by martin, tested by martin and myself,
with some ideas from chuq as well.


# 1.325 07-Mar-2010 mrg

need _ALIGN in locore.h as well, for DEBUG kernels.


# 1.324 07-Mar-2010 mrg

gas has supported SPARC ".empty" for a long while; get rid of an
ancient workaround.


# 1.323 06-Mar-2010 mrg

move the memcpy/memset implementations out into their own file, with the
block copy versions as well. move some of the definitions in locore.s
into a new locore.h.

locore.s is almost 2000 lines shorter with this change.


# 1.322 04-Mar-2010 mrg

- in _bus_dmamap_unload(), pmap_page_protect() and pmap_clear_reference()
switch the dcache_flush_page() into a dcache_flush_page_all()
- in both pmap_kremove()/pmap_remove(), remove the blast_dcache() call
and replace it with dcache_flush_page_all()
- in pmap_get_page() [used to allocate PTP's], always call pmap_zero_page(pa)
- flush the dcache of the dst page in pmap_{copy,zero}_page() by redirecting
throught a C function that calls the (renamed) asm. the old asm code had a
comment about needing to do this...
- add a couple of membar #Sync's that the USIII manual recommends


based on discussions with chuq@, skrll@ and martin@.


these help my SB2000 / SB2500 with both disk / nfs builds and other tasks,
sometimes lasting for several hours before failing or asserting.


# 1.321 24-Feb-2010 mrg

when handing back page table pages to UVM, flush them from the dcache
on all CPUs.

idea from skrll@, and makes my disk-based SB2000 stable.

tested on U60, SB2000 and SB2500.


# 1.320 24-Feb-2010 mrg

- re-introduce sp_tlb_flush_pte() and sp_tlb_flush_all() that call
the right USI/USIII version.
- define tlb_flush_pte() in terms of sp_tlb_flush_pte() for the
!MULTIPROCESSOR case

this centralises some CPU_IS_USIII_UP() tests.


# 1.319 22-Feb-2010 mrg

move {dump,print}_[id]tlb() into a separate file.


# 1.318 22-Feb-2010 mrg

- store the maximum [id]cache size / line size for each cpu

- remove patch_kernel() since it isn't necessary and has been patching
the wrong thing in general.

- implement USIII versions of blast_icache(), dcache_flush_page() and
cache_flush_phys(). use the newly recorded cache size/line sizes.

- in winfixsave, flush the D$ with the right size index and ops. this
kills one of the wrong tag->inval patches.

- for blast_dcache(), use the newly recorded dcache_size/line_size.

- for blast_icache(), use the newly recorded cache size/line sizes.
for the USIII verison, disable the I$ while writing to ASI_ICACHE_TAG.


these changes removed several hard coded cache sizes values, some very
wrong kernel patching, and seem to make the current failure modes for
USIII less common, but not gone.


# 1.317 15-Feb-2010 mrg

- don't flush 32-bit entries for 64-bit code, it does not seem to be
necessary. #define TLB_FLUSH_LOWVA to turn it back on.
- remove the #if 0'd code in sparc64_ipi_flush_pte_usiii(), i have
verified that it is not required.
- add a missing membar #Sync to sp_tlb_flush_pte_usiii().


# 1.316 15-Feb-2010 nakayama

Fix linker error of GENERIC32 kernel.


# 1.315 15-Feb-2010 mrg

use TLB_SIZE_SPITFIRE in a couple of places, and note that the
{print,dump}_[id]tlb() versions are currently spitfire specific.


# 1.314 15-Feb-2010 mrg

introduce a new patch_kernel() and call it from the end of bootstrap().
use it to patch up TLB flush instructions that don't match for USI/II
and later. we can also hopefully use this to make GENERIC.MP minimally
expensive on single CPU machines as well.

this is the last piece needed to get GENERIC/GENERIC.MP to boot on the
USIII* machines.

idea and some initial code from openbsd.


# 1.313 13-Feb-2010 mrg

remove KTR support. it's never been a working part of netbsd src tree.


# 1.312 09-Feb-2010 wiz

Fix typo in comment.


Revision tags: uebayasi-xip-base
# 1.311 06-Feb-2010 mrg

branches: 1.311.2;
- properly map the schizo interrupt registers, so we can use the normal
virtual mappings to access them.
- with the above fxied, kill SCHIZO_BUS_SPACE_BROKEN, and introduce
an options CHEETAH for now, that disables the SPITFIRE code in locore.
- merge schizo_init() into schizo_attach() and clean up the softc a bit.


with this we are only one more step away from GENERIC booting on USIII
machines.


# 1.310 02-Feb-2010 mrg

- split sp_tlb_flush_pte() and switchtoctx() into sp_tlb_flush_pte_us()/
sp_tlb_flush_pte_usiii() and switchtoctx_us()/switchtoctx_usiii() and
implement the latter while i'm here. it works ... sometimes i think,
but also sometimes panics/hangs.
- fix a comment in sparc64_ipi_flush_pte_usiii()


# 1.309 02-Feb-2010 mrg

for now, reduce a few #ifdef SPITFIRE cases by introducing a new
ASI_DCACHE_TAG_OR_INV that is either ASI_DCACHE_{TAG,_INVALIDATE}.

increase the common code in cache_flush_phys().


# 1.308 01-Feb-2010 mrg

- sp_tlb_flush_all() becomes sp_tlb_flush_all_us() and sp_tlb_flush_all_usiii()
- sparc64_ipi_flush_pte() becomes sparc64_ipi_flush_pte_us() and
sparc64_ipi_flush_pte_usiii()
- add some commented out code to disable interrupts and raise the traplevel
in sparc64_ipi_flush_pte_usiii()
- cache_flush_phys() was missing a little of code in the cheetah case


# 1.307 01-Feb-2010 mrg

for USIII, use the new "tlb demap all" operation in sp_tlb_flush_all()


# 1.306 01-Feb-2010 mrg

remove unused icache_flush_page() implementation.


# 1.305 23-Jan-2010 mrg

remove the final uses of DATA_START.

now we can remove the 16KB space reserved at the start of the data segment,
and i now understand why i wrote this now removed comment 3.5 years ago:
"this shouldn't be needed... but kernel usually hangs without it"


# 1.304 23-Jan-2010 mrg

remove most of the code that writes debugging info DATA_START + offset.


# 1.303 23-Jan-2010 mrg

remove CHKPT() macro and uses. it's likely wrong in SMP land and probably should
be replaced with KTR-style uses if necessary.


# 1.302 23-Jan-2010 mrg

fix a comment.


Revision tags: matt-premerge-20091211
# 1.301 10-Dec-2009 rmind

Rename L_ADDR to L_PCB and amend some comments accordingly.


# 1.300 05-Dec-2009 mrg

- adjust the PA mask to the 43 bits supported by USIII.
- rework the spitfire/cheetah cache_flush_phys() to avoid several #ifdefs
- add a membar #Sync after sparc64_ipi_drop_fpstate (probably unnecessary)


# 1.299 30-Nov-2009 nakayama

sp_tlb_flush_pte for cheetah:
- restore interrupts properly in case of %tl > 0.


# 1.298 30-Nov-2009 mrg

stablize UP USIII support by blocking interrupts around sp_tlb_flush_pte()
i was seeing stack corruption while taking an interrupt in this function.

get USIII SMP mostly working by implementing the cheetah version of
sparc64_ipi_flush_pte().


SMP support is still not entirely stable. i can reproducably get a:

panic: fpusave_lwp ipi didn't

while running build.sh, when an awk process is exiting. other simple
heavy work loads do not crash for me right now.


# 1.297 30-Nov-2009 mrg

delete some no longer used code:
- smp_tlb_flush_ctx()
- smp_tlb_flush_all()
- sparc64_ipi_flush_ctx()
- sparc64_ipi_flush_all()
- sp_tlb_flush_ctx()


# 1.296 29-Nov-2009 nakayama

- calculate end PA correctly.
- wrap more spitfire specific (flushing I$) code.
- fix inverted #if condition for flushing I$ (and restore ASI_ICACHE_TAG).


# 1.295 28-Nov-2009 mrg

implement enough code to get SB2000/SB2500 booting to multiuser. does
not last long if you use it, but an idle machine has stayed up 10 hours.

- for the !SPITFIRE case, use ASI_DCACHE_INVALIDATE instead of
ASI_DCACHE_TAG when clearing tlb entries. from openbsd.

- convert some comment "! Not yet" into "WRITEME", so that attempting
to build a USIII MULTIPROCESSOR kernel fails to build until the code
is written.

- add some more WRITEME's for the above.

- implement a !SPITFIRE version of sp_tlb_flush_all(). since there are
no spare regs, for now just always increase %tl around this call. (we
could maybe store a token in %o3 along with the saved %pstate info.)


# 1.294 26-Nov-2009 matt

Kill proc0paddr. Use lwp0.l_addr instead.


# 1.293 25-Nov-2009 mrg

s/L_ADDR/L_PCB/, requested by rmind.


# 1.292 17-Oct-2009 nakayama

Wrap unused code with #if 0 which is called from #if 0'ed code.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5
# 1.291 30-May-2009 martin

cpu_setfunc() can not use lwp_trampoline, as that has additional lwp startup
semantics. Use a simpler setfunc_trampoline instead.


# 1.290 18-May-2009 nakayama

Remove random() from locore.s since it is in libkern.


# 1.289 16-May-2009 nakayama

Remove clear %tick in locore.s since it is cleared at cpu_initclocks() in
clock.c.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 nick-hppapmap-base mjf-devfs2-base
# 1.288 15-Dec-2008 mrg

restore some old "intrdebug" code, but leave it under NOT_DEBUG. most
of it works, but one that prints func/arg for each handler is not very
stable...

for now, while schizo bus space pointer accesses aren't working, add
a SCHIZO_BUS_SPACE_BROKEN option so you can build a kernel with schizo.

with this, and the prior schizo interrupt fix, you can now fail to run
/sbin/init!


Revision tags: haad-dm-base2 haad-nbase2 haad-dm-base
# 1.287 09-Dec-2008 martin

Get rid of get_maxctx() - it doesn't work on newer cpus and we will have
to find a better way for (some) sun4v machines - all sun4u use 13 bit
contexts anyway.


Revision tags: netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 ad-audiomp2-base netbsd-5-base
# 1.286 30-Oct-2008 nakayama

branches: 1.286.2; 1.286.6;
Wrap more code specific to USE_BLOCK_STORE_LOAD.


Revision tags: matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4
# 1.285 05-Oct-2008 nakayama

branches: 1.285.2;
- in flushing cache, use 32 as increment/decrement value to match the
cache line size.
- remove useless restore of %asi.
- remove nop in delay slot if we can.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 1.284 10-Jul-2008 nakayama

Use proper CCR.


# 1.283 10-Jul-2008 nakayama

sparc64_ipi_save_fpstate:
- use primary MMU context for consistency with other trap/interrupt handlers.

sparc64_ipi_save_fpstate, savefpstate:
- avoid storing fp registers as we can.

sparc64_ipi_save_fpstate, savefpstate, loadfpstate:
- remove unaligned case since buffers allocated with pool_cache are ensured
64-byte aligned.

Ok by martin@.


# 1.282 02-Jul-2008 nakayama

branches: 1.282.2;
UltraSPARCs don't have floating point queue, and reading %fq regsiter
will cause illegal instruction trap. So remove the code handling them.


# 1.281 29-Jun-2008 nakayama

Wrap IPI calls with #ifdef MULTIPROCESSOR.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.280 14-Jun-2008 nakayama

Close unterminated comment.
Fix unexpected behavior in case of loadfpstate from unaligned buffer.


Revision tags: yamt-pf42-base3
# 1.279 31-May-2008 nakayama

branches: 1.279.2;
openfirmware_exit:
- disable interrupts with %pstate.
- prepare 64-bit stack and enable 64-bit addresses for 32-bit SMP kernels.


Revision tags: hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 yamt-nfs-mp-base yamt-pf42-base
# 1.278 16-Apr-2008 nakayama

branches: 1.278.2; 1.278.4; 1.278.6;
Disable TRAPSTATS which was accidentally enabled when yamt-idlelwp branch
was merged.

Ok by martin@.


# 1.277 14-Apr-2008 nakayama

Remove sparc64_ipi_sync_tick.

Since we can use counter-timer as timecounter instead of %tick on SMP kernel,
it is not necessary to sync all CPUs %tick registers.


# 1.276 14-Apr-2008 nakayama

Add workaround for BB_ERRATA_1 on writing to TICK_CMPR register in
next_tick(). If writing to TICK_CMPR fails, we lose hardclock interrupt
on secondary CPUs.

About BB_ERRATA_1 from comment in OpenSolaris:

/*
* Writes to the TICK_COMPARE register sometimes fail on blackbird modules.
* The failure occurs only when the following instruction decodes to wr or
* wrpr. The workaround is to immediately follow writes to TICK_COMPARE
* with a read, thus stalling the pipe and keeping following instructions
* from causing data corruption. Aligning to a quadword will ensure these
* two instructions are not split due to i$ misses.
*/


# 1.275 28-Mar-2008 nakayama

Don't read fplwp content in delay slot for considering the case fplwp was
modifiled.

Reported by Chris Ross on port-sparc64.


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.274 20-Mar-2008 nakayama

- remove disabling interrupt in IPI.
- unused VA bits in MMU demap is 13 bits, not 12 bits.


# 1.273 18-Mar-2008 nakayama

Fix a race when increment an interrupt level event counter.


# 1.272 17-Mar-2008 nakayama

Fix a race condition in IPI handlers of save/drop fpstate, from OpenBSD.
Reported and tested by martin@.


# 1.271 17-Mar-2008 nakayama

Make schedintr interrupt handler per-CPU.
While there rename tickintr interrupt handler and share initialization
code with schedintr.


# 1.270 14-Mar-2008 nakayama

Improve IPI handling:
- make IPI takes two arguments.
- add IPI event counters per-CPU.
- implement IPI functions which were missing or broken.
- insert DELAY while halting primary CPU in IPI handler.


# 1.269 02-Mar-2008 nakayama

- make interrupt pending list per-CPU.
- make tickintr() MP-safe.
- remove unused port-sparc derived interrupt code.

Ok by martin@.


# 1.268 02-Mar-2008 nakayama

Don't get IPI handler argument (from bogus address), and ack IRQ twice.


# 1.267 28-Feb-2008 martin

Make TSBs and MMU contexts per-cpu.


Revision tags: nick-net80211-sync-base mjf-devfs-base hpcarm-cleanup-base
# 1.266 26-Jan-2008 nakayama

branches: 1.266.2; 1.266.6;
Fix for 32-bit kernels.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.265 15-Jan-2008 skrll

Store a sensbile PCB_PC value in snapshot - the return point.

This helps gdb somewhat.

OK'd by martin.


# 1.264 14-Jan-2008 martin

Fix register name typo/copy&pasto - %g6 is not %o6/%sp.
From OpenBSD.


Revision tags: matt-armv6-base
# 1.263 06-Jan-2008 martin

Load the next cpu_info pointer with LDPTR instead of ld.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2
# 1.262 09-Dec-2007 martin

branches: 1.262.2;
Provide cpu_intr_p(), at least for non-MULTIPROCESSOR kernels.
Based on suggestions by Andrew Doran.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.261 22-Oct-2007 martin

branches: 1.261.2; 1.261.4; 1.261.6;
Remove an unused .globl declaration


Revision tags: yamt-x86pmap-base4
# 1.260 17-Oct-2007 garbled

Merge the ppcoea-renovation branch to HEAD.

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

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

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base ppcoea-renovation-base vmlocking-base
# 1.259 09-Sep-2007 martin

branches: 1.259.4;
Make cpufrequency and friends per cpu values.
Prepare a hz tick interrupt on secondary CPUs via %tick, but do not
enable it yet, as it breaks ddb.


# 1.258 09-Sep-2007 martin

Do not ACK IPIs before we finished loading all arguments.


# 1.257 06-Sep-2007 martin

Remove the (now unused) second 64k page mapped per CPU.
From matthew green, with small changes by me. All bugs are mine.


# 1.256 25-Aug-2007 martin

branches: 1.256.2;
Remove INITSTACK completely - at the time we used to switch to it, we
already have access to all of lwp0 and it's uarea - so we can switch
to the correct lwp0 stack easily before calling main.


# 1.255 25-Aug-2007 martin

When exiting to OF, use the interrupt stack instead of INITSTACK


# 1.254 25-Aug-2007 martin

Rework cpu_mp_startup slightly:
- temporarily use the cpu's interrupt stack untill we are ready
to access non-OF-based mappings, then directly switch to the cpu's
idlelwp's uarea stack
- disable interrupts untill we are ready to call C code


# 1.253 13-Aug-2007 macallan

remove two restore without matching save


Revision tags: nick-csl-alignment-base matt-mips64-base mjf-ufs-trans-base
# 1.252 06-Jul-2007 martin

branches: 1.252.4; 1.252.8;
A few nits for 32bit SMP kernels, noticed by mrg.
While there, simplify the fpstate IPIs a bit.


# 1.251 05-Jul-2007 martin

sparc64_ipi_save_fpstate is not a leaf function - create a full grown
stack frame.


# 1.250 28-May-2007 mrg

clean up cpu_switchto() a little - no need to flushw or membar
excessively. optimise an rdpr. tested by tnn.


# 1.249 23-May-2007 martin

Fix a stupid bug in the save_fpstate ipi, which caused overwriting of
struct lwp of the lwp owning the fpu. Fix clearing the fplwp - %o0 will
not survive the call to savefpstate - duh!


# 1.248 20-May-2007 martin

Simplify tf_tstate setting when leaving for userland initially - I seem
to have confused the if with the else case of the previous C code.
Funny that it worked at all.


# 1.247 20-May-2007 martin

cpu_switchto() has to return it's first arg, always. This differs from
my reading of the documentation, but helps in the real world and seems
to be what other ports do.


# 1.246 20-May-2007 martin

Remove special case handling for userland lwps from cpu_lwp_fork, instead
do it in lwp_trampoline when we first return to userland.


# 1.245 19-May-2007 martin

cpu_idle is a leaf function, so we better "return from leaf".
Use return value from cpu_switchto for previous lwp in lwp_trampoline.
Also shamelessly steal a comment from uwe written for sparc that explains
all this.
Thanks to tnn, mrg, and uwe for helping to debug this.


# 1.244 17-May-2007 yamt

merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base ad-audiomp-base
# 1.243 22-Feb-2007 martin

branches: 1.243.4; 1.243.6; 1.243.12;
uvm.page_idle_zero now is a bool, not a 32bit value any more.


# 1.242 21-Feb-2007 mrg

shave 9 insns off the tsb setup in cpu_initialize & cpu_mp_startup.


# 1.241 21-Feb-2007 martin

Get rid of unused (thus always zero) "curlwp" variable hidden in assembler
code (C code always uses a cpuinfo based macro).


# 1.240 18-Feb-2007 martin

Make use of another call delay slot, pointed out by uwe.


# 1.239 18-Feb-2007 martin

Make use of a call delay slot and avoid a bogus EMPTY.
Spotted by Juergen Hannken-Illjes, with input from Andrew Doran and
Valeriy E. Ushakov.


# 1.238 18-Feb-2007 martin

Whitespace cosmetics


# 1.237 18-Feb-2007 martin

Backout previous: EMPTY was misused


# 1.236 18-Feb-2007 martin

Make EMPTY expand to nop with gas, as it is used to mark empty branch
delay slots.


# 1.235 15-Feb-2007 martin

branches: 1.235.2;
Fix obvious copy&pasto in SCHED_DEBUG register usage.


Revision tags: post-newlock2-merge
# 1.234 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.233 25-Dec-2006 wiz

Spell "relevant" correctly. From Zafer Aydogan.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.232 25-Oct-2006 mrg

branches: 1.232.2; 1.232.4;
- note that __idle_u should go away but doing so breaks things
- fix several comments to reality
- clean up the #ifdef NO_VCACHE code slightly
- use call instead of set/jmpl
- remove a couple of unnecessary stores to curlwp


Revision tags: yamt-splraiseipl-base2
# 1.231 18-Oct-2006 rjs

Clean up some comments. Cosmetic change to use correct structure
offset names.

Optimize out two instructions from sparc64_ipi_save_fpstate and
sparc64_ipi_drop_fpstate.


# 1.230 17-Oct-2006 mrg

allocate 128KB (as opposed to 64KB) per-cpu, and place the interrupt
stack, cpu_info structure, panicstack, idle uarea and normal kernel
stack in here. the idle uarea and kernel stack are in the 2nd 64KB
page. the interrupt stack and cpu_info structure are as the same
place in the 1st 64KB page, and the panicstack grows down from the
top of this page. update comments in param.h to suit (XXX: a lot
of these constants should move to a header file that will not pollute
the name space so much.) map these pages identically between
cpu_initialise() and cpu_mp_startup(), and deal with the two 64KB
pages in pmap_extract(). keep an unmapped 64KB page between them.

don't initialise the unused "ci_eintstack" member of the cpu_info
structure

use constants to initialise many addresses in the cpu_info structure,
consolidating these assignments from cpu0 and cpu>0

delete u0/estack0/panicstack from locore.s

clean up some wrong comments in locore.s

fix a 32bit-only bug in cpu_mp_startup().

delete 'u0' entirely.


this fixes recent random lossage seen on port-sparc64: processes
stuck in RUN state, data faults, and hangs.


# 1.229 04-Oct-2006 mrg

use call instead of set/jmpl. add an entry point for idle that expects
sched_lock to be unlocked, and use this for non-boot cpu's. complete a
comment describing how registers in idle_switch are expected to be set.


# 1.228 03-Oct-2006 mrg

use the same SAVE_LOCALS_INS definition for 32 bit and 64 bit kernels.
refactor TRAP_SETUP() a little between these two versions to be more alike.


# 1.227 03-Oct-2006 mrg

use the correct size/type for MP variables (pointers and longs).

a 32 bit MULTIPROCESSOR kernel now builds (and crashes quickly.)


# 1.226 03-Oct-2006 mrg

in the 64bit version of SAVE_LOCAL_INS, s/BIAS/STKB/ to allow future
sharing of the 32 and 64 bit versions of the {TRAP,INTR}_SETUP macros.


# 1.225 19-Sep-2006 mrg

- remove some way old FP setup/teardown code
- put the block memcpy/memset inside #ifdef USE_BLOCK_STORE_LOAD which
is (now) defined.

no functional change, same .o is generated.


# 1.224 19-Sep-2006 mrg

re-order the changes in rev 1.217 to give registers a little bit of
time to settle between usage, like it was before hand.


# 1.223 19-Sep-2006 mrg

- remove a wrong comment.
- add a new entry point for idle called idle_switch that is called by
cpu_switch() in the MP case when sched_whichqs is zero, properly
setting up the idle stack. from petrov@ via martin@.


# 1.222 19-Sep-2006 mrg

rework interrupt_vector() slightly:
- for the IPI case, avoid loading the address of intrlev into %g3
- remove some NOT_DEBUG code
- load the interrupt argument #2 in the delay slot

this removes 2 nops during interrupt processing for the normal
case, and an additional 2 ALU instructions for IPIs


# 1.221 18-Sep-2006 mrg

- sparc64_ipi_halt(): we shouldn't return from sparc64_ipi_halt_thiscpu()
so replace a branch with a 'sir'
- in #if 0 code, in sparc64_ipi_flush_pte() and sparc64_ipi_flush_ctx()
save/restore the out registers that the sp_tlb_flush_xxx() versions
around calling them
- in sp_tlb_flush_pte() and sp_tlb_flush_ctx(), replace global register
usage with out registers so that we don't clobber the (alternate)
global registers when these are called from IPI context


# 1.220 18-Sep-2006 mrg

- remove an extra 'sir' that followed one in a macro
- add some named labels to some spill/fill handlers
- remove 2 unused strings


Revision tags: yamt-splraiseipl-base
# 1.219 18-Sep-2006 martin

branches: 1.219.2;
Lazy FPU handling for the MULTIPROCESSOR case


# 1.218 16-Sep-2006 nakayama

From OpenBSD:
- reload %fprs for checking it again.
- use symbolic names for checking in %fprs.

revision 1.51
date: 2005/07/18 14:50:11; author: deraadt; state: Exp; lines: +2 -1
cache a copy of the fprs so we know what fp restore we should do after

revision 1.50
date: 2005/07/14 01:46:13; author: deraadt; state: Exp; lines: +4 -4
use symbolic names for checking in %fprs, as above


# 1.217 16-Sep-2006 nakayama

Fix a couple of %y register save/restore errors, inspired from OpenBSD.

revision 1.44
date: 2004/04/23 04:18:17; author: marc; state: Exp; lines: +5 -4

fix a couple of %y register save/restore errors
1) don't save %y in a register that is later used before restoring %y
2) always restore %y after calling a signal handler
tested by drahn@, OK pval


# 1.216 15-Sep-2006 martin

Do not bother to save fpu state when we are about to get rid of it.


Revision tags: yamt-pdpolicy-base9
# 1.215 13-Sep-2006 mrg

SMP cleanup. provide support for multiple CPUs in DDB. (SMP itself
is still not working.)

cpu.h:
- add a pointer for DDB regs in SMP environment to struct cpu_info
- remove the #defines for mp_pause_cpus() and mp_resume_cpus()
cpuset.h:
- remove CPUSET_ALL() and rename CPUSET_ALL_BUT() to CPUSET_EXCEPT()
from petrov.
db_machdep.h:
- rename the members of db_regs_t to be the same as sparc
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- redo DDB_REGS to no longer be a pointer to a fixed data structure
but to one allocated per-cpu when ddb is entered
- move a bunch of prototypes in here
intr.h:
- remove SPARC64_IPI_* macros, no longer used
db_interface.c:
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- make "nil" a 64 bit entity
- change the ddb register access methods to work in multiprocessor
environment, it is now very much like sparc does it
- in kdb_trap() avoid accessing ddb_regp when it is NULL
- update several messages to include the cpu number
- unpause other cpus much later when resuming from ddb
- rename db_lock() to db_lock_cmd(), as the sparc-like code has
db_lock as a simple lock
- remove "mach cpus" command, and replace it with "mach cpu" (which
does the same) and also implement "mach cpu N" to switch to
another cpus saved trapframe
db_trace.c:
- update for the ddb_regs -> ddb_regp change
genassym.cf:
- add TF_KSTACK as offsetof(struct trapframe64, tf_kstack)
ipifuncs.c:
- overhaul extensively
- remove all normal interrupt handlers as IPI's, we now handle
them all specially in locore.s:interrupt_vector
- add a simplelock around all ipi functions - it's not safe for
multiple cpus to be sending IPI's to each other right now
- rename sparc64_ipi_pause() to sparc64_ipi_pause_thiscpu() and,
if DDB is configured, enable it to save the passed-in trapframe
to a db_regs_t for this cpu's saved DDB registers.
- remove the "ipimask" system (SPARC64_IPI_* macros) and instead
pass functions directly
- in sparc64_send_ipi() always set the interrupt arguments to 0,
the address and argument of the to be called function. (the
argument right now is the address of ipi_tlb_args variable, and
part of the reason why only one CPU can send IPI's at a time.)
don't wait forever for an IPI to complete. some of this is
from petrov.
- rename sparc64_ipi_{halt,pause,resume}_cpus() to
mp_{halt,pause,resume}_cpus()
- new function mp_cpu_is_paused() used to avoid access missing
saved DDB registers
- actually broadcast the flush in smp_tlb_flush_pte(),
smp_tlb_flush_ctx() and smp_tlb_flush_all(). the other end may
not do anything yet in the pte/ctx cases yet...
kgdb_machdep.c:
- rework for changed member names in db_regs_t.
locore.s:
- shave an instruction from syscall_setup() (set + ld -> sethi + ld)
- remove some old dead debug code
- add new sparc64_ipi_halt IPI entry point, it just calls the C
vector to shutdown.
- add new sparc64_ipi_pause IPI entry point, which just traps into
the debugger using the normal breakpoint trap. these cpus usually
lose the race in db_interface.c:db_suspend_others() and end up
calling the C vector sparc64_ipi_pause_thiscpu().
- add #if 0'ed code to sparc64_ipi_flush_{pte,ctx}() IPI entry
points to call the sp_ version of these functions.
- in rft_kernel (return from trap, kernel), check to see if the
%tpc is at the sparc64_ipi_pause_trap_point and if so, call
"done" not "retry"
- rework cpu_switch slightly: save the passed-in lwp instead of
using the one in curlwp
- in cpu_loadproc(), save the new lwp not the old lwp, to curlwp
- in cpu_initialize(), set %tl to zero as well. from petrov.
- in cpu_exit(), fix a load register confusion. from petrov.
- change some "set" in delay branch to "mov".
machdep.c:
- deal with function renames
pmap.c:
- remove a spurious space
trap.c:
- remove unused "trapstats" variable
- add cpu number to a couple of messages


# 1.214 09-Sep-2006 mrg

significant clean up effort, largely from petrov@ via martin@.

- fix a bunch of comments for proc->lwp
- remove old TRAPTRACE, NOT_DEBUG, etc. code that has bit-rotted
- put some older DEBUG code under NOT_DEBUG
- add a bunch of new debugging/tracing code ("KTR") that depends on
other changes not yet present.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base yamt-pdpolicy-base5 chap-midi-base simonb-timecounters-base rpaulo-netinet-merge-pcb-base
# 1.213 14-May-2006 elad

branches: 1.213.6; 1.213.8;
integrate kauth.


# 1.212 12-May-2006 skrll

Fix some comments.


Revision tags: elad-kernelauth-base
# 1.211 09-May-2006 rjs

Load CPCB in cpu_mp_startup.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.210 11-Feb-2006 cdi

branches: 1.210.2; 1.210.4; 1.210.6;
ANSIfication: u_intN_t -> uintN_t, use ANSI function declarations/definitions
instead of K&R ones.


# 1.209 27-Jan-2006 cdi

branches: 1.209.2; 1.209.4;
Alter sparc64 bootstrap, catch up to ofwboot v1.9:

- Accept bootinfo structure passed down from ofwboot v1.9
- Drop kernel re-mapping code
- Use permanent 4MB mappings provided by the loader instead
- Change kernel entry address to point directly at the code instead of pointing
at the trap table's first slot. This allows the bootloader to detect
those kernels which are aware of the new boot scheme
- Due to the changes in kernel mapping code, alter secondary CPU bootstrap
code to use trampoline just like FreeBSD does (some FreeBSD code is used
here as well)


# 1.208 12-Jan-2006 cdi

Fix a typo: %g0 should be used instead of %o0 when initializing FPU in dostart:
and cpu_mp_startup:, %o0 is not even initialized at this point.


# 1.207 11-Dec-2005 christos

branches: 1.207.2;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 1.206 10-Jul-2005 christos

Re-factor syscall, and make it use syscall_{plain,fancy}.


# 1.205 31-May-2005 chs

branches: 1.205.2;
remove vestigal {,e}intr{names,cnt} symbols now that vmstat doesn't need them.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.204 12-Feb-2005 chs

branches: 1.204.4; 1.204.6; 1.204.8;
in sparc_interrupt(), wait to enable interrupts until just before calling
the handler and disable them again right after the handler returns.
we don't want another hardware interrupt coming in while we're mucking
with the list pointers. also, clear the intrhand's ih_pending pointer
before calling the handler rather than after, so that if another interrupt
comes in while the handler is running, we can put the intrhand back on
the list so it will be called again.

in send_softint(), disable interrupts via %pstate instead of %pil, so that
hardware interrupts at higher levels are blocked while we manipulate the
intrpending list. also, if the intrhand already has ih_pending set,
don't bother poking the SET_SOFTINT register again, since being on the list
implies that there is already a softint pending in the hardware.

these appear to fix PR 21750 (the "sleep forever" problem).

while I'm here, remove more vestiges of the !INTRLIST softint stuff
(code and comments). and in sparc64_ipi_flush_all(), interrupts are
already disabled so we don't need to fiddle with %pstate.


Revision tags: yamt-km-base2
# 1.203 30-Jan-2005 martin

Remove the no long usefull variants selected by undefining INTRLIST and
INTR_INTERLOCK to improve readability. Same object code generated as before.


Revision tags: yamt-km-base
# 1.202 16-Jan-2005 chs

branches: 1.202.2;
use ENTRY_NOPROFILE() for various entry points,
stack traces work better that way.


Revision tags: kent-audio1-beforemerge kent-audio1-base
# 1.201 03-Dec-2004 chs

branches: 1.201.4;
remove cache_flush_virt() and PADDRT, they're no longer used.
allocate a stack frame for blast_dcache() when profiling so it shows up.
in dcache_flush_page(), use a stride of 32 instead of 16 to match the
cache line size. correct various comments.


# 1.200 08-Nov-2004 petrov

Don't compile sparc64_ipi functions when UP.


# 1.199 25-Oct-2004 martin

No need to clear %o1 when returning a 64 bit integer from pseg_get if we
are compiling for a 64 bit kernel.


# 1.198 24-Jul-2004 nakayama

Change interrupt pending list end value to -1, to avoid linking an
interrupt handler twice.

It may fix "sleep forever" bug.


# 1.197 09-Apr-2004 petrov

Clean-up unused defines and variables.


Revision tags: netbsd-2-0-base
# 1.196 26-Mar-2004 petrov

branches: 1.196.2;
Use want_resched from cpu_info area.


# 1.195 23-Mar-2004 martin

Replace intrcnts by evcnts. XXX - needs slight tweaking for MULTIPROCESSOR.


# 1.194 14-Mar-2004 chs

checkpoint of MP work from dennis and myself. includes cross-processor
interrupt framework, a sledgehammer TLB invalidation and misc MP fixes.
doesn't work at all yet.


# 1.193 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.192 19-Jan-2004 martin

Rename switchexit to cpu_exit and g/c the old C implementation of cpu_exit.


# 1.191 18-Jan-2004 martin

Support RAS for 32bit kernels too.


# 1.190 16-Jan-2004 martin

In proc_trampoline don't bother to clear condition codes in the trap
frame, since we no longer rely on this.
While there fix a few comments.


# 1.189 08-Jan-2004 martin

Minor cleanup


# 1.188 06-Jan-2004 martin

Implement restartable atomic sequences (RAS) for sparc64.


# 1.187 06-Jan-2004 petrov

Spinup secondary cpus. Based on codes sent to me by Dennis Chernoivanov
and Chuck Silvers.


# 1.186 04-Jan-2004 jdolecek

update to recent changes - exit2() doesn't exist anymore and the
exit path always calls lwp_exit2()
pointed out Martin Husemann


# 1.185 02-Dec-2003 martin

Minor cleanup: remove unused code, sync a comment with current reality.


# 1.184 25-Nov-2003 cdi

Use per-cpu pcb, curlwp and fplwp rather than global ones. This brings
GENERIC.MP configuration to a usable state.

Approved by petrov@.


# 1.183 24-Nov-2003 cdi

Call 'proc_trampoline_mp' from 'proc_trampoline' in a multiprocessor
configuration. Fix process locking. Approved by petrov@.


# 1.182 20-Nov-2003 petrov

Remove nwindows calculation, it's not used. Set l_cpu in cpu_switch.


# 1.181 09-Nov-2003 martin

Get rid of bcopy/bzero.


# 1.180 26-Oct-2003 christos

Initial siginfo support for sparc64 (untested). COMPAT_16 sigcontext signal
delivery tested.


# 1.179 24-Aug-2003 chs

add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default. the changes
fall into two basic catagories:

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

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

originally from openbsd, adapted for netbsd by me.


# 1.178 08-Jul-2003 cdi

traceit: don't use %g7 as it is to become curcpu() register. Add comments.


# 1.177 18-May-2003 martin

branches: 1.177.2;
Make kernels with options KGDB at least compile.
Still needs some work to make it working.


# 1.176 29-Apr-2003 nakayama

Use BLOCK_ALIGN rather than BLOCK_SIZE for aligning a pointer.


# 1.175 27-Apr-2003 ragge

Preserve the symbol table in the LKM || KSYMS cases also.


# 1.174 04-Apr-2003 petrov

use branch slot in pmap_copy_page.


# 1.173 24-Mar-2003 nakayama

Divide `set' instruction in delay slot (from OpenBSD change to rev 1.30).


# 1.172 10-Feb-2003 martin

Remove some #if 0 code and a few XXX marked membars w/o proper
justification for their existence.


# 1.171 09-Feb-2003 martin

Remove left over pieces from reusing the signal trampoline for upcalls.
This should fix signal delivery for 32bit kernels.


# 1.170 05-Feb-2003 nakayama

Switch to use cycle counter (%tick) based microtime().

This is derived from alpha/microtime.c and i386/tsc_microtime.c,
and will share with both ports.

This should fix PR port-sparc64/18452.
(approved by martin)


# 1.169 04-Feb-2003 martin

Fix return value of pseg_set, which I accidently broke in rev. 1.164.

Fix register names in comment and shave off another register (hint
from uwe).


# 1.168 01-Feb-2003 martin

Rearrange register usage in pseg_set a bit and shave off %g4.


# 1.167 01-Feb-2003 martin

Remove a few #ifdef _LP64 by using STPTR/LDPTR macros.
Thanks to Matthew Green for the pointer.


# 1.166 31-Jan-2003 martin

Apply leaf procedure optimization to pseg_set (again).


# 1.165 31-Jan-2003 martin

Make the pmap count resident/wired mappings on the fly instead of
walking the page tables whenever this information is needed.

Add an option PMAP_COUNT_DEBUG to assert the new counts and the
page table walk agree.

The old solution had very bad performance impact, for example
by the high CPU load when running top(1).

Thanks to Simon Burge for pointing at the cause of the problem and
to Valeriy E. Ushakov for optimizing my simple minded assembler code.


# 1.164 27-Jan-2003 martin

Remove unused function pseg_find (which looked quite similar to
pseg_get anyway).


# 1.163 18-Jan-2003 thorpej

Merge the nathanw_sa branch.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.162 16-Jan-2003 petrov

Move dump_dtlb back under DDB.


# 1.161 15-Jan-2003 chs

fix two bugs in my last pmap rework:
- in tlb_flush_all(), don't skip TLB entries with the high bit on,
I was confused about which MMU register it was using. it's also fine
to use the last hardware context.
- in pmap_create(), don't allocate a hardware context for the new pmap.
it's unnecessary, and when this would cause us to recycle all the contexts,
it would result in the current process's context being set to 0
(ie. the kernel's context). the current process could then return to
userspace without going through the context-switch code (and thus without
having a hardware context reallocated). this would lead to user mappings
being entered in the kernel's context later, causing all sorts of trouble.
add some assertions to catch this kind of thing.


Revision tags: fvdl_fs64_base
# 1.160 25-Dec-2002 petrov

new function dump_itlb.


Revision tags: gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.159 22-Sep-2002 chs

many improvements:
- use struct vm_page_md for attaching pv entries to struct vm_page
- change pseg_set()'s return value to indicate whether the spare page
was used as an L2 or L3 PTP.
- use a pool for pv entries instead of malloc().
- put PTPs on a list attached to the pmap so we can free them
more efficiently (by just walking the list) in pmap_destroy().
- use the new pmap_remove_all() interface to avoid flushing the cache and TLB
for each pmap_remove() that's done as we are tearing down an address space.
- in pmap_enter(), handle replacing an existing mapping more efficiently
than just calling pmap_remove() on it. also, skip flushing the
TSB and TLB if there was no previous mapping, since there can't be
anything we need to flush. also, preload the TSB if we're pre-setting
the mod/ref bits.
- allocate hardware contexts like the MIPS pmap:
allocate them all sequentially without reuse, then once we run out
just invalidate all user TLB entries and flush the entire L1 dcache.
- fix pmap_extract() for the case where the va is not page-aligned and
nothing is mapped there.
- fix calculation of TSB size. it was comparing physmem (which is
in units of pages) to constants that only make sense if they are
in units of bytes.
- avoid sleeping in pmap_enter(), instead let the caller do it.
- use pmap_kenter_pa() instead of pmap_enter() where appropriate.
- remove code to handle impossible cases in various functions.
- tweak asm code to pipeline a little better.
- remove many unnecessary spls and membars.
- lots of code cleanup.
- no doubt other stuff that I've forgotten.

the result of all this is that a fork+exit microbenchmark is 34% faster
and a fork+exec+exit microbenchmark is 28% faster.


Revision tags: gehenna-devsw-base
# 1.158 18-Jul-2002 wiz

Spell 'should' correctly.


# 1.157 07-Jun-2002 eeh

Shave 10% off the time needed to flush the D$ through a bit of instruction
reordering.


# 1.156 05-Jun-2002 eeh

Handle improperly aligned stack pointers more cleanly.


# 1.155 04-Jun-2002 eeh

Fix the fork trampoline to properly use the supplied tstate.


# 1.154 31-May-2002 thorpej

Make this work with an ISO C preprocessor.


Revision tags: netbsd-1-6-base
# 1.153 14-May-2002 eeh

branches: 1.153.2; 1.153.4;
Only save locals and ins in trapframes for DEBUG kernels.


# 1.152 04-May-2002 kleink

Add some comments to the CPP conditionals controlling the trap macro
definitions, to ease navigation somewhat.


# 1.151 16-Apr-2002 eeh

Make lots of routines profile-friendly and get rid of some cruft.


Revision tags: eeh-devprop-base
# 1.150 21-Mar-2002 petrov

Not needed debug stuff deleted.


# 1.149 16-Mar-2002 mrg

tell newer binutils that our use of %g2 and %g3 is OK here.


# 1.148 15-Mar-2002 eeh

Cleanup MMU initialization to prevent hangs.


Revision tags: newlock-base ifpoll-base
# 1.147 09-Feb-2002 eeh

branches: 1.147.4;
Fix microsecond calculation in microtime.


# 1.146 07-Feb-2002 eeh

Fix register allocation in microtime().


# 1.145 29-Jan-2002 eeh

Shift the UPAID in the correct direction.


# 1.144 17-Jan-2002 eeh

Be more tolerant of unaligned stack pointers.


# 1.143 17-Jan-2002 eeh

Enable block insns in bcopy and bzero.


# 1.142 16-Jan-2002 eeh

In bcopy use 32-bit comparisons in 32-bit kernels.


# 1.141 16-Jan-2002 eeh

Use correct calculation for the trapframe in softtrap for ILP32.


# 1.140 20-Nov-2001 lukem

- pull in opt_kgdb.h where necessary
- replace opt_kgdb_machdep.h with opt_kgdb.h
- defparam opt_kgdb.h:
KGDB_DEV KGDB_DEVNAME KGDB_DEVADDR KGDB_DEVRATE KGDB_DEVMODE
- move from opt_ddbparam.h to opt_ddb.h:
DDB_FROMCONSOLE DDB_ONPANIC DDB_HISTORY_SIZE DDB_BREAK_CHAR SYMTAB_SPACE
- replace KGDBDEV with KGDB_DEV
- replace KGDBADDR with KGDB_DEVADDR
- replace KGDBMODE with KGDB_DEVMODE
- replace KGDBRATE with KGDB_DEVRATE
- use `9600' instead of `0x2580' for 9600 baud rate
- use correct quotes for options KGDB_DEVNAME="\"com\""
- use correct quotes for options KGDB_DEV="17*256+0"
- remove unnecessary dependancy on Makefile for kgdb_stub.o
- minor whitespace cleanup


Revision tags: thorpej-mips-cache-base thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf
# 1.139 14-Sep-2001 thorpej

branches: 1.139.4;
Don't declare intrhand[] here -- that's taken care of in intr.c.


Revision tags: thorpej-devvp-base
# 1.138 30-Aug-2001 eeh

branches: 1.138.2;
Preliminary UltraSPARC III suport (not enabled yet).


# 1.137 13-Aug-2001 jdolecek

g/c _remque()/_insque(); use the C version in libkern


# 1.136 09-Aug-2001 eeh

Fix context masking lossage caused by last version.


# 1.135 08-Aug-2001 eeh

Clean up the trap code to handle the changes cause by supporting non-faulting
accesses. Also change the parameter order so trap frames are easy to find.


# 1.134 07-Aug-2001 eeh

Make sure C code always has ASI_PRIMARY_NOFAULT in the %asi register so
the compiler will be happy if it ever starts generating speculative loads.


# 1.133 05-Aug-2001 eeh

Add support for non-faulting loads and optimize MMU miss handling paths.


# 1.132 02-Aug-2001 eeh

Fix bcopy.


# 1.131 02-Aug-2001 eeh

Sync bzero w/libc version.


# 1.130 01-Aug-2001 eeh

Integrate fixes from userland memset.


# 1.129 31-Jul-2001 eeh

Code cleanup and optimization.


# 1.128 23-Jul-2001 eeh

Get rid of some debug code that really isn't all that useful any more.


# 1.127 19-Jul-2001 eeh

Do ignore unregistered interrupts instead of faulting.


# 1.126 16-Jul-2001 eeh

Make bcopy a 32-bit friendly.


# 1.125 11-Jul-2001 eeh

Fix problems booting 32-bit kernels and dispatching level-15 interrupts.


# 1.124 08-Jul-2001 eeh

branches: 1.124.2;
Code cleanup. Add block_disable to let you turn on block set/copy routines.


# 1.123 05-Jul-2001 eeh

New block bzero and bcopy.


# 1.122 04-Jul-2001 eeh

Replace old bcopy with a much faster version.


# 1.121 01-Jul-2001 martin

Disable axidently enabled debug code to make -current compile again.


# 1.120 30-Jun-2001 eeh

Use a newer version (still disabled) of block bcopy.


# 1.119 30-Jun-2001 eeh

Fixup fpu save restore, get rid of some unused copy functions, and add
a new bcopy.


# 1.118 21-Jun-2001 eeh

Allow multiple 4MB pages for both kernel text and kernel data.

Note: DEBUG checks will not allow accesses to the hole between
text and data segments, so you may need to update programs that
use libkvm before relocating the start of kernel data.


# 1.117 06-Jun-2001 mrg

extract the netbsd32, sunos, 32 bit svr4 and 64 bit svr4 sigcode out into
separate files, so that compat lkms can link with them as well.


# 1.116 30-May-2001 lukem

add missing #include "opt_kgdb.h"


Revision tags: thorpej_scsipi_beforemerge
# 1.115 25-Apr-2001 simonb

Spell occurred correctly.


Revision tags: thorpej_scsipi_nbase thorpej_scsipi_base
# 1.114 09-Apr-2001 eeh

Interrupt latency fix from sparc port. (Hm. One insn instead of 5).


# 1.113 07-Mar-2001 eeh

Fix inverted preprocessor logic. (Spotted by Charles.)


# 1.112 21-Feb-2001 eeh

branches: 1.112.2;
Add support for 64-bit SVR4 (Solaris 8) binaries.


# 1.111 10-Feb-2001 pk

Fix conditional for svr4 compat inclusion.


# 1.110 05-Feb-2001 eeh

Add signal trampoline for 64-bit svr4 emulations.


# 1.109 31-Dec-2000 eeh

Make INCR() atomic.


# 1.108 29-Dec-2000 eeh

pseg_get tells us whether it really needed that spare page after all.


# 1.107 07-Dec-2000 eeh

Fixup calculating where fpstate should be saved in the signal trampoline
code so it doesn't overwrite something important like the registers.


# 1.106 09-Nov-2000 eeh

Fix ILP32 bug in probe_get().


# 1.105 22-Oct-2000 pk

Restore revision 1.102.

I hope it sticks this time..


# 1.104 20-Oct-2000 eeh

Fix hang in 32-bit kernels caused by relocation of KERNBASE.


# 1.103 04-Oct-2000 eeh

Fix interrupt lossage problem and some cosmetic changes.


# 1.102 01-Oct-2000 pk

cpu_initialize: global registers aren't preserved across calls to
prom_printf(), so replace %g3 with %l7 (which isn't used despite
the `usage' comment).

Also, clean up white-space turds.


# 1.101 29-Sep-2000 eeh

This seems to fix the interrupt lossage of non-debug kernels.


# 1.100 28-Sep-2000 eeh

Fix INTR_SETUP() to properly distinguish kernel and user addresses.

Make microtime() return the correct time on %tick machines.

Re-enable debug stuff in dostart for now to detect kernel mapping issues.


# 1.99 25-Sep-2000 pk

Missing `#if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)'


# 1.98 17-Sep-2000 eeh

Make the improved %tick changes work with machines that use the counter-timer
for the clock.


# 1.97 12-Sep-2000 eeh

Fix new version of microtime.


# 1.96 11-Sep-2000 eeh

(Hopefully) fix clock skew on machines that us %tick for the clock (UIIi).


# 1.95 31-Aug-2000 eeh

Use casx instead of stx to change entries in the page table trees.


# 1.94 23-Aug-2000 eeh

Update the scheduler to the new locking scheme.


# 1.93 10-Aug-2000 eeh

Fix signal delivery.


# 1.92 02-Aug-2000 eeh

Get kernel profiling to work. Now if only gprof worked....


# 1.91 01-Aug-2000 eeh

Overhaul cache flush code and coredump code.


# 1.90 25-Jul-2000 pk

Re-instate a couple of delay slot NOPs marked `XXX spitfire bug?'


# 1.89 24-Jul-2000 mycroft

Optimization to pmap_zero_page(): we only need to use the first 16 FP regs,
as in bzero().


# 1.88 24-Jul-2000 mycroft

Fix a whitespace glitch.


# 1.87 24-Jul-2000 mycroft

Pull in the bzero() changes from libc for real, with a couple of kernel-
specific hacks:
* Make the bias handling depend on STKB, so it switches correctly for 32-bit
kernels.
* Use the 32-bit stw/ld for 32-bit kernels.
* Add a few `-STKB's that were missed in the previous change.


# 1.86 24-Jul-2000 pk

Cosmetic & readability:
- local label cleanup in interrupt handling code;
- in debugging sections when testing `intrdebug': use a unique
local label (97) to enhanced clarity;
- comment-out unused code;
- kill a bug as the satisfying result of doing all of the above.


# 1.85 24-Jul-2000 eeh

Fix stack issues in bzero.


# 1.84 24-Jul-2000 mycroft

Revert the previous change for now. I don't have time to debug it tonight.


# 1.83 23-Jul-2000 mycroft

Copy bzero change from libc.


# 1.82 20-Jul-2000 pk

Since `intrcnt' points to an array of long ints, reserve the appropriate
amount of space depending on _LP64. Provide macros to load/store signed
and unsigned long ints.

Also, make the `intrcnt' and `intrpending' arrays 16 entries long, as on
sparc/v9 interrupt #15 is just a regular interrupt.


# 1.81 19-Jul-2000 eeh

Fix merge problem.


# 1.80 19-Jul-2000 eeh

Disable interrupt interlock using ih->ih_pending field. Seems to cause
more problems than it solves.


# 1.79 19-Jul-2000 eeh

Miscellaneous cleanup.


# 1.78 18-Jul-2000 pk

Correct args usage comment in probeget.
Whitespace cleanup.


# 1.77 18-Jul-2000 pk

probeget: 9 -> 0x9


# 1.76 18-Jul-2000 pk

If `ih_pending' is set simply return from the trap, don't schedule another
soft interrupt.


Revision tags: mrg-merge-1-5-top
# 1.75 18-Jul-2000 pk

openfirmware: don't lower %pil


# 1.74 17-Jul-2000 pk

Kill typos in interrupt code.


# 1.73 17-Jul-2000 pk

probeget: do the same song and dance as ld*a() macros in ctlreg.h do.


# 1.72 14-Jul-2000 eeh

Move some macro definitions out of genassym and into locore.s


# 1.71 08-Jul-2000 mrg

backout part of previous: turn off intrdebug, and another debug message


# 1.70 07-Jul-2000 pk

Changes for readability:
- #define LP64 dependent STACKFRAME macro once
- use a LOAD_ASCIZ macro for setting up the format string
for debug messages.


# 1.69 07-Jul-2000 eeh

Temporary fix to prevent the clock from stopping on UIIi machines.


# 1.68 03-Jul-2000 eeh

Prevent interrupts from being posted if they are active and deprecate polled
interrupts. This seems to eliminate the spurious interrupts.


# 1.67 02-Jul-2000 eeh

Clean up interrupt handling some more.


# 1.66 30-Jun-2000 eeh

Fix interrupt delivery on UltraSPARC IIi machines.


# 1.65 24-Jun-2000 eeh

With these changes the kernel seems almost stable again.


# 1.64 24-Jun-2000 eeh

More VM cleanup:

Move the cpu_info structure above the interrupt stack so it won't
get corrupted if the stack overflows.

Flush the D$ before and after all MMU bypass accesses since the
D$ latches all of those.


# 1.63 23-Jun-2000 eeh

Make probeget() and probeset() really work for a change.


Revision tags: netbsd-1-5-base
# 1.62 19-Jun-2000 eeh

branches: 1.62.2;
Have separate data and text segments, make text read-only.


# 1.61 12-Jun-2000 eeh

Start reorganizing the kernel for MULTIPROCESSOR support.


# 1.60 31-May-2000 thorpej

Add a comment about needing to initialize p_cpu when multiple
processors are supported.


Revision tags: minoura-xpg4dl-base
# 1.59 26-May-2000 thorpej

branches: 1.59.2;
First sweep at scheduler state cleanup. Collect MI scheduler
state into global and per-CPU scheduler state:

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

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

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

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

Tested on i386 and Alpha. Changes are mostly mechanical, but apologies
in advance if it doesn't compile on a particular platform.


# 1.58 26-May-2000 thorpej

Don't set `runtime' here; it's done at the end of mi_switch().
cvS: ----------------------------------------------------------------------


# 1.57 26-May-2000 thorpej

Introduce a new process state distinct from SRUN called SONPROC
which indicates that the process is actually running on a
processor. Test against SONPROC as appropriate rather than
combinations of SRUN and curproc. Update all context switch code
to properly set SONPROC when the process becomes the current
process on the CPU.


# 1.56 22-Apr-2000 eeh

If we trap due to a bad kernel stack, try to switch to the interrupt strack
before breaking into the debugger.


# 1.55 18-Apr-2000 eeh

Prevent the system from getting watchdog reset by returning directly to user
mode if restoring the user window traps. Also reduce the time we run with
%tl>0.


# 1.54 13-Apr-2000 eeh

Apparently gas 2.9.5 (don't ask) does not like to add values to %lo()
directives so move the additions inside %lo() to make it happy.
Hopefully this won't break older versions.


# 1.53 10-Apr-2000 mrg

- fix a speeling error
- rename some numbered labels to be a bit less confusing.
- remove dead code
- fix a debug error message (argh!)


# 1.52 10-Apr-2000 pk

Get a kernel without DDB to build.


# 1.51 16-Mar-2000 eeh

Revamp interrupts again:

Fix a bug causing interrmittent panics in interrupt dispatch.
Use interrupt vectors for softints.
Add a new send_softint interface.
Improved D$ flushing.
Improve traptrace and other debugging enhancements.


Revision tags: chs-ubc2-newbase
# 1.50 16-Jan-2000 eeh

Interrupt handlers return zero if they didn't handle the interrupt.


# 1.49 10-Jan-2000 eeh

Add debugger single-stepping and fix interrupt dispatch bugs.


# 1.48 30-Dec-1999 eeh

Lots of changes:

remove ffs()
add bzero that uses block store insns
save %gsr to fpstate
revert to physical accesses for pmap_zero_page so we don't
have conflicting page mappings
general cleanup.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base fvdl-softdep-base
# 1.47 06-Nov-1999 eeh

Handle zero length properly in copyinstr() copyoutstr() and copystr().


Revision tags: comdex-fall-1999-base
# 1.46 11-Oct-1999 eeh

branches: 1.46.2; 1.46.4;
Update to post 1.4.


# 1.45 05-Oct-1999 eeh

branches: 1.45.2;
Make broken versions of gas happy by using sethi/or instead of set for
(negative) addresses.


# 1.44 17-Sep-1999 thorpej

Centralize the declaration and clearing of `cold'.


Revision tags: chs-ubc2-base
# 1.43 18-Jul-1999 eeh

More fun with pmap.


# 1.42 21-Jun-1999 eeh

Improve TRAPTRACE. Add FLTRACE that only tracks MMU faults.


# 1.41 05-Jun-1999 eeh

Make pbrobeget() and probeset() work for 64-bit values as well. To do this
the arguments are changed so the address is first and the ASI second so we
can have the address in %o0:%o1 and not worry about unused registers.

Also a bit of copyright cleanup.


# 1.40 05-Jun-1999 mrg

update a commit slightly.


# 1.39 30-May-1999 eeh

Add code to support using %tick as the system clock if no "counter-timer" node
is found.


# 1.38 09-May-1999 eeh

Fixup non-DEBUG kernels.


# 1.37 29-Apr-1999 christos

Add sunos_sigcode (32 bit only)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.36 26-Mar-1999 eeh

branches: 1.36.4;
COMPAT_SPARC32 -> COMPAT_NETBSD32


# 1.35 25-Mar-1999 mrg

clean and up make compile


# 1.34 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.33 22-Mar-1999 eeh

Need to set up the pointers properly for partial FPU register stores.


# 1.32 22-Mar-1999 eeh

Flush D$ on bypass accesses.


# 1.31 28-Feb-1999 eeh

Use block load/store in pmap_zero_page()/pmap_copy_page().


# 1.30 17-Feb-1999 eeh

Let's test out vectored interrupts.


# 1.29 15-Feb-1999 hubertf

RCS ID police


# 1.28 11-Feb-1999 mrg

fix a comment pasto.


# 1.27 11-Jan-1999 eeh

Finally fixed 64-bit signal trampoline.


# 1.26 10-Jan-1999 eeh

Handle the symbol table properly in a 32-bit kernel that was booted from a
64-bit bootloader.


# 1.25 09-Jan-1999 eeh

More signal fixup.


Revision tags: kenh-if-detach-base
# 1.24 26-Nov-1998 mycroft

Sync kcopy() with 32-bit SPARC version.


# 1.23 16-Nov-1998 eeh

Fixup the last broken bits of the signal handling code.


Revision tags: chs-ubc-base
# 1.22 08-Oct-1998 eeh

Fix more syscall32 and signal breakage.


# 1.21 22-Sep-1998 eeh

More fixup in the signal area.

64-bit syscall cleanup.

Add emulation for some new FPU insns: conversion to 64-bit long int and
conditional moves.


# 1.20 17-Sep-1998 thorpej

SYS_sigreturn -> SYS___sigreturn14.


# 1.19 13-Sep-1998 eeh

Fixup signal changes (hopefully). However SUN_COMPAT is likely broken by
this and I don't know how to fix it.

We can now exec a 64-bit init through a really ugly hack (don't ask.)


# 1.18 11-Sep-1998 eeh

Add labels for the compat_sparc32 signal trampoline and break -- er -- fix
suword and fuword.


# 1.17 09-Sep-1998 eeh

Don't use %tick for microtime on 32-bit kernels -- breaks gettimeofday.


# 1.16 09-Sep-1998 thorpej

Adjust for the new "reaper" kernel thread: do not free the vmspace and
u-area in machine-dependent code. Instead, call exit2() to schedule
the reaper to free them for us, once it is safe to do so (i.e. we are
no longer running on the dead proc's vmspace and stack).


# 1.15 07-Sep-1998 eeh

Fix data corruption problem caused by broken debug code.


# 1.14 07-Sep-1998 eeh

Add new 64-bit trap vectors.


# 1.13 06-Sep-1998 eeh

32-bit fixup.


# 1.12 06-Sep-1998 eeh

Disable some debug stuff.


# 1.11 05-Sep-1998 eeh

It slices. It dices. It does everything except exec a sparc32_compat init.


# 1.10 02-Sep-1998 eeh

Periodic update: now starts probing devices.


# 1.9 30-Aug-1998 eeh

Some more 64-bit cleanup. Now everything compiles.


# 1.8 29-Aug-1998 eeh

Some more 64-bit-ification.


# 1.7 27-Aug-1998 eeh

Add 64-bit pmap support:

Moved from a two level 512/1024 entry setup mapping 32 (9/10/13) bits
respectively to a three level 1024/1024/1024 entry setup mapping 43
(10/10/10/13) bits. In 32-bit mode we waste about 1/12 pages mapping the high
11 bits. We also only manage 43 of the possible 44 bits of virtual address
space, wasting half of it. Oh well, maybe we'll do better next revision.


Revision tags: PMAP32
# 1.6 26-Aug-1998 mrg

panicstack: is needed outside of DEBUG. use _C_LABEL, and printf not db_printf (incase no ddb!)


# 1.5 13-Aug-1998 eeh

Merge paddr_t changes into the main branch.


Revision tags: eeh-paddr_t-base
# 1.4 07-Jul-1998 eeh

branches: 1.4.2;
General update:

Added genassym.cf
Removed lderr which should never have gotten in
Removed lots of dead code from locore.s
Added some softint stuff to intr.c
Added support for halt -p
esp and le both use bus_dmamap_*() functions now
instead of kdvma_mapin()
groundwork for PCI (but we still have no drivers for
any sun4u PCI devices)


# 1.3 04-Jul-1998 jonathan

defopt DDB.


# 1.2 26-Jun-1998 thorpej

defopt COMPAT_SVR4


# 1.1 20-Jun-1998 eeh

branches: 1.1.1;
Initial revision


# 1.406 27-Jan-2017 palle

sun4v: implement missing handling of itsb traps 0x008 and 0x009. Based on code from OpenBSD. Tested using qemu.


Revision tags: bouyer-socketcan-base
# 1.405 07-Jan-2017 palle

sun4v: slowtrap() now selects normal globals properly on both sun4u and sun4v platforms. Verified using qemu for both sun4u and sun4v systems


Revision tags: pgoyette-localcount-20170107
# 1.404 05-Jan-2017 palle

sun4v: TRAP_SETUP() updated to set mmu context id properly for both sun4v and sun4u platforms. Verified using qemu for both sun4u and sun4v systems


# 1.403 04-Jan-2017 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x00-0x23 and 0x28-0x30


# 1.402 29-Dec-2016 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x32-0x7f


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.401 20-Sep-2016 nakayama

Fix RAS for 32-bit kernels. trapframe is always 64-bit.


Revision tags: localcount-20160914
# 1.400 23-Aug-2016 palle

sun4v: rework sun4v_datatrap so it works properly when running on a T2-based system like T5120 - for some reason %tl is 0 when entering sun4v_datatrap causing a crash (sir instruction), so ignore the %tl value for now upon entry to sun4v_datatrap - with this fix both T1 and T2 based systems reach the same point - hangs in rft_user after the init process is started


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726
# 1.399 18-Jul-2016 palle

sun4v: handle device interrupts properly - both legacy (sysino) and cookies


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 1.398 04-Jun-2016 palle

branches: 1.398.2;
sun4v: rtf_user now uses macros GET_MMU_CONTEXTID and SET_MMU_CONTEXTID. Tested on sun4u (QEMU) and sun4v (T2000). Parts from OpenBSD.


Revision tags: nick-nhusb-base-20160529
# 1.397 18-May-2016 nakayama

Decrement %tl in trap handler not to make it zero unconditionally
for the nested trap, and remove useless mov.


# 1.396 17-May-2016 palle

sun4v: Implement missng MMU protection trap handling - mostly from OpenBSD


# 1.395 16-May-2016 palle

Avoid assembler-specific defines by using the export keyword in genassym.cf instead


# 1.394 15-May-2016 nakayama

%g1 is not preserved across function call, so load it before
return_from_trap.


# 1.393 13-May-2016 palle

sun4v: add missing implementation of sun4v_datatrap_tl0 so data_access_fault() is called - mostly from OpenBSD


# 1.392 13-May-2016 nakayama

- ci_paddr is always 64-bit.
- intrlev is array of pointer.
- ih_ack is pointer.


# 1.391 10-May-2016 palle

sun4v: make device interrupts work. Introduce a new intrhand_alloc() function for allocation of interrupt handlers and adapt to this. Parts from OpenBSD. ok martin@


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.390 09-Mar-2016 nakayama

32-bit kernels use 32-bit stack.


# 1.389 03-Mar-2016 palle

sun4v: rft_kernel should pay attention to the number of register windows that can be restored. We cannot rely on fill traps to occur, since sun4v only has two trap levels available in privileged mode. Based on code from OpenBSD. ok martin@


# 1.388 14-Feb-2016 palle

sun4v: add breakpoint trap entry to the sun4v trap table


# 1.387 03-Feb-2016 palle

sun4v: extend dmmu_set_secondary_context() to handle both sun4u and sun4v. ok martin@


Revision tags: nick-nhusb-base-20151226
# 1.386 06-Nov-2015 martin

Basically revert r1.246 of locore.s and r1.73 of vm_machdep.c:

Remove special case handling for userland lwps from cpu_lwp_fork,
instead do it in lwp_trampoline when we first return to userland.

which was a stupid idea - since we did now set all fork child's %tstate
(and thus %pstate when back in userland) to the current kernel's userland
default. This meant we lost the address mask bit for 32bit processes and
all memory model details for 64bit ones.

Move it back to cpu_lwp_fork and fix the condition to only do it once when
forking init.


# 1.385 05-Nov-2015 martin

Most of the time return_from_trap already got called with tf->tf_tstate
loaded in register %g1 - make it so for two more callers and remove
the reload of that value.


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606 nick-nhusb-base-20150406
# 1.384 05-Apr-2015 palle

sun4v: Ensure that the TTEs CP and CV bits are the same (both set) for the primary cpu and secondary cpus INTSTACK mappings


# 1.383 01-Apr-2015 palle

sun4v: Implement handling of cpu_mondo trap - from OpenBSD - tested using the Legion simulator


# 1.382 04-Mar-2015 palle

sun4v: revert some of the logic introduced in revision 1.378 - flushw is not necessary on sun4v (OpenBSD patches the flushw instruction to a nop instruction) - with these changes the kernel reaches cpu_boot_secondary_processors() when running in the Legion simulator (crashes due to missing handling of cpu_mondo_trap)


# 1.381 02-Mar-2015 nakayama

prom_printf converts "\n" to "\r\n" internally, so omit "\r".


# 1.380 02-Mar-2015 nakayama

PANICSTACK is a pointer itself, not a pointer to pointer.


# 1.379 02-Mar-2015 nakayama

Use panic stack temporarily for calling prom_printf in a trap
handler.

It seems that openfirmware cannot handle over 4GB pointers, and
stack pointers may point to over 4GB since VA layout was rearranged
by rev 1.33 of vmparam.h. Therefore, use panic stack to avoid
panicking in OF_write used by prom_printf.


# 1.378 23-Feb-2015 palle

sun4v: sparc_interupt - ensure that the trap level and globals level are the same when the flushw instruction is issued - othwise warnings occur when using the sun4v Legion simulator.


Revision tags: nick-nhusb-base
# 1.377 26-Oct-2014 palle

branches: 1.377.2;
sun4v: Create CLEANWIN0 and CLEANWIN1 macros for handling clean window traps on both sun4u and sun4u (based on the original code inlined in the sun4u trap table). Update trap tables accordingly for both sun4u and sun4v. Ok martin@


# 1.376 24-Oct-2014 nakayama

Fix typo in comment.


# 1.375 18-Oct-2014 snj

src is too big these days to tolerate superfluous apostrophes. It's
"its", people!


# 1.374 15-Oct-2014 palle

sun4v: fixed bug causing the real address to be incorrectly calculated as zero


# 1.373 24-Sep-2014 palle

sun4v: add code to enable startup of secondary cpus on both sun4u and sun4v systems - ok martin@


# 1.372 04-Sep-2014 palle

sun4v: All cpus must be setup with a TSB descriptor, so pmap_setup_tsb_sun4v() must take a pointer to the TSB descriptor


# 1.371 31-Aug-2014 palle

sun4v: Split the NORMAL_GLOBALS and ALTERNATE_GLOBALS macros to _SUN4U and _SUN4V variants. Rework the return_from_trap logic to use the new variants so it is possible to use a global register as scratch register.


# 1.370 14-Aug-2014 nakayama

Add missing delay slot in DEBUG kernel.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.369 30-Jul-2014 palle

branches: 1.369.2;
Fix ALTERNATE_GLOBALS so it at least works on sun4u - using a scratch register is not a good idea...


# 1.368 27-Jul-2014 palle

sun4v: Introduce a new macro ALTERNATE_GLOBALS (matching NORMAL_GLOBALS). Two new helper macros ENABLE_INTERRUPTS and DISABLE_INTERRUPTS are also created. With these changes the GENERIC.UP kernel will reach rootmount on sun4v systems - ok martin@


# 1.367 26-Jul-2014 palle

Improved the NORMAL_GLOBALS macro in the sun4u case, so only the relevant bit (AG) in %pstate is affected - ok martin@


# 1.366 24-Jul-2014 palle

sun4v: add missing spill/fill handling for trap level 1 + cosmetic changes to comments for trap level 0 entries


# 1.365 19-Jul-2014 palle

sun4v: Introduce a NORMAL_GLOBALS macro - first used in sparc_interrupt - other relevant uses will be handled as the sun4v work is progressesing - ok martin@


# 1.364 16-Jul-2014 palle

sun4v: Introduce SET_MMU_CONTEXTID macro for setting the mmu context id on both sun4u and sun4v


# 1.363 13-Jul-2014 palle

sun4v: add interrupt handling to sun4v trap table


# 1.362 13-Jul-2014 palle

Bugfix: add missing cmp instruction to GET_MAXCWP macro


# 1.361 30-Jun-2014 palle

sun4v: The maximum number of register windows is a constant and thus not available via the %ver register (sun4u only). Introduce a macro GET_MAXCWP that handles this, so cpu_switchto() works properly on sun4v. Other relevant reference to %ver can be adapted to use GET_MAXCWP as the sun4v port progresses. OK martin@


# 1.360 31-May-2014 palle

sun4v: added missing dtsb miss handling for trap level 1 - with this update the kernel now reaches configure() on sun4v systems


# 1.359 30-May-2014 palle

Remove debugging code introduced by accident in locore.s revision 1.357


Revision tags: yamt-pagecache-base9 rmind-smpnet-nbase rmind-smpnet-base
# 1.358 05-May-2014 palle

sun4v: the trap base address should be assigned to %l1 so %tba is properly setup later in the code - now the kernel gets as far as printing the copyright disclaimer, kernel version and total and available memory before crashing


# 1.357 21-Apr-2014 palle

sun4v: Update comment: modified -> access


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.356 21-Feb-2014 palle

branches: 1.356.2;
sun4v: Rename TLB_ defines to SUN4U_TLB_ so entries created using TSB_DATA() are properly setup for sun4u and sun4v. Relocate the cputyp variable from autoconf.c to locore.s and make it const in param.h so optimized code can be generated. Parts from OpenBSD. Optimization suggested by nakayama@. OK martin@, mrg@, nakayama@


# 1.355 31-Jan-2014 tsutsui

defined(LKM) -> defined(MODULAR)


# 1.354 26-Jan-2014 palle

sun4v: Add handling of spill/fill and dtsb miss traps (with a XXX to be handled later)


# 1.353 07-Jan-2014 palle

sun4v: trap table setup - currently populated with dummy entries which will be properly implemented later - parts from OpenBSD - OK martin@


# 1.352 29-Dec-2013 nakayama

Make buildable w/o options SUN4V.


# 1.351 27-Dec-2013 palle

a) make the hunt through the cpus list more generic b) sun4v: ensure that the interrupt stack is mapped permanently and the TSB is setup properly - parts from OpenBSD. OK martin@


# 1.350 06-Dec-2013 nakayama

Increase an interrupt depth only in the case of hardware interrupts,
and remove the ci_idepth trick in softint_fastintr.

Fixes the following diagnostic panic reported in port-sparc64.

panic: kernel diagnostic assertion "!cpu_intr_p()" failed: file
"../../../../kern/subr_xcall.c", line 351


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 1.349 24-May-2013 nakayama

branches: 1.349.2;
Disable interrupts after calling data_access_error as with
data_access_fault.


# 1.348 28-Apr-2013 nakayama

Use macros in machine/asm.h instead of locally defined, and
introduce CASPTRA for casxa/casa.


Revision tags: agc-symver-base
# 1.347 23-Jan-2013 martin

Fix sparc64_ipi_ccall by adding proper trap setup.
Fixes xcall(9) problems, as exposed by pserialize(9). Noticed by
J. Hannken-Illjes, cause pointed out by Takeshi Nakayama.


# 1.346 23-Jan-2013 martin

Sligthly clean up the (by default unused) #ifdef TRAPS_USE_IG


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.345 10-Nov-2012 nakayama

Revise comment.


# 1.344 10-Nov-2012 nakayama

Use macro instead of magic number.


# 1.343 09-Nov-2012 nakayama

Make setstick() and getstick() to inline functions.


# 1.342 08-Nov-2012 macallan

use system tick timer instead of %tick on UltraSPARC-III-ish CPUs
review & fixes by Takeshi Nakayama


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.341 17-Mar-2012 mrg

branches: 1.341.2;
port the corrected ECC error handling code from freebsd. i noticed my U10
took one of these and then hang. it shouldn't hang, there's a 'sir' here that
doesn't seem to reset properly. oh well.

tested by simulated a trap via 'ta 0x10' and considering that the same, but
it hasn't been tested against a real ECC error yet.


Revision tags: jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base4
# 1.340 03-Mar-2012 nakayama

Fix the root cause of the hack "disable optimizations for uvm_bio.c
on 32 bit kernels".

gcc converts a division in the calculation of UBC_UMAP_ADDR macro
to multiplication (smul or combination of add/sll), and the
register of its result contains a garbage in upper 32 bits (the
upper 32 bits of smul/add/sll's result isn't zero cleared).

Then it passes to pseg_get{,_real} through pmap_extract without the
zero clear of upper 32 bits in the optimization case. So the
result of pseg_get and pmap_extact sometimes gets screwed up.


Revision tags: jmcneill-usbmp-base5 jmcneill-usbmp-base3
# 1.339 19-Feb-2012 rmind

Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.


Revision tags: jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.338 04-Sep-2011 nakayama

branches: 1.338.2; 1.338.6; 1.338.8;
ih_pil is an interrupt level, not an interrupt mask.


# 1.337 27-Jul-2011 nakayama

ivec is assigned to hardware, so count its event counter up in
interrupt_vector, not in softint, and do some optimization.


# 1.336 20-Jul-2011 macallan

add per ivec event counters


# 1.335 12-Jul-2011 mrg

rename sparc64 BLOCK_SIZE and BLOCK_ALIGN to have SPARC64_ prefixes.
for the assembler files, define the old names to the new names
since using the new names cause ugliness due to longer identifer
names, and reduces churn.

fixes build issues in dtv and vaguely makes <machine/psl.h> slightly
less name-space invasive.


# 1.334 18-Jun-2011 nakayama

Add fast softint(9) support for sparc64.

Reviewed on port-sparc64.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 1.333 12-May-2011 mrg

branches: 1.333.2;
first steps towards fujitsu SPARC64 support:

- SPARC64 systems have interrupts with upto 14 bits set, but we only look
at the first 11 bits. trim non IPI interrupts to 11 bits


Revision tags: uebayasi-xip-base7 bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 jym-xensuspend-nbase jym-xensuspend-base
# 1.332 20-Dec-2010 matt

branches: 1.332.2;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.


Revision tags: uebayasi-xip-base6 uebayasi-xip-base5 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 1.331 10-Jul-2010 nakayama

Clear the upper word explicitly before combining two 32-bit values to 64-bit
on 32-bit kernels.


# 1.330 23-May-2010 martin

Split copy related functions out of locore.s into copy.S, move functions
only needed on multiprocessors into mp_subr.S.


# 1.329 17-May-2010 martin

Simplify primary CPU startup slightly by using the fact that our cpuinfo's
curpcb pointer points to the uarea/pcb of lwp0 and by remembering the pointer
to this cpuinfo, thus avoiding a few CPUINFO_VA references.


Revision tags: uebayasi-xip-base1
# 1.328 20-Mar-2010 chs

fix copy{in,out}{,str}() to return the error returned by uvm_fault().
fixes PR 41813.


Revision tags: yamt-nfs-mp-base9
# 1.327 10-Mar-2010 mrg

branches: 1.327.2;
XXX: workaround we'd like to remove when pmap / uvm locking is cleaned up:

- rename pseg_get() and pseg_set() to pseg_get_real() and pseg_set_real().
- if USE_LOCKSAFE_PSEG_GETSET is defined, which it current is by default,
define pseg_[gs]et() in terms of functions that take a new pseg_lock
mutex at IPL_VM while calling into the real functions.

this seems to avoid the pseg_set() crashes we've seen:
1 - spare needed, when pseg_get() just worked for this pmap
2 - the 2rd ldxa via ASI_PHYS_CACHED in pseg_set() loads garbage
into %o4, and causes the 3rd ldxa to fault


# 1.326 08-Mar-2010 mrg

blast_dcache() SMP friendly:

- blast_dcache() becomes sp_blast_dcache(dcache_size, dcache_line_size)
- new smp_blast_dcache(sparc64_cpuset_t) that blasts the D$ on this cpuset
- sparc64_ipi_blast_dcache() to support the above
- in pmap_remove_all(), when freeing mmu contexts for this pmap, mark
the set of cpus to blast the d$ on as well and convert the
blast_dcache() call into smp_blast_dcache() on the cpus who ran this
pmap, or, sp_blast_dcache(dcache_size, dcache_line_size)
- convert the remaining blast_dcache() in machdep.c to sp_blast_dcache()
- in pmap_destroy()/pmap_remove_all() take the pmap_lock() always since
we assert it is held always.

with these changes, NFS builds on the U60 seem to be stable now, and
the USIII machines also can often complete a single build.sh run now,
diskful or diskless.


reviewed by mlelstv and partially by martin, tested by martin and myself,
with some ideas from chuq as well.


# 1.325 07-Mar-2010 mrg

need _ALIGN in locore.h as well, for DEBUG kernels.


# 1.324 07-Mar-2010 mrg

gas has supported SPARC ".empty" for a long while; get rid of an
ancient workaround.


# 1.323 06-Mar-2010 mrg

move the memcpy/memset implementations out into their own file, with the
block copy versions as well. move some of the definitions in locore.s
into a new locore.h.

locore.s is almost 2000 lines shorter with this change.


# 1.322 04-Mar-2010 mrg

- in _bus_dmamap_unload(), pmap_page_protect() and pmap_clear_reference()
switch the dcache_flush_page() into a dcache_flush_page_all()
- in both pmap_kremove()/pmap_remove(), remove the blast_dcache() call
and replace it with dcache_flush_page_all()
- in pmap_get_page() [used to allocate PTP's], always call pmap_zero_page(pa)
- flush the dcache of the dst page in pmap_{copy,zero}_page() by redirecting
throught a C function that calls the (renamed) asm. the old asm code had a
comment about needing to do this...
- add a couple of membar #Sync's that the USIII manual recommends


based on discussions with chuq@, skrll@ and martin@.


these help my SB2000 / SB2500 with both disk / nfs builds and other tasks,
sometimes lasting for several hours before failing or asserting.


# 1.321 24-Feb-2010 mrg

when handing back page table pages to UVM, flush them from the dcache
on all CPUs.

idea from skrll@, and makes my disk-based SB2000 stable.

tested on U60, SB2000 and SB2500.


# 1.320 24-Feb-2010 mrg

- re-introduce sp_tlb_flush_pte() and sp_tlb_flush_all() that call
the right USI/USIII version.
- define tlb_flush_pte() in terms of sp_tlb_flush_pte() for the
!MULTIPROCESSOR case

this centralises some CPU_IS_USIII_UP() tests.


# 1.319 22-Feb-2010 mrg

move {dump,print}_[id]tlb() into a separate file.


# 1.318 22-Feb-2010 mrg

- store the maximum [id]cache size / line size for each cpu

- remove patch_kernel() since it isn't necessary and has been patching
the wrong thing in general.

- implement USIII versions of blast_icache(), dcache_flush_page() and
cache_flush_phys(). use the newly recorded cache size/line sizes.

- in winfixsave, flush the D$ with the right size index and ops. this
kills one of the wrong tag->inval patches.

- for blast_dcache(), use the newly recorded dcache_size/line_size.

- for blast_icache(), use the newly recorded cache size/line sizes.
for the USIII verison, disable the I$ while writing to ASI_ICACHE_TAG.


these changes removed several hard coded cache sizes values, some very
wrong kernel patching, and seem to make the current failure modes for
USIII less common, but not gone.


# 1.317 15-Feb-2010 mrg

- don't flush 32-bit entries for 64-bit code, it does not seem to be
necessary. #define TLB_FLUSH_LOWVA to turn it back on.
- remove the #if 0'd code in sparc64_ipi_flush_pte_usiii(), i have
verified that it is not required.
- add a missing membar #Sync to sp_tlb_flush_pte_usiii().


# 1.316 15-Feb-2010 nakayama

Fix linker error of GENERIC32 kernel.


# 1.315 15-Feb-2010 mrg

use TLB_SIZE_SPITFIRE in a couple of places, and note that the
{print,dump}_[id]tlb() versions are currently spitfire specific.


# 1.314 15-Feb-2010 mrg

introduce a new patch_kernel() and call it from the end of bootstrap().
use it to patch up TLB flush instructions that don't match for USI/II
and later. we can also hopefully use this to make GENERIC.MP minimally
expensive on single CPU machines as well.

this is the last piece needed to get GENERIC/GENERIC.MP to boot on the
USIII* machines.

idea and some initial code from openbsd.


# 1.313 13-Feb-2010 mrg

remove KTR support. it's never been a working part of netbsd src tree.


# 1.312 09-Feb-2010 wiz

Fix typo in comment.


Revision tags: uebayasi-xip-base
# 1.311 06-Feb-2010 mrg

branches: 1.311.2;
- properly map the schizo interrupt registers, so we can use the normal
virtual mappings to access them.
- with the above fxied, kill SCHIZO_BUS_SPACE_BROKEN, and introduce
an options CHEETAH for now, that disables the SPITFIRE code in locore.
- merge schizo_init() into schizo_attach() and clean up the softc a bit.


with this we are only one more step away from GENERIC booting on USIII
machines.


# 1.310 02-Feb-2010 mrg

- split sp_tlb_flush_pte() and switchtoctx() into sp_tlb_flush_pte_us()/
sp_tlb_flush_pte_usiii() and switchtoctx_us()/switchtoctx_usiii() and
implement the latter while i'm here. it works ... sometimes i think,
but also sometimes panics/hangs.
- fix a comment in sparc64_ipi_flush_pte_usiii()


# 1.309 02-Feb-2010 mrg

for now, reduce a few #ifdef SPITFIRE cases by introducing a new
ASI_DCACHE_TAG_OR_INV that is either ASI_DCACHE_{TAG,_INVALIDATE}.

increase the common code in cache_flush_phys().


# 1.308 01-Feb-2010 mrg

- sp_tlb_flush_all() becomes sp_tlb_flush_all_us() and sp_tlb_flush_all_usiii()
- sparc64_ipi_flush_pte() becomes sparc64_ipi_flush_pte_us() and
sparc64_ipi_flush_pte_usiii()
- add some commented out code to disable interrupts and raise the traplevel
in sparc64_ipi_flush_pte_usiii()
- cache_flush_phys() was missing a little of code in the cheetah case


# 1.307 01-Feb-2010 mrg

for USIII, use the new "tlb demap all" operation in sp_tlb_flush_all()


# 1.306 01-Feb-2010 mrg

remove unused icache_flush_page() implementation.


# 1.305 23-Jan-2010 mrg

remove the final uses of DATA_START.

now we can remove the 16KB space reserved at the start of the data segment,
and i now understand why i wrote this now removed comment 3.5 years ago:
"this shouldn't be needed... but kernel usually hangs without it"


# 1.304 23-Jan-2010 mrg

remove most of the code that writes debugging info DATA_START + offset.


# 1.303 23-Jan-2010 mrg

remove CHKPT() macro and uses. it's likely wrong in SMP land and probably should
be replaced with KTR-style uses if necessary.


# 1.302 23-Jan-2010 mrg

fix a comment.


Revision tags: matt-premerge-20091211
# 1.301 10-Dec-2009 rmind

Rename L_ADDR to L_PCB and amend some comments accordingly.


# 1.300 05-Dec-2009 mrg

- adjust the PA mask to the 43 bits supported by USIII.
- rework the spitfire/cheetah cache_flush_phys() to avoid several #ifdefs
- add a membar #Sync after sparc64_ipi_drop_fpstate (probably unnecessary)


# 1.299 30-Nov-2009 nakayama

sp_tlb_flush_pte for cheetah:
- restore interrupts properly in case of %tl > 0.


# 1.298 30-Nov-2009 mrg

stablize UP USIII support by blocking interrupts around sp_tlb_flush_pte()
i was seeing stack corruption while taking an interrupt in this function.

get USIII SMP mostly working by implementing the cheetah version of
sparc64_ipi_flush_pte().


SMP support is still not entirely stable. i can reproducably get a:

panic: fpusave_lwp ipi didn't

while running build.sh, when an awk process is exiting. other simple
heavy work loads do not crash for me right now.


# 1.297 30-Nov-2009 mrg

delete some no longer used code:
- smp_tlb_flush_ctx()
- smp_tlb_flush_all()
- sparc64_ipi_flush_ctx()
- sparc64_ipi_flush_all()
- sp_tlb_flush_ctx()


# 1.296 29-Nov-2009 nakayama

- calculate end PA correctly.
- wrap more spitfire specific (flushing I$) code.
- fix inverted #if condition for flushing I$ (and restore ASI_ICACHE_TAG).


# 1.295 28-Nov-2009 mrg

implement enough code to get SB2000/SB2500 booting to multiuser. does
not last long if you use it, but an idle machine has stayed up 10 hours.

- for the !SPITFIRE case, use ASI_DCACHE_INVALIDATE instead of
ASI_DCACHE_TAG when clearing tlb entries. from openbsd.

- convert some comment "! Not yet" into "WRITEME", so that attempting
to build a USIII MULTIPROCESSOR kernel fails to build until the code
is written.

- add some more WRITEME's for the above.

- implement a !SPITFIRE version of sp_tlb_flush_all(). since there are
no spare regs, for now just always increase %tl around this call. (we
could maybe store a token in %o3 along with the saved %pstate info.)


# 1.294 26-Nov-2009 matt

Kill proc0paddr. Use lwp0.l_addr instead.


# 1.293 25-Nov-2009 mrg

s/L_ADDR/L_PCB/, requested by rmind.


# 1.292 17-Oct-2009 nakayama

Wrap unused code with #if 0 which is called from #if 0'ed code.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5
# 1.291 30-May-2009 martin

cpu_setfunc() can not use lwp_trampoline, as that has additional lwp startup
semantics. Use a simpler setfunc_trampoline instead.


# 1.290 18-May-2009 nakayama

Remove random() from locore.s since it is in libkern.


# 1.289 16-May-2009 nakayama

Remove clear %tick in locore.s since it is cleared at cpu_initclocks() in
clock.c.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 nick-hppapmap-base mjf-devfs2-base
# 1.288 15-Dec-2008 mrg

restore some old "intrdebug" code, but leave it under NOT_DEBUG. most
of it works, but one that prints func/arg for each handler is not very
stable...

for now, while schizo bus space pointer accesses aren't working, add
a SCHIZO_BUS_SPACE_BROKEN option so you can build a kernel with schizo.

with this, and the prior schizo interrupt fix, you can now fail to run
/sbin/init!


Revision tags: haad-dm-base2 haad-nbase2 haad-dm-base
# 1.287 09-Dec-2008 martin

Get rid of get_maxctx() - it doesn't work on newer cpus and we will have
to find a better way for (some) sun4v machines - all sun4u use 13 bit
contexts anyway.


Revision tags: netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 ad-audiomp2-base netbsd-5-base
# 1.286 30-Oct-2008 nakayama

branches: 1.286.2; 1.286.6;
Wrap more code specific to USE_BLOCK_STORE_LOAD.


Revision tags: matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4
# 1.285 05-Oct-2008 nakayama

branches: 1.285.2;
- in flushing cache, use 32 as increment/decrement value to match the
cache line size.
- remove useless restore of %asi.
- remove nop in delay slot if we can.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 1.284 10-Jul-2008 nakayama

Use proper CCR.


# 1.283 10-Jul-2008 nakayama

sparc64_ipi_save_fpstate:
- use primary MMU context for consistency with other trap/interrupt handlers.

sparc64_ipi_save_fpstate, savefpstate:
- avoid storing fp registers as we can.

sparc64_ipi_save_fpstate, savefpstate, loadfpstate:
- remove unaligned case since buffers allocated with pool_cache are ensured
64-byte aligned.

Ok by martin@.


# 1.282 02-Jul-2008 nakayama

branches: 1.282.2;
UltraSPARCs don't have floating point queue, and reading %fq regsiter
will cause illegal instruction trap. So remove the code handling them.


# 1.281 29-Jun-2008 nakayama

Wrap IPI calls with #ifdef MULTIPROCESSOR.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.280 14-Jun-2008 nakayama

Close unterminated comment.
Fix unexpected behavior in case of loadfpstate from unaligned buffer.


Revision tags: yamt-pf42-base3
# 1.279 31-May-2008 nakayama

branches: 1.279.2;
openfirmware_exit:
- disable interrupts with %pstate.
- prepare 64-bit stack and enable 64-bit addresses for 32-bit SMP kernels.


Revision tags: hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 yamt-nfs-mp-base yamt-pf42-base
# 1.278 16-Apr-2008 nakayama

branches: 1.278.2; 1.278.4; 1.278.6;
Disable TRAPSTATS which was accidentally enabled when yamt-idlelwp branch
was merged.

Ok by martin@.


# 1.277 14-Apr-2008 nakayama

Remove sparc64_ipi_sync_tick.

Since we can use counter-timer as timecounter instead of %tick on SMP kernel,
it is not necessary to sync all CPUs %tick registers.


# 1.276 14-Apr-2008 nakayama

Add workaround for BB_ERRATA_1 on writing to TICK_CMPR register in
next_tick(). If writing to TICK_CMPR fails, we lose hardclock interrupt
on secondary CPUs.

About BB_ERRATA_1 from comment in OpenSolaris:

/*
* Writes to the TICK_COMPARE register sometimes fail on blackbird modules.
* The failure occurs only when the following instruction decodes to wr or
* wrpr. The workaround is to immediately follow writes to TICK_COMPARE
* with a read, thus stalling the pipe and keeping following instructions
* from causing data corruption. Aligning to a quadword will ensure these
* two instructions are not split due to i$ misses.
*/


# 1.275 28-Mar-2008 nakayama

Don't read fplwp content in delay slot for considering the case fplwp was
modifiled.

Reported by Chris Ross on port-sparc64.


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.274 20-Mar-2008 nakayama

- remove disabling interrupt in IPI.
- unused VA bits in MMU demap is 13 bits, not 12 bits.


# 1.273 18-Mar-2008 nakayama

Fix a race when increment an interrupt level event counter.


# 1.272 17-Mar-2008 nakayama

Fix a race condition in IPI handlers of save/drop fpstate, from OpenBSD.
Reported and tested by martin@.


# 1.271 17-Mar-2008 nakayama

Make schedintr interrupt handler per-CPU.
While there rename tickintr interrupt handler and share initialization
code with schedintr.


# 1.270 14-Mar-2008 nakayama

Improve IPI handling:
- make IPI takes two arguments.
- add IPI event counters per-CPU.
- implement IPI functions which were missing or broken.
- insert DELAY while halting primary CPU in IPI handler.


# 1.269 02-Mar-2008 nakayama

- make interrupt pending list per-CPU.
- make tickintr() MP-safe.
- remove unused port-sparc derived interrupt code.

Ok by martin@.


# 1.268 02-Mar-2008 nakayama

Don't get IPI handler argument (from bogus address), and ack IRQ twice.


# 1.267 28-Feb-2008 martin

Make TSBs and MMU contexts per-cpu.


Revision tags: nick-net80211-sync-base mjf-devfs-base hpcarm-cleanup-base
# 1.266 26-Jan-2008 nakayama

branches: 1.266.2; 1.266.6;
Fix for 32-bit kernels.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.265 15-Jan-2008 skrll

Store a sensbile PCB_PC value in snapshot - the return point.

This helps gdb somewhat.

OK'd by martin.


# 1.264 14-Jan-2008 martin

Fix register name typo/copy&pasto - %g6 is not %o6/%sp.
From OpenBSD.


Revision tags: matt-armv6-base
# 1.263 06-Jan-2008 martin

Load the next cpu_info pointer with LDPTR instead of ld.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2
# 1.262 09-Dec-2007 martin

branches: 1.262.2;
Provide cpu_intr_p(), at least for non-MULTIPROCESSOR kernels.
Based on suggestions by Andrew Doran.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.261 22-Oct-2007 martin

branches: 1.261.2; 1.261.4; 1.261.6;
Remove an unused .globl declaration


Revision tags: yamt-x86pmap-base4
# 1.260 17-Oct-2007 garbled

Merge the ppcoea-renovation branch to HEAD.

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

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

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base ppcoea-renovation-base vmlocking-base
# 1.259 09-Sep-2007 martin

branches: 1.259.4;
Make cpufrequency and friends per cpu values.
Prepare a hz tick interrupt on secondary CPUs via %tick, but do not
enable it yet, as it breaks ddb.


# 1.258 09-Sep-2007 martin

Do not ACK IPIs before we finished loading all arguments.


# 1.257 06-Sep-2007 martin

Remove the (now unused) second 64k page mapped per CPU.
From matthew green, with small changes by me. All bugs are mine.


# 1.256 25-Aug-2007 martin

branches: 1.256.2;
Remove INITSTACK completely - at the time we used to switch to it, we
already have access to all of lwp0 and it's uarea - so we can switch
to the correct lwp0 stack easily before calling main.


# 1.255 25-Aug-2007 martin

When exiting to OF, use the interrupt stack instead of INITSTACK


# 1.254 25-Aug-2007 martin

Rework cpu_mp_startup slightly:
- temporarily use the cpu's interrupt stack untill we are ready
to access non-OF-based mappings, then directly switch to the cpu's
idlelwp's uarea stack
- disable interrupts untill we are ready to call C code


# 1.253 13-Aug-2007 macallan

remove two restore without matching save


Revision tags: nick-csl-alignment-base matt-mips64-base mjf-ufs-trans-base
# 1.252 06-Jul-2007 martin

branches: 1.252.4; 1.252.8;
A few nits for 32bit SMP kernels, noticed by mrg.
While there, simplify the fpstate IPIs a bit.


# 1.251 05-Jul-2007 martin

sparc64_ipi_save_fpstate is not a leaf function - create a full grown
stack frame.


# 1.250 28-May-2007 mrg

clean up cpu_switchto() a little - no need to flushw or membar
excessively. optimise an rdpr. tested by tnn.


# 1.249 23-May-2007 martin

Fix a stupid bug in the save_fpstate ipi, which caused overwriting of
struct lwp of the lwp owning the fpu. Fix clearing the fplwp - %o0 will
not survive the call to savefpstate - duh!


# 1.248 20-May-2007 martin

Simplify tf_tstate setting when leaving for userland initially - I seem
to have confused the if with the else case of the previous C code.
Funny that it worked at all.


# 1.247 20-May-2007 martin

cpu_switchto() has to return it's first arg, always. This differs from
my reading of the documentation, but helps in the real world and seems
to be what other ports do.


# 1.246 20-May-2007 martin

Remove special case handling for userland lwps from cpu_lwp_fork, instead
do it in lwp_trampoline when we first return to userland.


# 1.245 19-May-2007 martin

cpu_idle is a leaf function, so we better "return from leaf".
Use return value from cpu_switchto for previous lwp in lwp_trampoline.
Also shamelessly steal a comment from uwe written for sparc that explains
all this.
Thanks to tnn, mrg, and uwe for helping to debug this.


# 1.244 17-May-2007 yamt

merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base ad-audiomp-base
# 1.243 22-Feb-2007 martin

branches: 1.243.4; 1.243.6; 1.243.12;
uvm.page_idle_zero now is a bool, not a 32bit value any more.


# 1.242 21-Feb-2007 mrg

shave 9 insns off the tsb setup in cpu_initialize & cpu_mp_startup.


# 1.241 21-Feb-2007 martin

Get rid of unused (thus always zero) "curlwp" variable hidden in assembler
code (C code always uses a cpuinfo based macro).


# 1.240 18-Feb-2007 martin

Make use of another call delay slot, pointed out by uwe.


# 1.239 18-Feb-2007 martin

Make use of a call delay slot and avoid a bogus EMPTY.
Spotted by Juergen Hannken-Illjes, with input from Andrew Doran and
Valeriy E. Ushakov.


# 1.238 18-Feb-2007 martin

Whitespace cosmetics


# 1.237 18-Feb-2007 martin

Backout previous: EMPTY was misused


# 1.236 18-Feb-2007 martin

Make EMPTY expand to nop with gas, as it is used to mark empty branch
delay slots.


# 1.235 15-Feb-2007 martin

branches: 1.235.2;
Fix obvious copy&pasto in SCHED_DEBUG register usage.


Revision tags: post-newlock2-merge
# 1.234 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.233 25-Dec-2006 wiz

Spell "relevant" correctly. From Zafer Aydogan.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.232 25-Oct-2006 mrg

branches: 1.232.2; 1.232.4;
- note that __idle_u should go away but doing so breaks things
- fix several comments to reality
- clean up the #ifdef NO_VCACHE code slightly
- use call instead of set/jmpl
- remove a couple of unnecessary stores to curlwp


Revision tags: yamt-splraiseipl-base2
# 1.231 18-Oct-2006 rjs

Clean up some comments. Cosmetic change to use correct structure
offset names.

Optimize out two instructions from sparc64_ipi_save_fpstate and
sparc64_ipi_drop_fpstate.


# 1.230 17-Oct-2006 mrg

allocate 128KB (as opposed to 64KB) per-cpu, and place the interrupt
stack, cpu_info structure, panicstack, idle uarea and normal kernel
stack in here. the idle uarea and kernel stack are in the 2nd 64KB
page. the interrupt stack and cpu_info structure are as the same
place in the 1st 64KB page, and the panicstack grows down from the
top of this page. update comments in param.h to suit (XXX: a lot
of these constants should move to a header file that will not pollute
the name space so much.) map these pages identically between
cpu_initialise() and cpu_mp_startup(), and deal with the two 64KB
pages in pmap_extract(). keep an unmapped 64KB page between them.

don't initialise the unused "ci_eintstack" member of the cpu_info
structure

use constants to initialise many addresses in the cpu_info structure,
consolidating these assignments from cpu0 and cpu>0

delete u0/estack0/panicstack from locore.s

clean up some wrong comments in locore.s

fix a 32bit-only bug in cpu_mp_startup().

delete 'u0' entirely.


this fixes recent random lossage seen on port-sparc64: processes
stuck in RUN state, data faults, and hangs.


# 1.229 04-Oct-2006 mrg

use call instead of set/jmpl. add an entry point for idle that expects
sched_lock to be unlocked, and use this for non-boot cpu's. complete a
comment describing how registers in idle_switch are expected to be set.


# 1.228 03-Oct-2006 mrg

use the same SAVE_LOCALS_INS definition for 32 bit and 64 bit kernels.
refactor TRAP_SETUP() a little between these two versions to be more alike.


# 1.227 03-Oct-2006 mrg

use the correct size/type for MP variables (pointers and longs).

a 32 bit MULTIPROCESSOR kernel now builds (and crashes quickly.)


# 1.226 03-Oct-2006 mrg

in the 64bit version of SAVE_LOCAL_INS, s/BIAS/STKB/ to allow future
sharing of the 32 and 64 bit versions of the {TRAP,INTR}_SETUP macros.


# 1.225 19-Sep-2006 mrg

- remove some way old FP setup/teardown code
- put the block memcpy/memset inside #ifdef USE_BLOCK_STORE_LOAD which
is (now) defined.

no functional change, same .o is generated.


# 1.224 19-Sep-2006 mrg

re-order the changes in rev 1.217 to give registers a little bit of
time to settle between usage, like it was before hand.


# 1.223 19-Sep-2006 mrg

- remove a wrong comment.
- add a new entry point for idle called idle_switch that is called by
cpu_switch() in the MP case when sched_whichqs is zero, properly
setting up the idle stack. from petrov@ via martin@.


# 1.222 19-Sep-2006 mrg

rework interrupt_vector() slightly:
- for the IPI case, avoid loading the address of intrlev into %g3
- remove some NOT_DEBUG code
- load the interrupt argument #2 in the delay slot

this removes 2 nops during interrupt processing for the normal
case, and an additional 2 ALU instructions for IPIs


# 1.221 18-Sep-2006 mrg

- sparc64_ipi_halt(): we shouldn't return from sparc64_ipi_halt_thiscpu()
so replace a branch with a 'sir'
- in #if 0 code, in sparc64_ipi_flush_pte() and sparc64_ipi_flush_ctx()
save/restore the out registers that the sp_tlb_flush_xxx() versions
around calling them
- in sp_tlb_flush_pte() and sp_tlb_flush_ctx(), replace global register
usage with out registers so that we don't clobber the (alternate)
global registers when these are called from IPI context


# 1.220 18-Sep-2006 mrg

- remove an extra 'sir' that followed one in a macro
- add some named labels to some spill/fill handlers
- remove 2 unused strings


Revision tags: yamt-splraiseipl-base
# 1.219 18-Sep-2006 martin

branches: 1.219.2;
Lazy FPU handling for the MULTIPROCESSOR case


# 1.218 16-Sep-2006 nakayama

From OpenBSD:
- reload %fprs for checking it again.
- use symbolic names for checking in %fprs.

revision 1.51
date: 2005/07/18 14:50:11; author: deraadt; state: Exp; lines: +2 -1
cache a copy of the fprs so we know what fp restore we should do after

revision 1.50
date: 2005/07/14 01:46:13; author: deraadt; state: Exp; lines: +4 -4
use symbolic names for checking in %fprs, as above


# 1.217 16-Sep-2006 nakayama

Fix a couple of %y register save/restore errors, inspired from OpenBSD.

revision 1.44
date: 2004/04/23 04:18:17; author: marc; state: Exp; lines: +5 -4

fix a couple of %y register save/restore errors
1) don't save %y in a register that is later used before restoring %y
2) always restore %y after calling a signal handler
tested by drahn@, OK pval


# 1.216 15-Sep-2006 martin

Do not bother to save fpu state when we are about to get rid of it.


Revision tags: yamt-pdpolicy-base9
# 1.215 13-Sep-2006 mrg

SMP cleanup. provide support for multiple CPUs in DDB. (SMP itself
is still not working.)

cpu.h:
- add a pointer for DDB regs in SMP environment to struct cpu_info
- remove the #defines for mp_pause_cpus() and mp_resume_cpus()
cpuset.h:
- remove CPUSET_ALL() and rename CPUSET_ALL_BUT() to CPUSET_EXCEPT()
from petrov.
db_machdep.h:
- rename the members of db_regs_t to be the same as sparc
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- redo DDB_REGS to no longer be a pointer to a fixed data structure
but to one allocated per-cpu when ddb is entered
- move a bunch of prototypes in here
intr.h:
- remove SPARC64_IPI_* macros, no longer used
db_interface.c:
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- make "nil" a 64 bit entity
- change the ddb register access methods to work in multiprocessor
environment, it is now very much like sparc does it
- in kdb_trap() avoid accessing ddb_regp when it is NULL
- update several messages to include the cpu number
- unpause other cpus much later when resuming from ddb
- rename db_lock() to db_lock_cmd(), as the sparc-like code has
db_lock as a simple lock
- remove "mach cpus" command, and replace it with "mach cpu" (which
does the same) and also implement "mach cpu N" to switch to
another cpus saved trapframe
db_trace.c:
- update for the ddb_regs -> ddb_regp change
genassym.cf:
- add TF_KSTACK as offsetof(struct trapframe64, tf_kstack)
ipifuncs.c:
- overhaul extensively
- remove all normal interrupt handlers as IPI's, we now handle
them all specially in locore.s:interrupt_vector
- add a simplelock around all ipi functions - it's not safe for
multiple cpus to be sending IPI's to each other right now
- rename sparc64_ipi_pause() to sparc64_ipi_pause_thiscpu() and,
if DDB is configured, enable it to save the passed-in trapframe
to a db_regs_t for this cpu's saved DDB registers.
- remove the "ipimask" system (SPARC64_IPI_* macros) and instead
pass functions directly
- in sparc64_send_ipi() always set the interrupt arguments to 0,
the address and argument of the to be called function. (the
argument right now is the address of ipi_tlb_args variable, and
part of the reason why only one CPU can send IPI's at a time.)
don't wait forever for an IPI to complete. some of this is
from petrov.
- rename sparc64_ipi_{halt,pause,resume}_cpus() to
mp_{halt,pause,resume}_cpus()
- new function mp_cpu_is_paused() used to avoid access missing
saved DDB registers
- actually broadcast the flush in smp_tlb_flush_pte(),
smp_tlb_flush_ctx() and smp_tlb_flush_all(). the other end may
not do anything yet in the pte/ctx cases yet...
kgdb_machdep.c:
- rework for changed member names in db_regs_t.
locore.s:
- shave an instruction from syscall_setup() (set + ld -> sethi + ld)
- remove some old dead debug code
- add new sparc64_ipi_halt IPI entry point, it just calls the C
vector to shutdown.
- add new sparc64_ipi_pause IPI entry point, which just traps into
the debugger using the normal breakpoint trap. these cpus usually
lose the race in db_interface.c:db_suspend_others() and end up
calling the C vector sparc64_ipi_pause_thiscpu().
- add #if 0'ed code to sparc64_ipi_flush_{pte,ctx}() IPI entry
points to call the sp_ version of these functions.
- in rft_kernel (return from trap, kernel), check to see if the
%tpc is at the sparc64_ipi_pause_trap_point and if so, call
"done" not "retry"
- rework cpu_switch slightly: save the passed-in lwp instead of
using the one in curlwp
- in cpu_loadproc(), save the new lwp not the old lwp, to curlwp
- in cpu_initialize(), set %tl to zero as well. from petrov.
- in cpu_exit(), fix a load register confusion. from petrov.
- change some "set" in delay branch to "mov".
machdep.c:
- deal with function renames
pmap.c:
- remove a spurious space
trap.c:
- remove unused "trapstats" variable
- add cpu number to a couple of messages


# 1.214 09-Sep-2006 mrg

significant clean up effort, largely from petrov@ via martin@.

- fix a bunch of comments for proc->lwp
- remove old TRAPTRACE, NOT_DEBUG, etc. code that has bit-rotted
- put some older DEBUG code under NOT_DEBUG
- add a bunch of new debugging/tracing code ("KTR") that depends on
other changes not yet present.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base yamt-pdpolicy-base5 chap-midi-base simonb-timecounters-base rpaulo-netinet-merge-pcb-base
# 1.213 14-May-2006 elad

branches: 1.213.6; 1.213.8;
integrate kauth.


# 1.212 12-May-2006 skrll

Fix some comments.


Revision tags: elad-kernelauth-base
# 1.211 09-May-2006 rjs

Load CPCB in cpu_mp_startup.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.210 11-Feb-2006 cdi

branches: 1.210.2; 1.210.4; 1.210.6;
ANSIfication: u_intN_t -> uintN_t, use ANSI function declarations/definitions
instead of K&R ones.


# 1.209 27-Jan-2006 cdi

branches: 1.209.2; 1.209.4;
Alter sparc64 bootstrap, catch up to ofwboot v1.9:

- Accept bootinfo structure passed down from ofwboot v1.9
- Drop kernel re-mapping code
- Use permanent 4MB mappings provided by the loader instead
- Change kernel entry address to point directly at the code instead of pointing
at the trap table's first slot. This allows the bootloader to detect
those kernels which are aware of the new boot scheme
- Due to the changes in kernel mapping code, alter secondary CPU bootstrap
code to use trampoline just like FreeBSD does (some FreeBSD code is used
here as well)


# 1.208 12-Jan-2006 cdi

Fix a typo: %g0 should be used instead of %o0 when initializing FPU in dostart:
and cpu_mp_startup:, %o0 is not even initialized at this point.


# 1.207 11-Dec-2005 christos

branches: 1.207.2;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 1.206 10-Jul-2005 christos

Re-factor syscall, and make it use syscall_{plain,fancy}.


# 1.205 31-May-2005 chs

branches: 1.205.2;
remove vestigal {,e}intr{names,cnt} symbols now that vmstat doesn't need them.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.204 12-Feb-2005 chs

branches: 1.204.4; 1.204.6; 1.204.8;
in sparc_interrupt(), wait to enable interrupts until just before calling
the handler and disable them again right after the handler returns.
we don't want another hardware interrupt coming in while we're mucking
with the list pointers. also, clear the intrhand's ih_pending pointer
before calling the handler rather than after, so that if another interrupt
comes in while the handler is running, we can put the intrhand back on
the list so it will be called again.

in send_softint(), disable interrupts via %pstate instead of %pil, so that
hardware interrupts at higher levels are blocked while we manipulate the
intrpending list. also, if the intrhand already has ih_pending set,
don't bother poking the SET_SOFTINT register again, since being on the list
implies that there is already a softint pending in the hardware.

these appear to fix PR 21750 (the "sleep forever" problem).

while I'm here, remove more vestiges of the !INTRLIST softint stuff
(code and comments). and in sparc64_ipi_flush_all(), interrupts are
already disabled so we don't need to fiddle with %pstate.


Revision tags: yamt-km-base2
# 1.203 30-Jan-2005 martin

Remove the no long usefull variants selected by undefining INTRLIST and
INTR_INTERLOCK to improve readability. Same object code generated as before.


Revision tags: yamt-km-base
# 1.202 16-Jan-2005 chs

branches: 1.202.2;
use ENTRY_NOPROFILE() for various entry points,
stack traces work better that way.


Revision tags: kent-audio1-beforemerge kent-audio1-base
# 1.201 03-Dec-2004 chs

branches: 1.201.4;
remove cache_flush_virt() and PADDRT, they're no longer used.
allocate a stack frame for blast_dcache() when profiling so it shows up.
in dcache_flush_page(), use a stride of 32 instead of 16 to match the
cache line size. correct various comments.


# 1.200 08-Nov-2004 petrov

Don't compile sparc64_ipi functions when UP.


# 1.199 25-Oct-2004 martin

No need to clear %o1 when returning a 64 bit integer from pseg_get if we
are compiling for a 64 bit kernel.


# 1.198 24-Jul-2004 nakayama

Change interrupt pending list end value to -1, to avoid linking an
interrupt handler twice.

It may fix "sleep forever" bug.


# 1.197 09-Apr-2004 petrov

Clean-up unused defines and variables.


Revision tags: netbsd-2-0-base
# 1.196 26-Mar-2004 petrov

branches: 1.196.2;
Use want_resched from cpu_info area.


# 1.195 23-Mar-2004 martin

Replace intrcnts by evcnts. XXX - needs slight tweaking for MULTIPROCESSOR.


# 1.194 14-Mar-2004 chs

checkpoint of MP work from dennis and myself. includes cross-processor
interrupt framework, a sledgehammer TLB invalidation and misc MP fixes.
doesn't work at all yet.


# 1.193 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.192 19-Jan-2004 martin

Rename switchexit to cpu_exit and g/c the old C implementation of cpu_exit.


# 1.191 18-Jan-2004 martin

Support RAS for 32bit kernels too.


# 1.190 16-Jan-2004 martin

In proc_trampoline don't bother to clear condition codes in the trap
frame, since we no longer rely on this.
While there fix a few comments.


# 1.189 08-Jan-2004 martin

Minor cleanup


# 1.188 06-Jan-2004 martin

Implement restartable atomic sequences (RAS) for sparc64.


# 1.187 06-Jan-2004 petrov

Spinup secondary cpus. Based on codes sent to me by Dennis Chernoivanov
and Chuck Silvers.


# 1.186 04-Jan-2004 jdolecek

update to recent changes - exit2() doesn't exist anymore and the
exit path always calls lwp_exit2()
pointed out Martin Husemann


# 1.185 02-Dec-2003 martin

Minor cleanup: remove unused code, sync a comment with current reality.


# 1.184 25-Nov-2003 cdi

Use per-cpu pcb, curlwp and fplwp rather than global ones. This brings
GENERIC.MP configuration to a usable state.

Approved by petrov@.


# 1.183 24-Nov-2003 cdi

Call 'proc_trampoline_mp' from 'proc_trampoline' in a multiprocessor
configuration. Fix process locking. Approved by petrov@.


# 1.182 20-Nov-2003 petrov

Remove nwindows calculation, it's not used. Set l_cpu in cpu_switch.


# 1.181 09-Nov-2003 martin

Get rid of bcopy/bzero.


# 1.180 26-Oct-2003 christos

Initial siginfo support for sparc64 (untested). COMPAT_16 sigcontext signal
delivery tested.


# 1.179 24-Aug-2003 chs

add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default. the changes
fall into two basic catagories:

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

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

originally from openbsd, adapted for netbsd by me.


# 1.178 08-Jul-2003 cdi

traceit: don't use %g7 as it is to become curcpu() register. Add comments.


# 1.177 18-May-2003 martin

branches: 1.177.2;
Make kernels with options KGDB at least compile.
Still needs some work to make it working.


# 1.176 29-Apr-2003 nakayama

Use BLOCK_ALIGN rather than BLOCK_SIZE for aligning a pointer.


# 1.175 27-Apr-2003 ragge

Preserve the symbol table in the LKM || KSYMS cases also.


# 1.174 04-Apr-2003 petrov

use branch slot in pmap_copy_page.


# 1.173 24-Mar-2003 nakayama

Divide `set' instruction in delay slot (from OpenBSD change to rev 1.30).


# 1.172 10-Feb-2003 martin

Remove some #if 0 code and a few XXX marked membars w/o proper
justification for their existence.


# 1.171 09-Feb-2003 martin

Remove left over pieces from reusing the signal trampoline for upcalls.
This should fix signal delivery for 32bit kernels.


# 1.170 05-Feb-2003 nakayama

Switch to use cycle counter (%tick) based microtime().

This is derived from alpha/microtime.c and i386/tsc_microtime.c,
and will share with both ports.

This should fix PR port-sparc64/18452.
(approved by martin)


# 1.169 04-Feb-2003 martin

Fix return value of pseg_set, which I accidently broke in rev. 1.164.

Fix register names in comment and shave off another register (hint
from uwe).


# 1.168 01-Feb-2003 martin

Rearrange register usage in pseg_set a bit and shave off %g4.


# 1.167 01-Feb-2003 martin

Remove a few #ifdef _LP64 by using STPTR/LDPTR macros.
Thanks to Matthew Green for the pointer.


# 1.166 31-Jan-2003 martin

Apply leaf procedure optimization to pseg_set (again).


# 1.165 31-Jan-2003 martin

Make the pmap count resident/wired mappings on the fly instead of
walking the page tables whenever this information is needed.

Add an option PMAP_COUNT_DEBUG to assert the new counts and the
page table walk agree.

The old solution had very bad performance impact, for example
by the high CPU load when running top(1).

Thanks to Simon Burge for pointing at the cause of the problem and
to Valeriy E. Ushakov for optimizing my simple minded assembler code.


# 1.164 27-Jan-2003 martin

Remove unused function pseg_find (which looked quite similar to
pseg_get anyway).


# 1.163 18-Jan-2003 thorpej

Merge the nathanw_sa branch.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.162 16-Jan-2003 petrov

Move dump_dtlb back under DDB.


# 1.161 15-Jan-2003 chs

fix two bugs in my last pmap rework:
- in tlb_flush_all(), don't skip TLB entries with the high bit on,
I was confused about which MMU register it was using. it's also fine
to use the last hardware context.
- in pmap_create(), don't allocate a hardware context for the new pmap.
it's unnecessary, and when this would cause us to recycle all the contexts,
it would result in the current process's context being set to 0
(ie. the kernel's context). the current process could then return to
userspace without going through the context-switch code (and thus without
having a hardware context reallocated). this would lead to user mappings
being entered in the kernel's context later, causing all sorts of trouble.
add some assertions to catch this kind of thing.


Revision tags: fvdl_fs64_base
# 1.160 25-Dec-2002 petrov

new function dump_itlb.


Revision tags: gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.159 22-Sep-2002 chs

many improvements:
- use struct vm_page_md for attaching pv entries to struct vm_page
- change pseg_set()'s return value to indicate whether the spare page
was used as an L2 or L3 PTP.
- use a pool for pv entries instead of malloc().
- put PTPs on a list attached to the pmap so we can free them
more efficiently (by just walking the list) in pmap_destroy().
- use the new pmap_remove_all() interface to avoid flushing the cache and TLB
for each pmap_remove() that's done as we are tearing down an address space.
- in pmap_enter(), handle replacing an existing mapping more efficiently
than just calling pmap_remove() on it. also, skip flushing the
TSB and TLB if there was no previous mapping, since there can't be
anything we need to flush. also, preload the TSB if we're pre-setting
the mod/ref bits.
- allocate hardware contexts like the MIPS pmap:
allocate them all sequentially without reuse, then once we run out
just invalidate all user TLB entries and flush the entire L1 dcache.
- fix pmap_extract() for the case where the va is not page-aligned and
nothing is mapped there.
- fix calculation of TSB size. it was comparing physmem (which is
in units of pages) to constants that only make sense if they are
in units of bytes.
- avoid sleeping in pmap_enter(), instead let the caller do it.
- use pmap_kenter_pa() instead of pmap_enter() where appropriate.
- remove code to handle impossible cases in various functions.
- tweak asm code to pipeline a little better.
- remove many unnecessary spls and membars.
- lots of code cleanup.
- no doubt other stuff that I've forgotten.

the result of all this is that a fork+exit microbenchmark is 34% faster
and a fork+exec+exit microbenchmark is 28% faster.


Revision tags: gehenna-devsw-base
# 1.158 18-Jul-2002 wiz

Spell 'should' correctly.


# 1.157 07-Jun-2002 eeh

Shave 10% off the time needed to flush the D$ through a bit of instruction
reordering.


# 1.156 05-Jun-2002 eeh

Handle improperly aligned stack pointers more cleanly.


# 1.155 04-Jun-2002 eeh

Fix the fork trampoline to properly use the supplied tstate.


# 1.154 31-May-2002 thorpej

Make this work with an ISO C preprocessor.


Revision tags: netbsd-1-6-base
# 1.153 14-May-2002 eeh

branches: 1.153.2; 1.153.4;
Only save locals and ins in trapframes for DEBUG kernels.


# 1.152 04-May-2002 kleink

Add some comments to the CPP conditionals controlling the trap macro
definitions, to ease navigation somewhat.


# 1.151 16-Apr-2002 eeh

Make lots of routines profile-friendly and get rid of some cruft.


Revision tags: eeh-devprop-base
# 1.150 21-Mar-2002 petrov

Not needed debug stuff deleted.


# 1.149 16-Mar-2002 mrg

tell newer binutils that our use of %g2 and %g3 is OK here.


# 1.148 15-Mar-2002 eeh

Cleanup MMU initialization to prevent hangs.


Revision tags: newlock-base ifpoll-base
# 1.147 09-Feb-2002 eeh

branches: 1.147.4;
Fix microsecond calculation in microtime.


# 1.146 07-Feb-2002 eeh

Fix register allocation in microtime().


# 1.145 29-Jan-2002 eeh

Shift the UPAID in the correct direction.


# 1.144 17-Jan-2002 eeh

Be more tolerant of unaligned stack pointers.


# 1.143 17-Jan-2002 eeh

Enable block insns in bcopy and bzero.


# 1.142 16-Jan-2002 eeh

In bcopy use 32-bit comparisons in 32-bit kernels.


# 1.141 16-Jan-2002 eeh

Use correct calculation for the trapframe in softtrap for ILP32.


# 1.140 20-Nov-2001 lukem

- pull in opt_kgdb.h where necessary
- replace opt_kgdb_machdep.h with opt_kgdb.h
- defparam opt_kgdb.h:
KGDB_DEV KGDB_DEVNAME KGDB_DEVADDR KGDB_DEVRATE KGDB_DEVMODE
- move from opt_ddbparam.h to opt_ddb.h:
DDB_FROMCONSOLE DDB_ONPANIC DDB_HISTORY_SIZE DDB_BREAK_CHAR SYMTAB_SPACE
- replace KGDBDEV with KGDB_DEV
- replace KGDBADDR with KGDB_DEVADDR
- replace KGDBMODE with KGDB_DEVMODE
- replace KGDBRATE with KGDB_DEVRATE
- use `9600' instead of `0x2580' for 9600 baud rate
- use correct quotes for options KGDB_DEVNAME="\"com\""
- use correct quotes for options KGDB_DEV="17*256+0"
- remove unnecessary dependancy on Makefile for kgdb_stub.o
- minor whitespace cleanup


Revision tags: thorpej-mips-cache-base thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf
# 1.139 14-Sep-2001 thorpej

branches: 1.139.4;
Don't declare intrhand[] here -- that's taken care of in intr.c.


Revision tags: thorpej-devvp-base
# 1.138 30-Aug-2001 eeh

branches: 1.138.2;
Preliminary UltraSPARC III suport (not enabled yet).


# 1.137 13-Aug-2001 jdolecek

g/c _remque()/_insque(); use the C version in libkern


# 1.136 09-Aug-2001 eeh

Fix context masking lossage caused by last version.


# 1.135 08-Aug-2001 eeh

Clean up the trap code to handle the changes cause by supporting non-faulting
accesses. Also change the parameter order so trap frames are easy to find.


# 1.134 07-Aug-2001 eeh

Make sure C code always has ASI_PRIMARY_NOFAULT in the %asi register so
the compiler will be happy if it ever starts generating speculative loads.


# 1.133 05-Aug-2001 eeh

Add support for non-faulting loads and optimize MMU miss handling paths.


# 1.132 02-Aug-2001 eeh

Fix bcopy.


# 1.131 02-Aug-2001 eeh

Sync bzero w/libc version.


# 1.130 01-Aug-2001 eeh

Integrate fixes from userland memset.


# 1.129 31-Jul-2001 eeh

Code cleanup and optimization.


# 1.128 23-Jul-2001 eeh

Get rid of some debug code that really isn't all that useful any more.


# 1.127 19-Jul-2001 eeh

Do ignore unregistered interrupts instead of faulting.


# 1.126 16-Jul-2001 eeh

Make bcopy a 32-bit friendly.


# 1.125 11-Jul-2001 eeh

Fix problems booting 32-bit kernels and dispatching level-15 interrupts.


# 1.124 08-Jul-2001 eeh

branches: 1.124.2;
Code cleanup. Add block_disable to let you turn on block set/copy routines.


# 1.123 05-Jul-2001 eeh

New block bzero and bcopy.


# 1.122 04-Jul-2001 eeh

Replace old bcopy with a much faster version.


# 1.121 01-Jul-2001 martin

Disable axidently enabled debug code to make -current compile again.


# 1.120 30-Jun-2001 eeh

Use a newer version (still disabled) of block bcopy.


# 1.119 30-Jun-2001 eeh

Fixup fpu save restore, get rid of some unused copy functions, and add
a new bcopy.


# 1.118 21-Jun-2001 eeh

Allow multiple 4MB pages for both kernel text and kernel data.

Note: DEBUG checks will not allow accesses to the hole between
text and data segments, so you may need to update programs that
use libkvm before relocating the start of kernel data.


# 1.117 06-Jun-2001 mrg

extract the netbsd32, sunos, 32 bit svr4 and 64 bit svr4 sigcode out into
separate files, so that compat lkms can link with them as well.


# 1.116 30-May-2001 lukem

add missing #include "opt_kgdb.h"


Revision tags: thorpej_scsipi_beforemerge
# 1.115 25-Apr-2001 simonb

Spell occurred correctly.


Revision tags: thorpej_scsipi_nbase thorpej_scsipi_base
# 1.114 09-Apr-2001 eeh

Interrupt latency fix from sparc port. (Hm. One insn instead of 5).


# 1.113 07-Mar-2001 eeh

Fix inverted preprocessor logic. (Spotted by Charles.)


# 1.112 21-Feb-2001 eeh

branches: 1.112.2;
Add support for 64-bit SVR4 (Solaris 8) binaries.


# 1.111 10-Feb-2001 pk

Fix conditional for svr4 compat inclusion.


# 1.110 05-Feb-2001 eeh

Add signal trampoline for 64-bit svr4 emulations.


# 1.109 31-Dec-2000 eeh

Make INCR() atomic.


# 1.108 29-Dec-2000 eeh

pseg_get tells us whether it really needed that spare page after all.


# 1.107 07-Dec-2000 eeh

Fixup calculating where fpstate should be saved in the signal trampoline
code so it doesn't overwrite something important like the registers.


# 1.106 09-Nov-2000 eeh

Fix ILP32 bug in probe_get().


# 1.105 22-Oct-2000 pk

Restore revision 1.102.

I hope it sticks this time..


# 1.104 20-Oct-2000 eeh

Fix hang in 32-bit kernels caused by relocation of KERNBASE.


# 1.103 04-Oct-2000 eeh

Fix interrupt lossage problem and some cosmetic changes.


# 1.102 01-Oct-2000 pk

cpu_initialize: global registers aren't preserved across calls to
prom_printf(), so replace %g3 with %l7 (which isn't used despite
the `usage' comment).

Also, clean up white-space turds.


# 1.101 29-Sep-2000 eeh

This seems to fix the interrupt lossage of non-debug kernels.


# 1.100 28-Sep-2000 eeh

Fix INTR_SETUP() to properly distinguish kernel and user addresses.

Make microtime() return the correct time on %tick machines.

Re-enable debug stuff in dostart for now to detect kernel mapping issues.


# 1.99 25-Sep-2000 pk

Missing `#if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)'


# 1.98 17-Sep-2000 eeh

Make the improved %tick changes work with machines that use the counter-timer
for the clock.


# 1.97 12-Sep-2000 eeh

Fix new version of microtime.


# 1.96 11-Sep-2000 eeh

(Hopefully) fix clock skew on machines that us %tick for the clock (UIIi).


# 1.95 31-Aug-2000 eeh

Use casx instead of stx to change entries in the page table trees.


# 1.94 23-Aug-2000 eeh

Update the scheduler to the new locking scheme.


# 1.93 10-Aug-2000 eeh

Fix signal delivery.


# 1.92 02-Aug-2000 eeh

Get kernel profiling to work. Now if only gprof worked....


# 1.91 01-Aug-2000 eeh

Overhaul cache flush code and coredump code.


# 1.90 25-Jul-2000 pk

Re-instate a couple of delay slot NOPs marked `XXX spitfire bug?'


# 1.89 24-Jul-2000 mycroft

Optimization to pmap_zero_page(): we only need to use the first 16 FP regs,
as in bzero().


# 1.88 24-Jul-2000 mycroft

Fix a whitespace glitch.


# 1.87 24-Jul-2000 mycroft

Pull in the bzero() changes from libc for real, with a couple of kernel-
specific hacks:
* Make the bias handling depend on STKB, so it switches correctly for 32-bit
kernels.
* Use the 32-bit stw/ld for 32-bit kernels.
* Add a few `-STKB's that were missed in the previous change.


# 1.86 24-Jul-2000 pk

Cosmetic & readability:
- local label cleanup in interrupt handling code;
- in debugging sections when testing `intrdebug': use a unique
local label (97) to enhanced clarity;
- comment-out unused code;
- kill a bug as the satisfying result of doing all of the above.


# 1.85 24-Jul-2000 eeh

Fix stack issues in bzero.


# 1.84 24-Jul-2000 mycroft

Revert the previous change for now. I don't have time to debug it tonight.


# 1.83 23-Jul-2000 mycroft

Copy bzero change from libc.


# 1.82 20-Jul-2000 pk

Since `intrcnt' points to an array of long ints, reserve the appropriate
amount of space depending on _LP64. Provide macros to load/store signed
and unsigned long ints.

Also, make the `intrcnt' and `intrpending' arrays 16 entries long, as on
sparc/v9 interrupt #15 is just a regular interrupt.


# 1.81 19-Jul-2000 eeh

Fix merge problem.


# 1.80 19-Jul-2000 eeh

Disable interrupt interlock using ih->ih_pending field. Seems to cause
more problems than it solves.


# 1.79 19-Jul-2000 eeh

Miscellaneous cleanup.


# 1.78 18-Jul-2000 pk

Correct args usage comment in probeget.
Whitespace cleanup.


# 1.77 18-Jul-2000 pk

probeget: 9 -> 0x9


# 1.76 18-Jul-2000 pk

If `ih_pending' is set simply return from the trap, don't schedule another
soft interrupt.


Revision tags: mrg-merge-1-5-top
# 1.75 18-Jul-2000 pk

openfirmware: don't lower %pil


# 1.74 17-Jul-2000 pk

Kill typos in interrupt code.


# 1.73 17-Jul-2000 pk

probeget: do the same song and dance as ld*a() macros in ctlreg.h do.


# 1.72 14-Jul-2000 eeh

Move some macro definitions out of genassym and into locore.s


# 1.71 08-Jul-2000 mrg

backout part of previous: turn off intrdebug, and another debug message


# 1.70 07-Jul-2000 pk

Changes for readability:
- #define LP64 dependent STACKFRAME macro once
- use a LOAD_ASCIZ macro for setting up the format string
for debug messages.


# 1.69 07-Jul-2000 eeh

Temporary fix to prevent the clock from stopping on UIIi machines.


# 1.68 03-Jul-2000 eeh

Prevent interrupts from being posted if they are active and deprecate polled
interrupts. This seems to eliminate the spurious interrupts.


# 1.67 02-Jul-2000 eeh

Clean up interrupt handling some more.


# 1.66 30-Jun-2000 eeh

Fix interrupt delivery on UltraSPARC IIi machines.


# 1.65 24-Jun-2000 eeh

With these changes the kernel seems almost stable again.


# 1.64 24-Jun-2000 eeh

More VM cleanup:

Move the cpu_info structure above the interrupt stack so it won't
get corrupted if the stack overflows.

Flush the D$ before and after all MMU bypass accesses since the
D$ latches all of those.


# 1.63 23-Jun-2000 eeh

Make probeget() and probeset() really work for a change.


Revision tags: netbsd-1-5-base
# 1.62 19-Jun-2000 eeh

branches: 1.62.2;
Have separate data and text segments, make text read-only.


# 1.61 12-Jun-2000 eeh

Start reorganizing the kernel for MULTIPROCESSOR support.


# 1.60 31-May-2000 thorpej

Add a comment about needing to initialize p_cpu when multiple
processors are supported.


Revision tags: minoura-xpg4dl-base
# 1.59 26-May-2000 thorpej

branches: 1.59.2;
First sweep at scheduler state cleanup. Collect MI scheduler
state into global and per-CPU scheduler state:

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

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

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

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

Tested on i386 and Alpha. Changes are mostly mechanical, but apologies
in advance if it doesn't compile on a particular platform.


# 1.58 26-May-2000 thorpej

Don't set `runtime' here; it's done at the end of mi_switch().
cvS: ----------------------------------------------------------------------


# 1.57 26-May-2000 thorpej

Introduce a new process state distinct from SRUN called SONPROC
which indicates that the process is actually running on a
processor. Test against SONPROC as appropriate rather than
combinations of SRUN and curproc. Update all context switch code
to properly set SONPROC when the process becomes the current
process on the CPU.


# 1.56 22-Apr-2000 eeh

If we trap due to a bad kernel stack, try to switch to the interrupt strack
before breaking into the debugger.


# 1.55 18-Apr-2000 eeh

Prevent the system from getting watchdog reset by returning directly to user
mode if restoring the user window traps. Also reduce the time we run with
%tl>0.


# 1.54 13-Apr-2000 eeh

Apparently gas 2.9.5 (don't ask) does not like to add values to %lo()
directives so move the additions inside %lo() to make it happy.
Hopefully this won't break older versions.


# 1.53 10-Apr-2000 mrg

- fix a speeling error
- rename some numbered labels to be a bit less confusing.
- remove dead code
- fix a debug error message (argh!)


# 1.52 10-Apr-2000 pk

Get a kernel without DDB to build.


# 1.51 16-Mar-2000 eeh

Revamp interrupts again:

Fix a bug causing interrmittent panics in interrupt dispatch.
Use interrupt vectors for softints.
Add a new send_softint interface.
Improved D$ flushing.
Improve traptrace and other debugging enhancements.


Revision tags: chs-ubc2-newbase
# 1.50 16-Jan-2000 eeh

Interrupt handlers return zero if they didn't handle the interrupt.


# 1.49 10-Jan-2000 eeh

Add debugger single-stepping and fix interrupt dispatch bugs.


# 1.48 30-Dec-1999 eeh

Lots of changes:

remove ffs()
add bzero that uses block store insns
save %gsr to fpstate
revert to physical accesses for pmap_zero_page so we don't
have conflicting page mappings
general cleanup.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base fvdl-softdep-base
# 1.47 06-Nov-1999 eeh

Handle zero length properly in copyinstr() copyoutstr() and copystr().


Revision tags: comdex-fall-1999-base
# 1.46 11-Oct-1999 eeh

branches: 1.46.2; 1.46.4;
Update to post 1.4.


# 1.45 05-Oct-1999 eeh

branches: 1.45.2;
Make broken versions of gas happy by using sethi/or instead of set for
(negative) addresses.


# 1.44 17-Sep-1999 thorpej

Centralize the declaration and clearing of `cold'.


Revision tags: chs-ubc2-base
# 1.43 18-Jul-1999 eeh

More fun with pmap.


# 1.42 21-Jun-1999 eeh

Improve TRAPTRACE. Add FLTRACE that only tracks MMU faults.


# 1.41 05-Jun-1999 eeh

Make pbrobeget() and probeset() work for 64-bit values as well. To do this
the arguments are changed so the address is first and the ASI second so we
can have the address in %o0:%o1 and not worry about unused registers.

Also a bit of copyright cleanup.


# 1.40 05-Jun-1999 mrg

update a commit slightly.


# 1.39 30-May-1999 eeh

Add code to support using %tick as the system clock if no "counter-timer" node
is found.


# 1.38 09-May-1999 eeh

Fixup non-DEBUG kernels.


# 1.37 29-Apr-1999 christos

Add sunos_sigcode (32 bit only)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.36 26-Mar-1999 eeh

branches: 1.36.4;
COMPAT_SPARC32 -> COMPAT_NETBSD32


# 1.35 25-Mar-1999 mrg

clean and up make compile


# 1.34 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.33 22-Mar-1999 eeh

Need to set up the pointers properly for partial FPU register stores.


# 1.32 22-Mar-1999 eeh

Flush D$ on bypass accesses.


# 1.31 28-Feb-1999 eeh

Use block load/store in pmap_zero_page()/pmap_copy_page().


# 1.30 17-Feb-1999 eeh

Let's test out vectored interrupts.


# 1.29 15-Feb-1999 hubertf

RCS ID police


# 1.28 11-Feb-1999 mrg

fix a comment pasto.


# 1.27 11-Jan-1999 eeh

Finally fixed 64-bit signal trampoline.


# 1.26 10-Jan-1999 eeh

Handle the symbol table properly in a 32-bit kernel that was booted from a
64-bit bootloader.


# 1.25 09-Jan-1999 eeh

More signal fixup.


Revision tags: kenh-if-detach-base
# 1.24 26-Nov-1998 mycroft

Sync kcopy() with 32-bit SPARC version.


# 1.23 16-Nov-1998 eeh

Fixup the last broken bits of the signal handling code.


Revision tags: chs-ubc-base
# 1.22 08-Oct-1998 eeh

Fix more syscall32 and signal breakage.


# 1.21 22-Sep-1998 eeh

More fixup in the signal area.

64-bit syscall cleanup.

Add emulation for some new FPU insns: conversion to 64-bit long int and
conditional moves.


# 1.20 17-Sep-1998 thorpej

SYS_sigreturn -> SYS___sigreturn14.


# 1.19 13-Sep-1998 eeh

Fixup signal changes (hopefully). However SUN_COMPAT is likely broken by
this and I don't know how to fix it.

We can now exec a 64-bit init through a really ugly hack (don't ask.)


# 1.18 11-Sep-1998 eeh

Add labels for the compat_sparc32 signal trampoline and break -- er -- fix
suword and fuword.


# 1.17 09-Sep-1998 eeh

Don't use %tick for microtime on 32-bit kernels -- breaks gettimeofday.


# 1.16 09-Sep-1998 thorpej

Adjust for the new "reaper" kernel thread: do not free the vmspace and
u-area in machine-dependent code. Instead, call exit2() to schedule
the reaper to free them for us, once it is safe to do so (i.e. we are
no longer running on the dead proc's vmspace and stack).


# 1.15 07-Sep-1998 eeh

Fix data corruption problem caused by broken debug code.


# 1.14 07-Sep-1998 eeh

Add new 64-bit trap vectors.


# 1.13 06-Sep-1998 eeh

32-bit fixup.


# 1.12 06-Sep-1998 eeh

Disable some debug stuff.


# 1.11 05-Sep-1998 eeh

It slices. It dices. It does everything except exec a sparc32_compat init.


# 1.10 02-Sep-1998 eeh

Periodic update: now starts probing devices.


# 1.9 30-Aug-1998 eeh

Some more 64-bit cleanup. Now everything compiles.


# 1.8 29-Aug-1998 eeh

Some more 64-bit-ification.


# 1.7 27-Aug-1998 eeh

Add 64-bit pmap support:

Moved from a two level 512/1024 entry setup mapping 32 (9/10/13) bits
respectively to a three level 1024/1024/1024 entry setup mapping 43
(10/10/10/13) bits. In 32-bit mode we waste about 1/12 pages mapping the high
11 bits. We also only manage 43 of the possible 44 bits of virtual address
space, wasting half of it. Oh well, maybe we'll do better next revision.


Revision tags: PMAP32
# 1.6 26-Aug-1998 mrg

panicstack: is needed outside of DEBUG. use _C_LABEL, and printf not db_printf (incase no ddb!)


# 1.5 13-Aug-1998 eeh

Merge paddr_t changes into the main branch.


Revision tags: eeh-paddr_t-base
# 1.4 07-Jul-1998 eeh

branches: 1.4.2;
General update:

Added genassym.cf
Removed lderr which should never have gotten in
Removed lots of dead code from locore.s
Added some softint stuff to intr.c
Added support for halt -p
esp and le both use bus_dmamap_*() functions now
instead of kdvma_mapin()
groundwork for PCI (but we still have no drivers for
any sun4u PCI devices)


# 1.3 04-Jul-1998 jonathan

defopt DDB.


# 1.2 26-Jun-1998 thorpej

defopt COMPAT_SVR4


# 1.1 20-Jun-1998 eeh

branches: 1.1.1;
Initial revision


# 1.405 07-Jan-2017 palle

sun4v: slowtrap() now selects normal globals properly on both sun4u and sun4v platforms. Verified using qemu for both sun4u and sun4v systems


Revision tags: pgoyette-localcount-20170107
# 1.404 05-Jan-2017 palle

sun4v: TRAP_SETUP() updated to set mmu context id properly for both sun4v and sun4u platforms. Verified using qemu for both sun4u and sun4v systems


# 1.403 04-Jan-2017 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x00-0x23 and 0x28-0x30


# 1.402 29-Dec-2016 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x32-0x7f


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.401 20-Sep-2016 nakayama

Fix RAS for 32-bit kernels. trapframe is always 64-bit.


Revision tags: localcount-20160914
# 1.400 23-Aug-2016 palle

sun4v: rework sun4v_datatrap so it works properly when running on a T2-based system like T5120 - for some reason %tl is 0 when entering sun4v_datatrap causing a crash (sir instruction), so ignore the %tl value for now upon entry to sun4v_datatrap - with this fix both T1 and T2 based systems reach the same point - hangs in rft_user after the init process is started


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726
# 1.399 18-Jul-2016 palle

sun4v: handle device interrupts properly - both legacy (sysino) and cookies


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 1.398 04-Jun-2016 palle

branches: 1.398.2;
sun4v: rtf_user now uses macros GET_MMU_CONTEXTID and SET_MMU_CONTEXTID. Tested on sun4u (QEMU) and sun4v (T2000). Parts from OpenBSD.


Revision tags: nick-nhusb-base-20160529
# 1.397 18-May-2016 nakayama

Decrement %tl in trap handler not to make it zero unconditionally
for the nested trap, and remove useless mov.


# 1.396 17-May-2016 palle

sun4v: Implement missng MMU protection trap handling - mostly from OpenBSD


# 1.395 16-May-2016 palle

Avoid assembler-specific defines by using the export keyword in genassym.cf instead


# 1.394 15-May-2016 nakayama

%g1 is not preserved across function call, so load it before
return_from_trap.


# 1.393 13-May-2016 palle

sun4v: add missing implementation of sun4v_datatrap_tl0 so data_access_fault() is called - mostly from OpenBSD


# 1.392 13-May-2016 nakayama

- ci_paddr is always 64-bit.
- intrlev is array of pointer.
- ih_ack is pointer.


# 1.391 10-May-2016 palle

sun4v: make device interrupts work. Introduce a new intrhand_alloc() function for allocation of interrupt handlers and adapt to this. Parts from OpenBSD. ok martin@


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.390 09-Mar-2016 nakayama

32-bit kernels use 32-bit stack.


# 1.389 03-Mar-2016 palle

sun4v: rft_kernel should pay attention to the number of register windows that can be restored. We cannot rely on fill traps to occur, since sun4v only has two trap levels available in privileged mode. Based on code from OpenBSD. ok martin@


# 1.388 14-Feb-2016 palle

sun4v: add breakpoint trap entry to the sun4v trap table


# 1.387 03-Feb-2016 palle

sun4v: extend dmmu_set_secondary_context() to handle both sun4u and sun4v. ok martin@


Revision tags: nick-nhusb-base-20151226
# 1.386 06-Nov-2015 martin

Basically revert r1.246 of locore.s and r1.73 of vm_machdep.c:

Remove special case handling for userland lwps from cpu_lwp_fork,
instead do it in lwp_trampoline when we first return to userland.

which was a stupid idea - since we did now set all fork child's %tstate
(and thus %pstate when back in userland) to the current kernel's userland
default. This meant we lost the address mask bit for 32bit processes and
all memory model details for 64bit ones.

Move it back to cpu_lwp_fork and fix the condition to only do it once when
forking init.


# 1.385 05-Nov-2015 martin

Most of the time return_from_trap already got called with tf->tf_tstate
loaded in register %g1 - make it so for two more callers and remove
the reload of that value.


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606 nick-nhusb-base-20150406
# 1.384 05-Apr-2015 palle

sun4v: Ensure that the TTEs CP and CV bits are the same (both set) for the primary cpu and secondary cpus INTSTACK mappings


# 1.383 01-Apr-2015 palle

sun4v: Implement handling of cpu_mondo trap - from OpenBSD - tested using the Legion simulator


# 1.382 04-Mar-2015 palle

sun4v: revert some of the logic introduced in revision 1.378 - flushw is not necessary on sun4v (OpenBSD patches the flushw instruction to a nop instruction) - with these changes the kernel reaches cpu_boot_secondary_processors() when running in the Legion simulator (crashes due to missing handling of cpu_mondo_trap)


# 1.381 02-Mar-2015 nakayama

prom_printf converts "\n" to "\r\n" internally, so omit "\r".


# 1.380 02-Mar-2015 nakayama

PANICSTACK is a pointer itself, not a pointer to pointer.


# 1.379 02-Mar-2015 nakayama

Use panic stack temporarily for calling prom_printf in a trap
handler.

It seems that openfirmware cannot handle over 4GB pointers, and
stack pointers may point to over 4GB since VA layout was rearranged
by rev 1.33 of vmparam.h. Therefore, use panic stack to avoid
panicking in OF_write used by prom_printf.


# 1.378 23-Feb-2015 palle

sun4v: sparc_interupt - ensure that the trap level and globals level are the same when the flushw instruction is issued - othwise warnings occur when using the sun4v Legion simulator.


Revision tags: nick-nhusb-base
# 1.377 26-Oct-2014 palle

branches: 1.377.2;
sun4v: Create CLEANWIN0 and CLEANWIN1 macros for handling clean window traps on both sun4u and sun4u (based on the original code inlined in the sun4u trap table). Update trap tables accordingly for both sun4u and sun4v. Ok martin@


# 1.376 24-Oct-2014 nakayama

Fix typo in comment.


# 1.375 18-Oct-2014 snj

src is too big these days to tolerate superfluous apostrophes. It's
"its", people!


# 1.374 15-Oct-2014 palle

sun4v: fixed bug causing the real address to be incorrectly calculated as zero


# 1.373 24-Sep-2014 palle

sun4v: add code to enable startup of secondary cpus on both sun4u and sun4v systems - ok martin@


# 1.372 04-Sep-2014 palle

sun4v: All cpus must be setup with a TSB descriptor, so pmap_setup_tsb_sun4v() must take a pointer to the TSB descriptor


# 1.371 31-Aug-2014 palle

sun4v: Split the NORMAL_GLOBALS and ALTERNATE_GLOBALS macros to _SUN4U and _SUN4V variants. Rework the return_from_trap logic to use the new variants so it is possible to use a global register as scratch register.


# 1.370 14-Aug-2014 nakayama

Add missing delay slot in DEBUG kernel.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.369 30-Jul-2014 palle

branches: 1.369.2;
Fix ALTERNATE_GLOBALS so it at least works on sun4u - using a scratch register is not a good idea...


# 1.368 27-Jul-2014 palle

sun4v: Introduce a new macro ALTERNATE_GLOBALS (matching NORMAL_GLOBALS). Two new helper macros ENABLE_INTERRUPTS and DISABLE_INTERRUPTS are also created. With these changes the GENERIC.UP kernel will reach rootmount on sun4v systems - ok martin@


# 1.367 26-Jul-2014 palle

Improved the NORMAL_GLOBALS macro in the sun4u case, so only the relevant bit (AG) in %pstate is affected - ok martin@


# 1.366 24-Jul-2014 palle

sun4v: add missing spill/fill handling for trap level 1 + cosmetic changes to comments for trap level 0 entries


# 1.365 19-Jul-2014 palle

sun4v: Introduce a NORMAL_GLOBALS macro - first used in sparc_interrupt - other relevant uses will be handled as the sun4v work is progressesing - ok martin@


# 1.364 16-Jul-2014 palle

sun4v: Introduce SET_MMU_CONTEXTID macro for setting the mmu context id on both sun4u and sun4v


# 1.363 13-Jul-2014 palle

sun4v: add interrupt handling to sun4v trap table


# 1.362 13-Jul-2014 palle

Bugfix: add missing cmp instruction to GET_MAXCWP macro


# 1.361 30-Jun-2014 palle

sun4v: The maximum number of register windows is a constant and thus not available via the %ver register (sun4u only). Introduce a macro GET_MAXCWP that handles this, so cpu_switchto() works properly on sun4v. Other relevant reference to %ver can be adapted to use GET_MAXCWP as the sun4v port progresses. OK martin@


# 1.360 31-May-2014 palle

sun4v: added missing dtsb miss handling for trap level 1 - with this update the kernel now reaches configure() on sun4v systems


# 1.359 30-May-2014 palle

Remove debugging code introduced by accident in locore.s revision 1.357


Revision tags: yamt-pagecache-base9 rmind-smpnet-nbase rmind-smpnet-base
# 1.358 05-May-2014 palle

sun4v: the trap base address should be assigned to %l1 so %tba is properly setup later in the code - now the kernel gets as far as printing the copyright disclaimer, kernel version and total and available memory before crashing


# 1.357 21-Apr-2014 palle

sun4v: Update comment: modified -> access


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.356 21-Feb-2014 palle

branches: 1.356.2;
sun4v: Rename TLB_ defines to SUN4U_TLB_ so entries created using TSB_DATA() are properly setup for sun4u and sun4v. Relocate the cputyp variable from autoconf.c to locore.s and make it const in param.h so optimized code can be generated. Parts from OpenBSD. Optimization suggested by nakayama@. OK martin@, mrg@, nakayama@


# 1.355 31-Jan-2014 tsutsui

defined(LKM) -> defined(MODULAR)


# 1.354 26-Jan-2014 palle

sun4v: Add handling of spill/fill and dtsb miss traps (with a XXX to be handled later)


# 1.353 07-Jan-2014 palle

sun4v: trap table setup - currently populated with dummy entries which will be properly implemented later - parts from OpenBSD - OK martin@


# 1.352 29-Dec-2013 nakayama

Make buildable w/o options SUN4V.


# 1.351 27-Dec-2013 palle

a) make the hunt through the cpus list more generic b) sun4v: ensure that the interrupt stack is mapped permanently and the TSB is setup properly - parts from OpenBSD. OK martin@


# 1.350 06-Dec-2013 nakayama

Increase an interrupt depth only in the case of hardware interrupts,
and remove the ci_idepth trick in softint_fastintr.

Fixes the following diagnostic panic reported in port-sparc64.

panic: kernel diagnostic assertion "!cpu_intr_p()" failed: file
"../../../../kern/subr_xcall.c", line 351


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 1.349 24-May-2013 nakayama

branches: 1.349.2;
Disable interrupts after calling data_access_error as with
data_access_fault.


# 1.348 28-Apr-2013 nakayama

Use macros in machine/asm.h instead of locally defined, and
introduce CASPTRA for casxa/casa.


Revision tags: agc-symver-base
# 1.347 23-Jan-2013 martin

Fix sparc64_ipi_ccall by adding proper trap setup.
Fixes xcall(9) problems, as exposed by pserialize(9). Noticed by
J. Hannken-Illjes, cause pointed out by Takeshi Nakayama.


# 1.346 23-Jan-2013 martin

Sligthly clean up the (by default unused) #ifdef TRAPS_USE_IG


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.345 10-Nov-2012 nakayama

Revise comment.


# 1.344 10-Nov-2012 nakayama

Use macro instead of magic number.


# 1.343 09-Nov-2012 nakayama

Make setstick() and getstick() to inline functions.


# 1.342 08-Nov-2012 macallan

use system tick timer instead of %tick on UltraSPARC-III-ish CPUs
review & fixes by Takeshi Nakayama


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.341 17-Mar-2012 mrg

branches: 1.341.2;
port the corrected ECC error handling code from freebsd. i noticed my U10
took one of these and then hang. it shouldn't hang, there's a 'sir' here that
doesn't seem to reset properly. oh well.

tested by simulated a trap via 'ta 0x10' and considering that the same, but
it hasn't been tested against a real ECC error yet.


Revision tags: jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base4
# 1.340 03-Mar-2012 nakayama

Fix the root cause of the hack "disable optimizations for uvm_bio.c
on 32 bit kernels".

gcc converts a division in the calculation of UBC_UMAP_ADDR macro
to multiplication (smul or combination of add/sll), and the
register of its result contains a garbage in upper 32 bits (the
upper 32 bits of smul/add/sll's result isn't zero cleared).

Then it passes to pseg_get{,_real} through pmap_extract without the
zero clear of upper 32 bits in the optimization case. So the
result of pseg_get and pmap_extact sometimes gets screwed up.


Revision tags: jmcneill-usbmp-base5 jmcneill-usbmp-base3
# 1.339 19-Feb-2012 rmind

Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.


Revision tags: jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.338 04-Sep-2011 nakayama

branches: 1.338.2; 1.338.6; 1.338.8;
ih_pil is an interrupt level, not an interrupt mask.


# 1.337 27-Jul-2011 nakayama

ivec is assigned to hardware, so count its event counter up in
interrupt_vector, not in softint, and do some optimization.


# 1.336 20-Jul-2011 macallan

add per ivec event counters


# 1.335 12-Jul-2011 mrg

rename sparc64 BLOCK_SIZE and BLOCK_ALIGN to have SPARC64_ prefixes.
for the assembler files, define the old names to the new names
since using the new names cause ugliness due to longer identifer
names, and reduces churn.

fixes build issues in dtv and vaguely makes <machine/psl.h> slightly
less name-space invasive.


# 1.334 18-Jun-2011 nakayama

Add fast softint(9) support for sparc64.

Reviewed on port-sparc64.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 1.333 12-May-2011 mrg

branches: 1.333.2;
first steps towards fujitsu SPARC64 support:

- SPARC64 systems have interrupts with upto 14 bits set, but we only look
at the first 11 bits. trim non IPI interrupts to 11 bits


Revision tags: uebayasi-xip-base7 bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 jym-xensuspend-nbase jym-xensuspend-base
# 1.332 20-Dec-2010 matt

branches: 1.332.2;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.


Revision tags: uebayasi-xip-base6 uebayasi-xip-base5 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 1.331 10-Jul-2010 nakayama

Clear the upper word explicitly before combining two 32-bit values to 64-bit
on 32-bit kernels.


# 1.330 23-May-2010 martin

Split copy related functions out of locore.s into copy.S, move functions
only needed on multiprocessors into mp_subr.S.


# 1.329 17-May-2010 martin

Simplify primary CPU startup slightly by using the fact that our cpuinfo's
curpcb pointer points to the uarea/pcb of lwp0 and by remembering the pointer
to this cpuinfo, thus avoiding a few CPUINFO_VA references.


Revision tags: uebayasi-xip-base1
# 1.328 20-Mar-2010 chs

fix copy{in,out}{,str}() to return the error returned by uvm_fault().
fixes PR 41813.


Revision tags: yamt-nfs-mp-base9
# 1.327 10-Mar-2010 mrg

branches: 1.327.2;
XXX: workaround we'd like to remove when pmap / uvm locking is cleaned up:

- rename pseg_get() and pseg_set() to pseg_get_real() and pseg_set_real().
- if USE_LOCKSAFE_PSEG_GETSET is defined, which it current is by default,
define pseg_[gs]et() in terms of functions that take a new pseg_lock
mutex at IPL_VM while calling into the real functions.

this seems to avoid the pseg_set() crashes we've seen:
1 - spare needed, when pseg_get() just worked for this pmap
2 - the 2rd ldxa via ASI_PHYS_CACHED in pseg_set() loads garbage
into %o4, and causes the 3rd ldxa to fault


# 1.326 08-Mar-2010 mrg

blast_dcache() SMP friendly:

- blast_dcache() becomes sp_blast_dcache(dcache_size, dcache_line_size)
- new smp_blast_dcache(sparc64_cpuset_t) that blasts the D$ on this cpuset
- sparc64_ipi_blast_dcache() to support the above
- in pmap_remove_all(), when freeing mmu contexts for this pmap, mark
the set of cpus to blast the d$ on as well and convert the
blast_dcache() call into smp_blast_dcache() on the cpus who ran this
pmap, or, sp_blast_dcache(dcache_size, dcache_line_size)
- convert the remaining blast_dcache() in machdep.c to sp_blast_dcache()
- in pmap_destroy()/pmap_remove_all() take the pmap_lock() always since
we assert it is held always.

with these changes, NFS builds on the U60 seem to be stable now, and
the USIII machines also can often complete a single build.sh run now,
diskful or diskless.


reviewed by mlelstv and partially by martin, tested by martin and myself,
with some ideas from chuq as well.


# 1.325 07-Mar-2010 mrg

need _ALIGN in locore.h as well, for DEBUG kernels.


# 1.324 07-Mar-2010 mrg

gas has supported SPARC ".empty" for a long while; get rid of an
ancient workaround.


# 1.323 06-Mar-2010 mrg

move the memcpy/memset implementations out into their own file, with the
block copy versions as well. move some of the definitions in locore.s
into a new locore.h.

locore.s is almost 2000 lines shorter with this change.


# 1.322 04-Mar-2010 mrg

- in _bus_dmamap_unload(), pmap_page_protect() and pmap_clear_reference()
switch the dcache_flush_page() into a dcache_flush_page_all()
- in both pmap_kremove()/pmap_remove(), remove the blast_dcache() call
and replace it with dcache_flush_page_all()
- in pmap_get_page() [used to allocate PTP's], always call pmap_zero_page(pa)
- flush the dcache of the dst page in pmap_{copy,zero}_page() by redirecting
throught a C function that calls the (renamed) asm. the old asm code had a
comment about needing to do this...
- add a couple of membar #Sync's that the USIII manual recommends


based on discussions with chuq@, skrll@ and martin@.


these help my SB2000 / SB2500 with both disk / nfs builds and other tasks,
sometimes lasting for several hours before failing or asserting.


# 1.321 24-Feb-2010 mrg

when handing back page table pages to UVM, flush them from the dcache
on all CPUs.

idea from skrll@, and makes my disk-based SB2000 stable.

tested on U60, SB2000 and SB2500.


# 1.320 24-Feb-2010 mrg

- re-introduce sp_tlb_flush_pte() and sp_tlb_flush_all() that call
the right USI/USIII version.
- define tlb_flush_pte() in terms of sp_tlb_flush_pte() for the
!MULTIPROCESSOR case

this centralises some CPU_IS_USIII_UP() tests.


# 1.319 22-Feb-2010 mrg

move {dump,print}_[id]tlb() into a separate file.


# 1.318 22-Feb-2010 mrg

- store the maximum [id]cache size / line size for each cpu

- remove patch_kernel() since it isn't necessary and has been patching
the wrong thing in general.

- implement USIII versions of blast_icache(), dcache_flush_page() and
cache_flush_phys(). use the newly recorded cache size/line sizes.

- in winfixsave, flush the D$ with the right size index and ops. this
kills one of the wrong tag->inval patches.

- for blast_dcache(), use the newly recorded dcache_size/line_size.

- for blast_icache(), use the newly recorded cache size/line sizes.
for the USIII verison, disable the I$ while writing to ASI_ICACHE_TAG.


these changes removed several hard coded cache sizes values, some very
wrong kernel patching, and seem to make the current failure modes for
USIII less common, but not gone.


# 1.317 15-Feb-2010 mrg

- don't flush 32-bit entries for 64-bit code, it does not seem to be
necessary. #define TLB_FLUSH_LOWVA to turn it back on.
- remove the #if 0'd code in sparc64_ipi_flush_pte_usiii(), i have
verified that it is not required.
- add a missing membar #Sync to sp_tlb_flush_pte_usiii().


# 1.316 15-Feb-2010 nakayama

Fix linker error of GENERIC32 kernel.


# 1.315 15-Feb-2010 mrg

use TLB_SIZE_SPITFIRE in a couple of places, and note that the
{print,dump}_[id]tlb() versions are currently spitfire specific.


# 1.314 15-Feb-2010 mrg

introduce a new patch_kernel() and call it from the end of bootstrap().
use it to patch up TLB flush instructions that don't match for USI/II
and later. we can also hopefully use this to make GENERIC.MP minimally
expensive on single CPU machines as well.

this is the last piece needed to get GENERIC/GENERIC.MP to boot on the
USIII* machines.

idea and some initial code from openbsd.


# 1.313 13-Feb-2010 mrg

remove KTR support. it's never been a working part of netbsd src tree.


# 1.312 09-Feb-2010 wiz

Fix typo in comment.


Revision tags: uebayasi-xip-base
# 1.311 06-Feb-2010 mrg

branches: 1.311.2;
- properly map the schizo interrupt registers, so we can use the normal
virtual mappings to access them.
- with the above fxied, kill SCHIZO_BUS_SPACE_BROKEN, and introduce
an options CHEETAH for now, that disables the SPITFIRE code in locore.
- merge schizo_init() into schizo_attach() and clean up the softc a bit.


with this we are only one more step away from GENERIC booting on USIII
machines.


# 1.310 02-Feb-2010 mrg

- split sp_tlb_flush_pte() and switchtoctx() into sp_tlb_flush_pte_us()/
sp_tlb_flush_pte_usiii() and switchtoctx_us()/switchtoctx_usiii() and
implement the latter while i'm here. it works ... sometimes i think,
but also sometimes panics/hangs.
- fix a comment in sparc64_ipi_flush_pte_usiii()


# 1.309 02-Feb-2010 mrg

for now, reduce a few #ifdef SPITFIRE cases by introducing a new
ASI_DCACHE_TAG_OR_INV that is either ASI_DCACHE_{TAG,_INVALIDATE}.

increase the common code in cache_flush_phys().


# 1.308 01-Feb-2010 mrg

- sp_tlb_flush_all() becomes sp_tlb_flush_all_us() and sp_tlb_flush_all_usiii()
- sparc64_ipi_flush_pte() becomes sparc64_ipi_flush_pte_us() and
sparc64_ipi_flush_pte_usiii()
- add some commented out code to disable interrupts and raise the traplevel
in sparc64_ipi_flush_pte_usiii()
- cache_flush_phys() was missing a little of code in the cheetah case


# 1.307 01-Feb-2010 mrg

for USIII, use the new "tlb demap all" operation in sp_tlb_flush_all()


# 1.306 01-Feb-2010 mrg

remove unused icache_flush_page() implementation.


# 1.305 23-Jan-2010 mrg

remove the final uses of DATA_START.

now we can remove the 16KB space reserved at the start of the data segment,
and i now understand why i wrote this now removed comment 3.5 years ago:
"this shouldn't be needed... but kernel usually hangs without it"


# 1.304 23-Jan-2010 mrg

remove most of the code that writes debugging info DATA_START + offset.


# 1.303 23-Jan-2010 mrg

remove CHKPT() macro and uses. it's likely wrong in SMP land and probably should
be replaced with KTR-style uses if necessary.


# 1.302 23-Jan-2010 mrg

fix a comment.


Revision tags: matt-premerge-20091211
# 1.301 10-Dec-2009 rmind

Rename L_ADDR to L_PCB and amend some comments accordingly.


# 1.300 05-Dec-2009 mrg

- adjust the PA mask to the 43 bits supported by USIII.
- rework the spitfire/cheetah cache_flush_phys() to avoid several #ifdefs
- add a membar #Sync after sparc64_ipi_drop_fpstate (probably unnecessary)


# 1.299 30-Nov-2009 nakayama

sp_tlb_flush_pte for cheetah:
- restore interrupts properly in case of %tl > 0.


# 1.298 30-Nov-2009 mrg

stablize UP USIII support by blocking interrupts around sp_tlb_flush_pte()
i was seeing stack corruption while taking an interrupt in this function.

get USIII SMP mostly working by implementing the cheetah version of
sparc64_ipi_flush_pte().


SMP support is still not entirely stable. i can reproducably get a:

panic: fpusave_lwp ipi didn't

while running build.sh, when an awk process is exiting. other simple
heavy work loads do not crash for me right now.


# 1.297 30-Nov-2009 mrg

delete some no longer used code:
- smp_tlb_flush_ctx()
- smp_tlb_flush_all()
- sparc64_ipi_flush_ctx()
- sparc64_ipi_flush_all()
- sp_tlb_flush_ctx()


# 1.296 29-Nov-2009 nakayama

- calculate end PA correctly.
- wrap more spitfire specific (flushing I$) code.
- fix inverted #if condition for flushing I$ (and restore ASI_ICACHE_TAG).


# 1.295 28-Nov-2009 mrg

implement enough code to get SB2000/SB2500 booting to multiuser. does
not last long if you use it, but an idle machine has stayed up 10 hours.

- for the !SPITFIRE case, use ASI_DCACHE_INVALIDATE instead of
ASI_DCACHE_TAG when clearing tlb entries. from openbsd.

- convert some comment "! Not yet" into "WRITEME", so that attempting
to build a USIII MULTIPROCESSOR kernel fails to build until the code
is written.

- add some more WRITEME's for the above.

- implement a !SPITFIRE version of sp_tlb_flush_all(). since there are
no spare regs, for now just always increase %tl around this call. (we
could maybe store a token in %o3 along with the saved %pstate info.)


# 1.294 26-Nov-2009 matt

Kill proc0paddr. Use lwp0.l_addr instead.


# 1.293 25-Nov-2009 mrg

s/L_ADDR/L_PCB/, requested by rmind.


# 1.292 17-Oct-2009 nakayama

Wrap unused code with #if 0 which is called from #if 0'ed code.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5
# 1.291 30-May-2009 martin

cpu_setfunc() can not use lwp_trampoline, as that has additional lwp startup
semantics. Use a simpler setfunc_trampoline instead.


# 1.290 18-May-2009 nakayama

Remove random() from locore.s since it is in libkern.


# 1.289 16-May-2009 nakayama

Remove clear %tick in locore.s since it is cleared at cpu_initclocks() in
clock.c.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 nick-hppapmap-base mjf-devfs2-base
# 1.288 15-Dec-2008 mrg

restore some old "intrdebug" code, but leave it under NOT_DEBUG. most
of it works, but one that prints func/arg for each handler is not very
stable...

for now, while schizo bus space pointer accesses aren't working, add
a SCHIZO_BUS_SPACE_BROKEN option so you can build a kernel with schizo.

with this, and the prior schizo interrupt fix, you can now fail to run
/sbin/init!


Revision tags: haad-dm-base2 haad-nbase2 haad-dm-base
# 1.287 09-Dec-2008 martin

Get rid of get_maxctx() - it doesn't work on newer cpus and we will have
to find a better way for (some) sun4v machines - all sun4u use 13 bit
contexts anyway.


Revision tags: netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 ad-audiomp2-base netbsd-5-base
# 1.286 30-Oct-2008 nakayama

branches: 1.286.2; 1.286.6;
Wrap more code specific to USE_BLOCK_STORE_LOAD.


Revision tags: matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4
# 1.285 05-Oct-2008 nakayama

branches: 1.285.2;
- in flushing cache, use 32 as increment/decrement value to match the
cache line size.
- remove useless restore of %asi.
- remove nop in delay slot if we can.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 1.284 10-Jul-2008 nakayama

Use proper CCR.


# 1.283 10-Jul-2008 nakayama

sparc64_ipi_save_fpstate:
- use primary MMU context for consistency with other trap/interrupt handlers.

sparc64_ipi_save_fpstate, savefpstate:
- avoid storing fp registers as we can.

sparc64_ipi_save_fpstate, savefpstate, loadfpstate:
- remove unaligned case since buffers allocated with pool_cache are ensured
64-byte aligned.

Ok by martin@.


# 1.282 02-Jul-2008 nakayama

branches: 1.282.2;
UltraSPARCs don't have floating point queue, and reading %fq regsiter
will cause illegal instruction trap. So remove the code handling them.


# 1.281 29-Jun-2008 nakayama

Wrap IPI calls with #ifdef MULTIPROCESSOR.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.280 14-Jun-2008 nakayama

Close unterminated comment.
Fix unexpected behavior in case of loadfpstate from unaligned buffer.


Revision tags: yamt-pf42-base3
# 1.279 31-May-2008 nakayama

branches: 1.279.2;
openfirmware_exit:
- disable interrupts with %pstate.
- prepare 64-bit stack and enable 64-bit addresses for 32-bit SMP kernels.


Revision tags: hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 yamt-nfs-mp-base yamt-pf42-base
# 1.278 16-Apr-2008 nakayama

branches: 1.278.2; 1.278.4; 1.278.6;
Disable TRAPSTATS which was accidentally enabled when yamt-idlelwp branch
was merged.

Ok by martin@.


# 1.277 14-Apr-2008 nakayama

Remove sparc64_ipi_sync_tick.

Since we can use counter-timer as timecounter instead of %tick on SMP kernel,
it is not necessary to sync all CPUs %tick registers.


# 1.276 14-Apr-2008 nakayama

Add workaround for BB_ERRATA_1 on writing to TICK_CMPR register in
next_tick(). If writing to TICK_CMPR fails, we lose hardclock interrupt
on secondary CPUs.

About BB_ERRATA_1 from comment in OpenSolaris:

/*
* Writes to the TICK_COMPARE register sometimes fail on blackbird modules.
* The failure occurs only when the following instruction decodes to wr or
* wrpr. The workaround is to immediately follow writes to TICK_COMPARE
* with a read, thus stalling the pipe and keeping following instructions
* from causing data corruption. Aligning to a quadword will ensure these
* two instructions are not split due to i$ misses.
*/


# 1.275 28-Mar-2008 nakayama

Don't read fplwp content in delay slot for considering the case fplwp was
modifiled.

Reported by Chris Ross on port-sparc64.


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.274 20-Mar-2008 nakayama

- remove disabling interrupt in IPI.
- unused VA bits in MMU demap is 13 bits, not 12 bits.


# 1.273 18-Mar-2008 nakayama

Fix a race when increment an interrupt level event counter.


# 1.272 17-Mar-2008 nakayama

Fix a race condition in IPI handlers of save/drop fpstate, from OpenBSD.
Reported and tested by martin@.


# 1.271 17-Mar-2008 nakayama

Make schedintr interrupt handler per-CPU.
While there rename tickintr interrupt handler and share initialization
code with schedintr.


# 1.270 14-Mar-2008 nakayama

Improve IPI handling:
- make IPI takes two arguments.
- add IPI event counters per-CPU.
- implement IPI functions which were missing or broken.
- insert DELAY while halting primary CPU in IPI handler.


# 1.269 02-Mar-2008 nakayama

- make interrupt pending list per-CPU.
- make tickintr() MP-safe.
- remove unused port-sparc derived interrupt code.

Ok by martin@.


# 1.268 02-Mar-2008 nakayama

Don't get IPI handler argument (from bogus address), and ack IRQ twice.


# 1.267 28-Feb-2008 martin

Make TSBs and MMU contexts per-cpu.


Revision tags: nick-net80211-sync-base mjf-devfs-base hpcarm-cleanup-base
# 1.266 26-Jan-2008 nakayama

branches: 1.266.2; 1.266.6;
Fix for 32-bit kernels.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.265 15-Jan-2008 skrll

Store a sensbile PCB_PC value in snapshot - the return point.

This helps gdb somewhat.

OK'd by martin.


# 1.264 14-Jan-2008 martin

Fix register name typo/copy&pasto - %g6 is not %o6/%sp.
From OpenBSD.


Revision tags: matt-armv6-base
# 1.263 06-Jan-2008 martin

Load the next cpu_info pointer with LDPTR instead of ld.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2
# 1.262 09-Dec-2007 martin

branches: 1.262.2;
Provide cpu_intr_p(), at least for non-MULTIPROCESSOR kernels.
Based on suggestions by Andrew Doran.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.261 22-Oct-2007 martin

branches: 1.261.2; 1.261.4; 1.261.6;
Remove an unused .globl declaration


Revision tags: yamt-x86pmap-base4
# 1.260 17-Oct-2007 garbled

Merge the ppcoea-renovation branch to HEAD.

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

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

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base ppcoea-renovation-base vmlocking-base
# 1.259 09-Sep-2007 martin

branches: 1.259.4;
Make cpufrequency and friends per cpu values.
Prepare a hz tick interrupt on secondary CPUs via %tick, but do not
enable it yet, as it breaks ddb.


# 1.258 09-Sep-2007 martin

Do not ACK IPIs before we finished loading all arguments.


# 1.257 06-Sep-2007 martin

Remove the (now unused) second 64k page mapped per CPU.
From matthew green, with small changes by me. All bugs are mine.


# 1.256 25-Aug-2007 martin

branches: 1.256.2;
Remove INITSTACK completely - at the time we used to switch to it, we
already have access to all of lwp0 and it's uarea - so we can switch
to the correct lwp0 stack easily before calling main.


# 1.255 25-Aug-2007 martin

When exiting to OF, use the interrupt stack instead of INITSTACK


# 1.254 25-Aug-2007 martin

Rework cpu_mp_startup slightly:
- temporarily use the cpu's interrupt stack untill we are ready
to access non-OF-based mappings, then directly switch to the cpu's
idlelwp's uarea stack
- disable interrupts untill we are ready to call C code


# 1.253 13-Aug-2007 macallan

remove two restore without matching save


Revision tags: nick-csl-alignment-base matt-mips64-base mjf-ufs-trans-base
# 1.252 06-Jul-2007 martin

branches: 1.252.4; 1.252.8;
A few nits for 32bit SMP kernels, noticed by mrg.
While there, simplify the fpstate IPIs a bit.


# 1.251 05-Jul-2007 martin

sparc64_ipi_save_fpstate is not a leaf function - create a full grown
stack frame.


# 1.250 28-May-2007 mrg

clean up cpu_switchto() a little - no need to flushw or membar
excessively. optimise an rdpr. tested by tnn.


# 1.249 23-May-2007 martin

Fix a stupid bug in the save_fpstate ipi, which caused overwriting of
struct lwp of the lwp owning the fpu. Fix clearing the fplwp - %o0 will
not survive the call to savefpstate - duh!


# 1.248 20-May-2007 martin

Simplify tf_tstate setting when leaving for userland initially - I seem
to have confused the if with the else case of the previous C code.
Funny that it worked at all.


# 1.247 20-May-2007 martin

cpu_switchto() has to return it's first arg, always. This differs from
my reading of the documentation, but helps in the real world and seems
to be what other ports do.


# 1.246 20-May-2007 martin

Remove special case handling for userland lwps from cpu_lwp_fork, instead
do it in lwp_trampoline when we first return to userland.


# 1.245 19-May-2007 martin

cpu_idle is a leaf function, so we better "return from leaf".
Use return value from cpu_switchto for previous lwp in lwp_trampoline.
Also shamelessly steal a comment from uwe written for sparc that explains
all this.
Thanks to tnn, mrg, and uwe for helping to debug this.


# 1.244 17-May-2007 yamt

merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base ad-audiomp-base
# 1.243 22-Feb-2007 martin

branches: 1.243.4; 1.243.6; 1.243.12;
uvm.page_idle_zero now is a bool, not a 32bit value any more.


# 1.242 21-Feb-2007 mrg

shave 9 insns off the tsb setup in cpu_initialize & cpu_mp_startup.


# 1.241 21-Feb-2007 martin

Get rid of unused (thus always zero) "curlwp" variable hidden in assembler
code (C code always uses a cpuinfo based macro).


# 1.240 18-Feb-2007 martin

Make use of another call delay slot, pointed out by uwe.


# 1.239 18-Feb-2007 martin

Make use of a call delay slot and avoid a bogus EMPTY.
Spotted by Juergen Hannken-Illjes, with input from Andrew Doran and
Valeriy E. Ushakov.


# 1.238 18-Feb-2007 martin

Whitespace cosmetics


# 1.237 18-Feb-2007 martin

Backout previous: EMPTY was misused


# 1.236 18-Feb-2007 martin

Make EMPTY expand to nop with gas, as it is used to mark empty branch
delay slots.


# 1.235 15-Feb-2007 martin

branches: 1.235.2;
Fix obvious copy&pasto in SCHED_DEBUG register usage.


Revision tags: post-newlock2-merge
# 1.234 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.233 25-Dec-2006 wiz

Spell "relevant" correctly. From Zafer Aydogan.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.232 25-Oct-2006 mrg

branches: 1.232.2; 1.232.4;
- note that __idle_u should go away but doing so breaks things
- fix several comments to reality
- clean up the #ifdef NO_VCACHE code slightly
- use call instead of set/jmpl
- remove a couple of unnecessary stores to curlwp


Revision tags: yamt-splraiseipl-base2
# 1.231 18-Oct-2006 rjs

Clean up some comments. Cosmetic change to use correct structure
offset names.

Optimize out two instructions from sparc64_ipi_save_fpstate and
sparc64_ipi_drop_fpstate.


# 1.230 17-Oct-2006 mrg

allocate 128KB (as opposed to 64KB) per-cpu, and place the interrupt
stack, cpu_info structure, panicstack, idle uarea and normal kernel
stack in here. the idle uarea and kernel stack are in the 2nd 64KB
page. the interrupt stack and cpu_info structure are as the same
place in the 1st 64KB page, and the panicstack grows down from the
top of this page. update comments in param.h to suit (XXX: a lot
of these constants should move to a header file that will not pollute
the name space so much.) map these pages identically between
cpu_initialise() and cpu_mp_startup(), and deal with the two 64KB
pages in pmap_extract(). keep an unmapped 64KB page between them.

don't initialise the unused "ci_eintstack" member of the cpu_info
structure

use constants to initialise many addresses in the cpu_info structure,
consolidating these assignments from cpu0 and cpu>0

delete u0/estack0/panicstack from locore.s

clean up some wrong comments in locore.s

fix a 32bit-only bug in cpu_mp_startup().

delete 'u0' entirely.


this fixes recent random lossage seen on port-sparc64: processes
stuck in RUN state, data faults, and hangs.


# 1.229 04-Oct-2006 mrg

use call instead of set/jmpl. add an entry point for idle that expects
sched_lock to be unlocked, and use this for non-boot cpu's. complete a
comment describing how registers in idle_switch are expected to be set.


# 1.228 03-Oct-2006 mrg

use the same SAVE_LOCALS_INS definition for 32 bit and 64 bit kernels.
refactor TRAP_SETUP() a little between these two versions to be more alike.


# 1.227 03-Oct-2006 mrg

use the correct size/type for MP variables (pointers and longs).

a 32 bit MULTIPROCESSOR kernel now builds (and crashes quickly.)


# 1.226 03-Oct-2006 mrg

in the 64bit version of SAVE_LOCAL_INS, s/BIAS/STKB/ to allow future
sharing of the 32 and 64 bit versions of the {TRAP,INTR}_SETUP macros.


# 1.225 19-Sep-2006 mrg

- remove some way old FP setup/teardown code
- put the block memcpy/memset inside #ifdef USE_BLOCK_STORE_LOAD which
is (now) defined.

no functional change, same .o is generated.


# 1.224 19-Sep-2006 mrg

re-order the changes in rev 1.217 to give registers a little bit of
time to settle between usage, like it was before hand.


# 1.223 19-Sep-2006 mrg

- remove a wrong comment.
- add a new entry point for idle called idle_switch that is called by
cpu_switch() in the MP case when sched_whichqs is zero, properly
setting up the idle stack. from petrov@ via martin@.


# 1.222 19-Sep-2006 mrg

rework interrupt_vector() slightly:
- for the IPI case, avoid loading the address of intrlev into %g3
- remove some NOT_DEBUG code
- load the interrupt argument #2 in the delay slot

this removes 2 nops during interrupt processing for the normal
case, and an additional 2 ALU instructions for IPIs


# 1.221 18-Sep-2006 mrg

- sparc64_ipi_halt(): we shouldn't return from sparc64_ipi_halt_thiscpu()
so replace a branch with a 'sir'
- in #if 0 code, in sparc64_ipi_flush_pte() and sparc64_ipi_flush_ctx()
save/restore the out registers that the sp_tlb_flush_xxx() versions
around calling them
- in sp_tlb_flush_pte() and sp_tlb_flush_ctx(), replace global register
usage with out registers so that we don't clobber the (alternate)
global registers when these are called from IPI context


# 1.220 18-Sep-2006 mrg

- remove an extra 'sir' that followed one in a macro
- add some named labels to some spill/fill handlers
- remove 2 unused strings


Revision tags: yamt-splraiseipl-base
# 1.219 18-Sep-2006 martin

branches: 1.219.2;
Lazy FPU handling for the MULTIPROCESSOR case


# 1.218 16-Sep-2006 nakayama

From OpenBSD:
- reload %fprs for checking it again.
- use symbolic names for checking in %fprs.

revision 1.51
date: 2005/07/18 14:50:11; author: deraadt; state: Exp; lines: +2 -1
cache a copy of the fprs so we know what fp restore we should do after

revision 1.50
date: 2005/07/14 01:46:13; author: deraadt; state: Exp; lines: +4 -4
use symbolic names for checking in %fprs, as above


# 1.217 16-Sep-2006 nakayama

Fix a couple of %y register save/restore errors, inspired from OpenBSD.

revision 1.44
date: 2004/04/23 04:18:17; author: marc; state: Exp; lines: +5 -4

fix a couple of %y register save/restore errors
1) don't save %y in a register that is later used before restoring %y
2) always restore %y after calling a signal handler
tested by drahn@, OK pval


# 1.216 15-Sep-2006 martin

Do not bother to save fpu state when we are about to get rid of it.


Revision tags: yamt-pdpolicy-base9
# 1.215 13-Sep-2006 mrg

SMP cleanup. provide support for multiple CPUs in DDB. (SMP itself
is still not working.)

cpu.h:
- add a pointer for DDB regs in SMP environment to struct cpu_info
- remove the #defines for mp_pause_cpus() and mp_resume_cpus()
cpuset.h:
- remove CPUSET_ALL() and rename CPUSET_ALL_BUT() to CPUSET_EXCEPT()
from petrov.
db_machdep.h:
- rename the members of db_regs_t to be the same as sparc
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- redo DDB_REGS to no longer be a pointer to a fixed data structure
but to one allocated per-cpu when ddb is entered
- move a bunch of prototypes in here
intr.h:
- remove SPARC64_IPI_* macros, no longer used
db_interface.c:
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- make "nil" a 64 bit entity
- change the ddb register access methods to work in multiprocessor
environment, it is now very much like sparc does it
- in kdb_trap() avoid accessing ddb_regp when it is NULL
- update several messages to include the cpu number
- unpause other cpus much later when resuming from ddb
- rename db_lock() to db_lock_cmd(), as the sparc-like code has
db_lock as a simple lock
- remove "mach cpus" command, and replace it with "mach cpu" (which
does the same) and also implement "mach cpu N" to switch to
another cpus saved trapframe
db_trace.c:
- update for the ddb_regs -> ddb_regp change
genassym.cf:
- add TF_KSTACK as offsetof(struct trapframe64, tf_kstack)
ipifuncs.c:
- overhaul extensively
- remove all normal interrupt handlers as IPI's, we now handle
them all specially in locore.s:interrupt_vector
- add a simplelock around all ipi functions - it's not safe for
multiple cpus to be sending IPI's to each other right now
- rename sparc64_ipi_pause() to sparc64_ipi_pause_thiscpu() and,
if DDB is configured, enable it to save the passed-in trapframe
to a db_regs_t for this cpu's saved DDB registers.
- remove the "ipimask" system (SPARC64_IPI_* macros) and instead
pass functions directly
- in sparc64_send_ipi() always set the interrupt arguments to 0,
the address and argument of the to be called function. (the
argument right now is the address of ipi_tlb_args variable, and
part of the reason why only one CPU can send IPI's at a time.)
don't wait forever for an IPI to complete. some of this is
from petrov.
- rename sparc64_ipi_{halt,pause,resume}_cpus() to
mp_{halt,pause,resume}_cpus()
- new function mp_cpu_is_paused() used to avoid access missing
saved DDB registers
- actually broadcast the flush in smp_tlb_flush_pte(),
smp_tlb_flush_ctx() and smp_tlb_flush_all(). the other end may
not do anything yet in the pte/ctx cases yet...
kgdb_machdep.c:
- rework for changed member names in db_regs_t.
locore.s:
- shave an instruction from syscall_setup() (set + ld -> sethi + ld)
- remove some old dead debug code
- add new sparc64_ipi_halt IPI entry point, it just calls the C
vector to shutdown.
- add new sparc64_ipi_pause IPI entry point, which just traps into
the debugger using the normal breakpoint trap. these cpus usually
lose the race in db_interface.c:db_suspend_others() and end up
calling the C vector sparc64_ipi_pause_thiscpu().
- add #if 0'ed code to sparc64_ipi_flush_{pte,ctx}() IPI entry
points to call the sp_ version of these functions.
- in rft_kernel (return from trap, kernel), check to see if the
%tpc is at the sparc64_ipi_pause_trap_point and if so, call
"done" not "retry"
- rework cpu_switch slightly: save the passed-in lwp instead of
using the one in curlwp
- in cpu_loadproc(), save the new lwp not the old lwp, to curlwp
- in cpu_initialize(), set %tl to zero as well. from petrov.
- in cpu_exit(), fix a load register confusion. from petrov.
- change some "set" in delay branch to "mov".
machdep.c:
- deal with function renames
pmap.c:
- remove a spurious space
trap.c:
- remove unused "trapstats" variable
- add cpu number to a couple of messages


# 1.214 09-Sep-2006 mrg

significant clean up effort, largely from petrov@ via martin@.

- fix a bunch of comments for proc->lwp
- remove old TRAPTRACE, NOT_DEBUG, etc. code that has bit-rotted
- put some older DEBUG code under NOT_DEBUG
- add a bunch of new debugging/tracing code ("KTR") that depends on
other changes not yet present.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base yamt-pdpolicy-base5 chap-midi-base simonb-timecounters-base rpaulo-netinet-merge-pcb-base
# 1.213 14-May-2006 elad

branches: 1.213.6; 1.213.8;
integrate kauth.


# 1.212 12-May-2006 skrll

Fix some comments.


Revision tags: elad-kernelauth-base
# 1.211 09-May-2006 rjs

Load CPCB in cpu_mp_startup.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.210 11-Feb-2006 cdi

branches: 1.210.2; 1.210.4; 1.210.6;
ANSIfication: u_intN_t -> uintN_t, use ANSI function declarations/definitions
instead of K&R ones.


# 1.209 27-Jan-2006 cdi

branches: 1.209.2; 1.209.4;
Alter sparc64 bootstrap, catch up to ofwboot v1.9:

- Accept bootinfo structure passed down from ofwboot v1.9
- Drop kernel re-mapping code
- Use permanent 4MB mappings provided by the loader instead
- Change kernel entry address to point directly at the code instead of pointing
at the trap table's first slot. This allows the bootloader to detect
those kernels which are aware of the new boot scheme
- Due to the changes in kernel mapping code, alter secondary CPU bootstrap
code to use trampoline just like FreeBSD does (some FreeBSD code is used
here as well)


# 1.208 12-Jan-2006 cdi

Fix a typo: %g0 should be used instead of %o0 when initializing FPU in dostart:
and cpu_mp_startup:, %o0 is not even initialized at this point.


# 1.207 11-Dec-2005 christos

branches: 1.207.2;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 1.206 10-Jul-2005 christos

Re-factor syscall, and make it use syscall_{plain,fancy}.


# 1.205 31-May-2005 chs

branches: 1.205.2;
remove vestigal {,e}intr{names,cnt} symbols now that vmstat doesn't need them.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.204 12-Feb-2005 chs

branches: 1.204.4; 1.204.6; 1.204.8;
in sparc_interrupt(), wait to enable interrupts until just before calling
the handler and disable them again right after the handler returns.
we don't want another hardware interrupt coming in while we're mucking
with the list pointers. also, clear the intrhand's ih_pending pointer
before calling the handler rather than after, so that if another interrupt
comes in while the handler is running, we can put the intrhand back on
the list so it will be called again.

in send_softint(), disable interrupts via %pstate instead of %pil, so that
hardware interrupts at higher levels are blocked while we manipulate the
intrpending list. also, if the intrhand already has ih_pending set,
don't bother poking the SET_SOFTINT register again, since being on the list
implies that there is already a softint pending in the hardware.

these appear to fix PR 21750 (the "sleep forever" problem).

while I'm here, remove more vestiges of the !INTRLIST softint stuff
(code and comments). and in sparc64_ipi_flush_all(), interrupts are
already disabled so we don't need to fiddle with %pstate.


Revision tags: yamt-km-base2
# 1.203 30-Jan-2005 martin

Remove the no long usefull variants selected by undefining INTRLIST and
INTR_INTERLOCK to improve readability. Same object code generated as before.


Revision tags: yamt-km-base
# 1.202 16-Jan-2005 chs

branches: 1.202.2;
use ENTRY_NOPROFILE() for various entry points,
stack traces work better that way.


Revision tags: kent-audio1-beforemerge kent-audio1-base
# 1.201 03-Dec-2004 chs

branches: 1.201.4;
remove cache_flush_virt() and PADDRT, they're no longer used.
allocate a stack frame for blast_dcache() when profiling so it shows up.
in dcache_flush_page(), use a stride of 32 instead of 16 to match the
cache line size. correct various comments.


# 1.200 08-Nov-2004 petrov

Don't compile sparc64_ipi functions when UP.


# 1.199 25-Oct-2004 martin

No need to clear %o1 when returning a 64 bit integer from pseg_get if we
are compiling for a 64 bit kernel.


# 1.198 24-Jul-2004 nakayama

Change interrupt pending list end value to -1, to avoid linking an
interrupt handler twice.

It may fix "sleep forever" bug.


# 1.197 09-Apr-2004 petrov

Clean-up unused defines and variables.


Revision tags: netbsd-2-0-base
# 1.196 26-Mar-2004 petrov

branches: 1.196.2;
Use want_resched from cpu_info area.


# 1.195 23-Mar-2004 martin

Replace intrcnts by evcnts. XXX - needs slight tweaking for MULTIPROCESSOR.


# 1.194 14-Mar-2004 chs

checkpoint of MP work from dennis and myself. includes cross-processor
interrupt framework, a sledgehammer TLB invalidation and misc MP fixes.
doesn't work at all yet.


# 1.193 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.192 19-Jan-2004 martin

Rename switchexit to cpu_exit and g/c the old C implementation of cpu_exit.


# 1.191 18-Jan-2004 martin

Support RAS for 32bit kernels too.


# 1.190 16-Jan-2004 martin

In proc_trampoline don't bother to clear condition codes in the trap
frame, since we no longer rely on this.
While there fix a few comments.


# 1.189 08-Jan-2004 martin

Minor cleanup


# 1.188 06-Jan-2004 martin

Implement restartable atomic sequences (RAS) for sparc64.


# 1.187 06-Jan-2004 petrov

Spinup secondary cpus. Based on codes sent to me by Dennis Chernoivanov
and Chuck Silvers.


# 1.186 04-Jan-2004 jdolecek

update to recent changes - exit2() doesn't exist anymore and the
exit path always calls lwp_exit2()
pointed out Martin Husemann


# 1.185 02-Dec-2003 martin

Minor cleanup: remove unused code, sync a comment with current reality.


# 1.184 25-Nov-2003 cdi

Use per-cpu pcb, curlwp and fplwp rather than global ones. This brings
GENERIC.MP configuration to a usable state.

Approved by petrov@.


# 1.183 24-Nov-2003 cdi

Call 'proc_trampoline_mp' from 'proc_trampoline' in a multiprocessor
configuration. Fix process locking. Approved by petrov@.


# 1.182 20-Nov-2003 petrov

Remove nwindows calculation, it's not used. Set l_cpu in cpu_switch.


# 1.181 09-Nov-2003 martin

Get rid of bcopy/bzero.


# 1.180 26-Oct-2003 christos

Initial siginfo support for sparc64 (untested). COMPAT_16 sigcontext signal
delivery tested.


# 1.179 24-Aug-2003 chs

add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default. the changes
fall into two basic catagories:

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

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

originally from openbsd, adapted for netbsd by me.


# 1.178 08-Jul-2003 cdi

traceit: don't use %g7 as it is to become curcpu() register. Add comments.


# 1.177 18-May-2003 martin

branches: 1.177.2;
Make kernels with options KGDB at least compile.
Still needs some work to make it working.


# 1.176 29-Apr-2003 nakayama

Use BLOCK_ALIGN rather than BLOCK_SIZE for aligning a pointer.


# 1.175 27-Apr-2003 ragge

Preserve the symbol table in the LKM || KSYMS cases also.


# 1.174 04-Apr-2003 petrov

use branch slot in pmap_copy_page.


# 1.173 24-Mar-2003 nakayama

Divide `set' instruction in delay slot (from OpenBSD change to rev 1.30).


# 1.172 10-Feb-2003 martin

Remove some #if 0 code and a few XXX marked membars w/o proper
justification for their existence.


# 1.171 09-Feb-2003 martin

Remove left over pieces from reusing the signal trampoline for upcalls.
This should fix signal delivery for 32bit kernels.


# 1.170 05-Feb-2003 nakayama

Switch to use cycle counter (%tick) based microtime().

This is derived from alpha/microtime.c and i386/tsc_microtime.c,
and will share with both ports.

This should fix PR port-sparc64/18452.
(approved by martin)


# 1.169 04-Feb-2003 martin

Fix return value of pseg_set, which I accidently broke in rev. 1.164.

Fix register names in comment and shave off another register (hint
from uwe).


# 1.168 01-Feb-2003 martin

Rearrange register usage in pseg_set a bit and shave off %g4.


# 1.167 01-Feb-2003 martin

Remove a few #ifdef _LP64 by using STPTR/LDPTR macros.
Thanks to Matthew Green for the pointer.


# 1.166 31-Jan-2003 martin

Apply leaf procedure optimization to pseg_set (again).


# 1.165 31-Jan-2003 martin

Make the pmap count resident/wired mappings on the fly instead of
walking the page tables whenever this information is needed.

Add an option PMAP_COUNT_DEBUG to assert the new counts and the
page table walk agree.

The old solution had very bad performance impact, for example
by the high CPU load when running top(1).

Thanks to Simon Burge for pointing at the cause of the problem and
to Valeriy E. Ushakov for optimizing my simple minded assembler code.


# 1.164 27-Jan-2003 martin

Remove unused function pseg_find (which looked quite similar to
pseg_get anyway).


# 1.163 18-Jan-2003 thorpej

Merge the nathanw_sa branch.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.162 16-Jan-2003 petrov

Move dump_dtlb back under DDB.


# 1.161 15-Jan-2003 chs

fix two bugs in my last pmap rework:
- in tlb_flush_all(), don't skip TLB entries with the high bit on,
I was confused about which MMU register it was using. it's also fine
to use the last hardware context.
- in pmap_create(), don't allocate a hardware context for the new pmap.
it's unnecessary, and when this would cause us to recycle all the contexts,
it would result in the current process's context being set to 0
(ie. the kernel's context). the current process could then return to
userspace without going through the context-switch code (and thus without
having a hardware context reallocated). this would lead to user mappings
being entered in the kernel's context later, causing all sorts of trouble.
add some assertions to catch this kind of thing.


Revision tags: fvdl_fs64_base
# 1.160 25-Dec-2002 petrov

new function dump_itlb.


Revision tags: gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.159 22-Sep-2002 chs

many improvements:
- use struct vm_page_md for attaching pv entries to struct vm_page
- change pseg_set()'s return value to indicate whether the spare page
was used as an L2 or L3 PTP.
- use a pool for pv entries instead of malloc().
- put PTPs on a list attached to the pmap so we can free them
more efficiently (by just walking the list) in pmap_destroy().
- use the new pmap_remove_all() interface to avoid flushing the cache and TLB
for each pmap_remove() that's done as we are tearing down an address space.
- in pmap_enter(), handle replacing an existing mapping more efficiently
than just calling pmap_remove() on it. also, skip flushing the
TSB and TLB if there was no previous mapping, since there can't be
anything we need to flush. also, preload the TSB if we're pre-setting
the mod/ref bits.
- allocate hardware contexts like the MIPS pmap:
allocate them all sequentially without reuse, then once we run out
just invalidate all user TLB entries and flush the entire L1 dcache.
- fix pmap_extract() for the case where the va is not page-aligned and
nothing is mapped there.
- fix calculation of TSB size. it was comparing physmem (which is
in units of pages) to constants that only make sense if they are
in units of bytes.
- avoid sleeping in pmap_enter(), instead let the caller do it.
- use pmap_kenter_pa() instead of pmap_enter() where appropriate.
- remove code to handle impossible cases in various functions.
- tweak asm code to pipeline a little better.
- remove many unnecessary spls and membars.
- lots of code cleanup.
- no doubt other stuff that I've forgotten.

the result of all this is that a fork+exit microbenchmark is 34% faster
and a fork+exec+exit microbenchmark is 28% faster.


Revision tags: gehenna-devsw-base
# 1.158 18-Jul-2002 wiz

Spell 'should' correctly.


# 1.157 07-Jun-2002 eeh

Shave 10% off the time needed to flush the D$ through a bit of instruction
reordering.


# 1.156 05-Jun-2002 eeh

Handle improperly aligned stack pointers more cleanly.


# 1.155 04-Jun-2002 eeh

Fix the fork trampoline to properly use the supplied tstate.


# 1.154 31-May-2002 thorpej

Make this work with an ISO C preprocessor.


Revision tags: netbsd-1-6-base
# 1.153 14-May-2002 eeh

branches: 1.153.2; 1.153.4;
Only save locals and ins in trapframes for DEBUG kernels.


# 1.152 04-May-2002 kleink

Add some comments to the CPP conditionals controlling the trap macro
definitions, to ease navigation somewhat.


# 1.151 16-Apr-2002 eeh

Make lots of routines profile-friendly and get rid of some cruft.


Revision tags: eeh-devprop-base
# 1.150 21-Mar-2002 petrov

Not needed debug stuff deleted.


# 1.149 16-Mar-2002 mrg

tell newer binutils that our use of %g2 and %g3 is OK here.


# 1.148 15-Mar-2002 eeh

Cleanup MMU initialization to prevent hangs.


Revision tags: newlock-base ifpoll-base
# 1.147 09-Feb-2002 eeh

branches: 1.147.4;
Fix microsecond calculation in microtime.


# 1.146 07-Feb-2002 eeh

Fix register allocation in microtime().


# 1.145 29-Jan-2002 eeh

Shift the UPAID in the correct direction.


# 1.144 17-Jan-2002 eeh

Be more tolerant of unaligned stack pointers.


# 1.143 17-Jan-2002 eeh

Enable block insns in bcopy and bzero.


# 1.142 16-Jan-2002 eeh

In bcopy use 32-bit comparisons in 32-bit kernels.


# 1.141 16-Jan-2002 eeh

Use correct calculation for the trapframe in softtrap for ILP32.


# 1.140 20-Nov-2001 lukem

- pull in opt_kgdb.h where necessary
- replace opt_kgdb_machdep.h with opt_kgdb.h
- defparam opt_kgdb.h:
KGDB_DEV KGDB_DEVNAME KGDB_DEVADDR KGDB_DEVRATE KGDB_DEVMODE
- move from opt_ddbparam.h to opt_ddb.h:
DDB_FROMCONSOLE DDB_ONPANIC DDB_HISTORY_SIZE DDB_BREAK_CHAR SYMTAB_SPACE
- replace KGDBDEV with KGDB_DEV
- replace KGDBADDR with KGDB_DEVADDR
- replace KGDBMODE with KGDB_DEVMODE
- replace KGDBRATE with KGDB_DEVRATE
- use `9600' instead of `0x2580' for 9600 baud rate
- use correct quotes for options KGDB_DEVNAME="\"com\""
- use correct quotes for options KGDB_DEV="17*256+0"
- remove unnecessary dependancy on Makefile for kgdb_stub.o
- minor whitespace cleanup


Revision tags: thorpej-mips-cache-base thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf
# 1.139 14-Sep-2001 thorpej

branches: 1.139.4;
Don't declare intrhand[] here -- that's taken care of in intr.c.


Revision tags: thorpej-devvp-base
# 1.138 30-Aug-2001 eeh

branches: 1.138.2;
Preliminary UltraSPARC III suport (not enabled yet).


# 1.137 13-Aug-2001 jdolecek

g/c _remque()/_insque(); use the C version in libkern


# 1.136 09-Aug-2001 eeh

Fix context masking lossage caused by last version.


# 1.135 08-Aug-2001 eeh

Clean up the trap code to handle the changes cause by supporting non-faulting
accesses. Also change the parameter order so trap frames are easy to find.


# 1.134 07-Aug-2001 eeh

Make sure C code always has ASI_PRIMARY_NOFAULT in the %asi register so
the compiler will be happy if it ever starts generating speculative loads.


# 1.133 05-Aug-2001 eeh

Add support for non-faulting loads and optimize MMU miss handling paths.


# 1.132 02-Aug-2001 eeh

Fix bcopy.


# 1.131 02-Aug-2001 eeh

Sync bzero w/libc version.


# 1.130 01-Aug-2001 eeh

Integrate fixes from userland memset.


# 1.129 31-Jul-2001 eeh

Code cleanup and optimization.


# 1.128 23-Jul-2001 eeh

Get rid of some debug code that really isn't all that useful any more.


# 1.127 19-Jul-2001 eeh

Do ignore unregistered interrupts instead of faulting.


# 1.126 16-Jul-2001 eeh

Make bcopy a 32-bit friendly.


# 1.125 11-Jul-2001 eeh

Fix problems booting 32-bit kernels and dispatching level-15 interrupts.


# 1.124 08-Jul-2001 eeh

branches: 1.124.2;
Code cleanup. Add block_disable to let you turn on block set/copy routines.


# 1.123 05-Jul-2001 eeh

New block bzero and bcopy.


# 1.122 04-Jul-2001 eeh

Replace old bcopy with a much faster version.


# 1.121 01-Jul-2001 martin

Disable axidently enabled debug code to make -current compile again.


# 1.120 30-Jun-2001 eeh

Use a newer version (still disabled) of block bcopy.


# 1.119 30-Jun-2001 eeh

Fixup fpu save restore, get rid of some unused copy functions, and add
a new bcopy.


# 1.118 21-Jun-2001 eeh

Allow multiple 4MB pages for both kernel text and kernel data.

Note: DEBUG checks will not allow accesses to the hole between
text and data segments, so you may need to update programs that
use libkvm before relocating the start of kernel data.


# 1.117 06-Jun-2001 mrg

extract the netbsd32, sunos, 32 bit svr4 and 64 bit svr4 sigcode out into
separate files, so that compat lkms can link with them as well.


# 1.116 30-May-2001 lukem

add missing #include "opt_kgdb.h"


Revision tags: thorpej_scsipi_beforemerge
# 1.115 25-Apr-2001 simonb

Spell occurred correctly.


Revision tags: thorpej_scsipi_nbase thorpej_scsipi_base
# 1.114 09-Apr-2001 eeh

Interrupt latency fix from sparc port. (Hm. One insn instead of 5).


# 1.113 07-Mar-2001 eeh

Fix inverted preprocessor logic. (Spotted by Charles.)


# 1.112 21-Feb-2001 eeh

branches: 1.112.2;
Add support for 64-bit SVR4 (Solaris 8) binaries.


# 1.111 10-Feb-2001 pk

Fix conditional for svr4 compat inclusion.


# 1.110 05-Feb-2001 eeh

Add signal trampoline for 64-bit svr4 emulations.


# 1.109 31-Dec-2000 eeh

Make INCR() atomic.


# 1.108 29-Dec-2000 eeh

pseg_get tells us whether it really needed that spare page after all.


# 1.107 07-Dec-2000 eeh

Fixup calculating where fpstate should be saved in the signal trampoline
code so it doesn't overwrite something important like the registers.


# 1.106 09-Nov-2000 eeh

Fix ILP32 bug in probe_get().


# 1.105 22-Oct-2000 pk

Restore revision 1.102.

I hope it sticks this time..


# 1.104 20-Oct-2000 eeh

Fix hang in 32-bit kernels caused by relocation of KERNBASE.


# 1.103 04-Oct-2000 eeh

Fix interrupt lossage problem and some cosmetic changes.


# 1.102 01-Oct-2000 pk

cpu_initialize: global registers aren't preserved across calls to
prom_printf(), so replace %g3 with %l7 (which isn't used despite
the `usage' comment).

Also, clean up white-space turds.


# 1.101 29-Sep-2000 eeh

This seems to fix the interrupt lossage of non-debug kernels.


# 1.100 28-Sep-2000 eeh

Fix INTR_SETUP() to properly distinguish kernel and user addresses.

Make microtime() return the correct time on %tick machines.

Re-enable debug stuff in dostart for now to detect kernel mapping issues.


# 1.99 25-Sep-2000 pk

Missing `#if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)'


# 1.98 17-Sep-2000 eeh

Make the improved %tick changes work with machines that use the counter-timer
for the clock.


# 1.97 12-Sep-2000 eeh

Fix new version of microtime.


# 1.96 11-Sep-2000 eeh

(Hopefully) fix clock skew on machines that us %tick for the clock (UIIi).


# 1.95 31-Aug-2000 eeh

Use casx instead of stx to change entries in the page table trees.


# 1.94 23-Aug-2000 eeh

Update the scheduler to the new locking scheme.


# 1.93 10-Aug-2000 eeh

Fix signal delivery.


# 1.92 02-Aug-2000 eeh

Get kernel profiling to work. Now if only gprof worked....


# 1.91 01-Aug-2000 eeh

Overhaul cache flush code and coredump code.


# 1.90 25-Jul-2000 pk

Re-instate a couple of delay slot NOPs marked `XXX spitfire bug?'


# 1.89 24-Jul-2000 mycroft

Optimization to pmap_zero_page(): we only need to use the first 16 FP regs,
as in bzero().


# 1.88 24-Jul-2000 mycroft

Fix a whitespace glitch.


# 1.87 24-Jul-2000 mycroft

Pull in the bzero() changes from libc for real, with a couple of kernel-
specific hacks:
* Make the bias handling depend on STKB, so it switches correctly for 32-bit
kernels.
* Use the 32-bit stw/ld for 32-bit kernels.
* Add a few `-STKB's that were missed in the previous change.


# 1.86 24-Jul-2000 pk

Cosmetic & readability:
- local label cleanup in interrupt handling code;
- in debugging sections when testing `intrdebug': use a unique
local label (97) to enhanced clarity;
- comment-out unused code;
- kill a bug as the satisfying result of doing all of the above.


# 1.85 24-Jul-2000 eeh

Fix stack issues in bzero.


# 1.84 24-Jul-2000 mycroft

Revert the previous change for now. I don't have time to debug it tonight.


# 1.83 23-Jul-2000 mycroft

Copy bzero change from libc.


# 1.82 20-Jul-2000 pk

Since `intrcnt' points to an array of long ints, reserve the appropriate
amount of space depending on _LP64. Provide macros to load/store signed
and unsigned long ints.

Also, make the `intrcnt' and `intrpending' arrays 16 entries long, as on
sparc/v9 interrupt #15 is just a regular interrupt.


# 1.81 19-Jul-2000 eeh

Fix merge problem.


# 1.80 19-Jul-2000 eeh

Disable interrupt interlock using ih->ih_pending field. Seems to cause
more problems than it solves.


# 1.79 19-Jul-2000 eeh

Miscellaneous cleanup.


# 1.78 18-Jul-2000 pk

Correct args usage comment in probeget.
Whitespace cleanup.


# 1.77 18-Jul-2000 pk

probeget: 9 -> 0x9


# 1.76 18-Jul-2000 pk

If `ih_pending' is set simply return from the trap, don't schedule another
soft interrupt.


Revision tags: mrg-merge-1-5-top
# 1.75 18-Jul-2000 pk

openfirmware: don't lower %pil


# 1.74 17-Jul-2000 pk

Kill typos in interrupt code.


# 1.73 17-Jul-2000 pk

probeget: do the same song and dance as ld*a() macros in ctlreg.h do.


# 1.72 14-Jul-2000 eeh

Move some macro definitions out of genassym and into locore.s


# 1.71 08-Jul-2000 mrg

backout part of previous: turn off intrdebug, and another debug message


# 1.70 07-Jul-2000 pk

Changes for readability:
- #define LP64 dependent STACKFRAME macro once
- use a LOAD_ASCIZ macro for setting up the format string
for debug messages.


# 1.69 07-Jul-2000 eeh

Temporary fix to prevent the clock from stopping on UIIi machines.


# 1.68 03-Jul-2000 eeh

Prevent interrupts from being posted if they are active and deprecate polled
interrupts. This seems to eliminate the spurious interrupts.


# 1.67 02-Jul-2000 eeh

Clean up interrupt handling some more.


# 1.66 30-Jun-2000 eeh

Fix interrupt delivery on UltraSPARC IIi machines.


# 1.65 24-Jun-2000 eeh

With these changes the kernel seems almost stable again.


# 1.64 24-Jun-2000 eeh

More VM cleanup:

Move the cpu_info structure above the interrupt stack so it won't
get corrupted if the stack overflows.

Flush the D$ before and after all MMU bypass accesses since the
D$ latches all of those.


# 1.63 23-Jun-2000 eeh

Make probeget() and probeset() really work for a change.


Revision tags: netbsd-1-5-base
# 1.62 19-Jun-2000 eeh

branches: 1.62.2;
Have separate data and text segments, make text read-only.


# 1.61 12-Jun-2000 eeh

Start reorganizing the kernel for MULTIPROCESSOR support.


# 1.60 31-May-2000 thorpej

Add a comment about needing to initialize p_cpu when multiple
processors are supported.


Revision tags: minoura-xpg4dl-base
# 1.59 26-May-2000 thorpej

branches: 1.59.2;
First sweep at scheduler state cleanup. Collect MI scheduler
state into global and per-CPU scheduler state:

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

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

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

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

Tested on i386 and Alpha. Changes are mostly mechanical, but apologies
in advance if it doesn't compile on a particular platform.


# 1.58 26-May-2000 thorpej

Don't set `runtime' here; it's done at the end of mi_switch().
cvS: ----------------------------------------------------------------------


# 1.57 26-May-2000 thorpej

Introduce a new process state distinct from SRUN called SONPROC
which indicates that the process is actually running on a
processor. Test against SONPROC as appropriate rather than
combinations of SRUN and curproc. Update all context switch code
to properly set SONPROC when the process becomes the current
process on the CPU.


# 1.56 22-Apr-2000 eeh

If we trap due to a bad kernel stack, try to switch to the interrupt strack
before breaking into the debugger.


# 1.55 18-Apr-2000 eeh

Prevent the system from getting watchdog reset by returning directly to user
mode if restoring the user window traps. Also reduce the time we run with
%tl>0.


# 1.54 13-Apr-2000 eeh

Apparently gas 2.9.5 (don't ask) does not like to add values to %lo()
directives so move the additions inside %lo() to make it happy.
Hopefully this won't break older versions.


# 1.53 10-Apr-2000 mrg

- fix a speeling error
- rename some numbered labels to be a bit less confusing.
- remove dead code
- fix a debug error message (argh!)


# 1.52 10-Apr-2000 pk

Get a kernel without DDB to build.


# 1.51 16-Mar-2000 eeh

Revamp interrupts again:

Fix a bug causing interrmittent panics in interrupt dispatch.
Use interrupt vectors for softints.
Add a new send_softint interface.
Improved D$ flushing.
Improve traptrace and other debugging enhancements.


Revision tags: chs-ubc2-newbase
# 1.50 16-Jan-2000 eeh

Interrupt handlers return zero if they didn't handle the interrupt.


# 1.49 10-Jan-2000 eeh

Add debugger single-stepping and fix interrupt dispatch bugs.


# 1.48 30-Dec-1999 eeh

Lots of changes:

remove ffs()
add bzero that uses block store insns
save %gsr to fpstate
revert to physical accesses for pmap_zero_page so we don't
have conflicting page mappings
general cleanup.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base fvdl-softdep-base
# 1.47 06-Nov-1999 eeh

Handle zero length properly in copyinstr() copyoutstr() and copystr().


Revision tags: comdex-fall-1999-base
# 1.46 11-Oct-1999 eeh

branches: 1.46.2; 1.46.4;
Update to post 1.4.


# 1.45 05-Oct-1999 eeh

branches: 1.45.2;
Make broken versions of gas happy by using sethi/or instead of set for
(negative) addresses.


# 1.44 17-Sep-1999 thorpej

Centralize the declaration and clearing of `cold'.


Revision tags: chs-ubc2-base
# 1.43 18-Jul-1999 eeh

More fun with pmap.


# 1.42 21-Jun-1999 eeh

Improve TRAPTRACE. Add FLTRACE that only tracks MMU faults.


# 1.41 05-Jun-1999 eeh

Make pbrobeget() and probeset() work for 64-bit values as well. To do this
the arguments are changed so the address is first and the ASI second so we
can have the address in %o0:%o1 and not worry about unused registers.

Also a bit of copyright cleanup.


# 1.40 05-Jun-1999 mrg

update a commit slightly.


# 1.39 30-May-1999 eeh

Add code to support using %tick as the system clock if no "counter-timer" node
is found.


# 1.38 09-May-1999 eeh

Fixup non-DEBUG kernels.


# 1.37 29-Apr-1999 christos

Add sunos_sigcode (32 bit only)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.36 26-Mar-1999 eeh

branches: 1.36.4;
COMPAT_SPARC32 -> COMPAT_NETBSD32


# 1.35 25-Mar-1999 mrg

clean and up make compile


# 1.34 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.33 22-Mar-1999 eeh

Need to set up the pointers properly for partial FPU register stores.


# 1.32 22-Mar-1999 eeh

Flush D$ on bypass accesses.


# 1.31 28-Feb-1999 eeh

Use block load/store in pmap_zero_page()/pmap_copy_page().


# 1.30 17-Feb-1999 eeh

Let's test out vectored interrupts.


# 1.29 15-Feb-1999 hubertf

RCS ID police


# 1.28 11-Feb-1999 mrg

fix a comment pasto.


# 1.27 11-Jan-1999 eeh

Finally fixed 64-bit signal trampoline.


# 1.26 10-Jan-1999 eeh

Handle the symbol table properly in a 32-bit kernel that was booted from a
64-bit bootloader.


# 1.25 09-Jan-1999 eeh

More signal fixup.


Revision tags: kenh-if-detach-base
# 1.24 26-Nov-1998 mycroft

Sync kcopy() with 32-bit SPARC version.


# 1.23 16-Nov-1998 eeh

Fixup the last broken bits of the signal handling code.


Revision tags: chs-ubc-base
# 1.22 08-Oct-1998 eeh

Fix more syscall32 and signal breakage.


# 1.21 22-Sep-1998 eeh

More fixup in the signal area.

64-bit syscall cleanup.

Add emulation for some new FPU insns: conversion to 64-bit long int and
conditional moves.


# 1.20 17-Sep-1998 thorpej

SYS_sigreturn -> SYS___sigreturn14.


# 1.19 13-Sep-1998 eeh

Fixup signal changes (hopefully). However SUN_COMPAT is likely broken by
this and I don't know how to fix it.

We can now exec a 64-bit init through a really ugly hack (don't ask.)


# 1.18 11-Sep-1998 eeh

Add labels for the compat_sparc32 signal trampoline and break -- er -- fix
suword and fuword.


# 1.17 09-Sep-1998 eeh

Don't use %tick for microtime on 32-bit kernels -- breaks gettimeofday.


# 1.16 09-Sep-1998 thorpej

Adjust for the new "reaper" kernel thread: do not free the vmspace and
u-area in machine-dependent code. Instead, call exit2() to schedule
the reaper to free them for us, once it is safe to do so (i.e. we are
no longer running on the dead proc's vmspace and stack).


# 1.15 07-Sep-1998 eeh

Fix data corruption problem caused by broken debug code.


# 1.14 07-Sep-1998 eeh

Add new 64-bit trap vectors.


# 1.13 06-Sep-1998 eeh

32-bit fixup.


# 1.12 06-Sep-1998 eeh

Disable some debug stuff.


# 1.11 05-Sep-1998 eeh

It slices. It dices. It does everything except exec a sparc32_compat init.


# 1.10 02-Sep-1998 eeh

Periodic update: now starts probing devices.


# 1.9 30-Aug-1998 eeh

Some more 64-bit cleanup. Now everything compiles.


# 1.8 29-Aug-1998 eeh

Some more 64-bit-ification.


# 1.7 27-Aug-1998 eeh

Add 64-bit pmap support:

Moved from a two level 512/1024 entry setup mapping 32 (9/10/13) bits
respectively to a three level 1024/1024/1024 entry setup mapping 43
(10/10/10/13) bits. In 32-bit mode we waste about 1/12 pages mapping the high
11 bits. We also only manage 43 of the possible 44 bits of virtual address
space, wasting half of it. Oh well, maybe we'll do better next revision.


Revision tags: PMAP32
# 1.6 26-Aug-1998 mrg

panicstack: is needed outside of DEBUG. use _C_LABEL, and printf not db_printf (incase no ddb!)


# 1.5 13-Aug-1998 eeh

Merge paddr_t changes into the main branch.


Revision tags: eeh-paddr_t-base
# 1.4 07-Jul-1998 eeh

branches: 1.4.2;
General update:

Added genassym.cf
Removed lderr which should never have gotten in
Removed lots of dead code from locore.s
Added some softint stuff to intr.c
Added support for halt -p
esp and le both use bus_dmamap_*() functions now
instead of kdvma_mapin()
groundwork for PCI (but we still have no drivers for
any sun4u PCI devices)


# 1.3 04-Jul-1998 jonathan

defopt DDB.


# 1.2 26-Jun-1998 thorpej

defopt COMPAT_SVR4


# 1.1 20-Jun-1998 eeh

branches: 1.1.1;
Initial revision


# 1.402 29-Dec-2016 palle

sun4v: make debugging kernel bringup a bit easier by using the slowtrap code path for currently unhandled trap level 1 trap entries 0x32-0x7f


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.401 20-Sep-2016 nakayama

Fix RAS for 32-bit kernels. trapframe is always 64-bit.


Revision tags: localcount-20160914
# 1.400 23-Aug-2016 palle

sun4v: rework sun4v_datatrap so it works properly when running on a T2-based system like T5120 - for some reason %tl is 0 when entering sun4v_datatrap causing a crash (sir instruction), so ignore the %tl value for now upon entry to sun4v_datatrap - with this fix both T1 and T2 based systems reach the same point - hangs in rft_user after the init process is started


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726
# 1.399 18-Jul-2016 palle

sun4v: handle device interrupts properly - both legacy (sysino) and cookies


Revision tags: pgoyette-localcount-base nick-nhusb-base-20160907
# 1.398 04-Jun-2016 palle

branches: 1.398.2;
sun4v: rtf_user now uses macros GET_MMU_CONTEXTID and SET_MMU_CONTEXTID. Tested on sun4u (QEMU) and sun4v (T2000). Parts from OpenBSD.


Revision tags: nick-nhusb-base-20160529
# 1.397 18-May-2016 nakayama

Decrement %tl in trap handler not to make it zero unconditionally
for the nested trap, and remove useless mov.


# 1.396 17-May-2016 palle

sun4v: Implement missng MMU protection trap handling - mostly from OpenBSD


# 1.395 16-May-2016 palle

Avoid assembler-specific defines by using the export keyword in genassym.cf instead


# 1.394 15-May-2016 nakayama

%g1 is not preserved across function call, so load it before
return_from_trap.


# 1.393 13-May-2016 palle

sun4v: add missing implementation of sun4v_datatrap_tl0 so data_access_fault() is called - mostly from OpenBSD


# 1.392 13-May-2016 nakayama

- ci_paddr is always 64-bit.
- intrlev is array of pointer.
- ih_ack is pointer.


# 1.391 10-May-2016 palle

sun4v: make device interrupts work. Introduce a new intrhand_alloc() function for allocation of interrupt handlers and adapt to this. Parts from OpenBSD. ok martin@


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.390 09-Mar-2016 nakayama

32-bit kernels use 32-bit stack.


# 1.389 03-Mar-2016 palle

sun4v: rft_kernel should pay attention to the number of register windows that can be restored. We cannot rely on fill traps to occur, since sun4v only has two trap levels available in privileged mode. Based on code from OpenBSD. ok martin@


# 1.388 14-Feb-2016 palle

sun4v: add breakpoint trap entry to the sun4v trap table


# 1.387 03-Feb-2016 palle

sun4v: extend dmmu_set_secondary_context() to handle both sun4u and sun4v. ok martin@


Revision tags: nick-nhusb-base-20151226
# 1.386 06-Nov-2015 martin

Basically revert r1.246 of locore.s and r1.73 of vm_machdep.c:

Remove special case handling for userland lwps from cpu_lwp_fork,
instead do it in lwp_trampoline when we first return to userland.

which was a stupid idea - since we did now set all fork child's %tstate
(and thus %pstate when back in userland) to the current kernel's userland
default. This meant we lost the address mask bit for 32bit processes and
all memory model details for 64bit ones.

Move it back to cpu_lwp_fork and fix the condition to only do it once when
forking init.


# 1.385 05-Nov-2015 martin

Most of the time return_from_trap already got called with tf->tf_tstate
loaded in register %g1 - make it so for two more callers and remove
the reload of that value.


Revision tags: nick-nhusb-base-20150921 nick-nhusb-base-20150606 nick-nhusb-base-20150406
# 1.384 05-Apr-2015 palle

sun4v: Ensure that the TTEs CP and CV bits are the same (both set) for the primary cpu and secondary cpus INTSTACK mappings


# 1.383 01-Apr-2015 palle

sun4v: Implement handling of cpu_mondo trap - from OpenBSD - tested using the Legion simulator


# 1.382 04-Mar-2015 palle

sun4v: revert some of the logic introduced in revision 1.378 - flushw is not necessary on sun4v (OpenBSD patches the flushw instruction to a nop instruction) - with these changes the kernel reaches cpu_boot_secondary_processors() when running in the Legion simulator (crashes due to missing handling of cpu_mondo_trap)


# 1.381 02-Mar-2015 nakayama

prom_printf converts "\n" to "\r\n" internally, so omit "\r".


# 1.380 02-Mar-2015 nakayama

PANICSTACK is a pointer itself, not a pointer to pointer.


# 1.379 02-Mar-2015 nakayama

Use panic stack temporarily for calling prom_printf in a trap
handler.

It seems that openfirmware cannot handle over 4GB pointers, and
stack pointers may point to over 4GB since VA layout was rearranged
by rev 1.33 of vmparam.h. Therefore, use panic stack to avoid
panicking in OF_write used by prom_printf.


# 1.378 23-Feb-2015 palle

sun4v: sparc_interupt - ensure that the trap level and globals level are the same when the flushw instruction is issued - othwise warnings occur when using the sun4v Legion simulator.


Revision tags: nick-nhusb-base
# 1.377 26-Oct-2014 palle

branches: 1.377.2;
sun4v: Create CLEANWIN0 and CLEANWIN1 macros for handling clean window traps on both sun4u and sun4u (based on the original code inlined in the sun4u trap table). Update trap tables accordingly for both sun4u and sun4v. Ok martin@


# 1.376 24-Oct-2014 nakayama

Fix typo in comment.


# 1.375 18-Oct-2014 snj

src is too big these days to tolerate superfluous apostrophes. It's
"its", people!


# 1.374 15-Oct-2014 palle

sun4v: fixed bug causing the real address to be incorrectly calculated as zero


# 1.373 24-Sep-2014 palle

sun4v: add code to enable startup of secondary cpus on both sun4u and sun4v systems - ok martin@


# 1.372 04-Sep-2014 palle

sun4v: All cpus must be setup with a TSB descriptor, so pmap_setup_tsb_sun4v() must take a pointer to the TSB descriptor


# 1.371 31-Aug-2014 palle

sun4v: Split the NORMAL_GLOBALS and ALTERNATE_GLOBALS macros to _SUN4U and _SUN4V variants. Rework the return_from_trap logic to use the new variants so it is possible to use a global register as scratch register.


# 1.370 14-Aug-2014 nakayama

Add missing delay slot in DEBUG kernel.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.369 30-Jul-2014 palle

branches: 1.369.2;
Fix ALTERNATE_GLOBALS so it at least works on sun4u - using a scratch register is not a good idea...


# 1.368 27-Jul-2014 palle

sun4v: Introduce a new macro ALTERNATE_GLOBALS (matching NORMAL_GLOBALS). Two new helper macros ENABLE_INTERRUPTS and DISABLE_INTERRUPTS are also created. With these changes the GENERIC.UP kernel will reach rootmount on sun4v systems - ok martin@


# 1.367 26-Jul-2014 palle

Improved the NORMAL_GLOBALS macro in the sun4u case, so only the relevant bit (AG) in %pstate is affected - ok martin@


# 1.366 24-Jul-2014 palle

sun4v: add missing spill/fill handling for trap level 1 + cosmetic changes to comments for trap level 0 entries


# 1.365 19-Jul-2014 palle

sun4v: Introduce a NORMAL_GLOBALS macro - first used in sparc_interrupt - other relevant uses will be handled as the sun4v work is progressesing - ok martin@


# 1.364 16-Jul-2014 palle

sun4v: Introduce SET_MMU_CONTEXTID macro for setting the mmu context id on both sun4u and sun4v


# 1.363 13-Jul-2014 palle

sun4v: add interrupt handling to sun4v trap table


# 1.362 13-Jul-2014 palle

Bugfix: add missing cmp instruction to GET_MAXCWP macro


# 1.361 30-Jun-2014 palle

sun4v: The maximum number of register windows is a constant and thus not available via the %ver register (sun4u only). Introduce a macro GET_MAXCWP that handles this, so cpu_switchto() works properly on sun4v. Other relevant reference to %ver can be adapted to use GET_MAXCWP as the sun4v port progresses. OK martin@


# 1.360 31-May-2014 palle

sun4v: added missing dtsb miss handling for trap level 1 - with this update the kernel now reaches configure() on sun4v systems


# 1.359 30-May-2014 palle

Remove debugging code introduced by accident in locore.s revision 1.357


Revision tags: yamt-pagecache-base9 rmind-smpnet-nbase rmind-smpnet-base
# 1.358 05-May-2014 palle

sun4v: the trap base address should be assigned to %l1 so %tba is properly setup later in the code - now the kernel gets as far as printing the copyright disclaimer, kernel version and total and available memory before crashing


# 1.357 21-Apr-2014 palle

sun4v: Update comment: modified -> access


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.356 21-Feb-2014 palle

branches: 1.356.2;
sun4v: Rename TLB_ defines to SUN4U_TLB_ so entries created using TSB_DATA() are properly setup for sun4u and sun4v. Relocate the cputyp variable from autoconf.c to locore.s and make it const in param.h so optimized code can be generated. Parts from OpenBSD. Optimization suggested by nakayama@. OK martin@, mrg@, nakayama@


# 1.355 31-Jan-2014 tsutsui

defined(LKM) -> defined(MODULAR)


# 1.354 26-Jan-2014 palle

sun4v: Add handling of spill/fill and dtsb miss traps (with a XXX to be handled later)


# 1.353 07-Jan-2014 palle

sun4v: trap table setup - currently populated with dummy entries which will be properly implemented later - parts from OpenBSD - OK martin@


# 1.352 29-Dec-2013 nakayama

Make buildable w/o options SUN4V.


# 1.351 27-Dec-2013 palle

a) make the hunt through the cpus list more generic b) sun4v: ensure that the interrupt stack is mapped permanently and the TSB is setup properly - parts from OpenBSD. OK martin@


# 1.350 06-Dec-2013 nakayama

Increase an interrupt depth only in the case of hardware interrupts,
and remove the ci_idepth trick in softint_fastintr.

Fixes the following diagnostic panic reported in port-sparc64.

panic: kernel diagnostic assertion "!cpu_intr_p()" failed: file
"../../../../kern/subr_xcall.c", line 351


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 1.349 24-May-2013 nakayama

branches: 1.349.2;
Disable interrupts after calling data_access_error as with
data_access_fault.


# 1.348 28-Apr-2013 nakayama

Use macros in machine/asm.h instead of locally defined, and
introduce CASPTRA for casxa/casa.


Revision tags: agc-symver-base
# 1.347 23-Jan-2013 martin

Fix sparc64_ipi_ccall by adding proper trap setup.
Fixes xcall(9) problems, as exposed by pserialize(9). Noticed by
J. Hannken-Illjes, cause pointed out by Takeshi Nakayama.


# 1.346 23-Jan-2013 martin

Sligthly clean up the (by default unused) #ifdef TRAPS_USE_IG


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7
# 1.345 10-Nov-2012 nakayama

Revise comment.


# 1.344 10-Nov-2012 nakayama

Use macro instead of magic number.


# 1.343 09-Nov-2012 nakayama

Make setstick() and getstick() to inline functions.


# 1.342 08-Nov-2012 macallan

use system tick timer instead of %tick on UltraSPARC-III-ish CPUs
review & fixes by Takeshi Nakayama


Revision tags: yamt-pagecache-base6 jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 1.341 17-Mar-2012 mrg

branches: 1.341.2;
port the corrected ECC error handling code from freebsd. i noticed my U10
took one of these and then hang. it shouldn't hang, there's a 'sir' here that
doesn't seem to reset properly. oh well.

tested by simulated a trap via 'ta 0x10' and considering that the same, but
it hasn't been tested against a real ECC error yet.


Revision tags: jmcneill-usbmp-base7 jmcneill-usbmp-base6 jmcneill-usbmp-base4
# 1.340 03-Mar-2012 nakayama

Fix the root cause of the hack "disable optimizations for uvm_bio.c
on 32 bit kernels".

gcc converts a division in the calculation of UBC_UMAP_ADDR macro
to multiplication (smul or combination of add/sll), and the
register of its result contains a garbage in upper 32 bits (the
upper 32 bits of smul/add/sll's result isn't zero cleared).

Then it passes to pseg_get{,_real} through pmap_extract without the
zero clear of upper 32 bits in the optimization case. So the
result of pseg_get and pmap_extact sometimes gets screwed up.


Revision tags: jmcneill-usbmp-base5 jmcneill-usbmp-base3
# 1.339 19-Feb-2012 rmind

Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.


Revision tags: jmcneill-usbmp-pre-base2 jmcneill-usbmp-base2 netbsd-6-base jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.338 04-Sep-2011 nakayama

branches: 1.338.2; 1.338.6; 1.338.8;
ih_pil is an interrupt level, not an interrupt mask.


# 1.337 27-Jul-2011 nakayama

ivec is assigned to hardware, so count its event counter up in
interrupt_vector, not in softint, and do some optimization.


# 1.336 20-Jul-2011 macallan

add per ivec event counters


# 1.335 12-Jul-2011 mrg

rename sparc64 BLOCK_SIZE and BLOCK_ALIGN to have SPARC64_ prefixes.
for the assembler files, define the old names to the new names
since using the new names cause ugliness due to longer identifer
names, and reduces churn.

fixes build issues in dtv and vaguely makes <machine/psl.h> slightly
less name-space invasive.


# 1.334 18-Jun-2011 nakayama

Add fast softint(9) support for sparc64.

Reviewed on port-sparc64.


Revision tags: rmind-uvmplock-nbase cherry-xenmp-base rmind-uvmplock-base
# 1.333 12-May-2011 mrg

branches: 1.333.2;
first steps towards fujitsu SPARC64 support:

- SPARC64 systems have interrupts with upto 14 bits set, but we only look
at the first 11 bits. trim non IPI interrupts to 11 bits


Revision tags: uebayasi-xip-base7 bouyer-quota2-nbase bouyer-quota2-base jruoho-x86intr-base matt-mips64-premerge-20101231 jym-xensuspend-nbase jym-xensuspend-base
# 1.332 20-Dec-2010 matt

branches: 1.332.2;
Move counting of faults, traps, intrs, soft[intr]s, syscalls, and nswtch
from uvmexp to per-cpu cpu_data and move them to 64bits. Remove unneeded
includes of <uvm/uvm_extern.h> and/or <uvm/uvm.h>.


Revision tags: uebayasi-xip-base6 uebayasi-xip-base5 uebayasi-xip-base4 uebayasi-xip-base3 yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 1.331 10-Jul-2010 nakayama

Clear the upper word explicitly before combining two 32-bit values to 64-bit
on 32-bit kernels.


# 1.330 23-May-2010 martin

Split copy related functions out of locore.s into copy.S, move functions
only needed on multiprocessors into mp_subr.S.


# 1.329 17-May-2010 martin

Simplify primary CPU startup slightly by using the fact that our cpuinfo's
curpcb pointer points to the uarea/pcb of lwp0 and by remembering the pointer
to this cpuinfo, thus avoiding a few CPUINFO_VA references.


Revision tags: uebayasi-xip-base1
# 1.328 20-Mar-2010 chs

fix copy{in,out}{,str}() to return the error returned by uvm_fault().
fixes PR 41813.


Revision tags: yamt-nfs-mp-base9
# 1.327 10-Mar-2010 mrg

branches: 1.327.2;
XXX: workaround we'd like to remove when pmap / uvm locking is cleaned up:

- rename pseg_get() and pseg_set() to pseg_get_real() and pseg_set_real().
- if USE_LOCKSAFE_PSEG_GETSET is defined, which it current is by default,
define pseg_[gs]et() in terms of functions that take a new pseg_lock
mutex at IPL_VM while calling into the real functions.

this seems to avoid the pseg_set() crashes we've seen:
1 - spare needed, when pseg_get() just worked for this pmap
2 - the 2rd ldxa via ASI_PHYS_CACHED in pseg_set() loads garbage
into %o4, and causes the 3rd ldxa to fault


# 1.326 08-Mar-2010 mrg

blast_dcache() SMP friendly:

- blast_dcache() becomes sp_blast_dcache(dcache_size, dcache_line_size)
- new smp_blast_dcache(sparc64_cpuset_t) that blasts the D$ on this cpuset
- sparc64_ipi_blast_dcache() to support the above
- in pmap_remove_all(), when freeing mmu contexts for this pmap, mark
the set of cpus to blast the d$ on as well and convert the
blast_dcache() call into smp_blast_dcache() on the cpus who ran this
pmap, or, sp_blast_dcache(dcache_size, dcache_line_size)
- convert the remaining blast_dcache() in machdep.c to sp_blast_dcache()
- in pmap_destroy()/pmap_remove_all() take the pmap_lock() always since
we assert it is held always.

with these changes, NFS builds on the U60 seem to be stable now, and
the USIII machines also can often complete a single build.sh run now,
diskful or diskless.


reviewed by mlelstv and partially by martin, tested by martin and myself,
with some ideas from chuq as well.


# 1.325 07-Mar-2010 mrg

need _ALIGN in locore.h as well, for DEBUG kernels.


# 1.324 07-Mar-2010 mrg

gas has supported SPARC ".empty" for a long while; get rid of an
ancient workaround.


# 1.323 06-Mar-2010 mrg

move the memcpy/memset implementations out into their own file, with the
block copy versions as well. move some of the definitions in locore.s
into a new locore.h.

locore.s is almost 2000 lines shorter with this change.


# 1.322 04-Mar-2010 mrg

- in _bus_dmamap_unload(), pmap_page_protect() and pmap_clear_reference()
switch the dcache_flush_page() into a dcache_flush_page_all()
- in both pmap_kremove()/pmap_remove(), remove the blast_dcache() call
and replace it with dcache_flush_page_all()
- in pmap_get_page() [used to allocate PTP's], always call pmap_zero_page(pa)
- flush the dcache of the dst page in pmap_{copy,zero}_page() by redirecting
throught a C function that calls the (renamed) asm. the old asm code had a
comment about needing to do this...
- add a couple of membar #Sync's that the USIII manual recommends


based on discussions with chuq@, skrll@ and martin@.


these help my SB2000 / SB2500 with both disk / nfs builds and other tasks,
sometimes lasting for several hours before failing or asserting.


# 1.321 24-Feb-2010 mrg

when handing back page table pages to UVM, flush them from the dcache
on all CPUs.

idea from skrll@, and makes my disk-based SB2000 stable.

tested on U60, SB2000 and SB2500.


# 1.320 24-Feb-2010 mrg

- re-introduce sp_tlb_flush_pte() and sp_tlb_flush_all() that call
the right USI/USIII version.
- define tlb_flush_pte() in terms of sp_tlb_flush_pte() for the
!MULTIPROCESSOR case

this centralises some CPU_IS_USIII_UP() tests.


# 1.319 22-Feb-2010 mrg

move {dump,print}_[id]tlb() into a separate file.


# 1.318 22-Feb-2010 mrg

- store the maximum [id]cache size / line size for each cpu

- remove patch_kernel() since it isn't necessary and has been patching
the wrong thing in general.

- implement USIII versions of blast_icache(), dcache_flush_page() and
cache_flush_phys(). use the newly recorded cache size/line sizes.

- in winfixsave, flush the D$ with the right size index and ops. this
kills one of the wrong tag->inval patches.

- for blast_dcache(), use the newly recorded dcache_size/line_size.

- for blast_icache(), use the newly recorded cache size/line sizes.
for the USIII verison, disable the I$ while writing to ASI_ICACHE_TAG.


these changes removed several hard coded cache sizes values, some very
wrong kernel patching, and seem to make the current failure modes for
USIII less common, but not gone.


# 1.317 15-Feb-2010 mrg

- don't flush 32-bit entries for 64-bit code, it does not seem to be
necessary. #define TLB_FLUSH_LOWVA to turn it back on.
- remove the #if 0'd code in sparc64_ipi_flush_pte_usiii(), i have
verified that it is not required.
- add a missing membar #Sync to sp_tlb_flush_pte_usiii().


# 1.316 15-Feb-2010 nakayama

Fix linker error of GENERIC32 kernel.


# 1.315 15-Feb-2010 mrg

use TLB_SIZE_SPITFIRE in a couple of places, and note that the
{print,dump}_[id]tlb() versions are currently spitfire specific.


# 1.314 15-Feb-2010 mrg

introduce a new patch_kernel() and call it from the end of bootstrap().
use it to patch up TLB flush instructions that don't match for USI/II
and later. we can also hopefully use this to make GENERIC.MP minimally
expensive on single CPU machines as well.

this is the last piece needed to get GENERIC/GENERIC.MP to boot on the
USIII* machines.

idea and some initial code from openbsd.


# 1.313 13-Feb-2010 mrg

remove KTR support. it's never been a working part of netbsd src tree.


# 1.312 09-Feb-2010 wiz

Fix typo in comment.


Revision tags: uebayasi-xip-base
# 1.311 06-Feb-2010 mrg

branches: 1.311.2;
- properly map the schizo interrupt registers, so we can use the normal
virtual mappings to access them.
- with the above fxied, kill SCHIZO_BUS_SPACE_BROKEN, and introduce
an options CHEETAH for now, that disables the SPITFIRE code in locore.
- merge schizo_init() into schizo_attach() and clean up the softc a bit.


with this we are only one more step away from GENERIC booting on USIII
machines.


# 1.310 02-Feb-2010 mrg

- split sp_tlb_flush_pte() and switchtoctx() into sp_tlb_flush_pte_us()/
sp_tlb_flush_pte_usiii() and switchtoctx_us()/switchtoctx_usiii() and
implement the latter while i'm here. it works ... sometimes i think,
but also sometimes panics/hangs.
- fix a comment in sparc64_ipi_flush_pte_usiii()


# 1.309 02-Feb-2010 mrg

for now, reduce a few #ifdef SPITFIRE cases by introducing a new
ASI_DCACHE_TAG_OR_INV that is either ASI_DCACHE_{TAG,_INVALIDATE}.

increase the common code in cache_flush_phys().


# 1.308 01-Feb-2010 mrg

- sp_tlb_flush_all() becomes sp_tlb_flush_all_us() and sp_tlb_flush_all_usiii()
- sparc64_ipi_flush_pte() becomes sparc64_ipi_flush_pte_us() and
sparc64_ipi_flush_pte_usiii()
- add some commented out code to disable interrupts and raise the traplevel
in sparc64_ipi_flush_pte_usiii()
- cache_flush_phys() was missing a little of code in the cheetah case


# 1.307 01-Feb-2010 mrg

for USIII, use the new "tlb demap all" operation in sp_tlb_flush_all()


# 1.306 01-Feb-2010 mrg

remove unused icache_flush_page() implementation.


# 1.305 23-Jan-2010 mrg

remove the final uses of DATA_START.

now we can remove the 16KB space reserved at the start of the data segment,
and i now understand why i wrote this now removed comment 3.5 years ago:
"this shouldn't be needed... but kernel usually hangs without it"


# 1.304 23-Jan-2010 mrg

remove most of the code that writes debugging info DATA_START + offset.


# 1.303 23-Jan-2010 mrg

remove CHKPT() macro and uses. it's likely wrong in SMP land and probably should
be replaced with KTR-style uses if necessary.


# 1.302 23-Jan-2010 mrg

fix a comment.


Revision tags: matt-premerge-20091211
# 1.301 10-Dec-2009 rmind

Rename L_ADDR to L_PCB and amend some comments accordingly.


# 1.300 05-Dec-2009 mrg

- adjust the PA mask to the 43 bits supported by USIII.
- rework the spitfire/cheetah cache_flush_phys() to avoid several #ifdefs
- add a membar #Sync after sparc64_ipi_drop_fpstate (probably unnecessary)


# 1.299 30-Nov-2009 nakayama

sp_tlb_flush_pte for cheetah:
- restore interrupts properly in case of %tl > 0.


# 1.298 30-Nov-2009 mrg

stablize UP USIII support by blocking interrupts around sp_tlb_flush_pte()
i was seeing stack corruption while taking an interrupt in this function.

get USIII SMP mostly working by implementing the cheetah version of
sparc64_ipi_flush_pte().


SMP support is still not entirely stable. i can reproducably get a:

panic: fpusave_lwp ipi didn't

while running build.sh, when an awk process is exiting. other simple
heavy work loads do not crash for me right now.


# 1.297 30-Nov-2009 mrg

delete some no longer used code:
- smp_tlb_flush_ctx()
- smp_tlb_flush_all()
- sparc64_ipi_flush_ctx()
- sparc64_ipi_flush_all()
- sp_tlb_flush_ctx()


# 1.296 29-Nov-2009 nakayama

- calculate end PA correctly.
- wrap more spitfire specific (flushing I$) code.
- fix inverted #if condition for flushing I$ (and restore ASI_ICACHE_TAG).


# 1.295 28-Nov-2009 mrg

implement enough code to get SB2000/SB2500 booting to multiuser. does
not last long if you use it, but an idle machine has stayed up 10 hours.

- for the !SPITFIRE case, use ASI_DCACHE_INVALIDATE instead of
ASI_DCACHE_TAG when clearing tlb entries. from openbsd.

- convert some comment "! Not yet" into "WRITEME", so that attempting
to build a USIII MULTIPROCESSOR kernel fails to build until the code
is written.

- add some more WRITEME's for the above.

- implement a !SPITFIRE version of sp_tlb_flush_all(). since there are
no spare regs, for now just always increase %tl around this call. (we
could maybe store a token in %o3 along with the saved %pstate info.)


# 1.294 26-Nov-2009 matt

Kill proc0paddr. Use lwp0.l_addr instead.


# 1.293 25-Nov-2009 mrg

s/L_ADDR/L_PCB/, requested by rmind.


# 1.292 17-Oct-2009 nakayama

Wrap unused code with #if 0 which is called from #if 0'ed code.


Revision tags: yamt-nfs-mp-base8 yamt-nfs-mp-base7 jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5
# 1.291 30-May-2009 martin

cpu_setfunc() can not use lwp_trampoline, as that has additional lwp startup
semantics. Use a simpler setfunc_trampoline instead.


# 1.290 18-May-2009 nakayama

Remove random() from locore.s since it is in libkern.


# 1.289 16-May-2009 nakayama

Remove clear %tick in locore.s since it is cleared at cpu_initclocks() in
clock.c.


Revision tags: yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 nick-hppapmap-base2 nick-hppapmap-base mjf-devfs2-base
# 1.288 15-Dec-2008 mrg

restore some old "intrdebug" code, but leave it under NOT_DEBUG. most
of it works, but one that prints func/arg for each handler is not very
stable...

for now, while schizo bus space pointer accesses aren't working, add
a SCHIZO_BUS_SPACE_BROKEN option so you can build a kernel with schizo.

with this, and the prior schizo interrupt fix, you can now fail to run
/sbin/init!


Revision tags: haad-dm-base2 haad-nbase2 haad-dm-base
# 1.287 09-Dec-2008 martin

Get rid of get_maxctx() - it doesn't work on newer cpus and we will have
to find a better way for (some) sun4v machines - all sun4u use 13 bit
contexts anyway.


Revision tags: netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 ad-audiomp2-base netbsd-5-base
# 1.286 30-Oct-2008 nakayama

branches: 1.286.2; 1.286.6;
Wrap more code specific to USE_BLOCK_STORE_LOAD.


Revision tags: matt-mips64-base2 haad-dm-base1 wrstuden-revivesa-base-4
# 1.285 05-Oct-2008 nakayama

branches: 1.285.2;
- in flushing cache, use 32 as increment/decrement value to match the
cache line size.
- remove useless restore of %asi.
- remove nop in delay slot if we can.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 simonb-wapbl-nbase simonb-wapbl-base
# 1.284 10-Jul-2008 nakayama

Use proper CCR.


# 1.283 10-Jul-2008 nakayama

sparc64_ipi_save_fpstate:
- use primary MMU context for consistency with other trap/interrupt handlers.

sparc64_ipi_save_fpstate, savefpstate:
- avoid storing fp registers as we can.

sparc64_ipi_save_fpstate, savefpstate, loadfpstate:
- remove unaligned case since buffers allocated with pool_cache are ensured
64-byte aligned.

Ok by martin@.


# 1.282 02-Jul-2008 nakayama

branches: 1.282.2;
UltraSPARCs don't have floating point queue, and reading %fq regsiter
will cause illegal instruction trap. So remove the code handling them.


# 1.281 29-Jun-2008 nakayama

Wrap IPI calls with #ifdef MULTIPROCESSOR.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.280 14-Jun-2008 nakayama

Close unterminated comment.
Fix unexpected behavior in case of loadfpstate from unaligned buffer.


Revision tags: yamt-pf42-base3
# 1.279 31-May-2008 nakayama

branches: 1.279.2;
openfirmware_exit:
- disable interrupts with %pstate.
- prepare 64-bit stack and enable 64-bit addresses for 32-bit SMP kernels.


Revision tags: hpcarm-cleanup-nbase yamt-pf42-baseX yamt-pf42-base2 yamt-nfs-mp-base2 yamt-nfs-mp-base yamt-pf42-base
# 1.278 16-Apr-2008 nakayama

branches: 1.278.2; 1.278.4; 1.278.6;
Disable TRAPSTATS which was accidentally enabled when yamt-idlelwp branch
was merged.

Ok by martin@.


# 1.277 14-Apr-2008 nakayama

Remove sparc64_ipi_sync_tick.

Since we can use counter-timer as timecounter instead of %tick on SMP kernel,
it is not necessary to sync all CPUs %tick registers.


# 1.276 14-Apr-2008 nakayama

Add workaround for BB_ERRATA_1 on writing to TICK_CMPR register in
next_tick(). If writing to TICK_CMPR fails, we lose hardclock interrupt
on secondary CPUs.

About BB_ERRATA_1 from comment in OpenSolaris:

/*
* Writes to the TICK_COMPARE register sometimes fail on blackbird modules.
* The failure occurs only when the following instruction decodes to wr or
* wrpr. The workaround is to immediately follow writes to TICK_COMPARE
* with a read, thus stalling the pipe and keeping following instructions
* from causing data corruption. Aligning to a quadword will ensure these
* two instructions are not split due to i$ misses.
*/


# 1.275 28-Mar-2008 nakayama

Don't read fplwp content in delay slot for considering the case fplwp was
modifiled.

Reported by Chris Ross on port-sparc64.


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 1.274 20-Mar-2008 nakayama

- remove disabling interrupt in IPI.
- unused VA bits in MMU demap is 13 bits, not 12 bits.


# 1.273 18-Mar-2008 nakayama

Fix a race when increment an interrupt level event counter.


# 1.272 17-Mar-2008 nakayama

Fix a race condition in IPI handlers of save/drop fpstate, from OpenBSD.
Reported and tested by martin@.


# 1.271 17-Mar-2008 nakayama

Make schedintr interrupt handler per-CPU.
While there rename tickintr interrupt handler and share initialization
code with schedintr.


# 1.270 14-Mar-2008 nakayama

Improve IPI handling:
- make IPI takes two arguments.
- add IPI event counters per-CPU.
- implement IPI functions which were missing or broken.
- insert DELAY while halting primary CPU in IPI handler.


# 1.269 02-Mar-2008 nakayama

- make interrupt pending list per-CPU.
- make tickintr() MP-safe.
- remove unused port-sparc derived interrupt code.

Ok by martin@.


# 1.268 02-Mar-2008 nakayama

Don't get IPI handler argument (from bogus address), and ack IRQ twice.


# 1.267 28-Feb-2008 martin

Make TSBs and MMU contexts per-cpu.


Revision tags: nick-net80211-sync-base mjf-devfs-base hpcarm-cleanup-base
# 1.266 26-Jan-2008 nakayama

branches: 1.266.2; 1.266.6;
Fix for 32-bit kernels.


Revision tags: bouyer-xeni386-nbase bouyer-xeni386-base
# 1.265 15-Jan-2008 skrll

Store a sensbile PCB_PC value in snapshot - the return point.

This helps gdb somewhat.

OK'd by martin.


# 1.264 14-Jan-2008 martin

Fix register name typo/copy&pasto - %g6 is not %o6/%sp.
From OpenBSD.


Revision tags: matt-armv6-base
# 1.263 06-Jan-2008 martin

Load the next cpu_info pointer with LDPTR instead of ld.


Revision tags: vmlocking2-base3 yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2
# 1.262 09-Dec-2007 martin

branches: 1.262.2;
Provide cpu_intr_p(), at least for non-MULTIPROCESSOR kernels.
Based on suggestions by Andrew Doran.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base jmcneill-pm-base reinoud-bufcleanup-base
# 1.261 22-Oct-2007 martin

branches: 1.261.2; 1.261.4; 1.261.6;
Remove an unused .globl declaration


Revision tags: yamt-x86pmap-base4
# 1.260 17-Oct-2007 garbled

Merge the ppcoea-renovation branch to HEAD.

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

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

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base ppcoea-renovation-base vmlocking-base
# 1.259 09-Sep-2007 martin

branches: 1.259.4;
Make cpufrequency and friends per cpu values.
Prepare a hz tick interrupt on secondary CPUs via %tick, but do not
enable it yet, as it breaks ddb.


# 1.258 09-Sep-2007 martin

Do not ACK IPIs before we finished loading all arguments.


# 1.257 06-Sep-2007 martin

Remove the (now unused) second 64k page mapped per CPU.
From matthew green, with small changes by me. All bugs are mine.


# 1.256 25-Aug-2007 martin

branches: 1.256.2;
Remove INITSTACK completely - at the time we used to switch to it, we
already have access to all of lwp0 and it's uarea - so we can switch
to the correct lwp0 stack easily before calling main.


# 1.255 25-Aug-2007 martin

When exiting to OF, use the interrupt stack instead of INITSTACK


# 1.254 25-Aug-2007 martin

Rework cpu_mp_startup slightly:
- temporarily use the cpu's interrupt stack untill we are ready
to access non-OF-based mappings, then directly switch to the cpu's
idlelwp's uarea stack
- disable interrupts untill we are ready to call C code


# 1.253 13-Aug-2007 macallan

remove two restore without matching save


Revision tags: nick-csl-alignment-base matt-mips64-base mjf-ufs-trans-base
# 1.252 06-Jul-2007 martin

branches: 1.252.4; 1.252.8;
A few nits for 32bit SMP kernels, noticed by mrg.
While there, simplify the fpstate IPIs a bit.


# 1.251 05-Jul-2007 martin

sparc64_ipi_save_fpstate is not a leaf function - create a full grown
stack frame.


# 1.250 28-May-2007 mrg

clean up cpu_switchto() a little - no need to flushw or membar
excessively. optimise an rdpr. tested by tnn.


# 1.249 23-May-2007 martin

Fix a stupid bug in the save_fpstate ipi, which caused overwriting of
struct lwp of the lwp owning the fpu. Fix clearing the fplwp - %o0 will
not survive the call to savefpstate - duh!


# 1.248 20-May-2007 martin

Simplify tf_tstate setting when leaving for userland initially - I seem
to have confused the if with the else case of the previous C code.
Funny that it worked at all.


# 1.247 20-May-2007 martin

cpu_switchto() has to return it's first arg, always. This differs from
my reading of the documentation, but helps in the real world and seems
to be what other ports do.


# 1.246 20-May-2007 martin

Remove special case handling for userland lwps from cpu_lwp_fork, instead
do it in lwp_trampoline when we first return to userland.


# 1.245 19-May-2007 martin

cpu_idle is a leaf function, so we better "return from leaf".
Use return value from cpu_switchto for previous lwp in lwp_trampoline.
Also shamelessly steal a comment from uwe written for sparc that explains
all this.
Thanks to tnn, mrg, and uwe for helping to debug this.


# 1.244 17-May-2007 yamt

merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.


Revision tags: yamt-idlelwp-base8 thorpej-atomic-base ad-audiomp-base
# 1.243 22-Feb-2007 martin

branches: 1.243.4; 1.243.6; 1.243.12;
uvm.page_idle_zero now is a bool, not a 32bit value any more.


# 1.242 21-Feb-2007 mrg

shave 9 insns off the tsb setup in cpu_initialize & cpu_mp_startup.


# 1.241 21-Feb-2007 martin

Get rid of unused (thus always zero) "curlwp" variable hidden in assembler
code (C code always uses a cpuinfo based macro).


# 1.240 18-Feb-2007 martin

Make use of another call delay slot, pointed out by uwe.


# 1.239 18-Feb-2007 martin

Make use of a call delay slot and avoid a bogus EMPTY.
Spotted by Juergen Hannken-Illjes, with input from Andrew Doran and
Valeriy E. Ushakov.


# 1.238 18-Feb-2007 martin

Whitespace cosmetics


# 1.237 18-Feb-2007 martin

Backout previous: EMPTY was misused


# 1.236 18-Feb-2007 martin

Make EMPTY expand to nop with gas, as it is used to mark empty branch
delay slots.


# 1.235 15-Feb-2007 martin

branches: 1.235.2;
Fix obvious copy&pasto in SCHED_DEBUG register usage.


Revision tags: post-newlock2-merge
# 1.234 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 1.233 25-Dec-2006 wiz

Spell "relevant" correctly. From Zafer Aydogan.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 1.232 25-Oct-2006 mrg

branches: 1.232.2; 1.232.4;
- note that __idle_u should go away but doing so breaks things
- fix several comments to reality
- clean up the #ifdef NO_VCACHE code slightly
- use call instead of set/jmpl
- remove a couple of unnecessary stores to curlwp


Revision tags: yamt-splraiseipl-base2
# 1.231 18-Oct-2006 rjs

Clean up some comments. Cosmetic change to use correct structure
offset names.

Optimize out two instructions from sparc64_ipi_save_fpstate and
sparc64_ipi_drop_fpstate.


# 1.230 17-Oct-2006 mrg

allocate 128KB (as opposed to 64KB) per-cpu, and place the interrupt
stack, cpu_info structure, panicstack, idle uarea and normal kernel
stack in here. the idle uarea and kernel stack are in the 2nd 64KB
page. the interrupt stack and cpu_info structure are as the same
place in the 1st 64KB page, and the panicstack grows down from the
top of this page. update comments in param.h to suit (XXX: a lot
of these constants should move to a header file that will not pollute
the name space so much.) map these pages identically between
cpu_initialise() and cpu_mp_startup(), and deal with the two 64KB
pages in pmap_extract(). keep an unmapped 64KB page between them.

don't initialise the unused "ci_eintstack" member of the cpu_info
structure

use constants to initialise many addresses in the cpu_info structure,
consolidating these assignments from cpu0 and cpu>0

delete u0/estack0/panicstack from locore.s

clean up some wrong comments in locore.s

fix a 32bit-only bug in cpu_mp_startup().

delete 'u0' entirely.


this fixes recent random lossage seen on port-sparc64: processes
stuck in RUN state, data faults, and hangs.


# 1.229 04-Oct-2006 mrg

use call instead of set/jmpl. add an entry point for idle that expects
sched_lock to be unlocked, and use this for non-boot cpu's. complete a
comment describing how registers in idle_switch are expected to be set.


# 1.228 03-Oct-2006 mrg

use the same SAVE_LOCALS_INS definition for 32 bit and 64 bit kernels.
refactor TRAP_SETUP() a little between these two versions to be more alike.


# 1.227 03-Oct-2006 mrg

use the correct size/type for MP variables (pointers and longs).

a 32 bit MULTIPROCESSOR kernel now builds (and crashes quickly.)


# 1.226 03-Oct-2006 mrg

in the 64bit version of SAVE_LOCAL_INS, s/BIAS/STKB/ to allow future
sharing of the 32 and 64 bit versions of the {TRAP,INTR}_SETUP macros.


# 1.225 19-Sep-2006 mrg

- remove some way old FP setup/teardown code
- put the block memcpy/memset inside #ifdef USE_BLOCK_STORE_LOAD which
is (now) defined.

no functional change, same .o is generated.


# 1.224 19-Sep-2006 mrg

re-order the changes in rev 1.217 to give registers a little bit of
time to settle between usage, like it was before hand.


# 1.223 19-Sep-2006 mrg

- remove a wrong comment.
- add a new entry point for idle called idle_switch that is called by
cpu_switch() in the MP case when sched_whichqs is zero, properly
setting up the idle stack. from petrov@ via martin@.


# 1.222 19-Sep-2006 mrg

rework interrupt_vector() slightly:
- for the IPI case, avoid loading the address of intrlev into %g3
- remove some NOT_DEBUG code
- load the interrupt argument #2 in the delay slot

this removes 2 nops during interrupt processing for the normal
case, and an additional 2 ALU instructions for IPIs


# 1.221 18-Sep-2006 mrg

- sparc64_ipi_halt(): we shouldn't return from sparc64_ipi_halt_thiscpu()
so replace a branch with a 'sir'
- in #if 0 code, in sparc64_ipi_flush_pte() and sparc64_ipi_flush_ctx()
save/restore the out registers that the sp_tlb_flush_xxx() versions
around calling them
- in sp_tlb_flush_pte() and sp_tlb_flush_ctx(), replace global register
usage with out registers so that we don't clobber the (alternate)
global registers when these are called from IPI context


# 1.220 18-Sep-2006 mrg

- remove an extra 'sir' that followed one in a macro
- add some named labels to some spill/fill handlers
- remove 2 unused strings


Revision tags: yamt-splraiseipl-base
# 1.219 18-Sep-2006 martin

branches: 1.219.2;
Lazy FPU handling for the MULTIPROCESSOR case


# 1.218 16-Sep-2006 nakayama

From OpenBSD:
- reload %fprs for checking it again.
- use symbolic names for checking in %fprs.

revision 1.51
date: 2005/07/18 14:50:11; author: deraadt; state: Exp; lines: +2 -1
cache a copy of the fprs so we know what fp restore we should do after

revision 1.50
date: 2005/07/14 01:46:13; author: deraadt; state: Exp; lines: +4 -4
use symbolic names for checking in %fprs, as above


# 1.217 16-Sep-2006 nakayama

Fix a couple of %y register save/restore errors, inspired from OpenBSD.

revision 1.44
date: 2004/04/23 04:18:17; author: marc; state: Exp; lines: +5 -4

fix a couple of %y register save/restore errors
1) don't save %y in a register that is later used before restoring %y
2) always restore %y after calling a signal handler
tested by drahn@, OK pval


# 1.216 15-Sep-2006 martin

Do not bother to save fpu state when we are about to get rid of it.


Revision tags: yamt-pdpolicy-base9
# 1.215 13-Sep-2006 mrg

SMP cleanup. provide support for multiple CPUs in DDB. (SMP itself
is still not working.)

cpu.h:
- add a pointer for DDB regs in SMP environment to struct cpu_info
- remove the #defines for mp_pause_cpus() and mp_resume_cpus()
cpuset.h:
- remove CPUSET_ALL() and rename CPUSET_ALL_BUT() to CPUSET_EXCEPT()
from petrov.
db_machdep.h:
- rename the members of db_regs_t to be the same as sparc
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- redo DDB_REGS to no longer be a pointer to a fixed data structure
but to one allocated per-cpu when ddb is entered
- move a bunch of prototypes in here
intr.h:
- remove SPARC64_IPI_* macros, no longer used
db_interface.c:
- change "db_regs_t ddb_regs" to "db_regs_t *ddb_regp" and change
all references to suit
- make "nil" a 64 bit entity
- change the ddb register access methods to work in multiprocessor
environment, it is now very much like sparc does it
- in kdb_trap() avoid accessing ddb_regp when it is NULL
- update several messages to include the cpu number
- unpause other cpus much later when resuming from ddb
- rename db_lock() to db_lock_cmd(), as the sparc-like code has
db_lock as a simple lock
- remove "mach cpus" command, and replace it with "mach cpu" (which
does the same) and also implement "mach cpu N" to switch to
another cpus saved trapframe
db_trace.c:
- update for the ddb_regs -> ddb_regp change
genassym.cf:
- add TF_KSTACK as offsetof(struct trapframe64, tf_kstack)
ipifuncs.c:
- overhaul extensively
- remove all normal interrupt handlers as IPI's, we now handle
them all specially in locore.s:interrupt_vector
- add a simplelock around all ipi functions - it's not safe for
multiple cpus to be sending IPI's to each other right now
- rename sparc64_ipi_pause() to sparc64_ipi_pause_thiscpu() and,
if DDB is configured, enable it to save the passed-in trapframe
to a db_regs_t for this cpu's saved DDB registers.
- remove the "ipimask" system (SPARC64_IPI_* macros) and instead
pass functions directly
- in sparc64_send_ipi() always set the interrupt arguments to 0,
the address and argument of the to be called function. (the
argument right now is the address of ipi_tlb_args variable, and
part of the reason why only one CPU can send IPI's at a time.)
don't wait forever for an IPI to complete. some of this is
from petrov.
- rename sparc64_ipi_{halt,pause,resume}_cpus() to
mp_{halt,pause,resume}_cpus()
- new function mp_cpu_is_paused() used to avoid access missing
saved DDB registers
- actually broadcast the flush in smp_tlb_flush_pte(),
smp_tlb_flush_ctx() and smp_tlb_flush_all(). the other end may
not do anything yet in the pte/ctx cases yet...
kgdb_machdep.c:
- rework for changed member names in db_regs_t.
locore.s:
- shave an instruction from syscall_setup() (set + ld -> sethi + ld)
- remove some old dead debug code
- add new sparc64_ipi_halt IPI entry point, it just calls the C
vector to shutdown.
- add new sparc64_ipi_pause IPI entry point, which just traps into
the debugger using the normal breakpoint trap. these cpus usually
lose the race in db_interface.c:db_suspend_others() and end up
calling the C vector sparc64_ipi_pause_thiscpu().
- add #if 0'ed code to sparc64_ipi_flush_{pte,ctx}() IPI entry
points to call the sp_ version of these functions.
- in rft_kernel (return from trap, kernel), check to see if the
%tpc is at the sparc64_ipi_pause_trap_point and if so, call
"done" not "retry"
- rework cpu_switch slightly: save the passed-in lwp instead of
using the one in curlwp
- in cpu_loadproc(), save the new lwp not the old lwp, to curlwp
- in cpu_initialize(), set %tl to zero as well. from petrov.
- in cpu_exit(), fix a load register confusion. from petrov.
- change some "set" in delay branch to "mov".
machdep.c:
- deal with function renames
pmap.c:
- remove a spurious space
trap.c:
- remove unused "trapstats" variable
- add cpu number to a couple of messages


# 1.214 09-Sep-2006 mrg

significant clean up effort, largely from petrov@ via martin@.

- fix a bunch of comments for proc->lwp
- remove old TRAPTRACE, NOT_DEBUG, etc. code that has bit-rotted
- put some older DEBUG code under NOT_DEBUG
- add a bunch of new debugging/tracing code ("KTR") that depends on
other changes not yet present.


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base8 yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base yamt-pdpolicy-base5 chap-midi-base simonb-timecounters-base rpaulo-netinet-merge-pcb-base
# 1.213 14-May-2006 elad

branches: 1.213.6; 1.213.8;
integrate kauth.


# 1.212 12-May-2006 skrll

Fix some comments.


Revision tags: elad-kernelauth-base
# 1.211 09-May-2006 rjs

Load CPCB in cpu_mp_startup.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 1.210 11-Feb-2006 cdi

branches: 1.210.2; 1.210.4; 1.210.6;
ANSIfication: u_intN_t -> uintN_t, use ANSI function declarations/definitions
instead of K&R ones.


# 1.209 27-Jan-2006 cdi

branches: 1.209.2; 1.209.4;
Alter sparc64 bootstrap, catch up to ofwboot v1.9:

- Accept bootinfo structure passed down from ofwboot v1.9
- Drop kernel re-mapping code
- Use permanent 4MB mappings provided by the loader instead
- Change kernel entry address to point directly at the code instead of pointing
at the trap table's first slot. This allows the bootloader to detect
those kernels which are aware of the new boot scheme
- Due to the changes in kernel mapping code, alter secondary CPU bootstrap
code to use trampoline just like FreeBSD does (some FreeBSD code is used
here as well)


# 1.208 12-Jan-2006 cdi

Fix a typo: %g0 should be used instead of %o0 when initializing FPU in dostart:
and cpu_mp_startup:, %o0 is not even initialized at this point.


# 1.207 11-Dec-2005 christos

branches: 1.207.2;
merge ktrace-lwp.


Revision tags: yamt-readahead-base3 yamt-readahead-base2 yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base ktrace-lwp-base
# 1.206 10-Jul-2005 christos

Re-factor syscall, and make it use syscall_{plain,fancy}.


# 1.205 31-May-2005 chs

branches: 1.205.2;
remove vestigal {,e}intr{names,cnt} symbols now that vmstat doesn't need them.


Revision tags: netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 yamt-km-base4 yamt-km-base3 netbsd-3-base kent-audio2-base
# 1.204 12-Feb-2005 chs

branches: 1.204.4; 1.204.6; 1.204.8;
in sparc_interrupt(), wait to enable interrupts until just before calling
the handler and disable them again right after the handler returns.
we don't want another hardware interrupt coming in while we're mucking
with the list pointers. also, clear the intrhand's ih_pending pointer
before calling the handler rather than after, so that if another interrupt
comes in while the handler is running, we can put the intrhand back on
the list so it will be called again.

in send_softint(), disable interrupts via %pstate instead of %pil, so that
hardware interrupts at higher levels are blocked while we manipulate the
intrpending list. also, if the intrhand already has ih_pending set,
don't bother poking the SET_SOFTINT register again, since being on the list
implies that there is already a softint pending in the hardware.

these appear to fix PR 21750 (the "sleep forever" problem).

while I'm here, remove more vestiges of the !INTRLIST softint stuff
(code and comments). and in sparc64_ipi_flush_all(), interrupts are
already disabled so we don't need to fiddle with %pstate.


Revision tags: yamt-km-base2
# 1.203 30-Jan-2005 martin

Remove the no long usefull variants selected by undefining INTRLIST and
INTR_INTERLOCK to improve readability. Same object code generated as before.


Revision tags: yamt-km-base
# 1.202 16-Jan-2005 chs

branches: 1.202.2;
use ENTRY_NOPROFILE() for various entry points,
stack traces work better that way.


Revision tags: kent-audio1-beforemerge kent-audio1-base
# 1.201 03-Dec-2004 chs

branches: 1.201.4;
remove cache_flush_virt() and PADDRT, they're no longer used.
allocate a stack frame for blast_dcache() when profiling so it shows up.
in dcache_flush_page(), use a stride of 32 instead of 16 to match the
cache line size. correct various comments.


# 1.200 08-Nov-2004 petrov

Don't compile sparc64_ipi functions when UP.


# 1.199 25-Oct-2004 martin

No need to clear %o1 when returning a 64 bit integer from pseg_get if we
are compiling for a 64 bit kernel.


# 1.198 24-Jul-2004 nakayama

Change interrupt pending list end value to -1, to avoid linking an
interrupt handler twice.

It may fix "sleep forever" bug.


# 1.197 09-Apr-2004 petrov

Clean-up unused defines and variables.


Revision tags: netbsd-2-0-base
# 1.196 26-Mar-2004 petrov

branches: 1.196.2;
Use want_resched from cpu_info area.


# 1.195 23-Mar-2004 martin

Replace intrcnts by evcnts. XXX - needs slight tweaking for MULTIPROCESSOR.


# 1.194 14-Mar-2004 chs

checkpoint of MP work from dennis and myself. includes cross-processor
interrupt framework, a sledgehammer TLB invalidation and misc MP fixes.
doesn't work at all yet.


# 1.193 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.192 19-Jan-2004 martin

Rename switchexit to cpu_exit and g/c the old C implementation of cpu_exit.


# 1.191 18-Jan-2004 martin

Support RAS for 32bit kernels too.


# 1.190 16-Jan-2004 martin

In proc_trampoline don't bother to clear condition codes in the trap
frame, since we no longer rely on this.
While there fix a few comments.


# 1.189 08-Jan-2004 martin

Minor cleanup


# 1.188 06-Jan-2004 martin

Implement restartable atomic sequences (RAS) for sparc64.


# 1.187 06-Jan-2004 petrov

Spinup secondary cpus. Based on codes sent to me by Dennis Chernoivanov
and Chuck Silvers.


# 1.186 04-Jan-2004 jdolecek

update to recent changes - exit2() doesn't exist anymore and the
exit path always calls lwp_exit2()
pointed out Martin Husemann


# 1.185 02-Dec-2003 martin

Minor cleanup: remove unused code, sync a comment with current reality.


# 1.184 25-Nov-2003 cdi

Use per-cpu pcb, curlwp and fplwp rather than global ones. This brings
GENERIC.MP configuration to a usable state.

Approved by petrov@.


# 1.183 24-Nov-2003 cdi

Call 'proc_trampoline_mp' from 'proc_trampoline' in a multiprocessor
configuration. Fix process locking. Approved by petrov@.


# 1.182 20-Nov-2003 petrov

Remove nwindows calculation, it's not used. Set l_cpu in cpu_switch.


# 1.181 09-Nov-2003 martin

Get rid of bcopy/bzero.


# 1.180 26-Oct-2003 christos

Initial siginfo support for sparc64 (untested). COMPAT_16 sigcontext signal
delivery tested.


# 1.179 24-Aug-2003 chs

add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default. the changes
fall into two basic catagories:

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

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

originally from openbsd, adapted for netbsd by me.


# 1.178 08-Jul-2003 cdi

traceit: don't use %g7 as it is to become curcpu() register. Add comments.


# 1.177 18-May-2003 martin

branches: 1.177.2;
Make kernels with options KGDB at least compile.
Still needs some work to make it working.


# 1.176 29-Apr-2003 nakayama

Use BLOCK_ALIGN rather than BLOCK_SIZE for aligning a pointer.


# 1.175 27-Apr-2003 ragge

Preserve the symbol table in the LKM || KSYMS cases also.


# 1.174 04-Apr-2003 petrov

use branch slot in pmap_copy_page.


# 1.173 24-Mar-2003 nakayama

Divide `set' instruction in delay slot (from OpenBSD change to rev 1.30).


# 1.172 10-Feb-2003 martin

Remove some #if 0 code and a few XXX marked membars w/o proper
justification for their existence.


# 1.171 09-Feb-2003 martin

Remove left over pieces from reusing the signal trampoline for upcalls.
This should fix signal delivery for 32bit kernels.


# 1.170 05-Feb-2003 nakayama

Switch to use cycle counter (%tick) based microtime().

This is derived from alpha/microtime.c and i386/tsc_microtime.c,
and will share with both ports.

This should fix PR port-sparc64/18452.
(approved by martin)


# 1.169 04-Feb-2003 martin

Fix return value of pseg_set, which I accidently broke in rev. 1.164.

Fix register names in comment and shave off another register (hint
from uwe).


# 1.168 01-Feb-2003 martin

Rearrange register usage in pseg_set a bit and shave off %g4.


# 1.167 01-Feb-2003 martin

Remove a few #ifdef _LP64 by using STPTR/LDPTR macros.
Thanks to Matthew Green for the pointer.


# 1.166 31-Jan-2003 martin

Apply leaf procedure optimization to pseg_set (again).


# 1.165 31-Jan-2003 martin

Make the pmap count resident/wired mappings on the fly instead of
walking the page tables whenever this information is needed.

Add an option PMAP_COUNT_DEBUG to assert the new counts and the
page table walk agree.

The old solution had very bad performance impact, for example
by the high CPU load when running top(1).

Thanks to Simon Burge for pointing at the cause of the problem and
to Valeriy E. Ushakov for optimizing my simple minded assembler code.


# 1.164 27-Jan-2003 martin

Remove unused function pseg_find (which looked quite similar to
pseg_get anyway).


# 1.163 18-Jan-2003 thorpej

Merge the nathanw_sa branch.


Revision tags: nathanw_sa_before_merge nathanw_sa_base
# 1.162 16-Jan-2003 petrov

Move dump_dtlb back under DDB.


# 1.161 15-Jan-2003 chs

fix two bugs in my last pmap rework:
- in tlb_flush_all(), don't skip TLB entries with the high bit on,
I was confused about which MMU register it was using. it's also fine
to use the last hardware context.
- in pmap_create(), don't allocate a hardware context for the new pmap.
it's unnecessary, and when this would cause us to recycle all the contexts,
it would result in the current process's context being set to 0
(ie. the kernel's context). the current process could then return to
userspace without going through the context-switch code (and thus without
having a hardware context reallocated). this would lead to user mappings
being entered in the kernel's context later, causing all sorts of trouble.
add some assertions to catch this kind of thing.


Revision tags: fvdl_fs64_base
# 1.160 25-Dec-2002 petrov

new function dump_itlb.


Revision tags: gmcgarry_ctxsw_base gmcgarry_ucred_base kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.159 22-Sep-2002 chs

many improvements:
- use struct vm_page_md for attaching pv entries to struct vm_page
- change pseg_set()'s return value to indicate whether the spare page
was used as an L2 or L3 PTP.
- use a pool for pv entries instead of malloc().
- put PTPs on a list attached to the pmap so we can free them
more efficiently (by just walking the list) in pmap_destroy().
- use the new pmap_remove_all() interface to avoid flushing the cache and TLB
for each pmap_remove() that's done as we are tearing down an address space.
- in pmap_enter(), handle replacing an existing mapping more efficiently
than just calling pmap_remove() on it. also, skip flushing the
TSB and TLB if there was no previous mapping, since there can't be
anything we need to flush. also, preload the TSB if we're pre-setting
the mod/ref bits.
- allocate hardware contexts like the MIPS pmap:
allocate them all sequentially without reuse, then once we run out
just invalidate all user TLB entries and flush the entire L1 dcache.
- fix pmap_extract() for the case where the va is not page-aligned and
nothing is mapped there.
- fix calculation of TSB size. it was comparing physmem (which is
in units of pages) to constants that only make sense if they are
in units of bytes.
- avoid sleeping in pmap_enter(), instead let the caller do it.
- use pmap_kenter_pa() instead of pmap_enter() where appropriate.
- remove code to handle impossible cases in various functions.
- tweak asm code to pipeline a little better.
- remove many unnecessary spls and membars.
- lots of code cleanup.
- no doubt other stuff that I've forgotten.

the result of all this is that a fork+exit microbenchmark is 34% faster
and a fork+exec+exit microbenchmark is 28% faster.


Revision tags: gehenna-devsw-base
# 1.158 18-Jul-2002 wiz

Spell 'should' correctly.


# 1.157 07-Jun-2002 eeh

Shave 10% off the time needed to flush the D$ through a bit of instruction
reordering.


# 1.156 05-Jun-2002 eeh

Handle improperly aligned stack pointers more cleanly.


# 1.155 04-Jun-2002 eeh

Fix the fork trampoline to properly use the supplied tstate.


# 1.154 31-May-2002 thorpej

Make this work with an ISO C preprocessor.


Revision tags: netbsd-1-6-base
# 1.153 14-May-2002 eeh

branches: 1.153.2; 1.153.4;
Only save locals and ins in trapframes for DEBUG kernels.


# 1.152 04-May-2002 kleink

Add some comments to the CPP conditionals controlling the trap macro
definitions, to ease navigation somewhat.


# 1.151 16-Apr-2002 eeh

Make lots of routines profile-friendly and get rid of some cruft.


Revision tags: eeh-devprop-base
# 1.150 21-Mar-2002 petrov

Not needed debug stuff deleted.


# 1.149 16-Mar-2002 mrg

tell newer binutils that our use of %g2 and %g3 is OK here.


# 1.148 15-Mar-2002 eeh

Cleanup MMU initialization to prevent hangs.


Revision tags: newlock-base ifpoll-base
# 1.147 09-Feb-2002 eeh

branches: 1.147.4;
Fix microsecond calculation in microtime.


# 1.146 07-Feb-2002 eeh

Fix register allocation in microtime().


# 1.145 29-Jan-2002 eeh

Shift the UPAID in the correct direction.


# 1.144 17-Jan-2002 eeh

Be more tolerant of unaligned stack pointers.


# 1.143 17-Jan-2002 eeh

Enable block insns in bcopy and bzero.


# 1.142 16-Jan-2002 eeh

In bcopy use 32-bit comparisons in 32-bit kernels.


# 1.141 16-Jan-2002 eeh

Use correct calculation for the trapframe in softtrap for ILP32.


# 1.140 20-Nov-2001 lukem

- pull in opt_kgdb.h where necessary
- replace opt_kgdb_machdep.h with opt_kgdb.h
- defparam opt_kgdb.h:
KGDB_DEV KGDB_DEVNAME KGDB_DEVADDR KGDB_DEVRATE KGDB_DEVMODE
- move from opt_ddbparam.h to opt_ddb.h:
DDB_FROMCONSOLE DDB_ONPANIC DDB_HISTORY_SIZE DDB_BREAK_CHAR SYMTAB_SPACE
- replace KGDBDEV with KGDB_DEV
- replace KGDBADDR with KGDB_DEVADDR
- replace KGDBMODE with KGDB_DEVMODE
- replace KGDBRATE with KGDB_DEVRATE
- use `9600' instead of `0x2580' for 9600 baud rate
- use correct quotes for options KGDB_DEVNAME="\"com\""
- use correct quotes for options KGDB_DEV="17*256+0"
- remove unnecessary dependancy on Makefile for kgdb_stub.o
- minor whitespace cleanup


Revision tags: thorpej-mips-cache-base thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf
# 1.139 14-Sep-2001 thorpej

branches: 1.139.4;
Don't declare intrhand[] here -- that's taken care of in intr.c.


Revision tags: thorpej-devvp-base
# 1.138 30-Aug-2001 eeh

branches: 1.138.2;
Preliminary UltraSPARC III suport (not enabled yet).


# 1.137 13-Aug-2001 jdolecek

g/c _remque()/_insque(); use the C version in libkern


# 1.136 09-Aug-2001 eeh

Fix context masking lossage caused by last version.


# 1.135 08-Aug-2001 eeh

Clean up the trap code to handle the changes cause by supporting non-faulting
accesses. Also change the parameter order so trap frames are easy to find.


# 1.134 07-Aug-2001 eeh

Make sure C code always has ASI_PRIMARY_NOFAULT in the %asi register so
the compiler will be happy if it ever starts generating speculative loads.


# 1.133 05-Aug-2001 eeh

Add support for non-faulting loads and optimize MMU miss handling paths.


# 1.132 02-Aug-2001 eeh

Fix bcopy.


# 1.131 02-Aug-2001 eeh

Sync bzero w/libc version.


# 1.130 01-Aug-2001 eeh

Integrate fixes from userland memset.


# 1.129 31-Jul-2001 eeh

Code cleanup and optimization.


# 1.128 23-Jul-2001 eeh

Get rid of some debug code that really isn't all that useful any more.


# 1.127 19-Jul-2001 eeh

Do ignore unregistered interrupts instead of faulting.


# 1.126 16-Jul-2001 eeh

Make bcopy a 32-bit friendly.


# 1.125 11-Jul-2001 eeh

Fix problems booting 32-bit kernels and dispatching level-15 interrupts.


# 1.124 08-Jul-2001 eeh

branches: 1.124.2;
Code cleanup. Add block_disable to let you turn on block set/copy routines.


# 1.123 05-Jul-2001 eeh

New block bzero and bcopy.


# 1.122 04-Jul-2001 eeh

Replace old bcopy with a much faster version.


# 1.121 01-Jul-2001 martin

Disable axidently enabled debug code to make -current compile again.


# 1.120 30-Jun-2001 eeh

Use a newer version (still disabled) of block bcopy.


# 1.119 30-Jun-2001 eeh

Fixup fpu save restore, get rid of some unused copy functions, and add
a new bcopy.


# 1.118 21-Jun-2001 eeh

Allow multiple 4MB pages for both kernel text and kernel data.

Note: DEBUG checks will not allow accesses to the hole between
text and data segments, so you may need to update programs that
use libkvm before relocating the start of kernel data.


# 1.117 06-Jun-2001 mrg

extract the netbsd32, sunos, 32 bit svr4 and 64 bit svr4 sigcode out into
separate files, so that compat lkms can link with them as well.


# 1.116 30-May-2001 lukem

add missing #include "opt_kgdb.h"


Revision tags: thorpej_scsipi_beforemerge
# 1.115 25-Apr-2001 simonb

Spell occurred correctly.


Revision tags: thorpej_scsipi_nbase thorpej_scsipi_base
# 1.114 09-Apr-2001 eeh

Interrupt latency fix from sparc port. (Hm. One insn instead of 5).


# 1.113 07-Mar-2001 eeh

Fix inverted preprocessor logic. (Spotted by Charles.)


# 1.112 21-Feb-2001 eeh

branches: 1.112.2;
Add support for 64-bit SVR4 (Solaris 8) binaries.


# 1.111 10-Feb-2001 pk

Fix conditional for svr4 compat inclusion.


# 1.110 05-Feb-2001 eeh

Add signal trampoline for 64-bit svr4 emulations.


# 1.109 31-Dec-2000 eeh

Make INCR() atomic.


# 1.108 29-Dec-2000 eeh

pseg_get tells us whether it really needed that spare page after all.


# 1.107 07-Dec-2000 eeh

Fixup calculating where fpstate should be saved in the signal trampoline
code so it doesn't overwrite something important like the registers.


# 1.106 09-Nov-2000 eeh

Fix ILP32 bug in probe_get().


# 1.105 22-Oct-2000 pk

Restore revision 1.102.

I hope it sticks this time..


# 1.104 20-Oct-2000 eeh

Fix hang in 32-bit kernels caused by relocation of KERNBASE.


# 1.103 04-Oct-2000 eeh

Fix interrupt lossage problem and some cosmetic changes.


# 1.102 01-Oct-2000 pk

cpu_initialize: global registers aren't preserved across calls to
prom_printf(), so replace %g3 with %l7 (which isn't used despite
the `usage' comment).

Also, clean up white-space turds.


# 1.101 29-Sep-2000 eeh

This seems to fix the interrupt lossage of non-debug kernels.


# 1.100 28-Sep-2000 eeh

Fix INTR_SETUP() to properly distinguish kernel and user addresses.

Make microtime() return the correct time on %tick machines.

Re-enable debug stuff in dostart for now to detect kernel mapping issues.


# 1.99 25-Sep-2000 pk

Missing `#if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)'


# 1.98 17-Sep-2000 eeh

Make the improved %tick changes work with machines that use the counter-timer
for the clock.


# 1.97 12-Sep-2000 eeh

Fix new version of microtime.


# 1.96 11-Sep-2000 eeh

(Hopefully) fix clock skew on machines that us %tick for the clock (UIIi).


# 1.95 31-Aug-2000 eeh

Use casx instead of stx to change entries in the page table trees.


# 1.94 23-Aug-2000 eeh

Update the scheduler to the new locking scheme.


# 1.93 10-Aug-2000 eeh

Fix signal delivery.


# 1.92 02-Aug-2000 eeh

Get kernel profiling to work. Now if only gprof worked....


# 1.91 01-Aug-2000 eeh

Overhaul cache flush code and coredump code.


# 1.90 25-Jul-2000 pk

Re-instate a couple of delay slot NOPs marked `XXX spitfire bug?'


# 1.89 24-Jul-2000 mycroft

Optimization to pmap_zero_page(): we only need to use the first 16 FP regs,
as in bzero().


# 1.88 24-Jul-2000 mycroft

Fix a whitespace glitch.


# 1.87 24-Jul-2000 mycroft

Pull in the bzero() changes from libc for real, with a couple of kernel-
specific hacks:
* Make the bias handling depend on STKB, so it switches correctly for 32-bit
kernels.
* Use the 32-bit stw/ld for 32-bit kernels.
* Add a few `-STKB's that were missed in the previous change.


# 1.86 24-Jul-2000 pk

Cosmetic & readability:
- local label cleanup in interrupt handling code;
- in debugging sections when testing `intrdebug': use a unique
local label (97) to enhanced clarity;
- comment-out unused code;
- kill a bug as the satisfying result of doing all of the above.


# 1.85 24-Jul-2000 eeh

Fix stack issues in bzero.


# 1.84 24-Jul-2000 mycroft

Revert the previous change for now. I don't have time to debug it tonight.


# 1.83 23-Jul-2000 mycroft

Copy bzero change from libc.


# 1.82 20-Jul-2000 pk

Since `intrcnt' points to an array of long ints, reserve the appropriate
amount of space depending on _LP64. Provide macros to load/store signed
and unsigned long ints.

Also, make the `intrcnt' and `intrpending' arrays 16 entries long, as on
sparc/v9 interrupt #15 is just a regular interrupt.


# 1.81 19-Jul-2000 eeh

Fix merge problem.


# 1.80 19-Jul-2000 eeh

Disable interrupt interlock using ih->ih_pending field. Seems to cause
more problems than it solves.


# 1.79 19-Jul-2000 eeh

Miscellaneous cleanup.


# 1.78 18-Jul-2000 pk

Correct args usage comment in probeget.
Whitespace cleanup.


# 1.77 18-Jul-2000 pk

probeget: 9 -> 0x9


# 1.76 18-Jul-2000 pk

If `ih_pending' is set simply return from the trap, don't schedule another
soft interrupt.


Revision tags: mrg-merge-1-5-top
# 1.75 18-Jul-2000 pk

openfirmware: don't lower %pil


# 1.74 17-Jul-2000 pk

Kill typos in interrupt code.


# 1.73 17-Jul-2000 pk

probeget: do the same song and dance as ld*a() macros in ctlreg.h do.


# 1.72 14-Jul-2000 eeh

Move some macro definitions out of genassym and into locore.s


# 1.71 08-Jul-2000 mrg

backout part of previous: turn off intrdebug, and another debug message


# 1.70 07-Jul-2000 pk

Changes for readability:
- #define LP64 dependent STACKFRAME macro once
- use a LOAD_ASCIZ macro for setting up the format string
for debug messages.


# 1.69 07-Jul-2000 eeh

Temporary fix to prevent the clock from stopping on UIIi machines.


# 1.68 03-Jul-2000 eeh

Prevent interrupts from being posted if they are active and deprecate polled
interrupts. This seems to eliminate the spurious interrupts.


# 1.67 02-Jul-2000 eeh

Clean up interrupt handling some more.


# 1.66 30-Jun-2000 eeh

Fix interrupt delivery on UltraSPARC IIi machines.


# 1.65 24-Jun-2000 eeh

With these changes the kernel seems almost stable again.


# 1.64 24-Jun-2000 eeh

More VM cleanup:

Move the cpu_info structure above the interrupt stack so it won't
get corrupted if the stack overflows.

Flush the D$ before and after all MMU bypass accesses since the
D$ latches all of those.


# 1.63 23-Jun-2000 eeh

Make probeget() and probeset() really work for a change.


Revision tags: netbsd-1-5-base
# 1.62 19-Jun-2000 eeh

branches: 1.62.2;
Have separate data and text segments, make text read-only.


# 1.61 12-Jun-2000 eeh

Start reorganizing the kernel for MULTIPROCESSOR support.


# 1.60 31-May-2000 thorpej

Add a comment about needing to initialize p_cpu when multiple
processors are supported.


Revision tags: minoura-xpg4dl-base
# 1.59 26-May-2000 thorpej

branches: 1.59.2;
First sweep at scheduler state cleanup. Collect MI scheduler
state into global and per-CPU scheduler state:

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

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

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

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

Tested on i386 and Alpha. Changes are mostly mechanical, but apologies
in advance if it doesn't compile on a particular platform.


# 1.58 26-May-2000 thorpej

Don't set `runtime' here; it's done at the end of mi_switch().
cvS: ----------------------------------------------------------------------


# 1.57 26-May-2000 thorpej

Introduce a new process state distinct from SRUN called SONPROC
which indicates that the process is actually running on a
processor. Test against SONPROC as appropriate rather than
combinations of SRUN and curproc. Update all context switch code
to properly set SONPROC when the process becomes the current
process on the CPU.


# 1.56 22-Apr-2000 eeh

If we trap due to a bad kernel stack, try to switch to the interrupt strack
before breaking into the debugger.


# 1.55 18-Apr-2000 eeh

Prevent the system from getting watchdog reset by returning directly to user
mode if restoring the user window traps. Also reduce the time we run with
%tl>0.


# 1.54 13-Apr-2000 eeh

Apparently gas 2.9.5 (don't ask) does not like to add values to %lo()
directives so move the additions inside %lo() to make it happy.
Hopefully this won't break older versions.


# 1.53 10-Apr-2000 mrg

- fix a speeling error
- rename some numbered labels to be a bit less confusing.
- remove dead code
- fix a debug error message (argh!)


# 1.52 10-Apr-2000 pk

Get a kernel without DDB to build.


# 1.51 16-Mar-2000 eeh

Revamp interrupts again:

Fix a bug causing interrmittent panics in interrupt dispatch.
Use interrupt vectors for softints.
Add a new send_softint interface.
Improved D$ flushing.
Improve traptrace and other debugging enhancements.


Revision tags: chs-ubc2-newbase
# 1.50 16-Jan-2000 eeh

Interrupt handlers return zero if they didn't handle the interrupt.


# 1.49 10-Jan-2000 eeh

Add debugger single-stepping and fix interrupt dispatch bugs.


# 1.48 30-Dec-1999 eeh

Lots of changes:

remove ffs()
add bzero that uses block store insns
save %gsr to fpstate
revert to physical accesses for pmap_zero_page so we don't
have conflicting page mappings
general cleanup.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base fvdl-softdep-base
# 1.47 06-Nov-1999 eeh

Handle zero length properly in copyinstr() copyoutstr() and copystr().


Revision tags: comdex-fall-1999-base
# 1.46 11-Oct-1999 eeh

branches: 1.46.2; 1.46.4;
Update to post 1.4.


# 1.45 05-Oct-1999 eeh

branches: 1.45.2;
Make broken versions of gas happy by using sethi/or instead of set for
(negative) addresses.


# 1.44 17-Sep-1999 thorpej

Centralize the declaration and clearing of `cold'.


Revision tags: chs-ubc2-base
# 1.43 18-Jul-1999 eeh

More fun with pmap.


# 1.42 21-Jun-1999 eeh

Improve TRAPTRACE. Add FLTRACE that only tracks MMU faults.


# 1.41 05-Jun-1999 eeh

Make pbrobeget() and probeset() work for 64-bit values as well. To do this
the arguments are changed so the address is first and the ASI second so we
can have the address in %o0:%o1 and not worry about unused registers.

Also a bit of copyright cleanup.


# 1.40 05-Jun-1999 mrg

update a commit slightly.


# 1.39 30-May-1999 eeh

Add code to support using %tick as the system clock if no "counter-timer" node
is found.


# 1.38 09-May-1999 eeh

Fixup non-DEBUG kernels.


# 1.37 29-Apr-1999 christos

Add sunos_sigcode (32 bit only)


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 kame_141_19991130 netbsd-1-4-PATCH001 kame_14_19990705 kame_14_19990628 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.36 26-Mar-1999 eeh

branches: 1.36.4;
COMPAT_SPARC32 -> COMPAT_NETBSD32


# 1.35 25-Mar-1999 mrg

clean and up make compile


# 1.34 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.33 22-Mar-1999 eeh

Need to set up the pointers properly for partial FPU register stores.


# 1.32 22-Mar-1999 eeh

Flush D$ on bypass accesses.


# 1.31 28-Feb-1999 eeh

Use block load/store in pmap_zero_page()/pmap_copy_page().


# 1.30 17-Feb-1999 eeh

Let's test out vectored interrupts.


# 1.29 15-Feb-1999 hubertf

RCS ID police


# 1.28 11-Feb-1999 mrg

fix a comment pasto.


# 1.27 11-Jan-1999 eeh

Finally fixed 64-bit signal trampoline.


# 1.26 10-Jan-1999 eeh

Handle the symbol table properly in a 32-bit kernel that was booted from a
64-bit bootloader.


# 1.25 09-Jan-1999 eeh

More signal fixup.


Revision tags: kenh-if-detach-base
# 1.24 26-Nov-1998 mycroft

Sync kcopy() with 32-bit SPARC version.


# 1.23 16-Nov-1998 eeh

Fixup the last broken bits of the signal handling code.


Revision tags: chs-ubc-base
# 1.22 08-Oct-1998 eeh

Fix more syscall32 and signal breakage.


# 1.21 22-Sep-1998 eeh

More fixup in the signal area.

64-bit syscall cleanup.

Add emulation for some new FPU insns: conversion to 64-bit long int and
conditional moves.


# 1.20 17-Sep-1998 thorpej

SYS_sigreturn -> SYS___sigreturn14.


# 1.19 13-Sep-1998 eeh

Fixup signal changes (hopefully). However SUN_COMPAT is likely broken by
this and I don't know how to fix it.

We can now exec a 64-bit init through a really ugly hack (don't ask.)


# 1.18 11-Sep-1998 eeh

Add labels for the compat_sparc32 signal trampoline and break -- er -- fix
suword and fuword.


# 1.17 09-Sep-1998 eeh

Don't use %tick for microtime on 32-bit kernels -- breaks gettimeofday.


# 1.16 09-Sep-1998 thorpej

Adjust for the new "reaper" kernel thread: do not free the vmspace and
u-area in machine-dependent code. Instead, call exit2() to schedule
the reaper to free them for us, once it is safe to do so (i.e. we are
no longer running on the dead proc's vmspace and stack).


# 1.15 07-Sep-1998 eeh

Fix data corruption problem caused by broken debug code.


# 1.14 07-Sep-1998 eeh

Add new 64-bit trap vectors.


# 1.13 06-Sep-1998 eeh

32-bit fixup.


# 1.12 06-Sep-1998 eeh

Disable some debug stuff.


# 1.11 05-Sep-1998 eeh

It slices. It dices. It does everything except exec a sparc32_compat init.


# 1.10 02-Sep-1998 eeh

Periodic update: now starts probing devices.


# 1.9 30-Aug-1998 eeh

Some more 64-bit cleanup. Now everything compiles.


# 1.8 29-Aug-1998 eeh

Some more 64-bit-ification.


# 1.7 27-Aug-1998 eeh

Add 64-bit pmap support:

Moved from a two level 512/1024 entry setup mapping 32 (9/10/13) bits
respectively to a three level 1024/1024/1024 entry setup mapping 43
(10/10/10/13) bits. In 32-bit mode we waste about 1/12 pages mapping the high
11 bits. We also only manage 43 of the possible 44 bits of virtual address
space, wasting half of it. Oh well, maybe we'll do better next revision.


Revision tags: PMAP32
# 1.6 26-Aug-1998 mrg

panicstack: is needed outside of DEBUG. use _C_LABEL, and printf not db_printf (incase no ddb!)


# 1.5 13-Aug-1998 eeh

Merge paddr_t changes into the main branch.


Revision tags: eeh-paddr_t-base
# 1.4 07-Jul-1998 eeh

branches: 1.4.2;
General update:

Added genassym.cf
Removed lderr which should never have gotten in
Removed lots of dead code from locore.s
Added some softint stuff to intr.c
Added support for halt -p
esp and le both use bus_dmamap_*() functions now
instead of kdvma_mapin()
groundwork for PCI (but we still have no drivers for
any sun4u PCI devices)


# 1.3 04-Jul-1998 jonathan

defopt DDB.


# 1.2 26-Jun-1998 thorpej

defopt COMPAT_SVR4


# 1.1 20-Jun-1998 eeh

branches: 1.1.1;
Initial revision