BSD 4_3_Net_2 release
[unix-history] / usr / src / lib / csu.vax / gmon.c
index f7b1a59..fc47ec9 100644 (file)
@@ -1,19 +1,52 @@
-/*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+/*-
+ * Copyright (c) 1983 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * 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.
  */
 
  */
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)gmon.c     5.4 (Berkeley) 8/27/87";
-#endif LIBC_SCCS and not lint
+#ifndef lint
+static char sccsid[] = "@(#)gmon.c     5.8 (Berkeley) 5/27/91";
+#endif /* not lint */
+
+#include <unistd.h>
 
 #ifdef DEBUG
 #include <stdio.h>
 
 #ifdef DEBUG
 #include <stdio.h>
-#endif DEBUG
+#endif
 
 #include "gmon.h"
 
 
 #include "gmon.h"
 
+extern mcount() asm ("mcount");
+extern mcount2() asm ("mcount2");
+extern char *minbrk asm ("minbrk");
+
     /*
      * froms is actually a bunch of unsigned shorts indexing tos
      */
     /*
      * froms is actually a bunch of unsigned shorts indexing tos
      */
@@ -31,7 +64,7 @@ static int    s_scale;
     /* see profil(2) where this is describe (incorrectly) */
 #define                SCALE_1_TO_1    0x10000L
 
     /* see profil(2) where this is describe (incorrectly) */
 #define                SCALE_1_TO_1    0x10000L
 
-#define        MSG "No space for monitor buffer(s)\n"
+#define        MSG "No space for profiling buffer(s)\n"
 
 monstartup(lowpc, highpc)
     char       *lowpc;
 
 monstartup(lowpc, highpc)
     char       *lowpc;
@@ -39,8 +72,7 @@ monstartup(lowpc, highpc)
 {
     int                        monsize;
     char               *buffer;
 {
     int                        monsize;
     char               *buffer;
-    char               *sbrk();
-    extern char                *minbrk;
+    register int       o;
 
        /*
         *      round lowpc and highpc to multiples of the density we're using
 
        /*
         *      round lowpc and highpc to multiples of the density we're using
@@ -80,7 +112,20 @@ monstartup(lowpc, highpc)
     }
     minbrk = sbrk(0);
     tos[0].link = 0;
     }
     minbrk = sbrk(0);
     tos[0].link = 0;
-    monitor( lowpc , highpc , buffer , monsize , tolimit );
+    sbuf = buffer;
+    ssiz = monsize;
+    ( (struct phdr *) buffer ) -> lpc = lowpc;
+    ( (struct phdr *) buffer ) -> hpc = highpc;
+    ( (struct phdr *) buffer ) -> ncnt = ssiz;
+    monsize -= sizeof(struct phdr);
+    if ( monsize <= 0 )
+       return;
+    o = highpc - lowpc;
+    if( monsize < o )
+       s_scale = ( (float) monsize / o ) * SCALE_1_TO_1;
+    else
+       s_scale = SCALE_1_TO_1;
+    moncontrol(1);
 }
 
 _mcleanup()
 }
 
 _mcleanup()
@@ -92,6 +137,7 @@ _mcleanup()
     int                        toindex;
     struct rawarc      rawarc;
 
     int                        toindex;
     struct rawarc      rawarc;
 
+    moncontrol(0);
     fd = creat( "gmon.out" , 0666 );
     if ( fd < 0 ) {
        perror( "mcount: gmon.out" );
     fd = creat( "gmon.out" , 0666 );
     if ( fd < 0 ) {
        perror( "mcount: gmon.out" );
@@ -122,32 +168,22 @@ _mcleanup()
     close( fd );
 }
 
     close( fd );
 }
 
-asm(".text");
-asm(".align 2");
-asm("#the beginning of mcount()");
-asm(".data");
-mcount()
+asm(".text; .globl mcount; mcount: pushl 16(fp); calls $1,mcount2; rsb");
+
+mcount2(frompcindex, selfpc)
+       register unsigned short         *frompcindex;
+       register char                   *selfpc;
 {
 {
-       register char                   *selfpc;        /* r11 => r5 */
-       register unsigned short         *frompcindex;   /* r10 => r4 */
-       register struct tostruct        *top;           /* r9  => r3 */
-       register struct tostruct        *prevtop;       /* r8  => r2 */
-       register long                   toindex;        /* r7  => r1 */
+       register struct tostruct        *top;
+       register struct tostruct        *prevtop;
+       register long                   toindex;
 
 
-       /*
-        *      find the return address for mcount,
-        *      and the return address for mcount's caller.
-        */
-       asm("   .text");                /* make sure we're in text space */
-       asm("   movl (sp), r11");       /* selfpc = ... (jsb frame) */
-       asm("   movl 16(fp), r10");     /* frompcindex =     (calls frame) */
        /*
         *      check that we are profiling
         *      and that we aren't recursively invoked.
         */
        /*
         *      check that we are profiling
         *      and that we aren't recursively invoked.
         */
-       if (profiling) {
-               goto out;
-       }
+       if (profiling)
+               return;
        profiling++;
        /*
         *      check that frompcindex is a reasonable pc value.
        profiling++;
        /*
         *      check that frompcindex is a reasonable pc value.
@@ -231,49 +267,13 @@ mcount()
        }
 done:
        profiling--;
        }
 done:
        profiling--;
-       /* and fall through */
-out:
-       asm("   rsb");
+       return;
 
 overflow:
        profiling++; /* halt further profiling */
 #   define     TOLIMIT "mcount: tos overflow\n"
        write(2, TOLIMIT, sizeof(TOLIMIT) - 1);
 
 overflow:
        profiling++; /* halt further profiling */
 #   define     TOLIMIT "mcount: tos overflow\n"
        write(2, TOLIMIT, sizeof(TOLIMIT) - 1);
-       goto out;
-}
-asm(".text");
-asm("#the end of mcount()");
-asm(".data");
-
-/*VARARGS1*/
-monitor( lowpc , highpc , buf , bufsiz , nfunc )
-    char       *lowpc;
-    char       *highpc;
-    char       *buf;   /* declared ``short buffer[]'' in monitor(3) */
-    int                bufsiz;
-    int                nfunc;  /* not used, available for compatability only */
-{
-    register o;
-
-    if ( lowpc == 0 ) {
-       moncontrol(0);
-       _mcleanup();
        return;
        return;
-    }
-    sbuf = buf;
-    ssiz = bufsiz;
-    ( (struct phdr *) buf ) -> lpc = lowpc;
-    ( (struct phdr *) buf ) -> hpc = highpc;
-    ( (struct phdr *) buf ) -> ncnt = ssiz;
-    bufsiz -= sizeof(struct phdr);
-    if ( bufsiz <= 0 )
-       return;
-    o = highpc - lowpc;
-    if( bufsiz < o )
-       s_scale = ( (float) bufsiz / o ) * SCALE_1_TO_1;
-    else
-       s_scale = SCALE_1_TO_1;
-    moncontrol(1);
 }
 
 /*
 }
 
 /*
@@ -287,7 +287,7 @@ moncontrol(mode)
     if (mode) {
        /* start */
        profil(sbuf + sizeof(struct phdr), ssiz - sizeof(struct phdr),
     if (mode) {
        /* start */
        profil(sbuf + sizeof(struct phdr), ssiz - sizeof(struct phdr),
-               s_lowpc, s_scale);
+               (int)s_lowpc, s_scale);
        profiling = 0;
     } else {
        /* stop */
        profiling = 0;
     } else {
        /* stop */