xref: /linux/tools/objtool/include/objtool/arch.h (revision 63e6995005be8ceb8a1d56a18df1a1a40c28356d)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Copyright (C) 2015 Josh Poimboeuf <jpoimboe@redhat.com>
4  */
5 
6 #ifndef _ARCH_H
7 #define _ARCH_H
8 
9 #include <stdbool.h>
10 #include <linux/list.h>
11 #include <objtool/objtool.h>
12 #include <objtool/cfi.h>
13 
14 enum insn_type {
15 	INSN_JUMP_CONDITIONAL,
16 	INSN_JUMP_UNCONDITIONAL,
17 	INSN_JUMP_DYNAMIC,
18 	INSN_JUMP_DYNAMIC_CONDITIONAL,
19 	INSN_CALL,
20 	INSN_CALL_DYNAMIC,
21 	INSN_RETURN,
22 	INSN_SYSCALL,
23 	INSN_SYSRET,
24 	INSN_BUG,
25 	INSN_NOP,
26 	INSN_STAC,
27 	INSN_CLAC,
28 	INSN_STD,
29 	INSN_CLD,
30 	INSN_TRAP,
31 	INSN_ENDBR,
32 	INSN_LEA_RIP,
33 	INSN_OTHER,
34 };
35 
36 enum op_dest_type {
37 	OP_DEST_REG,
38 	OP_DEST_REG_INDIRECT,
39 	OP_DEST_MEM,
40 	OP_DEST_PUSH,
41 	OP_DEST_PUSHF,
42 };
43 
44 struct op_dest {
45 	enum op_dest_type type;
46 	unsigned char reg;
47 	int offset;
48 };
49 
50 enum op_src_type {
51 	OP_SRC_REG,
52 	OP_SRC_REG_INDIRECT,
53 	OP_SRC_CONST,
54 	OP_SRC_POP,
55 	OP_SRC_POPF,
56 	OP_SRC_ADD,
57 	OP_SRC_AND,
58 };
59 
60 struct op_src {
61 	enum op_src_type type;
62 	unsigned char reg;
63 	int offset;
64 };
65 
66 struct stack_op {
67 	struct stack_op *next;
68 	struct op_dest dest;
69 	struct op_src src;
70 };
71 
72 struct instruction;
73 
74 int arch_ftrace_match(const char *name);
75 
76 void arch_initial_func_cfi_state(struct cfi_init_state *state);
77 
78 int arch_decode_instruction(struct objtool_file *file, const struct section *sec,
79 			    unsigned long offset, unsigned int maxlen,
80 			    struct instruction *insn);
81 
82 bool arch_callee_saved_reg(unsigned char reg);
83 
84 unsigned long arch_jump_destination(struct instruction *insn);
85 
86 s64 arch_insn_adjusted_addend(struct instruction *insn, struct reloc *reloc);
87 u64 arch_adjusted_addend(struct reloc *reloc);
88 
89 const char *arch_nop_insn(int len);
90 const char *arch_ret_insn(int len);
91 
92 int arch_decode_hint_reg(u8 sp_reg, int *base);
93 
94 bool arch_is_retpoline(struct symbol *sym);
95 bool arch_is_rethunk(struct symbol *sym);
96 bool arch_is_embedded_insn(struct symbol *sym);
97 
98 int arch_rewrite_retpolines(struct objtool_file *file);
99 
100 bool arch_pc_relative_reloc(struct reloc *reloc);
101 bool arch_absolute_reloc(struct elf *elf, struct reloc *reloc);
102 
103 unsigned int arch_reloc_size(struct reloc *reloc);
104 unsigned long arch_jump_table_sym_offset(struct reloc *reloc, struct reloc *table);
105 
106 extern const char *arch_reg_name[CFI_NUM_REGS];
107 
108 #ifdef DISAS
109 
110 #include <bfd.h>
111 #include <dis-asm.h>
112 
113 int arch_disas_info_init(struct disassemble_info *dinfo);
114 
115 #endif /* DISAS */
116 
117 #endif /* _ARCH_H */
118