Subject: CVS commit: src
To: None <source-changes@netbsd.org>
From: Castor Fu <castor@netbsd.org>
List: source-changes
Date: 01/14/1999 17:23:16
Module Name:	src
Committed By:	castor
Date:		Fri Jan 15 01:23:15 UTC 1999

Modified Files:
	src/sys/arch/mips/mips: db_interface.c db_trace.c fp.S genassym.cf
	    locore.S mips_machdep.c pmap.c trap.c vm_machdep.c
Added Files:
	src/sys/arch/mips/mips: genpubassym.cf locore_mips1.S locore_mips3.S
Log Message:
* Elimination of UADDR/KERNELSTACK

Affected files:
include/mips_param.h, include/pcb.h,
mips/locore_mips1.S, mips/locore_mips3.S,
mips/mips_machdep.c, mips/vm_machdep.c

Issue:

So far, NetBSD/mips has not successfully got rid of fixed-address
kernel stack.  USPACE (two 4KB pages) of each process has two distinct
KSEG2 addresses, both refer to a single physical storage; one address
for fixed range [ UADDR .. KERNELSTACK ), and another for "normal" KSEG2
address which was allocated by kernel memory manager and unique to each
others of processes.

"Doubly mapped" USPACE complicates context switch.  Both address ranges
have to be managed with a special care of "wired" TLB entries which
are never replaced until next context switch to ensure no TLB miss for
USPACE access.  It's equally crumbersome that MIPS processor's cache
machinary gets be confused about USPACE contents because there are two
distinct KSEG2 addresses to manipulate one physical storage.

Solution:

Purge KERNELSTACK constant for kernel stack pointer and replace
it with process unique values.  Kernel stack bottom is located at
'curproc->p_addr + USPACE'.  Context switch is simplified as it unloads
half of TLB hardwiring burden.  It just manages the unique KSEG2 address
of each USPACE to be wired.  As the side effect, switch_exit() has no
MIPS processor ISA dependent code anymore.  It switchs kernel stack to
proc0's USPACE which has KSEG0 address and no need of TLB entry.

* Extensive use of 'genassym.cf'

To hide target port dependent and/or processor register size dependent
constants from assembler routines, 'genassym.cf' now has an extentive
set of definitions for various constants and offset values of
structural objects.  This change will contribute possible NetBSD/mips64
portability too.

* Separation and rename of locore_r2000/_r4000.S

Those files are now indepedent standalones from locore.S to ease
maintainance works, and renamed to match MIPS processor ISA version.

* Changes in kernel mode exception handlers

Kernel mode exception handlers hold exception contexts by pushing a
certain set of register values on stack for resuming kernel mode
processing.  This context is now represented with 'struct trapframe',
which is smaller than full scale (user mode) exception context 'struct
frame'.  Stack consumption of kernel mode exception services is now
similar to 4.4BSD/mips.

* Relocation of exception frame

User mode context 'struct frame' is moved to the very bottom of kernel
stack at 'curproc->p_addr + USPACE - sizeof(struct frame)'  This change
saves a bit of instructions on every return to user processes as it
eliminates reference to global variable 'curpcb' each time.

* Refurblished DDB backtrace routine

It's a growing concern to maintain stacktrace() code correctly.  It
could be simplified by enforcing special arrangements for some of
obscure locore routines which violate usual coding conventions.

New backtrace code searchs for certain instructions peculiar to any of
function tails.  Specifically, "jr ra" for normal function returns, "jr
k0" for MIPS1 exception handlers and "eret" for MIPS3 handlers.

* Support for 64-bit safe user code
Affected Files:
${ARCH}/include/pubassym.cf lib/libc/arch/mips/gen/*setjmp*
include/setjmp.h mips/include/[lots] mips/mips/[lots]

Solution:

We define macros REG_L/REG_S and SZREG for loading and storing
registers and for the size of registers.  The exact meaning
of these is controlled by a macro (currently _MIPS64) which
allows one to treat the registers as either 32-bit or 64-bit.
There are data types mips_reg_t and mips_fpreg_t which represent
the true register sizes, and avoid confusing register_t.

We needed a way to dynamically gen the structure sizes of things
like sigcontext for setjmp.h, so we defined a pubassym.cf for
libc routines like setjmp and longjmp.

NetBSD/mips allows ${ARCH}'s to be defined which preserve
all 64-bits of registers across user context switches.  There
are still a few niceties to clean up for kernel mode context
switches.

* Support for QED 52xx processors
Affected Files:
mips/locore_mips3.S mips/pmap.c include/locore.h

Issue:
The QED 52xx family of processors are targeted at low cost
embedded systems, (i.e. CPUs ~$30) for systems like routers, printers,
etc.  We have added preliminary support for some of the idiosyncrasies
of this processor, e.g. no L2 cache, etc.  More work needs to be
done here because with a modest 2-way  L1 cache, some of the rampant
flushing has significant performance implications.  However,
it doesn't crash, which is a start.

Solution:
A routine for flushing the cache based on virtual addresses was added;
a routine which deals with the two-way set associativity of the
5230 L1 cache was added, accomodations to 5230's instruction hazards
were added.

* TLB Miss code for mips3/mips4 processors cleaned up significantly.
Affected Files:
mips/locore_mips3.S mips/vm_machdep.c include/locore.h mips_machdep.c
Issue:
The TLB Miss handler exceeded the allowed size, which wasn't
a problem because there was no handler for when the processor
was in 64-bit mode.  The handler for invalid TLB exceptions
also appears to have much vestigial code, which made it
difficult to understand.

Solution:
Use the XCONTEXT register to store a pointer to the segment
map table, this coupled with removing some dead code allows
the handlers to fit.