changeset 3286:42c5ca5ac4e2

* src/mcount.S: Add mcount functions for call-graph profiling. * cdl/hal_powerpc.cdl: Add option to build mcount functions.
author jld
date Sat, 22 Mar 2014 17:08:11 +0000
parents 8b3440f8b6b6
children a62acc61759e
files packages/NEWS packages/hal/powerpc/arch/current/ChangeLog packages/hal/powerpc/arch/current/cdl/hal_powerpc.cdl packages/hal/powerpc/arch/current/src/mcount.S
diffstat 4 files changed, 149 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/packages/NEWS
+++ b/packages/NEWS
@@ -1,3 +1,5 @@
+* PowerPC call-graph profiling support by John Dallaway.
+* ARM call-graph profiling support by John Dallaway.
 * Cortex-M call-graph profiling support by John Dallaway.
 * Complex number math library port from newlib by Ilija Kocho.
 * Single-precision floating point math library port from newlib by
--- a/packages/hal/powerpc/arch/current/ChangeLog
+++ b/packages/hal/powerpc/arch/current/ChangeLog
@@ -1,3 +1,9 @@
+2014-03-20  John Dallaway  <john@dallaway.org.uk>
+
+	* src/mcount.S: Add mcount functions for call-graph profiling.
+	* cdl/hal_powerpc.cdl: Add option to build mcount functions.
+	[ Bugzilla 1001961 ]
+
 2011-01-02  Sergei Gavrikov  <sergei.gavrikov@gmail.com>
 
 	* cdl/hal_powerpc.cdl: Eliminate some warnings. [ Bugzilla
@@ -1946,7 +1952,7 @@ Mon Aug 17 16:23:46 1998  Jesper Skov  <
 // ####GPLCOPYRIGHTBEGIN####                                                
 // -------------------------------------------                              
 // This file is part of eCos, the Embedded Configurable Operating System.   
-// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2006, 2007, 2008 Free Software Foundation, Inc.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2006, 2007, 2008, 2014 Free Software Foundation, Inc.
 //
 // This program is free software; you can redistribute it and/or modify     
 // it under the terms of the GNU General Public License as published by     
--- a/packages/hal/powerpc/arch/current/cdl/hal_powerpc.cdl
+++ b/packages/hal/powerpc/arch/current/cdl/hal_powerpc.cdl
@@ -8,7 +8,7 @@
 ## ####ECOSGPLCOPYRIGHTBEGIN####                                            
 ## -------------------------------------------                              
 ## This file is part of eCos, the Embedded Configurable Operating System.   
-## Copyright (C) 1998, 1999, 2000, 2001, 2002, 2007 Free Software Foundation, Inc.
+## Copyright (C) 1998, 1999, 2000, 2001, 2002, 2007, 2014 Free Software Foundation, Inc.
 ##
 ## eCos is free software; you can redistribute it and/or modify it under    
 ## the terms of the GNU General Public License as published by the Free     
@@ -41,7 +41,7 @@
 #
 # Author(s):      jskov
 # Original data:  bartv
-# Contributors:
+# Contributors:   jld
 # Date:           1999-11-02
 #
 #####DESCRIPTIONEND####
@@ -66,6 +66,8 @@ cdl_package CYGPKG_HAL_POWERPC {
         requires 1 == CYGINT_HAL_POWERPC_VARIANT
     }
 
+    implements    CYGINT_PROFILE_HAL_MCOUNT
+
     compile       hal_misc.c context.S ppc_stub.c hal_intr.c
 
     # The "-o file" is a workaround for CR100958 - without it the
@@ -253,6 +255,18 @@ cdl_package CYGPKG_HAL_POWERPC {
         }
     }
 
+    cdl_option CYGBLD_HAL_POWERPC_MCOUNT {
+        display           "Support call-graph profiling"
+        flavor            bool
+        no_define
+        active_if         CYGPKG_PROFILE_GPROF
+        calculated        CYGPKG_PROFILE_CALLGRAPH
+        compile           mcount.S
+        description       "
+            Calculate whether mcount functions should be built
+            to support call-graph profiling."
+    }
+
     cdl_option CYGBLD_LINKER_SCRIPT {
         display "Linker script"
         flavor data
new file mode 100644
--- /dev/null
+++ b/packages/hal/powerpc/arch/current/src/mcount.S
@@ -0,0 +1,124 @@
+/*==========================================================================
+//
+//      mcount.S
+//
+//      PowerPC mcount implementation
+//
+//==========================================================================
+// ####ECOSGPLCOPYRIGHTBEGIN####                                            
+// -------------------------------------------                              
+// This file is part of eCos, the Embedded Configurable Operating System.   
+// Copyright (C) 2014 Free Software Foundation, Inc.                        
+//
+// eCos is free software; you can redistribute it and/or modify it under    
+// the terms of the GNU General Public License as published by the Free     
+// Software Foundation; either version 2 or (at your option) any later      
+// version.                                                                 
+//
+// eCos is distributed in the hope that it will be useful, but WITHOUT      
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
+// for more details.                                                        
+//
+// You should have received a copy of the GNU General Public License        
+// along with eCos; if not, write to the Free Software Foundation, Inc.,    
+// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
+//
+// As a special exception, if other files instantiate templates or use      
+// macros or inline functions from this file, or you compile this file      
+// and link it with other works to produce a work based on this file,       
+// this file does not by itself cause the resulting work to be covered by   
+// the GNU General Public License. However the source code for this file    
+// must still be made available in accordance with section (3) of the GNU   
+// General Public License v2.                                               
+//
+// This exception does not invalidate any other reasons why a work based    
+// on this file might be covered by the GNU General Public License.         
+// -------------------------------------------                              
+// ####ECOSGPLCOPYRIGHTEND####                                              
+//==========================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s):       jld
+// Contributor(s):  
+// Date:            2014-03-20
+// Description:     This file provides mcount functions used for
+//                  call-graph profiling.
+//
+//####DESCRIPTIONEND####
+//
+//========================================================================
+*/
+
+#include <cyg/hal/arch.inc>
+
+/*
+// GCC inserts mcount code at the start of every function when compiling
+// with "-pg". For GCC targeting PowerPC, the following code is inserted:
+//
+//   mflr r0
+//   stw r0, 4(r1)
+//   bl _mcount
+//
+// We provide an implementation of _mcount() to call the eCos
+// __profile_mcount() function.
+*/
+
+        .section ".text.mcount"
+        .globl _mcount
+_mcount:
+        // create stack frame
+        stwu r1, -48(r1)
+
+        // caller assumes r3-r10 will be preserved and we use r14
+        stw r3, 8(r1)
+        stw r4, 12(r1)
+        stw r5, 16(r1)
+        stw r6, 20(r1)
+        stw r7, 24(r1)
+        stw r8, 28(r1)
+        stw r9, 32(r1)
+        stw r10, 36(r1)
+        stw r14, 40(r1)
+
+        // set up parameters for __profile_mcount() and preserve
+        // lr across our __profile_mcount() call
+        lwz r3, 52(r1)
+        subi r3, r3, 2
+        mflr r4
+        stw r4, 44(r1)
+
+        // disable interrupts
+        lwi r0, ~CYGARC_REG_MSR_INTBITS
+        mfmsr r14
+        and r0, r0, r14
+        mtmsr r0
+
+        // call eCos __profile_mcount()
+        // r14 is preserved across the call per EABI standard
+        bl __profile_mcount
+
+        // restore interrupts
+        mtmsr r14
+
+        // restore registers
+        lwz r3, 8(r1)
+        lwz r4, 12(r1)
+        lwz r5, 16(r1)
+        lwz r6, 20(r1)
+        lwz r7, 24(r1)
+        lwz r8, 28(r1)
+        lwz r9, 32(r1)
+        lwz r10, 36(r1)
+        lwz r14, 40(r1)
+
+        // unwind stack frame and return
+        lwz r0, 44(r1)
+        mtctr r0
+        lwz r0, 52(r1)
+        mtlr r0
+        addi r1, r1, 48
+        bctr
+
+//==========================================================================
+// end of mcount.S