Back to index

glibc  2.9
machine-gmon.h
Go to the documentation of this file.
00001 /* Machine-dependent definitions for profiling support.  ARM EABI version.
00002    Copyright (C) 2008 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 /* GCC for the ARM cannot compile __builtin_return_address(N) for N != 0, 
00021    so we must use an assembly stub.  */
00022 
00023 #include <sysdep.h>
00024 static void mcount_internal (u_long frompc, u_long selfpc) __attribute_used__;
00025 
00026 #define _MCOUNT_DECL(frompc, selfpc) \
00027 static void mcount_internal (u_long frompc, u_long selfpc)
00028 
00029 /* Use an assembly stub with a special ABI.  The calling lr has been
00030    pushed to the stack (which will be misaligned).  We should preserve
00031    all registers except ip and pop a word off the stack.
00032 
00033    NOTE: This assumes mcount_internal does not clobber any non-core
00034    (coprocessor) registers.  Currently this is true, but may require
00035    additional attention in the future.
00036 
00037    The calling sequence looks something like:
00038 func:
00039    push {lr}
00040    bl __gnu_mount_nc
00041    <function body>
00042  */
00043 
00044 
00045 #define MCOUNT                                                        \
00046 void __attribute__((__naked__)) __gnu_mcount_nc(void)                 \
00047 {                                                              \
00048     asm ("push {r0, r1, r2, r3, lr}\n\t"                       \
00049         "bic r1, lr, #1\n\t"                                          \
00050         "ldr r0, [sp, #20]\n\t"                                \
00051         "bl mcount_internal\n\t"                               \
00052         "pop {r0, r1, r2, r3, ip, lr}\n\t"                            \
00053         "bx ip");                                              \
00054 }                                                              \
00055 OLD_MCOUNT
00056 
00057 /* Provide old mcount for backwards compatibility.  This requires
00058    code be compiled with APCS frame pointers.  */
00059 
00060 #ifndef NO_UNDERSCORES
00061 /* The asm symbols for C functions are `_function'.
00062    The canonical name for the counter function is `mcount', no _.  */
00063 void _mcount (void) asm ("mcount");
00064 #else
00065 /* The canonical name for the function is `_mcount' in both C and asm,
00066    but some old asm code might assume it's `mcount'.  */
00067 void _mcount (void);
00068 weak_alias (_mcount, mcount)
00069 #endif
00070 
00071 #ifdef __thumb2__
00072 
00073 #define OLD_MCOUNT                                             \
00074 void __attribute__((__naked__)) _mcount (void)                        \
00075 {                                                              \
00076   __asm__("push             {r0, r1, r2, r3, fp, lr};"                \
00077          "movs              r0, fp;"                                  \
00078          "ittt              ne;"                                      \
00079          "ldrne      r0, [r0, #-4];"                                  \
00080          "movsne     r1, lr;"                                  \
00081          "blne              mcount_internal;"                         \
00082          "pop        {r0, r1, r2, r3, fp, pc}");               \
00083 }
00084 
00085 #else
00086 
00087 #define OLD_MCOUNT                                             \
00088 void __attribute__((__naked__)) _mcount (void)                        \
00089 {                                                              \
00090   __asm__("stmdb     sp!, {r0, r1, r2, r3, fp, lr};"                  \
00091          "movs              fp, fp;"                                  \
00092          "ldrne      r0, [fp, #-4];"                                  \
00093          "movnes     r1, lr;"                                  \
00094          "blne              mcount_internal;"                         \
00095          "ldmia      sp!, {r0, r1, r2, r3, fp, lr};"                  \
00096          "bx         lr");                                     \
00097 }
00098 
00099 #endif