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_CONTEXT_SWITCH, 23 INSN_BUG, 24 INSN_NOP, 25 INSN_STAC, 26 INSN_CLAC, 27 INSN_STD, 28 INSN_CLD, 29 INSN_OTHER, 30 }; 31 32 enum op_dest_type { 33 OP_DEST_REG, 34 OP_DEST_REG_INDIRECT, 35 OP_DEST_MEM, 36 OP_DEST_PUSH, 37 OP_DEST_PUSHF, 38 }; 39 40 struct op_dest { 41 enum op_dest_type type; 42 unsigned char reg; 43 int offset; 44 }; 45 46 enum op_src_type { 47 OP_SRC_REG, 48 OP_SRC_REG_INDIRECT, 49 OP_SRC_CONST, 50 OP_SRC_POP, 51 OP_SRC_POPF, 52 OP_SRC_ADD, 53 OP_SRC_AND, 54 }; 55 56 struct op_src { 57 enum op_src_type type; 58 unsigned char reg; 59 int offset; 60 }; 61 62 struct stack_op { 63 struct op_dest dest; 64 struct op_src src; 65 struct list_head list; 66 }; 67 68 struct instruction; 69 70 void arch_initial_func_cfi_state(struct cfi_init_state *state); 71 72 int arch_decode_instruction(struct objtool_file *file, const struct section *sec, 73 unsigned long offset, unsigned int maxlen, 74 unsigned int *len, enum insn_type *type, 75 unsigned long *immediate, 76 struct list_head *ops_list); 77 78 bool arch_callee_saved_reg(unsigned char reg); 79 80 unsigned long arch_jump_destination(struct instruction *insn); 81 82 unsigned long arch_dest_reloc_offset(int addend); 83 84 const char *arch_nop_insn(int len); 85 const char *arch_ret_insn(int len); 86 87 int arch_decode_hint_reg(u8 sp_reg, int *base); 88 89 bool arch_is_retpoline(struct symbol *sym); 90 91 int arch_rewrite_retpolines(struct objtool_file *file); 92 93 #endif /* _ARCH_H */ 94