Profiling cleanup 1/2: fix crashes (all registers need to be left intact
authorMatthew Dillon <dillon@dragonflybsd.org>
Sun, 20 Jul 2003 04:20:32 +0000 (04:20 +0000)
committerMatthew Dillon <dillon@dragonflybsd.org>
Sun, 20 Jul 2003 04:20:32 +0000 (04:20 +0000)
from assembly), and fix a few syntax issues, etc.   It isn't ticking away
properly yet but at least it isn't crashing.

Submitted-by: Kip Macy <kmacy@fsmware.com>
Additional-work: dillon

sys/cpu/i386/include/asmacros.h
sys/cpu/i386/include/profile.h
sys/i386/i386/swtch.s
sys/i386/include/asmacros.h
sys/i386/include/profile.h
sys/i386/isa/prof_machdep.c
sys/platform/pc32/i386/swtch.s
sys/platform/pc32/isa/prof_machdep.c

index 8008a0e..6f4dbc2 100644 (file)
@@ -31,7 +31,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/i386/include/asmacros.h,v 1.18 1999/08/28 00:44:06 peter Exp $
- * $DragonFly: src/sys/cpu/i386/include/asmacros.h,v 1.4 2003/07/01 20:31:34 dillon Exp $
+ * $DragonFly: src/sys/cpu/i386/include/asmacros.h,v 1.5 2003/07/20 04:20:32 dillon Exp $
  */
 
 #ifndef _MACHINE_ASMACROS_H_
@@ -86,8 +86,8 @@
  * but gcc currently generates calls to it at the start of the epilogue to
  * avoid problems with -fpic.
  *
- * [.]mcount and __mcount may clobber the call-used registers and %ef.
- * [.]mexitcount may clobber %ecx and %ef.
+ * [.]mcount and __mcount will not clobber the call-used registers or %ef.
+ * [.]mexitcount will not clobber the call-used registers or %ef.
  *
  * Cross-jumping makes non-statistical profiling timing more complicated.
  * It is handled in many cases by calling [.]mexitcount before jumping.  It
 #define CROSSJUMPTARGET(label) \
        ALIGN_TEXT; __CONCAT(to,label): ; MCOUNT; jmp label
 #define ENTRY(name)            GEN_ENTRY(name) ; 9: ; MCOUNT
-#define FAKE_MCOUNT(caller)    pushl caller ; call _mcount ; popl %ecx
-#define MCOUNT                 call _mcount
+#define FAKE_MCOUNT(caller)    pushl caller ; call __mcount ; addl $4,%esp
+#define MCOUNT                 call __mcount
 #define MCOUNT_LABEL(name)     GEN_ENTRY(name) ; nop ; ALIGN_TEXT
 #define MEXITCOUNT             call HIDENAME(mexitcount)
 #define ret                    MEXITCOUNT ; NON_GPROF_RET
index 22a68c1..ed0c3c6 100644 (file)
@@ -32,7 +32,7 @@
  *
  *     @(#)profile.h   8.1 (Berkeley) 6/11/93
  * $FreeBSD: src/sys/i386/include/profile.h,v 1.20 1999/12/29 04:33:05 peter Exp $
- * $DragonFly: src/sys/cpu/i386/include/profile.h,v 1.2 2003/06/17 04:28:36 dillon Exp $
+ * $DragonFly: src/sys/cpu/i386/include/profile.h,v 1.3 2003/07/20 04:20:32 dillon Exp $
  */
 
 #ifndef _MACHINE_PROFILE_H_
@@ -70,7 +70,7 @@
                          s_lock_np(&mcount_lock); }
 #define        MCOUNT_EXIT(s)  { s_unlock_np(&mcount_lock); write_eflags(s); }
 #else
-#define        MCOUNT_ENTER(s) { s = read_eflags(); disable_intr(); }
+#define        MCOUNT_ENTER(s) { s = read_eflags(); cpu_disable_intr(); }
 #define        MCOUNT_EXIT(s)  (write_eflags(s))
 #endif
 #endif /* GUPROF */
index 53d2152..fcd1c1a 100644 (file)
@@ -35,7 +35,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/i386/i386/swtch.s,v 1.89.2.10 2003/01/23 03:36:24 ps Exp $
- * $DragonFly: src/sys/i386/i386/Attic/swtch.s,v 1.24 2003/07/11 17:42:08 dillon Exp $
+ * $DragonFly: src/sys/i386/i386/Attic/swtch.s,v 1.25 2003/07/20 04:20:29 dillon Exp $
  */
 
 #include "npx.h"
@@ -380,8 +380,6 @@ cpu_switch_load_gs:
 
        ret
 
-CROSSJUMPTARGET(sw1a)
-
 badsw2:
        pushl   $sw0_2
        call    panic
index 1591f4e..d3c50d8 100644 (file)
@@ -31,7 +31,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/i386/include/asmacros.h,v 1.18 1999/08/28 00:44:06 peter Exp $
- * $DragonFly: src/sys/i386/include/Attic/asmacros.h,v 1.4 2003/07/01 20:31:34 dillon Exp $
+ * $DragonFly: src/sys/i386/include/Attic/asmacros.h,v 1.5 2003/07/20 04:20:32 dillon Exp $
  */
 
 #ifndef _MACHINE_ASMACROS_H_
@@ -86,8 +86,8 @@
  * but gcc currently generates calls to it at the start of the epilogue to
  * avoid problems with -fpic.
  *
- * [.]mcount and __mcount may clobber the call-used registers and %ef.
- * [.]mexitcount may clobber %ecx and %ef.
+ * [.]mcount and __mcount will not clobber the call-used registers or %ef.
+ * [.]mexitcount will not clobber the call-used registers or %ef.
  *
  * Cross-jumping makes non-statistical profiling timing more complicated.
  * It is handled in many cases by calling [.]mexitcount before jumping.  It
 #define CROSSJUMPTARGET(label) \
        ALIGN_TEXT; __CONCAT(to,label): ; MCOUNT; jmp label
 #define ENTRY(name)            GEN_ENTRY(name) ; 9: ; MCOUNT
-#define FAKE_MCOUNT(caller)    pushl caller ; call _mcount ; popl %ecx
-#define MCOUNT                 call _mcount
+#define FAKE_MCOUNT(caller)    pushl caller ; call __mcount ; addl $4,%esp
+#define MCOUNT                 call __mcount
 #define MCOUNT_LABEL(name)     GEN_ENTRY(name) ; nop ; ALIGN_TEXT
 #define MEXITCOUNT             call HIDENAME(mexitcount)
 #define ret                    MEXITCOUNT ; NON_GPROF_RET
index 9844e33..3b6423f 100644 (file)
@@ -32,7 +32,7 @@
  *
  *     @(#)profile.h   8.1 (Berkeley) 6/11/93
  * $FreeBSD: src/sys/i386/include/profile.h,v 1.20 1999/12/29 04:33:05 peter Exp $
- * $DragonFly: src/sys/i386/include/Attic/profile.h,v 1.2 2003/06/17 04:28:36 dillon Exp $
+ * $DragonFly: src/sys/i386/include/Attic/profile.h,v 1.3 2003/07/20 04:20:32 dillon Exp $
  */
 
 #ifndef _MACHINE_PROFILE_H_
@@ -70,7 +70,7 @@
                          s_lock_np(&mcount_lock); }
 #define        MCOUNT_EXIT(s)  { s_unlock_np(&mcount_lock); write_eflags(s); }
 #else
-#define        MCOUNT_ENTER(s) { s = read_eflags(); disable_intr(); }
+#define        MCOUNT_ENTER(s) { s = read_eflags(); cpu_disable_intr(); }
 #define        MCOUNT_EXIT(s)  (write_eflags(s))
 #endif
 #endif /* GUPROF */
index 0aeed22..ac2bfc7 100644 (file)
@@ -24,7 +24,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/i386/isa/prof_machdep.c,v 1.14.2.1 2000/08/03 00:09:30 ps Exp $
- * $DragonFly: src/sys/i386/isa/Attic/prof_machdep.c,v 1.2 2003/06/17 04:28:37 dillon Exp $
+ * $DragonFly: src/sys/i386/isa/Attic/prof_machdep.c,v 1.3 2003/07/20 04:20:32 dillon Exp $
  */
 
 #ifdef GUPROF
@@ -89,7 +89,10 @@ __mcount:                                                    \n\
        # hasn't changed the stack except to call here, so the  \n\
        # caller's raddr is above our raddr.                    \n\
        #                                                       \n\
-       movl    4(%esp),%edx                                    \n\
+       pushl   %eax                                            \n\
+       pushl   %ecx                                            \n\
+       pushl   %edx                                            \n\
+       movl    12+4(%esp),%edx                                 \n\
        jmp     .got_frompc                                     \n\
                                                                \n\
        .p2align 4,0x90                                         \n\
@@ -103,6 +106,9 @@ __mcount:                                                   \n\
        # raddr is in the caller's frame following the caller's \n\
        # caller's frame pointer.                               \n\
        #                                                       \n\
+       pushl   %eax                                            \n\
+       pushl   %ecx                                            \n\
+       pushl   %edx                                            \n\
        movl    4(%ebp),%edx                                    \n\
 .got_frompc:                                                   \n\
        #                                                       \n\
@@ -117,6 +123,9 @@ __mcount:                                                   \n\
        call    " __XSTRING(CNAME(mcount)) "                    \n\
        addl    $8,%esp                                         \n\
        popfl                                                   \n\
+       popl    %edx                                            \n\
+       popl    %ecx                                            \n\
+       popl    %eax                                            \n\
 .mcount_exit:                                                  \n\
        ret                                                     \n\
 ");
@@ -151,8 +160,9 @@ GMON_PROF_HIRES     =       4                                       \n\
        cmpl    $GMON_PROF_HIRES," __XSTRING(CNAME(_gmonparam)) "+GM_STATE \n\
        jne     .mexitcount_exit                                \n\
        pushl   %edx                                            \n\
+       pushl   %ecx                                            \n\
        pushl   %eax                                            \n\
-       movl    8(%esp),%eax                                    \n\
+       movl    12(%esp),%eax                                   \n\
        pushfl                                                  \n\
        pushl   %eax                                            \n\
        cli                                                     \n\
@@ -160,6 +170,7 @@ GMON_PROF_HIRES     =       4                                       \n\
        addl    $4,%esp                                         \n\
        popfl                                                   \n\
        popl    %eax                                            \n\
+       popl    %ecx                                            \n\
        popl    %edx                                            \n\
 .mexitcount_exit:                                              \n\
        ret                                                     \n\
index 193c357..6cee6ec 100644 (file)
@@ -35,7 +35,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/i386/i386/swtch.s,v 1.89.2.10 2003/01/23 03:36:24 ps Exp $
- * $DragonFly: src/sys/platform/pc32/i386/swtch.s,v 1.24 2003/07/11 17:42:08 dillon Exp $
+ * $DragonFly: src/sys/platform/pc32/i386/swtch.s,v 1.25 2003/07/20 04:20:29 dillon Exp $
  */
 
 #include "npx.h"
@@ -380,8 +380,6 @@ cpu_switch_load_gs:
 
        ret
 
-CROSSJUMPTARGET(sw1a)
-
 badsw2:
        pushl   $sw0_2
        call    panic
index 3a25017..acbd1b0 100644 (file)
@@ -24,7 +24,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/i386/isa/prof_machdep.c,v 1.14.2.1 2000/08/03 00:09:30 ps Exp $
- * $DragonFly: src/sys/platform/pc32/isa/prof_machdep.c,v 1.2 2003/06/17 04:28:37 dillon Exp $
+ * $DragonFly: src/sys/platform/pc32/isa/prof_machdep.c,v 1.3 2003/07/20 04:20:32 dillon Exp $
  */
 
 #ifdef GUPROF
@@ -89,7 +89,10 @@ __mcount:                                                    \n\
        # hasn't changed the stack except to call here, so the  \n\
        # caller's raddr is above our raddr.                    \n\
        #                                                       \n\
-       movl    4(%esp),%edx                                    \n\
+       pushl   %eax                                            \n\
+       pushl   %ecx                                            \n\
+       pushl   %edx                                            \n\
+       movl    12+4(%esp),%edx                                 \n\
        jmp     .got_frompc                                     \n\
                                                                \n\
        .p2align 4,0x90                                         \n\
@@ -103,6 +106,9 @@ __mcount:                                                   \n\
        # raddr is in the caller's frame following the caller's \n\
        # caller's frame pointer.                               \n\
        #                                                       \n\
+       pushl   %eax                                            \n\
+       pushl   %ecx                                            \n\
+       pushl   %edx                                            \n\
        movl    4(%ebp),%edx                                    \n\
 .got_frompc:                                                   \n\
        #                                                       \n\
@@ -117,6 +123,9 @@ __mcount:                                                   \n\
        call    " __XSTRING(CNAME(mcount)) "                    \n\
        addl    $8,%esp                                         \n\
        popfl                                                   \n\
+       popl    %edx                                            \n\
+       popl    %ecx                                            \n\
+       popl    %eax                                            \n\
 .mcount_exit:                                                  \n\
        ret                                                     \n\
 ");
@@ -151,8 +160,9 @@ GMON_PROF_HIRES     =       4                                       \n\
        cmpl    $GMON_PROF_HIRES," __XSTRING(CNAME(_gmonparam)) "+GM_STATE \n\
        jne     .mexitcount_exit                                \n\
        pushl   %edx                                            \n\
+       pushl   %ecx                                            \n\
        pushl   %eax                                            \n\
-       movl    8(%esp),%eax                                    \n\
+       movl    12(%esp),%eax                                   \n\
        pushfl                                                  \n\
        pushl   %eax                                            \n\
        cli                                                     \n\
@@ -160,6 +170,7 @@ GMON_PROF_HIRES     =       4                                       \n\
        addl    $4,%esp                                         \n\
        popfl                                                   \n\
        popl    %eax                                            \n\
+       popl    %ecx                                            \n\
        popl    %edx                                            \n\
 .mexitcount_exit:                                              \n\
        ret                                                     \n\