xref: /linux/arch/x86/include/asm/unwind_hints.h (revision 0e2b2a76278153d1ac312b0691cb65dabb9aef3e)
1 #ifndef _ASM_X86_UNWIND_HINTS_H
2 #define _ASM_X86_UNWIND_HINTS_H
3 
4 #include <linux/objtool.h>
5 
6 #include "orc_types.h"
7 
8 #ifdef __ASSEMBLY__
9 
10 .macro UNWIND_HINT_END_OF_STACK
11 	UNWIND_HINT type=UNWIND_HINT_TYPE_END_OF_STACK
12 .endm
13 
14 .macro UNWIND_HINT_UNDEFINED
15 	UNWIND_HINT type=UNWIND_HINT_TYPE_UNDEFINED
16 .endm
17 
18 .macro UNWIND_HINT_ENTRY
19 	VALIDATE_UNRET_BEGIN
20 	UNWIND_HINT_END_OF_STACK
21 .endm
22 
23 .macro UNWIND_HINT_REGS base=%rsp offset=0 indirect=0 extra=1 partial=0 signal=1
24 	.if \base == %rsp
25 		.if \indirect
26 			.set sp_reg, ORC_REG_SP_INDIRECT
27 		.else
28 			.set sp_reg, ORC_REG_SP
29 		.endif
30 	.elseif \base == %rbp
31 		.set sp_reg, ORC_REG_BP
32 	.elseif \base == %rdi
33 		.set sp_reg, ORC_REG_DI
34 	.elseif \base == %rdx
35 		.set sp_reg, ORC_REG_DX
36 	.elseif \base == %r10
37 		.set sp_reg, ORC_REG_R10
38 	.else
39 		.error "UNWIND_HINT_REGS: bad base register"
40 	.endif
41 
42 	.set sp_offset, \offset
43 
44 	.if \partial
45 		.set type, UNWIND_HINT_TYPE_REGS_PARTIAL
46 	.elseif \extra == 0
47 		.set type, UNWIND_HINT_TYPE_REGS_PARTIAL
48 		.set sp_offset, \offset + (16*8)
49 	.else
50 		.set type, UNWIND_HINT_TYPE_REGS
51 	.endif
52 
53 	UNWIND_HINT sp_reg=sp_reg sp_offset=sp_offset type=type signal=\signal
54 .endm
55 
56 .macro UNWIND_HINT_IRET_REGS base=%rsp offset=0 signal=1
57 	UNWIND_HINT_REGS base=\base offset=\offset partial=1 signal=\signal
58 .endm
59 
60 .macro UNWIND_HINT_IRET_ENTRY base=%rsp offset=0 signal=1
61 	VALIDATE_UNRET_BEGIN
62 	UNWIND_HINT_IRET_REGS base=\base offset=\offset signal=\signal
63 .endm
64 
65 .macro UNWIND_HINT_FUNC
66 	UNWIND_HINT sp_reg=ORC_REG_SP sp_offset=8 type=UNWIND_HINT_TYPE_FUNC
67 .endm
68 
69 .macro UNWIND_HINT_SAVE
70 	UNWIND_HINT type=UNWIND_HINT_TYPE_SAVE
71 .endm
72 
73 .macro UNWIND_HINT_RESTORE
74 	UNWIND_HINT type=UNWIND_HINT_TYPE_RESTORE
75 .endm
76 
77 #else
78 
79 #define UNWIND_HINT_UNDEFINED \
80 	UNWIND_HINT(UNWIND_HINT_TYPE_UNDEFINED, 0, 0, 0)
81 
82 #define UNWIND_HINT_FUNC \
83 	UNWIND_HINT(UNWIND_HINT_TYPE_FUNC, ORC_REG_SP, 8, 0)
84 
85 #define UNWIND_HINT_SAVE \
86 	UNWIND_HINT(UNWIND_HINT_TYPE_SAVE, 0, 0, 0)
87 
88 #define UNWIND_HINT_RESTORE \
89 	UNWIND_HINT(UNWIND_HINT_TYPE_RESTORE, 0, 0, 0)
90 
91 #endif /* __ASSEMBLY__ */
92 
93 #endif /* _ASM_X86_UNWIND_HINTS_H */
94