Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / powerpc / powerpc32 / ppc-mcount.S
blobd8b72ff5bdbc9573fadbbc0facae5c02a6719430
1 /* PowerPC-specific implementation of profiling support.
2    Copyright (C) 1997-2014 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, see
17    <http://www.gnu.org/licenses/>.  */
19 /* This would be bad.  */
20 #ifdef PROF
21 #undef PROF
22 #endif
24 #include <sysdep.h>
26 /* We do profiling as described in the SYSV ELF ABI, except that glibc
27    _mcount manages its own counters.  The caller has put the address the
28    caller will return to in the usual place on the stack, 4(r1).  _mcount
29    is responsible for ensuring that when it returns no argument-passing
30    registers are disturbed, and that the LR is set back to (what the
31    caller sees as) 4(r1).
33    This is intended so that the following code can be inserted at the
34    front of any routine without changing the routine:
36         .data
37         mflr    r0
38         stw     r0,4(r1)
39         bl      _mcount
42 ENTRY(_mcount)
43         stwu    r1,-48(r1)
44         cfi_adjust_cfa_offset (48)
45 /* We need to save the parameter-passing registers.  */
46         stw     r3, 12(r1)
47         stw     r4, 16(r1)
48         stw     r5, 20(r1)
49         stw     r6, 24(r1)
50         mflr    r4
51         lwz     r3, 52(r1)
52         mfcr    r5
53         stw     r7, 28(r1)
54         stw     r8, 32(r1)
55         stw     r9, 36(r1)
56         stw     r10,40(r1)
57         stw     r4, 44(r1)
58         cfi_offset (lr, -4)
59         stw     r5,  8(r1)
60 #ifndef SHARED
61         bl      JUMPTARGET(__mcount_internal)
62 #else
63         bl      __mcount_internal@local
64 #endif
65  /* Restore the registers...  */
66         lwz     r6,  8(r1)
67         lwz     r0, 44(r1)
68         lwz     r3, 12(r1)
69         mtctr   r0
70         lwz     r4, 16(r1)
71         mtcrf   0xff,r6
72         lwz     r5, 20(r1)
73         lwz     r6, 24(r1)
74         lwz     r0, 52(r1)
75         lwz     r7, 28(r1)
76         lwz     r8, 32(r1)
77         mtlr    r0
78         lwz     r9, 36(r1)
79         lwz     r10,40(r1)
80  /* ...unwind the stack frame, and return to your usual programming.  */
81         addi    r1,r1,48
82         bctr
83 END(_mcount)