improvements
authorDon Ahn <donahn@ucbvax.Berkeley.EDU>
Sun, 24 Jun 1990 10:33:59 +0000 (02:33 -0800)
committerDon Ahn <donahn@ucbvax.Berkeley.EDU>
Sun, 24 Jun 1990 10:33:59 +0000 (02:33 -0800)
SCCS-vsn: sys/i386/i386/machdep.c 5.2
SCCS-vsn: sys/i386/i386/swapgeneric.c 5.3
SCCS-vsn: sys/i386/i386/trap.c 5.2
SCCS-vsn: sys/i386/i386/vm_machdep.c 5.2

usr/src/sys/i386/i386/machdep.c
usr/src/sys/i386/i386/swapgeneric.c
usr/src/sys/i386/i386/trap.c
usr/src/sys/i386/i386/vm_machdep.c

index 287d767..5a4aab1 100644 (file)
@@ -7,9 +7,16 @@
  *
  * %sccs.include.386.c%
  *
  *
  * %sccs.include.386.c%
  *
- *     @(#)machdep.c   5.1 (Berkeley) %G%
+ *     @(#)machdep.c   5.2 (Berkeley) %G%
  */
 
  */
 
+/*
+ * Copyright (c) 1982,1987 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ *     @(#)machdep.c   1.16.1.1 (Berkeley) 11/24/87
+ */
 
 #include "param.h"
 #include "systm.h"
 
 #include "param.h"
 #include "systm.h"
@@ -89,15 +96,28 @@ kernel and run-time configured storage (e.g. valloc), using memory
 above 0x100000 for the cmap, and wasting the stuff left over after
 valloc-end up to 0xa0000 (640K). Will have to fix this before beta,
 and will have to somehow move this out into per bus adapter directory
 above 0x100000 for the cmap, and wasting the stuff left over after
 valloc-end up to 0xa0000 (640K). Will have to fix this before beta,
 and will have to somehow move this out into per bus adapter directory
-(e.g. configurable). For now, punt */
+(e.g. configurable). For now, punt
+
+How about starting cmap normally following valloc space, and then
+write a routine than allocs only phys pages in the 0xa0000-0x100000
+hole?
+
+*/
        kernmem = 640/4;
        kernmem -= btoc(sizeof (struct msgbuf));
        kernmem = 640/4;
        kernmem -= btoc(sizeof (struct msgbuf));
-/*pg("kern %x, msgbufmap", kernmem);*/
        pte = msgbufmap;
        for (i = 0; i < btoc(sizeof (struct msgbuf)); i++)
                *(int *)pte++ = PG_V | PG_KW | ctob(kernmem + i);
        pte = msgbufmap;
        for (i = 0; i < btoc(sizeof (struct msgbuf)); i++)
                *(int *)pte++ = PG_V | PG_KW | ctob(kernmem + i);
-/*XXX*/        maxmem = freemem = physmem = 1024/4+kernmem;
-       cmaxmem = 1024/4;
+/*XXX*/        maxmem = freemem = physmem = 2048/4+kernmem;
+       cmaxmem = 2048/4;
+
+/* unmap particular region being written into, so we can find offending ptr */
+/*{ extern char b_uregion[], e_uregion[];
+#define        ptidx(s)        ((s - sbase)/NBPG)
+       pte = Sysmap + ptidx(b_uregion) + 1 ;
+       for (i = ptidx(b_uregion) + 1 ; i < ptidx (e_uregion) ; i++)
+               *(int *)pte++ = 0 ;
+}*/
        load_cr3(_cr3());
 
 #ifdef KDB
        load_cr3(_cr3());
 
 #ifdef KDB
@@ -121,7 +141,6 @@ and will have to somehow move this out into per bus adapter directory
         */
        v = (caddr_t)(sbase + (firstaddr * NBPG));
        /*v = sbase + (firstaddr * NBPG);*/
         */
        v = (caddr_t)(sbase + (firstaddr * NBPG));
        /*v = sbase + (firstaddr * NBPG);*/
-/*pg("vallocs %x", v);*/
 #define        valloc(name, type, num) \
            (name) = (type *)v; v = (caddr_t)((name)+(num))
 #define        valloclim(name, type, num, lim) \
 #define        valloc(name, type, num) \
            (name) = (type *)v; v = (caddr_t)((name)+(num))
 #define        valloclim(name, type, num, lim) \
@@ -237,7 +256,6 @@ and will have to somehow move this out into per bus adapter directory
                mapaddr += MAXBSIZE / NBPG;
        }
 
                mapaddr += MAXBSIZE / NBPG;
        }
 
-       /*unixsize = btoc((int)(v - sbase));*/
        unixsize = btoc((int)(v - sbase));
        if (firstaddr >= physmem - 8*UPAGES)
                panic("no memory");
        unixsize = btoc((int)(v - sbase));
        if (firstaddr >= physmem - 8*UPAGES)
                panic("no memory");
@@ -258,7 +276,7 @@ and will have to somehow move this out into per bus adapter directory
         * THE USER PAGE TABLE MAP IS CALLED ``kernelmap''
         * WHICH IS A VERY UNDESCRIPTIVE AND INCONSISTENT NAME.
         */
         * THE USER PAGE TABLE MAP IS CALLED ``kernelmap''
         * WHICH IS A VERY UNDESCRIPTIVE AND INCONSISTENT NAME.
         */
-firstaddr = 0x100; maxmem = 0x200;             /*XXX*/
+firstaddr = 0x100; maxmem = 0x300;             /*XXX*/
        meminit(firstaddr, maxmem);
        maxmem = freemem;
        printf("avail mem = %d\n", ctob(maxmem));
        meminit(firstaddr, maxmem);
        maxmem = freemem;
        printf("avail mem = %d\n", ctob(maxmem));
@@ -270,7 +288,8 @@ firstaddr = 0x100; maxmem = 0x200;          /*XXX*/
  * PTEs for mapping user space into kernel for phyio operations.
  * One page is enough to handle 4Mb of simultaneous raw IO operations.
  */
  * PTEs for mapping user space into kernel for phyio operations.
  * One page is enough to handle 4Mb of simultaneous raw IO operations.
  */
-#define USRIOSIZE      (30)
+#undef USRIOSIZE
+#define USRIOSIZE 30
        rminit(useriomap, (long)USRIOSIZE, (long)1, "usrio", nproc);
        rminit(mbmap, (long)(nmbclusters * CLSIZE), (long)CLSIZE,
            "mbclusters", nmbclusters/4);
        rminit(useriomap, (long)USRIOSIZE, (long)1, "usrio", nproc);
        rminit(mbmap, (long)(nmbclusters * CLSIZE), (long)CLSIZE,
            "mbclusters", nmbclusters/4);
@@ -366,6 +385,7 @@ sendsig(p, sig, mask, frmtrp)
                 * Process has trashed its stack; give it an illegal
                 * instruction to halt it in its tracks.
                 */
                 * Process has trashed its stack; give it an illegal
                 * instruction to halt it in its tracks.
                 */
+printf("sendsig: failed to grow stack %x\n", fp);
                u.u_signal[SIGILL] = SIG_DFL;
                sig = sigmask(SIGILL);
                u.u_procp->p_sigignore &= ~sig;
                u.u_signal[SIGILL] = SIG_DFL;
                sig = sigmask(SIGILL);
                u.u_procp->p_sigignore &= ~sig;
@@ -797,7 +817,7 @@ struct region_descriptor r_idt = {
        sizeof(idt)-1,(char *)idt
 };
 
        sizeof(idt)-1,(char *)idt
 };
 
-setidt(idx, func, typ) char *func; {
+setidt(idx, func, typ, dpl) char *func; {
        struct gate_descriptor *ip = idt + idx;
 
        ip->gd_looffset = (int)func;
        struct gate_descriptor *ip = idt + idx;
 
        ip->gd_looffset = (int)func;
@@ -805,7 +825,7 @@ setidt(idx, func, typ) char *func; {
        ip->gd_stkcpy = 0;
        ip->gd_xx = 0;
        ip->gd_type = typ;
        ip->gd_stkcpy = 0;
        ip->gd_xx = 0;
        ip->gd_type = typ;
-       ip->gd_dpl = 0;
+       ip->gd_dpl = dpl;
        ip->gd_p = 1;
        ip->gd_hioffset = ((int)func)>>16 ;
 }
        ip->gd_p = 1;
        ip->gd_hioffset = ((int)func)>>16 ;
 }
@@ -879,58 +899,58 @@ init386() { extern ssdtosd(), lgdt(), lidt(), lldt(), etext;
 /* Note. eventually want private ldts per process */
 
 /* exceptions */
 /* Note. eventually want private ldts per process */
 
 /* exceptions */
-       setidt(0, &IDTVEC(div),  SDT_SYS386TGT);
-       setidt(1, &IDTVEC(dbg),  SDT_SYS386TGT);
-       setidt(2, &IDTVEC(nmi),  SDT_SYS386TGT);
-       setidt(3, &IDTVEC(bpt),  SDT_SYS386TGT);
-       setidt(4, &IDTVEC(ofl),  SDT_SYS386TGT);
-       setidt(5, &IDTVEC(bnd),  SDT_SYS386TGT);
-       setidt(6, &IDTVEC(ill),  SDT_SYS386TGT);
-       setidt(7, &IDTVEC(dna),  SDT_SYS386TGT);
-       setidt(8, &IDTVEC(dble),  SDT_SYS386TGT);
-       setidt(9, &IDTVEC(fpusegm),  SDT_SYS386TGT);
-       setidt(10, &IDTVEC(tss),  SDT_SYS386TGT);
-       setidt(11, &IDTVEC(missing),  SDT_SYS386TGT);
-       setidt(12, &IDTVEC(stk),  SDT_SYS386TGT);
-       setidt(13, &IDTVEC(prot),  SDT_SYS386TGT);
-       setidt(14, &IDTVEC(page),  SDT_SYS386TGT);
-       setidt(15, &IDTVEC(rsvd),  SDT_SYS386TGT);
-       setidt(16, &IDTVEC(fpu),  SDT_SYS386TGT);
-       setidt(17, &IDTVEC(rsvd0),  SDT_SYS386TGT);
-       setidt(18, &IDTVEC(rsvd1),  SDT_SYS386TGT);
-       setidt(19, &IDTVEC(rsvd2),  SDT_SYS386TGT);
-       setidt(20, &IDTVEC(rsvd3),  SDT_SYS386TGT);
-       setidt(21, &IDTVEC(rsvd4),  SDT_SYS386TGT);
-       setidt(22, &IDTVEC(rsvd5),  SDT_SYS386TGT);
-       setidt(23, &IDTVEC(rsvd6),  SDT_SYS386TGT);
-       setidt(24, &IDTVEC(rsvd7),  SDT_SYS386TGT);
-       setidt(25, &IDTVEC(rsvd8),  SDT_SYS386TGT);
-       setidt(26, &IDTVEC(rsvd9),  SDT_SYS386TGT);
-       setidt(27, &IDTVEC(rsvd10),  SDT_SYS386TGT);
-       setidt(28, &IDTVEC(rsvd11),  SDT_SYS386TGT);
-       setidt(29, &IDTVEC(rsvd12),  SDT_SYS386TGT);
-       setidt(30, &IDTVEC(rsvd13),  SDT_SYS386TGT);
-       setidt(31, &IDTVEC(rsvd14),  SDT_SYS386TGT);
+       setidt(0, &IDTVEC(div),  SDT_SYS386TGT, SEL_KPL);
+       setidt(1, &IDTVEC(dbg),  SDT_SYS386TGT, SEL_KPL);
+       setidt(2, &IDTVEC(nmi),  SDT_SYS386TGT, SEL_KPL);
+         setidt(3, &IDTVEC(bpt),  SDT_SYS386TGT, SEL_UPL);
+       setidt(4, &IDTVEC(ofl),  SDT_SYS386TGT, SEL_KPL);
+       setidt(5, &IDTVEC(bnd),  SDT_SYS386TGT, SEL_KPL);
+       setidt(6, &IDTVEC(ill),  SDT_SYS386TGT, SEL_KPL);
+       setidt(7, &IDTVEC(dna),  SDT_SYS386TGT, SEL_KPL);
+       setidt(8, &IDTVEC(dble),  SDT_SYS386TGT, SEL_KPL);
+       setidt(9, &IDTVEC(fpusegm),  SDT_SYS386TGT, SEL_KPL);
+       setidt(10, &IDTVEC(tss),  SDT_SYS386TGT, SEL_KPL);
+       setidt(11, &IDTVEC(missing),  SDT_SYS386TGT, SEL_KPL);
+       setidt(12, &IDTVEC(stk),  SDT_SYS386TGT, SEL_KPL);
+       setidt(13, &IDTVEC(prot),  SDT_SYS386TGT, SEL_KPL);
+       setidt(14, &IDTVEC(page),  SDT_SYS386TGT, SEL_KPL);
+       setidt(15, &IDTVEC(rsvd),  SDT_SYS386TGT, SEL_KPL);
+       setidt(16, &IDTVEC(fpu),  SDT_SYS386TGT, SEL_KPL);
+       setidt(17, &IDTVEC(rsvd0),  SDT_SYS386TGT, SEL_KPL);
+       setidt(18, &IDTVEC(rsvd1),  SDT_SYS386TGT, SEL_KPL);
+       setidt(19, &IDTVEC(rsvd2),  SDT_SYS386TGT, SEL_KPL);
+       setidt(20, &IDTVEC(rsvd3),  SDT_SYS386TGT, SEL_KPL);
+       setidt(21, &IDTVEC(rsvd4),  SDT_SYS386TGT, SEL_KPL);
+       setidt(22, &IDTVEC(rsvd5),  SDT_SYS386TGT, SEL_KPL);
+       setidt(23, &IDTVEC(rsvd6),  SDT_SYS386TGT, SEL_KPL);
+       setidt(24, &IDTVEC(rsvd7),  SDT_SYS386TGT, SEL_KPL);
+       setidt(25, &IDTVEC(rsvd8),  SDT_SYS386TGT, SEL_KPL);
+       setidt(26, &IDTVEC(rsvd9),  SDT_SYS386TGT, SEL_KPL);
+       setidt(27, &IDTVEC(rsvd10),  SDT_SYS386TGT, SEL_KPL);
+       setidt(28, &IDTVEC(rsvd11),  SDT_SYS386TGT, SEL_KPL);
+       setidt(29, &IDTVEC(rsvd12),  SDT_SYS386TGT, SEL_KPL);
+       setidt(30, &IDTVEC(rsvd13),  SDT_SYS386TGT, SEL_KPL);
+       setidt(31, &IDTVEC(rsvd14),  SDT_SYS386TGT, SEL_KPL);
 
 /* first icu */
 
 /* first icu */
-       setidt(32, &IDTVEC(intr0),  SDT_SYS386IGT);
-       setidt(33, &IDTVEC(intr1),  SDT_SYS386IGT);
-       setidt(34, &IDTVEC(intr9),  SDT_SYS386IGT); /* note: never happens */
-       setidt(35, &IDTVEC(intr3),  SDT_SYS386IGT);
-       setidt(36, &IDTVEC(intr4),  SDT_SYS386IGT);
-       setidt(37, &IDTVEC(intr5),  SDT_SYS386IGT);
-       setidt(38, &IDTVEC(intr6),  SDT_SYS386IGT);
-       setidt(39, &IDTVEC(intr7),  SDT_SYS386IGT);
+       setidt(32, &IDTVEC(intr0),  SDT_SYS386IGT, SEL_KPL);
+       setidt(33, &IDTVEC(intr1),  SDT_SYS386IGT, SEL_KPL);
+       setidt(34, &IDTVEC(intr9),  SDT_SYS386IGT, SEL_KPL); /* note: never happens */
+       setidt(35, &IDTVEC(intr3),  SDT_SYS386IGT, SEL_KPL);
+       setidt(36, &IDTVEC(intr4),  SDT_SYS386IGT, SEL_KPL);
+       setidt(37, &IDTVEC(intr5),  SDT_SYS386IGT, SEL_KPL);
+       setidt(38, &IDTVEC(intr6),  SDT_SYS386IGT, SEL_KPL);
+       setidt(39, &IDTVEC(intr7),  SDT_SYS386IGT, SEL_KPL);
 
 /* second icu */
 
 /* second icu */
-       setidt(40, &IDTVEC(intr8),  SDT_SYS386IGT);
-       setidt(41, &IDTVEC(intr9),  SDT_SYS386IGT);
-       setidt(42, &IDTVEC(intr10),  SDT_SYS386IGT);
-       setidt(43, &IDTVEC(intr11),  SDT_SYS386IGT);
-       setidt(44, &IDTVEC(intr12),  SDT_SYS386IGT);
-       setidt(45, &IDTVEC(intr13),  SDT_SYS386IGT);
-       setidt(46, &IDTVEC(intr14),  SDT_SYS386IGT);
-       setidt(47, &IDTVEC(intr15),  SDT_SYS386IGT);
+       setidt(40, &IDTVEC(intr8),  SDT_SYS386IGT, SEL_KPL);
+       setidt(41, &IDTVEC(intr9),  SDT_SYS386IGT, SEL_KPL);
+       setidt(42, &IDTVEC(intr10),  SDT_SYS386IGT, SEL_KPL);
+       setidt(43, &IDTVEC(intr11),  SDT_SYS386IGT, SEL_KPL);
+       setidt(44, &IDTVEC(intr12),  SDT_SYS386IGT, SEL_KPL);
+       setidt(45, &IDTVEC(intr13),  SDT_SYS386IGT, SEL_KPL);
+       setidt(46, &IDTVEC(intr14),  SDT_SYS386IGT, SEL_KPL);
+       setidt(47, &IDTVEC(intr15),  SDT_SYS386IGT, SEL_KPL);
 
        lgdt(gdt, sizeof(gdt)-1);
        lidt(idt, sizeof(idt)-1);
 
        lgdt(gdt, sizeof(gdt)-1);
        lidt(idt, sizeof(idt)-1);
@@ -1041,56 +1061,80 @@ vmunaccess() {}
  */
 copyinstr(fromaddr, toaddr, maxlength, lencopied) int *lencopied;
        char *toaddr; {
  */
 copyinstr(fromaddr, toaddr, maxlength, lencopied) int *lencopied;
        char *toaddr; {
-       int c;
-       char *t = toaddr;
+       int c,tally;
 
 
-/*printf("\ncpyinstr(%x,%x) %x|", fromaddr, toaddr, *(((int *) &fromaddr) - 1) );*/
-       *lencopied = 0;
+       tally = 0;
        while (maxlength--) {
                c = fubyte(fromaddr++);
        while (maxlength--) {
                c = fubyte(fromaddr++);
-               if (c == -1) return(EFAULT);
-c &= 0xff;
-               (*lencopied)++;
+               if (c == -1) {
+                       if(lencopied) *lencopied = tally;
+                       return(EFAULT);
+               }
+               tally++;
                *toaddr++ = (char) c;
                if (c == 0){
                *toaddr++ = (char) c;
                if (c == 0){
-/* if(*lencopied < 50 && *t > 0) printf("%s|\n", t);*/
-return(0);
-}
+                       if(lencopied) *lencopied = tally;
+                       return(0);
+               }
        }
        }
+       if(lencopied) *lencopied = tally;
        return(ENOENT);
 }
 
 copyoutstr(fromaddr, toaddr, maxlength, lencopied) int *lencopied;
        u_char *fromaddr; {
        int c;
        return(ENOENT);
 }
 
 copyoutstr(fromaddr, toaddr, maxlength, lencopied) int *lencopied;
        u_char *fromaddr; {
        int c;
-       u_char *f = fromaddr;
-
-/*printf("\ncpyoutstr(%x,%x)%x|", fromaddr, toaddr, maxlength, 
-       *(((int *) &fromaddr) - 1) );*/
+       int tally;
 
 
-       *lencopied = 0;
+       tally = 0;
        while (maxlength--) {
                c = subyte(toaddr++,*fromaddr);
                if (c == -1) return(EFAULT);
        while (maxlength--) {
                c = subyte(toaddr++,*fromaddr);
                if (c == -1) return(EFAULT);
-               (*lencopied)++;
+               tally++;
                if (*fromaddr++ == 0){
                if (*fromaddr++ == 0){
-/*if(*lencopied < 50 && *f < 127) printf("%s|\n", f);*/
+                       if(lencopied) *lencopied = tally;
                        return(0);
                        return(0);
-}
+               }
        }
        }
+       if(lencopied) *lencopied = tally;
        return(ENOENT);
 }
 
 copystr(fromaddr, toaddr, maxlength, lencopied) int *lencopied;
        u_char *fromaddr, *toaddr; {
        return(ENOENT);
 }
 
 copystr(fromaddr, toaddr, maxlength, lencopied) int *lencopied;
        u_char *fromaddr, *toaddr; {
-       int c;
+       int tally;
 
 
-       *lencopied = 0;
+       tally = 0;
        while (maxlength--) {
                *toaddr = *fromaddr++;
        while (maxlength--) {
                *toaddr = *fromaddr++;
-               (*lencopied)++;
-               if (*toaddr++ == 0)
+               tally++;
+               if (*toaddr++ == 0) {
+                       if(lencopied) *lencopied = tally;
                        return(0);
                        return(0);
+               }
        }
        }
+       if(lencopied) *lencopied = tally;
        return(ENOENT);
 }
        return(ENOENT);
 }
+
+/* 
+ * ovbcopy - like bcopy, but recognizes overlapping ranges and handles 
+ *           them correctly.
+ */
+ovbcopy(from, to, bytes)
+       char *from, *to;
+       int bytes;                      /* num bytes to copy */
+{
+       /* Assume that bcopy copies left-to-right (low addr first). */
+       if (from + bytes <= to || to + bytes <= from || to == from)
+               bcopy(from, to, bytes); /* non-overlapping or no-op*/
+       else if (from > to)
+               bcopy(from, to, bytes); /* overlapping but OK */
+       else {
+               /* to > from: overlapping, and must copy right-to-left. */
+               from += bytes - 1;
+               to += bytes - 1;
+               while (bytes-- > 0)
+                       *to-- = *from--;
+       }
+}
index c566d95..1487566 100644 (file)
@@ -7,9 +7,10 @@
  *
  * %sccs.include.386.c%
  *
  *
  * %sccs.include.386.c%
  *
- *     @(#)swapgeneric.c       5.2 (Berkeley) %G%
+ *     @(#)swapgeneric.c       5.3 (Berkeley) %G%
  */
 
  */
 
+/*     swapgeneric.c   1.5     86/11/25        */
 
 #include "../machine/pte.h"
 
 
 #include "../machine/pte.h"
 
 /*
  * Generic configuration;  all in one
  */
 /*
  * Generic configuration;  all in one
  */
-dev_t  rootdev = 0;
-dev_t  argdev = 1;
-dev_t  dumpdev = 1;
+dev_t  rootdev = makedev(0,0);
+dev_t  argdev = makedev(0,1);
+dev_t  dumpdev = makedev(0,1);
 int    nswap;
 struct swdevt swdevt[] = {
 int    nswap;
 struct swdevt swdevt[] = {
-       { 1,    0,      4*4096 },
+       { 1,    0,      0 },
        { 0,    1,      0 },
 };
 long   dumplo;
        { 0,    1,      0 },
 };
 long   dumplo;
@@ -41,7 +42,7 @@ struct        genericconf {
        char    *gc_name;
        dev_t   gc_root;
 } genericconf[] = {
        char    *gc_name;
        dev_t   gc_root;
 } genericconf[] = {
-       { (caddr_t)&wddriver,   "wd",   makedev(1, 0),  },
+       { (caddr_t)&wddriver,   "wd",   makedev(0, 0),  },
        { 0 },
 };
 
        { 0 },
 };
 
index 9359bfd..97c07ac 100644 (file)
@@ -44,6 +44,7 @@ trap(frame)
        struct timeval syst;
        extern int nofault;
 
        struct timeval syst;
        extern int nofault;
 
+#ifdef DEBUG
 dprintf(DALLTRAPS, "%d. trap",u.u_procp->p_pid);
 dprintf(DALLTRAPS, "\npc:%x cs:%x ds:%x eflags:%x isp %x\n",
                frame.tf_eip, frame.tf_cs, frame.tf_ds, frame.tf_eflags,
 dprintf(DALLTRAPS, "%d. trap",u.u_procp->p_pid);
 dprintf(DALLTRAPS, "\npc:%x cs:%x ds:%x eflags:%x isp %x\n",
                frame.tf_eip, frame.tf_cs, frame.tf_ds, frame.tf_eflags,
@@ -55,8 +56,9 @@ dprintf(DALLTRAPS, "edx %x ecx %x eax %x\n",
                frame.tf_edx, frame.tf_ecx, frame.tf_eax);
 dprintf(DALLTRAPS|DPAUSE, "ec %x type %x cr0 %x cr2 %x cpl %x \n",
                frame.tf_err, frame.tf_trapno, rcr0(), rcr2(), cpl);
                frame.tf_edx, frame.tf_ecx, frame.tf_eax);
 dprintf(DALLTRAPS|DPAUSE, "ec %x type %x cr0 %x cr2 %x cpl %x \n",
                frame.tf_err, frame.tf_trapno, rcr0(), rcr2(), cpl);
+#endif
 
 
-       locr0[tEFLAGS] &= ~PSL_NT;      /* clear nested trap */
+       locr0[tEFLAGS] &= ~PSL_NT;      /* clear nested trap XXX */
 if(nofault && frame.tf_trapno != 0xc)
        { locr0[tEIP] = nofault; return;}
 
 if(nofault && frame.tf_trapno != 0xc)
        { locr0[tEIP] = nofault; return;}
 
@@ -68,6 +70,7 @@ if(nofault && frame.tf_trapno != 0xc)
        switch (type) {
 
        default:
        switch (type) {
 
        default:
+bit_sucker:
 #ifdef KDB
                if (kdb_trap(&psl))
                        return;
 #ifdef KDB
                if (kdb_trap(&psl))
                        return;
@@ -77,13 +80,16 @@ if(nofault && frame.tf_trapno != 0xc)
                panic("trap");
                /*NOTREACHED*/
 
                panic("trap");
                /*NOTREACHED*/
 
+       case T_SEGNPFLT + USER:
        case T_PROTFLT + USER:          /* protection fault */
        case T_PROTFLT + USER:          /* protection fault */
+               u.u_code = code + BUS_SEGM_FAULT ;
                i = SIGBUS;
                break;
 
        case T_PRIVINFLT + USER:        /* privileged instruction fault */
        case T_RESADFLT + USER:         /* reserved addressing fault */
                i = SIGBUS;
                break;
 
        case T_PRIVINFLT + USER:        /* privileged instruction fault */
        case T_RESADFLT + USER:         /* reserved addressing fault */
-       case T_RESOPFLT + USER:         /* resereved operand fault */
+       case T_RESOPFLT + USER:         /* reserved operand fault */
+       case T_FPOPFLT + USER:          /* coprocessor operand fault */
                u.u_code = type &~ USER;
                i = SIGILL;
                break;
                u.u_code = type &~ USER;
                i = SIGILL;
                break;
@@ -97,8 +103,27 @@ if(nofault && frame.tf_trapno != 0xc)
                }
                goto out;
 
                }
                goto out;
 
-       case T_ARITHTRAP + USER:
+       case T_DNA + USER:
+               u.u_code = FPE_FPU_NP_TRAP;
+               i = SIGFPE;
+               break;
+
+       case T_BOUND + USER:
+               u.u_code = FPE_SUBRNG_TRAP;
+               i = SIGFPE;
+               break;
+
+       case T_OFLOW + USER:
+               u.u_code = FPE_INTOVF_TRAP;
+               i = SIGFPE;
+               break;
+
        case T_DIVIDE + USER:
        case T_DIVIDE + USER:
+               u.u_code = FPE_INTDIV_TRAP;
+               i = SIGFPE;
+               break;
+
+       case T_ARITHTRAP + USER:
                u.u_code = code;
                i = SIGFPE;
                break;
                u.u_code = code;
                i = SIGFPE;
                break;
@@ -111,7 +136,7 @@ if(nofault && frame.tf_trapno != 0xc)
        case T_SEGFLT + USER:
                if (grow((unsigned)locr0[tESP]) /*|| grow(code)*/)
                        goto out;
        case T_SEGFLT + USER:
                if (grow((unsigned)locr0[tESP]) /*|| grow(code)*/)
                        goto out;
-xxx:
+               u.u_code = code;
                i = SIGSEGV;
                break;
 
                i = SIGSEGV;
                break;
 
@@ -124,28 +149,57 @@ xxx:
                        { register u_int vp;
                        struct pte *pte;
 
                        { register u_int vp;
                        struct pte *pte;
 
-                       if (rcr2() >= &Sysbase) goto xxx;
-                       vp = btop((int)rcr2());
-                       if (vp >= dptov(u.u_procp, u.u_procp->p_dsize) &&
-                           vp < sptov(u.u_procp, u.u_procp->p_ssize-1)) {
-                               if (grow((unsigned)locr0[tESP]) || grow(rcr2()))
-                               goto out;
-                               else    {
-if(nofault) { locr0[tEIP] = nofault; return;}
-printf("didnt");
-                               i = SIGSEGV;
+                       if(u.u_procp->p_pid == 2) goto bit_sucker;
+#define PGEX_P 0x01
+                       if (rcr2() >= &Sysbase || code & PGEX_P) {
+                               u.u_code = code + BUS_PAGE_FAULT;
+                               i = SIGBUS;
                                break;
                                break;
+                       } else {
+                               vp = btop((int)rcr2());
+                               if (vp >= dptov(u.u_procp, u.u_procp->p_dsize)
+                               && vp < sptov(u.u_procp, u.u_procp->p_ssize-1)){
+                                       if (grow((unsigned)locr0[tESP])
+                                       || grow(rcr2()))
+                                               goto out;
+                                       else    if (nofault) {
+                                               locr0[tEIP] = nofault;
+                                               return;
+                                       }
+#ifdef DEBUG
+pg("didnt ");
+printf("\npc:%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);
+printf("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);
+printf("edx %x ecx %x eax %x\n",
+               frame.tf_edx, frame.tf_ecx, frame.tf_eax);
+printf("ec %x type %x cr0 %x cr2 %x cpl %x \n",
+               frame.tf_err, frame.tf_trapno, rcr0(), rcr2(), cpl);
+#endif
+                                       i = SIGSEGV;
+                                       break;
+                               }
+                               i = u.u_error;
+                               pagein(rcr2(), 0);
+                               u.u_error = i;
+                               if (type == T_PAGEFLT) return;
+
+                               if(nofault) {
+                                       locr0[tEIP] = nofault;
+                                       return;
                                }
                                }
+                               goto out;
                        }
                        }
-                       i = u.u_error;
-                       pagein(rcr2(), 0);
-                       u.u_error = i;
-               if (type == T_PAGEFLT)
-                               return;
-if(nofault) { locr0[tEIP] = nofault; return;}
-                       goto out;
-       }
+               }
 
 
+       case T_TRCTRAP:  /* trace trap -- someone single stepping lcall's */
+               locr0[tEFLAGS] &= ~PSL_T;
+                       /* 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 + USER:           /* bpt instruction fault */
        case T_TRCTRAP + USER:          /* trace trap */
                locr0[tEFLAGS] &= ~PSL_T;
@@ -180,11 +234,6 @@ if(nofault) { locr0[tEIP] = nofault; return;}
 out:
        p = u.u_procp;
 
 out:
        p = u.u_procp;
 
-if(p->p_cursig)
-printf("out cursig %x flg %x sig %x ign %x msk %x\n", 
-       p->p_cursig,
-       p->p_flag, p->p_sig, p->p_sigignore, p->p_sigmask);
-
        if (p->p_cursig || ISSIG(p))
                psig(1);
        p->p_pri = p->p_usrpri;
        if (p->p_cursig || ISSIG(p))
                psig(1);
        p->p_pri = p->p_usrpri;
@@ -220,7 +269,6 @@ printf("out cursig %x flg %x sig %x ign %x msk %x\n",
 /*
  * Called from locore when a system call occurs
  */
 /*
  * Called from locore when a system call occurs
  */
-int fuckup;
 /*ARGSUSED*/
 syscall(frame)
        struct syscframe frame;
 /*ARGSUSED*/
 syscall(frame)
        struct syscframe frame;
@@ -240,9 +288,17 @@ syscall(frame)
 #endif
        syst = u.u_ru.ru_stime;
        if (ISPL(locr0[sCS]) != SEL_UPL)
 #endif
        syst = u.u_ru.ru_stime;
        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);
                panic("syscall");
                panic("syscall");
+}
        u.u_ar0 = locr0;
        u.u_ar0 = locr0;
-svfpsp();
        params = (caddr_t)locr0[sESP] + NBPW ;
        u.u_error = 0;
        /*
        params = (caddr_t)locr0[sESP] + NBPW ;
        u.u_error = 0;
        /*
@@ -271,7 +327,6 @@ svfpsp();
                u.u_eosys = NORMALRETURN;
                (*callp->sy_call)();
        }
                u.u_eosys = NORMALRETURN;
                (*callp->sy_call)();
        }
-/*rsfpsp();*/
        if (u.u_eosys == NORMALRETURN) {
                if (u.u_error) {
 /*dprintf(DSYSFAIL,"%d. fail %d %d\n",u.u_procp->p_pid,  code, u.u_error);*/
        if (u.u_eosys == NORMALRETURN) {
                if (u.u_error) {
 /*dprintf(DSYSFAIL,"%d. fail %d %d\n",u.u_procp->p_pid,  code, u.u_error);*/
@@ -330,7 +385,6 @@ nosys()
        psignal(u.u_procp, SIGSYS);
 }
 
        psignal(u.u_procp, SIGSYS);
 }
 
-#ifdef notdef
 /*
  * Ignored system call
  */
 /*
  * Ignored system call
  */
@@ -338,4 +392,3 @@ nullsys()
 {
 
 }
 {
 
 }
-#endif
index 2e358fb..05dafee 100644 (file)
@@ -7,9 +7,23 @@
  *
  * %sccs.include.386.c%
  *
  *
  * %sccs.include.386.c%
  *
- *     @(#)vm_machdep.c        5.1 (Berkeley) %G%
+ *     @(#)vm_machdep.c        5.2 (Berkeley) %G%
  */
 
  */
 
+/*
+ * Copyright (c) 1988 University of Utah.
+ * All rights reserved.  The Utah Software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ *     Utah $Hdr: vm_machdep.c 1.16.1.1 89/06/23$
+ */
+/*
+ * Copyright (c) 1982, 1986 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ *     @(#)vm_machdep.c        7.1 (Berkeley) 6/5/86
+ */
 
 #include "pte.h"
 
 
 #include "pte.h"
 
@@ -236,10 +250,11 @@ probew(addr)
        p = u.u_procp;
        page = btop(addr);
        if (page < dptov(p, p->p_dsize) || page > sptov(p, p->p_ssize))
        p = u.u_procp;
        page = btop(addr);
        if (page < dptov(p, p->p_dsize) || page > sptov(p, p->p_ssize))
+/*
 {
 {
-dprintf(DPHYS,"vtopte %x %x\n", vtopte(p, page), *(int *)vtopte(p, page) );
+dprintf(DPHYS,"vtopte %x %x\n", vtopte(p, page), *(int *)vtopte(p, page) );*/
                return((*(int *)vtopte(p, page) & PG_PROT) == PG_UW);
                return((*(int *)vtopte(p, page) & PG_PROT) == PG_UW);
-}
+/*}*/
        return(0);
 }
 
        return(0);
 }
 
@@ -256,7 +271,7 @@ kernacc(addr, count, rw)
        register int ix, cnt;
        extern long Syssize;
 
        register int ix, cnt;
        extern long Syssize;
 
-dprintf(DPHYS,"kernacc %x count %d rw %d", addr, count, rw);
+/*dprintf(DPHYS,"kernacc %x count %d rw %d", addr, count, rw);*/
        if (count <= 0)
                return(0);
        pde = (struct pde *)((u_int)u.u_procp->p_p0br + u.u_procp->p_szpt * NBPG);
        if (count <= 0)
                return(0);
        pde = (struct pde *)((u_int)u.u_procp->p_p0br + u.u_procp->p_szpt * NBPG);
@@ -265,25 +280,25 @@ dprintf(DPHYS,"kernacc %x count %d rw %d", addr, count, rw);
        cnt -= ix;
        for (pde += ix; cnt; cnt--, pde++)
                if (pde->pd_v == 0)
        cnt -= ix;
        for (pde += ix; cnt; cnt--, pde++)
                if (pde->pd_v == 0)
-{
-dprintf(DPHYS,"nope pde %x, idx %x\n", pde, ix);
+/*{
+dprintf(DPHYS,"nope pde %x, idx %x\n", pde, ix);*/
                        return(0);
                        return(0);
-}
+/*}*/
        ix = btop(addr-0xfe000000);
        cnt = btop(addr-0xfe000000+count+NBPG-1);
        if (cnt > (int)&Syssize)
        ix = btop(addr-0xfe000000);
        cnt = btop(addr-0xfe000000+count+NBPG-1);
        if (cnt > (int)&Syssize)
-{
-dprintf(DPHYS,"nope cnt %x\n", cnt);
+/*{
+dprintf(DPHYS,"nope cnt %x\n", cnt);*/
                return(0);
                return(0);
-}
+/*}*/
        cnt -= ix;
        for (pte = &Sysmap[ix]; cnt; cnt--, pte++)
                if (pte->pg_v == 0 /*|| (rw == B_WRITE && pte->pg_prot == 1)*/) 
        cnt -= ix;
        for (pte = &Sysmap[ix]; cnt; cnt--, pte++)
                if (pte->pg_v == 0 /*|| (rw == B_WRITE && pte->pg_prot == 1)*/) 
-{
-dprintf(DPHYS,"nope pte %x %x, idx %x\n", pte, *(int *)pte, ix);
+/*{
+dprintf(DPHYS,"nope pte %x %x, idx %x\n", pte, *(int *)pte, ix);*/
                        return(0);
                        return(0);
-}
-dprintf(DPHYS,"yup\n");
+/*}
+dprintf(DPHYS,"yup\n");*/
        return(1);
 }
 
        return(1);
 }
 
@@ -295,7 +310,7 @@ useracc(addr, count, rw)
        register u_int addr2;
        extern int prober(), probew();
 
        register u_int addr2;
        extern int prober(), probew();
 
-dprintf(DPHYS,"useracc %x count %d rw %d", addr, count, rw);
+/*dprintf(DPHYS,"useracc %x count %d rw %d", addr, count, rw);*/
        if (count <= 0)
                return(0);
        addr2 = addr;
        if (count <= 0)
                return(0);
        addr2 = addr;
@@ -303,13 +318,13 @@ dprintf(DPHYS,"useracc %x count %d rw %d", addr, count, rw);
        func = (rw == B_READ) ? prober : probew;
        do {
                if ((*func)(addr2) == 0)
        func = (rw == B_READ) ? prober : probew;
        do {
                if ((*func)(addr2) == 0)
-{
-dprintf(DPHYS,"nope %x\n", addr);
+/*{
+dprintf(DPHYS,"nope %x\n", addr);*/
                        return(0);
                        return(0);
-}
+/*}*/
                addr2 = (addr2 + NBPG) & ~PGOFSET;
        } while (addr2 < addr);
                addr2 = (addr2 + NBPG) & ~PGOFSET;
        } while (addr2 < addr);
-dprintf(DPHYS,"yup\n", addr);
+/*dprintf(DPHYS,"yup\n", addr);*/
        return(1);
 }
 
        return(1);
 }
 
@@ -350,7 +365,7 @@ initcr3(p)
  * Page directory table address is given by Usrptmap index of p_szpt.
  * [used by vgetpt for kernal mode entries, and ptexpand for user mode entries]
  */
  * Page directory table address is given by Usrptmap index of p_szpt.
  * [used by vgetpt for kernal mode entries, and ptexpand for user mode entries]
  */
-initpdt(p, usr)
+initpdt(p)
        register struct proc *p;
 {
        register int i, k, sz;
        register struct proc *p;
 {
        register int i, k, sz;
@@ -359,7 +374,6 @@ initpdt(p, usr)
        extern Sysbase;
 
 /*pg("initpdt");*/
        extern Sysbase;
 
 /*pg("initpdt");*/
-if(!usr) {
        /* clear entire map */
        pde = vtopde(p, 0);
        bzero(pde, NBPG);
        /* clear entire map */
        pde = vtopde(p, 0);
        bzero(pde, NBPG);
@@ -375,8 +389,6 @@ if(!usr) {
        pde->pd_pfnum = Usrptmap[btokmx(p->p_addr)].pg_pfnum;
 /*printf("%d.u. pde %x pfnum %x virt %x\n", p->p_pid, pde, pde->pd_pfnum,
 p->p_addr);*/
        pde->pd_pfnum = Usrptmap[btokmx(p->p_addr)].pg_pfnum;
 /*printf("%d.u. pde %x pfnum %x virt %x\n", p->p_pid, pde, pde->pd_pfnum,
 p->p_addr);*/
-       return;
-}
 
        /* otherwise, fill in user map */
        k = btokmx(p->p_p0br);
 
        /* otherwise, fill in user map */
        k = btokmx(p->p_p0br);
@@ -385,7 +397,7 @@ p->p_addr);*/
 
        /* text and data */
        sz = ctopt(p->p_tsize + p->p_dsize);
 
        /* text and data */
        sz = ctopt(p->p_tsize + p->p_dsize);
-dprintf(DEXPAND,"textdata 0 to %d\n",sz-1);
+/*dprintf(DEXPAND,"textdata 0 to %d\n",sz-1);*/
        for (i = 0; i < sz; i++, pde++) {
                *(int *)pde = PG_UW | PG_V;
                pde->pd_pfnum = Usrptmap[k++].pg_pfnum;
        for (i = 0; i < sz; i++, pde++) {
                *(int *)pde = PG_UW | PG_V;
                pde->pd_pfnum = Usrptmap[k++].pg_pfnum;
@@ -402,7 +414,7 @@ dprintf(DEXPAND,"textdata 0 to %d\n",sz-1);
                k += p->p_szpt - sz;
        /* hole */
        sz = NPTEPG - ctopt(p->p_ssize + UPAGES + btoc(&Sysbase));
                k += p->p_szpt - sz;
        /* hole */
        sz = NPTEPG - ctopt(p->p_ssize + UPAGES + btoc(&Sysbase));
-dprintf(DEXPAND,"zero %d upto %d\n", i, sz-1);
+/*dprintf(DEXPAND,"zero %d upto %d\n", i, sz-1);*/
        for ( ; i < sz; i++, pde++)
 /* definite bug here... does not hit all entries, but point moot due
 to bzero above XXX*/
        for ( ; i < sz; i++, pde++)
 /* definite bug here... does not hit all entries, but point moot due
 to bzero above XXX*/
@@ -412,7 +424,7 @@ to bzero above XXX*/
 }
        /* stack and u-area */
        sz = NPTEPG - ctopt(UPAGES + btoc(&Sysbase));
 }
        /* stack and u-area */
        sz = NPTEPG - ctopt(UPAGES + btoc(&Sysbase));
-dprintf(DEXPAND,"stack %d upto %d\n", i, sz-1);
+/*dprintf(DEXPAND,"stack %d upto %d\n", i, sz-1);*/
        for ( ; i < sz; i++, pde++) {
                *(int *)pde = PG_UW | PG_V;
                pde->pd_pfnum = Usrptmap[k++].pg_pfnum;
        for ( ; i < sz; i++, pde++) {
                *(int *)pde = PG_UW | PG_V;
                pde->pd_pfnum = Usrptmap[k++].pg_pfnum;
@@ -514,6 +526,7 @@ vmapbuf(bp)
                iopte++, pte++;
                a++;
        }
                iopte++, pte++;
                a++;
        }
+       load_cr3(_cr3());
 }
 
 /*
 }
 
 /*