vfs initialization code moved to vfs_init.c
[unix-history] / usr / src / sys / kern / subr_prof.c
index 734910b..c86c451 100644 (file)
@@ -1,15 +1,17 @@
 /*
  * Copyright (c) 1982, 1986 Regents of the University of California.
 /*
  * 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.
+ * All rights reserved.
  *
  *
- *     @(#)subr_prof.c 7.3 (Berkeley) %G%
+ * %sccs.include.redist.c%
+ *
+ *     @(#)subr_prof.c 7.12 (Berkeley) %G%
  */
 
 #ifdef GPROF
 #include "gprof.h"
 #include "param.h"
 #include "systm.h"
  */
 
 #ifdef GPROF
 #include "gprof.h"
 #include "param.h"
 #include "systm.h"
+#include "kernel.h"
 #include "malloc.h"
 
 /*
 #include "malloc.h"
 
 /*
@@ -19,12 +21,7 @@ int  profiling = 3;
 u_short        *froms;
 struct tostruct *tos = 0;
 long   tolimit = 0;
 u_short        *froms;
 struct tostruct *tos = 0;
 long   tolimit = 0;
-#if defined(vax)
-char   *s_lowpc = (char *)0x80000000;
-#endif
-#if defined(tahoe)
-char   *s_lowpc = (char *)0xc0000000;
-#endif
+char   *s_lowpc = (char *)KERNBASE;
 extern char etext;
 char   *s_highpc = &etext;
 u_long s_textsize = 0;
 extern char etext;
 char   *s_highpc = &etext;
 u_long s_textsize = 0;
@@ -53,14 +50,16 @@ kmstartup()
                printf("No space for monitor buffer(s)\n");
                return;
        }
                printf("No space for monitor buffer(s)\n");
                return;
        }
+       bzero(sbuf, ssiz);
        fromssize = s_textsize / HASHFRACTION;
        fromssize = s_textsize / HASHFRACTION;
-       froms = (u_short *)malloc(fromssize, M_GPROF, M_WAITOK);
+       froms = (u_short *)malloc(fromssize, M_GPROF, M_NOWAIT);
        if (froms == 0) {
                printf("No space for monitor buffer(s)\n");
                free(sbuf, M_GPROF);
                sbuf = 0;
                return;
        }
        if (froms == 0) {
                printf("No space for monitor buffer(s)\n");
                free(sbuf, M_GPROF);
                sbuf = 0;
                return;
        }
+       bzero(froms, fromssize);
        tolimit = s_textsize * ARCDENSITY / 100;
        if (tolimit < MINARCS)
                tolimit = MINARCS;
        tolimit = s_textsize * ARCDENSITY / 100;
        if (tolimit < MINARCS)
                tolimit = MINARCS;
@@ -74,26 +73,24 @@ kmstartup()
                free(froms, M_GPROF), froms = 0;
                return;
        }
                free(froms, M_GPROF), froms = 0;
                return;
        }
+       bzero(tos, tossize);
        tos[0].link = 0;
        ((struct phdr *)sbuf)->lpc = s_lowpc;
        ((struct phdr *)sbuf)->hpc = s_highpc;
        ((struct phdr *)sbuf)->ncnt = ssiz;
        tos[0].link = 0;
        ((struct phdr *)sbuf)->lpc = s_lowpc;
        ((struct phdr *)sbuf)->hpc = s_highpc;
        ((struct phdr *)sbuf)->ncnt = ssiz;
-       kcount = (u_short *)(((int)sbuf) + sizeof (struct phdr));
-#ifdef notdef
-       /*
-        * Profiling is what mcount checks to see if
-        * all the data structures are ready!!!
-        */
-       profiling = 0;          /* patch by hand when you're ready */
+       ((struct phdr *)sbuf)->version = GMONVERSION;
+#ifdef PROFTIMER
+       initprofclock();
+       ((struct phdr *)sbuf)->profrate = profhz;
+#else
+       ((struct phdr *)sbuf)->profrate = hz;
 #endif
 #endif
+       kcount = (u_short *)(((int)sbuf) + sizeof (struct phdr));
 }
 
 /*
  * This routine is massaged so that it may be jsb'ed to on vax.
  */
 }
 
 /*
  * This routine is massaged so that it may be jsb'ed to on vax.
  */
-asm(".text");
-asm("#the beginning of mcount()");
-asm(".data");
 mcount()
 {
        register char *selfpc;                  /* r11 => r5 */
 mcount()
 {
        register char *selfpc;                  /* r11 => r5 */
@@ -103,7 +100,6 @@ mcount()
        register long toindex;                  /* r7  => r1 */
        static int s;
 
        register long toindex;                  /* r7  => r1 */
        static int s;
 
-       asm("   .text");                /* make sure we're in text space */
        /*
         * Check that we are profiling.
         */
        /*
         * Check that we are profiling.
         */
@@ -116,24 +112,53 @@ mcount()
 #ifdef lint
        selfpc = (char *)0;
        frompcindex = 0;
 #ifdef lint
        selfpc = (char *)0;
        frompcindex = 0;
+#else
+       ;                               /* avoid label botch */
+#ifdef __GNUC__
+#if defined(vax)
+       Fix Me!!
+#endif
+#if defined(tahoe)
+       Fix Me!!
+#endif
+#if defined(hp300)
+       /*
+        * selfpc = pc pushed by mcount jsr,
+        * frompcindex = pc pushed by jsr into self.
+        * In GCC the caller's stack frame has already been built so we
+        * have to chase a6 to find caller's raddr.  This assumes that all
+        * routines we are profiling were built with GCC and that all
+        * profiled routines use link/unlk.
+        */
+       asm("movl a6@(4),%0" : "=r" (selfpc));
+       asm("movl a6@(0)@(4),%0" : "=r" (frompcindex));
+#endif
 #else
 #if defined(vax)
        asm("   movl (sp), r11");       /* selfpc = ... (jsb frame) */
        asm("   movl 16(fp), r10");     /* frompcindex =     (calls frame) */
 #endif
 #if defined(tahoe)
 #else
 #if defined(vax)
        asm("   movl (sp), r11");       /* selfpc = ... (jsb frame) */
        asm("   movl 16(fp), r10");     /* frompcindex =     (calls frame) */
 #endif
 #if defined(tahoe)
-       ;                               /* avoid label botch */
        asm("   movl -8(fp),r12");      /* selfpc = callf frame */
        asm("   movl (fp),r11");
        asm("   movl -8(r11),r11");     /* frompcindex = 1 callf frame back */
 #endif
        asm("   movl -8(fp),r12");      /* selfpc = callf frame */
        asm("   movl (fp),r11");
        asm("   movl -8(r11),r11");     /* frompcindex = 1 callf frame back */
 #endif
+#if defined(hp300)
+       Fix Me!!
 #endif
 #endif
+#endif /* not __GNUC__ */
+#endif /* not lint */
        /*
         * Insure that we cannot be recursively invoked.
         * this requires that splhigh() and splx() below
         * do NOT call mcount!
         */
        /*
         * Insure that we cannot be recursively invoked.
         * this requires that splhigh() and splx() below
         * do NOT call mcount!
         */
+#if defined(hp300)
+       asm("movw       sr,%0" : "=g" (s));
+       asm("movw       #0x2700,sr");
+#else
        s = splhigh();
        s = splhigh();
+#endif
        /*
         * Check that frompcindex is a reasonable pc value.
         * For example: signal catchers get called from the stack,
        /*
         * Check that frompcindex is a reasonable pc value.
         * For example: signal catchers get called from the stack,
@@ -211,7 +236,11 @@ mcount()
 
        }
 done:
 
        }
 done:
+#if defined(hp300)
+       asm("movw       %0,sr" : : "g" (s));
+#else
        splx(s);
        splx(s);
+#endif
        /* and fall through */
 out:
 #if defined(vax)
        /* and fall through */
 out:
 #if defined(vax)