xref: /openbmc/linux/arch/x86/include/asm/unwind_hints.h (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
139358a03SJosh Poimboeuf #ifndef _ASM_X86_UNWIND_HINTS_H
239358a03SJosh Poimboeuf #define _ASM_X86_UNWIND_HINTS_H
339358a03SJosh Poimboeuf 
4ee819aedSJulien Thierry #include <linux/objtool.h>
5ee819aedSJulien Thierry 
639358a03SJosh Poimboeuf #include "orc_types.h"
739358a03SJosh Poimboeuf 
839358a03SJosh Poimboeuf #ifdef __ASSEMBLY__
939358a03SJosh Poimboeuf 
10*fb799447SJosh Poimboeuf .macro UNWIND_HINT_END_OF_STACK
11*fb799447SJosh Poimboeuf 	UNWIND_HINT type=UNWIND_HINT_TYPE_END_OF_STACK
12*fb799447SJosh Poimboeuf .endm
13*fb799447SJosh Poimboeuf 
14*fb799447SJosh Poimboeuf .macro UNWIND_HINT_UNDEFINED
15*fb799447SJosh Poimboeuf 	UNWIND_HINT type=UNWIND_HINT_TYPE_UNDEFINED
1639358a03SJosh Poimboeuf .endm
1739358a03SJosh Poimboeuf 
18a09a6e23SPeter Zijlstra .macro UNWIND_HINT_ENTRY
194708ea14SJosh Poimboeuf 	VALIDATE_UNRET_BEGIN
20*fb799447SJosh Poimboeuf 	UNWIND_HINT_END_OF_STACK
21a09a6e23SPeter Zijlstra .endm
22a09a6e23SPeter Zijlstra 
23ffb1b4a4SJosh Poimboeuf .macro UNWIND_HINT_REGS base=%rsp offset=0 indirect=0 extra=1 partial=0 signal=1
24af79ded4SJosh Poimboeuf 	.if \base == %rsp
25af79ded4SJosh Poimboeuf 		.if \indirect
2639358a03SJosh Poimboeuf 			.set sp_reg, ORC_REG_SP_INDIRECT
27af79ded4SJosh Poimboeuf 		.else
2839358a03SJosh Poimboeuf 			.set sp_reg, ORC_REG_SP
29af79ded4SJosh Poimboeuf 		.endif
3039358a03SJosh Poimboeuf 	.elseif \base == %rbp
3139358a03SJosh Poimboeuf 		.set sp_reg, ORC_REG_BP
3239358a03SJosh Poimboeuf 	.elseif \base == %rdi
3339358a03SJosh Poimboeuf 		.set sp_reg, ORC_REG_DI
3439358a03SJosh Poimboeuf 	.elseif \base == %rdx
3539358a03SJosh Poimboeuf 		.set sp_reg, ORC_REG_DX
3639358a03SJosh Poimboeuf 	.elseif \base == %r10
3739358a03SJosh Poimboeuf 		.set sp_reg, ORC_REG_R10
3839358a03SJosh Poimboeuf 	.else
3939358a03SJosh Poimboeuf 		.error "UNWIND_HINT_REGS: bad base register"
4039358a03SJosh Poimboeuf 	.endif
4139358a03SJosh Poimboeuf 
4239358a03SJosh Poimboeuf 	.set sp_offset, \offset
4339358a03SJosh Poimboeuf 
44ee819aedSJulien Thierry 	.if \partial
45ee819aedSJulien Thierry 		.set type, UNWIND_HINT_TYPE_REGS_PARTIAL
4639358a03SJosh Poimboeuf 	.elseif \extra == 0
47ee819aedSJulien Thierry 		.set type, UNWIND_HINT_TYPE_REGS_PARTIAL
4839358a03SJosh Poimboeuf 		.set sp_offset, \offset + (16*8)
4939358a03SJosh Poimboeuf 	.else
50ee819aedSJulien Thierry 		.set type, UNWIND_HINT_TYPE_REGS
5139358a03SJosh Poimboeuf 	.endif
5239358a03SJosh Poimboeuf 
53ffb1b4a4SJosh Poimboeuf 	UNWIND_HINT sp_reg=sp_reg sp_offset=sp_offset type=type signal=\signal
5439358a03SJosh Poimboeuf .endm
5539358a03SJosh Poimboeuf 
56ffb1b4a4SJosh Poimboeuf .macro UNWIND_HINT_IRET_REGS base=%rsp offset=0 signal=1
57ffb1b4a4SJosh Poimboeuf 	UNWIND_HINT_REGS base=\base offset=\offset partial=1 signal=\signal
5839358a03SJosh Poimboeuf .endm
5939358a03SJosh Poimboeuf 
604708ea14SJosh Poimboeuf .macro UNWIND_HINT_IRET_ENTRY base=%rsp offset=0 signal=1
614708ea14SJosh Poimboeuf 	VALIDATE_UNRET_BEGIN
624708ea14SJosh Poimboeuf 	UNWIND_HINT_IRET_REGS base=\base offset=\offset signal=\signal
634708ea14SJosh Poimboeuf .endm
644708ea14SJosh Poimboeuf 
65b735bd3eSJosh Poimboeuf .macro UNWIND_HINT_FUNC
66b735bd3eSJosh Poimboeuf 	UNWIND_HINT sp_reg=ORC_REG_SP sp_offset=8 type=UNWIND_HINT_TYPE_FUNC
67e25eea89SPeter Zijlstra .endm
68e25eea89SPeter Zijlstra 
698faea26eSJosh Poimboeuf .macro UNWIND_HINT_SAVE
708faea26eSJosh Poimboeuf 	UNWIND_HINT type=UNWIND_HINT_TYPE_SAVE
718faea26eSJosh Poimboeuf .endm
728faea26eSJosh Poimboeuf 
738faea26eSJosh Poimboeuf .macro UNWIND_HINT_RESTORE
748faea26eSJosh Poimboeuf 	UNWIND_HINT type=UNWIND_HINT_TYPE_RESTORE
758faea26eSJosh Poimboeuf .endm
768faea26eSJosh Poimboeuf 
77eb4a3f7dSJosh Poimboeuf #else
78eb4a3f7dSJosh Poimboeuf 
79eb4a3f7dSJosh Poimboeuf #define UNWIND_HINT_UNDEFINED \
80*fb799447SJosh Poimboeuf 	UNWIND_HINT(UNWIND_HINT_TYPE_UNDEFINED, 0, 0, 0)
81eb4a3f7dSJosh Poimboeuf 
8239358a03SJosh Poimboeuf #define UNWIND_HINT_FUNC \
8339358a03SJosh Poimboeuf 	UNWIND_HINT(UNWIND_HINT_TYPE_FUNC, ORC_REG_SP, 8, 0)
8439358a03SJosh Poimboeuf 
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