From 52736a0a13c8e6e526a15ae80cb713785a0e54e9 Mon Sep 17 00:00:00 2001 From: marcel Date: Wed, 25 Aug 2004 07:42:34 +0000 Subject: Make profiling actually work. The gcc compiler emits a call to the _mcount() stub when profiling is enabled. Emit this code sequence for assembly routines as welli (MCOUNT definition in . We do not pass the GOT entry however as the 4th argument, because it's not used. The _mcount() stub calls __mcount(), which does the actual work. Define _MCOUNT_DECL to define __mcount. We do not have an implementation of mcount(), so we define MCOUNT as empty, but have a weak alias to _mcount() in _mcount.S. Note that the _mcount() stub in the kernel is slightly different from the stub in userland. This is because we do not have to worry about nested routines in the kernel. --- sys/ia64/ia64/support.S | 42 ++++++++++++++++ sys/ia64/include/asm.h | 15 +++--- sys/ia64/include/cpu.h | 5 ++ sys/ia64/include/profile.h | 117 +++++++++++---------------------------------- 4 files changed, 85 insertions(+), 94 deletions(-) (limited to 'sys/ia64') diff --git a/sys/ia64/ia64/support.S b/sys/ia64/ia64/support.S index da70dd4..cbec9e5 100644 --- a/sys/ia64/ia64/support.S +++ b/sys/ia64/ia64/support.S @@ -900,3 +900,45 @@ ENTRY(spillfd, 2) stf.spill [r33] = f6 br.ret.sptk rp END(spillfd) + +#if defined(GPROF) +/* + * Important registers: + * r8 structure return address + * rp our return address + * in0 caller's ar.pfs + * in1 caller's gp + * in2 caller's rp + * in3 GOT entry + * ar.pfs our pfs + */ +ENTRY_NOPROFILE(_mcount, 4) + alloc loc0 = ar.pfs, 4, 3, 2, 0 + mov loc1 = r8 + mov loc2 = rp + ;; + mov out0 = in2 + mov out1 = rp + br.call.sptk rp = __mcount + ;; +1: + mov gp = in1 + mov r14 = ip + mov b7 = loc2 + ;; + add r14 = 2f - 1b, r14 + mov ar.pfs = loc0 + mov rp = in2 + ;; + mov b7 = r14 + mov b6 = loc2 + mov r8 = loc1 + mov r14 = in0 + br.ret.sptk b7 + ;; +2: + mov ar.pfs = r14 + br.sptk b6 + ;; +END(_mcount) +#endif diff --git a/sys/ia64/include/asm.h b/sys/ia64/include/asm.h index 8be7b8a..73a29d7 100644 --- a/sys/ia64/include/asm.h +++ b/sys/ia64/include/asm.h @@ -43,12 +43,15 @@ /* * MCOUNT */ - -#if !defined(GPROF) && !defined(PROF) -#define MCOUNT /* nothing */ +#if defined(GPROF) +#define MCOUNT \ + alloc out0 = ar.pfs, 8, 0, 4, 0; \ + mov out1 = r1; \ + mov out2 = b0;; \ + mov out3 = r0; \ + br.call.sptk b0 = _mcount;; #else -#define MCOUNT \ - br.call.sptk.many b7=_mcount +#define MCOUNT /* nothing */ #endif /* @@ -61,7 +64,7 @@ .align 16; \ .proc _name_; \ _name_:; \ - .regstk _n_args_, 0, 0, 0 \ + .regstk _n_args_, 0, 0, 0; \ MCOUNT #define ENTRY_NOPROFILE(_name_, _n_args_) \ diff --git a/sys/ia64/include/cpu.h b/sys/ia64/include/cpu.h index c7a4603..da33f82 100644 --- a/sys/ia64/include/cpu.h +++ b/sys/ia64/include/cpu.h @@ -78,6 +78,11 @@ struct clockframe { #ifdef _KERNEL +#ifdef GPROF +extern char btext[]; +extern char etext[]; +#endif + /* * Return contents of in-cpu fast counter as a sort of "bogo-time" * for non-critical timing. diff --git a/sys/ia64/include/profile.h b/sys/ia64/include/profile.h index 518b974..6c06e07 100644 --- a/sys/ia64/include/profile.h +++ b/sys/ia64/include/profile.h @@ -1,99 +1,37 @@ -/* $FreeBSD$ */ -/* From: NetBSD: profile.h,v 1.9 1997/04/06 08:47:37 cgd Exp */ - /* - * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University. + * Copyright (c) 2004 Marcel Moolenaar * All rights reserved. * - * Author: Chris G. Demetriou - * - * Permission to use, copy, modify and distribute this software and - * its documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND - * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to + * 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. * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. * - * any improvements or extensions that they make and grant Carnegie the - * rights to redistribute these changes. + * $FreeBSD$ */ -#define _MCOUNT_DECL void mcount - -#define FUNCTION_ALIGNMENT 32 +#define _MCOUNT_DECL void __mcount +#define MCOUNT -typedef u_long fptrdiff_t; +#define FUNCTION_ALIGNMENT 32 -#define MCOUNT __asm (" \n\ - .globl _mcount \n\ - .proc _mcount \n\ -_mcount: \n\ - alloc loc0=ar.pfs,8,7,2,0 // space to save r8-r11,rp,b7 \n\ - add sp=-8*16,sp // space to save f8-f15 \n\ - mov loc1=rp // caller's return address \n\ - mov loc2=b7 // our return back to caller \n\ - ;; \n\ - add r17=16,sp // leave 16 bytes for mcount \n\ - add r18=32,sp \n\ - ;; \n\ - mov loc3=r8 // structure return address \n\ - mov loc4=r9 // language specific \n\ - mov loc5=r10 // language specific \n\ - mov loc6=r11 // language specific \n\ - ;; \n\ - stf.spill [r17]=f8,32 // save float arguments \n\ - stf.spill [r18]=f9,32 \n\ - mov out0=rp // frompc \n\ - ;; \n\ - stf.spill [r17]=f10,32 \n\ - stf.spill [r18]=f11,32 \n\ - mov out1=b7 // selfpc \n\ - ;; \n\ - stf.spill [r17]=f12,32 \n\ - stf.spill [r18]=f13,32 \n\ - ;; \n\ - stf.spill [r17]=f14,32 \n\ - stf.spill [r18]=f15,32 \n\ - ;; \n\ - br.call.sptk.many rp=mcount \n\ - ;; \n\ - add r17=16,sp \n\ - add r18=32,sp \n\ - ;; \n\ - ldf.fill f8=[r17],32 \n\ - ldf.fill f9=[r18],32 \n\ - mov r8=loc3 // restore structure pointer \n\ - ;; \n\ - ldf.fill f10=[r17],32 // restore float arguments \n\ - ldf.fill f11=[r18],32 \n\ - mov r9=loc4 \n\ - ;; \n\ - ldf.fill f12=[r17],32 // etc. \n\ - ldf.fill f13=[r18],32 \n\ - mov r10=loc5 \n\ - ;; \n\ - ldf.fill f14=[r17],32 \n\ - ldf.fill f15=[r18],32 \n\ - mov r11=loc6 \n\ - ;; \n\ - mov b7=loc2 // clean up \n\ - mov rp=loc1 \n\ - mov ar.pfs=loc0 \n\ - ;; \n\ - alloc r14=ar.pfs,0,0,8,0 // drop our register frame \n\ - br.sptk.many b7 // back to caller \n\ - \n\ - .end _mcount"); +typedef unsigned long fptrdiff_t; #ifdef _KERNEL /* @@ -104,6 +42,9 @@ _mcount: \n\ #define MCOUNT_EXIT(s) \n\ intr_restore(_c) #define MCOUNT_DECL(s) register_t c; + #else /* !_KERNEL */ -typedef u_long uintfptr_t; + +typedef unsigned long uintfptr_t; + #endif -- cgit v1.1