blob: 580ce18575857349f42624403cb13de666a9ed88 [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001/* SPDX-License-Identifier: GPL-2.0-or-later */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002/*
3 * Copyright (C) 2015 Josh Poimboeuf <jpoimboe@redhat.com>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00004 */
5
6#ifndef _ARCH_H
7#define _ARCH_H
8
9#include <stdbool.h>
10#include <linux/list.h>
Olivier Deprez157378f2022-04-04 15:47:50 +020011#include "objtool.h"
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000012#include "cfi.h"
13
David Brazdil0f672f62019-12-10 10:32:29 +000014enum 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,
David Brazdil0f672f62019-12-10 10:32:29 +000023 INSN_BUG,
24 INSN_NOP,
25 INSN_STAC,
26 INSN_CLAC,
27 INSN_STD,
28 INSN_CLD,
Olivier Deprez92d4c212022-12-06 15:05:30 +010029 INSN_TRAP,
David Brazdil0f672f62019-12-10 10:32:29 +000030 INSN_OTHER,
31};
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000032
33enum op_dest_type {
34 OP_DEST_REG,
35 OP_DEST_REG_INDIRECT,
36 OP_DEST_MEM,
37 OP_DEST_PUSH,
David Brazdil0f672f62019-12-10 10:32:29 +000038 OP_DEST_PUSHF,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000039 OP_DEST_LEAVE,
40};
41
42struct op_dest {
43 enum op_dest_type type;
44 unsigned char reg;
45 int offset;
46};
47
48enum op_src_type {
49 OP_SRC_REG,
50 OP_SRC_REG_INDIRECT,
51 OP_SRC_CONST,
52 OP_SRC_POP,
David Brazdil0f672f62019-12-10 10:32:29 +000053 OP_SRC_POPF,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000054 OP_SRC_ADD,
55 OP_SRC_AND,
56};
57
58struct op_src {
59 enum op_src_type type;
60 unsigned char reg;
61 int offset;
62};
63
64struct stack_op {
65 struct op_dest dest;
66 struct op_src src;
Olivier Deprez157378f2022-04-04 15:47:50 +020067 struct list_head list;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000068};
69
Olivier Deprez157378f2022-04-04 15:47:50 +020070struct instruction;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000071
Olivier Deprez157378f2022-04-04 15:47:50 +020072void arch_initial_func_cfi_state(struct cfi_init_state *state);
73
74int arch_decode_instruction(const struct elf *elf, const struct section *sec,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000075 unsigned long offset, unsigned int maxlen,
David Brazdil0f672f62019-12-10 10:32:29 +000076 unsigned int *len, enum insn_type *type,
Olivier Deprez157378f2022-04-04 15:47:50 +020077 unsigned long *immediate,
78 struct list_head *ops_list);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000079
80bool arch_callee_saved_reg(unsigned char reg);
81
Olivier Deprez157378f2022-04-04 15:47:50 +020082unsigned long arch_jump_destination(struct instruction *insn);
83
84unsigned long arch_dest_reloc_offset(int addend);
85
86const char *arch_nop_insn(int len);
Olivier Deprez92d4c212022-12-06 15:05:30 +010087const char *arch_ret_insn(int len);
Olivier Deprez157378f2022-04-04 15:47:50 +020088
Olivier Deprez92d4c212022-12-06 15:05:30 +010089int arch_decode_hint_reg(u8 sp_reg, int *base);
90
91bool arch_is_retpoline(struct symbol *sym);
92bool arch_is_rethunk(struct symbol *sym);
93
94int arch_rewrite_retpolines(struct objtool_file *file);
Olivier Deprez157378f2022-04-04 15:47:50 +020095
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000096#endif /* _ARCH_H */