Subject: Re: locore?
To: None <firstname.lastname@example.org, tech-kern@NetBSD.ORG>
From: Chris Torek <email@example.com>
Date: 06/29/1995 22:16:59
> KS - kernel stack - a per-user-thread stack in the kernel address space
> IS - interrupt stack - a single stack for handling all interrupts
Make this `a per CPU stack for handling interrupts' ... though if you
have only one CPU, it works out the same.
> if old state == user
> save on kernel stack (so ready for ast)
For many (most?) machines, many (most?) interrupts will *not* result
in an AST, so this would generally be wasted effort. User state
should probably be saved in whatever place is most convenient. ASTs
should generally be deferred until just before (or during) a return
to user mode, and at that point the user state is generally pretty
much restored anyway, so that an AST pseudo-trap can simply save it
away as if it were a regular trap.
Specific machines might change some or all of the above, but the rest
of the kernel is unlikely to care.
A simpler rule set (which I believe to be correct) is:
When you take an interrupt, the new stack is the interrupt
stack (a change iff you were not already on the IS).
When you trap from user mode, the new stack is the kernel
stack (always a change).
Nothing else needs to change stacks, except of course various returns:
When you return from a trap or interrupt, the new stack is
whichever stack you were on before. If this is the user
stack (i.e., returning to user mode), check for ASTs (unless
the hardware does this for you).
(Some machines may also need a special `panic stack' for emergencies.)