diff options
author | Eric Andersen <andersen@codepoet.org> | 2003-03-03 20:58:42 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2003-03-03 20:58:42 +0000 |
commit | 67eff66438688fddebe41f77fd252a3b2b135271 (patch) | |
tree | 18dbee3e9afe50d27095140198e2aa34df1de061 /libc | |
parent | 2229d0fa131387b9b8ad16ac88347350a080aeb5 (diff) |
Initial effort at adding profiling support.
Diffstat (limited to 'libc')
53 files changed, 2660 insertions, 3 deletions
diff --git a/libc/sysdeps/linux/alpha/bits/atomicity.h b/libc/sysdeps/linux/alpha/bits/atomicity.h new file mode 100644 index 000000000..9388f2384 --- /dev/null +++ b/libc/sysdeps/linux/alpha/bits/atomicity.h @@ -0,0 +1,102 @@ +/* Low-level functions for atomic operations. Alpha version. + Copyright (C) 1999 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _ATOMICITY_H +#define _ATOMICITY_H 1 + +#include <inttypes.h> + + +static inline int +__attribute__ ((unused)) +exchange_and_add (volatile uint32_t *mem, int val) +{ + register int result, tmp; + + __asm__ __volatile__ ( + "/* Inline exchange & add */\n" + "1:\t" + "ldl_l %0,%3\n\t" + "addl %0,%4,%1\n\t" + "stl_c %1,%2\n\t" + "beq %1,2f\n" + ".subsection 1\n" + "2:\t" + "br 1b\n" + ".previous\n\t" + "mb\n\t" + "/* End exchange & add */" + : "=&r"(result), "=&r"(tmp), "=m"(*mem) + : "m" (*mem), "r"(val)); + + return result; +} + +static inline void +__attribute__ ((unused)) +atomic_add (volatile uint32_t *mem, int val) +{ + register int result; + + __asm__ __volatile__ ( + "/* Inline exchange & add */\n" + "1:\t" + "ldl_l %0,%2\n\t" + "addl %0,%3,%0\n\t" + "stl_c %0,%1\n\t" + "beq %0,2f\n\t" + ".subsection 1\n" + "2:\t" + "br 1b\n" + ".previous\n\t" + "mb\n\t" + "/* End exchange & add */" + : "=&r"(result), "=m"(*mem) + : "m" (*mem), "r"(val)); +} + +static inline long +__attribute__ ((unused)) +compare_and_swap (volatile long int *p, long int oldval, long int newval) +{ + long int ret; + + __asm__ __volatile__ ( + "/* Inline compare & swap */\n" + "1:\t" + "ldq_l %0,%4\n\t" + "cmpeq %0,%2,%0\n\t" + "beq %0,3f\n\t" + "mov %3,%0\n\t" + "stq_c %0,%1\n\t" + "beq %0,2f\n\t" + ".subsection 1\n" + "2:\t" + "br 1b\n" + ".previous\n\t" + "3:\t" + "mb\n\t" + "/* End compare & swap */" + : "=&r"(ret), "=m"(*p) + : "r"(oldval), "r"(newval), "m"(*p)); + + return ret; +} + +#endif /* atomicity.h */ diff --git a/libc/sysdeps/linux/alpha/bits/machine-gmon.h b/libc/sysdeps/linux/alpha/bits/machine-gmon.h new file mode 100644 index 000000000..5f5522c0b --- /dev/null +++ b/libc/sysdeps/linux/alpha/bits/machine-gmon.h @@ -0,0 +1,26 @@ +/* Machine-specific calling sequence for `mcount' profiling function. alpha + Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#define _MCOUNT_DECL(from, self) \ + void __mcount (u_long from, u_long self) + +/* Call __mcount with our the return PC for our caller, and the return + PC our caller will return to. Empty since we use an assembly stub + instead. */ +#define MCOUNT diff --git a/libc/sysdeps/linux/alpha/bits/sigcontextinfo.h b/libc/sysdeps/linux/alpha/bits/sigcontextinfo.h new file mode 100644 index 000000000..eb6f4f075 --- /dev/null +++ b/libc/sysdeps/linux/alpha/bits/sigcontextinfo.h @@ -0,0 +1,25 @@ +/* Copyright (C) 1999 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#define SIGCONTEXT struct sigcontext +#define SIGCONTEXT_EXTRA_ARGS +#define GET_PC(ctx) ((void *) (ctx).sc_pc) +#define GET_FRAME(ctx) ((void *) (ctx).sc_regs[15]) +#define GET_STACK(ctx) ((void *) (ctx).sc_regs[30]) +#define CALL_SIGHANDLER(handler, signo, ctx) \ + (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx)) diff --git a/libc/sysdeps/linux/alpha/bits/stackinfo.h b/libc/sysdeps/linux/alpha/bits/stackinfo.h new file mode 100644 index 000000000..0a281bd43 --- /dev/null +++ b/libc/sysdeps/linux/alpha/bits/stackinfo.h @@ -0,0 +1,28 @@ +/* Copyright (C) 2001 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* This file contains a bit of information about the stack allocation + of the processor. */ + +#ifndef _STACKINFO_H +#define _STACKINFO_H 1 + +/* On Alpha the stack grows down. */ +#define _STACK_GROWS_DOWN 1 + +#endif /* stackinfo.h */ diff --git a/libc/sysdeps/linux/arm/bits/armsigctx.h b/libc/sysdeps/linux/arm/bits/armsigctx.h new file mode 100644 index 000000000..4530cdbda --- /dev/null +++ b/libc/sysdeps/linux/arm/bits/armsigctx.h @@ -0,0 +1,73 @@ +/* Definition of `struct sigcontext' for Linux/ARM + Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* The format of struct sigcontext changed between 2.0 and 2.1 kernels. + Fortunately 2.0 puts a magic number in the first word and this is not + a legal value for `trap_no', so we can tell them apart. */ + +/* Early 2.2 and 2.3 kernels do not have the `fault_address' member in + the sigcontext structure. Unfortunately there is no reliable way + to test for its presence and this word will contain garbage for too-old + kernels. Versions 2.2.14 and 2.3.35 (plus later versions) are known to + include this element. */ + +#ifndef __ARMSIGCTX_H +#define __ARMSIGCTX_H 1 + +#include <asm/ptrace.h> + +union k_sigcontext + { + struct + { + unsigned long int trap_no; + unsigned long int error_code; + unsigned long int oldmask; + unsigned long int arm_r0; + unsigned long int arm_r1; + unsigned long int arm_r2; + unsigned long int arm_r3; + unsigned long int arm_r4; + unsigned long int arm_r5; + unsigned long int arm_r6; + unsigned long int arm_r7; + unsigned long int arm_r8; + unsigned long int arm_r9; + unsigned long int arm_r10; + unsigned long int arm_fp; + unsigned long int arm_ip; + unsigned long int arm_sp; + unsigned long int arm_lr; + unsigned long int arm_pc; + unsigned long int arm_cpsr; + unsigned long fault_address; + } v21; + struct + { + unsigned long int magic; + struct pt_regs reg; + unsigned long int trap_no; + unsigned long int error_code; + unsigned long int oldmask; + } v20; +}; + +#define SIGCONTEXT_2_0_MAGIC 0x4B534154 + +#endif /* bits/armsigctx.h */ diff --git a/libc/sysdeps/linux/arm/bits/atomicity.h b/libc/sysdeps/linux/arm/bits/atomicity.h new file mode 100644 index 000000000..1a437a6d3 --- /dev/null +++ b/libc/sysdeps/linux/arm/bits/atomicity.h @@ -0,0 +1,87 @@ +/* Low-level functions for atomic operations. ARM version. + Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _ATOMICITY_H +#define _ATOMICITY_H 1 + +#include <inttypes.h> + + +static inline int +__attribute__ ((unused)) +exchange_and_add (volatile uint32_t *mem, int val) +{ + int tmp1; + int tmp2; + int result; + __asm__ ("\n" + "0:\tldr\t%0,[%3]\n\t" + "add\t%1,%0,%4\n\t" + "swp\t%2,%1,[%3]\n\t" + "cmp\t%0,%2\n\t" + "swpne\t%1,%2,[%3]\n\t" + "bne\t0b" + : "=&r" (result), "=&r" (tmp1), "=&r" (tmp2) + : "r" (mem), "r"(val) + : "cc", "memory"); + return result; +} + +static inline void +__attribute__ ((unused)) +atomic_add (volatile uint32_t *mem, int val) +{ + int tmp1; + int tmp2; + int tmp3; + __asm__ ("\n" + "0:\tldr\t%0,[%3]\n\t" + "add\t%1,%0,%4\n\t" + "swp\t%2,%1,[%3]\n\t" + "cmp\t%0,%2\n\t" + "swpne\t%1,%2,[%3]\n\t" + "bne\t0b" + : "=&r" (tmp1), "=&r" (tmp2), "=&r" (tmp3) + : "r" (mem), "r"(val) + : "cc", "memory"); +} + +static inline int +__attribute__ ((unused)) +compare_and_swap (volatile long int *p, long int oldval, long int newval) +{ + int result, tmp; + __asm__ ("\n" + "0:\tldr\t%1,[%2]\n\t" + "mov\t%0,#0\n\t" + "cmp\t%1,%4\n\t" + "bne\t1f\n\t" + "swp\t%0,%3,[%2]\n\t" + "cmp\t%1,%0\n\t" + "swpne\t%1,%0,[%2]\n\t" + "bne\t0b\n\t" + "mov\t%0,#1\n" + "1:" + : "=&r" (result), "=&r" (tmp) + : "r" (p), "r" (newval), "r" (oldval) + : "cc", "memory"); + return result; +} + +#endif /* atomicity.h */ diff --git a/libc/sysdeps/linux/arm/bits/machine-gmon.h b/libc/sysdeps/linux/arm/bits/machine-gmon.h new file mode 100644 index 000000000..039dfd951 --- /dev/null +++ b/libc/sysdeps/linux/arm/bits/machine-gmon.h @@ -0,0 +1,67 @@ +/* Machine-dependent definitions for profiling support. ARM version. + Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* GCC for the ARM cannot compile __builtin_return_address(N) for N != 0, + so we must use an assembly stub. */ + +#include <sysdep.h> +#ifndef NO_UNDERSCORES +/* The asm symbols for C functions are `_function'. + The canonical name for the counter function is `mcount', no _. */ +void _mcount (void) asm ("mcount"); +#else +/* The canonical name for the function is `_mcount' in both C and asm, + but some old asm code might assume it's `mcount'. */ +void _mcount (void); +weak_alias (_mcount, mcount) +#endif + +static void mcount_internal (u_long frompc, u_long selfpc); + +#define _MCOUNT_DECL(frompc, selfpc) \ +static void mcount_internal (u_long frompc, u_long selfpc) + +/* This macro/func MUST save r0, r1 because the compiler inserts + blind calls to _mount(), ignoring the fact that _mcount may + clobber registers; therefore, _mcount may NOT clobber registers */ +/* if (this_fp!=0) { + r0 = this_fp + r1 = this_lr + r1 = [r1-4] which is caller's lr + if (r1!=0) + r1 = caller's lr + call mcount_internal(this_lr, caller's_lr) + } +*/ + +#define MCOUNT \ +void _mcount (void) \ +{ \ + __asm__("stmdb sp!, {r0, r1, r2, r3};" \ + "movs fp, fp;" \ + "moveq r1, #0;" \ + "ldrne r1, [fp, $-4];" \ + "ldrne r0, [fp, $-12];" \ + "movnes r0, r0;" \ + "ldrne r0, [r0, $-4];" \ + "movs r0, r0;" \ + "blne mcount_internal;" \ + "ldmia sp!, {r0, r1, r2, r3}"); \ +} + diff --git a/libc/sysdeps/linux/arm/bits/profil-counter.h b/libc/sysdeps/linux/arm/bits/profil-counter.h new file mode 100644 index 000000000..5d8be9dba --- /dev/null +++ b/libc/sysdeps/linux/arm/bits/profil-counter.h @@ -0,0 +1,32 @@ +/* Low-level statistical profiling support function. Linux/ARM version. + Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <signal.h> +#include <bits/armsigctx.h> + +void +profil_counter (int signo, int _a2, int _a3, int _a4, union k_sigcontext sc) +{ + void *pc; + if (sc.v20.magic == SIGCONTEXT_2_0_MAGIC) + pc = (void *) sc.v20.reg.ARM_pc; + else + pc = (void *) sc.v21.arm_pc; + profil_count (pc); +} diff --git a/libc/sysdeps/linux/arm/bits/sigcontextinfo.h b/libc/sysdeps/linux/arm/bits/sigcontextinfo.h new file mode 100644 index 000000000..aebc3cfd5 --- /dev/null +++ b/libc/sysdeps/linux/arm/bits/sigcontextinfo.h @@ -0,0 +1,35 @@ +/* Copyright (C) 1999 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Philip Blundell <philb@gnu.org>, 1999. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <bits/armsigctx.h> + +#define SIGCONTEXT int _a2, int _a3, int _a4, union k_sigcontext +#define SIGCONTEXT_EXTRA_ARGS _a2, _a3, _a4, + +#define GET_PC(ctx) ((void *)((ctx.v20.magic == SIGCONTEXT_2_0_MAGIC) ? \ + ctx.v20.reg.ARM_pc : ctx.v21.arm_pc)) +#define GET_FRAME(ctx) \ + ADVANCE_STACK_FRAME((void *)((ctx.v20.magic == SIGCONTEXT_2_0_MAGIC) ? \ + ctx.v20.reg.ARM_fp : ctx.v21.arm_fp)) +#define GET_STACK(ctx) ((void *)((ctx.v20.magic == SIGCONTEXT_2_0_MAGIC) ? \ + ctx.v20.reg.ARM_sp : ctx.v21.arm_sp)) +#define ADVANCE_STACK_FRAME(frm) \ + ((struct layout *)frm - 1) +#define CALL_SIGHANDLER(handler, signo, ctx) \ + (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx)) diff --git a/libc/sysdeps/linux/arm/bits/stackinfo.h b/libc/sysdeps/linux/arm/bits/stackinfo.h new file mode 100644 index 000000000..2410ba9bd --- /dev/null +++ b/libc/sysdeps/linux/arm/bits/stackinfo.h @@ -0,0 +1,28 @@ +/* Copyright (C) 2001 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* This file contains a bit of information about the stack allocation + of the processor. */ + +#ifndef _STACKINFO_H +#define _STACKINFO_H 1 + +/* On Arm the stack grows down. */ +#define _STACK_GROWS_DOWN 1 + +#endif /* stackinfo.h */ diff --git a/libc/sysdeps/linux/common/.cvsignore b/libc/sysdeps/linux/common/.cvsignore index f8fa8225d..0232d6900 100644 --- a/libc/sysdeps/linux/common/.cvsignore +++ b/libc/sysdeps/linux/common/.cvsignore @@ -1,3 +1,4 @@ crti.S crtn.S initfini.S +gmon-start.S diff --git a/libc/sysdeps/linux/common/Makefile b/libc/sysdeps/linux/common/Makefile index 5b9717f2b..d51fc4281 100644 --- a/libc/sysdeps/linux/common/Makefile +++ b/libc/sysdeps/linux/common/Makefile @@ -29,6 +29,9 @@ CSRC= waitpid.c getdnnm.c gethstnm.c getcwd.c ptrace.c \ ifneq ($(strip $(EXCLUDE_BRK)),y) CSRC+=sbrk.c endif +ifeq ($(strip $(UCLIBC_PROFILING)),y) +CSRC+=gmon.c +endif COBJS=$(patsubst %.c,%.o, $(CSRC)) MSRC=syscalls.c @@ -44,6 +47,9 @@ SAFECFLAGS := $(subst -g,,$(SAFECFL |