blob: 4a84c3081b8e131572b32c9e02a7dfbcf8c40068 [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
Olivier Deprez157378f2022-04-04 15:47:50 +020014#ifdef INSN_USE_ORC
15#include <asm/orc_types.h>
16#endif
17
David Brazdil0f672f62019-12-10 10:32:29 +000018enum 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,
David Brazdil0f672f62019-12-10 10:32:29 +000027 INSN_BUG,
28 INSN_NOP,
29 INSN_STAC,
30 INSN_CLAC,
31 INSN_STD,
32 INSN_CLD,
33 INSN_OTHER,
34};
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000035
36enum op_dest_type {
37 OP_DEST_REG,
38 OP_DEST_REG_INDIRECT,
39 OP_DEST_MEM,
40 OP_DEST_PUSH,
David Brazdil0f672f62019-12-10 10:32:29 +000041 OP_DEST_PUSHF,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000042 OP_DEST_LEAVE,
43};
44
45struct op_dest {
46 enum op_dest_type type;
47 unsigned char reg;
48 int offset;
49};
50
51enum op_src_type {
52 OP_SRC_REG,
53 OP_SRC_REG_INDIRECT,
54 OP_SRC_CONST,
55 OP_SRC_POP,
David Brazdil0f672f62019-12-10 10:32:29 +000056 OP_SRC_POPF,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000057 OP_SRC_ADD,
58 OP_SRC_AND,
59};
60
61struct op_src {
62 enum op_src_type type;
63 unsigned char reg;
64 int offset;
65};
66
67struct stack_op {
68 struct op_dest dest;
69 struct op_src src;
Olivier Deprez157378f2022-04-04 15:47:50 +020070 struct list_head list;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000071};
72
Olivier Deprez157378f2022-04-04 15:47:50 +020073struct instruction;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000074
Olivier Deprez157378f2022-04-04 15:47:50 +020075void arch_initial_func_cfi_state(struct cfi_init_state *state);
76
77int arch_decode_instruction(const struct elf *elf, const struct section *sec,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000078 unsigned long offset, unsigned int maxlen,
David Brazdil0f672f62019-12-10 10:32:29 +000079 unsigned int *len, enum insn_type *type,
Olivier Deprez157378f2022-04-04 15:47:50 +020080 unsigned long *immediate,
81 struct list_head *ops_list);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000082
83bool arch_callee_saved_reg(unsigned char reg);
84
Olivier Deprez157378f2022-04-04 15:47:50 +020085unsigned long arch_jump_destination(struct instruction *insn);
86
87unsigned long arch_dest_reloc_offset(int addend);
88
89const char *arch_nop_insn(int len);
90
91int arch_decode_hint_reg(struct instruction *insn, u8 sp_reg);
92
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000093#endif /* _ARCH_H */