Update.
[glibc.git] / sysdeps / powerpc / ppc-mcount.S
blob06f1fcda12ad3fd59f6decc439f1db0849da6fc7
1 /* PowerPC-specific implementation of profiling support.
2    Copyright (C) 1997 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 Library General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    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    Library General Public License for more details.
15    You should have received a copy of the GNU Library General Public
16    License along with the GNU C Library; see the file COPYING.LIB.  If not,
17    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18    Boston, MA 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  /* Restore the registers...  */
67         lwz     %r6,  8(%r1)
68         lwz     %r0, 44(%r1)
69         lwz     %r3, 12(%r1)
70         mtctr   %r0
71         lwz     %r4, 16(%r1)
72         mtcrf   0xff,%r6
73         lwz     %r5, 20(%r1)
74         lwz     %r6, 24(%r1)
75         lwz     %r0, 52(%r1)
76         lwz     %r7, 28(%r1)
77         lwz     %r8, 32(%r1)
78         mtlr    %r0
79         lwz     %r9, 36(%r1)
80         lwz     %r10,40(%r1)
81  /* ...unwind the stack frame, and return to your usual programming.  */
82         addi    %r1,%r1,48
83         bctr
84 END(_mcount)