(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / powerpc / powerpc32 / ppc-mcount.S
bloba72d676bbe2a1d37229f7613c1ac69b8ef379808
1 /* PowerPC-specific implementation of profiling support.
2    Copyright (C) 1997, 1999 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., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 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, _mcount is called
28    with the address of a data word in r0 (that is different for every
29    routine, initialised to 0, and otherwise unused).  The caller has put
30    the address the caller will return to in the usual place on the stack,
31    4(r1).  _mcount is responsible for ensuring that when it returns no
32    argument-passing registers are disturbed, and that the LR is set back
33    to (what the caller sees as) 4(r1).
35    This is intended so that the following code can be inserted at the
36    front of any routine without changing the routine:
38         .data
39         .align  2
40    0:   .long   0
41         .previous
42         mflr    r0
43         lis     r11,0b@ha
44         stw     r0,4(r1)
45         addi    r0,r11,0b@l
46         bl      _mcount
49 ENTRY(_mcount)
50         stwu    r1,-48(r1)
51 /* We need to save the parameter-passing registers.  */
52         stw     r3, 12(r1)
53         stw     r4, 16(r1)
54         stw     r5, 20(r1)
55         stw     r6, 24(r1)
56         mflr    r4
57         lwz     r3, 52(r1)
58         mfcr    r5
59         stw     r7, 28(r1)
60         stw     r8, 32(r1)
61         stw     r9, 36(r1)
62         stw     r10,40(r1)
63         stw     r4, 44(r1)
64         stw     r5,  8(r1)
65         bl      JUMPTARGET(__mcount_internal)
66         nop
67  /* Restore the registers...  */
68         lwz     r6,  8(r1)
69         lwz     r0, 44(r1)
70         lwz     r3, 12(r1)
71         mtctr   r0
72         lwz     r4, 16(r1)
73         mtcrf   0xff,r6
74         lwz     r5, 20(r1)
75         lwz     r6, 24(r1)
76         lwz     r0, 52(r1)
77         lwz     r7, 28(r1)
78         lwz     r8, 32(r1)
79         mtlr    r0
80         lwz     r9, 36(r1)
81         lwz     r10,40(r1)
82  /* ...unwind the stack frame, and return to your usual programming.  */
83         addi    r1,r1,48
84         bctr
85 END(_mcount)