1993-06-12 14:58:17 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1990 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* the University of Utah, and William Jolitz.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
genassym.c:
Remove NKMEMCLUSTERS, it is no longer define or used.
locores.s:
Fix comment on PTDpde and APTDpde to be pde instead of pte
Add new equation for calculating location of Sysmap
Remove Bill's old #ifdef garbage for counting up memory,
that stuff will never be made to work and was just cluttering
up the file.
Add code that places the PTD, page table pages, and kernel
stack below the 640k ISA hole if there is room for it, otherwise
put this stuff all at 1MB. This fixes the 28K bogusity in
the boot blocks, that can now go away!
Fix the caclulation of where first is to be dependent on
NKPDE so that we can skip over the above mentioned areas.
The 28K thing is now 44K in size due to the increase in
kernel virtual memory space, but since we no longer have
to worry about that this is no big deal.
Use if NNPX > 0 instead of ifdef NPX for floating point code.
machdep.c
Change the calculation of for the buffer cache to be
20% of all memory above 2MB and add back the upper limit
of 2/5's of the VM_KMEM_SIZE so that we do not eat ALL
of the kernel memory space on large memory machines, note
that this will not even come into effect unless you have
more than 32MB. The current buffer cache limit is 6.7MB
due to this caclulation.
It seems that we where erroniously allocating bufpages pages
for buffer_map. buffer_map is UNUSED in this implementation
of the buffer cache, but since the map is referenced in
several if statements a quick fix was to simply allocate
1 vm page (but no real memory) to it.
pmap.h
Remove rcsid, don't want them in the kernel files!
Removed some cruft inside an #ifdef DEBUGx that caused
compiler errors if you where compiling this for debug.
Use the #defines for PD_SHIFT and PG_SHIFT in place of
constants.
trap.c:
Remove patch kit header and rcsid, fix $Id$.
Now include "npx.h" and use NNPX for controlling the
floating point code.
Remove a now completly invalid check for a maximum virtual
address, the virtual address now ends at 0xFFFFFFFF so
there is no more MAX!! (Thanks David, I completly missed
that one!)
vm_machdep.c
Remove patch kit header and rcsid, fix $Id$.
Now include "npx.h" and use NNPX for controlling the
floating point code.
Replace several 0xFE00000 constants with KERNBASE
1993-10-15 10:34:29 +00:00
|
|
|
* from: @(#)trap.c 7.4 (Berkeley) 5/13/91
|
1993-12-12 12:22:57 +00:00
|
|
|
* $Id: trap.c,v 1.10 1993/12/03 05:07:45 alm Exp $
|
1993-06-12 14:58:17 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 386 Trap and System call handleing
|
|
|
|
*/
|
|
|
|
|
genassym.c:
Remove NKMEMCLUSTERS, it is no longer define or used.
locores.s:
Fix comment on PTDpde and APTDpde to be pde instead of pte
Add new equation for calculating location of Sysmap
Remove Bill's old #ifdef garbage for counting up memory,
that stuff will never be made to work and was just cluttering
up the file.
Add code that places the PTD, page table pages, and kernel
stack below the 640k ISA hole if there is room for it, otherwise
put this stuff all at 1MB. This fixes the 28K bogusity in
the boot blocks, that can now go away!
Fix the caclulation of where first is to be dependent on
NKPDE so that we can skip over the above mentioned areas.
The 28K thing is now 44K in size due to the increase in
kernel virtual memory space, but since we no longer have
to worry about that this is no big deal.
Use if NNPX > 0 instead of ifdef NPX for floating point code.
machdep.c
Change the calculation of for the buffer cache to be
20% of all memory above 2MB and add back the upper limit
of 2/5's of the VM_KMEM_SIZE so that we do not eat ALL
of the kernel memory space on large memory machines, note
that this will not even come into effect unless you have
more than 32MB. The current buffer cache limit is 6.7MB
due to this caclulation.
It seems that we where erroniously allocating bufpages pages
for buffer_map. buffer_map is UNUSED in this implementation
of the buffer cache, but since the map is referenced in
several if statements a quick fix was to simply allocate
1 vm page (but no real memory) to it.
pmap.h
Remove rcsid, don't want them in the kernel files!
Removed some cruft inside an #ifdef DEBUGx that caused
compiler errors if you where compiling this for debug.
Use the #defines for PD_SHIFT and PG_SHIFT in place of
constants.
trap.c:
Remove patch kit header and rcsid, fix $Id$.
Now include "npx.h" and use NNPX for controlling the
floating point code.
Remove a now completly invalid check for a maximum virtual
address, the virtual address now ends at 0xFFFFFFFF so
there is no more MAX!! (Thanks David, I completly missed
that one!)
vm_machdep.c
Remove patch kit header and rcsid, fix $Id$.
Now include "npx.h" and use NNPX for controlling the
floating point code.
Replace several 0xFE00000 constants with KERNBASE
1993-10-15 10:34:29 +00:00
|
|
|
#include "npx.h"
|
1993-06-12 14:58:17 +00:00
|
|
|
#include "machine/cpu.h"
|
|
|
|
#include "machine/psl.h"
|
|
|
|
#include "machine/reg.h"
|
|
|
|
|
|
|
|
#include "param.h"
|
|
|
|
#include "systm.h"
|
|
|
|
#include "proc.h"
|
|
|
|
#include "user.h"
|
|
|
|
#include "acct.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#ifdef KTRACE
|
|
|
|
#include "ktrace.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "vm/vm_param.h"
|
|
|
|
#include "vm/pmap.h"
|
|
|
|
#include "vm/vm_map.h"
|
|
|
|
#include "sys/vmmeter.h"
|
|
|
|
|
|
|
|
#include "machine/trap.h"
|
|
|
|
|
1993-07-27 10:52:31 +00:00
|
|
|
#ifdef __GNUC__
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The "r" contraint could be "rm" except for fatal bugs in gas. As usual,
|
|
|
|
* we omit the size from the mov instruction to avoid nonfatal bugs in gas.
|
|
|
|
*/
|
|
|
|
#define read_gs() ({ u_short gs; __asm("mov %%gs,%0" : "=r" (gs)); gs; })
|
|
|
|
#define write_gs(gs) __asm("mov %0,%%gs" : : "r" ((u_short) gs))
|
|
|
|
|
|
|
|
#else /* not __GNUC__ */
|
|
|
|
|
|
|
|
u_short read_gs __P((void));
|
|
|
|
void write_gs __P((/* promoted u_short */ int gs));
|
|
|
|
|
|
|
|
#endif /* __GNUC__ */
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
struct sysent sysent[];
|
|
|
|
int nsysent;
|
|
|
|
unsigned rcr2();
|
|
|
|
extern short cpl;
|
|
|
|
|
First steps in rewriting locore.s, and making info useful
when the machine panics.
i386/i386/locore.s:
1) got rid of most .set directives that were being used like
#define's, and replaced them with appropriate #define's in
the appropriate header files (accessed via genassym).
2) added comments to header inclusions and global definitions,
and global variables
3) replaced some hardcoded constants with cpp defines (such as
PDESIZE and others)
4) aligned all comments to the same column to make them easier to
read
5) moved macro definitions for ENTRY, ALIGN, NOP, etc. to
/sys/i386/include/asmacros.h
6) added #ifdef BDE_DEBUGGER around all of Bruce's debugger code
7) added new global '_KERNend' to store last location+1 of kernel
8) cleaned up zeroing of bss so that only bss is zeroed
9) fix zeroing of page tables so that it really does zero them all
- not just if they follow the bss.
10) rewrote page table initialization code so that 1) works correctly
and 2) write protects the kernel text by default
11) properly initialize the kernel page directory, upages, p0stack PT,
and page tables. The previous scheme was more than a bit
screwy.
12) change allocation of virtual area of IO hole so that it is
fixed at KERNBASE + 0xa0000. The previous scheme put it
right after the kernel page tables and then later expected
it to be at KERNBASE +0xa0000
13) change multiple bogus settings of user read/write of various
areas of kernel VM - including the IO hole; we should never
be accessing the IO hole in user mode through the kernel
page tables
14) split kernel support routines such as bcopy, bzero, copyin,
copyout, etc. into a seperate file 'support.s'
15) split swtch and related routines into a seperate 'swtch.s'
16) split routines related to traps, syscalls, and interrupts
into a seperate file 'exception.s'
17) remove some unused global variables from locore that got
inserted by Garrett when he pulled them out of some .h
files.
i386/isa/icu.s:
1) clean up global variable declarations
2) move in declaration of astpending and netisr
i386/i386/pmap.c:
1) fix calculation of virtual_avail. It previously was calculated
to be right in the middle of the kernel page tables - not
a good place to start allocating kernel VM.
2) properly allocate kernel page dir/tables etc out of kernel map
- previously only took out 2 pages.
i386/i386/machdep.c:
1) modify boot() to print a warning that the system will reboot in
PANIC_REBOOT_WAIT_TIME amount of seconds, and let the user
abort with a key on the console. The machine will wait for
ever if a key is typed before the reboot. The default is
15 seconds, but can be set to 0 to mean don't wait at all,
-1 to mean wait forever, or any positive value to wait for
that many seconds.
2) print "Rebooting..." just before doing it.
kern/subr_prf.c:
1) remove PANICWAIT as it is deprecated by the change to machdep.c
i386/i386/trap.c:
1) add table of trap type strings and use it to print a real trap/
panic message rather than just a number. Lot's of work to
be done here, but this is the first step. Symbolic traceback
is in the TODO.
i386/i386/Makefile.i386:
1) add support in to build support.s, exception.s and swtch.s
...and various changes to various header files to make all of the
above happen.
1993-11-13 02:25:21 +00:00
|
|
|
#define MAX_TRAP_MSG 27
|
|
|
|
char *trap_msg[] = {
|
|
|
|
"reserved addressing fault", /* 0 T_RESADFLT */
|
|
|
|
"privileged instruction fault", /* 1 T_PRIVINFLT */
|
|
|
|
"reserved operand fault", /* 2 T_RESOPFLT */
|
|
|
|
"breakpoint instruction fault", /* 3 T_BPTFLT */
|
|
|
|
"", /* 4 unused */
|
|
|
|
"system call trap", /* 5 T_SYSCALL */
|
|
|
|
"arithmetic trap", /* 6 T_ARITHTRAP */
|
|
|
|
"system forced exception", /* 7 T_ASTFLT */
|
|
|
|
"segmentation (limit) fault", /* 8 T_SEGFLT */
|
|
|
|
"protection fault", /* 9 T_PROTFLT */
|
|
|
|
"trace trap", /* 10 T_TRCTRAP */
|
|
|
|
"", /* 11 unused */
|
|
|
|
"page fault", /* 12 T_PAGEFLT */
|
|
|
|
"page table fault", /* 13 T_TABLEFLT */
|
|
|
|
"alignment fault", /* 14 T_ALIGNFLT */
|
|
|
|
"kernel stack pointer not valid", /* 15 T_KSPNOTVAL */
|
|
|
|
"bus error", /* 16 T_BUSERR */
|
|
|
|
"kernel debugger fault", /* 17 T_KDBTRAP */
|
|
|
|
"integer divide fault", /* 18 T_DIVIDE */
|
|
|
|
"non-maskable interrupt trap", /* 19 T_NMI */
|
|
|
|
"overflow trap", /* 20 T_OFLOW */
|
|
|
|
"FPU bounds check fault", /* 21 T_BOUND */
|
|
|
|
"FPU device not available", /* 22 T_DNA */
|
|
|
|
"double fault", /* 23 T_DOUBLEFLT */
|
|
|
|
"FPU operand fetch fault", /* 24 T_FPOPFLT */
|
|
|
|
"invalid TSS fault", /* 25 T_TSSFLT */
|
|
|
|
"segment not present fault", /* 26 T_SEGNPFLT */
|
|
|
|
"stack fault", /* 27 T_STKFLT */
|
|
|
|
};
|
|
|
|
|
1993-12-12 12:22:57 +00:00
|
|
|
#define pde_v(v) (PTD[((v)>>PD_SHIFT)&1023].pd_v)
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* trap(frame):
|
|
|
|
* Exception, fault, and trap interface to BSD kernel. This
|
|
|
|
* common code is called from assembly language IDT gate entry
|
|
|
|
* routines that prepare a suitable stack frame, and restore this
|
|
|
|
* frame after the exception has been processed. Note that the
|
|
|
|
* effect is as if the arguments were passed call by reference.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
1993-11-25 01:38:01 +00:00
|
|
|
void
|
1993-06-12 14:58:17 +00:00
|
|
|
trap(frame)
|
|
|
|
struct trapframe frame;
|
|
|
|
{
|
|
|
|
register int i;
|
|
|
|
register struct proc *p = curproc;
|
|
|
|
struct timeval syst;
|
|
|
|
int ucode, type, code, eva;
|
|
|
|
|
|
|
|
frame.tf_eflags &= ~PSL_NT; /* clear nested trap XXX */
|
|
|
|
type = frame.tf_trapno;
|
|
|
|
#include "ddb.h"
|
|
|
|
#if NDDB > 0
|
|
|
|
if (curpcb && curpcb->pcb_onfault) {
|
|
|
|
if (frame.tf_trapno == T_BPTFLT
|
|
|
|
|| frame.tf_trapno == T_TRCTRAP)
|
|
|
|
if (kdb_trap (type, 0, &frame))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*pg("trap type %d code = %x eip = %x cs = %x eva = %x esp %x",
|
|
|
|
frame.tf_trapno, frame.tf_err, frame.tf_eip,
|
|
|
|
frame.tf_cs, rcr2(), frame.tf_esp);*/
|
|
|
|
if(curpcb == 0 || curproc == 0) goto we_re_toast;
|
1993-07-27 10:52:31 +00:00
|
|
|
if (curpcb->pcb_onfault && frame.tf_trapno != T_PAGEFLT) {
|
|
|
|
extern int _udatasel;
|
|
|
|
|
|
|
|
if (read_gs() != (u_short) _udatasel)
|
|
|
|
/*
|
|
|
|
* Some user has corrupted %gs but we depend on it in
|
|
|
|
* copyout() etc. Fix it up and retry.
|
|
|
|
*
|
|
|
|
* (We don't preserve %fs or %gs, so users can change
|
|
|
|
* them to either _ucodesel, _udatasel or a not-present
|
|
|
|
* selector, possibly ORed with 0 to 3, making them
|
|
|
|
* volatile for other users. Not preserving them saves
|
|
|
|
* time and doesn't lose functionality or open security
|
|
|
|
* holes.)
|
|
|
|
*/
|
|
|
|
write_gs(_udatasel);
|
|
|
|
else
|
1993-06-12 14:58:17 +00:00
|
|
|
copyfault:
|
1993-07-27 10:52:31 +00:00
|
|
|
frame.tf_eip = (int)curpcb->pcb_onfault;
|
1993-06-12 14:58:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
syst = p->p_stime;
|
|
|
|
if (ISPL(frame.tf_cs) == SEL_UPL) {
|
|
|
|
type |= T_USER;
|
|
|
|
p->p_regs = (int *)&frame;
|
|
|
|
curpcb->pcb_flags |= FM_TRAP; /* used by sendsig */
|
|
|
|
}
|
|
|
|
|
|
|
|
ucode=0;
|
|
|
|
eva = rcr2();
|
|
|
|
code = frame.tf_err;
|
|
|
|
switch (type) {
|
|
|
|
|
|
|
|
default:
|
|
|
|
we_re_toast:
|
|
|
|
#ifdef KDB
|
|
|
|
if (kdb_trap(&psl))
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
#if NDDB > 0
|
|
|
|
if (kdb_trap (type, 0, &frame))
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
First steps in rewriting locore.s, and making info useful
when the machine panics.
i386/i386/locore.s:
1) got rid of most .set directives that were being used like
#define's, and replaced them with appropriate #define's in
the appropriate header files (accessed via genassym).
2) added comments to header inclusions and global definitions,
and global variables
3) replaced some hardcoded constants with cpp defines (such as
PDESIZE and others)
4) aligned all comments to the same column to make them easier to
read
5) moved macro definitions for ENTRY, ALIGN, NOP, etc. to
/sys/i386/include/asmacros.h
6) added #ifdef BDE_DEBUGGER around all of Bruce's debugger code
7) added new global '_KERNend' to store last location+1 of kernel
8) cleaned up zeroing of bss so that only bss is zeroed
9) fix zeroing of page tables so that it really does zero them all
- not just if they follow the bss.
10) rewrote page table initialization code so that 1) works correctly
and 2) write protects the kernel text by default
11) properly initialize the kernel page directory, upages, p0stack PT,
and page tables. The previous scheme was more than a bit
screwy.
12) change allocation of virtual area of IO hole so that it is
fixed at KERNBASE + 0xa0000. The previous scheme put it
right after the kernel page tables and then later expected
it to be at KERNBASE +0xa0000
13) change multiple bogus settings of user read/write of various
areas of kernel VM - including the IO hole; we should never
be accessing the IO hole in user mode through the kernel
page tables
14) split kernel support routines such as bcopy, bzero, copyin,
copyout, etc. into a seperate file 'support.s'
15) split swtch and related routines into a seperate 'swtch.s'
16) split routines related to traps, syscalls, and interrupts
into a seperate file 'exception.s'
17) remove some unused global variables from locore that got
inserted by Garrett when he pulled them out of some .h
files.
i386/isa/icu.s:
1) clean up global variable declarations
2) move in declaration of astpending and netisr
i386/i386/pmap.c:
1) fix calculation of virtual_avail. It previously was calculated
to be right in the middle of the kernel page tables - not
a good place to start allocating kernel VM.
2) properly allocate kernel page dir/tables etc out of kernel map
- previously only took out 2 pages.
i386/i386/machdep.c:
1) modify boot() to print a warning that the system will reboot in
PANIC_REBOOT_WAIT_TIME amount of seconds, and let the user
abort with a key on the console. The machine will wait for
ever if a key is typed before the reboot. The default is
15 seconds, but can be set to 0 to mean don't wait at all,
-1 to mean wait forever, or any positive value to wait for
that many seconds.
2) print "Rebooting..." just before doing it.
kern/subr_prf.c:
1) remove PANICWAIT as it is deprecated by the change to machdep.c
i386/i386/trap.c:
1) add table of trap type strings and use it to print a real trap/
panic message rather than just a number. Lot's of work to
be done here, but this is the first step. Symbolic traceback
is in the TODO.
i386/i386/Makefile.i386:
1) add support in to build support.s, exception.s and swtch.s
...and various changes to various header files to make all of the
above happen.
1993-11-13 02:25:21 +00:00
|
|
|
if ((type & ~T_USER) <= MAX_TRAP_MSG)
|
|
|
|
printf("\n\nFatal trap %d: %s while in %s mode\n",
|
|
|
|
type & ~T_USER, trap_msg[type & ~T_USER],
|
|
|
|
(type & T_USER) ? "user" : "kernel");
|
|
|
|
|
|
|
|
printf("trap type = %d, code = %x\n eip = %x, cs = %x, eflags = %x, ",
|
1993-06-12 14:58:17 +00:00
|
|
|
frame.tf_trapno, frame.tf_err, frame.tf_eip,
|
|
|
|
frame.tf_cs, frame.tf_eflags);
|
First steps in rewriting locore.s, and making info useful
when the machine panics.
i386/i386/locore.s:
1) got rid of most .set directives that were being used like
#define's, and replaced them with appropriate #define's in
the appropriate header files (accessed via genassym).
2) added comments to header inclusions and global definitions,
and global variables
3) replaced some hardcoded constants with cpp defines (such as
PDESIZE and others)
4) aligned all comments to the same column to make them easier to
read
5) moved macro definitions for ENTRY, ALIGN, NOP, etc. to
/sys/i386/include/asmacros.h
6) added #ifdef BDE_DEBUGGER around all of Bruce's debugger code
7) added new global '_KERNend' to store last location+1 of kernel
8) cleaned up zeroing of bss so that only bss is zeroed
9) fix zeroing of page tables so that it really does zero them all
- not just if they follow the bss.
10) rewrote page table initialization code so that 1) works correctly
and 2) write protects the kernel text by default
11) properly initialize the kernel page directory, upages, p0stack PT,
and page tables. The previous scheme was more than a bit
screwy.
12) change allocation of virtual area of IO hole so that it is
fixed at KERNBASE + 0xa0000. The previous scheme put it
right after the kernel page tables and then later expected
it to be at KERNBASE +0xa0000
13) change multiple bogus settings of user read/write of various
areas of kernel VM - including the IO hole; we should never
be accessing the IO hole in user mode through the kernel
page tables
14) split kernel support routines such as bcopy, bzero, copyin,
copyout, etc. into a seperate file 'support.s'
15) split swtch and related routines into a seperate 'swtch.s'
16) split routines related to traps, syscalls, and interrupts
into a seperate file 'exception.s'
17) remove some unused global variables from locore that got
inserted by Garrett when he pulled them out of some .h
files.
i386/isa/icu.s:
1) clean up global variable declarations
2) move in declaration of astpending and netisr
i386/i386/pmap.c:
1) fix calculation of virtual_avail. It previously was calculated
to be right in the middle of the kernel page tables - not
a good place to start allocating kernel VM.
2) properly allocate kernel page dir/tables etc out of kernel map
- previously only took out 2 pages.
i386/i386/machdep.c:
1) modify boot() to print a warning that the system will reboot in
PANIC_REBOOT_WAIT_TIME amount of seconds, and let the user
abort with a key on the console. The machine will wait for
ever if a key is typed before the reboot. The default is
15 seconds, but can be set to 0 to mean don't wait at all,
-1 to mean wait forever, or any positive value to wait for
that many seconds.
2) print "Rebooting..." just before doing it.
kern/subr_prf.c:
1) remove PANICWAIT as it is deprecated by the change to machdep.c
i386/i386/trap.c:
1) add table of trap type strings and use it to print a real trap/
panic message rather than just a number. Lot's of work to
be done here, but this is the first step. Symbolic traceback
is in the TODO.
i386/i386/Makefile.i386:
1) add support in to build support.s, exception.s and swtch.s
...and various changes to various header files to make all of the
above happen.
1993-11-13 02:25:21 +00:00
|
|
|
eva = rcr2();
|
|
|
|
printf("cr2 = %x, current priority = %x\n", eva, cpl);
|
|
|
|
|
|
|
|
type &= ~T_USER;
|
|
|
|
if (type <= MAX_TRAP_MSG)
|
|
|
|
panic(trap_msg[type]);
|
|
|
|
else
|
|
|
|
panic("unknown/reserved trap");
|
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
/*NOTREACHED*/
|
|
|
|
|
|
|
|
case T_SEGNPFLT|T_USER:
|
|
|
|
case T_STKFLT|T_USER:
|
|
|
|
case T_PROTFLT|T_USER: /* protection fault */
|
|
|
|
ucode = code + BUS_SEGM_FAULT ;
|
|
|
|
i = SIGBUS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_PRIVINFLT|T_USER: /* privileged instruction fault */
|
|
|
|
case T_RESADFLT|T_USER: /* reserved addressing fault */
|
|
|
|
case T_RESOPFLT|T_USER: /* reserved operand fault */
|
|
|
|
case T_FPOPFLT|T_USER: /* coprocessor operand fault */
|
|
|
|
ucode = type &~ T_USER;
|
|
|
|
i = SIGILL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_ASTFLT|T_USER: /* Allow process switch */
|
|
|
|
astoff();
|
|
|
|
cnt.v_soft++;
|
|
|
|
if ((p->p_flag & SOWEUPC) && p->p_stats->p_prof.pr_scale) {
|
|
|
|
addupc(frame.tf_eip, &p->p_stats->p_prof, 1);
|
|
|
|
p->p_flag &= ~SOWEUPC;
|
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
case T_DNA|T_USER:
|
genassym.c:
Remove NKMEMCLUSTERS, it is no longer define or used.
locores.s:
Fix comment on PTDpde and APTDpde to be pde instead of pte
Add new equation for calculating location of Sysmap
Remove Bill's old #ifdef garbage for counting up memory,
that stuff will never be made to work and was just cluttering
up the file.
Add code that places the PTD, page table pages, and kernel
stack below the 640k ISA hole if there is room for it, otherwise
put this stuff all at 1MB. This fixes the 28K bogusity in
the boot blocks, that can now go away!
Fix the caclulation of where first is to be dependent on
NKPDE so that we can skip over the above mentioned areas.
The 28K thing is now 44K in size due to the increase in
kernel virtual memory space, but since we no longer have
to worry about that this is no big deal.
Use if NNPX > 0 instead of ifdef NPX for floating point code.
machdep.c
Change the calculation of for the buffer cache to be
20% of all memory above 2MB and add back the upper limit
of 2/5's of the VM_KMEM_SIZE so that we do not eat ALL
of the kernel memory space on large memory machines, note
that this will not even come into effect unless you have
more than 32MB. The current buffer cache limit is 6.7MB
due to this caclulation.
It seems that we where erroniously allocating bufpages pages
for buffer_map. buffer_map is UNUSED in this implementation
of the buffer cache, but since the map is referenced in
several if statements a quick fix was to simply allocate
1 vm page (but no real memory) to it.
pmap.h
Remove rcsid, don't want them in the kernel files!
Removed some cruft inside an #ifdef DEBUGx that caused
compiler errors if you where compiling this for debug.
Use the #defines for PD_SHIFT and PG_SHIFT in place of
constants.
trap.c:
Remove patch kit header and rcsid, fix $Id$.
Now include "npx.h" and use NNPX for controlling the
floating point code.
Remove a now completly invalid check for a maximum virtual
address, the virtual address now ends at 0xFFFFFFFF so
there is no more MAX!! (Thanks David, I completly missed
that one!)
vm_machdep.c
Remove patch kit header and rcsid, fix $Id$.
Now include "npx.h" and use NNPX for controlling the
floating point code.
Replace several 0xFE00000 constants with KERNBASE
1993-10-15 10:34:29 +00:00
|
|
|
#if NNPX > 0
|
1993-06-12 14:58:17 +00:00
|
|
|
/* if a transparent fault (due to context switch "late") */
|
|
|
|
if (npxdna()) return;
|
genassym.c:
Remove NKMEMCLUSTERS, it is no longer define or used.
locores.s:
Fix comment on PTDpde and APTDpde to be pde instead of pte
Add new equation for calculating location of Sysmap
Remove Bill's old #ifdef garbage for counting up memory,
that stuff will never be made to work and was just cluttering
up the file.
Add code that places the PTD, page table pages, and kernel
stack below the 640k ISA hole if there is room for it, otherwise
put this stuff all at 1MB. This fixes the 28K bogusity in
the boot blocks, that can now go away!
Fix the caclulation of where first is to be dependent on
NKPDE so that we can skip over the above mentioned areas.
The 28K thing is now 44K in size due to the increase in
kernel virtual memory space, but since we no longer have
to worry about that this is no big deal.
Use if NNPX > 0 instead of ifdef NPX for floating point code.
machdep.c
Change the calculation of for the buffer cache to be
20% of all memory above 2MB and add back the upper limit
of 2/5's of the VM_KMEM_SIZE so that we do not eat ALL
of the kernel memory space on large memory machines, note
that this will not even come into effect unless you have
more than 32MB. The current buffer cache limit is 6.7MB
due to this caclulation.
It seems that we where erroniously allocating bufpages pages
for buffer_map. buffer_map is UNUSED in this implementation
of the buffer cache, but since the map is referenced in
several if statements a quick fix was to simply allocate
1 vm page (but no real memory) to it.
pmap.h
Remove rcsid, don't want them in the kernel files!
Removed some cruft inside an #ifdef DEBUGx that caused
compiler errors if you where compiling this for debug.
Use the #defines for PD_SHIFT and PG_SHIFT in place of
constants.
trap.c:
Remove patch kit header and rcsid, fix $Id$.
Now include "npx.h" and use NNPX for controlling the
floating point code.
Remove a now completly invalid check for a maximum virtual
address, the virtual address now ends at 0xFFFFFFFF so
there is no more MAX!! (Thanks David, I completly missed
that one!)
vm_machdep.c
Remove patch kit header and rcsid, fix $Id$.
Now include "npx.h" and use NNPX for controlling the
floating point code.
Replace several 0xFE00000 constants with KERNBASE
1993-10-15 10:34:29 +00:00
|
|
|
#endif /* NNPX > 0 */
|
1993-08-28 13:25:22 +00:00
|
|
|
#ifdef MATH_EMULATE
|
1993-06-12 14:58:17 +00:00
|
|
|
i = math_emulate(&frame);
|
|
|
|
if (i == 0) return;
|
1993-08-28 13:25:22 +00:00
|
|
|
#else /* MATH_EMULTATE */
|
|
|
|
panic("trap: math emulation necessary!");
|
|
|
|
#endif /* MATH_EMULTATE */
|
1993-06-12 14:58:17 +00:00
|
|
|
ucode = FPE_FPU_NP_TRAP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_BOUND|T_USER:
|
|
|
|
ucode = FPE_SUBRNG_TRAP;
|
|
|
|
i = SIGFPE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_OFLOW|T_USER:
|
|
|
|
ucode = FPE_INTOVF_TRAP;
|
|
|
|
i = SIGFPE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_DIVIDE|T_USER:
|
|
|
|
ucode = FPE_INTDIV_TRAP;
|
|
|
|
i = SIGFPE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_ARITHTRAP|T_USER:
|
|
|
|
ucode = code;
|
|
|
|
i = SIGFPE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_PAGEFLT: /* allow page faults in kernel mode */
|
|
|
|
#if 0
|
|
|
|
/* XXX - check only applies to 386's and 486's with WP off */
|
|
|
|
if (code & PGEX_P) goto we_re_toast;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* fall into */
|
|
|
|
case T_PAGEFLT|T_USER: /* page fault */
|
|
|
|
{
|
|
|
|
register vm_offset_t va;
|
|
|
|
register struct vmspace *vm = p->p_vmspace;
|
|
|
|
register vm_map_t map;
|
1993-12-12 12:22:57 +00:00
|
|
|
int rv = 0;
|
1993-06-12 14:58:17 +00:00
|
|
|
vm_prot_t ftype;
|
|
|
|
extern vm_map_t kernel_map;
|
1993-12-12 12:22:57 +00:00
|
|
|
unsigned nss;
|
|
|
|
char *v;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
va = trunc_page((vm_offset_t)eva);
|
|
|
|
/*
|
|
|
|
* It is only a kernel address space fault iff:
|
|
|
|
* 1. (type & T_USER) == 0 and
|
|
|
|
* 2. pcb_onfault not set or
|
|
|
|
* 3. pcb_onfault set but supervisor space fault
|
|
|
|
* The last can occur during an exec() copyin where the
|
|
|
|
* argument space is lazy-allocated.
|
|
|
|
*/
|
|
|
|
if (type == T_PAGEFLT && va >= KERNBASE)
|
|
|
|
map = kernel_map;
|
|
|
|
else
|
|
|
|
map = &vm->vm_map;
|
|
|
|
if (code & PGEX_W)
|
|
|
|
ftype = VM_PROT_READ | VM_PROT_WRITE;
|
|
|
|
else
|
|
|
|
ftype = VM_PROT_READ;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (map == kernel_map && va == 0) {
|
|
|
|
printf("trap: bad kernel access at %x\n", va);
|
|
|
|
goto we_re_toast;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: rude hack to make stack limits "work"
|
|
|
|
*/
|
|
|
|
nss = 0;
|
1993-11-01 11:51:29 +00:00
|
|
|
if ((caddr_t)va >= vm->vm_maxsaddr
|
Patch from Gene Stark:
Subject: Page fault in PTE area fails in copyout
Index: sys/i386/i386/trap.c FreeBSD-1.0.2
Description:
Reading files of several megabytes into Emacs, or many small
files all at once, would fail with "IO error - bad address".
Repeat-By:
The bug can be exercised by a test program that malloc()'s
a 5MB chunk of memory, and then, without accessing the memory
first, filling it with data from a file using read().
(I read 64k chunks from /dev/wd0d into successive 64k regions
of the 5MB chunk.) The read() will fail with EFAULT at the first
virtual address boundary that is a multiple of 0x400000.
Fix:
The problem was code in sys/i386/i386/trap.c that tries to
figure out what kind of trap occurred and to handle it appropriately.
It was interpreting any page fault with virtual address
>= vm->vm_maxsaddr as being a user stack segment fault.
In fact, addresses >= USRSTACK are in the user structure/PTE area,
and if they are handled as stack faults, the proper PTE will
not be paged in when it is supposed to be. This situation comes
up in copyout() and copyoutstr(), if PTE's are accessed for the
first time ever. The page fault on accessing the nonexistent PTE
is mishandled as a stack fault, and then the fault that occurs on
the subsequent access to the page itself causes copyout to fail
with EFAULT.
1993-11-28 09:28:54 +00:00
|
|
|
&& (caddr_t)va < (caddr_t)USRSTACK
|
1993-12-12 12:22:57 +00:00
|
|
|
&& map != kernel_map) {
|
|
|
|
nss = roundup(USRSTACK - (unsigned)va, PAGE_SIZE);
|
|
|
|
if (nss > p->p_rlimit[RLIMIT_STACK].rlim_cur) {
|
1993-06-12 14:58:17 +00:00
|
|
|
rv = KERN_FAILURE;
|
|
|
|
goto nogo;
|
|
|
|
}
|
1993-12-12 12:22:57 +00:00
|
|
|
|
|
|
|
if (vm->vm_ssize && roundup(vm->vm_ssize << PGSHIFT,
|
|
|
|
DFLSSIZ) < nss) {
|
|
|
|
int grow_amount;
|
|
|
|
/*
|
|
|
|
* If necessary, grow the VM that the stack occupies
|
|
|
|
* to allow for the rlimit. This allows us to not have
|
|
|
|
* to allocate all of the VM up-front in execve (which
|
|
|
|
* is expensive).
|
|
|
|
* Grow the VM by the amount requested rounded up to
|
|
|
|
* the nearest DFLSSIZ to provide for some hysteresis.
|
|
|
|
*/
|
|
|
|
grow_amount = roundup(nss, DFLSSIZ);
|
|
|
|
v = (char *)USRSTACK - roundup(vm->vm_ssize << PGSHIFT,
|
|
|
|
DFLSSIZ) - grow_amount;
|
|
|
|
/*
|
|
|
|
* If there isn't enough room to extend by DFLSSIZ, then
|
|
|
|
* just extend to the maximum size
|
|
|
|
*/
|
|
|
|
if (v < vm->vm_maxsaddr) {
|
|
|
|
v = vm->vm_maxsaddr;
|
|
|
|
grow_amount = MAXSSIZ - (vm->vm_ssize << PGSHIFT);
|
|
|
|
}
|
|
|
|
if (vm_allocate(&vm->vm_map, &v, grow_amount, FALSE) !=
|
|
|
|
KERN_SUCCESS) {
|
|
|
|
goto nogo;
|
|
|
|
}
|
|
|
|
}
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check if page table is mapped, if not, fault it first */
|
|
|
|
if (!pde_v(va)) {
|
1993-12-12 12:22:57 +00:00
|
|
|
v = (char *)trunc_page(vtopte(va));
|
1993-06-12 14:58:17 +00:00
|
|
|
rv = vm_fault(map, v, ftype, FALSE);
|
|
|
|
if (rv != KERN_SUCCESS) goto nogo;
|
|
|
|
/* check if page table fault, increment wiring */
|
|
|
|
vm_map_pageable(map, v, round_page(v+1), FALSE);
|
|
|
|
} else v=0;
|
|
|
|
rv = vm_fault(map, va, ftype, FALSE);
|
|
|
|
if (rv == KERN_SUCCESS) {
|
|
|
|
/*
|
|
|
|
* XXX: continuation of rude stack hack
|
|
|
|
*/
|
1993-12-12 12:22:57 +00:00
|
|
|
nss = nss >> PGSHIFT;
|
1993-06-12 14:58:17 +00:00
|
|
|
if (nss > vm->vm_ssize)
|
|
|
|
vm->vm_ssize = nss;
|
1993-12-12 12:22:57 +00:00
|
|
|
/*
|
|
|
|
* va could be a page table address, if the fault
|
|
|
|
* occurred from within copyout. In that case,
|
|
|
|
* we have to wire it. (EWS 12/11/93)
|
|
|
|
*/
|
|
|
|
if (ispt(va))
|
|
|
|
vm_map_pageable(map, va, round_page(va+1), FALSE);
|
1993-06-12 14:58:17 +00:00
|
|
|
va = trunc_page(vtopte(va));
|
1993-12-12 12:22:57 +00:00
|
|
|
/*
|
|
|
|
* for page table, increment wiring
|
|
|
|
* as long as not a page table fault as well
|
|
|
|
*/
|
1993-06-12 14:58:17 +00:00
|
|
|
if (!v && type != T_PAGEFLT)
|
1993-12-12 12:22:57 +00:00
|
|
|
vm_map_pageable(map, va, round_page(va+1), FALSE);
|
1993-06-12 14:58:17 +00:00
|
|
|
if (type == T_PAGEFLT)
|
|
|
|
return;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
nogo:
|
|
|
|
if (type == T_PAGEFLT) {
|
|
|
|
if (curpcb->pcb_onfault)
|
|
|
|
goto copyfault;
|
|
|
|
printf("vm_fault(%x, %x, %x, 0) -> %x\n",
|
|
|
|
map, va, ftype, rv);
|
|
|
|
printf(" type %x, code %x\n",
|
|
|
|
type, code);
|
|
|
|
goto we_re_toast;
|
|
|
|
}
|
|
|
|
i = (rv == KERN_PROTECTION_FAILURE) ? SIGBUS : SIGSEGV;
|
1993-12-12 12:22:57 +00:00
|
|
|
|
|
|
|
/* kludge to pass faulting virtual address to sendsig */
|
1993-12-03 05:10:08 +00:00
|
|
|
ucode = type &~ T_USER;
|
|
|
|
frame.tf_err = eva;
|
1993-12-12 12:22:57 +00:00
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if NDDB == 0
|
|
|
|
case T_TRCTRAP: /* trace trap -- someone single stepping lcall's */
|
|
|
|
frame.tf_eflags &= ~PSL_T;
|
|
|
|
|
|
|
|
/* Q: how do we turn it on again? */
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case T_BPTFLT|T_USER: /* bpt instruction fault */
|
|
|
|
case T_TRCTRAP|T_USER: /* trace trap */
|
|
|
|
frame.tf_eflags &= ~PSL_T;
|
|
|
|
i = SIGTRAP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
#include "isa.h"
|
|
|
|
#if NISA > 0
|
|
|
|
case T_NMI:
|
|
|
|
case T_NMI|T_USER:
|
|
|
|
#if NDDB > 0
|
|
|
|
/* NMI can be hooked up to a pushbutton for debugging */
|
|
|
|
printf ("NMI ... going to debugger\n");
|
|
|
|
if (kdb_trap (type, 0, &frame))
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
/* machine/parity/power fail/"kitchen sink" faults */
|
|
|
|
if(isa_nmi(code) == 0) return;
|
|
|
|
else goto we_re_toast;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
trapsignal(p, i, ucode);
|
|
|
|
if ((type & T_USER) == 0)
|
|
|
|
return;
|
|
|
|
out:
|
|
|
|
while (i = CURSIG(p))
|
|
|
|
psig(i);
|
|
|
|
p->p_pri = p->p_usrpri;
|
|
|
|
if (want_resched) {
|
1993-11-04 15:05:41 +00:00
|
|
|
int s;
|
1993-06-12 14:58:17 +00:00
|
|
|
/*
|
|
|
|
* Since we are curproc, clock will normally just change
|
|
|
|
* our priority without moving us from one queue to another
|
|
|
|
* (since the running process is not on a queue.)
|
|
|
|
* If that happened after we setrq ourselves but before we
|
|
|
|
* swtch()'ed, we might not be on the queue indicated by
|
|
|
|
* our priority.
|
|
|
|
*/
|
1993-11-04 15:05:41 +00:00
|
|
|
s = splclock();
|
1993-06-12 14:58:17 +00:00
|
|
|
setrq(p);
|
|
|
|
p->p_stats->p_ru.ru_nivcsw++;
|
|
|
|
swtch();
|
1993-11-04 15:05:41 +00:00
|
|
|
splx(s);
|
1993-06-12 14:58:17 +00:00
|
|
|
while (i = CURSIG(p))
|
|
|
|
psig(i);
|
|
|
|
}
|
|
|
|
if (p->p_stats->p_prof.pr_scale) {
|
|
|
|
int ticks;
|
|
|
|
struct timeval *tv = &p->p_stime;
|
|
|
|
|
|
|
|
ticks = ((tv->tv_sec - syst.tv_sec) * 1000 +
|
|
|
|
(tv->tv_usec - syst.tv_usec) / 1000) / (tick / 1000);
|
|
|
|
if (ticks) {
|
|
|
|
#ifdef PROFTIMER
|
|
|
|
extern int profscale;
|
|
|
|
addupc(frame.tf_eip, &p->p_stats->p_prof,
|
|
|
|
ticks * profscale);
|
|
|
|
#else
|
|
|
|
addupc(frame.tf_eip, &p->p_stats->p_prof, ticks);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
curpri = p->p_pri;
|
|
|
|
curpcb->pcb_flags &= ~FM_TRAP; /* used by sendsig */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1993-07-27 10:52:31 +00:00
|
|
|
* Compensate for 386 brain damage (missing URKR).
|
|
|
|
* This is a little simpler than the pagefault handler in trap() because
|
|
|
|
* it the page tables have already been faulted in and high addresses
|
|
|
|
* are thrown out early for other reasons.
|
1993-06-12 14:58:17 +00:00
|
|
|
*/
|
1993-07-27 10:52:31 +00:00
|
|
|
int trapwrite(addr)
|
|
|
|
unsigned addr;
|
|
|
|
{
|
|
|
|
unsigned nss;
|
|
|
|
struct proc *p;
|
1993-06-12 14:58:17 +00:00
|
|
|
vm_offset_t va;
|
1993-07-27 10:52:31 +00:00
|
|
|
struct vmspace *vm;
|
1993-12-12 12:22:57 +00:00
|
|
|
char *v;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
va = trunc_page((vm_offset_t)addr);
|
1993-07-27 10:52:31 +00:00
|
|
|
/*
|
|
|
|
* XXX - MAX is END. Changed > to >= for temp. fix.
|
|
|
|
*/
|
|
|
|
if (va >= VM_MAXUSER_ADDRESS)
|
|
|
|
return (1);
|
|
|
|
/*
|
|
|
|
* XXX: rude stack hack adapted from trap().
|
|
|
|
*/
|
|
|
|
nss = 0;
|
|
|
|
p = curproc;
|
|
|
|
vm = p->p_vmspace;
|
Patch from Gene Stark:
Subject: Page fault in PTE area fails in copyout
Index: sys/i386/i386/trap.c FreeBSD-1.0.2
Description:
Reading files of several megabytes into Emacs, or many small
files all at once, would fail with "IO error - bad address".
Repeat-By:
The bug can be exercised by a test program that malloc()'s
a 5MB chunk of memory, and then, without accessing the memory
first, filling it with data from a file using read().
(I read 64k chunks from /dev/wd0d into successive 64k regions
of the 5MB chunk.) The read() will fail with EFAULT at the first
virtual address boundary that is a multiple of 0x400000.
Fix:
The problem was code in sys/i386/i386/trap.c that tries to
figure out what kind of trap occurred and to handle it appropriately.
It was interpreting any page fault with virtual address
>= vm->vm_maxsaddr as being a user stack segment fault.
In fact, addresses >= USRSTACK are in the user structure/PTE area,
and if they are handled as stack faults, the proper PTE will
not be paged in when it is supposed to be. This situation comes
up in copyout() and copyoutstr(), if PTE's are accessed for the
first time ever. The page fault on accessing the nonexistent PTE
is mishandled as a stack fault, and then the fault that occurs on
the subsequent access to the page itself causes copyout to fail
with EFAULT.
1993-11-28 09:28:54 +00:00
|
|
|
if ((caddr_t)va >= vm->vm_maxsaddr
|
1993-12-12 12:22:57 +00:00
|
|
|
&& (caddr_t)va < (caddr_t)USRSTACK) {
|
|
|
|
nss = roundup(USRSTACK - (unsigned)va, PAGE_SIZE);
|
|
|
|
if (nss > p->p_rlimit[RLIMIT_STACK].rlim_cur)
|
1993-07-27 10:52:31 +00:00
|
|
|
return (1);
|
1993-12-12 12:22:57 +00:00
|
|
|
|
|
|
|
if (vm->vm_ssize && roundup(vm->vm_ssize << PGSHIFT,
|
|
|
|
DFLSSIZ) < nss) {
|
|
|
|
int grow_amount;
|
|
|
|
/*
|
|
|
|
* If necessary, grow the VM that the stack occupies
|
|
|
|
* to allow for the rlimit. This allows us to not have
|
|
|
|
* to allocate all of the VM up-front in execve (which
|
|
|
|
* is expensive).
|
|
|
|
* Grow the VM by the amount requested rounded up to
|
|
|
|
* the nearest DFLSSIZ to provide for some hysteresis.
|
|
|
|
*/
|
|
|
|
grow_amount = roundup(nss, DFLSSIZ);
|
|
|
|
v = (char *)USRSTACK - roundup(vm->vm_ssize << PGSHIFT, DFLSSIZ) -
|
|
|
|
grow_amount;
|
|
|
|
/*
|
|
|
|
* If there isn't enough room to extend by DFLSSIZ, then
|
|
|
|
* just extend to the maximum size
|
|
|
|
*/
|
|
|
|
if (v < vm->vm_maxsaddr) {
|
|
|
|
v = vm->vm_maxsaddr;
|
|
|
|
grow_amount = MAXSSIZ - (vm->vm_ssize << PGSHIFT);
|
|
|
|
}
|
|
|
|
if (vm_allocate(&vm->vm_map, &v, grow_amount, FALSE) !=
|
|
|
|
KERN_SUCCESS) {
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
}
|
1993-07-27 10:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (vm_fault(&vm->vm_map, va, VM_PROT_READ | VM_PROT_WRITE, FALSE)
|
|
|
|
!= KERN_SUCCESS)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: continuation of rude stack hack
|
|
|
|
*/
|
1993-12-12 12:22:57 +00:00
|
|
|
nss = nss >> PGSHIFT;
|
1993-07-27 10:52:31 +00:00
|
|
|
if (nss > vm->vm_ssize)
|
|
|
|
vm->vm_ssize = nss;
|
|
|
|
|
|
|
|
return (0);
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* syscall(frame):
|
|
|
|
* System call request from POSIX system call gate interface to kernel.
|
|
|
|
* Like trap(), argument is call by reference.
|
|
|
|
*/
|
|
|
|
/*ARGSUSED*/
|
1993-11-25 01:38:01 +00:00
|
|
|
void
|
1993-06-12 14:58:17 +00:00
|
|
|
syscall(frame)
|
|
|
|
volatile struct syscframe frame;
|
|
|
|
{
|
|
|
|
register int *locr0 = ((int *)&frame);
|
|
|
|
register caddr_t params;
|
|
|
|
register int i;
|
|
|
|
register struct sysent *callp;
|
|
|
|
register struct proc *p = curproc;
|
|
|
|
struct timeval syst;
|
|
|
|
int error, opc;
|
|
|
|
int args[8], rval[2];
|
|
|
|
int code;
|
|
|
|
|
|
|
|
#ifdef lint
|
|
|
|
r0 = 0; r0 = r0; r1 = 0; r1 = r1;
|
|
|
|
#endif
|
|
|
|
syst = p->p_stime;
|
|
|
|
if (ISPL(frame.sf_cs) != SEL_UPL)
|
|
|
|
panic("syscall");
|
|
|
|
|
|
|
|
code = frame.sf_eax;
|
|
|
|
curpcb->pcb_flags &= ~FM_TRAP; /* used by sendsig */
|
|
|
|
p->p_regs = (int *)&frame;
|
|
|
|
params = (caddr_t)frame.sf_esp + sizeof (int) ;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reconstruct pc, assuming lcall $X,y is 7 bytes, as it is always.
|
|
|
|
*/
|
|
|
|
opc = frame.sf_eip - 7;
|
|
|
|
callp = (code >= nsysent) ? &sysent[63] : &sysent[code];
|
|
|
|
if (callp == sysent) {
|
|
|
|
i = fuword(params);
|
|
|
|
params += sizeof (int);
|
|
|
|
callp = (code >= nsysent) ? &sysent[63] : &sysent[code];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((i = callp->sy_narg * sizeof (int)) &&
|
|
|
|
(error = copyin(params, (caddr_t)args, (u_int)i))) {
|
|
|
|
frame.sf_eax = error;
|
|
|
|
frame.sf_eflags |= PSL_C; /* carry bit */
|
|
|
|
#ifdef KTRACE
|
|
|
|
if (KTRPOINT(p, KTR_SYSCALL))
|
|
|
|
ktrsyscall(p->p_tracep, code, callp->sy_narg, &args);
|
|
|
|
#endif
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
#ifdef KTRACE
|
|
|
|
if (KTRPOINT(p, KTR_SYSCALL))
|
|
|
|
ktrsyscall(p->p_tracep, code, callp->sy_narg, &args);
|
|
|
|
#endif
|
|
|
|
rval[0] = 0;
|
|
|
|
rval[1] = frame.sf_edx;
|
|
|
|
/*pg("%d. s %d\n", p->p_pid, code);*/
|
|
|
|
error = (*callp->sy_call)(p, args, rval);
|
|
|
|
if (error == ERESTART)
|
|
|
|
frame.sf_eip = opc;
|
|
|
|
else if (error != EJUSTRETURN) {
|
|
|
|
if (error) {
|
|
|
|
/*pg("error %d", error);*/
|
|
|
|
frame.sf_eax = error;
|
|
|
|
frame.sf_eflags |= PSL_C; /* carry bit */
|
|
|
|
} else {
|
|
|
|
frame.sf_eax = rval[0];
|
|
|
|
frame.sf_edx = rval[1];
|
|
|
|
frame.sf_eflags &= ~PSL_C; /* carry bit */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* else if (error == EJUSTRETURN) */
|
|
|
|
/* nothing to do */
|
|
|
|
done:
|
|
|
|
/*
|
|
|
|
* Reinitialize proc pointer `p' as it may be different
|
|
|
|
* if this is a child returning from fork syscall.
|
|
|
|
*/
|
|
|
|
p = curproc;
|
|
|
|
while (i = CURSIG(p))
|
|
|
|
psig(i);
|
|
|
|
p->p_pri = p->p_usrpri;
|
|
|
|
if (want_resched) {
|
1993-11-04 15:05:41 +00:00
|
|
|
int s;
|
1993-06-12 14:58:17 +00:00
|
|
|
/*
|
|
|
|
* Since we are curproc, clock will normally just change
|
|
|
|
* our priority without moving us from one queue to another
|
|
|
|
* (since the running process is not on a queue.)
|
|
|
|
* If that happened after we setrq ourselves but before we
|
|
|
|
* swtch()'ed, we might not be on the queue indicated by
|
|
|
|
* our priority.
|
|
|
|
*/
|
1993-11-04 15:05:41 +00:00
|
|
|
s = splclock();
|
1993-06-12 14:58:17 +00:00
|
|
|
setrq(p);
|
|
|
|
p->p_stats->p_ru.ru_nivcsw++;
|
|
|
|
swtch();
|
1993-11-04 15:05:41 +00:00
|
|
|
splx(s);
|
1993-06-12 14:58:17 +00:00
|
|
|
while (i = CURSIG(p))
|
|
|
|
psig(i);
|
|
|
|
}
|
|
|
|
if (p->p_stats->p_prof.pr_scale) {
|
|
|
|
int ticks;
|
|
|
|
struct timeval *tv = &p->p_stime;
|
|
|
|
|
|
|
|
ticks = ((tv->tv_sec - syst.tv_sec) * 1000 +
|
|
|
|
(tv->tv_usec - syst.tv_usec) / 1000) / (tick / 1000);
|
|
|
|
if (ticks) {
|
|
|
|
#ifdef PROFTIMER
|
|
|
|
extern int profscale;
|
|
|
|
addupc(frame.sf_eip, &p->p_stats->p_prof,
|
|
|
|
ticks * profscale);
|
|
|
|
#else
|
|
|
|
addupc(frame.sf_eip, &p->p_stats->p_prof, ticks);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
curpri = p->p_pri;
|
|
|
|
#ifdef KTRACE
|
|
|
|
if (KTRPOINT(p, KTR_SYSRET))
|
|
|
|
ktrsysret(p->p_tracep, code, error, rval[0]);
|
|
|
|
#endif
|
|
|
|
#ifdef DIAGNOSTICx
|
|
|
|
{ extern int _udatasel, _ucodesel;
|
|
|
|
if (frame.sf_ss != _udatasel)
|
|
|
|
printf("ss %x call %d\n", frame.sf_ss, code);
|
|
|
|
if ((frame.sf_cs&0xffff) != _ucodesel)
|
|
|
|
printf("cs %x call %d\n", frame.sf_cs, code);
|
|
|
|
if (frame.sf_eip > VM_MAXUSER_ADDRESS) {
|
|
|
|
printf("eip %x call %d\n", frame.sf_eip, code);
|
|
|
|
frame.sf_eip = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|