BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / i386 / i386 / trap.c
index 38a591f..53345d6 100644 (file)
@@ -5,24 +5,49 @@
  * This code is derived from software contributed to Berkeley by
  * the University of Utah, and William Jolitz.
  *
  * This code is derived from software contributed to Berkeley by
  * the University of Utah, and William Jolitz.
  *
- * %sccs.include.redist.c%
+ * 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.
  *
  *
- *     @(#)trap.c      5.10 (Berkeley) %G%
+ * 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.
+ *
+ *     @(#)trap.c      7.4 (Berkeley) 5/13/91
  */
 
 /*
  */
 
 /*
- * 386 Trap and System call handling
+ * 386 Trap and System call handleing
  */
 
  */
 
+#include "machine/cpu.h"
 #include "machine/psl.h"
 #include "machine/reg.h"
 #include "machine/psl.h"
 #include "machine/reg.h"
-#include "machine/segments.h"
-#include "machine/frame.h"
 
 #include "param.h"
 #include "systm.h"
 
 #include "param.h"
 #include "systm.h"
-#include "user.h"
 #include "proc.h"
 #include "proc.h"
+#include "user.h"
 #include "seg.h"
 #include "acct.h"
 #include "kernel.h"
 #include "seg.h"
 #include "acct.h"
 #include "kernel.h"
 #include "machine/trap.h"
 #include "machine/dbg.h"
 
 #include "machine/trap.h"
 #include "machine/dbg.h"
 
-#define        USER    0x40            /* user-mode flag added to type */
-#define        FRMTRAP 0x100           /* distinguish trap from syscall */
 
 struct sysent sysent[];
 int    nsysent;
 
 struct sysent sysent[];
 int    nsysent;
+unsigned rcr2();
+extern short cpl;
+
+
 /*
  * trap(frame):
  *     Exception, fault, and trap interface to BSD kernel. This
 /*
  * trap(frame):
  *     Exception, fault, and trap interface to BSD kernel. This
@@ -51,163 +78,131 @@ int       nsysent;
  * frame after the exception has been processed. Note that the
  * effect is as if the arguments were passed call by reference.
  */
  * frame after the exception has been processed. Note that the
  * effect is as if the arguments were passed call by reference.
  */
-unsigned rcr2(), Sysbase;
-extern short cpl;
-int um;
+
 /*ARGSUSED*/
 trap(frame)
        struct trapframe frame;
 /*ARGSUSED*/
 trap(frame)
        struct trapframe frame;
-#define type frame.tf_trapno
-#define code frame.tf_err
-#define pc frame.tf_eip
 {
 {
-       register int *locr0 = ((int *)&frame);
        register int i;
        register int i;
-       register struct proc *p;
+       register struct proc *p = curproc;
        struct timeval syst;
        struct timeval syst;
-       extern int nofault;
-       int ucode;
-
-#define DEBUG
-#ifdef DEBUG
-dprintf(DALLTRAPS, "\n%d. trap",u.u_procp->p_pid);
-dprintf(DALLTRAPS, " pc:%x cs:%x ds:%x eflags:%x isp %x\n",
-               frame.tf_eip, frame.tf_cs, frame.tf_ds, frame.tf_eflags,
-               frame.tf_isp);
-dprintf(DALLTRAPS, "edi %x esi %x ebp %x ebx %x esp %x\n",
-               frame.tf_edi, frame.tf_esi, frame.tf_ebp,
-               frame.tf_ebx, frame.tf_esp);
-dprintf(DALLTRAPS, "edx %x ecx %x eax %x\n",
-               frame.tf_edx, frame.tf_ecx, frame.tf_eax);
-/*p=u.u_procp;
-dprintf(DALLTRAPS, "sig %x %x %x \n",
-               p->p_sigignore, p->p_sigcatch, p->p_sigmask); */
-dprintf(DALLTRAPS, " ec %x type %x cpl %x ",
-               frame.tf_err&0xffff, frame.tf_trapno, cpl);
-/*pg("trap cr2 %x", rcr2());*/
-#endif
+       int ucode, type, code, eva;
 
 
-/*if(um && frame.tf_trapno == 0xc && (rcr2()&0xfffff000) == 0){
-       if (ISPL(locr0[tCS]) != SEL_UPL) {
-               if(nofault) goto anyways;
-               locr0[tEFLAGS] |= PSL_T;
-               *(int *)PTmap |= 1; load_cr3(rcr3());
+       frame.tf_eflags &= ~PSL_NT;     /* clear nested trap XXX */
+       type = frame.tf_trapno;
+       
+       if (curpcb->pcb_onfault && frame.tf_trapno != 0xc) {
+               frame.tf_eip = (int)curpcb->pcb_onfault;
                return;
        }
                return;
        }
-} else if (um) {
-printf("p %x ", *(int *) PTmap);
-*(int *)PTmap &= 0xfffffffe; load_cr3(rcr3());
-printf("p %x ", *(int *) PTmap);
-}
-anyways:
-
-if(pc == 0) um++;*/
-
-       locr0[tEFLAGS] &= ~PSL_NT;      /* clear nested trap XXX */
-if(nofault && frame.tf_trapno != 0xc)
-       { locr0[tEIP] = nofault; return;}
 
 
-       syst = u.u_ru.ru_stime;
-       if (ISPL(locr0[tCS]) == SEL_UPL) {
-               type |= USER;
-               u.u_ar0 = locr0;
+       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;
        ucode=0;
+       eva = rcr2();
+       code = frame.tf_err;
        switch (type) {
 
        default:
        switch (type) {
 
        default:
-bit_sucker:
+       we_re_toast:
 #ifdef KDB
                if (kdb_trap(&psl))
                        return;
 #endif
 
 #ifdef KDB
                if (kdb_trap(&psl))
                        return;
 #endif
 
-splhigh();
-printf("cr2 %x cpl %x ", rcr2(), cpl);
-               printf("trap type %d, code = %x, pc = %x cs = %x, eflags = %x\n", type, code, pc, frame.tf_cs, frame.tf_eflags);
-               type &= ~USER;
-pg("panic");
+               printf("trap type %d code = %x eip = %x cs = %x eflags = %x ",
+                       frame.tf_trapno, frame.tf_err, frame.tf_eip,
+                       frame.tf_cs, frame.tf_eflags);
+               printf("cr2 %x cpl %x\n", eva, cpl);
+               type &= ~T_USER;
                panic("trap");
                /*NOTREACHED*/
 
                panic("trap");
                /*NOTREACHED*/
 
-       case T_SEGNPFLT + USER:
-       case T_PROTFLT + USER:          /* protection fault */
+       case T_SEGNPFLT|T_USER:
+       case T_PROTFLT|T_USER:          /* protection fault */
 copyfault:
                ucode = code + BUS_SEGM_FAULT ;
                i = SIGBUS;
                break;
 
 copyfault:
                ucode = code + BUS_SEGM_FAULT ;
                i = SIGBUS;
                break;
 
-       case T_PRIVINFLT + USER:        /* privileged instruction fault */
-       case T_RESADFLT + USER:         /* reserved addressing fault */
-       case T_RESOPFLT + USER:         /* reserved operand fault */
-       case T_FPOPFLT + USER:          /* coprocessor operand fault */
-               ucode = type &~ USER;
+       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;
 
                i = SIGILL;
                break;
 
-       case T_ASTFLT + USER:           /* Allow process switch */
+       case T_ASTFLT|T_USER:           /* Allow process switch */
        case T_ASTFLT:
                astoff();
        case T_ASTFLT:
                astoff();
-               if ((u.u_procp->p_flag & SOWEUPC) && u.u_prof.pr_scale) {
-                       addupc(pc, &u.u_prof, 1);
-                       u.u_procp->p_flag &= ~SOWEUPC;
+               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;
 
                }
                goto out;
 
-       case T_DNA + USER:
+       case T_DNA|T_USER:
 #ifdef NPX
 #ifdef NPX
+               /* if a transparent fault (due to context switch "late") */
                if (npxdna()) return;
 #endif
                ucode = FPE_FPU_NP_TRAP;
                i = SIGFPE;
                break;
 
                if (npxdna()) return;
 #endif
                ucode = FPE_FPU_NP_TRAP;
                i = SIGFPE;
                break;
 
-       case T_BOUND + USER:
+       case T_BOUND|T_USER:
                ucode = FPE_SUBRNG_TRAP;
                i = SIGFPE;
                break;
 
                ucode = FPE_SUBRNG_TRAP;
                i = SIGFPE;
                break;
 
-       case T_OFLOW + USER:
+       case T_OFLOW|T_USER:
                ucode = FPE_INTOVF_TRAP;
                i = SIGFPE;
                break;
 
                ucode = FPE_INTOVF_TRAP;
                i = SIGFPE;
                break;
 
-       case T_DIVIDE + USER:
+       case T_DIVIDE|T_USER:
                ucode = FPE_INTDIV_TRAP;
                i = SIGFPE;
                break;
 
                ucode = FPE_INTDIV_TRAP;
                i = SIGFPE;
                break;
 
-       case T_ARITHTRAP + USER:
+       case T_ARITHTRAP|T_USER:
                ucode = code;
                i = SIGFPE;
                break;
 
        case T_PAGEFLT:                 /* allow page faults in kernel mode */
                ucode = code;
                i = SIGFPE;
                break;
 
        case T_PAGEFLT:                 /* allow page faults in kernel mode */
-               if (code & PGEX_P) goto bit_sucker;
+               if (code & PGEX_P) goto we_re_toast;
+
                /* fall into */
                /* fall into */
-       case T_PAGEFLT + USER:          /* page fault */
+       case T_PAGEFLT|T_USER:          /* page fault */
            {
                register vm_offset_t va;
            {
                register vm_offset_t va;
+               register struct vmspace *vm = p->p_vmspace;
                register vm_map_t map;
                int rv;
                vm_prot_t ftype;
                extern vm_map_t kernel_map;
                unsigned nss,v;
 
                register vm_map_t map;
                int rv;
                vm_prot_t ftype;
                extern vm_map_t kernel_map;
                unsigned nss,v;
 
-               va = trunc_page((vm_offset_t)rcr2());
+               va = trunc_page((vm_offset_t)eva);
                /*
                 * It is only a kernel address space fault iff:
                /*
                 * It is only a kernel address space fault iff:
-                *      1. (type & USER) == 0  and
-                *      2. nofault not set or
-                *      3. nofault set but supervisor space data fault
+                *      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.
                 */
                 * The last can occur during an exec() copyin where the
                 * argument space is lazy-allocated.
                 */
-               /*if (type == T_PAGEFLT && !nofault)*/
                if (type == T_PAGEFLT && va >= 0xfe000000)
                        map = kernel_map;
                else
                if (type == T_PAGEFLT && va >= 0xfe000000)
                        map = kernel_map;
                else
-                       map = u.u_procp->p_map;
+                       map = &vm->vm_map;
                if (code & PGEX_W)
                        ftype = VM_PROT_READ | VM_PROT_WRITE;
                else
                if (code & PGEX_W)
                        ftype = VM_PROT_READ | VM_PROT_WRITE;
                else
@@ -215,26 +210,26 @@ copyfault:
 
 #ifdef DEBUG
                if (map == kernel_map && va == 0) {
 
 #ifdef DEBUG
                if (map == kernel_map && va == 0) {
-                       printf("trap: bad kernel access at %x\n", v);
-                       goto bit_sucker;
+                       printf("trap: bad kernel access at %x\n", va);
+                       goto we_re_toast;
                }
 #endif
                /*
                 * XXX: rude hack to make stack limits "work"
                 */
                nss = 0;
                }
 #endif
                /*
                 * XXX: rude hack to make stack limits "work"
                 */
                nss = 0;
-               if ((caddr_t)va >= u.u_maxsaddr && map != kernel_map) {
+               if ((caddr_t)va >= vm->vm_maxsaddr && map != kernel_map) {
                        nss = clrnd(btoc(USRSTACK-(unsigned)va));
                        nss = clrnd(btoc(USRSTACK-(unsigned)va));
-                       if (nss > btoc(u.u_rlimit[RLIMIT_STACK].rlim_cur)) {
-pg("stk fuck");
+                       if (nss > btoc(p->p_rlimit[RLIMIT_STACK].rlim_cur)) {
                                rv = KERN_FAILURE;
                                goto nogo;
                        }
                }
                                rv = KERN_FAILURE;
                                goto nogo;
                        }
                }
+
                /* check if page table is mapped, if not, fault it first */
                /* check if page table is mapped, if not, fault it first */
-               if (!PTD[(va>>PD_SHIFT)&1023].pd_v) {
+#define pde_v(v) (PTD[((v)>>PD_SHIFT)&1023].pd_v)
+               if (!pde_v(va)) {
                        v = trunc_page(vtopte(va));
                        v = trunc_page(vtopte(va));
-/*pg("pt fault");*/
                        rv = vm_fault(map, v, ftype, FALSE);
                        if (rv != KERN_SUCCESS) goto nogo;
                        /* check if page table fault, increment wiring */
                        rv = vm_fault(map, v, ftype, FALSE);
                        if (rv != KERN_SUCCESS) goto nogo;
                        /* check if page table fault, increment wiring */
@@ -245,8 +240,8 @@ pg("stk fuck");
                        /*
                         * XXX: continuation of rude stack hack
                         */
                        /*
                         * XXX: continuation of rude stack hack
                         */
-                       if (nss > u.u_ssize)
-                               u.u_ssize = nss;
+                       if (nss > vm->vm_ssize)
+                               vm->vm_ssize = nss;
                        va = trunc_page(vtopte(va));
                        /* for page table, increment wiring
                           as long as not a page table fault as well */
                        va = trunc_page(vtopte(va));
                        /* for page table, increment wiring
                           as long as not a page table fault as well */
@@ -257,58 +252,51 @@ pg("stk fuck");
                        goto out;
                }
 nogo:
                        goto out;
                }
 nogo:
-/*pg("nogo");*/
                if (type == T_PAGEFLT) {
                if (type == T_PAGEFLT) {
-                       if (nofault)
+                       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 copyfault;
                        printf("vm_fault(%x, %x, %x, 0) -> %x\n",
                               map, va, ftype, rv);
                        printf("  type %x, code %x\n",
                               type, code);
-                       goto bit_sucker;
+                       goto we_re_toast;
                }
                i = (rv == KERN_PROTECTION_FAILURE) ? SIGBUS : SIGSEGV;
                break;
            }
 
        case T_TRCTRAP:  /* trace trap -- someone single stepping lcall's */
                }
                i = (rv == KERN_PROTECTION_FAILURE) ? SIGBUS : SIGSEGV;
                break;
            }
 
        case T_TRCTRAP:  /* trace trap -- someone single stepping lcall's */
-               locr0[tEFLAGS] &= ~PSL_T;
-if (um) {*(int *)PTmap &= 0xfffffffe; load_cr3(rcr3()); }
+               frame.tf_eflags &= ~PSL_T;
 
                        /* Q: how do we turn it on again? */
                return;
        
 
                        /* Q: how do we turn it on again? */
                return;
        
-       case T_BPTFLT + USER:           /* bpt instruction fault */
-       case T_TRCTRAP + USER:          /* trace trap */
-               locr0[tEFLAGS] &= ~PSL_T;
+       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:
                i = SIGTRAP;
                break;
 
 #include "isa.h"
 #if    NISA > 0
        case T_NMI:
-       case T_NMI + USER:
+       case T_NMI|T_USER:
+               /* machine/parity/power fail/"kitchen sink" faults */
                if(isa_nmi(code) == 0) return;
                if(isa_nmi(code) == 0) return;
-               else goto bit_sucker;
+               else goto we_re_toast;
 #endif
        }
 #endif
        }
-/*if(u.u_procp && (u.u_procp->p_pid == 1 || u.u_procp->p_pid == 3)) {
-       if( *(u_char *) 0xf7c != 0xc7) {
-               printf("%x!", *(u_char *) 0xf7c);
-               *(u_char *) 0xf7c = 0xc7;
-       }
-}*/
-       trapsignal(i, ucode|FRMTRAP);
-       if ((type & USER) == 0)
+
+       trapsignal(p, i, ucode);
+       if ((type & T_USER) == 0)
                return;
 out:
                return;
 out:
-       p = u.u_procp;
-       if (i = CURSIG(p))
-               psig(i,FRMTRAP);
+       while (i = CURSIG(p))
+               psig(i);
        p->p_pri = p->p_usrpri;
        p->p_pri = p->p_usrpri;
-       if (runrun) {
+       if (want_resched) {
                /*
                /*
-                * Since we are u.u_procp, clock will normally just change
+                * 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
                 * 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
@@ -317,29 +305,30 @@ out:
                 */
                (void) splclock();
                setrq(p);
                 */
                (void) splclock();
                setrq(p);
-               u.u_ru.ru_nivcsw++;
+               p->p_stats->p_ru.ru_nivcsw++;
                swtch();
                swtch();
-               if (i = CURSIG(p))
-                       psig(i,FRMTRAP);
+               while (i = CURSIG(p))
+                       psig(i);
        }
        }
-       if (u.u_prof.pr_scale) {
+       if (p->p_stats->p_prof.pr_scale) {
                int ticks;
                int ticks;
-               struct timeval *tv = &u.u_ru.ru_stime;
+               struct timeval *tv = &p->p_stime;
 
                ticks = ((tv->tv_sec - syst.tv_sec) * 1000 +
                        (tv->tv_usec - syst.tv_usec) / 1000) / (tick / 1000);
 
                ticks = ((tv->tv_sec - syst.tv_sec) * 1000 +
                        (tv->tv_usec - syst.tv_usec) / 1000) / (tick / 1000);
-               if (ticks)
-                       addupc(pc, &u.u_prof, ticks);
+               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;
        }
        curpri = p->p_pri;
-/*if(u.u_procp->p_pid == 3)
-               locr0[tEFLAGS] |= PSL_T;
-if(u.u_procp->p_pid == 1 && (pc == 0xec9 || pc == 0xebd))
-               locr0[tEFLAGS] |= PSL_T;*/
-spl0(); /*XXX*/
-#undef type
-#undef code
-#undef pc
+       curpcb->pcb_flags &= ~FM_TRAP;  /* used by sendsig */
+       spl0(); /*XXX*/
 }
 
 /*
 }
 
 /*
@@ -349,85 +338,67 @@ spl0(); /*XXX*/
  */
 /*ARGSUSED*/
 syscall(frame)
  */
 /*ARGSUSED*/
 syscall(frame)
-       struct syscframe frame;
-/*#define code frame.sf_eax    /* note: written over! */
-#define pc frame.sf_eip
+       volatile struct syscframe frame;
 {
        register int *locr0 = ((int *)&frame);
        register caddr_t params;
        register int i;
        register struct sysent *callp;
 {
        register int *locr0 = ((int *)&frame);
        register caddr_t params;
        register int i;
        register struct sysent *callp;
-       register struct proc *p;
+       register struct proc *p = curproc;
        struct timeval syst;
        int error, opc;
        int args[8], rval[2];
        struct timeval syst;
        int error, opc;
        int args[8], rval[2];
-int code;
+       int code;
 
 #ifdef lint
        r0 = 0; r0 = r0; r1 = 0; r1 = r1;
 #endif
 
 #ifdef lint
        r0 = 0; r0 = r0; r1 = 0; r1 = r1;
 #endif
-       syst = u.u_ru.ru_stime;
-       p = u.u_procp;
-       if (ISPL(locr0[sCS]) != SEL_UPL)
-{
-printf("\npc:%x cs:%x eflags:%x\n",
-               frame.sf_eip, frame.sf_cs, frame.sf_eflags);
-printf("edi %x esi %x ebp %x ebx %x esp %x\n",
-               frame.sf_edi, frame.sf_esi, frame.sf_ebp,
-               frame.sf_ebx, frame.sf_esp);
-printf("edx %x ecx %x eax %x\n", frame.sf_edx, frame.sf_ecx, frame.sf_eax);
-printf("cr0 %x cr2 %x cpl %x \n", rcr0(), rcr2(), cpl);
+       syst = p->p_stime;
+       if (ISPL(frame.sf_cs) != SEL_UPL)
                panic("syscall");
                panic("syscall");
-}
-if (um) {*(int *)PTmap &= 0xfffffffe; load_cr3(rcr3()); }
-/*if(u.u_procp && (u.u_procp->p_pid == 1 || u.u_procp->p_pid == 3)) {
-       if( *(u_char *) 0xf7c != 0xc7) {
-               printf("%x!", *(u_char *) 0xf7c);
-               *(u_char *) 0xf7c = 0xc7;
-       }
-}*/
-       u.u_ar0 = locr0;
-       params = (caddr_t)locr0[sESP] + NBPW ;
-code = frame.sf_eax;
+
+       code = frame.sf_eax;
+       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.
         */
 
        /*
         * Reconstruct pc, assuming lcall $X,y is 7 bytes, as it is always.
         */
-       opc = pc - 7;
+       opc = frame.sf_eip - 7;
        callp = (code >= nsysent) ? &sysent[63] : &sysent[code];
        if (callp == sysent) {
                i = fuword(params);
        callp = (code >= nsysent) ? &sysent[63] : &sysent[code];
        if (callp == sysent) {
                i = fuword(params);
-               params += NBPW;
+               params += sizeof (int);
                callp = (code >= nsysent) ? &sysent[63] : &sysent[code];
        }
                callp = (code >= nsysent) ? &sysent[63] : &sysent[code];
        }
-dprintf(DALLSYSC,"%d. call %d ", p->p_pid, code);
+
        if ((i = callp->sy_narg * sizeof (int)) &&
            (error = copyin(params, (caddr_t)args, (u_int)i))) {
        if ((i = callp->sy_narg * sizeof (int)) &&
            (error = copyin(params, (caddr_t)args, (u_int)i))) {
-               locr0[sEAX] = /*(u_char)*/ error;
-               locr0[sEFLAGS] |= PSL_C;        /* carry bit */
-#ifdef KTRACEx
+               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;
        }
                if (KTRPOINT(p, KTR_SYSCALL))
                        ktrsyscall(p->p_tracep, code, callp->sy_narg, &args);
 #endif
                goto done;
        }
-#ifdef KTRACEx
+#ifdef KTRACE
        if (KTRPOINT(p, KTR_SYSCALL))
                ktrsyscall(p->p_tracep, code, callp->sy_narg, &args);
 #endif
        rval[0] = 0;
        if (KTRPOINT(p, KTR_SYSCALL))
                ktrsyscall(p->p_tracep, code, callp->sy_narg, &args);
 #endif
        rval[0] = 0;
-       rval[1] = locr0[sEDX];
+       rval[1] = frame.sf_edx;
        error = (*callp->sy_call)(p, args, rval);
        if (error == ERESTART)
        error = (*callp->sy_call)(p, args, rval);
        if (error == ERESTART)
-               pc = opc;
+               frame.sf_eip = opc;
        else if (error != EJUSTRETURN) {
                if (error) {
        else if (error != EJUSTRETURN) {
                if (error) {
-                       locr0[sEAX] = error;
-                       locr0[sEFLAGS] |= PSL_C;        /* carry bit */
+                       frame.sf_eax = error;
+                       frame.sf_eflags |= PSL_C;       /* carry bit */
                } else {
                } else {
-                       locr0[sEAX] = rval[0];
-                       locr0[sEDX] = rval[1];
-                       locr0[sEFLAGS] &= ~PSL_C;       /* carry bit */
+                       frame.sf_eax = rval[0];
+                       frame.sf_edx = rval[1];
+                       frame.sf_eflags &= ~PSL_C;      /* carry bit */
                }
        }
        /* else if (error == EJUSTRETURN) */
                }
        }
        /* else if (error == EJUSTRETURN) */
@@ -437,22 +408,13 @@ done:
         * Reinitialize proc pointer `p' as it may be different
         * if this is a child returning from fork syscall.
         */
         * Reinitialize proc pointer `p' as it may be different
         * if this is a child returning from fork syscall.
         */
-       p = u.u_procp;
-       /*
-        * XXX the check for sigreturn ensures that we don't
-        * attempt to set up a call to a signal handler (sendsig) before
-        * we have cleaned up the stack from the last call (sigreturn).
-        * Allowing this seems to lock up the machine in certain scenarios.
-        * What should really be done is to clean up the signal handling
-        * so that this is not a problem.
-        */
-#include "syscall.h"
-       if (code != SYS_sigreturn && (i = CURSIG(p)))
-               psig(i,0);
+       p = curproc;
+       while (i = CURSIG(p))
+               psig(i);
        p->p_pri = p->p_usrpri;
        p->p_pri = p->p_usrpri;
-       if (runrun) {
+       if (want_resched) {
                /*
                /*
-                * Since we are u.u_procp, clock will normally just change
+                * 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
                 * 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
@@ -461,52 +423,30 @@ done:
                 */
                (void) splclock();
                setrq(p);
                 */
                (void) splclock();
                setrq(p);
-               u.u_ru.ru_nivcsw++;
+               p->p_stats->p_ru.ru_nivcsw++;
                swtch();
                swtch();
-               if (code != SYS_sigreturn && (i = CURSIG(p)))
-                       psig(i,0);
+               while (i = CURSIG(p))
+                       psig(i);
        }
        }
-       if (u.u_prof.pr_scale) {
+       if (p->p_stats->p_prof.pr_scale) {
                int ticks;
                int ticks;
-               struct timeval *tv = &u.u_ru.ru_stime;
+               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;
 
                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(pc, &u.u_prof, ticks * profscale);
+                       addupc(frame.sf_eip, &p->p_stats->p_prof,
+                           ticks * profscale);
 #else
 #else
-                       addupc(pc, &u.u_prof, ticks);
+                       addupc(frame.sf_eip, &p->p_stats->p_prof, ticks);
 #endif
                }
        }
        curpri = p->p_pri;
 #endif
                }
        }
        curpri = p->p_pri;
-#ifdef KTRACEx
+#ifdef KTRACE
        if (KTRPOINT(p, KTR_SYSRET))
                ktrsysret(p->p_tracep, code, error, rval[0]);
 #endif
 }
        if (KTRPOINT(p, KTR_SYSRET))
                ktrsysret(p->p_tracep, code, error, rval[0]);
 #endif
 }
-
-#ifdef notdef
-/*
- * nonexistent system call-- signal process (may want to handle it)
- * flag error if process won't see signal immediately
- * Q: should we do that all the time ??
- */
-nosys()
-{
-
-       if (u.u_signal[SIGSYS] == SIG_IGN || u.u_signal[SIGSYS] == SIG_HOLD)
-               u.u_error = EINVAL;
-       psignal(u.u_procp, SIGSYS);
-}
-#endif
-
-/*
- * Ignored system call
- */
-nullsys()
-{
-
-}