blob: 7a111a77b7aa418cb2c50edaf62a470150f7f888 [file] [log] [blame]
Josh Poimboeuf442f04c2016-02-28 22:22:41 -06001/*
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>
Josh Poimboeufbaa41462017-06-28 10:11:07 -050022#include <linux/list.h>
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060023#include "elf.h"
Josh Poimboeufbaa41462017-06-28 10:11:07 -050024#include "cfi.h"
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060025
Josh Poimboeufbaa41462017-06-28 10:11:07 -050026#define INSN_JUMP_CONDITIONAL 1
27#define INSN_JUMP_UNCONDITIONAL 2
28#define INSN_JUMP_DYNAMIC 3
29#define INSN_CALL 4
30#define INSN_CALL_DYNAMIC 5
31#define INSN_RETURN 6
32#define INSN_CONTEXT_SWITCH 7
33#define INSN_STACK 8
Josh Poimboeuf649ea4d2017-07-27 15:56:53 -050034#define INSN_BUG 9
35#define INSN_NOP 10
Peter Zijlstraea242132019-02-25 12:50:09 +010036#define INSN_STAC 11
37#define INSN_CLAC 12
Peter Zijlstra2f0f9e92019-02-25 11:10:55 +010038#define INSN_STD 13
39#define INSN_CLD 14
40#define INSN_OTHER 15
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060041#define INSN_LAST INSN_OTHER
42
Josh Poimboeufbaa41462017-06-28 10:11:07 -050043enum op_dest_type {
44 OP_DEST_REG,
45 OP_DEST_REG_INDIRECT,
46 OP_DEST_MEM,
47 OP_DEST_PUSH,
Peter Zijlstraea242132019-02-25 12:50:09 +010048 OP_DEST_PUSHF,
Josh Poimboeufbaa41462017-06-28 10:11:07 -050049 OP_DEST_LEAVE,
50};
51
52struct op_dest {
53 enum op_dest_type type;
54 unsigned char reg;
55 int offset;
56};
57
58enum op_src_type {
59 OP_SRC_REG,
60 OP_SRC_REG_INDIRECT,
61 OP_SRC_CONST,
62 OP_SRC_POP,
Peter Zijlstraea242132019-02-25 12:50:09 +010063 OP_SRC_POPF,
Josh Poimboeufbaa41462017-06-28 10:11:07 -050064 OP_SRC_ADD,
65 OP_SRC_AND,
66};
67
68struct op_src {
69 enum op_src_type type;
70 unsigned char reg;
71 int offset;
72};
73
74struct stack_op {
75 struct op_dest dest;
76 struct op_src src;
77};
78
79void arch_initial_func_cfi_state(struct cfi_state *state);
80
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060081int arch_decode_instruction(struct elf *elf, struct section *sec,
82 unsigned long offset, unsigned int maxlen,
83 unsigned int *len, unsigned char *type,
Josh Poimboeufbaa41462017-06-28 10:11:07 -050084 unsigned long *immediate, struct stack_op *op);
85
86bool arch_callee_saved_reg(unsigned char reg);
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060087
88#endif /* _ARCH_H */