1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_FRAME_H
3 #define _ASM_X86_FRAME_H
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.
12 #ifdef CONFIG_FRAME_POINTER
18 _ASM_MOV
%_ASM_SP
, %_ASM_BP
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.
32 * NOTE: This macro must be used *after* PUSH_AND_CLEAR_REGS because it corrupts
35 .macro ENCODE_FRAME_POINTER ptregs_offset
=0
36 leaq
1+\
ptregs_offset(%rsp
), %rbp
38 #else /* !CONFIG_X86_64 */
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.
45 * NOTE: This macro must be used *after* SAVE_ALL because it corrupts the
48 .macro ENCODE_FRAME_POINTER
50 andl $
0x7fffffff, %ebp
52 #endif /* CONFIG_X86_64 */
54 #else /* !__ASSEMBLY__ */
57 "push %" _ASM_BP "\n" \
58 _ASM_MOV "%" _ASM_SP ", %" _ASM_BP "\n"
60 #define FRAME_END "pop %" _ASM_BP "\n"
64 #define ENCODE_FRAME_POINTER \
65 "lea 1(%rsp), %rbp\n\t"
67 static inline unsigned long encode_frame_pointer(struct pt_regs
*regs
)
69 return (unsigned long)regs
+ 1;
72 #else /* !CONFIG_X86_64 */
74 #define ENCODE_FRAME_POINTER \
75 "movl %esp, %ebp\n\t" \
76 "andl $0x7fffffff, %ebp\n\t"
78 static inline unsigned long encode_frame_pointer(struct pt_regs
*regs
)
80 return (unsigned long)regs
& 0x7fffffff;
83 #endif /* CONFIG_X86_64 */
85 #endif /* __ASSEMBLY__ */
87 #define FRAME_OFFSET __ASM_SEL(4, 8)
89 #else /* !CONFIG_FRAME_POINTER */
93 .macro ENCODE_FRAME_POINTER ptregs_offset
=0
96 #else /* !__ASSEMBLY */
98 #define ENCODE_FRAME_POINTER
100 static inline unsigned long encode_frame_pointer(struct pt_regs
*regs
)
109 #define FRAME_OFFSET 0
111 #endif /* CONFIG_FRAME_POINTER */
113 #endif /* _ASM_X86_FRAME_H */