7944544e18494e99c2ff3a8cce68e77417dc2576
[platform/upstream/glibc.git] / sysdeps / alpha / _mcount.S
1 /* Machine-specific calling sequence for `mcount' profiling function.  alpha
2 Copyright (C) 1995 Free Software Foundation, Inc.
3 Contributed by David Mosberger (davidm@cs.arizona.edu).
4 This file is part of the GNU C Library.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB.  If
18 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
19 Cambridge, MA 02139, USA.  */
20
21 /* Assembly stub to invoke _mcount().  Compiler generated code calls
22 this stub after executing a function's prologue and without saving any
23 registers.  It is therefore necessary to preserve a0..a5 as they may
24 contain function arguments.  To work correctly with frame- less
25 functions, it is also necessary to preserve ra.  Finally, division
26 routines are invoked with a special calling convention and the
27 compiler treats those calls as if they were instructions.  In
28 particular, it doesn't save any of the temporary registers (caller
29 saved registers).  It is therefore necessary to preserve all
30 caller-saved registers as well
31  
32 Upon entering _mcount, register $at holds the return address and ra
33 holds the return address of the function's caller (selfpc and frompc,
34 respectively in gmon.c language...). */
35
36 #include <sysdep.h>
37
38 #undef ret      /* discard `ret' as defined in sysdep.h */
39
40         .set    noat
41         .set    noreorder
42
43 LEAF(_mcount, 0xb0)
44         .prologue 0
45
46         subq     sp, 0xb0, sp
47         stq      a0, 0x00(sp)
48         mov      ra, a0         # a0 = caller-pc
49         stq      a1, 0x08(sp)
50         mov     $at, a1         # a1 = self-pc
51         stq     $at, 0x10(sp)
52
53         stq      a2, 0x18(sp)
54         stq      a3, 0x20(sp)
55         stq      a4, 0x28(sp)
56         stq      a5, 0x30(sp)
57         stq      ra, 0x38(sp)
58         stq      gp, 0x40(sp)
59
60         br      gp, 1f
61 1:      ldgp    gp, 0(gp)
62
63         stq      t0, 0x48(sp)
64         stq      t1, 0x50(sp)
65         stq      t2, 0x58(sp)
66         stq      t3, 0x60(sp)
67         stq      t4, 0x68(sp)
68         stq      t5, 0x70(sp)
69         stq      t6, 0x78(sp)
70
71         lda      pv, __mcount
72
73         stq      t7, 0x80(sp)
74         stq      t8, 0x88(sp)
75         stq      t9, 0x90(sp)
76         stq     t10, 0x98(sp)
77         stq     t11, 0xa0(sp)
78         stq      v0, 0xa8(sp)
79
80         jsr     ra, (pv), __mcount
81
82         ldq      a0, 0x00(sp)
83         ldq      a1, 0x08(sp)
84         ldq     $at, 0x10(sp)   # restore self-pc
85         ldq      a2, 0x18(sp)
86         ldq      a3, 0x20(sp)
87         ldq      a4, 0x28(sp)
88         ldq      a5, 0x30(sp)
89         ldq      ra, 0x38(sp)
90         ldq      gp, 0x40(sp)
91         mov     $at, pv         # make pv point to return address
92         ldq      t0, 0x48(sp)   # this is important under OSF/1 to
93         ldq      t1, 0x50(sp)   # ensure that the code that we return
94         ldq      t2, 0x58(sp)   # can correctly compute its gp
95         ldq      t3, 0x60(sp)
96         ldq      t4, 0x68(sp)
97         ldq      t5, 0x70(sp)
98         ldq      t6, 0x78(sp)
99         ldq      t7, 0x80(sp)
100         ldq      t8, 0x88(sp)
101         ldq      t9, 0x90(sp)
102         ldq     t10, 0x98(sp)
103         ldq     t11, 0xa0(sp)
104         ldq      v0, 0xa8(sp)
105
106         addq    sp, 0xb0, sp
107         ret     zero,($at),1
108
109         .end _mcount