blob: 580e344db3dde6375845e183325b6b0ae0b6c505 [file] [log] [blame]
Thomas Gleixner1ccea772019-05-19 15:51:43 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Josh Poimboeuf442f04c2016-02-28 22:22:41 -06002/*
3 * Copyright (C) 2015 Josh Poimboeuf <jpoimboe@redhat.com>
Josh Poimboeuf442f04c2016-02-28 22:22:41 -06004 */
5
6#ifndef _ARCH_H
7#define _ARCH_H
8
9#include <stdbool.h>
Josh Poimboeufbaa41462017-06-28 10:11:07 -050010#include <linux/list.h>
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060011#include "elf.h"
Josh Poimboeufbaa41462017-06-28 10:11:07 -050012#include "cfi.h"
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060013
Josh Poimboeufbaa41462017-06-28 10:11:07 -050014#define INSN_JUMP_CONDITIONAL 1
15#define INSN_JUMP_UNCONDITIONAL 2
16#define INSN_JUMP_DYNAMIC 3
17#define INSN_CALL 4
18#define INSN_CALL_DYNAMIC 5
19#define INSN_RETURN 6
20#define INSN_CONTEXT_SWITCH 7
21#define INSN_STACK 8
Josh Poimboeuf649ea4d2017-07-27 15:56:53 -050022#define INSN_BUG 9
23#define INSN_NOP 10
Peter Zijlstraea242132019-02-25 12:50:09 +010024#define INSN_STAC 11
25#define INSN_CLAC 12
Peter Zijlstra2f0f9e92019-02-25 11:10:55 +010026#define INSN_STD 13
27#define INSN_CLD 14
28#define INSN_OTHER 15
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060029#define INSN_LAST INSN_OTHER
30
Josh Poimboeufbaa41462017-06-28 10:11:07 -050031enum op_dest_type {
32 OP_DEST_REG,
33 OP_DEST_REG_INDIRECT,
34 OP_DEST_MEM,
35 OP_DEST_PUSH,
Peter Zijlstraea242132019-02-25 12:50:09 +010036 OP_DEST_PUSHF,
Josh Poimboeufbaa41462017-06-28 10:11:07 -050037 OP_DEST_LEAVE,
38};
39
40struct op_dest {
41 enum op_dest_type type;
42 unsigned char reg;
43 int offset;
44};
45
46enum op_src_type {
47 OP_SRC_REG,
48 OP_SRC_REG_INDIRECT,
49 OP_SRC_CONST,
50 OP_SRC_POP,
Peter Zijlstraea242132019-02-25 12:50:09 +010051 OP_SRC_POPF,
Josh Poimboeufbaa41462017-06-28 10:11:07 -050052 OP_SRC_ADD,
53 OP_SRC_AND,
54};
55
56struct op_src {
57 enum op_src_type type;
58 unsigned char reg;
59 int offset;
60};
61
62struct stack_op {
63 struct op_dest dest;
64 struct op_src src;
65};
66
67void arch_initial_func_cfi_state(struct cfi_state *state);
68
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060069int arch_decode_instruction(struct elf *elf, struct section *sec,
70 unsigned long offset, unsigned int maxlen,
71 unsigned int *len, unsigned char *type,
Josh Poimboeufbaa41462017-06-28 10:11:07 -050072 unsigned long *immediate, struct stack_op *op);
73
74bool arch_callee_saved_reg(unsigned char reg);
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060075
76#endif /* _ARCH_H */