2 (C) Copyright IBM Corp. 2008
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14 * Neither the name of IBM nor the names of its contributors may be
15 used to endorse or promote products derived from this software without
16 specific prior written permission.
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 POSSIBILITY OF SUCH DAMAGE.
30 Author: Ken Werner <ken.werner@de.ibm.com>
33 /* _mcount extracts the address of the function just entered and the address
34 of the caller of that function and then calls __mcount_internal. The
35 prologue calls mcount without saving any registers. The return address is
36 stored in $75. The _mcount function has to:
37 - create a new stack frame
38 - save registers $2 to $75 on the stack
39 - copy the two addresses ($0 and $75) into the argument registers $3 and $4
40 - call __mcount_internal
44 /* The following two convenience macros assist in the coding of the
45 saving and restoring the register.
47 saveregs first, last Saves registers from first to the last.
48 restoreregs first, last Restores registers from last down to first.
50 Note: first must be less than or equal to last. */
51 .macro saveregs first, last
52 stqd $\first, \first*16($SP)
54 saveregs "(\first+1)",\last
58 .macro restoreregs first, last
59 lqd $\last, \last*16($SP)
61 restoreregs \first,"(\last-1)"
65 /* _mcount needs to be resident since the overlay manager uses the scratch
68 .align 3 /* 8 byte alignment. */
70 .type _mcount, @function
73 stqd $lr, 16($sp) /* Save link register in the callers stack frame. */
74 stqd $lr, -1216($sp) /* Store back pointer. */
75 il $lr, -1216 /* Push a new stack frame. */
76 a $sp, $sp, $lr /* Frame size: 16 * (74 + 2) = 1216. */
78 /* Save registers $2 to $75 on the stack. */
81 /* Bring the __mcount_internal arguments in place. */
82 lqd $3, 1232($sp) /* frompc (the link register). */
83 ori $4, $75, 0 /* selfpc (the gcc prologue puts "brsl $75, _mcount" in
84 front of every function). */
85 brsl $lr, __mcount_internal
87 /* Restore register $2 to $75 from the stack. */
91 a $sp, $sp, $lr /* Pop the stack frame. */
92 lqd $lr, 16($sp) /* Restore link register. */
93 bi $75 /* Branch to the called function. */