Mercurial > nand-ecoscentric
changeset 3362:8b3440f8b6b6
* src/mcount.S: Add mcount functions for call-graph profiling.
* cdl/hal_arm.cdl: Add option to build mcount functions.
[ Bugzilla 1001959 ]
| author | jld |
|---|---|
| date | Sun, 16 Mar 2014 19:39:11 +0000 |
| parents | 4839eca9f0c7 |
| children | 42c5ca5ac4e2 |
| files | packages/hal/arm/arch/current/ChangeLog packages/hal/arm/arch/current/cdl/hal_arm.cdl packages/hal/arm/arch/current/src/mcount.S |
| diffstat | 3 files changed, 164 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/packages/hal/arm/arch/current/ChangeLog +++ b/packages/hal/arm/arch/current/ChangeLog @@ -1,3 +1,9 @@ +2014-03-14 John Dallaway <john@dallaway.org.uk> + + * src/mcount.S: Add mcount functions for call-graph profiling. + * cdl/hal_arm.cdl: Add option to build mcount functions. + [ Bugzilla 1001959 ] + 2011-11-23 Nick Garnett <nickg@ecoscentric.com> * cdl/hal_arm.cdl: Add CDL to control whether both IRQs and FIQs @@ -1823,7 +1829,7 @@ 1998-10-16 Bart Veer <bartv@cygnus.co. // ####GPLCOPYRIGHTBEGIN#### // ------------------------------------------- // This file is part of eCos, the Embedded Configurable Operating System. -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2009 Free Software Foundation, Inc. +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2009, 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/arm/arch/current/cdl/hal_arm.cdl +++ b/packages/hal/arm/arch/current/cdl/hal_arm.cdl @@ -8,7 +8,7 @@ ## ####ECOSGPLCOPYRIGHTBEGIN#### ## ------------------------------------------- ## This file is part of eCos, the Embedded Configurable Operating System. -## Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. +## Copyright (C) 1998, 1999, 2000, 2001, 2002, 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): bartv # Original data: gthomas -# Contributors: +# Contributors: jld # Date: 1999-06-13 # #####DESCRIPTIONEND#### @@ -59,6 +59,8 @@ cdl_package CYGPKG_HAL_ARM { necessary to select a specific target platform HAL package." + implements CYGINT_PROFILE_HAL_MCOUNT + compile hal_misc.c context.S arm_stub.c hal_syscall.c # The "-o file" is a workaround for CR100958 - without it the @@ -382,6 +384,19 @@ cdl_package CYGPKG_HAL_ARM { } + cdl_option CYGBLD_HAL_ARM_MCOUNT { + display "Support call-graph profiling" + flavor bool + no_define + active_if CYGPKG_PROFILE_GPROF + calculated CYGPKG_PROFILE_CALLGRAPH + requires { CYGHWR_THUMB implies CYGBLD_ARM_ENABLE_THUMB_INTERWORK } + 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/arm/arch/current/src/mcount.S @@ -0,0 +1,140 @@ +/*========================================================================== +// +// mcount.S +// +// ARM 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-14 +// Description: This file provides mcount functions used for +// call-graph profiling. +// +//####DESCRIPTIONEND#### +// +//======================================================================== +*/ + +#include "arm.inc" + +/* +// GCC inserts mcount code at the start of every function when compiling +// with "-pg". For GCC prior to version 4.4 targeting ARM, the following +// code is inserted: +// +// mov r12, lr +// bl mcount +// .word <data pointer> +// +// For GCC version 4.4 and later targeting ARM, the following code is +// inserted: +// +// push { lr } +// bl __gnu_mcount_nc +// +// We provide implementations of both mcount() and __gnu_mcount_nc() to +// call the eCos __profile_mcount() function. +*/ + + .syntax unified + .arm + .globl mcount + .section .text.mcount + .type mcount, %function +mcount: + // resume execution beyond the data pointer on return to caller + add lr, lr, #4 + + // caller assumes r0-r3 will be preserved (non-AAPCS), we use + // r6 and must preserve lr across our __profile_mcount() call + push { r0, r1, r2, r3, r6, lr } + + // set up parameters for __profile_mcount() + sub r0, r12, #2 + bic r0, r0, #1 + bic r1, lr, #1 + + // disable interrupts + mrs r6, cpsr + orr r2, r6, #CPSR_INTR_MASK + msr cpsr, r2 + + // call eCos __profile_mcount() + // r6 is preserved across the call per AAPCS + bl __profile_mcount + + // restore interrupts + msr cpsr, r6 + + // restore registers and return + pop { r0, r1, r2, r3, r6, r12 } + bx r12 + + + .globl __gnu_mcount_nc + .section .text.__gnu_mcount_nc + .type __gnu_mcount_nc, %function +__gnu_mcount_nc: + // caller assumes r0-r3 will be preserved (non-AAPCS), we use + // r6 and must preserve lr across our __profile_mcount() call + push { r0, r1, r2, r3, r6, lr } + + // set up parameters for __profile_mcount() + ldr r0, [ sp, #24 ] + sub r0, r0, #2 + bic r0, r0, #1 + bic r1, lr, #1 + + // disable interrupts + mrs r6, cpsr + orr r2, r6, #CPSR_INTR_MASK + msr cpsr, r2 + + // call eCos __profile_mcount() + // r6 is preserved across the call per AAPCS + bl __profile_mcount + + // restore interrupts + msr cpsr, r6 + + // restore registers and return + pop { r0, r1, r2, r3, r6, r12, lr } + bx r12 + +//========================================================================== +// end of mcount.S
