2.9
[glibc/nacl-glibc.git] / sysdeps / powerpc / powerpc32 / ppc-mcount.S
blob7e39acb55b5460c70ac16e78af66ae68b203f9a7
1 /* PowerPC-specific implementation of profiling support.
2    Copyright (C) 1997, 1999, 2005, 2006 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, write to the Free
17    Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA
18    02110-1301 USA.  */
20 /* This would be bad.  */
21 #ifdef PROF
22 #undef PROF
23 #endif
25 #include <sysdep.h>
27 /* We do profiling as described in the SYSV ELF ABI, except that glibc
28    _mcount manages its own counters.  The caller has put the address the
29    caller will return to in the usual place on the stack, 4(r1).  _mcount
30    is responsible for ensuring that when it returns no argument-passing
31    registers are disturbed, and that the LR is set back to (what the
32    caller sees as) 4(r1).
34    This is intended so that the following code can be inserted at the
35    front of any routine without changing the routine:
37         .data
38         mflr    r0
39         stw     r0,4(r1)
40         bl      _mcount
43 ENTRY(_mcount)
44         stwu    r1,-48(r1)
45         cfi_adjust_cfa_offset (48)
46 /* We need to save the parameter-passing registers.  */
47         stw     r3, 12(r1)
48         stw     r4, 16(r1)
49         stw     r5, 20(r1)
50         stw     r6, 24(r1)
51         mflr    r4
52         lwz     r3, 52(r1)
53         mfcr    r5
54         stw     r7, 28(r1)
55         stw     r8, 32(r1)
56         stw     r9, 36(r1)
57         stw     r10,40(r1)
58         stw     r4, 44(r1)
59         cfi_offset (lr, -4)
60         stw     r5,  8(r1)
61         bl      __mcount_internal@local
62         nop
63  /* Restore the registers...  */
64         lwz     r6,  8(r1)
65         lwz     r0, 44(r1)
66         lwz     r3, 12(r1)
67         mtctr   r0
68         lwz     r4, 16(r1)
69         mtcrf   0xff,r6
70         lwz     r5, 20(r1)
71         lwz     r6, 24(r1)
72         lwz     r0, 52(r1)
73         lwz     r7, 28(r1)
74         lwz     r8, 32(r1)
75         mtlr    r0
76         lwz     r9, 36(r1)
77         lwz     r10,40(r1)
78  /* ...unwind the stack frame, and return to your usual programming.  */
79         addi    r1,r1,48
80         bctr
81 END(_mcount)