Loading...
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 "elf.h"
12#include "cfi.h"
13
14enum 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_STACK,
24 INSN_BUG,
25 INSN_NOP,
26 INSN_STAC,
27 INSN_CLAC,
28 INSN_STD,
29 INSN_CLD,
30 INSN_OTHER,
31};
32
33enum op_dest_type {
34 OP_DEST_REG,
35 OP_DEST_REG_INDIRECT,
36 OP_DEST_MEM,
37 OP_DEST_PUSH,
38 OP_DEST_PUSHF,
39 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,
53 OP_SRC_POPF,
54 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;
67};
68
69void arch_initial_func_cfi_state(struct cfi_state *state);
70
71int arch_decode_instruction(struct elf *elf, struct section *sec,
72 unsigned long offset, unsigned int maxlen,
73 unsigned int *len, enum insn_type *type,
74 unsigned long *immediate, struct stack_op *op);
75
76bool arch_callee_saved_reg(unsigned char reg);
77
78#endif /* _ARCH_H */
1/*
2 * Copyright (C) 2015 Josh Poimboeuf <jpoimboe@redhat.com>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef _ARCH_H
19#define _ARCH_H
20
21#include <stdbool.h>
22#include "elf.h"
23
24#define INSN_FP_SAVE 1
25#define INSN_FP_SETUP 2
26#define INSN_FP_RESTORE 3
27#define INSN_JUMP_CONDITIONAL 4
28#define INSN_JUMP_UNCONDITIONAL 5
29#define INSN_JUMP_DYNAMIC 6
30#define INSN_CALL 7
31#define INSN_CALL_DYNAMIC 8
32#define INSN_RETURN 9
33#define INSN_CONTEXT_SWITCH 10
34#define INSN_BUG 11
35#define INSN_NOP 12
36#define INSN_OTHER 13
37#define INSN_LAST INSN_OTHER
38
39int arch_decode_instruction(struct elf *elf, struct section *sec,
40 unsigned long offset, unsigned int maxlen,
41 unsigned int *len, unsigned char *type,
42 unsigned long *displacement);
43
44#endif /* _ARCH_H */