Add comment from sysdeps/powerpc/fpu/fraiseexcpt.c to fsetexcptflg.c.
[glibc.git] / sysdeps / x86_64 / _mcount.S
bloba506d21dcdc9c36a0f27ee7b20ca4d6fe70f0d21
1 /* Machine-specific calling sequence for `mcount' profiling function.  x86-64 version.
2    Copyright (C) 2002-2016 Free Software Foundation, Inc.
3    Contributed by Andreas Jaeger <aj@suse.de>.
4    This file is part of the GNU C Library.
6    The GNU C Library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
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    Lesser General Public License for more details.
16    You should have received a copy of the GNU Lesser General Public
17    License along with the GNU C Library; if not, see
18    <http://www.gnu.org/licenses/>.  */
20 /* Assembly stub to invoke _mcount().  Compiler generated code calls
21    this stub after executing a function's prologue and without saving any
22    registers.  It is therefore necessary to preserve %rcx, %rdx, %rsi, %rdi,
23    %r8, %r9 as they may contain function arguments.  */
25 #include <sysdep.h>
27 ENTRY(_mcount)
28         /* Allocate space for 7 registers.  */
29         subq    $56,%rsp
30         cfi_adjust_cfa_offset (56)
31         movq    %rax,(%rsp)
32         cfi_rel_offset (rax, 0)
33         movq    %rcx,8(%rsp)
34         cfi_rel_offset (rcx, 8)
35         movq    %rdx,16(%rsp)
36         cfi_rel_offset (rdx, 16)
37         movq    %rsi,24(%rsp)
38         cfi_rel_offset (rsi, 24)
39         movq    %rdi,32(%rsp)
40         cfi_rel_offset (rdi, 32)
41         movq    %r8,40(%rsp)
42         cfi_rel_offset (r8, 40)
43         movq    %r9,48(%rsp)
44         cfi_rel_offset (r9, 48)
46         /* Setup parameter for __mcount_internal.  */
47         /* selfpc is the return address on the stack.  */
48         movq    56(%rsp),%rsi
49         /* Get frompc via the frame pointer.  */
50         movq    8(%rbp),%rdi
51         call C_SYMBOL_NAME(__mcount_internal)
52         /* Pop the saved registers.  Please note that `mcount' has no
53            return value.  */
54         movq    48(%rsp),%r9
55         cfi_restore (r9)
56         movq    40(%rsp),%r8
57         cfi_restore (r8)
58         movq    32(%rsp),%rdi
59         cfi_restore (rdi)
60         movq    24(%rsp),%rsi
61         cfi_restore (rsi)
62         movq    16(%rsp),%rdx
63         cfi_restore (rdx)
64         movq    8(%rsp),%rcx
65         cfi_restore (rcx)
66         movq    (%rsp),%rax
67         cfi_restore (rax)
68         addq    $56,%rsp
69         cfi_adjust_cfa_offset (-56)
70         ret
71 END(_mcount)
73 #undef mcount
74 weak_alias (_mcount, mcount)
76 /* __fentry__ is different from _mcount in that it is called before
77    function prolog.  This means (among other things) that it has non-standard
78    stack alignment on entry: (%RSP & 0xF) == 0.  */
80 ENTRY(__fentry__)
81         /* Allocate space for 7 registers
82            (+8 bytes for proper stack alignment).  */
83         subq    $64,%rsp
84         cfi_adjust_cfa_offset (64)
85         movq    %rax,(%rsp)
86         cfi_rel_offset (rax, 0)
87         movq    %rcx,8(%rsp)
88         cfi_rel_offset (rcx, 8)
89         movq    %rdx,16(%rsp)
90         cfi_rel_offset (rdx, 16)
91         movq    %rsi,24(%rsp)
92         cfi_rel_offset (rsi, 24)
93         movq    %rdi,32(%rsp)
94         cfi_rel_offset (rdi, 32)
95         movq    %r8,40(%rsp)
96         cfi_rel_offset (r8, 40)
97         movq    %r9,48(%rsp)
98         cfi_rel_offset (r9, 48)
100         /* Setup parameter for __mcount_internal.  */
101         /* selfpc is the return address on the stack.  */
102         movq    64(%rsp),%rsi
103         /* caller is the return address above it */
104         movq    72(%rsp),%rdi
105         call C_SYMBOL_NAME(__mcount_internal)
106         /* Pop the saved registers.  Please note that `__fentry__' has no
107            return value.  */
108         movq    48(%rsp),%r9
109         cfi_restore (r9)
110         movq    40(%rsp),%r8
111         cfi_restore (r8)
112         movq    32(%rsp),%rdi
113         cfi_restore (rdi)
114         movq    24(%rsp),%rsi
115         cfi_restore (rsi)
116         movq    16(%rsp),%rdx
117         cfi_restore (rdx)
118         movq    8(%rsp),%rcx
119         cfi_restore (rcx)
120         movq    (%rsp),%rax
121         cfi_restore (rax)
122         addq    $64,%rsp
123         cfi_adjust_cfa_offset (-64)
124         ret
125 END(__fentry__)