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.h" 12 #include "cfi.h" 13 14 #ifdef INSN_USE_ORC 15 #include <asm/orc_types.h> 16 #endif 17 18 enum insn_type { 19 INSN_JUMP_CONDITIONAL, 20 INSN_JUMP_UNCONDITIONAL, 21 INSN_JUMP_DYNAMIC, 22 INSN_JUMP_DYNAMIC_CONDITIONAL, 23 INSN_CALL, 24 INSN_CALL_DYNAMIC, 25 INSN_RETURN, 26 INSN_CONTEXT_SWITCH, 27 INSN_BUG, 28 INSN_NOP, 29 INSN_STAC, 30 INSN_CLAC, 31 INSN_STD, 32 INSN_CLD, 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 OP_DEST_LEAVE, 43 }; 44 45 struct op_dest { 46 enum op_dest_type type; 47 unsigned char reg; 48 int offset; 49 }; 50 51 enum op_src_type { 52 OP_SRC_REG, 53 OP_SRC_REG_INDIRECT, 54 OP_SRC_CONST, 55 OP_SRC_POP, 56 OP_SRC_POPF, 57 OP_SRC_ADD, 58 OP_SRC_AND, 59 }; 60 61 struct op_src { 62 enum op_src_type type; 63 unsigned char reg; 64 int offset; 65 }; 66 67 struct stack_op { 68 struct op_dest dest; 69 struct op_src src; 70 struct list_head list; 71 }; 72 73 struct instruction; 74 75 void arch_initial_func_cfi_state(struct cfi_init_state *state); 76 77 int arch_decode_instruction(const struct elf *elf, const struct section *sec, 78 unsigned long offset, unsigned int maxlen, 79 unsigned int *len, enum insn_type *type, 80 unsigned long *immediate, 81 struct list_head *ops_list); 82 83 bool arch_callee_saved_reg(unsigned char reg); 84 85 unsigned long arch_jump_destination(struct instruction *insn); 86 87 unsigned long arch_dest_reloc_offset(int addend); 88 89 const char *arch_nop_insn(int len); 90 91 int arch_decode_hint_reg(struct instruction *insn, u8 sp_reg); 92 93 #endif /* _ARCH_H */ 94