1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Copyright (C) 2015 Josh Poimboeuf <[email protected]>
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_CONTEXT_SWITCH,
23 	INSN_BUG,
24 	INSN_NOP,
25 	INSN_STAC,
26 	INSN_CLAC,
27 	INSN_STD,
28 	INSN_CLD,
29 	INSN_TRAP,
30 	INSN_ENDBR,
31 	INSN_LEA_RIP,
32 	INSN_OTHER,
33 };
34 
35 enum op_dest_type {
36 	OP_DEST_REG,
37 	OP_DEST_REG_INDIRECT,
38 	OP_DEST_MEM,
39 	OP_DEST_PUSH,
40 	OP_DEST_PUSHF,
41 };
42 
43 struct op_dest {
44 	enum op_dest_type type;
45 	unsigned char reg;
46 	int offset;
47 };
48 
49 enum op_src_type {
50 	OP_SRC_REG,
51 	OP_SRC_REG_INDIRECT,
52 	OP_SRC_CONST,
53 	OP_SRC_POP,
54 	OP_SRC_POPF,
55 	OP_SRC_ADD,
56 	OP_SRC_AND,
57 };
58 
59 struct op_src {
60 	enum op_src_type type;
61 	unsigned char reg;
62 	int offset;
63 };
64 
65 struct stack_op {
66 	struct stack_op *next;
67 	struct op_dest dest;
68 	struct op_src src;
69 };
70 
71 struct instruction;
72 
73 int arch_ftrace_match(char *name);
74 
75 void arch_initial_func_cfi_state(struct cfi_init_state *state);
76 
77 int arch_decode_instruction(struct objtool_file *file, const struct section *sec,
78 			    unsigned long offset, unsigned int maxlen,
79 			    struct instruction *insn);
80 
81 bool arch_callee_saved_reg(unsigned char reg);
82 
83 unsigned long arch_jump_destination(struct instruction *insn);
84 
85 unsigned long arch_dest_reloc_offset(int addend);
86 
87 const char *arch_nop_insn(int len);
88 const char *arch_ret_insn(int len);
89 
90 int arch_decode_hint_reg(u8 sp_reg, int *base);
91 
92 bool arch_is_retpoline(struct symbol *sym);
93 bool arch_is_rethunk(struct symbol *sym);
94 bool arch_is_embedded_insn(struct symbol *sym);
95 
96 int arch_rewrite_retpolines(struct objtool_file *file);
97 
98 bool arch_pc_relative_reloc(struct reloc *reloc);
99 
100 unsigned int arch_reloc_size(struct reloc *reloc);
101 unsigned long arch_jump_table_sym_offset(struct reloc *reloc, struct reloc *table);
102 
103 #endif /* _ARCH_H */
104