blob: 296b346184b27bba25836516f4f24ffa29694a5f [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _ASM_X86_FRAME_H
3#define _ASM_X86_FRAME_H
4
5#include <asm/asm.h>
6
7/*
8 * These are stack frame creation macros. They should be used by every
9 * callable non-leaf asm function to make kernel stack traces more reliable.
10 */
11
12#ifdef CONFIG_FRAME_POINTER
13
14#ifdef __ASSEMBLY__
15
16.macro FRAME_BEGIN
17 push %_ASM_BP
18 _ASM_MOV %_ASM_SP, %_ASM_BP
19.endm
20
21.macro FRAME_END
22 pop %_ASM_BP
23.endm
24
David Brazdil0f672f62019-12-10 10:32:29 +000025#ifdef CONFIG_X86_64
26/*
27 * This is a sneaky trick to help the unwinder find pt_regs on the stack. The
28 * frame pointer is replaced with an encoded pointer to pt_regs. The encoding
29 * is just setting the LSB, which makes it an invalid stack address and is also
30 * a signal to the unwinder that it's a pt_regs pointer in disguise.
31 *
32 * NOTE: This macro must be used *after* PUSH_AND_CLEAR_REGS because it corrupts
33 * the original rbp.
34 */
35.macro ENCODE_FRAME_POINTER ptregs_offset=0
36 leaq 1+\ptregs_offset(%rsp), %rbp
37.endm
38#else /* !CONFIG_X86_64 */
39/*
40 * This is a sneaky trick to help the unwinder find pt_regs on the stack. The
41 * frame pointer is replaced with an encoded pointer to pt_regs. The encoding
42 * is just clearing the MSB, which makes it an invalid stack address and is also
43 * a signal to the unwinder that it's a pt_regs pointer in disguise.
44 *
45 * NOTE: This macro must be used *after* SAVE_ALL because it corrupts the
46 * original ebp.
47 */
48.macro ENCODE_FRAME_POINTER
49 mov %esp, %ebp
50 andl $0x7fffffff, %ebp
51.endm
52#endif /* CONFIG_X86_64 */
53
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000054#else /* !__ASSEMBLY__ */
55
56#define FRAME_BEGIN \
57 "push %" _ASM_BP "\n" \
58 _ASM_MOV "%" _ASM_SP ", %" _ASM_BP "\n"
59
60#define FRAME_END "pop %" _ASM_BP "\n"
61
David Brazdil0f672f62019-12-10 10:32:29 +000062#ifdef CONFIG_X86_64
63#define ENCODE_FRAME_POINTER \
64 "lea 1(%rsp), %rbp\n\t"
65#else /* !CONFIG_X86_64 */
66#define ENCODE_FRAME_POINTER \
67 "movl %esp, %ebp\n\t" \
68 "andl $0x7fffffff, %ebp\n\t"
69#endif /* CONFIG_X86_64 */
70
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000071#endif /* __ASSEMBLY__ */
72
73#define FRAME_OFFSET __ASM_SEL(4, 8)
74
75#else /* !CONFIG_FRAME_POINTER */
76
David Brazdil0f672f62019-12-10 10:32:29 +000077#ifdef __ASSEMBLY__
78
79.macro ENCODE_FRAME_POINTER ptregs_offset=0
80.endm
81
82#else /* !__ASSEMBLY */
83
84#define ENCODE_FRAME_POINTER
85
86#endif
87
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000088#define FRAME_BEGIN
89#define FRAME_END
90#define FRAME_OFFSET 0
91
92#endif /* CONFIG_FRAME_POINTER */
93
94#endif /* _ASM_X86_FRAME_H */